summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_lavc.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-08-16 21:00:20 +0200
committerwm4 <wm4@nowhere>2017-08-16 21:10:54 +0200
commit1f593beeb4c649c4718db6f9a4ee37a897af6ead (patch)
tree08d78c2cc473c234fc85ed55a48473f89c76f308 /audio/decode/ad_lavc.c
parent16e0a3948288e37034c572617cf47b0a4dc0e10e (diff)
downloadmpv-1f593beeb4c649c4718db6f9a4ee37a897af6ead.tar.bz2
mpv-1f593beeb4c649c4718db6f9a4ee37a897af6ead.tar.xz
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the new code is not affected by the copyright of the old code. This is needed, because the original mp_audio struct was written by someone who has disagreed with LGPL relicensing (it was called af_data at the time, and was defined in af.h). The "GPL'ed" struct contents that surive are pretty trivial: just the data pointer, and some metadata like the format, samplerate, etc. - but at least in this case, any new code would be extremely similar anyway, and I'm not really sure whether it's OK to claim different copyright. So what we do is we just use AVFrame (which of course is LGPL with 100% certainty), and add some accessors around it to adapt it to mpv conventions. Also, this gets rid of some annoying conventions of mp_audio, like the struct fields that require using an accessor to write to them anyway. For the most part, this change is only dumb replacements of mp_audio related functions and fields. One minor actual change is that you can't allocate the new type on the stack anymore. Some code still uses mp_audio. All audio filter code will be deleted, so it makes no sense to convert this code. (Audio filters which are LGPL and which we keep will have to be ported to a new filter infrastructure anyway.) player/audio.c uses it because it interacts with the old filter code. push.c has some complex use of mp_audio and mp_audio_buffer, but this and pull.c will most likely be rewritten to do something else.
Diffstat (limited to 'audio/decode/ad_lavc.c')
-rw-r--r--audio/decode/ad_lavc.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index d701630fc6..fb429d567b 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -40,7 +40,6 @@
struct priv {
AVCodecContext *avctx;
AVFrame *avframe;
- struct mp_audio frame;
bool force_channel_map;
uint32_t skip_samples, trim_samples;
bool preroll_done;
@@ -191,7 +190,7 @@ static bool send_packet(struct dec_audio *da, struct demux_packet *mpkt)
return true;
}
-static bool receive_frame(struct dec_audio *da, struct mp_audio **out)
+static bool receive_frame(struct dec_audio *da, struct mp_aframe **out)
{
struct priv *priv = da->priv;
AVCodecContext *avctx = priv->avctx;
@@ -217,25 +216,18 @@ static bool receive_frame(struct dec_audio *da, struct mp_audio **out)
double out_pts = mp_pts_from_av(priv->avframe->pts, &priv->codec_timebase);
- struct mp_audio *mpframe = mp_audio_from_avframe(priv->avframe);
+ struct mp_aframe *mpframe = mp_aframe_from_avframe(priv->avframe);
if (!mpframe)
return true;
- struct mp_chmap lavc_chmap = mpframe->channels;
- if (lavc_chmap.num != avctx->channels)
- mp_chmap_from_channels(&lavc_chmap, avctx->channels);
- if (priv->force_channel_map) {
- if (lavc_chmap.num == da->codec->channels.num)
- lavc_chmap = da->codec->channels;
- }
- mp_audio_set_channels(mpframe, &lavc_chmap);
+ if (priv->force_channel_map)
+ mp_aframe_set_chmap(mpframe, &da->codec->channels);
- mpframe->pts = out_pts;
+ if (out_pts == MP_NOPTS_VALUE)
+ out_pts = priv->next_pts;
+ mp_aframe_set_pts(mpframe, out_pts);
- if (mpframe->pts == MP_NOPTS_VALUE)
- mpframe->pts = priv->next_pts;
- if (mpframe->pts != MP_NOPTS_VALUE)
- priv->next_pts = mpframe->pts + mpframe->samples / (double)mpframe->rate;
+ priv->next_pts = mp_aframe_end_pts(mpframe);
#if LIBAVCODEC_VERSION_MICRO >= 100
AVFrameSideData *sd =
@@ -254,14 +246,14 @@ static bool receive_frame(struct dec_audio *da, struct mp_audio **out)
priv->preroll_done = true;
}
- uint32_t skip = MPMIN(priv->skip_samples, mpframe->samples);
+ uint32_t skip = MPMIN(priv->skip_samples, mp_aframe_get_size(mpframe));
if (skip) {
- mp_audio_skip_samples(mpframe, skip);
+ mp_aframe_skip_samples(mpframe, skip);
priv->skip_samples -= skip;
}
- uint32_t trim = MPMIN(priv->trim_samples, mpframe->samples);
+ uint32_t trim = MPMIN(priv->trim_samples, mp_aframe_get_size(mpframe));
if (trim) {
- mpframe->samples -= trim;
+ mp_aframe_set_size(mpframe, mp_aframe_get_size(mpframe) - trim);
priv->trim_samples -= trim;
}
@@ -269,7 +261,6 @@ static bool receive_frame(struct dec_audio *da, struct mp_audio **out)
av_frame_unref(priv->avframe);
- MP_DBG(da, "Decoded %d samples\n", mpframe->samples);
return true;
}