[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef MEDIA_BASE_DECODER_BUFFER_QUEUE_H_ |
| 6 | #define MEDIA_BASE_DECODER_BUFFER_QUEUE_H_ |
| 7 | |
avi | 1323b9c2 | 2015-12-23 06:22:36 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
Brett Wilson | 3137bc1 | 2017-09-19 22:23:37 | [diff] [blame] | 10 | #include "base/containers/circular_deque.h" |
avi | a82b9b5 | 2015-12-19 04:27:08 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 7e72e7b | 2013-06-28 05:40:10 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 14 | #include "media/base/media_export.h" |
| 15 | |
| 16 | namespace media { |
| 17 | |
| 18 | class 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. |
| 27 | class 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 Curtis | ca8ad98 | 2018-04-09 20:23:14 | [diff] [blame] | 36 | void Push(scoped_refptr<DecoderBuffer> buffer); |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 37 | |
| 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] | ac27575 | 2014-02-20 16:13:24 | [diff] [blame] | 56 | // Returns the total size of buffers inside the queue. |
| 57 | size_t data_size() const { return data_size_; } |
| 58 | |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 59 | private: |
Brett Wilson | 3137bc1 | 2017-09-19 22:23:37 | [diff] [blame] | 60 | using Queue = base::circular_deque<scoped_refptr<DecoderBuffer>>; |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 61 | 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] | ac27575 | 2014-02-20 16:13:24 | [diff] [blame] | 70 | // Total size in bytes of buffers in the queue. |
| 71 | size_t data_size_; |
| 72 | |
[email protected] | 7ca882dc | 2012-12-07 23:55:19 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(DecoderBufferQueue); |
| 74 | }; |
| 75 | |
| 76 | } // namespace media |
| 77 | |
| 78 | #endif // MEDIA_BASE_DECODER_BUFFER_QUEUE_H_ |