blob: 2263234d50c10f66e18108d2bb045c6063ab6bfd [file] [log] [blame]
[email protected]7ca882dc2012-12-07 23:55:191// 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.
4
5#ifndef MEDIA_BASE_DECODER_BUFFER_QUEUE_H_
6#define MEDIA_BASE_DECODER_BUFFER_QUEUE_H_
7
avi1323b9c22015-12-23 06:22:368#include <stddef.h>
9
Brett Wilson3137bc12017-09-19 22:23:3710#include "base/containers/circular_deque.h"
avia82b9b52015-12-19 04:27:0811#include "base/macros.h"
[email protected]7ca882dc2012-12-07 23:55:1912#include "base/memory/ref_counted.h"
[email protected]7e72e7b2013-06-28 05:40:1013#include "base/time/time.h"
[email protected]7ca882dc2012-12-07 23:55:1914#include "media/base/media_export.h"
15
16namespace media {
17
18class DecoderBuffer;
19
20// Maintains a queue of DecoderBuffers in increasing timestamp order.
21//
22// Individual buffer durations are ignored when calculating the duration of the
23// queue i.e., the queue must have at least 2 in-order buffers to calculate
24// duration.
25//
26// Not thread safe: access must be externally synchronized.
27class MEDIA_EXPORT DecoderBufferQueue {
28 public:
29 DecoderBufferQueue();
30 ~DecoderBufferQueue();
31
32 // Push |buffer| to the end of the queue. If |buffer| is queued out of order
33 // it will be excluded from duration calculations.
34 //
35 // It is invalid to push an end-of-stream |buffer|.
Dale Curtisca8ad982018-04-09 20:23:1436 void Push(scoped_refptr<DecoderBuffer> buffer);
[email protected]7ca882dc2012-12-07 23:55:1937
38 // Pops a DecoderBuffer from the front of the queue.
39 //
40 // It is invalid to call Pop() on an empty queue.
41 scoped_refptr<DecoderBuffer> Pop();
42
43 // Removes all queued buffers.
44 void Clear();
45
46 // Returns true if this queue is empty.
47 bool IsEmpty();
48
49 // Returns the duration of encoded data stored in this queue as measured by
50 // the timestamps of the earliest and latest buffers, ignoring out of order
51 // buffers.
52 //
53 // Returns zero if the queue is empty.
54 base::TimeDelta Duration();
55
[email protected]ac275752014-02-20 16:13:2456 // Returns the total size of buffers inside the queue.
57 size_t data_size() const { return data_size_; }
58
[email protected]7ca882dc2012-12-07 23:55:1959 private:
Brett Wilson3137bc12017-09-19 22:23:3760 using Queue = base::circular_deque<scoped_refptr<DecoderBuffer>>;
[email protected]7ca882dc2012-12-07 23:55:1961 Queue queue_;
62
63 // A subset of |queue_| that contains buffers that are in strictly
64 // increasing timestamp order. Used to calculate Duration() while ignoring
65 // out-of-order buffers.
66 Queue in_order_queue_;
67
68 base::TimeDelta earliest_valid_timestamp_;
69
[email protected]ac275752014-02-20 16:13:2470 // Total size in bytes of buffers in the queue.
71 size_t data_size_;
72
[email protected]7ca882dc2012-12-07 23:55:1973 DISALLOW_COPY_AND_ASSIGN(DecoderBufferQueue);
74};
75
76} // namespace media
77
78#endif // MEDIA_BASE_DECODER_BUFFER_QUEUE_H_