summaryrefslogtreecommitdiffstats
path: root/player/audio.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 /player/audio.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 'player/audio.c')
-rw-r--r--player/audio.c57
1 files changed, 37 insertions, 20 deletions
diff --git a/player/audio.c b/player/audio.c
index fcc442b974..25d7baa6af 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -352,6 +352,7 @@ static void ao_chain_uninit(struct ao_chain *ao_c)
af_destroy(ao_c->af);
talloc_free(ao_c->input_frame);
+ talloc_free(ao_c->input_format);
talloc_free(ao_c->ao_buffer);
talloc_free(ao_c);
}
@@ -368,6 +369,18 @@ void uninit_audio_chain(struct MPContext *mpctx)
}
}
+static void get_ao_format(struct ao *ao, struct mp_audio *aformat)
+{
+ int samplerate;
+ int format;
+ struct mp_chmap channels;
+ ao_get_format(ao, &samplerate, &format, &channels);
+ *aformat = (struct mp_audio){0};
+ mp_audio_set_format(aformat, format);
+ mp_audio_set_channels(aformat, &channels);
+ aformat->rate = samplerate;
+}
+
static void reinit_audio_filters_and_output(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
@@ -377,11 +390,9 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx)
struct af_stream *afs = ao_c->af;
if (ao_c->input_frame)
- mp_audio_copy_config(&ao_c->input_format, ao_c->input_frame);
+ mp_aframe_config_copy(ao_c->input_format, ao_c->input_frame);
- struct mp_audio in_format = ao_c->input_format;
-
- if (!mp_audio_config_valid(&in_format)) {
+ if (!mp_aframe_config_is_valid(ao_c->input_format)) {
// We don't know the audio format yet - so configure it later as we're
// resyncing. fill_audio_buffers() will call this function again.
mp_wakeup_core(mpctx);
@@ -390,18 +401,20 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx)
// Weak gapless audio: drain AO on decoder format changes
if (mpctx->ao_decoder_fmt && mpctx->ao && opts->gapless_audio < 0 &&
- !mp_audio_config_equals(mpctx->ao_decoder_fmt, &in_format))
+ !mp_aframe_config_equals(mpctx->ao_decoder_fmt, ao_c->input_format))
{
uninit_audio_out(mpctx);
}
+ struct mp_audio in_format;
+ mp_audio_config_from_aframe(&in_format, ao_c->input_format);
if (mpctx->ao && mp_audio_config_equals(&in_format, &afs->input))
return;
afs->output = (struct mp_audio){0};
if (mpctx->ao) {
- ao_get_format(mpctx->ao, &afs->output);
- } else if (af_fmt_is_pcm(in_format.format)) {
+ get_ao_format(mpctx->ao, &afs->output);
+ } else if (af_fmt_is_pcm(mp_aframe_get_format(ao_c->input_format))) {
afs->output.rate = opts->force_srate;
mp_audio_set_format(&afs->output, opts->audio_output_format);
if (opts->audio_output_channels.num_chmaps == 1) {
@@ -455,7 +468,7 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx)
struct mp_audio fmt = {0};
if (mpctx->ao)
- ao_get_format(mpctx->ao, &fmt);
+ get_ao_format(mpctx->ao, &fmt);
// Verify passthrough format was not changed.
if (mpctx->ao && af_fmt_is_spdif(afs->output.format)) {
@@ -477,7 +490,7 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx)
if (!audio_init_best_codec(ao_c->audio_src))
goto init_error;
reset_audio_state(mpctx);
- ao_c->input_format = (struct mp_audio){0};
+ mp_aframe_reset(ao_c->input_format);
mp_wakeup_core(mpctx); // reinit with new format next time
return;
}
@@ -492,8 +505,8 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx)
if (!mp_audio_config_equals(&afs->output, &afs->filter_output))
afs->initialized = 0;
- mpctx->ao_decoder_fmt = talloc(NULL, struct mp_audio);
- *mpctx->ao_decoder_fmt = in_format;
+ mpctx->ao_decoder_fmt = mp_aframe_create();
+ mp_aframe_config_copy(mpctx->ao_decoder_fmt, ao_c->input_format);
MP_INFO(mpctx, "AO: [%s] %s\n", ao_get_name(mpctx->ao),
mp_audio_config_to_str(&fmt));
@@ -580,6 +593,7 @@ void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track)
ao_c->pts = MP_NOPTS_VALUE;
ao_c->ao_buffer = mp_audio_buffer_create(NULL);
ao_c->ao = mpctx->ao;
+ ao_c->input_format = mp_aframe_create();
if (track) {
ao_c->track = track;
@@ -593,7 +607,7 @@ void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track)
if (mpctx->ao) {
struct mp_audio fmt;
- ao_get_format(mpctx->ao, &fmt);
+ get_ao_format(mpctx->ao, &fmt);
mp_audio_buffer_reinit(ao_c->ao_buffer, &fmt);
}
@@ -614,9 +628,7 @@ double written_audio_pts(struct MPContext *mpctx)
if (!ao_c)
return MP_NOPTS_VALUE;
- struct mp_audio in_format = ao_c->input_format;
-
- if (!mp_audio_config_valid(&in_format) || ao_c->af->initialized < 1)
+ if (ao_c->af->initialized < 1)
return MP_NOPTS_VALUE;
// first calculate the end pts of audio that has been output by decoder
@@ -653,7 +665,7 @@ static int write_to_ao(struct MPContext *mpctx, struct mp_audio *data, int flags
return 0;
struct ao *ao = mpctx->ao;
struct mp_audio out_format;
- ao_get_format(ao, &out_format);
+ get_ao_format(ao, &out_format);
#if HAVE_ENCODING
encode_lavc_set_audio_pts(mpctx->encode_lavc_ctx, playing_audio_pts(mpctx));
#endif
@@ -706,7 +718,7 @@ static bool get_sync_samples(struct MPContext *mpctx, int *skip)
return true;
struct mp_audio out_format = {0};
- ao_get_format(mpctx->ao, &out_format);
+ get_ao_format(mpctx->ao, &out_format);
double play_samplerate = out_format.rate / mpctx->audio_speed;
if (!opts->initial_audio_sync) {
@@ -879,14 +891,19 @@ static int filter_audio(struct MPContext *mpctx, struct mp_audio_buffer *outbuf,
}
// On format change, make sure to drain the filter chain.
- if (!mp_audio_config_equals(&afs->input, ao_c->input_frame)) {
+ struct mp_audio in_format;
+ mp_audio_config_from_aframe(&in_format, ao_c->input_format);
+ if (!mp_audio_config_equals(&afs->input, &in_format)) {
copy_output(mpctx, outbuf, minsamples, endpts, true, &eof);
res = AD_NEW_FMT;
break;
}
- struct mp_audio *mpa = ao_c->input_frame;
+ struct mp_audio *mpa = mp_audio_from_aframe(ao_c->input_frame);
+ talloc_free(ao_c->input_frame);
ao_c->input_frame = NULL;
+ if (!mpa)
+ abort();
if (mpa->pts == MP_NOPTS_VALUE) {
ao_c->pts = MP_NOPTS_VALUE;
} else {
@@ -990,7 +1007,7 @@ void fill_audio_out_buffers(struct MPContext *mpctx)
}
struct mp_audio out_format = {0};
- ao_get_format(mpctx->ao, &out_format);
+ get_ao_format(mpctx->ao, &out_format);
double play_samplerate = out_format.rate / mpctx->audio_speed;
int align = af_format_sample_alignment(out_format.format);