diff options
author | wm4 <wm4@nowhere> | 2017-08-16 21:00:20 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-08-16 21:10:54 +0200 |
commit | 1f593beeb4c649c4718db6f9a4ee37a897af6ead (patch) | |
tree | 08d78c2cc473c234fc85ed55a48473f89c76f308 /audio/decode/dec_audio.c | |
parent | 16e0a3948288e37034c572617cf47b0a4dc0e10e (diff) |
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/dec_audio.c')
-rw-r--r-- | audio/decode/dec_audio.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index 1351cb8ecd..401e26fb7b 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -38,8 +38,6 @@ #include "dec_audio.h" #include "ad.h" #include "audio/format.h" -#include "audio/audio.h" -#include "audio/audio_buffer.h" #include "audio/filter/af.h" @@ -179,25 +177,24 @@ static void fix_audio_pts(struct dec_audio *da) if (!da->current_frame) return; - if (da->current_frame->pts != MP_NOPTS_VALUE) { - double newpts = da->current_frame->pts; - + double frame_pts = mp_aframe_get_pts(da->current_frame); + if (frame_pts != MP_NOPTS_VALUE) { if (da->pts != MP_NOPTS_VALUE) - MP_STATS(da, "value %f audio-pts-err", da->pts - newpts); + MP_STATS(da, "value %f audio-pts-err", da->pts - frame_pts); // Keep the interpolated timestamp if it doesn't deviate more // than 1 ms from the real one. (MKV rounded timestamps.) - if (da->pts == MP_NOPTS_VALUE || fabs(da->pts - newpts) > 0.001) - da->pts = newpts; + if (da->pts == MP_NOPTS_VALUE || fabs(da->pts - frame_pts) > 0.001) + da->pts = frame_pts; } if (da->pts == MP_NOPTS_VALUE && da->header->missing_timestamps) da->pts = 0; - da->current_frame->pts = da->pts; + mp_aframe_set_pts(da->current_frame, da->pts); if (da->pts != MP_NOPTS_VALUE) - da->pts += da->current_frame->samples / (double)da->current_frame->rate; + da->pts += mp_aframe_duration(da->current_frame); } void audio_work(struct dec_audio *da) @@ -228,11 +225,6 @@ void audio_work(struct dec_audio *da) bool progress = da->ad_driver->receive_frame(da, &da->current_frame); - if (da->current_frame && !mp_audio_config_valid(da->current_frame)) { - talloc_free(da->current_frame); - da->current_frame = NULL; - } - da->current_state = da->current_frame ? DATA_OK : DATA_AGAIN; if (!progress) da->current_state = DATA_EOF; @@ -242,10 +234,11 @@ void audio_work(struct dec_audio *da) bool segment_end = da->current_state == DATA_EOF; if (da->current_frame) { - mp_audio_clip_timestamps(da->current_frame, da->start, da->end); - if (da->current_frame->pts != MP_NOPTS_VALUE && da->start != MP_NOPTS_VALUE) - segment_end = da->current_frame->pts >= da->end; - if (da->current_frame->samples == 0) { + mp_aframe_clip_timestamps(da->current_frame, da->start, da->end); + double frame_pts = mp_aframe_get_pts(da->current_frame); + if (frame_pts != MP_NOPTS_VALUE && da->start != MP_NOPTS_VALUE) + segment_end = frame_pts >= da->end; + if (mp_aframe_get_size(da->current_frame) == 0) { talloc_free(da->current_frame); da->current_frame = NULL; } @@ -280,7 +273,7 @@ void audio_work(struct dec_audio *da) // DATA_WAIT: waiting for demuxer; will receive a wakeup signal // DATA_EOF: end of file, no more frames to be expected // DATA_AGAIN: dropped frame or something similar -int audio_get_frame(struct dec_audio *da, struct mp_audio **out_frame) +int audio_get_frame(struct dec_audio *da, struct mp_aframe **out_frame) { *out_frame = NULL; if (da->current_frame) { |