summaryrefslogtreecommitdiffstats
path: root/audio/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-01-19 22:24:26 +0100
committerwm4 <wm4@nowhere>2016-01-19 22:24:38 +0100
commit30031edce3bb79051a125183c8dc152ba4e78e66 (patch)
treeb041672d79d6e93423a65e33260ba13eca23695d /audio/decode
parentc365b44e19e1ab1cdb0d2aaca5360108d6da862a (diff)
downloadmpv-30031edce3bb79051a125183c8dc152ba4e78e66.tar.bz2
mpv-30031edce3bb79051a125183c8dc152ba4e78e66.tar.xz
audio: move direct packet reading from decoders to common code
Another bit of preparation.
Diffstat (limited to 'audio/decode')
-rw-r--r--audio/decode/ad.h3
-rw-r--r--audio/decode/ad_lavc.c22
-rw-r--r--audio/decode/ad_spdif.c9
-rw-r--r--audio/decode/dec_audio.c20
-rw-r--r--audio/decode/dec_audio.h2
5 files changed, 27 insertions, 29 deletions
diff --git a/audio/decode/ad.h b/audio/decode/ad.h
index 05139549b1..771ceb7e88 100644
--- a/audio/decode/ad.h
+++ b/audio/decode/ad.h
@@ -35,7 +35,8 @@ struct ad_functions {
int (*init)(struct dec_audio *da, const char *decoder);
void (*uninit)(struct dec_audio *da);
int (*control)(struct dec_audio *da, int cmd, void *arg);
- int (*decode_packet)(struct dec_audio *da, struct mp_audio **out);
+ int (*decode_packet)(struct dec_audio *da, struct demux_packet *pkt,
+ struct mp_audio **out);
};
enum ad_ctrl {
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index 7e5c8d5aa5..f7304353af 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -42,7 +42,6 @@ struct priv {
AVFrame *avframe;
struct mp_audio frame;
bool force_channel_map;
- struct demux_packet *packet;
uint32_t skip_samples;
};
@@ -165,27 +164,18 @@ static int control(struct dec_audio *da, int cmd, void *arg)
switch (cmd) {
case ADCTRL_RESET:
avcodec_flush_buffers(ctx->avctx);
- talloc_free(ctx->packet);
- ctx->packet = NULL;
ctx->skip_samples = 0;
return CONTROL_TRUE;
}
return CONTROL_UNKNOWN;
}
-static int decode_packet(struct dec_audio *da, struct mp_audio **out)
+static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt,
+ struct mp_audio **out)
{
struct priv *priv = da->priv;
AVCodecContext *avctx = priv->avctx;
- struct demux_packet *mpkt = priv->packet;
- if (!mpkt) {
- if (demux_read_packet_async(da->header, &mpkt) == 0)
- return AD_WAIT;
- }
-
- priv->packet = talloc_steal(priv, mpkt);
-
int in_len = mpkt ? mpkt->len : 0;
AVPacket pkt;
@@ -203,13 +193,11 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
mpkt->len -= ret;
mpkt->pts = MP_NOPTS_VALUE; // don't reset PTS next time
}
- if (mpkt->len == 0 || ret < 0) {
- talloc_free(mpkt);
- priv->packet = NULL;
- }
// LATM may need many packets to find mux info
- if (ret == AVERROR(EAGAIN))
+ if (ret == AVERROR(EAGAIN)) {
+ mpkt->len = 0;
return AD_OK;
+ }
}
if (ret < 0) {
MP_ERR(da, "Error decoding audio.\n");
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index dd0ef181af..8f762545f3 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -242,16 +242,13 @@ fail:
return -1;
}
-static int decode_packet(struct dec_audio *da, struct mp_audio **out)
+static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt,
+ struct mp_audio **out)
{
struct spdifContext *spdif_ctx = da->priv;
spdif_ctx->out_buffer_len = 0;
- struct demux_packet *mpkt;
- if (demux_read_packet_async(da->header, &mpkt) == 0)
- return AD_WAIT;
-
if (!mpkt)
return AD_EOF;
@@ -259,13 +256,13 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
AVPacket pkt;
mp_set_av_packet(&pkt, mpkt, NULL);
+ mpkt->len = 0; // will be fully consumed
pkt.pts = pkt.dts = 0;
if (!spdif_ctx->lavf_ctx) {
if (init_filter(da, &pkt) < 0)
return AD_ERR;
}
int ret = av_write_frame(spdif_ctx->lavf_ctx, &pkt);
- talloc_free(mpkt);
avio_flush(spdif_ctx->lavf_ctx->pb);
if (ret < 0)
return AD_ERR;
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index f774ed1abd..f97636e475 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -161,13 +161,23 @@ void audio_uninit(struct dec_audio *d_audio)
uninit_decoder(d_audio);
af_destroy(d_audio->afilter);
talloc_free(d_audio->waiting);
+ talloc_free(d_audio->packet);
talloc_free(d_audio);
}
static int decode_new_frame(struct dec_audio *da)
{
while (!da->waiting) {
- int ret = da->ad_driver->decode_packet(da, &da->waiting);
+ if (!da->packet) {
+ if (demux_read_packet_async(da->header, &da->packet) == 0)
+ return AD_WAIT;
+ }
+
+ int ret = da->ad_driver->decode_packet(da, da->packet, &da->waiting);
+ if (ret < 0 || (da->packet && da->packet->len == 0)) {
+ talloc_free(da->packet);
+ da->packet = NULL;
+ }
if (ret < 0)
return ret;
@@ -285,8 +295,8 @@ void audio_reset_decoding(struct dec_audio *d_audio)
d_audio->pts = MP_NOPTS_VALUE;
d_audio->pts_offset = 0;
d_audio->pts_reset = false;
- if (d_audio->waiting) {
- talloc_free(d_audio->waiting);
- d_audio->waiting = NULL;
- }
+ talloc_free(d_audio->waiting);
+ d_audio->waiting = NULL;
+ talloc_free(d_audio->packet);
+ d_audio->packet = NULL;
}
diff --git a/audio/decode/dec_audio.h b/audio/decode/dec_audio.h
index 17ce6b838f..b273bb2af9 100644
--- a/audio/decode/dec_audio.h
+++ b/audio/decode/dec_audio.h
@@ -48,6 +48,8 @@ struct dec_audio {
bool pts_reset;
// For free use by the ad_driver
void *priv;
+ // Strictly internal to dec_audio.c
+ struct demux_packet *packet;
};
enum {