249
mxf_metadata_mpeg_video_descriptor_write_tags (MXFMetadataBase * m,
250
MXFPrimerPack * primer)
252
MXFMetadataMPEGVideoDescriptor *self = MXF_METADATA_MPEG_VIDEO_DESCRIPTOR (m);
254
MXF_METADATA_BASE_CLASS
255
(mxf_metadata_mpeg_video_descriptor_parent_class)->write_tags (m, primer);
258
if (self->single_sequence != -1) {
259
t = g_slice_new0 (MXFLocalTag);
260
memcpy (&t->ul, &_single_sequence_ul, 16);
262
t->data = g_slice_alloc (t->size);
264
GST_WRITE_UINT8 (t->data, (self->single_sequence) ? 1 : 0);
265
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
266
ret = g_list_prepend (ret, t);
269
if (self->const_b_frames) {
270
t = g_slice_new0 (MXFLocalTag);
271
memcpy (&t->ul, &_constant_b_frames_ul, 16);
273
t->data = g_slice_alloc (t->size);
275
GST_WRITE_UINT8 (t->data, (self->const_b_frames) ? 1 : 0);
276
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
277
ret = g_list_prepend (ret, t);
280
if (self->coded_content_type) {
281
t = g_slice_new0 (MXFLocalTag);
282
memcpy (&t->ul, &_coded_content_type_ul, 16);
284
t->data = g_slice_alloc (t->size);
286
GST_WRITE_UINT8 (t->data, self->coded_content_type);
287
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
288
ret = g_list_prepend (ret, t);
291
if (self->low_delay) {
292
t = g_slice_new0 (MXFLocalTag);
293
memcpy (&t->ul, &_low_delay_ul, 16);
295
t->data = g_slice_alloc (t->size);
297
GST_WRITE_UINT8 (t->data, (self->low_delay) ? 1 : 0);
298
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
299
ret = g_list_prepend (ret, t);
302
if (self->closed_gop) {
303
t = g_slice_new0 (MXFLocalTag);
304
memcpy (&t->ul, &_closed_gop_ul, 16);
306
t->data = g_slice_alloc (t->size);
308
GST_WRITE_UINT8 (t->data, (self->closed_gop) ? 1 : 0);
309
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
310
ret = g_list_prepend (ret, t);
313
if (self->identical_gop) {
314
t = g_slice_new0 (MXFLocalTag);
315
memcpy (&t->ul, &_identical_gop_ul, 16);
317
t->data = g_slice_alloc (t->size);
319
GST_WRITE_UINT8 (t->data, (self->identical_gop) ? 1 : 0);
320
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
321
ret = g_list_prepend (ret, t);
325
t = g_slice_new0 (MXFLocalTag);
326
memcpy (&t->ul, &_identical_gop_ul, 16);
328
t->data = g_slice_alloc (t->size);
330
GST_WRITE_UINT16_BE (t->data, self->max_gop);
331
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
332
ret = g_list_prepend (ret, t);
335
if (self->b_picture_count) {
336
t = g_slice_new0 (MXFLocalTag);
337
memcpy (&t->ul, &_b_picture_count_ul, 16);
339
t->data = g_slice_alloc (t->size);
341
GST_WRITE_UINT16_BE (t->data, self->b_picture_count);
342
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
343
ret = g_list_prepend (ret, t);
347
t = g_slice_new0 (MXFLocalTag);
348
memcpy (&t->ul, &_bitrate_ul, 16);
350
t->data = g_slice_alloc (t->size);
352
GST_WRITE_UINT32_BE (t->data, self->bitrate);
353
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
354
ret = g_list_prepend (ret, t);
357
if (self->profile_and_level) {
358
t = g_slice_new0 (MXFLocalTag);
359
memcpy (&t->ul, &_profile_and_level_ul, 16);
361
t->data = g_slice_alloc (t->size);
363
GST_WRITE_UINT8 (t->data, self->profile_and_level);
364
mxf_primer_pack_add_mapping (primer, 0, &t->ul);
365
ret = g_list_prepend (ret, t);
247
372
mxf_metadata_mpeg_video_descriptor_init (MXFMetadataMPEGVideoDescriptor * self)
374
self->single_sequence = -1;
736
861
mxf_mpeg_create_caps
868
} MPEGAudioMappingData;
871
mxf_mpeg_audio_write_func (GstBuffer * buffer, GstCaps * caps,
872
gpointer mapping_data, GstAdapter * adapter, GstBuffer ** outbuf,
879
static const guint8 mpeg_essence_container_ul[] = {
880
0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x02,
881
0x0d, 0x01, 0x03, 0x01, 0x02, 0x04, 0x01, 0x01
884
static MXFMetadataFileDescriptor *
885
mxf_mpeg_audio_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
886
MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
888
MXFMetadataGenericSoundEssenceDescriptor *ret;
890
MPEGAudioMappingData *md = g_new0 (MPEGAudioMappingData, 1);
896
ret = (MXFMetadataGenericSoundEssenceDescriptor *)
897
gst_mini_object_new (MXF_TYPE_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR);
899
s = gst_caps_get_structure (caps, 0);
900
if (strcmp (gst_structure_get_name (s), "audio/mpeg") == 0) {
903
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
904
GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps);
905
gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
909
if (mpegversion == 1) {
911
gint mpegaudioversion = 0;
913
gst_structure_get_int (s, "layer", &layer);
914
gst_structure_get_int (s, "mpegaudioversion", &mpegaudioversion);
916
if (mpegaudioversion == 1 && layer == 1)
917
memcpy (&ret->sound_essence_compression,
918
&sound_essence_compression_mpeg1_layer1, 16);
919
else if (mpegaudioversion == 1 && layer == 2)
920
memcpy (&ret->sound_essence_compression,
921
&sound_essence_compression_mpeg1_layer12, 16);
922
else if (mpegaudioversion == 2 && layer == 1)
923
memcpy (&ret->sound_essence_compression,
924
&sound_essence_compression_mpeg2_layer1, 16);
928
else if (layer == 2 || mpegversion == 1)
931
md->spf = 576; /* MPEG-2 or 2.5 */
933
/* Otherwise all 0x00, must be some kind of mpeg1 audio */
934
} else if (mpegversion == 2) {
935
memcpy (&ret->sound_essence_compression, &sound_essence_compression_aac,
937
md->spf = 1024; /* FIXME: is this correct? */
939
} else if (strcmp (gst_structure_get_name (s), "audio/x-ac3") == 0) {
940
memcpy (&ret->sound_essence_compression, &sound_essence_compression_ac3,
942
md->spf = 256; /* FIXME: is this correct? */
944
g_assert_not_reached ();
947
if (!gst_structure_get_int (s, "rate", &rate)) {
948
GST_ERROR ("Invalid rate");
949
gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
954
memcpy (&ret->parent.essence_container, &mpeg_essence_container_ul, 16);
956
if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps)) {
957
gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
961
*handler = mxf_mpeg_audio_write_func;
963
return (MXFMetadataFileDescriptor *) ret;
967
mxf_mpeg_audio_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
968
gpointer mapping_data, GstBuffer * buf)
974
mxf_mpeg_audio_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps,
975
gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package,
976
MXFMetadataTimelineTrack * track, MXFFraction * edit_rate)
978
MPEGAudioMappingData *md = mapping_data;
980
edit_rate->n = md->rate;
981
edit_rate->d = md->spf;
985
mxf_mpeg_audio_get_track_number_template (MXFMetadataFileDescriptor * a,
986
GstCaps * caps, gpointer mapping_data)
988
return (0x16 << 24) | (0x05 << 8);
991
static MXFEssenceElementWriter mxf_mpeg_audio_essence_element_writer = {
992
mxf_mpeg_audio_get_descriptor,
993
mxf_mpeg_audio_update_descriptor,
994
mxf_mpeg_audio_get_edit_rate,
995
mxf_mpeg_audio_get_track_number_template,
1000
#define MPEG_AUDIO_CAPS \
1002
"mpegversion = (int) 1, " \
1003
"layer = (int) [ 1, 3 ], " \
1004
"rate = (int) [ 8000, 48000 ], " \
1005
"channels = (int) [ 1, 2 ], " \
1006
"parsed = (boolean) TRUE; " \
1008
"rate = (int) [ 4000, 96000 ], " \
1009
"channels = (int) [ 1, 6 ]; " \
1011
"mpegversion = (int) 2, " \
1012
"rate = (int) [ 8000, 96000 ], " \
1013
"channels = (int) [ 1, 8 ]"
1015
/* See ISO/IEC 13818-2 for MPEG ES format */
1017
mxf_mpeg_is_mpeg2_frame (GstBuffer * buffer)
1019
GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
1022
while (gst_byte_reader_get_remaining (&reader) > 3) {
1023
if (gst_byte_reader_peek_uint24_be (&reader, &tmp) && tmp == 0x000001) {
1026
/* Found sync code */
1027
gst_byte_reader_skip (&reader, 3);
1029
if (!gst_byte_reader_get_uint8 (&reader, &type))
1037
gst_byte_reader_skip (&reader, 1);
1045
mxf_mpeg_is_mpeg4_frame (GstBuffer * buffer)
1047
GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
1050
while (gst_byte_reader_get_remaining (&reader) > 3) {
1051
if (gst_byte_reader_peek_uint24_be (&reader, &tmp) && tmp == 0x000001) {
1054
/* Found sync code */
1055
gst_byte_reader_skip (&reader, 3);
1057
if (!gst_byte_reader_get_uint8 (&reader, &type))
1065
gst_byte_reader_skip (&reader, 1);
1072
static GstFlowReturn
1073
mxf_mpeg_video_write_func (GstBuffer * buffer, GstCaps * caps,
1074
gpointer mapping_data, GstAdapter * adapter, GstBuffer ** outbuf,
1077
MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_OTHER;
1080
type = *((MXFMPEGEssenceType *) mapping_data);
1082
if (type == MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2) {
1083
if (buffer && !mxf_mpeg_is_mpeg2_frame (buffer)) {
1084
gst_adapter_push (adapter, buffer);
1087
} else if (buffer || gst_adapter_available (adapter)) {
1088
guint av = gst_adapter_available (adapter);
1092
ret = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) + av);
1094
ret = gst_buffer_new_and_alloc (av);
1097
GstBuffer *tmp = gst_adapter_take_buffer (adapter, av);
1098
memcpy (GST_BUFFER_DATA (ret), GST_BUFFER_DATA (tmp), av);
1099
gst_buffer_unref (tmp);
1103
memcpy (GST_BUFFER_DATA (ret) + av, GST_BUFFER_DATA (buffer),
1104
GST_BUFFER_SIZE (buffer));
1105
gst_buffer_unref (buffer);
1110
} else if (type == MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG4) {
1111
if (buffer && !mxf_mpeg_is_mpeg4_frame (buffer)) {
1112
gst_adapter_push (adapter, buffer);
1115
} else if (buffer || gst_adapter_available (adapter)) {
1116
guint av = gst_adapter_available (adapter);
1120
ret = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) + av);
1122
ret = gst_buffer_new_and_alloc (av);
1125
GstBuffer *tmp = gst_adapter_take_buffer (adapter, av);
1126
memcpy (GST_BUFFER_DATA (ret), GST_BUFFER_DATA (tmp), av);
1127
gst_buffer_unref (tmp);
1131
memcpy (GST_BUFFER_DATA (ret) + av, GST_BUFFER_DATA (buffer),
1132
GST_BUFFER_SIZE (buffer));
1133
gst_buffer_unref (buffer);
1144
static const guint8 mpeg_video_picture_essence_compression_ul[] = {
1145
0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x00,
1146
0x04, 0x01, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00
1149
static MXFMetadataFileDescriptor *
1150
mxf_mpeg_video_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
1151
MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
1153
MXFMetadataMPEGVideoDescriptor *ret;
1156
ret = (MXFMetadataMPEGVideoDescriptor *)
1157
gst_mini_object_new (MXF_TYPE_METADATA_MPEG_VIDEO_DESCRIPTOR);
1159
s = gst_caps_get_structure (caps, 0);
1161
memcpy (&ret->parent.parent.parent.essence_container,
1162
&mpeg_essence_container_ul, 16);
1163
memcpy (&ret->parent.parent.picture_essence_coding,
1164
&mpeg_video_picture_essence_compression_ul, 16);
1165
if (strcmp (gst_structure_get_name (s), "video/mpeg") == 0) {
1168
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
1169
GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps);
1170
gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
1174
if (mpegversion == 1) {
1175
MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2;
1177
*mapping_data = g_new0 (MXFMPEGEssenceType, 1);
1178
memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
1179
ret->parent.parent.picture_essence_coding.u[13] = 0x10;
1180
} else if (mpegversion == 2) {
1181
MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2;
1183
*mapping_data = g_new0 (MXFMPEGEssenceType, 1);
1184
memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
1185
ret->parent.parent.picture_essence_coding.u[13] = 0x01;
1188
const GstBuffer *codec_data;
1189
MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG4;
1191
*mapping_data = g_new0 (MXFMPEGEssenceType, 1);
1192
memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
1194
ret->parent.parent.picture_essence_coding.u[13] = 0x20;
1195
if ((v = gst_structure_get_value (s, "codec_data"))) {
1196
MXFLocalTag *t = g_slice_new0 (MXFLocalTag);
1197
codec_data = gst_value_get_buffer (v);
1198
t->size = GST_BUFFER_SIZE (codec_data);
1199
t->data = g_memdup (GST_BUFFER_DATA (codec_data), t->size);
1200
memcpy (&t->ul, &sony_mpeg4_extradata, 16);
1201
mxf_local_tag_insert (t, &MXF_METADATA_BASE (ret)->other_tags);
1204
} else if (strcmp (gst_structure_get_name (s), "video/x-h264") == 0) {
1205
MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_AVC;
1207
*mapping_data = g_new0 (MXFMPEGEssenceType, 1);
1208
memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
1209
ret->parent.parent.picture_essence_coding.u[13] = 0x30;
1211
g_assert_not_reached ();
1215
if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->
1216
parent.parent, caps)) {
1217
gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
1221
*handler = mxf_mpeg_video_write_func;
1223
return (MXFMetadataFileDescriptor *) ret;
1227
mxf_mpeg_video_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
1228
gpointer mapping_data, GstBuffer * buf)
1234
mxf_mpeg_video_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps,
1235
gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package,
1236
MXFMetadataTimelineTrack * track, MXFFraction * edit_rate)
1238
(*edit_rate).n = a->sample_rate.n;
1239
(*edit_rate).d = a->sample_rate.d;
1243
mxf_mpeg_video_get_track_number_template (MXFMetadataFileDescriptor * a,
1244
GstCaps * caps, gpointer mapping_data)
1246
return (0x15 << 24) | (0x05 << 8);
1249
static MXFEssenceElementWriter mxf_mpeg_video_essence_element_writer = {
1250
mxf_mpeg_video_get_descriptor,
1251
mxf_mpeg_video_update_descriptor,
1252
mxf_mpeg_video_get_edit_rate,
1253
mxf_mpeg_video_get_track_number_template,
1258
#define MPEG_VIDEO_CAPS \
1260
"mpegversion = (int) { 1, 2, 4 }, " \
1261
"systemstream = (boolean) FALSE, " \
1262
"width = " GST_VIDEO_SIZE_RANGE ", " \
1263
"height = " GST_VIDEO_SIZE_RANGE ", " \
1264
"framerate = " GST_VIDEO_FPS_RANGE "; " \
1266
"width = " GST_VIDEO_SIZE_RANGE ", " \
1267
"height = " GST_VIDEO_SIZE_RANGE ", " \
1268
"framerate = " GST_VIDEO_FPS_RANGE
740
1271
mxf_mpeg_init (void)
742
1273
mxf_metadata_register (MXF_TYPE_METADATA_MPEG_VIDEO_DESCRIPTOR);
743
1274
mxf_essence_element_handler_register (&mxf_mpeg_essence_element_handler);
1276
mxf_mpeg_audio_essence_element_writer.pad_template =
1277
gst_pad_template_new ("mpeg_audio_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
1278
gst_caps_from_string (MPEG_AUDIO_CAPS));
1279
memcpy (&mxf_mpeg_audio_essence_element_writer.data_definition,
1280
mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_SOUND_ESSENCE), 16);
1281
mxf_essence_element_writer_register (&mxf_mpeg_audio_essence_element_writer);
1283
mxf_mpeg_video_essence_element_writer.pad_template =
1284
gst_pad_template_new ("mpeg_video_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
1285
gst_caps_from_string (MPEG_VIDEO_CAPS));
1286
memcpy (&mxf_mpeg_video_essence_element_writer.data_definition,
1287
mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
1289
mxf_essence_element_writer_register (&mxf_mpeg_video_essence_element_writer);