summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_spdif.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_spdif.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_spdif.c')
-rw-r--r--audio/decode/ad_spdif.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 4b3e8149ec..0ca20e5485 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -40,8 +40,9 @@ struct spdifContext {
uint8_t out_buffer[OUTBUF_SIZE];
bool need_close;
bool use_dts_hd;
- struct mp_audio fmt;
- struct mp_audio_pool *pool;
+ struct mp_aframe *fmt;
+ int sstride;
+ struct mp_aframe_pool *pool;
bool got_eof;
struct demux_packet *queued_packet;
};
@@ -84,7 +85,7 @@ static int init(struct dec_audio *da, const char *decoder)
da->priv = spdif_ctx;
spdif_ctx->log = da->log;
spdif_ctx->use_dts_hd = da->opts->dtshd;
- spdif_ctx->pool = mp_audio_pool_create(spdif_ctx);
+ spdif_ctx->pool = mp_aframe_pool_create(spdif_ctx);
if (strcmp(decoder, "spdif_dts_hd") == 0)
spdif_ctx->use_dts_hd = true;
@@ -198,6 +199,9 @@ static int init_filter(struct dec_audio *da, AVPacket *pkt)
AVDictionary *format_opts = NULL;
+ spdif_ctx->fmt = mp_aframe_create();
+ talloc_steal(spdif_ctx, spdif_ctx->fmt);
+
int num_channels = 0;
int sample_format = 0;
int samplerate = 0;
@@ -246,9 +250,14 @@ static int init_filter(struct dec_audio *da, AVPacket *pkt)
default:
abort();
}
- mp_audio_set_num_channels(&spdif_ctx->fmt, num_channels);
- mp_audio_set_format(&spdif_ctx->fmt, sample_format);
- spdif_ctx->fmt.rate = samplerate;
+
+ struct mp_chmap chmap;
+ mp_chmap_from_channels(&chmap, num_channels);
+ mp_aframe_set_chmap(spdif_ctx->fmt, &chmap);
+ mp_aframe_set_format(spdif_ctx->fmt, sample_format);
+ mp_aframe_set_rate(spdif_ctx->fmt, samplerate);
+
+ spdif_ctx->sstride = mp_aframe_get_sstride(spdif_ctx->fmt);
if (avformat_write_header(lavf_ctx, &format_opts) < 0) {
MP_FATAL(da, "libavformat spdif initialization failed.\n");
@@ -279,7 +288,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 spdifContext *spdif_ctx = da->priv;
@@ -308,13 +317,21 @@ static bool receive_frame(struct dec_audio *da, struct mp_audio **out)
goto done;
}
- int samples = spdif_ctx->out_buffer_len / spdif_ctx->fmt.sstride;
- *out = mp_audio_pool_get(spdif_ctx->pool, &spdif_ctx->fmt, samples);
- if (!*out)
+ *out = mp_aframe_new_ref(spdif_ctx->fmt);
+ int samples = spdif_ctx->out_buffer_len / spdif_ctx->sstride;
+ if (mp_aframe_pool_allocate(spdif_ctx->pool, *out, samples) < 0) {
+ TA_FREEP(out);
goto done;
+ }
+
+ uint8_t **data = mp_aframe_get_data_rw(*out);
+ if (!data) {
+ TA_FREEP(out);
+ goto done;
+ }
- memcpy((*out)->planes[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
- (*out)->pts = pts;
+ memcpy(data[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
+ mp_aframe_set_pts(*out, pts);
done:
talloc_free(spdif_ctx->queued_packet);