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

Unified Diff: media/filters/ffmpeg_demuxer.cc

Issue 2719883005: Revert of Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: Created 3 years, 10 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_unittest.cc » ('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 7919a2e59809a17d1eed5e547c5f1d97f8376b75..f7747e6dbbcafbc81f3d8377849f1d4724d73e48 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -22,8 +22,6 @@
#include "base/strings/stringprintf.h"
#include "base/sys_byteorder.h"
#include "base/task_runner_util.h"
-#include "base/task_scheduler/post_task.h"
-#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "media/audio/sample_rates.h"
@@ -847,13 +845,7 @@
const scoped_refptr<MediaLog>& media_log)
: host_(NULL),
task_runner_(task_runner),
- // FFmpeg has no asynchronous API, so we use base::WaitableEvents inside
- // the BlockingUrlProtocol to handle hops to the render thread for network
- // reads and seeks.
- blocking_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
- base::TaskTraits().MayBlock().WithBaseSyncPrimitives().WithPriority(
- base::TaskPriority::USER_BLOCKING))),
- stopped_(false),
+ blocking_thread_("FFmpegDemuxer"),
pending_read_(false),
data_source_(data_source),
media_log_(media_log),
@@ -874,12 +866,6 @@
// NOTE: This class is not destroyed on |task_runner|, so we must ensure that
// there are no outstanding WeakPtrs by the time we reach here.
DCHECK(!weak_factory_.HasWeakPtrs());
-
- // There may be outstanding tasks in the blocking pool which are trying to use
- // these members, so release them in sequence with any outstanding calls. The
- // earlier call to Abort() on |data_source_| prevents further access to it.
- blocking_task_runner_->DeleteSoon(FROM_HERE, url_protocol_.release());
- blocking_task_runner_->DeleteSoon(FROM_HERE, glue_.release());
}
std::string FFmpegDemuxer::GetDisplayName() const {
@@ -913,8 +899,9 @@
format_context->max_analyze_duration = 60 * AV_TIME_BASE;
// Open the AVFormatContext using our glue layer.
+ CHECK(blocking_thread_.Start());
base::PostTaskAndReplyWithResult(
- blocking_task_runner_.get(), FROM_HERE,
+ blocking_thread_.task_runner().get(), FROM_HERE,
base::Bind(&FFmpegGlue::OpenContext, base::Unretained(glue_.get())),
base::Bind(&FFmpegDemuxer::OnOpenContextDone, weak_factory_.GetWeakPtr(),
status_cb));
@@ -924,7 +911,7 @@
DCHECK(task_runner_->BelongsToCurrentThread());
// If Stop() has been called, then drop this call.
- if (stopped_)
+ if (!blocking_thread_.IsRunning())
return;
// This should only be called after the demuxer has been initialized.
@@ -942,7 +929,7 @@
data_source_->Abort();
// Aborting the read may cause EOF to be marked, undo this.
- blocking_task_runner_->PostTask(
+ blocking_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&UnmarkEndOfStream, glue_->format_context()));
pending_read_ = false;
@@ -962,6 +949,12 @@
data_source_->Stop();
url_protocol_->Abort();
+ // This will block until all tasks complete. Note that after this returns it's
+ // possible for reply tasks (e.g., OnReadFrameDone()) to be queued on this
+ // thread. Each of the reply task methods must check whether we've stopped the
+ // thread and drop their results on the floor.
+ blocking_thread_.Stop();
+
for (const auto& stream : streams_) {
if (stream)
stream->Stop();
@@ -970,9 +963,7 @@
data_source_ = NULL;
// Invalidate WeakPtrs on |task_runner_|, destruction may happen on another
- // thread. We don't need to wait for any outstanding tasks since they will all
- // fail to return after invalidating WeakPtrs.
- stopped_ = true;
+ // thread.
weak_factory_.InvalidateWeakPtrs();
cancel_pending_seek_factory_.InvalidateWeakPtrs();
}
@@ -1031,7 +1022,7 @@
pending_seek_cb_ = cb;
base::PostTaskAndReplyWithResult(
- blocking_task_runner_.get(), FROM_HERE,
+ blocking_thread_.task_runner().get(), FROM_HERE,
base::Bind(&av_seek_frame, glue_->format_context(), seeking_stream->index,
ConvertToTimeBase(seeking_stream->time_base, seek_time),
// Always seek to a timestamp <= to the desired timestamp.
@@ -1168,7 +1159,7 @@
void FFmpegDemuxer::OnOpenContextDone(const PipelineStatusCB& status_cb,
bool result) {
DCHECK(task_runner_->BelongsToCurrentThread());
- if (stopped_) {
+ if (!blocking_thread_.IsRunning()) {
MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state";
status_cb.Run(PIPELINE_ERROR_ABORT);
return;
@@ -1182,17 +1173,20 @@
// Fully initialize AVFormatContext by parsing the stream a little.
base::PostTaskAndReplyWithResult(
- blocking_task_runner_.get(), FROM_HERE,
- base::Bind(&avformat_find_stream_info, glue_->format_context(),
+ blocking_thread_.task_runner().get(),
+ FROM_HERE,
+ base::Bind(&avformat_find_stream_info,
+ glue_->format_context(),
static_cast<AVDictionary**>(NULL)),
base::Bind(&FFmpegDemuxer::OnFindStreamInfoDone,
- weak_factory_.GetWeakPtr(), status_cb));
+ weak_factory_.GetWeakPtr(),
+ status_cb));
}
void FFmpegDemuxer::OnFindStreamInfoDone(const PipelineStatusCB& status_cb,
int result) {
DCHECK(task_runner_->BelongsToCurrentThread());
- if (stopped_ || !data_source_) {
+ if (!blocking_thread_.IsRunning() || !data_source_) {
MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state";
status_cb.Run(PIPELINE_ERROR_ABORT);
return;
@@ -1612,7 +1606,7 @@
DCHECK(task_runner_->BelongsToCurrentThread());
CHECK(!pending_seek_cb_.is_null());
- if (stopped_) {
+ if (!blocking_thread_.IsRunning()) {
MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state";
base::ResetAndReturn(&pending_seek_cb_).Run(PIPELINE_ERROR_ABORT);
return;
@@ -1698,8 +1692,8 @@
DCHECK(task_runner_->BelongsToCurrentThread());
// Make sure we have work to do before reading.
- if (stopped_ || !StreamsHaveAvailableCapacity() || pending_read_ ||
- !pending_seek_cb_.is_null()) {
+ if (!blocking_thread_.IsRunning() || !StreamsHaveAvailableCapacity() ||
+ pending_read_ || !pending_seek_cb_.is_null()) {
return;
}
@@ -1711,9 +1705,11 @@
pending_read_ = true;
base::PostTaskAndReplyWithResult(
- blocking_task_runner_.get(), FROM_HERE,
+ blocking_thread_.task_runner().get(),
+ FROM_HERE,
base::Bind(&av_read_frame, glue_->format_context(), packet_ptr),
- base::Bind(&FFmpegDemuxer::OnReadFrameDone, weak_factory_.GetWeakPtr(),
+ base::Bind(&FFmpegDemuxer::OnReadFrameDone,
+ weak_factory_.GetWeakPtr(),
base::Passed(&packet)));
}
@@ -1722,7 +1718,7 @@
DCHECK(pending_read_);
pending_read_ = false;
- if (stopped_ || !pending_seek_cb_.is_null())
+ if (!blocking_thread_.IsRunning() || !pending_seek_cb_.is_null())
return;
// Consider the stream as ended if:
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | media/filters/ffmpeg_demuxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698