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

Unified Diff: media/filters/ffmpeg_demuxer.cc

Issue 6648004: DemuxerFactory is born! (Closed)
Patch Set: Responses to scherkus@ CR Created 9 years, 9 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_demuxer.h ('k') | media/filters/ffmpeg_demuxer_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_demuxer.cc
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index d482c83a39084918f82eed1361f642b353f2582e..7b4f698805a9b1495cd25f1780bf5f7699fb7101 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -252,7 +252,9 @@ FFmpegDemuxer::FFmpegDemuxer(MessageLoop* message_loop)
read_event_(false, false),
read_has_failed_(false),
last_read_bytes_(0),
- read_position_(0) {
+ read_position_(0),
+ max_duration_(base::TimeDelta::FromMicroseconds(-1)),
+ deferred_status_(PIPELINE_OK) {
DCHECK(message_loop_);
}
@@ -315,8 +317,20 @@ void FFmpegDemuxer::OnAudioRendererDisabled() {
NewRunnableMethod(this, &FFmpegDemuxer::DisableAudioStreamTask));
}
+void FFmpegDemuxer::set_host(FilterHost* filter_host) {
+ Demuxer::set_host(filter_host);
+ if (data_source_)
+ data_source_->set_host(filter_host);
+ if (max_duration_.InMicroseconds() >= 0)
+ host()->SetDuration(max_duration_);
+ if (read_position_ > 0)
+ host()->SetCurrentReadPosition(read_position_);
+ if (deferred_status_ != PIPELINE_OK)
+ host()->SetError(deferred_status_);
+}
+
void FFmpegDemuxer::Initialize(DataSource* data_source,
- FilterCallback* callback) {
+ PipelineStatusCallback* callback) {
message_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this,
@@ -358,7 +372,10 @@ int FFmpegDemuxer::Read(int size, uint8* data) {
// let FFmpeg demuxer methods to run on.
size_t last_read_bytes = WaitForRead();
if (last_read_bytes == DataSource::kReadError) {
- host()->SetError(PIPELINE_ERROR_READ);
+ if (host())
+ host()->SetError(PIPELINE_ERROR_READ);
+ else
+ deferred_status_ = PIPELINE_ERROR_READ;
// Returns with a negative number to signal an error to FFmpeg.
read_has_failed_ = true;
@@ -366,7 +383,8 @@ int FFmpegDemuxer::Read(int size, uint8* data) {
}
read_position_ += last_read_bytes;
- host()->SetCurrentReadPosition(read_position_);
+ if (host())
+ host()->SetCurrentReadPosition(read_position_);
return last_read_bytes;
}
@@ -405,11 +423,13 @@ MessageLoop* FFmpegDemuxer::message_loop() {
}
void FFmpegDemuxer::InitializeTask(DataSource* data_source,
- FilterCallback* callback) {
+ PipelineStatusCallback* callback) {
DCHECK_EQ(MessageLoop::current(), message_loop_);
- scoped_ptr<FilterCallback> c(callback);
+ scoped_ptr<PipelineStatusCallback> callback_deleter(callback);
data_source_ = data_source;
+ if (host())
+ data_source_->set_host(host());
// Add ourself to Protocol list and get our unique key.
std::string key = FFmpegGlue::GetInstance()->AddProtocol(this);
@@ -423,8 +443,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
FFmpegGlue::GetInstance()->RemoveProtocol(this);
if (result < 0) {
- host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN);
- callback->Run();
+ callback->Run(DEMUXER_ERROR_COULD_NOT_OPEN);
return;
}
@@ -434,8 +453,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
// Fully initialize AVFormatContext by parsing the stream a little.
result = av_find_stream_info(format_context_);
if (result < 0) {
- host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE);
- callback->Run();
+ callback->Run(DEMUXER_ERROR_COULD_NOT_PARSE);
return;
}
@@ -466,8 +484,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
}
}
if (streams_.empty()) {
- host()->SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
- callback->Run();
+ callback->Run(DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
return;
}
if (format_context_->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) {
@@ -485,8 +502,10 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
}
// Good to go: set the duration and notify we're done initializing.
- host()->SetDuration(max_duration);
- callback->Run();
+ if (host())
+ host()->SetDuration(max_duration);
+ max_duration_ = max_duration;
+ callback->Run(PIPELINE_OK);
}
void FFmpegDemuxer::SeekTask(base::TimeDelta time, FilterCallback* callback) {
@@ -574,7 +593,9 @@ void FFmpegDemuxer::StopTask(FilterCallback* callback) {
for (iter = streams_.begin(); iter != streams_.end(); ++iter) {
(*iter)->Stop();
}
- if (callback) {
+ if (data_source_) {
+ data_source_->Stop(callback);
+ } else {
callback->Run();
delete callback;
}
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | media/filters/ffmpeg_demuxer_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698