Remove ScrollbarLayerImplBase.
[chromium-blink-merge.git] / media / base / decoder_buffer_queue.cc
blobab24c2dcc252b658d725d86513673a6d581ef705
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
3 // found in the LICENSE file.
5 #include "media/base/decoder_buffer_queue.h"
7 #include "base/logging.h"
8 #include "media/base/buffers.h"
9 #include "media/base/decoder_buffer.h"
11 namespace media {
13 DecoderBufferQueue::DecoderBufferQueue()
14 : earliest_valid_timestamp_(kNoTimestamp()) {
17 DecoderBufferQueue::~DecoderBufferQueue() {}
19 void DecoderBufferQueue::Push(const scoped_refptr<DecoderBuffer>& buffer) {
20 CHECK(!buffer->IsEndOfStream());
22 queue_.push_back(buffer);
24 // TODO(scherkus): FFmpeg returns some packets with no timestamp after
25 // seeking. Fix and turn this into CHECK(). See http://crbug.com/162192
26 if (buffer->GetTimestamp() == kNoTimestamp()) {
27 DVLOG(1) << "Buffer has no timestamp";
28 return;
31 if (earliest_valid_timestamp_ == kNoTimestamp()) {
32 earliest_valid_timestamp_ = buffer->GetTimestamp();
35 if (buffer->GetTimestamp() < earliest_valid_timestamp_) {
36 DVLOG(1)
37 << "Out of order timestamps: "
38 << buffer->GetTimestamp().InMicroseconds()
39 << " vs. "
40 << earliest_valid_timestamp_.InMicroseconds();
41 return;
44 earliest_valid_timestamp_ = buffer->GetTimestamp();
45 in_order_queue_.push_back(buffer);
48 scoped_refptr<DecoderBuffer> DecoderBufferQueue::Pop() {
49 scoped_refptr<DecoderBuffer> buffer = queue_.front();
50 queue_.pop_front();
52 if (!in_order_queue_.empty() &&
53 in_order_queue_.front() == buffer) {
54 in_order_queue_.pop_front();
57 return buffer;
60 void DecoderBufferQueue::Clear() {
61 queue_.clear();
62 in_order_queue_.clear();
63 earliest_valid_timestamp_ = kNoTimestamp();
66 bool DecoderBufferQueue::IsEmpty() {
67 return queue_.empty();
70 base::TimeDelta DecoderBufferQueue::Duration() {
71 if (in_order_queue_.size() < 2)
72 return base::TimeDelta();
74 base::TimeDelta start = in_order_queue_.front()->GetTimestamp();
75 base::TimeDelta end = in_order_queue_.back()->GetTimestamp();
76 return end - start;
79 } // namespace media