1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

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.
This commit is contained in:
wm4 2015-03-10 15:12:52 +01:00
parent 574bd127ec
commit 5f8b060ec2
3 changed files with 16 additions and 7 deletions

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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 */