summaryrefslogtreecommitdiffstats
path: root/gst/mxf
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2008-12-04 08:37:18 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2008-12-04 08:37:18 +0000
commit8201937c549034dc26dc289295a4ca0dfdceeb32 (patch)
tree5925f36690e4072dcf1d9f66ee244b0be00311aa /gst/mxf
parent7f61ced7e61ffe636e3a9a38ee2919a7ac9a43df (diff)
downloadgst-plugins-bad-8201937c549034dc26dc289295a4ca0dfdceeb32.tar.gz
gst-plugins-bad-8201937c549034dc26dc289295a4ca0dfdceeb32.tar.bz2
gst-plugins-bad-8201937c549034dc26dc289295a4ca0dfdceeb32.zip
gst/mxf/: Add support for SMPTE D10 essence (SMPTE 386M).
Original commit message from CVS: * gst/mxf/Makefile.am: * gst/mxf/mxfd10.c: (mxf_is_d10_essence_track), (mxf_d10_picture_handle_essence_element), (mxf_d10_sound_handle_essence_element), (mxf_d10_create_caps): * gst/mxf/mxfd10.h: * gst/mxf/mxfdemux.c: (gst_mxf_demux_handle_header_metadata_update_streams): Add support for SMPTE D10 essence (SMPTE 386M). * gst/mxf/mxfparse.c: (mxf_metadata_generic_picture_essence_descriptor_set_caps): Don't set width/height and PAR on the caps as those values are wrong for most files (height is sometimes the height of a field and aspect ratio is some random value). * gst/mxf/mxfaes-bwf.c: (mxf_bwf_create_caps), (mxf_aes3_create_caps): Fix calculation of block align if it isn't set in the descriptor.
Diffstat (limited to 'gst/mxf')
-rw-r--r--gst/mxf/Makefile.am4
-rw-r--r--gst/mxf/mxfaes-bwf.c12
-rw-r--r--gst/mxf/mxfd10.c229
-rw-r--r--gst/mxf/mxfd10.h36
-rw-r--r--gst/mxf/mxfdemux.c22
-rw-r--r--gst/mxf/mxfparse.c13
6 files changed, 305 insertions, 11 deletions
diff --git a/gst/mxf/Makefile.am b/gst/mxf/Makefile.am
index 40846ad1..4b164c07 100644
--- a/gst/mxf/Makefile.am
+++ b/gst/mxf/Makefile.am
@@ -8,7 +8,8 @@ libgstmxf_la_SOURCES = \
mxfmpeg.c \
mxfdv-dif.c \
mxfalaw.c \
- mxfjpeg2000.c
+ mxfjpeg2000.c \
+ mxfd10.c
libgstmxf_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS)
libgstmxf_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS)
@@ -22,5 +23,6 @@ noinst_HEADERS = \
mxfdv-dif.h \
mxfalaw.h \
mxfjpeg2000.h \
+ mxfd10.h \
mxftypes.h
diff --git a/gst/mxf/mxfaes-bwf.c b/gst/mxf/mxfaes-bwf.c
index ce4bbf51..a62d2703 100644
--- a/gst/mxf/mxfaes-bwf.c
+++ b/gst/mxf/mxfaes-bwf.c
@@ -570,7 +570,9 @@ mxf_bwf_create_caps (MXFMetadataGenericPackage * package,
if (wa_descriptor && wa_descriptor->block_align != 0)
block_align = wa_descriptor->block_align;
else
- block_align = GST_ROUND_UP_8 (descriptor->quantization_bits) / 8;
+ block_align =
+ (GST_ROUND_UP_8 (descriptor->quantization_bits) *
+ descriptor->channel_count) / 8;
ret = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT,
@@ -599,7 +601,9 @@ mxf_bwf_create_caps (MXFMetadataGenericPackage * package,
if (wa_descriptor && wa_descriptor->block_align != 0)
block_align = wa_descriptor->block_align;
else
- block_align = GST_ROUND_UP_8 (descriptor->quantization_bits) / 8;
+ block_align =
+ (GST_ROUND_UP_8 (descriptor->quantization_bits) *
+ descriptor->channel_count) / 8;
ret = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT,
@@ -679,7 +683,9 @@ mxf_aes3_create_caps (MXFMetadataGenericPackage * package,
if (wa_descriptor && wa_descriptor->block_align != 0)
block_align = wa_descriptor->block_align;
else
- block_align = GST_ROUND_UP_8 (descriptor->quantization_bits) / 8;
+ block_align =
+ (GST_ROUND_UP_8 (descriptor->quantization_bits) *
+ descriptor->channel_count) / 8;
ret = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT,
diff --git a/gst/mxf/mxfd10.c b/gst/mxf/mxfd10.c
new file mode 100644
index 00000000..75e74008
--- /dev/null
+++ b/gst/mxf/mxfd10.c
@@ -0,0 +1,229 @@
+/* GStreamer
+ * Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* Implementation of SMPTE 386M - Mapping Type-D10 essence data into the MXF
+ * Generic Container
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <string.h>
+
+#include "mxfd10.h"
+#include "mxfmpeg.h"
+#include "mxfaes-bwf.h"
+
+GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
+#define GST_CAT_DEFAULT mxf_debug
+
+gboolean
+mxf_is_d10_essence_track (const MXFMetadataTrack * track)
+{
+ guint i;
+
+ g_return_val_if_fail (track != NULL, FALSE);
+
+ if (track->descriptor == NULL)
+ return FALSE;
+
+ for (i = 0; i < track->n_descriptor; i++) {
+ MXFMetadataFileDescriptor *d = track->descriptor[i];
+ MXFUL *key = &d->essence_container;
+ /* SMPTE 386M 5.1 */
+ if (mxf_is_generic_container_essence_container_label (key) &&
+ key->u[12] == 0x02 && key->u[13] == 0x01 &&
+ (key->u[14] >= 0x01 && key->u[14] <= 0x06) &&
+ (key->u[15] == 0x01 || key->u[15] == 0x02))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static GstFlowReturn
+mxf_d10_picture_handle_essence_element (const MXFUL * key, GstBuffer * buffer,
+ GstCaps * caps, MXFMetadataGenericPackage * package,
+ MXFMetadataTrack * track, MXFMetadataStructuralComponent * component,
+ gpointer mapping_data, GstBuffer ** outbuf)
+{
+ *outbuf = buffer;
+
+ /* SMPTE 386M 5.2.1 */
+ if (key->u[12] != 0x05 || key->u[13] != 0x01 || key->u[14] != 0x01) {
+ GST_ERROR ("Invalid D10 picture essence element");
+ return GST_FLOW_ERROR;
+ }
+
+ return GST_FLOW_OK;
+}
+
+static GstFlowReturn
+mxf_d10_sound_handle_essence_element (const MXFUL * key, GstBuffer * buffer,
+ GstCaps * caps, MXFMetadataGenericPackage * package,
+ MXFMetadataTrack * track, MXFMetadataStructuralComponent * component,
+ gpointer mapping_data, GstBuffer ** outbuf)
+{
+ guint i, j, nsamples;
+ gint width, channels;
+ GstStructure *s = gst_caps_get_structure (caps, 0);
+ const guint8 *indata;
+ guint8 *outdata;
+
+ if (!gst_structure_get_int (s, "width", &width) ||
+ !gst_structure_get_int (s, "channels", &channels)) {
+ GST_ERROR ("Invalid caps");
+ return GST_FLOW_ERROR;
+ }
+
+ width /= 8;
+
+ /* SMPTE 386M 5.3.1 */
+ if (key->u[12] != 0x06 || key->u[13] != 0x01 || key->u[14] != 0x10) {
+ GST_ERROR ("Invalid D10 sound essence element");
+ return GST_FLOW_ERROR;
+ }
+
+ /* Now transform raw AES3 into raw audio, see SMPTE 331M */
+ if ((GST_BUFFER_SIZE (buffer) - 4) % 32 != 0) {
+ GST_ERROR ("Invalid D10 sound essence buffer size");
+ return GST_FLOW_ERROR;
+ }
+
+ nsamples = ((GST_BUFFER_SIZE (buffer) - 4) / 4) / 8;
+
+ *outbuf = gst_buffer_new_and_alloc (nsamples * width * channels);
+ gst_buffer_copy_metadata (*outbuf, buffer,
+ GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS |
+ GST_BUFFER_COPY_CAPS);
+
+ indata = GST_BUFFER_DATA (buffer);
+ outdata = GST_BUFFER_DATA (*outbuf);
+
+ for (i = 0; i < nsamples; i++) {
+ for (j = 0; j < channels; j++) {
+ guint32 in = GST_READ_UINT32_LE (indata);
+
+ if (width == 2) {
+ in = (in >> 12) & 0xffff;
+ GST_WRITE_UINT16_LE (outdata, in);
+ } else if (width == 3) {
+ in = (in >> 4) & 0xffffff;
+ GST_WRITE_UINT24_LE (outdata, in);
+ }
+ indata += 4;
+ outdata += width;
+ }
+ indata += 4 * (8 - channels);
+ }
+
+ gst_buffer_unref (buffer);
+
+ return GST_FLOW_OK;
+}
+
+GstCaps *
+mxf_d10_create_caps (MXFMetadataGenericPackage * package,
+ MXFMetadataTrack * track, GstTagList ** tags,
+ MXFEssenceElementHandler * handler, gpointer * mapping_data)
+{
+ MXFMetadataGenericPictureEssenceDescriptor *p = NULL;
+ MXFMetadataGenericSoundEssenceDescriptor *s = NULL;
+ guint i;
+ GstCaps *caps = NULL;
+
+ g_return_val_if_fail (package != NULL, NULL);
+ g_return_val_if_fail (track != NULL, NULL);
+
+ if (track->descriptor == NULL) {
+ GST_ERROR ("No descriptor found for this track");
+ return NULL;
+ }
+
+ for (i = 0; i < track->n_descriptor; i++) {
+ if (((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR ||
+ ((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_MPEG_VIDEO_DESCRIPTOR ||
+ ((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR) {
+ p = (MXFMetadataGenericPictureEssenceDescriptor *) track->descriptor[i];
+ break;
+ } else if (((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR ||
+ ((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_WAVE_AUDIO_ESSENCE_DESCRIPTOR ||
+ ((MXFMetadataGenericDescriptor *) track->descriptor[i])->type ==
+ MXF_METADATA_AES3_AUDIO_ESSENCE_DESCRIPTOR) {
+ s = (MXFMetadataGenericSoundEssenceDescriptor *) track->descriptor[i];
+ break;
+ }
+ }
+
+ if (!s && !p) {
+ GST_ERROR ("No descriptor found for this track");
+ return NULL;
+ }
+
+ if (!*tags)
+ *tags = gst_tag_list_new ();
+
+ if (s) {
+ if (s->channel_count == 0 ||
+ s->quantization_bits == 0 ||
+ s->audio_sampling_rate.n == 0 || s->audio_sampling_rate.d == 0) {
+ GST_ERROR ("Invalid descriptor");
+ return NULL;
+ }
+
+ if (s->quantization_bits != 16 && s->quantization_bits != 24) {
+ GST_ERROR ("Invalid width %u", s->quantization_bits);
+ return NULL;
+ }
+
+ /* FIXME: set channel layout */
+
+ caps = gst_caps_new_simple ("audio/x-raw-int",
+ "rate", G_TYPE_INT,
+ (gint) (((gdouble) s->audio_sampling_rate.n) /
+ ((gdouble) s->audio_sampling_rate.d) + 0.5), "channels",
+ G_TYPE_INT, s->channel_count, "signed", G_TYPE_BOOLEAN,
+ (s->quantization_bits != 8), "endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
+ "depth", G_TYPE_INT, s->quantization_bits, "width", G_TYPE_INT,
+ s->quantization_bits, NULL);
+
+ *handler = mxf_d10_sound_handle_essence_element;
+
+ gst_tag_list_add (*tags, GST_TAG_MERGE_APPEND, GST_TAG_VIDEO_CODEC,
+ "SMPTE D-10 Audio", NULL);
+ } else if (p) {
+ caps =
+ gst_caps_new_simple ("video/mpeg", "systemstream", G_TYPE_BOOLEAN,
+ FALSE, "mpegversion", G_TYPE_INT, 2, NULL);
+ mxf_metadata_generic_picture_essence_descriptor_set_caps (p, caps);
+
+ *handler = mxf_d10_picture_handle_essence_element;
+ gst_tag_list_add (*tags, GST_TAG_MERGE_APPEND, GST_TAG_VIDEO_CODEC,
+ "SMPTE D-10 Video", NULL);
+ }
+
+ return caps;
+}
diff --git a/gst/mxf/mxfd10.h b/gst/mxf/mxfd10.h
new file mode 100644
index 00000000..2fca77b8
--- /dev/null
+++ b/gst/mxf/mxfd10.h
@@ -0,0 +1,36 @@
+/* GStreamer
+ * Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* Implementation of SMPTE 386M - Mapping Type-D10 essence data into the MXF
+ * Generic Container
+ */
+
+#ifndef __MXF_D10_H__
+#define __MXF_D10_H__
+
+#include <gst/gst.h>
+
+#include "mxfparse.h"
+
+gboolean mxf_is_d10_essence_track (const MXFMetadataTrack *track);
+
+GstCaps *
+mxf_d10_create_caps (MXFMetadataGenericPackage *package, MXFMetadataTrack *track, GstTagList **tags, MXFEssenceElementHandler *handler, gpointer *mapping_data);
+
+#endif /* __MXF_D10_H__ */
diff --git a/gst/mxf/mxfdemux.c b/gst/mxf/mxfdemux.c
index 4b803148..e20ddf7b 100644
--- a/gst/mxf/mxfdemux.c
+++ b/gst/mxf/mxfdemux.c
@@ -36,6 +36,7 @@
#include "mxfdv-dif.h"
#include "mxfalaw.h"
#include "mxfjpeg2000.h"
+#include "mxfd10.h"
#include <string.h>
@@ -1346,9 +1347,8 @@ gst_mxf_demux_handle_header_metadata_resolve_references (GstMXFDemux * demux)
MXFMetadataEssenceContainerData, i);
for (j = 0; j < demux->content_storage.n_essence_container_data; j++) {
- if (mxf_ul_is_equal (&demux->
- content_storage.essence_container_data_uids[j],
- &data->instance_uid)) {
+ if (mxf_ul_is_equal (&demux->content_storage.
+ essence_container_data_uids[j], &data->instance_uid)) {
demux->content_storage.essence_container_data[j] = data;
break;
}
@@ -1907,6 +1907,10 @@ gst_mxf_demux_handle_header_metadata_update_streams (GstMXFDemux * demux)
caps =
mxf_jpeg2000_create_caps (source_package, source_track,
&pad->tags, &pad->handle_essence_element, &pad->mapping_data);
+ else if (mxf_is_d10_essence_track (source_track))
+ caps =
+ mxf_d10_create_caps (source_package, source_track,
+ &pad->tags, &pad->handle_essence_element, &pad->mapping_data);
break;
case MXF_METADATA_TRACK_SOUND_ESSENCE:
if (mxf_is_aes_bwf_essence_track (source_track))
@@ -1925,12 +1929,24 @@ gst_mxf_demux_handle_header_metadata_update_streams (GstMXFDemux * demux)
caps =
mxf_mpeg_create_caps (source_package, source_track,
&pad->tags, &pad->handle_essence_element, &pad->mapping_data);
+ else if (mxf_is_d10_essence_track (source_track))
+ caps =
+ mxf_d10_create_caps (source_package, source_track,
+ &pad->tags, &pad->handle_essence_element, &pad->mapping_data);
break;
case MXF_METADATA_TRACK_DATA_ESSENCE:
if (mxf_is_dv_dif_essence_track (source_track))
caps =
mxf_dv_dif_create_caps (source_package, source_track,
&pad->tags, &pad->handle_essence_element, &pad->mapping_data);
+ else if (mxf_is_mpeg_essence_track (source_track))
+ caps =
+ mxf_mpeg_create_caps (source_package, source_track,
+ &pad->tags, &pad->handle_essence_element, &pad->mapping_data);
+ else if (mxf_is_d10_essence_track (source_track))
+ caps =
+ mxf_d10_create_caps (source_package, source_track,
+ &pad->tags, &pad->handle_essence_element, &pad->mapping_data);
break;
default:
g_assert_not_reached ();
diff --git a/gst/mxf/mxfparse.c b/gst/mxf/mxfparse.c
index d88417cf..b1a87e04 100644
--- a/gst/mxf/mxfparse.c
+++ b/gst/mxf/mxfparse.c
@@ -2610,8 +2610,8 @@ void mxf_metadata_generic_picture_essence_descriptor_reset
void mxf_metadata_generic_picture_essence_descriptor_set_caps
(MXFMetadataGenericPictureEssenceDescriptor * descriptor, GstCaps * caps)
{
- guint par_n, par_d;
- guint width, height;
+ /*guint par_n, par_d;
+ guint width, height; */
MXFMetadataFileDescriptor *f = (MXFMetadataFileDescriptor *) descriptor;
g_return_if_fail (descriptor != NULL);
@@ -2620,6 +2620,10 @@ void mxf_metadata_generic_picture_essence_descriptor_set_caps
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, f->sample_rate.n,
f->sample_rate.d, NULL);
+ return;
+
+/* FIXME: This sets wrong values for most (all?) files */
+#if 0
width = descriptor->stored_width;
height = descriptor->stored_height;
@@ -2632,11 +2636,12 @@ void mxf_metadata_generic_picture_essence_descriptor_set_caps
if (descriptor->aspect_ratio.n == 0 || descriptor->aspect_ratio.d == 0)
return;
- par_n = height * descriptor->aspect_ratio.n;
- par_d = width * descriptor->aspect_ratio.d;
+ par_n = height * descriptor->aspect_ratio.d;
+ par_d = width * descriptor->aspect_ratio.n;
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
par_n, par_d, NULL);
+#endif
}
gboolean