diff options
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.cc | 18 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder.cc | 6 |
2 files changed, 17 insertions, 7 deletions
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 54ff1cc..714d0a9 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -47,17 +47,21 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { // TODO(hclam): Reuse the information provided by the demuxer for now, we may // need to wait until the first buffer is decoded to know the correct // information. - media_format_.SetAsInteger(MediaFormat::kChannels, - ffmpeg_demuxer_stream->av_stream()->codec->channels); + codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; + media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); media_format_.SetAsInteger(MediaFormat::kSampleBits, - ffmpeg_demuxer_stream->av_stream()->codec->bits_per_raw_sample); + codec_context_->bits_per_coded_sample); media_format_.SetAsInteger(MediaFormat::kSampleRate, - ffmpeg_demuxer_stream->av_stream()->codec->sample_rate); + codec_context_->sample_rate); media_format_.SetAsString(MediaFormat::kMimeType, mime_type::kUncompressedAudio); - // Grab the codec context from ffmpeg demuxer. - codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; + // Grab the codec context from FFmpeg demuxer. + AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); + if (!codec || avcodec_open(codec_context_, codec) < 0) { + host_->Error(PIPELINE_ERROR_DECODE); + return false; + } // Prepare the output buffer. output_buffer_ = static_cast<uint8*>(av_malloc(kOutputBufferSize)); @@ -93,6 +97,8 @@ void FFmpegAudioDecoder::OnDecode(Buffer* input) { DataBuffer* result_buffer = new DataBuffer(); memcpy(result_buffer->GetWritableData(output_buffer_size), output_buffer_, output_buffer_size); + result_buffer->SetTimestamp(input->GetTimestamp()); + result_buffer->SetDuration(input->GetDuration()); EnqueueResult(result_buffer); } } diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index 69111ff..f5d87bc 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -43,7 +43,11 @@ bool FFmpegVideoDecoder::OnInitialize(DemuxerStream* demuxer_stream) { media_format_.SetAsInteger(MediaFormat::kHeight, height_); codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; - + AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); + if (!codec || avcodec_open(codec_context_, codec) < 0) { + host_->Error(media::PIPELINE_ERROR_DECODE); + return false; + } return true; } |