Commit ebbe9d76 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Deflake FFmpegDemuxer tests by using RunLoop::QuitClosure.

Almost every DemuxerStream::Read() test was using a bare
base::RunLoop::Run() and later posting as deprecated quit closure for
the current loop. This updates all the tests to use a helper method
which properly sets the RunLoop and explicit QuitClosure.

It also cleans up some log spam and clang  warnings at the same
time.

I'm not sure this actually resolves the linked bug though, I think that
was actually a bug in ffmpeg which has subsequently been fixed in a
later ffmpeg roll.

BUG=996040
R=xhwang

Change-Id: I91e2221da5bb95017c82a255a2676a2a6ce5f944
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919722
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715914}
parent fd370464
...@@ -69,12 +69,12 @@ static base::Time ExtractTimelineOffset( ...@@ -69,12 +69,12 @@ static base::Time ExtractTimelineOffset(
const AVFormatContext* format_context) { const AVFormatContext* format_context) {
if (container == container_names::CONTAINER_WEBM) { if (container == container_names::CONTAINER_WEBM) {
const AVDictionaryEntry* entry = const AVDictionaryEntry* entry =
av_dict_get(format_context->metadata, "creation_time", NULL, 0); av_dict_get(format_context->metadata, "creation_time", nullptr, 0);
base::Time timeline_offset; base::Time timeline_offset;
// FFmpegDemuxerTests assume base::Time::FromUTCString() is used here. // FFmpegDemuxerTests assume base::Time::FromUTCString() is used here.
if (entry != NULL && entry->value != NULL && if (entry != nullptr && entry->value != nullptr &&
base::Time::FromUTCString(entry->value, &timeline_offset)) { base::Time::FromUTCString(entry->value, &timeline_offset)) {
return timeline_offset; return timeline_offset;
} }
...@@ -327,8 +327,8 @@ FFmpegDemuxerStream::FFmpegDemuxerStream( ...@@ -327,8 +327,8 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(
duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration);
if (is_encrypted) { if (is_encrypted) {
AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, AVDictionaryEntry* key =
0); av_dict_get(stream->metadata, "enc_key_id", nullptr, 0);
DCHECK(key); DCHECK(key);
DCHECK(key->value); DCHECK(key->value);
if (!key || !key->value) if (!key || !key->value)
...@@ -398,10 +398,10 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { ...@@ -398,10 +398,10 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
last_packet_dts_ = packet_dts; last_packet_dts_ = packet_dts;
if (waiting_for_keyframe_) { if (waiting_for_keyframe_) {
if (packet->flags & AV_PKT_FLAG_KEY) if (packet->flags & AV_PKT_FLAG_KEY) {
waiting_for_keyframe_ = false; waiting_for_keyframe_ = false;
else { } else {
DLOG(WARNING) << "Dropped non-keyframe pts=" << packet->pts; DVLOG(1) << "Dropped non-keyframe pts=" << packet->pts;
return; return;
} }
} }
...@@ -881,8 +881,8 @@ size_t FFmpegDemuxerStream::MemoryUsage() const { ...@@ -881,8 +881,8 @@ size_t FFmpegDemuxerStream::MemoryUsage() const {
std::string FFmpegDemuxerStream::GetMetadata(const char* key) const { std::string FFmpegDemuxerStream::GetMetadata(const char* key) const {
const AVDictionaryEntry* entry = const AVDictionaryEntry* entry =
av_dict_get(stream_->metadata, key, NULL, 0); av_dict_get(stream_->metadata, key, nullptr, 0);
return (entry == NULL || entry->value == NULL) ? "" : entry->value; return (entry == nullptr || entry->value == nullptr) ? "" : entry->value;
} }
// static // static
...@@ -905,21 +905,15 @@ FFmpegDemuxer::FFmpegDemuxer( ...@@ -905,21 +905,15 @@ FFmpegDemuxer::FFmpegDemuxer(
const MediaTracksUpdatedCB& media_tracks_updated_cb, const MediaTracksUpdatedCB& media_tracks_updated_cb,
MediaLog* media_log, MediaLog* media_log,
bool is_local_file) bool is_local_file)
: host_(NULL), : task_runner_(task_runner),
task_runner_(task_runner),
// FFmpeg has no asynchronous API, so we use base::WaitableEvents inside // FFmpeg has no asynchronous API, so we use base::WaitableEvents inside
// the BlockingUrlProtocol to handle hops to the render thread for network // the BlockingUrlProtocol to handle hops to the render thread for network
// reads and seeks. // reads and seeks.
blocking_task_runner_( blocking_task_runner_(
base::CreateSequencedTaskRunner({base::ThreadPool(), base::MayBlock(), base::CreateSequencedTaskRunner({base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_BLOCKING})), base::TaskPriority::USER_BLOCKING})),
stopped_(false),
pending_read_(false),
data_source_(data_source), data_source_(data_source),
media_log_(media_log), media_log_(media_log),
bitrate_(0),
start_time_(kNoTimestamp),
duration_known_(false),
encrypted_media_init_data_cb_(encrypted_media_init_data_cb), encrypted_media_init_data_cb_(encrypted_media_init_data_cb),
media_tracks_updated_cb_(media_tracks_updated_cb), media_tracks_updated_cb_(media_tracks_updated_cb),
is_local_file_(is_local_file) { is_local_file_(is_local_file) {
...@@ -1035,7 +1029,7 @@ void FFmpegDemuxer::Stop() { ...@@ -1035,7 +1029,7 @@ void FFmpegDemuxer::Stop() {
stream->Stop(); stream->Stop();
} }
data_source_ = NULL; data_source_ = nullptr;
// Invalidate WeakPtrs on |task_runner_|, destruction may happen on another // 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 // thread. We don't need to wait for any outstanding tasks since they will all
...@@ -1146,7 +1140,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::GetFirstEnabledFFmpegStream( ...@@ -1146,7 +1140,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::GetFirstEnabledFFmpegStream(
return stream.get(); return stream.get();
} }
} }
return NULL; return nullptr;
} }
base::TimeDelta FFmpegDemuxer::GetStartTime() const { base::TimeDelta FFmpegDemuxer::GetStartTime() const {
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "media/base/demuxer.h" #include "media/base/demuxer.h"
#include "media/base/pipeline_status.h" #include "media/base/pipeline_status.h"
#include "media/base/text_track_config.h" #include "media/base/text_track_config.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "media/ffmpeg/ffmpeg_deleters.h" #include "media/ffmpeg/ffmpeg_deleters.h"
#include "media/filters/blocking_url_protocol.h" #include "media/filters/blocking_url_protocol.h"
...@@ -337,7 +338,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { ...@@ -337,7 +338,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
// Executes |pending_seek_cb_| with |status| and closes out the async trace. // Executes |pending_seek_cb_| with |status| and closes out the async trace.
void RunPendingSeekCB(PipelineStatus status); void RunPendingSeekCB(PipelineStatus status);
DemuxerHost* host_; DemuxerHost* host_ = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
...@@ -348,13 +349,13 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { ...@@ -348,13 +349,13 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
PipelineStatusCallback init_cb_; PipelineStatusCallback init_cb_;
// Indicates if Stop() has been called. // Indicates if Stop() has been called.
bool stopped_; bool stopped_ = false;
// Tracks if there's an outstanding av_read_frame() operation. // Tracks if there's an outstanding av_read_frame() operation.
// //
// TODO(scherkus): Allow more than one read in flight for higher read // TODO(scherkus): Allow more than one read in flight for higher read
// throughput using demuxer_bench to verify improvements. // throughput using demuxer_bench to verify improvements.
bool pending_read_; bool pending_read_ = false;
// Tracks if there's an outstanding av_seek_frame() operation. Used to discard // Tracks if there's an outstanding av_seek_frame() operation. Used to discard
// results of pre-seek av_read_frame() operations. // results of pre-seek av_read_frame() operations.
...@@ -379,12 +380,12 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { ...@@ -379,12 +380,12 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
MediaLog* media_log_; MediaLog* media_log_;
// Derived bitrate after initialization has completed. // Derived bitrate after initialization has completed.
int bitrate_; int bitrate_ = 0;
// The first timestamp of the audio or video stream, whichever is lower. This // The first timestamp of the audio or video stream, whichever is lower. This
// is used to adjust timestamps so that external consumers always see a zero // is used to adjust timestamps so that external consumers always see a zero
// based timeline. // based timeline.
base::TimeDelta start_time_; base::TimeDelta start_time_ = kNoTimestamp;
// The Time associated with timestamp 0. Set to a null // The Time associated with timestamp 0. Set to a null
// time if the file doesn't have an association to Time. // time if the file doesn't have an association to Time.
...@@ -392,7 +393,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { ...@@ -392,7 +393,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
// Set if we know duration of the audio stream. Used when processing end of // Set if we know duration of the audio stream. Used when processing end of
// stream -- at this moment we definitely know duration. // stream -- at this moment we definitely know duration.
bool duration_known_; bool duration_known_ = false;
base::TimeDelta duration_; base::TimeDelta duration_;
// FFmpegURLProtocol implementation and corresponding glue bits. // FFmpegURLProtocol implementation and corresponding glue bits.
......
This diff is collapsed.
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