summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-10 15:12:52 +0100
committerwm4 <wm4@nowhere>2015-03-10 15:12:52 +0100
commit5f8b060ec2dde7d0ff5468a5b7499851c22b756d (patch)
tree593321dd494d3bf24727ec7ee3a7631b07b49cc8 /audio
parent574bd127ecadb6d7cbcad9aea2187b05a433dda1 (diff)
downloadmpv-5f8b060ec2dde7d0ff5468a5b7499851c22b756d.tar.bz2
mpv-5f8b060ec2dde7d0ff5468a5b7499851c22b756d.tar.xz
ad_spdif: move frame sizes to a general function
Needed for the next commit. This commit should probably be reverted as soon as we're working with full audio frames internally, instead of "flat" FIFOs.
Diffstat (limited to 'audio')
-rw-r--r--audio/decode/ad_spdif.c8
-rw-r--r--audio/format.c13
-rw-r--r--audio/format.h2
3 files changed, 16 insertions, 7 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index f7891767d2..3da5def868 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -117,13 +117,11 @@ static int init(struct dec_audio *da, const char *decoder)
int samplerate = 0;
switch (stream->codec->codec_id) {
case AV_CODEC_ID_AAC:
- spdif_ctx->iec61937_packet_size = 16384;
sample_format = AF_FORMAT_S_AAC;
samplerate = 48000;
num_channels = 2;
break;
case AV_CODEC_ID_AC3:
- spdif_ctx->iec61937_packet_size = 6144;
sample_format = AF_FORMAT_S_AC3;
samplerate = 48000;
num_channels = 2;
@@ -131,31 +129,26 @@ static int init(struct dec_audio *da, const char *decoder)
case AV_CODEC_ID_DTS:
if (da->opts->dtshd) {
av_dict_set(&format_opts, "dtshd_rate", "768000", 0); // 4*192000
- spdif_ctx->iec61937_packet_size = 32768;
sample_format = AF_FORMAT_S_DTSHD;
samplerate = 192000;
num_channels = 2*4;
} else {
- spdif_ctx->iec61937_packet_size = 32768;
sample_format = AF_FORMAT_S_DTS;
samplerate = 48000;
num_channels = 2;
}
break;
case AV_CODEC_ID_EAC3:
- spdif_ctx->iec61937_packet_size = 24576;
sample_format = AF_FORMAT_S_EAC3;
samplerate = 192000;
num_channels = 2;
break;
case AV_CODEC_ID_MP3:
- spdif_ctx->iec61937_packet_size = 4608;
sample_format = AF_FORMAT_S_MP3;
samplerate = 48000;
num_channels = 2;
break;
case AV_CODEC_ID_TRUEHD:
- spdif_ctx->iec61937_packet_size = 61440;
sample_format = AF_FORMAT_S_TRUEHD;
samplerate = 192000;
num_channels = 8;
@@ -166,6 +159,7 @@ static int init(struct dec_audio *da, const char *decoder)
mp_audio_set_num_channels(&spdif_ctx->fmt, num_channels);
mp_audio_set_format(&spdif_ctx->fmt, sample_format);
spdif_ctx->fmt.rate = samplerate;
+ spdif_ctx->iec61937_packet_size = af_format_sample_alignment(sample_format);
if (avformat_write_header(lavf_ctx, &format_opts) < 0) {
MP_FATAL(da, "libavformat spdif initialization failed.\n");
diff --git a/audio/format.c b/audio/format.c
index 08b369c090..5e83ead1b2 100644
--- a/audio/format.c
+++ b/audio/format.c
@@ -227,3 +227,16 @@ int af_format_conversion_score(int dst_format, int src_format)
score -= 2048; // has to convert float<->int
return score;
}
+
+int af_format_sample_alignment(int format)
+{
+ switch (format) {
+ case AF_FORMAT_S_AAC: return 16384;
+ case AF_FORMAT_S_AC3: return 6144;
+ case AF_FORMAT_S_DTSHD: return 32768;
+ case AF_FORMAT_S_EAC3: return 24576;
+ case AF_FORMAT_S_MP3: return 4608;
+ case AF_FORMAT_S_TRUEHD: return 61440;
+ default: return 1;
+ }
+}
diff --git a/audio/format.h b/audio/format.h
index b3ac0000c8..910b952fd2 100644
--- a/audio/format.h
+++ b/audio/format.h
@@ -125,4 +125,6 @@ void af_fill_silence(void *dst, size_t bytes, int format);
int af_format_conversion_score(int dst_format, int src_format);
+int af_format_sample_alignment(int format);
+
#endif /* MPLAYER_AF_FORMAT_H */