summaryrefslogtreecommitdiffstats
path: root/player/lavfi.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/lavfi.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/lavfi.c')
-rw-r--r--player/lavfi.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/player/lavfi.c b/player/lavfi.c
index ee0ca281e4..e5bfe7fdf5 100644
--- a/player/lavfi.c
+++ b/player/lavfi.c
@@ -37,7 +37,8 @@
#include "common/av_common.h"
#include "common/msg.h"
-#include "audio/audio.h"
+#include "audio/format.h"
+#include "audio/aframe.h"
#include "video/mp_image.h"
#include "audio/fmt-conversion.h"
#include "video/fmt-conversion.h"
@@ -96,7 +97,7 @@ struct lavfi_pad {
// 1-frame queue (used for both input and output)
struct mp_image *pending_v;
- struct mp_audio *pending_a;
+ struct mp_aframe *pending_a;
// -- dir==LAVFI_IN
@@ -107,7 +108,7 @@ struct lavfi_pad {
// used to check for format changes manually
struct mp_image *in_fmt_v;
- struct mp_audio in_fmt_a;
+ struct mp_aframe *in_fmt_a;
// -- dir==LAVFI_OUT
@@ -199,7 +200,7 @@ static void free_graph(struct lavfi *c)
pad->filter_pad = -1;
pad->buffer = NULL;
TA_FREEP(&pad->in_fmt_v);
- pad->in_fmt_a = (struct mp_audio){0};
+ TA_FREEP(&pad->in_fmt_a);
pad->buffer_is_eof = false;
pad->input_needed = false;
pad->input_waiting = false;
@@ -312,9 +313,14 @@ static void send_global_eof(struct lavfi *c)
// libavfilter allows changing some parameters on the fly, but not
// others.
-static bool is_aformat_ok(struct mp_audio *a, struct mp_audio *b)
+static bool is_aformat_ok(struct mp_aframe *a, struct mp_aframe *b)
{
- return mp_audio_config_equals(a, b);
+ struct mp_chmap ca = {0}, cb = {0};
+ mp_aframe_get_chmap(a, &ca);
+ mp_aframe_get_chmap(b, &cb);
+ return mp_chmap_equals(&ca, &cb) &&
+ mp_aframe_get_rate(a) == mp_aframe_get_rate(b) &&
+ mp_aframe_get_format(a) == mp_aframe_get_format(b);
}
static bool is_vformat_ok(struct mp_image *a, struct mp_image *b)
{
@@ -331,9 +337,9 @@ static void check_format_changes(struct lavfi *c)
if (!pad->buffer || pad->dir != LAVFI_IN)
continue;
- if (pad->type == STREAM_AUDIO && pad->pending_a && pad->in_fmt_a.format) {
+ if (pad->type == STREAM_AUDIO && pad->pending_a && pad->in_fmt_a) {
c->draining_new_format |= !is_aformat_ok(pad->pending_a,
- &pad->in_fmt_a);
+ pad->in_fmt_a);
}
if (pad->type == STREAM_VIDEO && pad->pending_v && pad->in_fmt_v) {
c->draining_new_format |= !is_vformat_ok(pad->pending_v,
@@ -389,7 +395,10 @@ static bool init_pads(struct lavfi *c)
if (pad->pending_a) {
assert(pad->type == STREAM_AUDIO);
- mp_audio_copy_config(&pad->in_fmt_a, pad->pending_a);
+ pad->in_fmt_a = mp_aframe_new_ref(pad->pending_a);
+ if (!pad->in_fmt_a)
+ goto error;
+ mp_aframe_unref_data(pad->in_fmt_a);
} else if (pad->pending_v) {
assert(pad->type == STREAM_VIDEO);
pad->in_fmt_v = mp_image_new_ref(pad->pending_v);
@@ -400,9 +409,11 @@ static bool init_pads(struct lavfi *c)
// libavfilter makes this painful. Init it with a dummy config,
// just so we can tell it the stream is EOF.
if (pad->type == STREAM_AUDIO) {
- mp_audio_set_format(&pad->in_fmt_a, AF_FORMAT_FLOAT);
- mp_audio_set_num_channels(&pad->in_fmt_a, 2);
- pad->in_fmt_a.rate = 48000;
+ pad->in_fmt_a = mp_aframe_create();
+ mp_aframe_set_format(pad->in_fmt_a, AF_FORMAT_FLOAT);
+ mp_aframe_set_chmap(pad->in_fmt_a,
+ &(struct mp_chmap)MP_CHMAP_INIT_STEREO);
+ mp_aframe_set_rate(pad->in_fmt_a, 48000);
} else if (pad->type == STREAM_VIDEO) {
pad->in_fmt_v = talloc_zero(NULL, struct mp_image);
mp_image_setfmt(pad->in_fmt_v, IMGFMT_420P);
@@ -421,11 +432,13 @@ static bool init_pads(struct lavfi *c)
char *filter_name = NULL;
if (pad->type == STREAM_AUDIO) {
params->time_base = pad->timebase =
- (AVRational){1, pad->in_fmt_a.rate};
- params->format = af_to_avformat(pad->in_fmt_a.format);
- params->sample_rate = pad->in_fmt_a.rate;
- params->channel_layout =
- mp_chmap_to_lavc(&pad->in_fmt_a.channels);
+ (AVRational){1, mp_aframe_get_rate(pad->in_fmt_a)};
+ params->format =
+ af_to_avformat(mp_aframe_get_format(pad->in_fmt_a));
+ params->sample_rate = mp_aframe_get_rate(pad->in_fmt_a);
+ struct mp_chmap chmap = {0};
+ mp_aframe_get_chmap(pad->in_fmt_a, &chmap);
+ params->channel_layout = mp_chmap_to_lavc(&chmap);
filter_name = "abuffer";
} else if (pad->type == STREAM_VIDEO) {
params->time_base = pad->timebase = AV_TIME_BASE_Q;
@@ -565,8 +578,8 @@ static void feed_input_pads(struct lavfi *c)
frame = mp_image_to_av_frame_and_unref(pad->pending_v);
pad->pending_v = NULL;
} else if (pad->pending_a) {
- pts = pad->pending_a->pts;
- frame = mp_audio_to_avframe_and_unref(pad->pending_a);
+ pts = mp_aframe_get_pts(pad->pending_a);
+ frame = mp_aframe_to_avframe_and_unref(pad->pending_a);
pad->pending_a = NULL;
} else {
if (!pad->input_eof) {
@@ -621,9 +634,9 @@ static void read_output_pads(struct lavfi *c)
pad->output_needed = false;
double pts = mp_pts_from_av(c->tmp_frame->pts, &pad->timebase);
if (pad->type == STREAM_AUDIO) {
- pad->pending_a = mp_audio_from_avframe(c->tmp_frame);
+ pad->pending_a = mp_aframe_from_avframe(c->tmp_frame);
if (pad->pending_a)
- pad->pending_a->pts = pts;
+ mp_aframe_set_pts(pad->pending_a, pts);
} else if (pad->type == STREAM_VIDEO) {
pad->pending_v = mp_image_from_av_frame(c->tmp_frame);
if (pad->pending_v)
@@ -733,7 +746,7 @@ static int lavfi_request_frame(struct lavfi_pad *pad)
// DATA_STARVE: needs more input data
// DATA_WAIT: needs more input data, and all inputs in LAVFI_WAIT state
// DATA_EOF: no more data
-int lavfi_request_frame_a(struct lavfi_pad *pad, struct mp_audio **out_aframe)
+int lavfi_request_frame_a(struct lavfi_pad *pad, struct mp_aframe **out_aframe)
{
int r = lavfi_request_frame(pad);
*out_aframe = pad->pending_a;
@@ -787,7 +800,7 @@ static void lavfi_sent_frame(struct lavfi_pad *pad)
}
// See lavfi_send_status() for remarks.
-void lavfi_send_frame_a(struct lavfi_pad *pad, struct mp_audio *aframe)
+void lavfi_send_frame_a(struct lavfi_pad *pad, struct mp_aframe *aframe)
{
assert(pad->type == STREAM_AUDIO);
assert(!pad->pending_a);