Patch by Anssi Hannula, anssi d hannula a iki d fi
Originally committed as revision 26160 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -60,6 +60,7 @@ typedef struct IEC61937Context { |
60 | 60 |
uint8_t *out_buf; ///< pointer to the outgoing data before byte-swapping |
61 | 61 |
int out_bytes; ///< amount of outgoing bytes |
62 | 62 |
|
63 |
+ int use_preamble; ///< preamble enabled (disabled for exactly pre-padded DTS) |
|
63 | 64 |
int extra_bswap; ///< extra bswap for payload (for LE DTS => standard BE DTS) |
64 | 65 |
|
65 | 66 |
uint8_t *hd_buf; ///< allocated buffer to concatenate hd audio frames |
... | ... |
@@ -153,6 +154,13 @@ static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt) |
153 | 153 |
} |
154 | 154 |
ctx->pkt_offset = blocks << 7; |
155 | 155 |
|
156 |
+ if (ctx->out_bytes == ctx->pkt_offset) { |
|
157 |
+ /* The DTS stream fits exactly into the output stream, so skip the |
|
158 |
+ * preamble as it would not fit in there. This is the case for dts |
|
159 |
+ * discs and dts-in-wav. */ |
|
160 |
+ ctx->use_preamble = 0; |
|
161 |
+ } |
|
162 |
+ |
|
156 | 163 |
return 0; |
157 | 164 |
} |
158 | 165 |
|
... | ... |
@@ -330,6 +338,7 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
330 | 330 |
ctx->out_buf = pkt->data; |
331 | 331 |
ctx->out_bytes = pkt->size; |
332 | 332 |
ctx->length_code = FFALIGN(pkt->size, 2) << 3; |
333 |
+ ctx->use_preamble = 1; |
|
333 | 334 |
ctx->extra_bswap = 0; |
334 | 335 |
|
335 | 336 |
ret = ctx->header_info(s, pkt); |
... | ... |
@@ -338,16 +347,18 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
338 | 338 |
if (!ctx->pkt_offset) |
339 | 339 |
return 0; |
340 | 340 |
|
341 |
- padding = (ctx->pkt_offset - BURST_HEADER_SIZE - ctx->out_bytes) >> 1; |
|
341 |
+ padding = (ctx->pkt_offset - ctx->use_preamble * BURST_HEADER_SIZE - ctx->out_bytes) >> 1; |
|
342 | 342 |
if (padding < 0) { |
343 | 343 |
av_log(s, AV_LOG_ERROR, "bitrate is too high\n"); |
344 | 344 |
return AVERROR(EINVAL); |
345 | 345 |
} |
346 | 346 |
|
347 |
+ if (ctx->use_preamble) { |
|
347 | 348 |
put_le16(s->pb, SYNCWORD1); //Pa |
348 | 349 |
put_le16(s->pb, SYNCWORD2); //Pb |
349 | 350 |
put_le16(s->pb, ctx->data_type); //Pc |
350 | 351 |
put_le16(s->pb, ctx->length_code);//Pd |
352 |
+ } |
|
351 | 353 |
|
352 | 354 |
if (HAVE_BIGENDIAN ^ ctx->extra_bswap) { |
353 | 355 |
put_buffer(s->pb, ctx->out_buf, ctx->out_bytes & ~1); |