diff options
author | Anssi Hannula <anssi.hannula@iki.fi> | 2010-12-29 23:42:27 +0000 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@rainbow.studorg.tuwien.ac.at> | 2010-12-29 23:42:27 +0000 |
commit | cc6c0c7b5231591396f771938ddf5ed90f3a49b1 (patch) | |
tree | 75377eed88369456ed7166f721dfab1acfa74c62 | |
parent | 720ea2d5b2b8498e686f164e8819eb25ea4b94f6 (diff) | |
download | ffmpeg-cc6c0c7b5231591396f771938ddf5ed90f3a49b1.tar.gz |
Do not add the preamble if the DTS stream is already padded, like DTS in
wav. In that case, DTS can be transmitted through S/PDIF without
the IEC 61937 headers.
Patch by Anssi Hannula, anssi d hannula a iki d fi
Originally committed as revision 26160 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/spdifenc.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c index e7be807334..704eb9e3ab 100644 --- a/libavformat/spdifenc.c +++ b/libavformat/spdifenc.c @@ -60,6 +60,7 @@ typedef struct IEC61937Context { uint8_t *out_buf; ///< pointer to the outgoing data before byte-swapping int out_bytes; ///< amount of outgoing bytes + int use_preamble; ///< preamble enabled (disabled for exactly pre-padded DTS) int extra_bswap; ///< extra bswap for payload (for LE DTS => standard BE DTS) uint8_t *hd_buf; ///< allocated buffer to concatenate hd audio frames @@ -153,6 +154,13 @@ static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt) } ctx->pkt_offset = blocks << 7; + if (ctx->out_bytes == ctx->pkt_offset) { + /* The DTS stream fits exactly into the output stream, so skip the + * preamble as it would not fit in there. This is the case for dts + * discs and dts-in-wav. */ + ctx->use_preamble = 0; + } + return 0; } @@ -330,6 +338,7 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) ctx->out_buf = pkt->data; ctx->out_bytes = pkt->size; ctx->length_code = FFALIGN(pkt->size, 2) << 3; + ctx->use_preamble = 1; ctx->extra_bswap = 0; ret = ctx->header_info(s, pkt); @@ -338,16 +347,18 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) if (!ctx->pkt_offset) return 0; - padding = (ctx->pkt_offset - BURST_HEADER_SIZE - ctx->out_bytes) >> 1; + padding = (ctx->pkt_offset - ctx->use_preamble * BURST_HEADER_SIZE - ctx->out_bytes) >> 1; if (padding < 0) { av_log(s, AV_LOG_ERROR, "bitrate is too high\n"); return AVERROR(EINVAL); } + if (ctx->use_preamble) { put_le16(s->pb, SYNCWORD1); //Pa put_le16(s->pb, SYNCWORD2); //Pb put_le16(s->pb, ctx->data_type); //Pc put_le16(s->pb, ctx->length_code);//Pd + } if (HAVE_BIGENDIAN ^ ctx->extra_bswap) { put_buffer(s->pb, ctx->out_buf, ctx->out_bytes & ~1); |