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

Unified Diff: media/filters/ffmpeg_demuxer.cc

Issue 1419753007: Fix race on demuxer memory usage. Reuse previous calculation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restyle. Created 5 years, 1 month 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') | no next file » | 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 7b843963f276b9c4877d823dc6a537f465696153..81bd2e9981b01bcec2026b5d2834ee96b726ca8f 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -742,6 +742,7 @@ FFmpegDemuxer::FFmpegDemuxer(
text_enabled_(false),
duration_known_(false),
encrypted_media_init_data_cb_(encrypted_media_init_data_cb),
+ stream_memory_usage_(0),
weak_factory_(this) {
DCHECK(task_runner_.get());
DCHECK(data_source_);
@@ -918,12 +919,8 @@ void FFmpegDemuxer::AddTextStreams() {
}
int64_t FFmpegDemuxer::GetMemoryUsage() const {
- int64_t allocation_size = 0;
- for (const auto& stream : streams_) {
- if (stream)
- allocation_size += stream->MemoryUsage();
- }
- return allocation_size;
+ base::AutoLock locker(stream_memory_usage_lock_);
+ return stream_memory_usage_;
}
// Helper for calculating the bitrate of the media based on information stored
@@ -1376,10 +1373,15 @@ void FFmpegDemuxer::OnReadFrameDone(ScopedAVPacket packet, int result) {
return;
}
+ // Max allowed memory usage, all streams combined.
+ const int64_t kDemuxerMemoryLimit = 150 * 1024 * 1024;
+ const bool is_max_memory_usage_reached =
+ UpdateMemoryUsage() > kDemuxerMemoryLimit;
+
// Consider the stream as ended if:
// - either underlying ffmpeg returned an error
// - or FFMpegDemuxer reached the maximum allowed memory usage.
- if (result < 0 || IsMaxMemoryUsageReached()) {
+ if (result < 0 || is_max_memory_usage_reached) {
// Update the duration based on the highest elapsed time across all streams
// if it was previously unknown.
if (!duration_known_) {
@@ -1445,24 +1447,16 @@ bool FFmpegDemuxer::StreamsHaveAvailableCapacity() {
return false;
}
-bool FFmpegDemuxer::IsMaxMemoryUsageReached() const {
+int64_t FFmpegDemuxer::UpdateMemoryUsage() {
DCHECK(task_runner_->BelongsToCurrentThread());
- // Max allowed memory usage, all streams combined.
- const size_t kDemuxerMemoryLimit = 150 * 1024 * 1024;
-
- size_t memory_left = kDemuxerMemoryLimit;
- for (StreamVector::const_iterator iter = streams_.begin();
- iter != streams_.end(); ++iter) {
- if (!(*iter))
- continue;
-
- size_t stream_memory_usage = (*iter)->MemoryUsage();
- if (stream_memory_usage > memory_left)
- return true;
- memory_left -= stream_memory_usage;
+ base::AutoLock locker(stream_memory_usage_lock_);
+ stream_memory_usage_ = 0;
+ for (const auto& stream : streams_) {
+ if (stream)
+ stream_memory_usage_ += stream->MemoryUsage();
}
- return false;
+ return stream_memory_usage_;
}
void FFmpegDemuxer::StreamHasEnded() {
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698