From 654f0627e4874ec9f010ab7e2d523bd2a3f3fba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 11 Mar 2009 19:34:12 +0100 Subject: mxfmux: Add support for muxing JPEG2000 code streams --- gst/mxf/mxfjpeg2000.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'gst/mxf/mxfjpeg2000.c') diff --git a/gst/mxf/mxfjpeg2000.c b/gst/mxf/mxfjpeg2000.c index c9d7b2aa..9ff13f70 100644 --- a/gst/mxf/mxfjpeg2000.c +++ b/gst/mxf/mxfjpeg2000.c @@ -31,9 +31,11 @@ #endif #include +#include #include #include "mxfjpeg2000.h" +#include "mxfwrite.h" GST_DEBUG_CATEGORY_EXTERN (mxf_debug); #define GST_CAT_DEFAULT mxf_debug @@ -202,8 +204,123 @@ static const MXFEssenceElementHandler mxf_jpeg2000_essence_element_handler = { mxf_jpeg2000_create_caps }; +static GstFlowReturn +mxf_jpeg2000_write_func (GstBuffer * buffer, GstCaps * caps, + gpointer mapping_data, GstAdapter * adapter, GstBuffer ** outbuf, + gboolean flush) +{ + *outbuf = buffer; + return GST_FLOW_OK; +} + +static const guint8 jpeg2000_essence_container_ul[] = { + 0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x07, + 0x0d, 0x01, 0x03, 0x01, 0x02, 0x0c, 0x01, 0x00 +}; + +static const guint jpeg2000_picture_essence_coding[] = { + 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x07, + 0x04, 0x01, 0x02, 0x02, 0x03, 0x01, 0x01, 0x00 +}; + +static MXFMetadataFileDescriptor * +mxf_jpeg2000_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, + MXFEssenceElementWriteFunc * handler, gpointer * mapping_data) +{ + MXFMetadataRGBAPictureEssenceDescriptor *ret; + GstStructure *s; + guint32 fourcc; + + s = gst_caps_get_structure (caps, 0); + if (strcmp (gst_structure_get_name (s), "image/x-jpc") != 0) + return NULL; + + if (!gst_structure_get_fourcc (s, "fourcc", &fourcc)) + return NULL; + + ret = (MXFMetadataRGBAPictureEssenceDescriptor *) + gst_mini_object_new (MXF_TYPE_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR); + + memcpy (&ret->parent.parent.essence_container, &jpeg2000_essence_container_ul, + 16); + memcpy (&ret->parent.picture_essence_coding, &jpeg2000_picture_essence_coding, + 16); + + if (fourcc == GST_MAKE_FOURCC ('s', 'R', 'G', 'B')) { + ret->n_pixel_layout = 3; + ret->pixel_layout = g_new0 (guint8, 6); + ret->pixel_layout[0] = 'R'; + ret->pixel_layout[1] = 8; + ret->pixel_layout[2] = 'G'; + ret->pixel_layout[3] = 8; + ret->pixel_layout[4] = 'B'; + ret->pixel_layout[5] = 8; + } else if (fourcc == GST_MAKE_FOURCC ('s', 'Y', 'U', 'V')) { + ret->n_pixel_layout = 3; + ret->pixel_layout = g_new0 (guint8, 6); + ret->pixel_layout[0] = 'Y'; + ret->pixel_layout[1] = 8; + ret->pixel_layout[2] = 'U'; + ret->pixel_layout[3] = 8; + ret->pixel_layout[4] = 'V'; + ret->pixel_layout[5] = 8; + } else { + g_assert_not_reached (); + } + + mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps); + *handler = mxf_jpeg2000_write_func; + + return (MXFMetadataFileDescriptor *) ret; +} + +static void +mxf_jpeg2000_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps, + gpointer mapping_data, GstBuffer * buf) +{ + return; +} + +static void +mxf_jpeg2000_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps, + gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package, + MXFMetadataTimelineTrack * track, MXFFraction * edit_rate) +{ + (*edit_rate).n = a->sample_rate.n; + (*edit_rate).d = a->sample_rate.d; +} + +static guint32 +mxf_jpeg2000_get_track_number_template (MXFMetadataFileDescriptor * a, + GstCaps * caps, gpointer mapping_data) +{ + return (0x15 << 24) | (0x08 << 8); +} + +static MXFEssenceElementWriter mxf_jpeg2000_essence_element_writer = { + mxf_jpeg2000_get_descriptor, + mxf_jpeg2000_update_descriptor, + mxf_jpeg2000_get_edit_rate, + mxf_jpeg2000_get_track_number_template, + NULL, + {{0,}} +}; + void mxf_jpeg2000_init (void) { mxf_essence_element_handler_register (&mxf_jpeg2000_essence_element_handler); + + mxf_jpeg2000_essence_element_writer.pad_template = + gst_pad_template_new ("jpeg2000_video_sink_%u", GST_PAD_SINK, + GST_PAD_REQUEST, + gst_caps_from_string ("image/x-jpc, fields = 1, width = " + GST_VIDEO_SIZE_RANGE ", height = " GST_VIDEO_SIZE_RANGE + ", framerate = " GST_VIDEO_FPS_RANGE + ", fourcc = (GstFourcc) { sRGB, sYUV }")); + memcpy (&mxf_jpeg2000_essence_element_writer.data_definition, + mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE), + 16); + mxf_essence_element_writer_register (&mxf_jpeg2000_essence_element_writer); } -- cgit v1.2.1 From effb5786da04e28effadc0602ef1ec5465458801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 22 Mar 2009 15:51:37 +0100 Subject: mxfmux: Fix some memory leaks, improve debugging and handle errors better --- gst/mxf/mxfjpeg2000.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gst/mxf/mxfjpeg2000.c') diff --git a/gst/mxf/mxfjpeg2000.c b/gst/mxf/mxfjpeg2000.c index 9ff13f70..1f76d76a 100644 --- a/gst/mxf/mxfjpeg2000.c +++ b/gst/mxf/mxfjpeg2000.c @@ -232,11 +232,11 @@ mxf_jpeg2000_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, guint32 fourcc; s = gst_caps_get_structure (caps, 0); - if (strcmp (gst_structure_get_name (s), "image/x-jpc") != 0) - return NULL; - - if (!gst_structure_get_fourcc (s, "fourcc", &fourcc)) + if (strcmp (gst_structure_get_name (s), "image/x-jpc") != 0 || + !gst_structure_get_fourcc (s, "fourcc", &fourcc)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); return NULL; + } ret = (MXFMetadataRGBAPictureEssenceDescriptor *) gst_mini_object_new (MXF_TYPE_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR); @@ -268,8 +268,12 @@ mxf_jpeg2000_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, g_assert_not_reached (); } - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_jpeg2000_write_func; return (MXFMetadataFileDescriptor *) ret; -- cgit v1.2.1 From e5caf2eddadd6746fac36a46444358b68d8dfa98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 26 Mar 2009 08:12:02 +0100 Subject: mxfmux: Cleanup --- gst/mxf/mxfjpeg2000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gst/mxf/mxfjpeg2000.c') diff --git a/gst/mxf/mxfjpeg2000.c b/gst/mxf/mxfjpeg2000.c index 1f76d76a..9d949d4e 100644 --- a/gst/mxf/mxfjpeg2000.c +++ b/gst/mxf/mxfjpeg2000.c @@ -291,8 +291,8 @@ mxf_jpeg2000_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps, gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package, MXFMetadataTimelineTrack * track, MXFFraction * edit_rate) { - (*edit_rate).n = a->sample_rate.n; - (*edit_rate).d = a->sample_rate.d; + edit_rate->n = a->sample_rate.n; + edit_rate->d = a->sample_rate.d; } static guint32 -- cgit v1.2.1