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

Side by Side Diff: media/base/decoder_buffer_queue.cc

Issue 164233005: Cap the memory usage in FFMpegDemuxer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert to IsMaxMemoryUsage api style in FFMpegDemuxer. Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/decoder_buffer_queue.h" 5 #include "media/base/decoder_buffer_queue.h"
6 6
7 #include <limits>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "media/base/buffers.h" 10 #include "media/base/buffers.h"
9 #include "media/base/decoder_buffer.h" 11 #include "media/base/decoder_buffer.h"
10 12
11 namespace media { 13 namespace media {
12 14
13 DecoderBufferQueue::DecoderBufferQueue() 15 DecoderBufferQueue::DecoderBufferQueue()
14 : earliest_valid_timestamp_(kNoTimestamp()) { 16 : earliest_valid_timestamp_(kNoTimestamp()),
17 data_size_(0) {
15 } 18 }
16 19
17 DecoderBufferQueue::~DecoderBufferQueue() {} 20 DecoderBufferQueue::~DecoderBufferQueue() {}
18 21
19 void DecoderBufferQueue::Push(const scoped_refptr<DecoderBuffer>& buffer) { 22 void DecoderBufferQueue::Push(const scoped_refptr<DecoderBuffer>& buffer) {
20 CHECK(!buffer->end_of_stream()); 23 CHECK(!buffer->end_of_stream());
21 24
22 queue_.push_back(buffer); 25 queue_.push_back(buffer);
23 26
27 DCHECK_LE(buffer->data_size(), std::numeric_limits<int>::max() - data_size_);
DaleCurtis 2014/02/19 18:59:25 This should be a CHECK(), you may need to CHECK(da
28 data_size_ += buffer->data_size();
29
24 // TODO(scherkus): FFmpeg returns some packets with no timestamp after 30 // TODO(scherkus): FFmpeg returns some packets with no timestamp after
25 // seeking. Fix and turn this into CHECK(). See http://crbug.com/162192 31 // seeking. Fix and turn this into CHECK(). See http://crbug.com/162192
26 if (buffer->timestamp() == kNoTimestamp()) { 32 if (buffer->timestamp() == kNoTimestamp()) {
27 DVLOG(1) << "Buffer has no timestamp"; 33 DVLOG(1) << "Buffer has no timestamp";
28 return; 34 return;
29 } 35 }
30 36
31 if (earliest_valid_timestamp_ == kNoTimestamp()) { 37 if (earliest_valid_timestamp_ == kNoTimestamp()) {
32 earliest_valid_timestamp_ = buffer->timestamp(); 38 earliest_valid_timestamp_ = buffer->timestamp();
33 } 39 }
34 40
35 if (buffer->timestamp() < earliest_valid_timestamp_) { 41 if (buffer->timestamp() < earliest_valid_timestamp_) {
36 DVLOG(1) 42 DVLOG(1)
37 << "Out of order timestamps: " 43 << "Out of order timestamps: "
38 << buffer->timestamp().InMicroseconds() 44 << buffer->timestamp().InMicroseconds()
39 << " vs. " 45 << " vs. "
40 << earliest_valid_timestamp_.InMicroseconds(); 46 << earliest_valid_timestamp_.InMicroseconds();
41 return; 47 return;
42 } 48 }
43 49
44 earliest_valid_timestamp_ = buffer->timestamp(); 50 earliest_valid_timestamp_ = buffer->timestamp();
45 in_order_queue_.push_back(buffer); 51 in_order_queue_.push_back(buffer);
46 } 52 }
47 53
48 scoped_refptr<DecoderBuffer> DecoderBufferQueue::Pop() { 54 scoped_refptr<DecoderBuffer> DecoderBufferQueue::Pop() {
49 scoped_refptr<DecoderBuffer> buffer = queue_.front(); 55 scoped_refptr<DecoderBuffer> buffer = queue_.front();
50 queue_.pop_front(); 56 queue_.pop_front();
51 57
58 data_size_ -= buffer->data_size();
59 DCHECK_GE(data_size_, 0);
60
52 if (!in_order_queue_.empty() && 61 if (!in_order_queue_.empty() &&
53 in_order_queue_.front().get() == buffer.get()) { 62 in_order_queue_.front().get() == buffer.get()) {
54 in_order_queue_.pop_front(); 63 in_order_queue_.pop_front();
55 } 64 }
56 65
57 return buffer; 66 return buffer;
58 } 67 }
59 68
60 void DecoderBufferQueue::Clear() { 69 void DecoderBufferQueue::Clear() {
61 queue_.clear(); 70 queue_.clear();
71 data_size_ = 0;
62 in_order_queue_.clear(); 72 in_order_queue_.clear();
63 earliest_valid_timestamp_ = kNoTimestamp(); 73 earliest_valid_timestamp_ = kNoTimestamp();
64 } 74 }
65 75
66 bool DecoderBufferQueue::IsEmpty() { 76 bool DecoderBufferQueue::IsEmpty() {
67 return queue_.empty(); 77 return queue_.empty();
68 } 78 }
69 79
70 base::TimeDelta DecoderBufferQueue::Duration() { 80 base::TimeDelta DecoderBufferQueue::Duration() {
71 if (in_order_queue_.size() < 2) 81 if (in_order_queue_.size() < 2)
72 return base::TimeDelta(); 82 return base::TimeDelta();
73 83
74 base::TimeDelta start = in_order_queue_.front()->timestamp(); 84 base::TimeDelta start = in_order_queue_.front()->timestamp();
75 base::TimeDelta end = in_order_queue_.back()->timestamp(); 85 base::TimeDelta end = in_order_queue_.back()->timestamp();
76 return end - start; 86 return end - start;
77 } 87 }
78 88
79 } // namespace media 89 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698