Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: media/filters/ffmpeg_video_decoder.cc

Issue 16274005: Separate DemuxerStream and VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win64 Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_video_decoder.cc
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index 8131d07c075ea86f643f7196cb589eeef5e3d216..0911d51e8bccbf770fe15f9c463550758d794175 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -15,7 +15,6 @@
#include "base/strings/string_number_conversions.h"
#include "media/base/bind_to_loop.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/demuxer_stream.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
#include "media/base/pipeline.h"
@@ -61,8 +60,7 @@ FFmpegVideoDecoder::FFmpegVideoDecoder(
weak_factory_(this),
state_(kUninitialized),
codec_context_(NULL),
- av_frame_(NULL),
- demuxer_stream_(NULL) {
+ av_frame_(NULL) {
}
int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context,
@@ -88,7 +86,7 @@ int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context,
codec_context->sample_aspect_ratio.num,
codec_context->sample_aspect_ratio.den);
} else {
- natural_size = demuxer_stream_->video_decoder_config().natural_size();
+ natural_size = config_.natural_size();
}
if (!VideoFrame::IsValidConfig(format, size, gfx::Rect(size), natural_size))
@@ -131,22 +129,22 @@ static void ReleaseVideoBufferImpl(AVCodecContext* s, AVFrame* frame) {
frame->opaque = NULL;
}
-void FFmpegVideoDecoder::Initialize(DemuxerStream* stream,
+void FFmpegVideoDecoder::Initialize(const VideoDecoderConfig& config,
const PipelineStatusCB& status_cb,
const StatisticsCB& statistics_cb) {
DCHECK(message_loop_->BelongsToCurrentThread());
- DCHECK(stream);
DCHECK(read_cb_.is_null());
DCHECK(reset_cb_.is_null());
+ DCHECK(!config.is_encrypted());
FFmpegGlue::InitializeFFmpeg();
weak_this_ = weak_factory_.GetWeakPtr();
- demuxer_stream_ = stream;
+ config_ = config;
statistics_cb_ = statistics_cb;
PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb);
- if (!ConfigureDecoder()) {
+ if (!config.IsValidConfig() || !ConfigureDecoder()) {
initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
return;
}
@@ -156,7 +154,8 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* stream,
initialize_cb.Run(PIPELINE_OK);
}
-void FFmpegVideoDecoder::Read(const ReadCB& read_cb) {
+void FFmpegVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
+ const ReadCB& read_cb) {
DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(!read_cb.is_null());
CHECK_NE(state_, kUninitialized);
@@ -174,7 +173,7 @@ void FFmpegVideoDecoder::Read(const ReadCB& read_cb) {
return;
}
- ReadFromDemuxerStream();
+ DecodeBuffer(buffer);
}
void FFmpegVideoDecoder::Reset(const base::Closure& closure) {
@@ -221,45 +220,6 @@ FFmpegVideoDecoder::~FFmpegVideoDecoder() {
DCHECK(!av_frame_);
}
-void FFmpegVideoDecoder::ReadFromDemuxerStream() {
- DCHECK_NE(state_, kUninitialized);
- DCHECK_NE(state_, kDecodeFinished);
- DCHECK_NE(state_, kError);
- DCHECK(!read_cb_.is_null());
-
- demuxer_stream_->Read(base::Bind(
- &FFmpegVideoDecoder::BufferReady, weak_this_));
-}
-
-void FFmpegVideoDecoder::BufferReady(
- DemuxerStream::Status status,
- const scoped_refptr<DecoderBuffer>& buffer) {
- DCHECK(message_loop_->BelongsToCurrentThread());
- DCHECK_NE(state_, kDecodeFinished);
- DCHECK_NE(state_, kError);
- DCHECK_EQ(status != DemuxerStream::kOk, !buffer.get()) << status;
-
- if (state_ == kUninitialized)
- return;
-
- DCHECK(!read_cb_.is_null());
-
- if (!reset_cb_.is_null()) {
- base::ResetAndReturn(&read_cb_).Run(kOk, NULL);
- DoReset();
- return;
- }
-
- if (status == DemuxerStream::kAborted) {
- base::ResetAndReturn(&read_cb_).Run(kOk, NULL);
- return;
- }
-
- // VideoFrameStream ensures no kConfigChanged is passed to VideoDecoders.
- DCHECK_EQ(status, DemuxerStream::kOk) << status;
- DecodeBuffer(buffer);
-}
-
void FFmpegVideoDecoder::DecodeBuffer(
const scoped_refptr<DecoderBuffer>& buffer) {
DCHECK(message_loop_->BelongsToCurrentThread());
@@ -268,7 +228,7 @@ void FFmpegVideoDecoder::DecodeBuffer(
DCHECK_NE(state_, kError);
DCHECK(reset_cb_.is_null());
DCHECK(!read_cb_.is_null());
- DCHECK(buffer.get());
+ DCHECK(buffer);
// During decode, because reads are issued asynchronously, it is possible to
// receive multiple end of stream buffers since each read is acked. When the
@@ -304,7 +264,7 @@ void FFmpegVideoDecoder::DecodeBuffer(
}
scoped_refptr<VideoFrame> video_frame;
- if (!Decode(buffer, &video_frame)) {
+ if (!FFmpegDecode(buffer, &video_frame)) {
state_ = kError;
base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL);
return;
@@ -325,14 +285,14 @@ void FFmpegVideoDecoder::DecodeBuffer(
return;
}
- ReadFromDemuxerStream();
+ base::ResetAndReturn(&read_cb_).Run(kNotEnoughData, NULL);
return;
}
base::ResetAndReturn(&read_cb_).Run(kOk, video_frame);
}
-bool FFmpegVideoDecoder::Decode(
+bool FFmpegVideoDecoder::FFmpegDecode(
const scoped_refptr<DecoderBuffer>& buffer,
scoped_refptr<VideoFrame>* video_frame) {
DCHECK(video_frame);
@@ -417,24 +377,12 @@ void FFmpegVideoDecoder::ReleaseFFmpegResources() {
}
bool FFmpegVideoDecoder::ConfigureDecoder() {
- const VideoDecoderConfig& config = demuxer_stream_->video_decoder_config();
-
- if (!config.IsValidConfig()) {
- DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString();
- return false;
- }
-
- if (config.is_encrypted()) {
- DLOG(ERROR) << "Encrypted video stream not supported.";
- return false;
- }
-
// Release existing decoder resources if necessary.
ReleaseFFmpegResources();
// Initialize AVCodecContext structure.
codec_context_ = avcodec_alloc_context3(NULL);
- VideoDecoderConfigToAVCodecContext(config, codec_context_);
+ VideoDecoderConfigToAVCodecContext(config_, codec_context_);
// Enable motion vector search (potentially slow), strong deblocking filter
// for damaged macroblocks, and set our error detection sensitivity.
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698