summaryrefslogtreecommitdiffstats
path: root/player/command.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/command.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/command.c')
-rw-r--r--player/command.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/player/command.c b/player/command.c
index b023e350c9..51b025cad4 100644
--- a/player/command.c
+++ b/player/command.c
@@ -56,7 +56,7 @@
#include "video/decode/vd.h"
#include "video/out/vo.h"
#include "video/csputils.h"
-#include "audio/audio_buffer.h"
+#include "audio/aframe.h"
#include "audio/out/ao.h"
#include "audio/filter/af.h"
#include "video/decode/dec_video.h"
@@ -2019,17 +2019,20 @@ static int mp_property_audio_codec(void *ctx, struct m_property *prop,
return m_property_strdup_ro(action, arg, c);
}
-static int property_audiofmt(struct mp_audio a, int action, void *arg)
+static int property_audiofmt(struct mp_aframe *fmt, int action, void *arg)
{
- if (!mp_audio_config_valid(&a))
+ if (!fmt || !mp_aframe_config_is_valid(fmt))
return M_PROPERTY_UNAVAILABLE;
+ struct mp_chmap chmap = {0};
+ mp_aframe_get_chmap(fmt, &chmap);
+
struct m_sub_property props[] = {
- {"samplerate", SUB_PROP_INT(a.rate)},
- {"channel-count", SUB_PROP_INT(a.channels.num)},
- {"channels", SUB_PROP_STR(mp_chmap_to_str(&a.channels))},
- {"hr-channels", SUB_PROP_STR(mp_chmap_to_str_hr(&a.channels))},
- {"format", SUB_PROP_STR(af_fmt_to_str(a.format))},
+ {"samplerate", SUB_PROP_INT(mp_aframe_get_rate(fmt))},
+ {"channel-count", SUB_PROP_INT(chmap.num)},
+ {"channels", SUB_PROP_STR(mp_chmap_to_str(&chmap))},
+ {"hr-channels", SUB_PROP_STR(mp_chmap_to_str_hr(&chmap))},
+ {"format", SUB_PROP_STR(af_fmt_to_str(mp_aframe_get_format(fmt)))},
{0}
};
@@ -2040,20 +2043,28 @@ static int mp_property_audio_params(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct mp_audio fmt = {0};
- if (mpctx->ao_chain)
- fmt = mpctx->ao_chain->input_format;
- return property_audiofmt(fmt, action, arg);
+ return property_audiofmt(mpctx->ao_chain ? mpctx->ao_chain->input_format : NULL,
+ action, arg);
}
static int mp_property_audio_out_params(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct mp_audio fmt = {0};
- if (mpctx->ao)
- ao_get_format(mpctx->ao, &fmt);
- return property_audiofmt(fmt, action, arg);
+ struct mp_aframe *frame = NULL;
+ if (mpctx->ao) {
+ frame = mp_aframe_create();
+ int samplerate;
+ int format;
+ struct mp_chmap channels;
+ ao_get_format(mpctx->ao, &samplerate, &format, &channels);
+ mp_aframe_set_rate(frame, samplerate);
+ mp_aframe_set_format(frame, format);
+ mp_aframe_set_chmap(frame, &channels);
+ }
+ int r = property_audiofmt(frame, action, arg);
+ talloc_free(frame);
+ return r;
}
/// Balance (RW)