From 41aefce730efd7da6068b7f61697c65759cd3f84 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 23 Mar 2013 17:49:52 +0100 Subject: audio: switch to libavcodec channel order, use libavresample for mixing Switch the internal channel order to libavcodec's. If the channel number mismatches at some point, use libavresample for up- or downmixing. Remove the old af_pan automatic downmixing. The libavcodec channel order should be equivalent to WAVEFORMATEX order, at least nowadays. reorder_ch.h assumes that WAVEFORMATEX and libavcodec might be different, but all defined channels have the same mappings. Remove the downmixing with af_pan as well as the channel conversion with af_channels from af.c, and prefer af_lavrresample for this. The automatic downmixing behavior should be the same as before (if the --channels option is set to 2, which is the default, the audio output is forced to 2 channels, and libavresample does all downmixing). Note that mpv still can't do channel layouts. It will pick the default channel layout according to the channel count. This will be fixed later by passing down the channel layout as well. af_hrtf depends on the order of the input channels, so reorder to ALSA (for which this code was written). This is better than changing the filter code, which is more risky. ao_pulse can accept waveext order directly, so set that as channel mapping. --- core/mplayer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index 78c3cae3c5..7023b6f8f8 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1562,6 +1562,9 @@ void reinit_audio_chain(struct MPContext *mpctx) mpctx->ao = ao_create(opts, mpctx->input); mpctx->ao->samplerate = opts->force_srate; mpctx->ao->format = opts->audio_output_format; + if (mpctx->sh_audio->channels != opts->audio_output_channels && + opts->audio_output_channels == 2) + mpctx->ao->channels = 2; } ao = mpctx->ao; -- cgit v1.2.3 From 071a8f50b96758ced05e1eef3aba5ce915a56479 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 31 Mar 2013 04:24:53 +0200 Subject: options: add option to prevent decoder audio downmixing Also rename --a52drc to --ad-lavc-ac3drc, and add --ad-lavc-o. --- core/mplayer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index 7023b6f8f8..64c8e9555d 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1562,8 +1562,8 @@ void reinit_audio_chain(struct MPContext *mpctx) mpctx->ao = ao_create(opts, mpctx->input); mpctx->ao->samplerate = opts->force_srate; mpctx->ao->format = opts->audio_output_format; - if (mpctx->sh_audio->channels != opts->audio_output_channels && - opts->audio_output_channels == 2) + // Automatic downmix + if (opts->audio_output_channels == 2 && mpctx->sh_audio->channels != 2) mpctx->ao->channels = 2; } ao = mpctx->ao; -- cgit v1.2.3 From aea2328906fc754c0d0cdea57c60d71522ae99a5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 5 Apr 2013 23:06:22 +0200 Subject: audio/out: switch to channel map This actually breaks audio for 5/6/8 channels. There's no reordering done yet. The actual reordering will be done inside of af_lavrresample and has to be made part of the format negotiation. --- core/mplayer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index 64c8e9555d..3f7df8ef36 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1564,7 +1564,7 @@ void reinit_audio_chain(struct MPContext *mpctx) mpctx->ao->format = opts->audio_output_format; // Automatic downmix if (opts->audio_output_channels == 2 && mpctx->sh_audio->channels != 2) - mpctx->ao->channels = 2; + mp_chmap_from_channels(&mpctx->ao->channels, 2); } ao = mpctx->ao; @@ -1591,7 +1591,7 @@ void reinit_audio_chain(struct MPContext *mpctx) mp_msg(MSGT_CPLAYER, MSGL_INFO, "AO: [%s] %dHz %dch %s (%d bytes per sample)\n", ao->driver->info->short_name, - ao->samplerate, ao->channels, + ao->samplerate, ao->channels.num, af_fmt2str_short(ao->format), af_fmt2bits(ao->format) / 8); mp_msg(MSGT_CPLAYER, MSGL_V, "AO: Description: %s\nAO: Author: %s\n", @@ -2160,7 +2160,7 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize) ptsdiff = written_pts - mpctx->sh_video->pts - mpctx->delay - mpctx->audio_delay; bytes = ptsdiff * bps; - bytes -= bytes % (ao->channels * af_fmt2bits(ao->format) / 8); + bytes -= bytes % (ao->channels.num * af_fmt2bits(ao->format) / 8); // ogg demuxers give packets without timing if (written_pts <= 1 && sh_audio->pts == MP_NOPTS_VALUE) { @@ -2229,7 +2229,7 @@ static int fill_audio_out_buffers(struct MPContext *mpctx, double endpts) bool partial_fill = false; sh_audio_t * const sh_audio = mpctx->sh_audio; bool modifiable_audio_format = !(ao->format & AF_FORMAT_SPECIAL_MASK); - int unitsize = ao->channels * af_fmt2bits(ao->format) / 8; + int unitsize = ao->channels.num * af_fmt2bits(ao->format) / 8; if (mpctx->paused) playsize = 1; // just initialize things (audio pts at least) -- cgit v1.2.3 From 4b5cee4617d0decbf93d06df4f45097fd7e00105 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 6 Apr 2013 22:43:12 +0200 Subject: core: use channel map on demuxer level too This helps passing the channel layout correctly from decoder to audio filter chain. (Because that part "reuses" the demuxer level codec parameters, which is very disgusting.) Note that ffmpeg stuff already passed the channel layout via mp_copy_lav_codec_headers(). So other than easier dealing with the demuxer/decoder parameters mess, there's no real advantage to doing this. Make the --channels option accept a channel map. Since simple numbers map to standard layouts with the given number of channels, this is downwards compatible. Likewise for demux_rawaudio. --- core/mplayer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index 3f7df8ef36..665216921e 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -324,7 +324,7 @@ static void print_file_properties(struct MPContext *mpctx, const char *filename) mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate); mp_msg(MSGT_IDENTIFY, MSGL_INFO, - "ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels); + "ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels.num); start_pts = ds_get_next_pts(mpctx->sh_audio->ds); } if (video_start_pts != MP_NOPTS_VALUE) { @@ -1563,8 +1563,11 @@ void reinit_audio_chain(struct MPContext *mpctx) mpctx->ao->samplerate = opts->force_srate; mpctx->ao->format = opts->audio_output_format; // Automatic downmix - if (opts->audio_output_channels == 2 && mpctx->sh_audio->channels != 2) + if (mp_chmap_is_stereo(&opts->audio_output_channels) && + !mp_chmap_is_stereo(&mpctx->sh_audio->channels)) + { mp_chmap_from_channels(&mpctx->ao->channels, 2); + } } ao = mpctx->ao; -- cgit v1.2.3 From 8bd6bf14bbe034cc198ed9b6ae8f5b871522ab55 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Apr 2013 20:19:13 +0200 Subject: audio: remove useless audio channels from AO, unless requested --- core/mplayer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index 665216921e..e73a384baa 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1584,6 +1584,8 @@ void reinit_audio_chain(struct MPContext *mpctx) if (!ao->initialized) { ao->buffersize = opts->ao_buffersize; ao->encode_lavc_ctx = mpctx->encode_lavc_ctx; + mp_chmap_remove_useless_channels(&ao->channels, + &opts->audio_output_channels); ao_init(ao, opts->audio_driver_list); if (!ao->initialized) { mp_tmsg(MSGT_CPLAYER, MSGL_ERR, -- cgit v1.2.3 From 3b1956608dd5536b9ee226b996d2d69b35bc065b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Apr 2013 01:58:33 +0200 Subject: audio: print channel map additionally to channel count on terminal --- core/mplayer.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'core/mplayer.c') diff --git a/core/mplayer.c b/core/mplayer.c index e73a384baa..bbc000d7cc 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1593,12 +1593,10 @@ void reinit_audio_chain(struct MPContext *mpctx) goto init_error; } ao->buffer.start = talloc_new(ao); - mp_msg(MSGT_CPLAYER, MSGL_INFO, - "AO: [%s] %dHz %dch %s (%d bytes per sample)\n", - ao->driver->info->short_name, - ao->samplerate, ao->channels.num, - af_fmt2str_short(ao->format), - af_fmt2bits(ao->format) / 8); + char *s = mp_audio_fmt_to_str(ao->samplerate, &ao->channels, ao->format); + mp_msg(MSGT_CPLAYER, MSGL_INFO, "AO: [%s] %s\n", + ao->driver->info->short_name, s); + talloc_free(s); mp_msg(MSGT_CPLAYER, MSGL_V, "AO: Description: %s\nAO: Author: %s\n", ao->driver->info->name, ao->driver->info->author); if (strlen(ao->driver->info->comment) > 0) -- cgit v1.2.3