summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_spdif.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-11 19:10:33 +0200
committerwm4 <wm4@nowhere>2013-07-11 19:10:33 +0200
commita5224836293ac02bd13f688cfc848aae6818e963 (patch)
treec67c9a61505583a0614ccc2c7cdbdb4e1deffda2 /audio/decode/ad_spdif.c
parent07c5327fa0c3411bcb8caad17d70b014d6b022dd (diff)
downloadmpv-a5224836293ac02bd13f688cfc848aae6818e963.tar.bz2
mpv-a5224836293ac02bd13f688cfc848aae6818e963.tar.xz
demux: remove facility for partial packet reads
Partial packet reads were needed because the video/audio parsers were working on top of them. So it could happen that a parser read a part of a packet, and returned that to the decoder. With libavformat/libavcodec, packets are already parsed, and everything is much simpler. Most of the simplifications in ad_spdif could have been done earlier. Remove some other stuff as well, like the questionable slave mode start time reporting (could be replaced by proper code, but we don't bother). Remove the unused skip_audio_frame() functionality as well (it was used by old demuxers). Some functions become private to demux.c, like demux_fill_buffer(). Introduce new packet read functions, which have simpler semantics. Packets returned from them are owned by the caller, and all packets in the demux.c packet queue are considered unread. Remove special code that dropped subtitle packets with size 0. This used to be needed because it caused special cases in the old code.
Diffstat (limited to 'audio/decode/ad_spdif.c')
-rw-r--r--audio/decode/ad_spdif.c59
1 files changed, 11 insertions, 48 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 49b7d9a0d8..f4fc430208 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -84,9 +84,7 @@ static int codecs[] = {
static int init(sh_audio_t *sh, const char *decoder)
{
- int x, in_size, srate, bps, *dtshd_rate;
- unsigned char *start;
- double pts;
+ int srate, bps, *dtshd_rate;
AVFormatContext *lavf_ctx = NULL;
AVStream *stream = NULL;
const AVOption *opt = NULL;
@@ -125,16 +123,8 @@ static int init(sh_audio_t *sh, const char *decoder)
goto fail;
}
- // get sample_rate & bitrate from parser
- x = ds_get_packet_pts(sh->ds, &start, &pts);
- in_size = x;
- if (x <= 0) {
- pts = MP_NOPTS_VALUE;
- x = 0;
- }
srate = 48000; //fake value
bps = 768000/8; //fake value
- sh->ds->buffer_pos -= in_size;
int num_channels = 0;
switch (lavf_ctx->streams[0]->codec->codec_id) {
@@ -214,42 +204,24 @@ static int decode_audio(sh_audio_t *sh, unsigned char *buf,
struct spdifContext *spdif_ctx = sh->context;
AVFormatContext *lavf_ctx = spdif_ctx->lavf_ctx;
AVPacket pkt;
- double pts;
- int ret, in_size, consumed, x;
- unsigned char *start = NULL;
- consumed = spdif_ctx->out_buffer_len = 0;
+ spdif_ctx->out_buffer_len = 0;
spdif_ctx->out_buffer_size = maxlen;
spdif_ctx->out_buffer = buf;
while (spdif_ctx->out_buffer_len + spdif_ctx->iec61937_packet_size < maxlen
&& spdif_ctx->out_buffer_len < minlen) {
- if (sh->ds->eof)
+ struct demux_packet *mpkt = demux_read_packet(sh->gsh);
+ if (!mpkt)
break;
- x = ds_get_packet_pts(sh->ds, &start, &pts);
- if (x <= 0) {
- continue; // END_NOT_FOUND
- } else {
- in_size = x;
- consumed = x;
- if (x == 0) {
- mp_msg(MSGT_DECAUDIO,MSGL_V,
- "start[%p] in_size[%d] consumed[%d] x[%d].\n",
- start, in_size, consumed, x);
- continue; // END_NOT_FOUND
- }
- sh->ds->buffer_pos -= in_size - consumed;
- }
- av_init_packet(&pkt);
- pkt.data = start;
- pkt.size = x;
- mp_msg(MSGT_DECAUDIO,MSGL_V,
- "start[%p] pkt.size[%d] in_size[%d] consumed[%d] x[%d].\n",
- start, pkt.size, in_size, consumed, x);
- if (pts != MP_NOPTS_VALUE) {
- sh->pts = pts;
+ mp_set_av_packet(&pkt, mpkt);
+ mp_msg(MSGT_DECAUDIO,MSGL_V, "pkt.data[%p] pkt.size[%d]\n",
+ pkt.data, pkt.size);
+ if (mpkt->pts != MP_NOPTS_VALUE) {
+ sh->pts = mpkt->pts;
sh->pts_bytes = 0;
}
- ret = lavf_ctx->oformat->write_packet(lavf_ctx, &pkt);
+ int ret = lavf_ctx->oformat->write_packet(lavf_ctx, &pkt);
+ talloc_free(mpkt);
if (ret < 0)
break;
}
@@ -259,15 +231,6 @@ static int decode_audio(sh_audio_t *sh, unsigned char *buf,
static int control(sh_audio_t *sh, int cmd, void *arg)
{
- unsigned char *start;
- double pts;
-
- switch (cmd) {
- case ADCTRL_RESYNC_STREAM:
- case ADCTRL_SKIP_FRAME:
- ds_get_packet_pts(sh->ds, &start, &pts);
- return CONTROL_TRUE;
- }
return CONTROL_UNKNOWN;
}