summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-11-21 14:52:08 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-11-21 14:52:08 +0200
commit37dbe7f5d07c8b1c4bb8529b87ddca7287ae8bae (patch)
tree91b8209605c657345d255b94a0833ba115ca9327
parent5a3edf4c0769c7e354ab6c9b0be3aa402254ff10 (diff)
downloadmpv-37dbe7f5d07c8b1c4bb8529b87ddca7287ae8bae.tar.bz2
mpv-37dbe7f5d07c8b1c4bb8529b87ddca7287ae8bae.tar.xz
demux_mkv, ad_ffmpeg: use Matroska OutputSamplingFrequency if available
Use the value of the OutputSamplingFrequency element instead of the SamplingFrequency element as the "container samplerate". In most cases this only removes a warning, as those typically differ for SBR AAC files and there was already a special case detecting this in ad_ffmpeg. The implementation adds a new "container_out_samplerate" field to the sh_audio struct. Reusing the existing "samplerate" field and the equivalent inside the 'wf' struct and just setting those to the new value instead would probably work (at least I'm not aware of any codec that would need the original SamplingFrequency for initialization). However using a separate field also avoids some ugliness: the 'wf' struct may not exist (though most demuxers create it), and the 'samplerate' field is overwritten to reflect the final value decided by codec when decoding is first initialized.
-rw-r--r--libmpcodecs/ad_ffmpeg.c27
-rw-r--r--libmpdemux/demux_mkv.c8
-rw-r--r--libmpdemux/stheader.h1
3 files changed, 25 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) {
diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c
index 358f152c16..5e205f7cc2 100644
--- a/libmpdemux/demux_mkv.c
+++ b/libmpdemux/demux_mkv.c
@@ -107,6 +107,7 @@ typedef struct mkv_track {
uint32_t a_formattag;
uint32_t a_channels, a_bps;
float a_sfreq;
+ float a_osfreq;
double default_duration;
@@ -525,6 +526,12 @@ static void parse_trackaudio(struct demuxer *demuxer, struct mkv_track *track,
"[mkv] | + Sampling frequency: %f\n", track->a_sfreq);
} else
track->a_sfreq = 8000;
+ if (audio->n_output_sampling_frequency) {
+ track->a_osfreq = audio->output_sampling_frequency;
+ mp_msg(MSGT_DEMUX, MSGL_V,
+ "[mkv] | + Output sampling frequency: %f\n", track->a_osfreq);
+ } else
+ track->a_osfreq = track->a_sfreq;
if (audio->n_bit_depth) {
track->a_bps = audio->bit_depth;
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n",
@@ -1410,6 +1417,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
sh_a->channels = track->a_channels;
sh_a->wf->nChannels = track->a_channels;
sh_a->samplerate = (uint32_t) track->a_sfreq;
+ sh_a->container_out_samplerate = track->a_osfreq;
sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq;
if (track->a_bps == 0) {
sh_a->samplesize = 2;
diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h
index 35409188d5..4bb2da3ac7 100644
--- a/libmpdemux/stheader.h
+++ b/libmpdemux/stheader.h
@@ -55,6 +55,7 @@ typedef struct sh_audio {
// output format:
int sample_format;
int samplerate;
+ int container_out_samplerate;
int samplesize;
int channels;
int o_bps; // == samplerate*samplesize*channels (uncompr. bytes/sec)