~ubuntu-branches/ubuntu/precise/gst-plugins-bad0.10/precise-proposed

« back to all changes in this revision

Viewing changes to gst/mxf/mxfmpeg.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-05-12 09:51:24 UTC
  • mto: (18.3.2 experimental) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20090512095124-ugy051q0n88kk9f8
Tags: upstream-0.10.11.2
Import upstream version 0.10.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#endif
34
34
 
35
35
#include <gst/gst.h>
 
36
#include <gst/video/video.h>
36
37
#include <string.h>
37
38
 
38
39
#include "mxfmpeg.h"
39
40
#include "mxfquark.h"
 
41
#include "mxfessence.h"
40
42
 
41
43
#include <gst/base/gstbytereader.h>
42
44
 
243
245
  return ret;
244
246
}
245
247
 
 
248
static GList *
 
249
mxf_metadata_mpeg_video_descriptor_write_tags (MXFMetadataBase * m,
 
250
    MXFPrimerPack * primer)
 
251
{
 
252
  MXFMetadataMPEGVideoDescriptor *self = MXF_METADATA_MPEG_VIDEO_DESCRIPTOR (m);
 
253
  GList *ret =
 
254
      MXF_METADATA_BASE_CLASS
 
255
      (mxf_metadata_mpeg_video_descriptor_parent_class)->write_tags (m, primer);
 
256
  MXFLocalTag *t;
 
257
 
 
258
  if (self->single_sequence != -1) {
 
259
    t = g_slice_new0 (MXFLocalTag);
 
260
    memcpy (&t->ul, &_single_sequence_ul, 16);
 
261
    t->size = 1;
 
262
    t->data = g_slice_alloc (t->size);
 
263
    t->g_slice = TRUE;
 
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);
 
267
  }
 
268
 
 
269
  if (self->const_b_frames) {
 
270
    t = g_slice_new0 (MXFLocalTag);
 
271
    memcpy (&t->ul, &_constant_b_frames_ul, 16);
 
272
    t->size = 1;
 
273
    t->data = g_slice_alloc (t->size);
 
274
    t->g_slice = TRUE;
 
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);
 
278
  }
 
279
 
 
280
  if (self->coded_content_type) {
 
281
    t = g_slice_new0 (MXFLocalTag);
 
282
    memcpy (&t->ul, &_coded_content_type_ul, 16);
 
283
    t->size = 1;
 
284
    t->data = g_slice_alloc (t->size);
 
285
    t->g_slice = TRUE;
 
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);
 
289
  }
 
290
 
 
291
  if (self->low_delay) {
 
292
    t = g_slice_new0 (MXFLocalTag);
 
293
    memcpy (&t->ul, &_low_delay_ul, 16);
 
294
    t->size = 1;
 
295
    t->data = g_slice_alloc (t->size);
 
296
    t->g_slice = TRUE;
 
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);
 
300
  }
 
301
 
 
302
  if (self->closed_gop) {
 
303
    t = g_slice_new0 (MXFLocalTag);
 
304
    memcpy (&t->ul, &_closed_gop_ul, 16);
 
305
    t->size = 1;
 
306
    t->data = g_slice_alloc (t->size);
 
307
    t->g_slice = TRUE;
 
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);
 
311
  }
 
312
 
 
313
  if (self->identical_gop) {
 
314
    t = g_slice_new0 (MXFLocalTag);
 
315
    memcpy (&t->ul, &_identical_gop_ul, 16);
 
316
    t->size = 1;
 
317
    t->data = g_slice_alloc (t->size);
 
318
    t->g_slice = TRUE;
 
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);
 
322
  }
 
323
 
 
324
  if (self->max_gop) {
 
325
    t = g_slice_new0 (MXFLocalTag);
 
326
    memcpy (&t->ul, &_identical_gop_ul, 16);
 
327
    t->size = 2;
 
328
    t->data = g_slice_alloc (t->size);
 
329
    t->g_slice = TRUE;
 
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);
 
333
  }
 
334
 
 
335
  if (self->b_picture_count) {
 
336
    t = g_slice_new0 (MXFLocalTag);
 
337
    memcpy (&t->ul, &_b_picture_count_ul, 16);
 
338
    t->size = 2;
 
339
    t->data = g_slice_alloc (t->size);
 
340
    t->g_slice = TRUE;
 
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);
 
344
  }
 
345
 
 
346
  if (self->bitrate) {
 
347
    t = g_slice_new0 (MXFLocalTag);
 
348
    memcpy (&t->ul, &_bitrate_ul, 16);
 
349
    t->size = 4;
 
350
    t->data = g_slice_alloc (t->size);
 
351
    t->g_slice = TRUE;
 
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);
 
355
  }
 
356
 
 
357
  if (self->profile_and_level) {
 
358
    t = g_slice_new0 (MXFLocalTag);
 
359
    memcpy (&t->ul, &_profile_and_level_ul, 16);
 
360
    t->size = 1;
 
361
    t->data = g_slice_alloc (t->size);
 
362
    t->g_slice = TRUE;
 
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);
 
366
  }
 
367
 
 
368
  return ret;
 
369
}
 
370
 
246
371
static void
247
372
mxf_metadata_mpeg_video_descriptor_init (MXFMetadataMPEGVideoDescriptor * self)
248
373
{
249
 
 
 
374
  self->single_sequence = -1;
250
375
}
251
376
 
252
377
static void
261
386
  metadata_base_class->name_quark = MXF_QUARK (MPEG_VIDEO_DESCRIPTOR);
262
387
  metadata_base_class->to_structure =
263
388
      mxf_metadata_mpeg_video_descriptor_to_structure;
 
389
  metadata_base_class->write_tags =
 
390
      mxf_metadata_mpeg_video_descriptor_write_tags;
264
391
 
265
392
  metadata_class->type = 0x0151;
266
393
}
380
507
    }
381
508
  }
382
509
 
383
 
  g_assert_not_reached ();
384
 
 
385
510
  return FALSE;
386
511
}
387
512
 
577
702
      codec_name = "MPEG-1 Audio";
578
703
    } else if (mxf_ul_is_equal (&s->sound_essence_compression,
579
704
            &sound_essence_compression_ac3)) {
580
 
      caps = gst_caps_new_simple ("audio/ac3", NULL);
 
705
      caps = gst_caps_new_simple ("audio/x-ac3", NULL);
581
706
      codec_name = "AC3 Audio";
582
707
    } else if (mxf_ul_is_equal (&s->sound_essence_compression,
583
708
            &sound_essence_compression_mpeg1_layer1)) {
736
861
  mxf_mpeg_create_caps
737
862
};
738
863
 
 
864
typedef struct
 
865
{
 
866
  guint spf;
 
867
  guint rate;
 
868
} MPEGAudioMappingData;
 
869
 
 
870
static GstFlowReturn
 
871
mxf_mpeg_audio_write_func (GstBuffer * buffer, GstCaps * caps,
 
872
    gpointer mapping_data, GstAdapter * adapter, GstBuffer ** outbuf,
 
873
    gboolean flush)
 
874
{
 
875
  *outbuf = buffer;
 
876
  return GST_FLOW_OK;
 
877
}
 
878
 
 
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
 
882
};
 
883
 
 
884
static MXFMetadataFileDescriptor *
 
885
mxf_mpeg_audio_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
 
886
    MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
 
887
{
 
888
  MXFMetadataGenericSoundEssenceDescriptor *ret;
 
889
  GstStructure *s;
 
890
  MPEGAudioMappingData *md = g_new0 (MPEGAudioMappingData, 1);
 
891
  gint rate;
 
892
 
 
893
  md->spf = -1;
 
894
  *mapping_data = md;
 
895
 
 
896
  ret = (MXFMetadataGenericSoundEssenceDescriptor *)
 
897
      gst_mini_object_new (MXF_TYPE_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR);
 
898
 
 
899
  s = gst_caps_get_structure (caps, 0);
 
900
  if (strcmp (gst_structure_get_name (s), "audio/mpeg") == 0) {
 
901
    gint mpegversion;
 
902
 
 
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));
 
906
      return NULL;
 
907
    }
 
908
 
 
909
    if (mpegversion == 1) {
 
910
      gint layer = 0;
 
911
      gint mpegaudioversion = 0;
 
912
 
 
913
      gst_structure_get_int (s, "layer", &layer);
 
914
      gst_structure_get_int (s, "mpegaudioversion", &mpegaudioversion);
 
915
 
 
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);
 
925
 
 
926
      if (layer == 1)
 
927
        md->spf = 384;
 
928
      else if (layer == 2 || mpegversion == 1)
 
929
        md->spf = 1152;
 
930
      else
 
931
        md->spf = 576;          /* MPEG-2 or 2.5 */
 
932
 
 
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,
 
936
          16);
 
937
      md->spf = 1024;           /* FIXME: is this correct? */
 
938
    }
 
939
  } else if (strcmp (gst_structure_get_name (s), "audio/x-ac3") == 0) {
 
940
    memcpy (&ret->sound_essence_compression, &sound_essence_compression_ac3,
 
941
        16);
 
942
    md->spf = 256;              /* FIXME: is this correct? */
 
943
  } else {
 
944
    g_assert_not_reached ();
 
945
  }
 
946
 
 
947
  if (!gst_structure_get_int (s, "rate", &rate)) {
 
948
    GST_ERROR ("Invalid rate");
 
949
    gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
 
950
    return NULL;
 
951
  }
 
952
  md->rate = rate;
 
953
 
 
954
  memcpy (&ret->parent.essence_container, &mpeg_essence_container_ul, 16);
 
955
 
 
956
  if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps)) {
 
957
    gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
 
958
    return NULL;
 
959
  }
 
960
 
 
961
  *handler = mxf_mpeg_audio_write_func;
 
962
 
 
963
  return (MXFMetadataFileDescriptor *) ret;
 
964
}
 
965
 
 
966
static void
 
967
mxf_mpeg_audio_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
 
968
    gpointer mapping_data, GstBuffer * buf)
 
969
{
 
970
  return;
 
971
}
 
972
 
 
973
static void
 
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)
 
977
{
 
978
  MPEGAudioMappingData *md = mapping_data;
 
979
 
 
980
  edit_rate->n = md->rate;
 
981
  edit_rate->d = md->spf;
 
982
}
 
983
 
 
984
static guint32
 
985
mxf_mpeg_audio_get_track_number_template (MXFMetadataFileDescriptor * a,
 
986
    GstCaps * caps, gpointer mapping_data)
 
987
{
 
988
  return (0x16 << 24) | (0x05 << 8);
 
989
}
 
990
 
 
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,
 
996
  NULL,
 
997
  {{0,}}
 
998
};
 
999
 
 
1000
#define MPEG_AUDIO_CAPS \
 
1001
      "audio/mpeg, " \
 
1002
      "mpegversion = (int) 1, " \
 
1003
      "layer = (int) [ 1, 3 ], " \
 
1004
      "rate = (int) [ 8000, 48000 ], " \
 
1005
      "channels = (int) [ 1, 2 ], " \
 
1006
      "parsed = (boolean) TRUE; " \
 
1007
      "audio/x-ac3, " \
 
1008
      "rate = (int) [ 4000, 96000 ], " \
 
1009
      "channels = (int) [ 1, 6 ]; " \
 
1010
      "audio/mpeg, " \
 
1011
      "mpegversion = (int) 2, " \
 
1012
      "rate = (int) [ 8000, 96000 ], " \
 
1013
      "channels = (int) [ 1, 8 ]"
 
1014
 
 
1015
/* See ISO/IEC 13818-2 for MPEG ES format */
 
1016
gboolean
 
1017
mxf_mpeg_is_mpeg2_frame (GstBuffer * buffer)
 
1018
{
 
1019
  GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
 
1020
  guint32 tmp;
 
1021
 
 
1022
  while (gst_byte_reader_get_remaining (&reader) > 3) {
 
1023
    if (gst_byte_reader_peek_uint24_be (&reader, &tmp) && tmp == 0x000001) {
 
1024
      guint8 type;
 
1025
 
 
1026
      /* Found sync code */
 
1027
      gst_byte_reader_skip (&reader, 3);
 
1028
 
 
1029
      if (!gst_byte_reader_get_uint8 (&reader, &type))
 
1030
        break;
 
1031
 
 
1032
      /* PICTURE */
 
1033
      if (type == 0x00) {
 
1034
        return TRUE;
 
1035
      }
 
1036
    } else {
 
1037
      gst_byte_reader_skip (&reader, 1);
 
1038
    }
 
1039
  }
 
1040
 
 
1041
  return FALSE;
 
1042
}
 
1043
 
 
1044
static gboolean
 
1045
mxf_mpeg_is_mpeg4_frame (GstBuffer * buffer)
 
1046
{
 
1047
  GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
 
1048
  guint32 tmp;
 
1049
 
 
1050
  while (gst_byte_reader_get_remaining (&reader) > 3) {
 
1051
    if (gst_byte_reader_peek_uint24_be (&reader, &tmp) && tmp == 0x000001) {
 
1052
      guint8 type;
 
1053
 
 
1054
      /* Found sync code */
 
1055
      gst_byte_reader_skip (&reader, 3);
 
1056
 
 
1057
      if (!gst_byte_reader_get_uint8 (&reader, &type))
 
1058
        break;
 
1059
 
 
1060
      /* PICTURE */
 
1061
      if (type == 0xb6) {
 
1062
        return TRUE;
 
1063
      }
 
1064
    } else {
 
1065
      gst_byte_reader_skip (&reader, 1);
 
1066
    }
 
1067
  }
 
1068
 
 
1069
  return FALSE;
 
1070
}
 
1071
 
 
1072
static GstFlowReturn
 
1073
mxf_mpeg_video_write_func (GstBuffer * buffer, GstCaps * caps,
 
1074
    gpointer mapping_data, GstAdapter * adapter, GstBuffer ** outbuf,
 
1075
    gboolean flush)
 
1076
{
 
1077
  MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_OTHER;
 
1078
 
 
1079
  if (mapping_data)
 
1080
    type = *((MXFMPEGEssenceType *) mapping_data);
 
1081
 
 
1082
  if (type == MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2) {
 
1083
    if (buffer && !mxf_mpeg_is_mpeg2_frame (buffer)) {
 
1084
      gst_adapter_push (adapter, buffer);
 
1085
      *outbuf = NULL;
 
1086
      return GST_FLOW_OK;
 
1087
    } else if (buffer || gst_adapter_available (adapter)) {
 
1088
      guint av = gst_adapter_available (adapter);
 
1089
      GstBuffer *ret;
 
1090
 
 
1091
      if (buffer)
 
1092
        ret = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) + av);
 
1093
      else
 
1094
        ret = gst_buffer_new_and_alloc (av);
 
1095
 
 
1096
      if (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);
 
1100
      }
 
1101
 
 
1102
      if (buffer) {
 
1103
        memcpy (GST_BUFFER_DATA (ret) + av, GST_BUFFER_DATA (buffer),
 
1104
            GST_BUFFER_SIZE (buffer));
 
1105
        gst_buffer_unref (buffer);
 
1106
      }
 
1107
      *outbuf = ret;
 
1108
      return GST_FLOW_OK;
 
1109
    }
 
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);
 
1113
      *outbuf = NULL;
 
1114
      return GST_FLOW_OK;
 
1115
    } else if (buffer || gst_adapter_available (adapter)) {
 
1116
      guint av = gst_adapter_available (adapter);
 
1117
      GstBuffer *ret;
 
1118
 
 
1119
      if (buffer)
 
1120
        ret = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer) + av);
 
1121
      else
 
1122
        ret = gst_buffer_new_and_alloc (av);
 
1123
 
 
1124
      if (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);
 
1128
      }
 
1129
 
 
1130
      if (buffer) {
 
1131
        memcpy (GST_BUFFER_DATA (ret) + av, GST_BUFFER_DATA (buffer),
 
1132
            GST_BUFFER_SIZE (buffer));
 
1133
        gst_buffer_unref (buffer);
 
1134
      }
 
1135
      *outbuf = ret;
 
1136
      return GST_FLOW_OK;
 
1137
    }
 
1138
  }
 
1139
 
 
1140
  *outbuf = buffer;
 
1141
  return GST_FLOW_OK;
 
1142
}
 
1143
 
 
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
 
1147
};
 
1148
 
 
1149
static MXFMetadataFileDescriptor *
 
1150
mxf_mpeg_video_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
 
1151
    MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
 
1152
{
 
1153
  MXFMetadataMPEGVideoDescriptor *ret;
 
1154
  GstStructure *s;
 
1155
 
 
1156
  ret = (MXFMetadataMPEGVideoDescriptor *)
 
1157
      gst_mini_object_new (MXF_TYPE_METADATA_MPEG_VIDEO_DESCRIPTOR);
 
1158
 
 
1159
  s = gst_caps_get_structure (caps, 0);
 
1160
 
 
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) {
 
1166
    gint mpegversion;
 
1167
 
 
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));
 
1171
      return NULL;
 
1172
    }
 
1173
 
 
1174
    if (mpegversion == 1) {
 
1175
      MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2;
 
1176
 
 
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;
 
1182
 
 
1183
      *mapping_data = g_new0 (MXFMPEGEssenceType, 1);
 
1184
      memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
 
1185
      ret->parent.parent.picture_essence_coding.u[13] = 0x01;
 
1186
    } else {
 
1187
      const GValue *v;
 
1188
      const GstBuffer *codec_data;
 
1189
      MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG4;
 
1190
 
 
1191
      *mapping_data = g_new0 (MXFMPEGEssenceType, 1);
 
1192
      memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
 
1193
 
 
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);
 
1202
      }
 
1203
    }
 
1204
  } else if (strcmp (gst_structure_get_name (s), "video/x-h264") == 0) {
 
1205
    MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_AVC;
 
1206
 
 
1207
    *mapping_data = g_new0 (MXFMPEGEssenceType, 1);
 
1208
    memcpy (*mapping_data, &type, sizeof (MXFMPEGEssenceType));
 
1209
    ret->parent.parent.picture_essence_coding.u[13] = 0x30;
 
1210
  } else {
 
1211
    g_assert_not_reached ();
 
1212
  }
 
1213
 
 
1214
 
 
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));
 
1218
    return NULL;
 
1219
  }
 
1220
 
 
1221
  *handler = mxf_mpeg_video_write_func;
 
1222
 
 
1223
  return (MXFMetadataFileDescriptor *) ret;
 
1224
}
 
1225
 
 
1226
static void
 
1227
mxf_mpeg_video_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
 
1228
    gpointer mapping_data, GstBuffer * buf)
 
1229
{
 
1230
  return;
 
1231
}
 
1232
 
 
1233
static void
 
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)
 
1237
{
 
1238
  (*edit_rate).n = a->sample_rate.n;
 
1239
  (*edit_rate).d = a->sample_rate.d;
 
1240
}
 
1241
 
 
1242
static guint32
 
1243
mxf_mpeg_video_get_track_number_template (MXFMetadataFileDescriptor * a,
 
1244
    GstCaps * caps, gpointer mapping_data)
 
1245
{
 
1246
  return (0x15 << 24) | (0x05 << 8);
 
1247
}
 
1248
 
 
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,
 
1254
  NULL,
 
1255
  {{0,}}
 
1256
};
 
1257
 
 
1258
#define MPEG_VIDEO_CAPS \
 
1259
"video/mpeg, " \
 
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 "; " \
 
1265
"video/x-h264, " \
 
1266
"width = " GST_VIDEO_SIZE_RANGE ", " \
 
1267
"height = " GST_VIDEO_SIZE_RANGE ", " \
 
1268
"framerate = " GST_VIDEO_FPS_RANGE
 
1269
 
739
1270
void
740
1271
mxf_mpeg_init (void)
741
1272
{
742
1273
  mxf_metadata_register (MXF_TYPE_METADATA_MPEG_VIDEO_DESCRIPTOR);
743
1274
  mxf_essence_element_handler_register (&mxf_mpeg_essence_element_handler);
 
1275
 
 
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);
 
1282
 
 
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),
 
1288
      16);
 
1289
  mxf_essence_element_writer_register (&mxf_mpeg_video_essence_element_writer);
 
1290
 
744
1291
}