diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 84372f8..659691c 100644
|
a
|
b
|
|
| 48 | 48 | #include "avio_internal.h" |
| 49 | 49 | #include "spdif.h" |
| 50 | 50 | #include "libavcodec/ac3.h" |
| | 51 | #include "libavcodec/ac3_parser.h" |
| 51 | 52 | #include "libavcodec/dca.h" |
| 52 | 53 | #include "libavcodec/dcadata.h" |
| 53 | 54 | #include "libavcodec/aacadtsdec.h" |
| 54 | 55 | #include "libavutil/opt.h" |
| 55 | 56 | |
| | 57 | #define AC3_HEADER_SIZE 7 |
| | 58 | |
| 56 | 59 | typedef struct IEC61937Context { |
| 57 | 60 | const AVClass *av_class; |
| 58 | 61 | enum IEC61937DataType data_type;///< burst info - reference to type of payload of the data-burst |
| … |
… |
static const AVClass class = { |
| 103 | 106 | static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt) |
| 104 | 107 | { |
| 105 | 108 | IEC61937Context *ctx = s->priv_data; |
| 106 | | int bitstream_mode = pkt->data[5] & 0x7; |
| | 109 | AC3HeaderInfo hdr; |
| | 110 | GetBitContext gbc; |
| | 111 | int ret; |
| 107 | 112 | |
| 108 | | ctx->data_type = IEC61937_AC3 | (bitstream_mode << 8); |
| 109 | | ctx->pkt_offset = AC3_FRAME_SIZE << 2; |
| | 113 | if (pkt->size < AC3_HEADER_SIZE) |
| | 114 | return AVERROR_INVALIDDATA; |
| | 115 | init_get_bits(&gbc, pkt->data, AC3_HEADER_SIZE * 8); |
| | 116 | ret = ff_ac3_parse_header(&gbc, &hdr); |
| | 117 | if (ret) { |
| | 118 | av_log(s, AV_LOG_ERROR, "Invalid AC3 header\n"); |
| | 119 | return AVERROR_INVALIDDATA; |
| | 120 | } |
| | 121 | if (hdr.num_blocks != 6) { |
| | 122 | av_log(s, AV_LOG_ERROR, "AC3 num_blocks[%d] not supported for IEC-61937\n", hdr.num_blocks); |
| | 123 | return AVERROR_INVALIDDATA; |
| | 124 | } |
| | 125 | ctx->data_type = IEC61937_AC3 | (hdr.bitstream_mode <<8); |
| | 126 | ctx->pkt_offset = AC3_FRAME_SIZE <<2; |
| | 127 | ctx->out_bytes = hdr.frame_size; |
| | 128 | ctx->length_code = ctx->out_bytes <<3; |
| 110 | 129 | return 0; |
| 111 | 130 | } |
| 112 | 131 | |
| … |
… |
static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt) |
| 326 | 345 | int extension = pkt->data[2] & 1; |
| 327 | 346 | |
| 328 | 347 | if (layer == 3 || version == 1) { |
| 329 | | av_log(s, AV_LOG_ERROR, "Wrong MPEG file format\n"); |
| | 348 | av_log(s, AV_LOG_ERROR, "Invalid MPEG header\n"); |
| 330 | 349 | return AVERROR_INVALIDDATA; |
| 331 | 350 | } |
| 332 | 351 | av_log(s, AV_LOG_DEBUG, "version: %i layer: %i extension: %i\n", version, layer, extension); |
| … |
… |
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt) |
| 351 | 370 | init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8); |
| 352 | 371 | ret = ff_aac_parse_header(&gbc, &hdr); |
| 353 | 372 | if (ret < 0) { |
| 354 | | av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n"); |
| | 373 | av_log(s, AV_LOG_ERROR, "Invalid AAC header\n"); |
| 355 | 374 | return AVERROR_INVALIDDATA; |
| 356 | 375 | } |
| 357 | 376 | |
| 358 | | ctx->pkt_offset = hdr.samples << 2; |
| | 377 | ctx->out_bytes = ret; |
| | 378 | ctx->pkt_offset = hdr.samples << 2; |
| | 379 | ctx->length_code = ctx->out_bytes << 3; |
| 359 | 380 | switch (hdr.num_aac_frames) { |
| 360 | 381 | case 1: |
| 361 | 382 | ctx->data_type = IEC61937_MPEG2_AAC; |
| … |
… |
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
| 503 | 524 | return ret; |
| 504 | 525 | if (!ctx->pkt_offset) |
| 505 | 526 | return 0; |
| | 527 | if (pkt->size < ctx->out_bytes) |
| | 528 | return AVERROR_INVALIDDATA; |
| 506 | 529 | |
| 507 | 530 | padding = (ctx->pkt_offset - ctx->use_preamble * BURST_HEADER_SIZE - ctx->out_bytes) & ~1; |
| 508 | 531 | if (padding < 0) { |