diff --git a/libavformat/rmenc.c b/libavformat/rmenc.c index a96c429..2ee159c 100644 --- a/libavformat/rmenc.c +++ b/libavformat/rmenc.c @@ -180,7 +180,7 @@ static int rv10_write_header(AVFormatContext *ctx, avio_wb32(s, codec_data_size); if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { - int coded_frame_size, fscode, sample_rate; + int coded_frame_size, fscode = 0, sample_rate; sample_rate = stream->enc->sample_rate; coded_frame_size = (stream->enc->bit_rate * stream->enc->frame_size) / (8 * sample_rate); @@ -193,22 +193,71 @@ static int rv10_write_header(AVFormatContext *ctx, avio_wb16(s, 4); /* unknown */ avio_wb32(s, 0x39); /* header size */ - switch(sample_rate) { - case 48000: - case 24000: - case 12000: - fscode = 1; - break; - default: - case 44100: - case 22050: - case 11025: - fscode = 2; - break; - case 32000: - case 16000: - case 8000: - fscode = 3; + if (stream->enc->codec_id == AV_CODEC_ID_AC3) { + if (stream->enc->sample_rate == 8000 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 16000) { + fscode = 0; + } else if (stream->enc->sample_rate == 11025 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 15960) { + coded_frame_size++; + fscode = 2; + } else if (stream->enc->sample_rate == 8000 && + stream->enc->channels == 2 && + stream->enc->bit_rate == 20000) { + fscode = 3; + } else if (stream->enc->sample_rate == 22050 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 39960) { + coded_frame_size++; + fscode = 4; + } else if (stream->enc->sample_rate == 16000 && + stream->enc->channels == 2 && + stream->enc->bit_rate == 40000) { + fscode = 5; + } else if (stream->enc->sample_rate == 44100 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 79928) { + coded_frame_size++; + fscode = 6; + } else if (stream->enc->sample_rate == 32000 && + stream->enc->channels == 2 && + stream->enc->bit_rate == 80000) { + fscode = 7; + } else if (stream->enc->sample_rate == 8000 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 8000) { + fscode = 8; + } else if (stream->enc->sample_rate == 8000 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 12000) { + fscode = 9; + } else if (stream->enc->sample_rate == 16000 && + stream->enc->channels == 1 && + stream->enc->bit_rate == 32000) { + fscode = 10; + } else if (stream->enc->sample_rate == 11025 && + stream->enc->channels == 2 && + stream->enc->bit_rate == 31920) { + coded_frame_size++; + fscode = 11; + } else { + av_log(ctx, AV_LOG_ERROR, "unsupported combination of sample rate, audio channels and bit rate\n"); + av_log(ctx, AV_LOG_ERROR, "supported modes are:\n"); + av_log(ctx, AV_LOG_ERROR, " 8000Hz, mono, 8000bps\n"); + av_log(ctx, AV_LOG_ERROR, " 8000Hz, mono, 12000bps\n"); + av_log(ctx, AV_LOG_ERROR, " 8000Hz, mono, 16000bps\n"); + av_log(ctx, AV_LOG_ERROR, " 8000Hz, stereo, 20000bps\n"); + av_log(ctx, AV_LOG_ERROR, "11025Hz, mono, 15960bps\n"); + av_log(ctx, AV_LOG_ERROR, "11025Hz, stereo, 31920bps\n"); + av_log(ctx, AV_LOG_ERROR, "16000Hz, mono, 32000bps\n"); + av_log(ctx, AV_LOG_ERROR, "22050Hz, mono, 39960bps\n"); + av_log(ctx, AV_LOG_ERROR, "16000Hz, stereo, 40000bps\n"); + av_log(ctx, AV_LOG_ERROR, "32000Hz, stereo, 80000bps\n"); + av_log(ctx, AV_LOG_ERROR, "44100Hz, mono, 79928bps\n"); + return AVERROR(EINVAL); + } } avio_wb16(s, fscode); /* codec additional info, for AC-3, seems to be a frequency code */