mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-08 18:39:54 +00:00
bc93b81dd5
Original commit message from CVS: * gst/mxf/Makefile.am: * gst/mxf/mxf.c: (plugin_init): * gst/mxf/mxfaes-bwf.c: (mxf_metadata_wave_audio_essence_descriptor_handle_tag), (mxf_metadata_wave_audio_essence_descriptor_init), (mxf_metadata_wave_audio_essence_descriptor_class_init), (mxf_metadata_aes3_audio_essence_descriptor_finalize), (mxf_metadata_aes3_audio_essence_descriptor_handle_tag), (mxf_metadata_aes3_audio_essence_descriptor_init), (mxf_metadata_aes3_audio_essence_descriptor_class_init), (mxf_is_aes_bwf_essence_track), (mxf_bwf_create_caps), (mxf_aes3_create_caps), (mxf_aes_bwf_create_caps), (mxf_aes_bwf_init): * gst/mxf/mxfaes-bwf.h: * gst/mxf/mxfalaw.c: (mxf_is_alaw_essence_track), (mxf_alaw_create_caps), (mxf_alaw_init): * gst/mxf/mxfalaw.h: * gst/mxf/mxfd10.c: (mxf_is_d10_essence_track), (mxf_d10_create_caps), (mxf_d10_init): * gst/mxf/mxfd10.h: * gst/mxf/mxfdemux.c: (gst_mxf_demux_reset_metadata), (gst_mxf_demux_handle_header_metadata_resolve_references), (gst_mxf_demux_find_package), (gst_mxf_demux_choose_package), (gst_mxf_demux_handle_header_metadata_update_streams), (gst_mxf_demux_handle_metadata), (gst_mxf_demux_handle_generic_container_essence_element), (gst_mxf_demux_handle_klv_packet), (gst_mxf_demux_src_query): * gst/mxf/mxfdemux.h: * gst/mxf/mxfdv-dif.c: (mxf_is_dv_dif_essence_track), (mxf_dv_dif_create_caps), (mxf_dv_dif_init): * gst/mxf/mxfdv-dif.h: * gst/mxf/mxfjpeg2000.c: (mxf_is_jpeg2000_essence_track), (mxf_jpeg2000_create_caps), (mxf_jpeg2000_init): * gst/mxf/mxfjpeg2000.h: * gst/mxf/mxfmetadata.c: (mxf_metadata_base_finalize), (mxf_metadata_base_handle_tag), (mxf_metadata_base_resolve), (mxf_metadata_base_init), (mxf_metadata_base_class_init), (mxf_metadata_parse), (mxf_metadata_resolve), (mxf_metadata_handle_tag), (mxf_metadata_class_init), (mxf_metadata_init), (mxf_metadata_init_types), (mxf_metadata_register), (mxf_metadata_new), (mxf_metadata_preface_finalize), (mxf_metadata_preface_handle_tag), (mxf_metadata_preface_resolve), (mxf_metadata_preface_init), (mxf_metadata_preface_class_init), (mxf_metadata_identification_finalize), (mxf_metadata_identification_handle_tag), (mxf_metadata_identification_init), (mxf_metadata_identification_class_init), (mxf_metadata_content_storage_finalize), (mxf_metadata_content_storage_handle_tag), (mxf_metadata_content_storage_resolve), (mxf_metadata_content_storage_init), (mxf_metadata_content_storage_class_init), (mxf_metadata_essence_container_data_handle_tag), (mxf_metadata_essence_container_data_resolve), (mxf_metadata_essence_container_data_init), (mxf_metadata_essence_container_data_class_init), (mxf_metadata_generic_package_finalize), (mxf_metadata_generic_package_handle_tag), (mxf_metadata_generic_package_resolve), (mxf_metadata_generic_package_init), (mxf_metadata_generic_package_class_init), (mxf_metadata_material_package_resolve), (mxf_metadata_material_package_init), (mxf_metadata_material_package_class_init), (mxf_metadata_source_package_finalize), (mxf_metadata_source_package_handle_tag), (mxf_metadata_source_package_resolve), (mxf_metadata_source_package_init), (mxf_metadata_source_package_class_init), (mxf_metadata_track_finalize), (mxf_metadata_track_handle_tag), (mxf_metadata_track_resolve), (mxf_metadata_track_init), (mxf_metadata_track_class_init), (mxf_metadata_track_identifier_parse), (mxf_metadata_timeline_track_handle_tag), (mxf_metadata_timeline_track_init), (mxf_metadata_timeline_track_class_init), (mxf_metadata_event_track_handle_tag), (mxf_metadata_event_track_init), (mxf_metadata_event_track_class_init), (mxf_metadata_static_track_init), (mxf_metadata_static_track_class_init), (mxf_metadata_sequence_finalize), (mxf_metadata_sequence_handle_tag), (mxf_metadata_sequence_resolve), (mxf_metadata_sequence_init), (mxf_metadata_sequence_class_init), (mxf_metadata_structural_component_handle_tag), (mxf_metadata_structural_component_init), (mxf_metadata_structural_component_class_init), (mxf_metadata_timecode_component_handle_tag), (mxf_metadata_timecode_component_init), (mxf_metadata_timecode_component_class_init), (mxf_metadata_source_clip_handle_tag), (mxf_metadata_source_clip_resolve), (mxf_metadata_source_clip_init), (mxf_metadata_source_clip_class_init), (mxf_metadata_dm_source_clip_finalize), (mxf_metadata_dm_source_clip_handle_tag), (mxf_metadata_dm_source_clip_init), (mxf_metadata_dm_source_clip_class_init), (mxf_metadata_dm_segment_finalize), (mxf_metadata_dm_segment_handle_tag), (mxf_metadata_dm_segment_resolve), (mxf_metadata_dm_segment_init), (mxf_metadata_dm_segment_class_init), (mxf_metadata_generic_descriptor_finalize), (mxf_metadata_generic_descriptor_handle_tag), (mxf_metadata_generic_descriptor_resolve), (mxf_metadata_generic_descriptor_init), (mxf_metadata_generic_descriptor_class_init), (mxf_metadata_file_descriptor_handle_tag), (mxf_metadata_file_descriptor_init), (mxf_metadata_file_descriptor_class_init), (mxf_metadata_generic_picture_essence_descriptor_handle_tag), (mxf_metadata_generic_picture_essence_descriptor_init), (mxf_metadata_generic_picture_essence_descriptor_class_init), (mxf_metadata_generic_picture_essence_descriptor_set_caps), (mxf_metadata_generic_sound_essence_descriptor_handle_tag), (mxf_metadata_generic_sound_essence_descriptor_init), (mxf_metadata_generic_sound_essence_descriptor_class_init), (mxf_metadata_cdci_picture_essence_descriptor_handle_tag), (mxf_metadata_cdci_picture_essence_descriptor_init), (mxf_metadata_cdci_picture_essence_descriptor_class_init), (mxf_metadata_rgba_picture_essence_descriptor_finalize), (mxf_metadata_rgba_picture_essence_descriptor_handle_tag), (mxf_metadata_rgba_picture_essence_descriptor_init), (mxf_metadata_rgba_picture_essence_descriptor_class_init), (mxf_metadata_generic_data_essence_descriptor_handle_tag), (mxf_metadata_generic_data_essence_descriptor_init), (mxf_metadata_generic_data_essence_descriptor_class_init), (mxf_metadata_multiple_descriptor_finalize), (mxf_metadata_multiple_descriptor_handle_tag), (mxf_metadata_multiple_descriptor_resolve), (mxf_metadata_multiple_descriptor_init), (mxf_metadata_multiple_descriptor_class_init), (mxf_metadata_locator_init), (mxf_metadata_locator_class_init), (mxf_metadata_text_locator_finalize), (mxf_metadata_text_locator_handle_tag), (mxf_metadata_text_locator_init), (mxf_metadata_text_locator_class_init), (mxf_metadata_network_locator_finalize), (mxf_metadata_network_locator_handle_tag), (mxf_metadata_network_locator_init), (mxf_metadata_network_locator_class_init): * gst/mxf/mxfmetadata.h: * gst/mxf/mxfmpeg.c: (mxf_metadata_mpeg_video_descriptor_handle_tag), (mxf_metadata_mpeg_video_descriptor_init), (mxf_metadata_mpeg_video_descriptor_class_init), (mxf_is_mpeg_essence_track), (mxf_mpeg_es_create_caps), (mxf_mpeg_create_caps), (mxf_mpeg_init): * gst/mxf/mxfmpeg.h: * gst/mxf/mxfparse.c: (mxf_index_table_segment_parse), (mxf_local_tag_add_to_hash_table): * gst/mxf/mxfparse.h: * gst/mxf/mxftypes.h: * gst/mxf/mxfup.c: (mxf_is_up_essence_track), (mxf_up_create_caps), (mxf_up_init): * gst/mxf/mxfup.h: Convert the structural metadata to GstMiniObjects to make a lot of code easier and to make everything better extensible. Add a "registry" for metadata handlers to improve extensibility even more and to remove metadata type specifics from mxfdemux. Clean up a lot of parts and add some more NULL checks.
249 lines
7.1 KiB
C
249 lines
7.1 KiB
C
/* 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
|
|
|
|
typedef struct
|
|
{
|
|
guint width, channels;
|
|
} MXFD10AudioMappingData;
|
|
|
|
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;
|
|
|
|
if (!d)
|
|
continue;
|
|
|
|
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;
|
|
const guint8 *indata;
|
|
guint8 *outdata;
|
|
MXFD10AudioMappingData *data = mapping_data;
|
|
|
|
g_return_val_if_fail (data != NULL, GST_FLOW_ERROR);
|
|
g_return_val_if_fail (data->channels != 0
|
|
&& data->width != 0, GST_FLOW_ERROR);
|
|
|
|
/* 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 * data->width * data->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);
|
|
|
|
/* Skip 32 bit header */
|
|
indata += 4;
|
|
|
|
for (i = 0; i < nsamples; i++) {
|
|
for (j = 0; j < data->channels; j++) {
|
|
guint32 in = GST_READ_UINT32_LE (indata);
|
|
|
|
/* Remove first 4 and last 4 bits as they only
|
|
* contain status data. Shift the 24 bit samples
|
|
* to the correct width afterwards. */
|
|
if (data->width == 2) {
|
|
in = (in >> 12) & 0xffff;
|
|
GST_WRITE_UINT16_LE (outdata, in);
|
|
} else if (data->width == 3) {
|
|
in = (in >> 4) & 0xffffff;
|
|
GST_WRITE_UINT24_LE (outdata, in);
|
|
}
|
|
indata += 4;
|
|
outdata += data->width;
|
|
}
|
|
/* There are always 8 channels but only the first
|
|
* ones contain valid data, skip the others */
|
|
indata += 4 * (8 - data->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 (!track->descriptor[i])
|
|
continue;
|
|
|
|
if (MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (track->
|
|
descriptor[i])) {
|
|
p = (MXFMetadataGenericPictureEssenceDescriptor *) track->descriptor[i];
|
|
break;
|
|
} else if (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (track->
|
|
descriptor[i])) {
|
|
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) {
|
|
MXFD10AudioMappingData *data;
|
|
|
|
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;
|
|
|
|
data = g_new0 (MXFD10AudioMappingData, 1);
|
|
data->width = s->quantization_bits / 8;
|
|
data->channels = s->channel_count;
|
|
*mapping_data = data;
|
|
|
|
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;
|
|
}
|
|
|
|
void
|
|
mxf_d10_init (void)
|
|
{
|
|
}
|