comparison mxf.c @ 2563:eae75c1e91fa libavformat

extract correct d10 aes3 audio channels number
author bcoudurier
date Fri, 21 Sep 2007 16:28:17 +0000
parents b21c2af60bc9
children 45a8990a6f11
comparison
equal deleted inserted replaced
2562:fa348896222e 2563:eae75c1e91fa
45 45
46 //#define DEBUG 46 //#define DEBUG
47 47
48 #include "avformat.h" 48 #include "avformat.h"
49 #include "aes.h" 49 #include "aes.h"
50 #include "bytestream.h"
50 51
51 typedef uint8_t UID[16]; 52 typedef uint8_t UID[16];
52 53
53 enum MXFMetadataSetType { 54 enum MXFMetadataSetType {
54 AnyType, 55 AnyType,
239 /* XXX: use AVBitStreamFilter */ 240 /* XXX: use AVBitStreamFilter */
240 static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length) 241 static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length)
241 { 242 {
242 uint8_t buffer[61444]; 243 uint8_t buffer[61444];
243 uint8_t *buf_ptr, *end_ptr, *data_ptr; 244 uint8_t *buf_ptr, *end_ptr, *data_ptr;
245 int i;
244 246
245 if (length > 61444) /* worst case PAL 1920 samples 8 channels */ 247 if (length > 61444) /* worst case PAL 1920 samples 8 channels */
246 return -1; 248 return -1;
247 get_buffer(pb, buffer, length); 249 get_buffer(pb, buffer, length);
248 av_new_packet(pkt, length); 250 av_new_packet(pkt, length);
249 data_ptr = pkt->data; 251 data_ptr = pkt->data;
250 end_ptr = buffer + length; 252 end_ptr = buffer + length;
251 buf_ptr = buffer + 4; /* skip SMPTE 331M header */ 253 buf_ptr = buffer + 4; /* skip SMPTE 331M header */
252 for (; buf_ptr < end_ptr; buf_ptr += 4) { 254 for (; buf_ptr < end_ptr; ) {
253 if (st->codec->bits_per_sample == 24) { 255 for (i = 0; i < st->codec->channels; i++) {
254 data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4); 256 uint32_t sample = bytestream_get_le32(&buf_ptr);
255 data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4); 257 if (st->codec->bits_per_sample == 24)
256 data_ptr[2] = (buf_ptr[0] >> 4) | ((buf_ptr[1] & 0x0f) << 4); 258 bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff);
257 data_ptr += 3; 259 else
258 } else { 260 bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff);
259 data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4); 261 }
260 data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4); 262 buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M
261 data_ptr += 2;
262 }
263 } 263 }
264 pkt->size = data_ptr - pkt->data; 264 pkt->size = data_ptr - pkt->data;
265 return 0; 265 return 0;
266 } 266 }
267 267
634 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */ 634 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */
635 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */ 635 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */
636 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */ 636 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */
637 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */ 637 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */
638 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 }, CODEC_ID_MP2, Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */ 638 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 }, CODEC_ID_MP2, Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */
639 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */ 639 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, CODEC_ID_PCM_S16LE, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */
640 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 40Mbps PAL Extended Template */ 640 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x03,0x01 }, CODEC_ID_PCM_S16LE, Frame }, /* D-10 Mapping 40Mbps PAL Extended Template */
641 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 50Mbps PAL Extended Template */ 641 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, CODEC_ID_PCM_S16LE, Frame }, /* D-10 Mapping 50Mbps PAL Extended Template */
642 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame }, 642 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame },
643 }; 643 };
644 644
645 /* 645 /*
646 * Match an uid independently of the version byte and up to len common bytes 646 * Match an uid independently of the version byte and up to len common bytes
856 } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) { 856 } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
857 if (descriptor->bits_per_sample == 24) 857 if (descriptor->bits_per_sample == 24)
858 st->codec->codec_id = CODEC_ID_PCM_S24BE; 858 st->codec->codec_id = CODEC_ID_PCM_S24BE;
859 else if (descriptor->bits_per_sample == 32) 859 else if (descriptor->bits_per_sample == 32)
860 st->codec->codec_id = CODEC_ID_PCM_S32BE; 860 st->codec->codec_id = CODEC_ID_PCM_S32BE;
861 if (descriptor->essence_container_ul[13] == 0x01) /* D-10 Mapping */
862 st->codec->channels = 8; /* force channels to 8 */
863 } else if (st->codec->codec_id == CODEC_ID_MP2) { 861 } else if (st->codec->codec_id == CODEC_ID_MP2) {
864 st->need_parsing = AVSTREAM_PARSE_FULL; 862 st->need_parsing = AVSTREAM_PARSE_FULL;
865 } 863 }
866 } 864 }
867 if (container_ul && container_ul->wrapping == Clip) { 865 if (container_ul && container_ul->wrapping == Clip) {