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

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: 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/buffers.h" 8 #include "media/base/buffers.h"
9 #include "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
10 10
11 namespace media { 11 namespace media {
12 12
damienv1 2014/02/14 17:23:33 #include <limits>
damienv1 2014/02/18 23:38:03 Done.
13 DecoderBufferQueue::DecoderBufferQueue() 13 DecoderBufferQueue::DecoderBufferQueue()
14 : earliest_valid_timestamp_(kNoTimestamp()) { 14 : earliest_valid_timestamp_(kNoTimestamp()),
15 data_size_(0) {
15 } 16 }
16 17
17 DecoderBufferQueue::~DecoderBufferQueue() {} 18 DecoderBufferQueue::~DecoderBufferQueue() {}
18 19
19 void DecoderBufferQueue::Push(const scoped_refptr<DecoderBuffer>& buffer) { 20 void DecoderBufferQueue::Push(const scoped_refptr<DecoderBuffer>& buffer) {
20 CHECK(!buffer->end_of_stream()); 21 CHECK(!buffer->end_of_stream());
21 22
22 queue_.push_back(buffer); 23 queue_.push_back(buffer);
23 24
25 DCHECK_LE(buffer->data_size(), std::numeric_limits<int>::max() - data_size_);
26 data_size_ += buffer->data_size();
27
24 // TODO(scherkus): FFmpeg returns some packets with no timestamp after 28 // TODO(scherkus): FFmpeg returns some packets with no timestamp after
25 // seeking. Fix and turn this into CHECK(). See http://crbug.com/162192 29 // seeking. Fix and turn this into CHECK(). See http://crbug.com/162192
26 if (buffer->timestamp() == kNoTimestamp()) { 30 if (buffer->timestamp() == kNoTimestamp()) {
27 DVLOG(1) << "Buffer has no timestamp"; 31 DVLOG(1) << "Buffer has no timestamp";
28 return; 32 return;
29 } 33 }
30 34
31 if (earliest_valid_timestamp_ == kNoTimestamp()) { 35 if (earliest_valid_timestamp_ == kNoTimestamp()) {
32 earliest_valid_timestamp_ = buffer->timestamp(); 36 earliest_valid_timestamp_ = buffer->timestamp();
33 } 37 }
34 38
35 if (buffer->timestamp() < earliest_valid_timestamp_) { 39 if (buffer->timestamp() < earliest_valid_timestamp_) {
36 DVLOG(1) 40 DVLOG(1)
37 << "Out of order timestamps: " 41 << "Out of order timestamps: "
38 << buffer->timestamp().InMicroseconds() 42 << buffer->timestamp().InMicroseconds()
39 << " vs. " 43 << " vs. "
40 << earliest_valid_timestamp_.InMicroseconds(); 44 << earliest_valid_timestamp_.InMicroseconds();
41 return; 45 return;
42 } 46 }
43 47
44 earliest_valid_timestamp_ = buffer->timestamp(); 48 earliest_valid_timestamp_ = buffer->timestamp();
45 in_order_queue_.push_back(buffer); 49 in_order_queue_.push_back(buffer);
46 } 50 }
47 51
48 scoped_refptr<DecoderBuffer> DecoderBufferQueue::Pop() { 52 scoped_refptr<DecoderBuffer> DecoderBufferQueue::Pop() {
49 scoped_refptr<DecoderBuffer> buffer = queue_.front(); 53 scoped_refptr<DecoderBuffer> buffer = queue_.front();
50 queue_.pop_front(); 54 queue_.pop_front();
51 55
56 data_size_ -= buffer->data_size();
57 DCHECK_GE(data_size_, 0);
58
52 if (!in_order_queue_.empty() && 59 if (!in_order_queue_.empty() &&
53 in_order_queue_.front().get() == buffer.get()) { 60 in_order_queue_.front().get() == buffer.get()) {
54 in_order_queue_.pop_front(); 61 in_order_queue_.pop_front();
55 } 62 }
56 63
57 return buffer; 64 return buffer;
58 } 65 }
59 66
60 void DecoderBufferQueue::Clear() { 67 void DecoderBufferQueue::Clear() {
61 queue_.clear(); 68 queue_.clear();
69 data_size_ = 0;
62 in_order_queue_.clear(); 70 in_order_queue_.clear();
63 earliest_valid_timestamp_ = kNoTimestamp(); 71 earliest_valid_timestamp_ = kNoTimestamp();
64 } 72 }
65 73
66 bool DecoderBufferQueue::IsEmpty() { 74 bool DecoderBufferQueue::IsEmpty() {
67 return queue_.empty(); 75 return queue_.empty();
68 } 76 }
69 77
70 base::TimeDelta DecoderBufferQueue::Duration() { 78 base::TimeDelta DecoderBufferQueue::Duration() {
71 if (in_order_queue_.size() < 2) 79 if (in_order_queue_.size() < 2)
72 return base::TimeDelta(); 80 return base::TimeDelta();
73 81
74 base::TimeDelta start = in_order_queue_.front()->timestamp(); 82 base::TimeDelta start = in_order_queue_.front()->timestamp();
75 base::TimeDelta end = in_order_queue_.back()->timestamp(); 83 base::TimeDelta end = in_order_queue_.back()->timestamp();
76 return end - start; 84 return end - start;
77 } 85 }
78 86
79 } // namespace media 87 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698