Commit 05022f55 authored by andoma's avatar andoma

Notify the input coder about the number of requested channels.

If the decoder does not fulfill our request, try using lavf's audio_resample().
If that also fails, bail out.



git-svn-id: file:///var/local/repositories/ffmpeg/trunk@11222 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent fd4a667a
...@@ -444,6 +444,7 @@ static void do_audio_out(AVFormatContext *s, ...@@ -444,6 +444,7 @@ static void do_audio_out(AVFormatContext *s,
int size_out, frame_bytes, ret; int size_out, frame_bytes, ret;
AVCodecContext *enc= ost->st->codec; AVCodecContext *enc= ost->st->codec;
AVCodecContext *dec= ist->st->codec;
/* SC: dynamic allocation of buffers */ /* SC: dynamic allocation of buffers */
if (!audio_buf) if (!audio_buf)
...@@ -453,6 +454,20 @@ static void do_audio_out(AVFormatContext *s, ...@@ -453,6 +454,20 @@ static void do_audio_out(AVFormatContext *s,
if (!audio_buf || !audio_out) if (!audio_buf || !audio_out)
return; /* Should signal an error ! */ return; /* Should signal an error ! */
if (enc->channels != dec->channels)
ost->audio_resample = 1;
if (ost->audio_resample && !ost->resample) {
ost->resample = audio_resample_init(enc->channels, dec->channels,
enc->sample_rate, dec->sample_rate);
if (!ost->resample) {
fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
dec->channels, dec->sample_rate,
enc->channels, enc->sample_rate);
exit(1);
}
}
if(audio_sync_method){ if(audio_sync_method){
double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
- av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2); - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
...@@ -1614,38 +1629,8 @@ static int av_encode(AVFormatContext **output_files, ...@@ -1614,38 +1629,8 @@ static int av_encode(AVFormatContext **output_files,
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE)) if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
goto fail; goto fail;
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
if (codec->channels == icodec->channels && icodec->request_channels = codec->channels;
codec->sample_rate == icodec->sample_rate) {
ost->audio_resample = 0;
} else {
if (codec->channels != icodec->channels &&
(icodec->codec_id == CODEC_ID_AC3 ||
icodec->codec_id == CODEC_ID_DTS)) {
/* Special case for 5:1 AC3 and DTS input */
/* and mono or stereo output */
/* Request specific number of channels */
icodec->channels = codec->channels;
if (codec->sample_rate == icodec->sample_rate)
ost->audio_resample = 0;
else {
ost->audio_resample = 1;
}
} else {
ost->audio_resample = 1;
}
}
if(audio_sync_method>1)
ost->audio_resample = 1;
if(ost->audio_resample){
ost->resample = audio_resample_init(codec->channels, icodec->channels,
codec->sample_rate, icodec->sample_rate);
if(!ost->resample){
printf("Can't resample. Aborting.\n");
abort();
}
}
ist->decoding_needed = 1; ist->decoding_needed = 1;
ost->encoding_needed = 1; ost->encoding_needed = 1;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment