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

« back to all changes in this revision

Viewing changes to gst/mxf/mxfaes-bwf.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:
36
36
#include <string.h>
37
37
 
38
38
#include "mxfaes-bwf.h"
 
39
#include "mxfessence.h"
39
40
#include "mxfquark.h"
40
41
 
41
42
GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
305
306
  return ret;
306
307
}
307
308
 
 
309
static GList *
 
310
mxf_metadata_wave_audio_essence_descriptor_write_tags (MXFMetadataBase * m,
 
311
    MXFPrimerPack * primer)
 
312
{
 
313
  MXFMetadataWaveAudioEssenceDescriptor *self =
 
314
      MXF_METADATA_WAVE_AUDIO_ESSENCE_DESCRIPTOR (m);
 
315
  GList *ret =
 
316
      MXF_METADATA_BASE_CLASS
 
317
      (mxf_metadata_wave_audio_essence_descriptor_parent_class)->write_tags (m,
 
318
      primer);
 
319
  MXFLocalTag *t;
 
320
  static const guint8 block_align_ul[] = {
 
321
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
322
    0x04, 0x02, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00
 
323
  };
 
324
  static const guint8 sequence_offset_ul[] = {
 
325
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
326
    0x04, 0x02, 0x03, 0x02, 0x02, 0x00, 0x00, 0x00
 
327
  };
 
328
  static const guint8 avg_bps_ul[] = {
 
329
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
330
    0x04, 0x02, 0x03, 0x03, 0x05, 0x00, 0x00, 0x00
 
331
  };
 
332
  static const guint8 channel_assignment_ul[] = {
 
333
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x07,
 
334
    0x04, 0x02, 0x01, 0x01, 0x05, 0x00, 0x00, 0x00
 
335
  };
 
336
  static const guint8 peak_envelope_version_ul[] = {
 
337
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
338
    0x04, 0x02, 0x03, 0x01, 0x06, 0x00, 0x00, 0x00
 
339
  };
 
340
  static const guint8 peak_envelope_format_ul[] = {
 
341
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
342
    0x04, 0x02, 0x03, 0x01, 0x07, 0x00, 0x00, 0x00
 
343
  };
 
344
  static const guint8 points_per_peak_value_ul[] = {
 
345
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
346
    0x04, 0x02, 0x03, 0x01, 0x08, 0x00, 0x00, 0x00
 
347
  };
 
348
  static const guint8 peak_envelope_block_size_ul[] = {
 
349
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
350
    0x04, 0x02, 0x03, 0x01, 0x09, 0x00, 0x00, 0x00
 
351
  };
 
352
  static const guint8 peak_channels_ul[] = {
 
353
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
354
    0x04, 0x02, 0x03, 0x01, 0x0A, 0x00, 0x00, 0x00
 
355
  };
 
356
  static const guint8 peak_frames_ul[] = {
 
357
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
358
    0x04, 0x02, 0x03, 0x01, 0x0B, 0x00, 0x00, 0x00
 
359
  };
 
360
  static const guint8 peak_of_peaks_position_ul[] = {
 
361
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
362
    0x04, 0x02, 0x03, 0x01, 0x0C, 0x00, 0x00, 0x00
 
363
  };
 
364
  static const guint8 peak_envelope_timestamp_ul[] = {
 
365
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
366
    0x04, 0x02, 0x03, 0x01, 0x0D, 0x00, 0x00, 0x00
 
367
  };
 
368
  static const guint8 peak_envelope_data_ul[] = {
 
369
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x08,
 
370
    0x04, 0x02, 0x03, 0x01, 0x0E, 0x00, 0x00, 0x00
 
371
  };
 
372
 
 
373
  t = g_slice_new0 (MXFLocalTag);
 
374
  memcpy (&t->ul, &block_align_ul, 16);
 
375
  t->size = 2;
 
376
  t->data = g_slice_alloc (t->size);
 
377
  t->g_slice = TRUE;
 
378
  GST_WRITE_UINT16_BE (t->data, self->block_align);
 
379
  mxf_primer_pack_add_mapping (primer, 0x3d0a, &t->ul);
 
380
  ret = g_list_prepend (ret, t);
 
381
 
 
382
  if (self->sequence_offset) {
 
383
    t = g_slice_new0 (MXFLocalTag);
 
384
    memcpy (&t->ul, &sequence_offset_ul, 16);
 
385
    t->size = 1;
 
386
    t->data = g_slice_alloc (t->size);
 
387
    t->g_slice = TRUE;
 
388
    GST_WRITE_UINT8 (t->data, self->sequence_offset);
 
389
    mxf_primer_pack_add_mapping (primer, 0x3d0b, &t->ul);
 
390
    ret = g_list_prepend (ret, t);
 
391
  }
 
392
 
 
393
  t = g_slice_new0 (MXFLocalTag);
 
394
  memcpy (&t->ul, &avg_bps_ul, 16);
 
395
  t->size = 4;
 
396
  t->data = g_slice_alloc (t->size);
 
397
  t->g_slice = TRUE;
 
398
  GST_WRITE_UINT32_BE (t->data, self->avg_bps);
 
399
  mxf_primer_pack_add_mapping (primer, 0x3d09, &t->ul);
 
400
  ret = g_list_prepend (ret, t);
 
401
 
 
402
  if (!mxf_ul_is_zero (&self->channel_assignment)) {
 
403
    t = g_slice_new0 (MXFLocalTag);
 
404
    memcpy (&t->ul, &channel_assignment_ul, 16);
 
405
    t->size = 16;
 
406
    t->data = g_slice_alloc (t->size);
 
407
    t->g_slice = TRUE;
 
408
    memcpy (t->data, &self->channel_assignment, 16);
 
409
    mxf_primer_pack_add_mapping (primer, 0x3d32, &t->ul);
 
410
    ret = g_list_prepend (ret, t);
 
411
  }
 
412
 
 
413
  if (self->peak_envelope_version) {
 
414
    t = g_slice_new0 (MXFLocalTag);
 
415
    memcpy (&t->ul, &peak_envelope_version_ul, 16);
 
416
    t->size = 4;
 
417
    t->data = g_slice_alloc (t->size);
 
418
    t->g_slice = TRUE;
 
419
    GST_WRITE_UINT32_BE (t->data, self->peak_envelope_version);
 
420
    mxf_primer_pack_add_mapping (primer, 0x3d29, &t->ul);
 
421
    ret = g_list_prepend (ret, t);
 
422
  }
 
423
 
 
424
  if (self->peak_envelope_format) {
 
425
    t = g_slice_new0 (MXFLocalTag);
 
426
    memcpy (&t->ul, &peak_envelope_format_ul, 16);
 
427
    t->size = 4;
 
428
    t->data = g_slice_alloc (t->size);
 
429
    t->g_slice = TRUE;
 
430
    GST_WRITE_UINT32_BE (t->data, self->peak_envelope_format);
 
431
    mxf_primer_pack_add_mapping (primer, 0x3d2a, &t->ul);
 
432
    ret = g_list_prepend (ret, t);
 
433
  }
 
434
 
 
435
  if (self->points_per_peak_value) {
 
436
    t = g_slice_new0 (MXFLocalTag);
 
437
    memcpy (&t->ul, &points_per_peak_value_ul, 16);
 
438
    t->size = 4;
 
439
    t->data = g_slice_alloc (t->size);
 
440
    t->g_slice = TRUE;
 
441
    GST_WRITE_UINT32_BE (t->data, self->points_per_peak_value);
 
442
    mxf_primer_pack_add_mapping (primer, 0x3d2b, &t->ul);
 
443
    ret = g_list_prepend (ret, t);
 
444
  }
 
445
 
 
446
  if (self->peak_envelope_block_size) {
 
447
    t = g_slice_new0 (MXFLocalTag);
 
448
    memcpy (&t->ul, &peak_envelope_block_size_ul, 16);
 
449
    t->size = 4;
 
450
    t->data = g_slice_alloc (t->size);
 
451
    t->g_slice = TRUE;
 
452
    GST_WRITE_UINT32_BE (t->data, self->peak_envelope_block_size);
 
453
    mxf_primer_pack_add_mapping (primer, 0x3d2c, &t->ul);
 
454
    ret = g_list_prepend (ret, t);
 
455
  }
 
456
 
 
457
  if (self->peak_channels) {
 
458
    t = g_slice_new0 (MXFLocalTag);
 
459
    memcpy (&t->ul, &peak_channels_ul, 16);
 
460
    t->size = 4;
 
461
    t->data = g_slice_alloc (t->size);
 
462
    t->g_slice = TRUE;
 
463
    GST_WRITE_UINT32_BE (t->data, self->peak_channels);
 
464
    mxf_primer_pack_add_mapping (primer, 0x3d2d, &t->ul);
 
465
    ret = g_list_prepend (ret, t);
 
466
  }
 
467
 
 
468
  if (self->peak_frames) {
 
469
    t = g_slice_new0 (MXFLocalTag);
 
470
    memcpy (&t->ul, &peak_frames_ul, 16);
 
471
    t->size = 4;
 
472
    t->data = g_slice_alloc (t->size);
 
473
    t->g_slice = TRUE;
 
474
    GST_WRITE_UINT32_BE (t->data, self->peak_frames);
 
475
    mxf_primer_pack_add_mapping (primer, 0x3d2e, &t->ul);
 
476
    ret = g_list_prepend (ret, t);
 
477
  }
 
478
 
 
479
  if (self->peak_of_peaks_position) {
 
480
    t = g_slice_new0 (MXFLocalTag);
 
481
    memcpy (&t->ul, &peak_of_peaks_position_ul, 16);
 
482
    t->size = 8;
 
483
    t->data = g_slice_alloc (t->size);
 
484
    t->g_slice = TRUE;
 
485
    GST_WRITE_UINT64_BE (t->data, self->peak_of_peaks_position);
 
486
    mxf_primer_pack_add_mapping (primer, 0x3d2f, &t->ul);
 
487
    ret = g_list_prepend (ret, t);
 
488
  }
 
489
 
 
490
  if (!mxf_timestamp_is_unknown (&self->peak_envelope_timestamp)) {
 
491
    t = g_slice_new0 (MXFLocalTag);
 
492
    memcpy (&t->ul, &peak_envelope_timestamp_ul, 16);
 
493
    t->size = 8;
 
494
    t->data = g_slice_alloc (t->size);
 
495
    t->g_slice = TRUE;
 
496
    mxf_timestamp_write (&self->peak_envelope_timestamp, t->data);
 
497
    mxf_primer_pack_add_mapping (primer, 0x3d30, &t->ul);
 
498
    ret = g_list_prepend (ret, t);
 
499
  }
 
500
 
 
501
  if (self->peak_envelope_data) {
 
502
    t = g_slice_new0 (MXFLocalTag);
 
503
    memcpy (&t->ul, &peak_envelope_data_ul, 16);
 
504
    t->size = self->peak_envelope_data_length;
 
505
    t->data = g_memdup (self->peak_envelope_data, t->size);
 
506
    mxf_primer_pack_add_mapping (primer, 0x3d31, &t->ul);
 
507
    ret = g_list_prepend (ret, t);
 
508
  }
 
509
 
 
510
  return ret;
 
511
}
 
512
 
308
513
static void
309
514
    mxf_metadata_wave_audio_essence_descriptor_init
310
515
    (MXFMetadataWaveAudioEssenceDescriptor * self)
324
529
  metadata_base_class->name_quark = MXF_QUARK (WAVE_AUDIO_ESSENCE_DESCRIPTOR);
325
530
  metadata_base_class->to_structure =
326
531
      mxf_metadata_wave_audio_essence_descriptor_to_structure;
 
532
  metadata_base_class->write_tags =
 
533
      mxf_metadata_wave_audio_essence_descriptor_write_tags;
327
534
  metadata_class->type = 0x0148;
328
535
}
329
536
 
705
912
  return ret;
706
913
}
707
914
 
 
915
static GList *
 
916
mxf_metadata_aes3_audio_essence_descriptor_write_tags (MXFMetadataBase * m,
 
917
    MXFPrimerPack * primer)
 
918
{
 
919
  MXFMetadataAES3AudioEssenceDescriptor *self =
 
920
      MXF_METADATA_AES3_AUDIO_ESSENCE_DESCRIPTOR (m);
 
921
  GList *ret =
 
922
      MXF_METADATA_BASE_CLASS
 
923
      (mxf_metadata_aes3_audio_essence_descriptor_parent_class)->write_tags (m,
 
924
      primer);
 
925
  MXFLocalTag *t;
 
926
  static const guint8 emphasis_ul[] = {
 
927
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
928
    0x04, 0x02, 0x05, 0x01, 0x06, 0x00, 0x00, 0x00
 
929
  };
 
930
  static const guint8 block_start_offset_ul[] = {
 
931
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
932
    0x04, 0x02, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00
 
933
  };
 
934
  static const guint8 auxiliary_bits_mode_ul[] = {
 
935
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
936
    0x04, 0x02, 0x05, 0x01, 0x01, 0x00, 0x00, 0x00
 
937
  };
 
938
  static const guint8 channel_status_mode_ul[] = {
 
939
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
940
    0x04, 0x02, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00
 
941
  };
 
942
  static const guint8 fixed_channel_status_data_ul[] = {
 
943
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
944
    0x04, 0x02, 0x05, 0x01, 0x03, 0x00, 0x00, 0x00
 
945
  };
 
946
  static const guint8 user_data_mode_ul[] = {
 
947
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
948
    0x04, 0x02, 0x05, 0x01, 0x04, 0x00, 0x00, 0x00
 
949
  };
 
950
  static const guint8 fixed_user_data_ul[] = {
 
951
    0x06, 0x0E, 0x2B, 0x34, 0x01, 0x01, 0x01, 0x05,
 
952
    0x04, 0x02, 0x05, 0x01, 0x05, 0x00, 0x00, 0x00
 
953
  };
 
954
 
 
955
  if (self->emphasis) {
 
956
    t = g_slice_new0 (MXFLocalTag);
 
957
    memcpy (&t->ul, &emphasis_ul, 16);
 
958
    t->size = 1;
 
959
    t->data = g_slice_alloc (t->size);
 
960
    t->g_slice = TRUE;
 
961
    GST_WRITE_UINT8 (t->data, self->emphasis);
 
962
    mxf_primer_pack_add_mapping (primer, 0x3d0d, &t->ul);
 
963
    ret = g_list_prepend (ret, t);
 
964
  }
 
965
 
 
966
  if (self->block_start_offset) {
 
967
    t = g_slice_new0 (MXFLocalTag);
 
968
    memcpy (&t->ul, &block_start_offset_ul, 16);
 
969
    t->size = 2;
 
970
    t->data = g_slice_alloc (t->size);
 
971
    t->g_slice = TRUE;
 
972
    GST_WRITE_UINT16_BE (t->data, self->block_start_offset);
 
973
    mxf_primer_pack_add_mapping (primer, 0x3d0f, &t->ul);
 
974
    ret = g_list_prepend (ret, t);
 
975
  }
 
976
 
 
977
  if (self->auxiliary_bits_mode) {
 
978
    t = g_slice_new0 (MXFLocalTag);
 
979
    memcpy (&t->ul, &auxiliary_bits_mode_ul, 16);
 
980
    t->size = 1;
 
981
    t->data = g_slice_alloc (t->size);
 
982
    t->g_slice = TRUE;
 
983
    GST_WRITE_UINT8 (t->data, self->auxiliary_bits_mode);
 
984
    mxf_primer_pack_add_mapping (primer, 0x3d08, &t->ul);
 
985
    ret = g_list_prepend (ret, t);
 
986
  }
 
987
 
 
988
  if (self->channel_status_mode) {
 
989
    t = g_slice_new0 (MXFLocalTag);
 
990
    memcpy (&t->ul, &channel_status_mode_ul, 16);
 
991
    t->size = 8 + self->n_channel_status_mode;
 
992
    t->data = g_slice_alloc (t->size);
 
993
    t->g_slice = TRUE;
 
994
    GST_WRITE_UINT32_BE (t->data, self->n_channel_status_mode);
 
995
    GST_WRITE_UINT32_BE (t->data + 4, 1);
 
996
    memcpy (t->data + 8, self->channel_status_mode, t->size);
 
997
    mxf_primer_pack_add_mapping (primer, 0x3d10, &t->ul);
 
998
    ret = g_list_prepend (ret, t);
 
999
  }
 
1000
 
 
1001
  if (self->fixed_channel_status_data) {
 
1002
    guint i;
 
1003
 
 
1004
    t = g_slice_new0 (MXFLocalTag);
 
1005
    memcpy (&t->ul, &fixed_channel_status_data_ul, 16);
 
1006
    t->size = 8 + 24 * self->n_fixed_channel_status_data;
 
1007
    t->data = g_slice_alloc (t->size);
 
1008
    t->g_slice = TRUE;
 
1009
    GST_WRITE_UINT32_BE (t->data, self->n_fixed_channel_status_data);
 
1010
    GST_WRITE_UINT32_BE (t->data + 4, 24);
 
1011
    for (i = 0; i < self->n_fixed_channel_status_data; i++)
 
1012
      memcpy (t->data + 8 + 24 * i, self->fixed_channel_status_data[i], 24);
 
1013
    mxf_primer_pack_add_mapping (primer, 0x3d11, &t->ul);
 
1014
    ret = g_list_prepend (ret, t);
 
1015
  }
 
1016
 
 
1017
  if (self->user_data_mode) {
 
1018
    t = g_slice_new0 (MXFLocalTag);
 
1019
    memcpy (&t->ul, &user_data_mode_ul, 16);
 
1020
    t->size = 8 + self->n_user_data_mode;
 
1021
    t->data = g_slice_alloc (t->size);
 
1022
    t->g_slice = TRUE;
 
1023
    GST_WRITE_UINT32_BE (t->data, self->n_user_data_mode);
 
1024
    GST_WRITE_UINT32_BE (t->data + 4, 1);
 
1025
    memcpy (t->data + 8, self->user_data_mode, t->size);
 
1026
    mxf_primer_pack_add_mapping (primer, 0x3d12, &t->ul);
 
1027
    ret = g_list_prepend (ret, t);
 
1028
  }
 
1029
 
 
1030
  if (self->fixed_user_data) {
 
1031
    guint i;
 
1032
 
 
1033
    t = g_slice_new0 (MXFLocalTag);
 
1034
    memcpy (&t->ul, &fixed_user_data_ul, 16);
 
1035
    t->size = 8 + 24 * self->n_fixed_user_data;
 
1036
    t->data = g_slice_alloc (t->size);
 
1037
    t->g_slice = TRUE;
 
1038
    GST_WRITE_UINT32_BE (t->data, self->n_fixed_user_data);
 
1039
    GST_WRITE_UINT32_BE (t->data + 4, 24);
 
1040
    for (i = 0; i < self->n_fixed_user_data; i++)
 
1041
      memcpy (t->data + 8 + 24 * i, self->fixed_user_data[i], 24);
 
1042
    mxf_primer_pack_add_mapping (primer, 0x3d11, &t->ul);
 
1043
    ret = g_list_prepend (ret, t);
 
1044
  }
 
1045
 
 
1046
  return ret;
 
1047
}
708
1048
 
709
1049
static void
710
1050
    mxf_metadata_aes3_audio_essence_descriptor_init
728
1068
  metadata_base_class->name_quark = MXF_QUARK (AES3_AUDIO_ESSENCE_DESCRIPTOR);
729
1069
  metadata_base_class->to_structure =
730
1070
      mxf_metadata_aes3_audio_essence_descriptor_to_structure;
 
1071
  metadata_base_class->write_tags =
 
1072
      mxf_metadata_aes3_audio_essence_descriptor_write_tags;
731
1073
  metadata_class->type = 0x0147;
732
1074
}
733
1075
 
841
1183
  /* FIXME: set a channel layout */
842
1184
 
843
1185
  if (mxf_ul_is_zero (&descriptor->sound_essence_compression) ||
844
 
      mxf_ul_is_equal (&descriptor->sound_essence_compression,
845
 
          &mxf_sound_essence_compression_uncompressed)) {
 
1186
      mxf_ul_is_subclass (&mxf_sound_essence_compression_uncompressed,
 
1187
          &descriptor->sound_essence_compression)) {
846
1188
    guint block_align;
847
1189
 
848
1190
    if (descriptor->channel_count == 0 ||
870
1212
    codec_name =
871
1213
        g_strdup_printf ("Uncompressed %u-bit little endian integer PCM audio",
872
1214
        (block_align / descriptor->channel_count) * 8);
873
 
  } else if (mxf_ul_is_equal (&descriptor->sound_essence_compression,
874
 
          &mxf_sound_essence_compression_aiff)) {
 
1215
  } else if (mxf_ul_is_subclass (&mxf_sound_essence_compression_aiff,
 
1216
          &descriptor->sound_essence_compression)) {
875
1217
    guint block_align;
876
1218
 
877
1219
    if (descriptor->channel_count == 0 ||
900
1242
    codec_name =
901
1243
        g_strdup_printf ("Uncompressed %u-bit big endian integer PCM audio",
902
1244
        (block_align / descriptor->channel_count) * 8);
903
 
  } else if (mxf_ul_is_equal (&descriptor->sound_essence_compression,
904
 
          &mxf_sound_essence_compression_alaw)) {
 
1245
  } else if (mxf_ul_is_subclass (&mxf_sound_essence_compression_alaw,
 
1246
          &descriptor->sound_essence_compression)) {
905
1247
 
906
1248
    if (descriptor->audio_sampling_rate.n != 0 ||
907
1249
        descriptor->audio_sampling_rate.d != 0 ||
1051
1393
  mxf_aes_bwf_create_caps
1052
1394
};
1053
1395
 
 
1396
typedef struct
 
1397
{
 
1398
  guint64 error;
 
1399
  gint width, rate, channels;
 
1400
  MXFFraction edit_rate;
 
1401
} BWFMappingData;
 
1402
 
 
1403
static GstFlowReturn
 
1404
mxf_bwf_write_func (GstBuffer * buffer, GstCaps * caps, gpointer mapping_data,
 
1405
    GstAdapter * adapter, GstBuffer ** outbuf, gboolean flush)
 
1406
{
 
1407
  BWFMappingData *md = mapping_data;
 
1408
  guint bytes;
 
1409
  guint64 speu =
 
1410
      gst_util_uint64_scale (md->rate, md->edit_rate.d, md->edit_rate.n);
 
1411
 
 
1412
  md->error += (md->edit_rate.d * md->rate) % (md->edit_rate.n);
 
1413
  if (md->error >= md->edit_rate.n) {
 
1414
    md->error = 0;
 
1415
    speu += 1;
 
1416
  }
 
1417
 
 
1418
  bytes = (speu * md->channels * md->width) / 8;
 
1419
 
 
1420
  if (buffer)
 
1421
    gst_adapter_push (adapter, buffer);
 
1422
 
 
1423
  if (gst_adapter_available (adapter) == 0)
 
1424
    return GST_FLOW_OK;
 
1425
 
 
1426
  if (flush)
 
1427
    bytes = MIN (gst_adapter_available (adapter), bytes);
 
1428
 
 
1429
  if (gst_adapter_available (adapter) >= bytes) {
 
1430
    *outbuf = gst_adapter_take_buffer (adapter, bytes);
 
1431
  }
 
1432
 
 
1433
  if (gst_adapter_available (adapter) >= bytes)
 
1434
    return GST_FLOW_CUSTOM_SUCCESS;
 
1435
  else
 
1436
    return GST_FLOW_OK;
 
1437
}
 
1438
 
 
1439
static const guint8 bwf_essence_container_ul[] = {
 
1440
  0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x01,
 
1441
  0x0d, 0x01, 0x03, 0x01, 0x02, 0x06, 0x01, 0x00
 
1442
};
 
1443
 
 
1444
static MXFMetadataFileDescriptor *
 
1445
mxf_bwf_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
 
1446
    MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
 
1447
{
 
1448
  MXFMetadataWaveAudioEssenceDescriptor *ret;
 
1449
  GstStructure *s;
 
1450
  BWFMappingData *md;
 
1451
  gint width, rate, channels, endianness;
 
1452
 
 
1453
  s = gst_caps_get_structure (caps, 0);
 
1454
  if (strcmp (gst_structure_get_name (s), "audio/x-raw-int") != 0 ||
 
1455
      !gst_structure_get_int (s, "width", &width) ||
 
1456
      !gst_structure_get_int (s, "rate", &rate) ||
 
1457
      !gst_structure_get_int (s, "channels", &channels) ||
 
1458
      !gst_structure_get_int (s, "endianness", &endianness)) {
 
1459
    GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps);
 
1460
    return NULL;
 
1461
  }
 
1462
 
 
1463
  ret = (MXFMetadataWaveAudioEssenceDescriptor *)
 
1464
      gst_mini_object_new (MXF_TYPE_METADATA_WAVE_AUDIO_ESSENCE_DESCRIPTOR);
 
1465
 
 
1466
  memcpy (&ret->parent.parent.essence_container, &bwf_essence_container_ul, 16);
 
1467
  if (endianness == G_LITTLE_ENDIAN)
 
1468
    memcpy (&ret->parent.sound_essence_compression,
 
1469
        &mxf_sound_essence_compression_uncompressed, 16);
 
1470
  else
 
1471
    memcpy (&ret->parent.sound_essence_compression,
 
1472
        &mxf_sound_essence_compression_aiff, 16);
 
1473
 
 
1474
  ret->block_align = (width / 8) * channels;
 
1475
  ret->parent.quantization_bits = width;
 
1476
  ret->avg_bps = ret->block_align * rate;
 
1477
 
 
1478
  if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (&ret->parent,
 
1479
          caps)) {
 
1480
    gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret));
 
1481
    return NULL;
 
1482
  }
 
1483
 
 
1484
  *handler = mxf_bwf_write_func;
 
1485
 
 
1486
  md = g_new0 (BWFMappingData, 1);
 
1487
  md->width = width;
 
1488
  md->rate = rate;
 
1489
  md->channels = channels;
 
1490
  *mapping_data = md;
 
1491
 
 
1492
  return (MXFMetadataFileDescriptor *) ret;
 
1493
}
 
1494
 
 
1495
static void
 
1496
mxf_bwf_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
 
1497
    gpointer mapping_data, GstBuffer * buf)
 
1498
{
 
1499
  return;
 
1500
}
 
1501
 
 
1502
static void
 
1503
mxf_bwf_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps,
 
1504
    gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package,
 
1505
    MXFMetadataTimelineTrack * track, MXFFraction * edit_rate)
 
1506
{
 
1507
  guint i;
 
1508
  gdouble min = G_MAXDOUBLE;
 
1509
  BWFMappingData *md = mapping_data;
 
1510
 
 
1511
  for (i = 0; i < package->parent.n_tracks; i++) {
 
1512
    MXFMetadataTimelineTrack *tmp;
 
1513
 
 
1514
    if (!MXF_IS_METADATA_TIMELINE_TRACK (package->parent.tracks[i]) ||
 
1515
        package->parent.tracks[i] == (MXFMetadataTrack *) track)
 
1516
      continue;
 
1517
 
 
1518
    tmp = MXF_METADATA_TIMELINE_TRACK (package->parent.tracks[i]);
 
1519
    if (((gdouble) tmp->edit_rate.n) / ((gdouble) tmp->edit_rate.d) < min) {
 
1520
      min = ((gdouble) tmp->edit_rate.n) / ((gdouble) tmp->edit_rate.d);
 
1521
      memcpy (edit_rate, &tmp->edit_rate, sizeof (MXFFraction));
 
1522
    }
 
1523
  }
 
1524
 
 
1525
  if (min == G_MAXDOUBLE) {
 
1526
    /* 100ms edit units */
 
1527
    edit_rate->n = 10;
 
1528
    edit_rate->d = 1;
 
1529
  }
 
1530
 
 
1531
  memcpy (&md->edit_rate, edit_rate, sizeof (MXFFraction));
 
1532
}
 
1533
 
 
1534
static guint32
 
1535
mxf_bwf_get_track_number_template (MXFMetadataFileDescriptor * a,
 
1536
    GstCaps * caps, gpointer mapping_data)
 
1537
{
 
1538
  return (0x16 << 24) | (0x01 << 8);
 
1539
}
 
1540
 
 
1541
static MXFEssenceElementWriter mxf_bwf_essence_element_writer = {
 
1542
  mxf_bwf_get_descriptor,
 
1543
  mxf_bwf_update_descriptor,
 
1544
  mxf_bwf_get_edit_rate,
 
1545
  mxf_bwf_get_track_number_template,
 
1546
  NULL,
 
1547
  {{0,}}
 
1548
};
 
1549
 
 
1550
#define BWF_CAPS \
 
1551
      "audio/x-raw-int, " \
 
1552
      "rate = (int) [ 1, MAX ], " \
 
1553
      "channels = (int) [ 1, MAX ], " \
 
1554
      "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
 
1555
      "width = (int) 32, " \
 
1556
      "depth = (int) 32, " \
 
1557
      "signed = (boolean) TRUE; " \
 
1558
      "audio/x-raw-int, " \
 
1559
      "rate = (int) [ 1, MAX ], " \
 
1560
      "channels = (int) [ 1, MAX ], " \
 
1561
      "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
 
1562
      "width = (int) 24, " \
 
1563
      "depth = (int) 24, " \
 
1564
      "signed = (boolean) TRUE; " \
 
1565
      "audio/x-raw-int, " \
 
1566
      "rate = (int) [ 1, MAX ], " \
 
1567
      "channels = (int) [ 1, MAX ], " \
 
1568
      "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
 
1569
      "width = (int) 16, " \
 
1570
      "depth = (int) 16, " \
 
1571
      "signed = (boolean) TRUE; " \
 
1572
      "audio/x-raw-int, " \
 
1573
      "rate = (int) [ 1, MAX ], " \
 
1574
      "channels = (int) [ 1, MAX ], " \
 
1575
      "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
 
1576
      "width = (int) 8, " \
 
1577
      "depth = (int) 8, " \
 
1578
      "signed = (boolean) FALSE"
 
1579
 
1054
1580
void
1055
1581
mxf_aes_bwf_init (void)
1056
1582
{
1058
1584
  mxf_metadata_register (MXF_TYPE_METADATA_AES3_AUDIO_ESSENCE_DESCRIPTOR);
1059
1585
 
1060
1586
  mxf_essence_element_handler_register (&mxf_aes_bwf_essence_handler);
 
1587
 
 
1588
  mxf_bwf_essence_element_writer.pad_template =
 
1589
      gst_pad_template_new ("bwf_audio_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
 
1590
      gst_caps_from_string (BWF_CAPS));
 
1591
  memcpy (&mxf_bwf_essence_element_writer.data_definition,
 
1592
      mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_SOUND_ESSENCE), 16);
 
1593
  mxf_essence_element_writer_register (&mxf_bwf_essence_element_writer);
1061
1594
}