summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-06 22:43:12 +0200
committerwm4 <wm4@nowhere>2013-05-12 21:24:55 +0200
commit4b5cee4617d0decbf93d06df4f45097fd7e00105 (patch)
treeb6d293e86d83ab5c3efd99153aa7a7a134d2937f /demux
parent586b75ad0840e154835ae67c7720b71bd36f8cc9 (diff)
downloadmpv-4b5cee4617d0decbf93d06df4f45097fd7e00105.tar.bz2
mpv-4b5cee4617d0decbf93d06df4f45097fd7e00105.tar.xz
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.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_lavf.c4
-rw-r--r--demux/demux_mkv.c6
-rw-r--r--demux/demux_rawaudio.c13
-rw-r--r--demux/stheader.h5
4 files changed, 16 insertions, 12 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index ba34e7acfa..9bfafe3257 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -341,7 +341,9 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
sh_audio->format = codec->codec_tag;
// probably unneeded
- sh_audio->channels = codec->channels;
+ mp_chmap_from_channels(&sh_audio->channels, codec->channels);
+ if (codec->channel_layout)
+ mp_chmap_from_lavc(&sh_audio->channels, codec->channel_layout);
sh_audio->samplerate = codec->sample_rate;
sh_audio->i_bps = codec->bit_rate / 8;
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index ee39038c77..4452aa9929 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1393,7 +1393,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
sh_a->format = track->a_formattag;
sh_a->wf->wFormatTag = track->a_formattag;
- sh_a->channels = track->a_channels;
+ mp_chmap_from_channels(&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;
@@ -1411,7 +1411,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
free(sh_a->wf);
sh_a->wf = NULL;
} else if (track->a_formattag == 0x0001) { /* PCM || PCM_BE */
- sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2;
+ sh_a->wf->nAvgBytesPerSec = sh_a->channels.num * sh_a->samplerate * 2;
sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
if (!strcmp(track->codec_id, MKV_A_PCM_BE))
sh_a->format = mmioFOURCC('t', 'w', 'o', 's');
@@ -1583,7 +1583,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
char *data = sh_a->codecdata;
memcpy(data + 0, "TTA1", 4);
AV_WL16(data + 4, 1);
- AV_WL16(data + 6, sh_a->channels);
+ AV_WL16(data + 6, sh_a->channels.num);
AV_WL16(data + 8, sh_a->wf->wBitsPerSample);
AV_WL32(data + 10, sh_a->samplerate);
// Bogus: last frame won't be played.
diff --git a/demux/demux_rawaudio.c b/demux/demux_rawaudio.c
index c6aad60806..3cd2500e03 100644
--- a/demux/demux_rawaudio.c
+++ b/demux/demux_rawaudio.c
@@ -31,12 +31,12 @@
#include "audio/format.h"
-static int channels = 2;
+static struct mp_chmap channels = MP_CHMAP_INIT_STEREO;
static int samplerate = 44100;
static int format = AF_FORMAT_S16_NE;
const m_option_t demux_rawaudio_opts[] = {
- { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
+ { "channels", &channels, &m_option_type_chmap, CONF_MIN, 1 },
{ "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL },
{ "format", &format, CONF_TYPE_AFMT, 0, 0, 0, NULL },
{NULL, NULL, 0, 0, 0, 0, NULL}
@@ -55,11 +55,12 @@ static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) {
sh_audio->format = format;
sh_audio->wf = w = malloc(sizeof(*w));
w->wFormatTag = 0;
- w->nChannels = sh_audio->channels = channels;
+ sh_audio->channels = channels;
+ w->nChannels = sh_audio->channels.num;
w->nSamplesPerSec = sh_audio->samplerate = samplerate;
int samplesize = (af_fmt2bits(format) + 7) / 8;
- w->nAvgBytesPerSec = samplerate * samplesize * channels;
- w->nBlockAlign = channels * samplesize;
+ w->nAvgBytesPerSec = samplerate * samplesize * w->nChannels;
+ w->nBlockAlign = w->nChannels * samplesize;
w->wBitsPerSample = 8 * samplesize;
w->cbSize = 0;
@@ -105,7 +106,7 @@ static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,float aud
else
pos = base + (rel_seek_secs*sh_audio->i_bps);
- pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
+ pos -= (pos % (sh_audio->channels.num * sh_audio->samplesize) );
stream_seek(s,pos);
// printf("demux_rawaudio: streamtell=%d\n",(int)stream_tell(demuxer->stream));
}
diff --git a/demux/stheader.h b/demux/stheader.h
index 8d1822c99f..488d94c114 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -23,6 +23,7 @@
#include "codec_tags.h"
+#include "audio/chmap.h"
#include "aviheader.h"
#include "ms_hdr.h"
struct MPOpts;
@@ -108,8 +109,8 @@ typedef struct sh_audio {
int samplerate;
int container_out_samplerate;
int samplesize;
- int channels;
- int o_bps; // == samplerate*samplesize*channels (uncompr. bytes/sec)
+ struct mp_chmap channels;
+ int o_bps; // == samplerate*samplesize*channels.num (uncompr. bytes/sec)
int i_bps; // == bitrate (compressed bytes/sec)
// in buffers:
int audio_in_minsize; // initial size to allocate for a_in_buffer if any