summaryrefslogtreecommitdiffstats
path: root/libmpcodecs/ad_ffmpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmpcodecs/ad_ffmpeg.c')
-rw-r--r--libmpcodecs/ad_ffmpeg.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 9009aaa82c..d2f329c645 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -52,10 +52,13 @@ static int preinit(sh_audio_t *sh)
return 1;
}
+/* Prefer playing audio with the samplerate given in container data
+ * if available, but take number the number of channels and sample format
+ * from the codec, since if the codec isn't using the correct values for
+ * those everything breaks anyway.
+ */
static int setup_format(sh_audio_t *sh_audio, const AVCodecContext *lavc_context)
{
- int broken_srate = 0;
- int samplerate = lavc_context->sample_rate;
int sample_format = sh_audio->sample_format;
switch (lavc_context->sample_fmt) {
case SAMPLE_FMT_U8: sample_format = AF_FORMAT_U8; break;
@@ -65,16 +68,18 @@ static int setup_format(sh_audio_t *sh_audio, const AVCodecContext *lavc_context
default:
mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Unsupported sample format\n");
}
- if(sh_audio->wf){
- // If the decoder uses the wrong number of channels all is lost anyway.
- // sh_audio->channels=sh_audio->wf->nChannels;
- if (lavc_context->codec_id == CODEC_ID_AAC &&
- samplerate == 2*sh_audio->wf->nSamplesPerSec) {
- broken_srate = 1;
- } else if (sh_audio->wf->nSamplesPerSec)
- samplerate=sh_audio->wf->nSamplesPerSec;
- }
+ bool broken_srate = false;
+ int samplerate = lavc_context->sample_rate;
+ int container_samplerate = sh_audio->container_out_samplerate;
+ if (!container_samplerate && sh_audio->wf)
+ container_samplerate = sh_audio->wf->nSamplesPerSec;
+ if (lavc_context->codec_id == CODEC_ID_AAC
+ && samplerate == 2 * container_samplerate)
+ broken_srate = true;
+ else if (container_samplerate)
+ samplerate = container_samplerate;
+
if (lavc_context->channels != sh_audio->channels ||
samplerate != sh_audio->samplerate ||
sample_format != sh_audio->sample_format) {