jpeg2000parse + openjpeg: Switch striped mode to its own caps

It's not compatible with any other element that use the non-striped
mode. In addition, in this mode, we require that every frame have the
same number of stripes or that the MARKER bit be present, which is
different from the other
formats too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/979>
This commit is contained in:
Stéphane Cerveau 2021-01-22 10:39:56 +01:00 committed by GStreamer Marge Bot
parent 619cbca642
commit 0d0e89108b
4 changed files with 131 additions and 118 deletions

View file

@ -1,4 +1,4 @@
{ {
"accurip": { "accurip": {
"description": "Computes an AccurateRip CRC", "description": "Computes an AccurateRip CRC",
"elements": { "elements": {
@ -217932,7 +217932,7 @@
"long-name": "OpenJPEG JPEG2000 decoder", "long-name": "OpenJPEG JPEG2000 decoder",
"pad-templates": { "pad-templates": {
"sink": { "sink": {
"caps": "image/x-j2c:\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\nimage/x-jpc:\n alignment: frame\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\nimage/jp2:\n", "caps": "image/x-j2c:\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\nimage/x-jpc:\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\nimage/jp2:\nimage/x-jpc-striped:\n num-stripes: [ 2, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n",
"direction": "sink", "direction": "sink",
"presence": "always" "presence": "always"
}, },
@ -217943,8 +217943,22 @@
} }
}, },
"properties": { "properties": {
"max-slice-threads": {
"blurb": "Maximum number of worker threads to spawn according to the frame boundary. (0 = no thread)",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "0",
"max": "2147483647",
"min": "0",
"mutable": "null",
"readable": true,
"type": "gint",
"writable": true
},
"max-threads": { "max-threads": {
"blurb": "Maximum number of worker threads to spawn. (0 = auto)", "blurb": "Maximum number of worker threads to spawn used by openjpeg internally. (0 = no thread)",
"conditionally-available": false, "conditionally-available": false,
"construct": false, "construct": false,
"construct-only": false, "construct-only": false,
@ -217983,7 +217997,7 @@
"presence": "always" "presence": "always"
}, },
"src": { "src": {
"caps": "image/x-j2c:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n num-components: [ 1, 4 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\nimage/x-jpc:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n num-components: [ 1, 4 ]\n num-stripes: [ 1, 2147483647 ]\n alignment: { (string)frame, (string)stripe }\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\nimage/jp2:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n", "caps": "image/x-j2c:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n num-components: [ 1, 4 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\nimage/x-jpc:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n num-components: [ 1, 4 ]\n num-stripes: [ 1, 2147483647 ]\n alignment: { (string)frame, (string)stripe }\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\nimage/jp2:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\nimage/x-jpc-striped:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n num-components: [ 1, 4 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n num-stripes: [ 2, 2147483647 ]\n stripe-height: [ 1, 2147483647 ]\n",
"direction": "src", "direction": "src",
"presence": "always" "presence": "always"
} }
@ -226301,12 +226315,12 @@
"long-name": "JPEG 2000 parser", "long-name": "JPEG 2000 parser",
"pad-templates": { "pad-templates": {
"sink": { "sink": {
"caps": "image/jp2:\nimage/x-jpc:\n alignment: { (string)frame, (string)stripe }\nimage/x-j2c:\n alignment: { (string)frame, (string)stripe }\n", "caps": "image/jp2:\nimage/x-jpc:\nimage/x-j2c:\nimage/x-jpc-striped:\n",
"direction": "sink", "direction": "sink",
"presence": "always" "presence": "always"
}, },
"src": { "src": {
"caps": "image/x-jpc:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n profile: [ 0, 49151 ]\n parsed: true\nimage/x-j2c:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n profile: [ 0, 49151 ]\n parsed: true\n", "caps": "image/x-jpc:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n profile: [ 0, 49151 ]\n parsed: true\nimage/x-j2c:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n profile: [ 0, 49151 ]\n parsed: true\nimage/x-jpc-striped:\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n sampling: { (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)YCbCr-4:4:4, (string)YCbCr-4:2:2, (string)YCbCr-4:2:0, (string)YCbCr-4:1:1, (string)YCbCr-4:1:0, (string)GRAYSCALE, (string)YCbCrA-4:4:4:4 }\n colorspace: { (string)sRGB, (string)sYUV, (string)GRAY }\n profile: [ 0, 49151 ]\n num-stripes: [ 2, 2147483647 ]\n parsed: true\n",
"direction": "src", "direction": "src",
"presence": "always" "presence": "always"
} }
@ -230150,4 +230164,4 @@
"tracers": {}, "tracers": {},
"url": "Unknown package origin" "url": "Unknown package origin"
} }
} }

View file

@ -101,11 +101,11 @@ static GstStaticPadTemplate gst_openjpeg_dec_sink_template =
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-j2c, " GST_STATIC_CAPS ("image/x-j2c, "
"alignment= (string){frame,stripe}, "
GST_JPEG2000_SAMPLING_LIST "; " GST_JPEG2000_SAMPLING_LIST "; "
"image/x-jpc," "image/x-jpc,"
"alignment= (string){frame,stripe}, " GST_JPEG2000_SAMPLING_LIST "; image/jp2 ; "
GST_JPEG2000_SAMPLING_LIST "; " "image/jp2") "image/x-jpc-striped, "
"num-stripes = (int) [2, MAX], " GST_JPEG2000_SAMPLING_LIST)
); );
static GstStaticPadTemplate gst_openjpeg_dec_src_template = static GstStaticPadTemplate gst_openjpeg_dec_src_template =
@ -359,8 +359,6 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
{ {
GstOpenJPEGDec *self = GST_OPENJPEG_DEC (decoder); GstOpenJPEGDec *self = GST_OPENJPEG_DEC (decoder);
GstStructure *s; GstStructure *s;
gint caps_int = 0;
const gchar *caps_string = NULL;
GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps); GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
@ -374,27 +372,22 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
} else if (gst_structure_has_name (s, "image/x-j2c")) { } else if (gst_structure_has_name (s, "image/x-j2c")) {
self->codec_format = OPJ_CODEC_J2K; self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = TRUE; self->is_jp2c = TRUE;
} else if (gst_structure_has_name (s, "image/x-jpc")) { } else if (gst_structure_has_name (s, "image/x-jpc") ||
gst_structure_has_name (s, "image/x-jpc-striped")) {
self->codec_format = OPJ_CODEC_J2K; self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = FALSE; self->is_jp2c = FALSE;
} else { } else {
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
} }
self->num_stripes = 1; if (gst_structure_has_name (s, "image/x-jpc-striped")) {
caps_string = gst_structure_get_string (s, "alignment"); gst_structure_get_int (s, "num-stripes", &self->num_stripes);
gst_structure_get_int (s, "num-stripes", &caps_int);
if (caps_int > 1) {
self->num_stripes = caps_int;
gst_video_decoder_set_subframe_mode (decoder, TRUE); gst_video_decoder_set_subframe_mode (decoder, TRUE);
} else { } else {
self->num_stripes = 1;
gst_video_decoder_set_subframe_mode (decoder, FALSE); gst_video_decoder_set_subframe_mode (decoder, FALSE);
if (g_strcmp0 (caps_string, "stripe") == 0) {
GST_ERROR_OBJECT (self,
"Alignment is set to stripe but num-stripes is missing");
return FALSE;
}
} }
self->sampling = self->sampling =
gst_jpeg2000_sampling_from_string (gst_structure_get_string (s, gst_jpeg2000_sampling_from_string (gst_structure_get_string (s,
"sampling")); "sampling"));

View file

@ -162,7 +162,15 @@ static GstStaticPadTemplate gst_openjpeg_enc_src_template =
"alignment = (string) { frame, stripe }, " "alignment = (string) { frame, stripe }, "
GST_JPEG2000_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
GST_JPEG2000_COLORSPACE_LIST "; " GST_JPEG2000_COLORSPACE_LIST "; "
"image/jp2, " "width = (int) [1, MAX], " "height = (int) [1, MAX]") "image/jp2, " "width = (int) [1, MAX], "
"height = (int) [1, MAX] ;"
"image/x-jpc-striped, "
"width = (int) [1, MAX], "
"height = (int) [1, MAX], "
"num-components = (int) [1, 4], "
GST_JPEG2000_SAMPLING_LIST ", "
GST_JPEG2000_COLORSPACE_LIST ", "
"num-stripes = (int) [2, MAX], stripe-height = (int) [1 , MAX]")
); );
#define parent_class gst_openjpeg_enc_parent_class #define parent_class gst_openjpeg_enc_parent_class
@ -742,20 +750,46 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
gst_video_codec_state_unref (self->input_state); gst_video_codec_state_unref (self->input_state);
self->input_state = gst_video_codec_state_ref (state); self->input_state = gst_video_codec_state_ref (state);
allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); if (stripe_mode) {
allowed_caps = gst_caps_truncate (allowed_caps); GstCaps *template_caps = gst_caps_new_empty_simple ("image/x-jpc-striped");
s = gst_caps_get_structure (allowed_caps, 0); GstCaps *my_caps;
if (gst_structure_has_name (s, "image/jp2")) {
self->codec_format = OPJ_CODEC_JP2; my_caps = gst_pad_query_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder),
self->is_jp2c = FALSE; template_caps);
} else if (gst_structure_has_name (s, "image/x-j2c")) { gst_caps_unref (template_caps);
self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = TRUE; allowed_caps = gst_pad_peer_query_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder),
} else if (gst_structure_has_name (s, "image/x-jpc")) { my_caps);
gst_caps_unref (my_caps);
if (gst_caps_is_empty (allowed_caps)) {
gst_caps_unref (allowed_caps);
GST_WARNING_OBJECT (self, "Striped JPEG 2000 not accepted downstream");
return FALSE;
}
self->codec_format = OPJ_CODEC_J2K; self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = FALSE; self->is_jp2c = FALSE;
allowed_caps = gst_caps_truncate (allowed_caps);
s = gst_caps_get_structure (allowed_caps, 0);
} else { } else {
g_return_val_if_reached (FALSE); allowed_caps =
gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
allowed_caps = gst_caps_truncate (allowed_caps);
s = gst_caps_get_structure (allowed_caps, 0);
if (gst_structure_has_name (s, "image/jp2")) {
self->codec_format = OPJ_CODEC_JP2;
self->is_jp2c = FALSE;
} else if (gst_structure_has_name (s, "image/x-j2c")) {
self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = TRUE;
} else if (gst_structure_has_name (s, "image/x-jpc")) {
self->codec_format = OPJ_CODEC_J2K;
self->is_jp2c = FALSE;
} else {
g_return_val_if_reached (FALSE);
}
} }
switch (state->info.finfo->format) { switch (state->info.finfo->format) {
@ -806,7 +840,6 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
g_assert_not_reached (); g_assert_not_reached ();
} }
/* sampling */ /* sampling */
/* note: encoder re-orders channels so that alpha channel is encoded as the last channel */ /* note: encoder re-orders channels so that alpha channel is encoded as the last channel */
switch (state->info.finfo->format) { switch (state->info.finfo->format) {
@ -861,21 +894,24 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
} else } else
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
if (sampling != GST_JPEG2000_SAMPLING_NONE) { if (stripe_mode) {
caps = gst_caps_new_simple (gst_structure_get_name (s), caps = gst_caps_new_simple ("image/x-jpc-striped",
"colorspace", G_TYPE_STRING, colorspace, "colorspace", G_TYPE_STRING, colorspace,
"sampling", G_TYPE_STRING, gst_jpeg2000_sampling_to_string (sampling), "sampling", G_TYPE_STRING, gst_jpeg2000_sampling_to_string (sampling),
"num-components", G_TYPE_INT, ncomps, "num-components", G_TYPE_INT, ncomps,
"alignment", G_TYPE_STRING, "num-stripes", G_TYPE_INT, self->num_stripes,
stripe_mode ? "stripe" : "frame", "stripe-height", G_TYPE_INT,
"num-stripes", G_TYPE_INT, self->num_stripes, NULL); get_stripe_height (self, 0,
GST_VIDEO_INFO_COMP_HEIGHT (&state->info, 0)), NULL);
} else if (sampling != GST_JPEG2000_SAMPLING_NONE) {
caps = gst_caps_new_simple (gst_structure_get_name (s),
"colorspace", G_TYPE_STRING, colorspace,
"sampling", G_TYPE_STRING, gst_jpeg2000_sampling_to_string (sampling),
"num-components", G_TYPE_INT, ncomps, NULL);
} else { } else {
caps = gst_caps_new_simple (gst_structure_get_name (s), caps = gst_caps_new_simple (gst_structure_get_name (s),
"colorspace", G_TYPE_STRING, colorspace, "colorspace", G_TYPE_STRING, colorspace,
"num-components", G_TYPE_INT, ncomps, "num-components", G_TYPE_INT, ncomps, NULL);
"alignment", G_TYPE_STRING,
stripe_mode ? "stripe" : "frame",
"num-stripes", G_TYPE_INT, self->num_stripes, NULL);
} }
gst_caps_unref (allowed_caps); gst_caps_unref (allowed_caps);
@ -1342,30 +1378,14 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder,
GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (encoder); GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (encoder);
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstVideoFrame vframe; GstVideoFrame vframe;
GstCaps *current_caps;
GstStructure *s;
gboolean subframe_mode = gboolean subframe_mode =
self->num_stripes != GST_OPENJPEG_ENC_DEFAULT_NUM_STRIPES; self->num_stripes != GST_OPENJPEG_ENC_DEFAULT_NUM_STRIPES;
GST_DEBUG_OBJECT (self, "Handling frame"); GST_DEBUG_OBJECT (self, "Handling frame");
current_caps = gst_pad_get_current_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
s = gst_caps_get_structure (current_caps, 0);
if (subframe_mode) { if (subframe_mode) {
const gchar *str = gst_structure_get_string (s, "alignment");
gint min_res; gint min_res;
if (g_strcmp0 (str, "stripe") != 0) {
GST_ERROR_OBJECT (self,
"Number of stripes set to %d, but alignment=stripe not supported downstream",
self->num_stripes);
gst_video_codec_frame_unref (frame);
ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
/* due to limitations in openjpeg library, /* due to limitations in openjpeg library,
* number of wavelet resolutions must not exceed floor(log(stripe height)) + 1 */ * number of wavelet resolutions must not exceed floor(log(stripe height)) + 1 */
if (!gst_video_frame_map (&vframe, &self->input_state->info, if (!gst_video_frame_map (&vframe, &self->input_state->info,
@ -1387,9 +1407,7 @@ gst_openjpeg_enc_handle_frame (GstVideoEncoder * encoder,
} }
if (self->encode_frame (encoder, frame) != GST_FLOW_OK) if (self->encode_frame (encoder, frame) != GST_FLOW_OK)
goto error; goto error;
done:
if (current_caps)
gst_caps_unref (current_caps);
return ret; return ret;
error: error:

View file

@ -109,15 +109,21 @@ static GstStaticPadTemplate srctemplate =
" width = (int)[1, MAX], height = (int)[1, MAX]," " width = (int)[1, MAX], height = (int)[1, MAX],"
GST_JPEG2000_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
GST_JPEG2000_COLORSPACE_LIST "," GST_JPEG2000_COLORSPACE_LIST ","
" profile = (int)[0, 49151]," " parsed = (boolean) true") " profile = (int)[0, 49151],"
" parsed = (boolean) true ; "
"image/x-jpc-striped,"
" width = (int)[1, MAX], height = (int)[1, MAX],"
GST_JPEG2000_SAMPLING_LIST ","
GST_JPEG2000_COLORSPACE_LIST ","
" profile = (int)[0, 49151],"
" num-stripes = [ 2, MAX ], parsed = (boolean) true;")
); );
static GstStaticPadTemplate sinktemplate = static GstStaticPadTemplate sinktemplate =
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/jp2;" GST_STATIC_CAPS ("image/jp2; image/x-jpc; image/x-j2c; "
"image/x-jpc, alignment = (string){frame, stripe};" "image/x-jpc-striped"));
"image/x-j2c, alignment = (string){frame, stripe}"));
#define parent_class gst_jpeg2000_parse_parent_class #define parent_class gst_jpeg2000_parse_parent_class
G_DEFINE_TYPE (GstJPEG2000Parse, gst_jpeg2000_parse, GST_TYPE_BASE_PARSE); G_DEFINE_TYPE (GstJPEG2000Parse, gst_jpeg2000_parse, GST_TYPE_BASE_PARSE);
@ -334,6 +340,8 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
guint num_prefix_bytes = 0; /* number of bytes to skip before actual code stream */ guint num_prefix_bytes = 0; /* number of bytes to skip before actual code stream */
GstCaps *src_caps = NULL; GstCaps *src_caps = NULL;
guint eoc_frame_size = 0; guint eoc_frame_size = 0;
gint num_stripes = 1;
gint stripe_height = 0;
for (i = 0; i < GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS; ++i) { for (i = 0; i < GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS; ++i) {
dx[i] = 1; dx[i] = 1;
@ -684,15 +692,30 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
/* use caps height if in sub-frame mode, as encoded frame height will be /* use caps height if in sub-frame mode, as encoded frame height will be
* strictly less than full frame height */ * strictly less than full frame height */
if (current_caps_struct) { if (current_caps_struct &&
gint num_stripes = 1; gst_structure_has_name (current_caps_struct, "image/x-jpc-striped")) {
gint h; gint h;
if (gst_structure_get_int (current_caps_struct, "num-stripes", &num_stripes) if (!gst_structure_get_int (current_caps_struct, "num-stripes",
&& num_stripes > 1) { &num_stripes) || num_stripes < 2) {
gst_structure_get_int (current_caps_struct, "height", &h); GST_ELEMENT_ERROR (parse, STREAM, FORMAT, (NULL),
height = h; ("Striped JPEG 2000 is missing the stripe count"));
ret = GST_FLOW_ERROR;
goto beach;
} }
if (!gst_structure_get_int (current_caps_struct, "stripe-height",
&stripe_height)) {
stripe_height = height;
} else if (stripe_height != height &&
!GST_BUFFER_FLAG_IS_SET (frame->buffer, GST_BUFFER_FLAG_MARKER)) {
GST_WARNING_OBJECT (parse,
"Only the last stripe is expected to be different"
" from the stripe height (%d != %u)", height, stripe_height);
}
gst_structure_get_int (current_caps_struct, "height", &h);
height = h;
} }
/* now we can set the source caps, if something has changed */ /* now we can set the source caps, if something has changed */
@ -705,8 +728,8 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
gint fr_num = 0, fr_denom = 0; gint fr_num = 0, fr_denom = 0;
src_caps = src_caps =
gst_caps_new_simple (media_type_from_codec_format gst_caps_new_simple (num_stripes > 1 ? "image/x-jpc-striped" :
(jpeg2000parse->src_codec_format), media_type_from_codec_format (jpeg2000parse->src_codec_format),
"width", G_TYPE_INT, width, "width", G_TYPE_INT, width,
"height", G_TYPE_INT, height, "height", G_TYPE_INT, height,
"colorspace", G_TYPE_STRING, "colorspace", G_TYPE_STRING,
@ -714,6 +737,10 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
G_TYPE_STRING, gst_jpeg2000_sampling_to_string (source_sampling), G_TYPE_STRING, gst_jpeg2000_sampling_to_string (source_sampling),
"profile", G_TYPE_INT, profile, "parsed", G_TYPE_BOOLEAN, TRUE, NULL); "profile", G_TYPE_INT, profile, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
if (num_stripes > 1)
gst_caps_set_simple (src_caps, "num-stripes", G_TYPE_INT, num_stripes,
"stripe_height", G_TYPE_INT, stripe_height, NULL);
if (gst_jpeg2000_parse_is_broadcast (capabilities) if (gst_jpeg2000_parse_is_broadcast (capabilities)
|| gst_jpeg2000_parse_is_imf (capabilities)) { || gst_jpeg2000_parse_is_imf (capabilities)) {
gst_caps_set_simple (src_caps, "main-level", G_TYPE_INT, main_level, gst_caps_set_simple (src_caps, "main-level", G_TYPE_INT, main_level,
@ -725,9 +752,9 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
} }
if (current_caps_struct) { if (current_caps_struct) {
gint caps_int = 0; const gchar *caps_string;
gboolean has_num_stripes = FALSE;
const gchar *caps_string = gst_structure_get_string caps_string = gst_structure_get_string
(current_caps_struct, "colorimetry"); (current_caps_struct, "colorimetry");
if (caps_string) { if (caps_string) {
gst_caps_set_simple (src_caps, "colorimetry", G_TYPE_STRING, gst_caps_set_simple (src_caps, "colorimetry", G_TYPE_STRING,
@ -757,45 +784,6 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
gst_caps_set_simple (src_caps, "chroma-site", G_TYPE_STRING, gst_caps_set_simple (src_caps, "chroma-site", G_TYPE_STRING,
caps_string, NULL); caps_string, NULL);
} }
caps_string = gst_structure_get_string (current_caps_struct, "alignment");
has_num_stripes =
gst_structure_get_int (current_caps_struct, "num-stripes", &caps_int);
if ((g_strcmp0 (caps_string, "stripe") == 0)
&& !has_num_stripes) {
GST_ERROR_OBJECT (jpeg2000parse,
"Alignment is set to stripe but num-stripes is missing");
ret = GST_FLOW_NOT_NEGOTIATED;
gst_caps_unref (src_caps);
goto beach;
}
/* if there is no alignment or number of strips in caps,
* we set alignment to default value : "frame"
*/
if (!caps_string && !has_num_stripes) {
gst_caps_set_simple (src_caps, "alignment", G_TYPE_STRING,
"frame", NULL);
} else {
if (caps_string) {
gst_caps_set_simple (src_caps, "alignment", G_TYPE_STRING,
caps_string, NULL);
}
if (has_num_stripes) {
gst_caps_set_simple (src_caps, "num-stripes", G_TYPE_INT,
caps_int, NULL);
/* remove PTS interpolation in the case of stripes having same PTS */
if (caps_int > 1)
gst_base_parse_set_pts_interpolation (GST_BASE_PARSE
(jpeg2000parse), FALSE);
/* lets deduce the alignment property */
if (!caps_string) {
GST_WARNING_OBJECT (jpeg2000parse,
"num-stripes is set but alignment is missing. We will deduce the correct value for \"alignment\"");
gst_caps_set_simple (src_caps, "alignment", G_TYPE_STRING,
caps_int > 1 ? "stripe" : "frame", NULL);
}
}
}
if (gst_structure_get_fraction (current_caps_struct, "framerate", &fr_num, if (gst_structure_get_fraction (current_caps_struct, "framerate", &fr_num,
&fr_denom)) { &fr_denom)) {
gst_caps_set_simple (src_caps, "framerate", GST_TYPE_FRACTION, fr_num, gst_caps_set_simple (src_caps, "framerate", GST_TYPE_FRACTION, fr_num,