Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [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 | |
| 8 | #include <deque> |
| 9 | |
| 10 | #include "base/memory/ref_counted.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 11 | #include "base/time/time.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "media/base/media_export.h" |
| 13 | |
| 14 | namespace media { |
| 15 | |
| 16 | class DecoderBuffer; |
| 17 | |
| 18 | // Maintains a queue of DecoderBuffers in increasing timestamp order. |
| 19 | // |
| 20 | // Individual buffer durations are ignored when calculating the duration of the |
| 21 | // queue i.e., the queue must have at least 2 in-order buffers to calculate |
| 22 | // duration. |
| 23 | // |
| 24 | // Not thread safe: access must be externally synchronized. |
| 25 | class MEDIA_EXPORT DecoderBufferQueue { |
| 26 | public: |
| 27 | DecoderBufferQueue(); |
| 28 | ~DecoderBufferQueue(); |
| 29 | |
| 30 | // Push |buffer| to the end of the queue. If |buffer| is queued out of order |
| 31 | // it will be excluded from duration calculations. |
| 32 | // |
| 33 | // It is invalid to push an end-of-stream |buffer|. |
| 34 | void Push(const scoped_refptr<DecoderBuffer>& buffer); |
| 35 | |
| 36 | // Pops a DecoderBuffer from the front of the queue. |
| 37 | // |
| 38 | // It is invalid to call Pop() on an empty queue. |
| 39 | scoped_refptr<DecoderBuffer> Pop(); |
| 40 | |
| 41 | // Removes all queued buffers. |
| 42 | void Clear(); |
| 43 | |
| 44 | // Returns true if this queue is empty. |
| 45 | bool IsEmpty(); |
| 46 | |
| 47 | // Returns the duration of encoded data stored in this queue as measured by |
| 48 | // the timestamps of the earliest and latest buffers, ignoring out of order |
| 49 | // buffers. |
| 50 | // |
| 51 | // Returns zero if the queue is empty. |
| 52 | base::TimeDelta Duration(); |
| 53 | |
| 54 | private: |
| 55 | typedef std::deque<scoped_refptr<DecoderBuffer> > Queue; |
| 56 | Queue queue_; |
| 57 | |
| 58 | // A subset of |queue_| that contains buffers that are in strictly |
| 59 | // increasing timestamp order. Used to calculate Duration() while ignoring |
| 60 | // out-of-order buffers. |
| 61 | Queue in_order_queue_; |
| 62 | |
| 63 | base::TimeDelta earliest_valid_timestamp_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(DecoderBufferQueue); |
| 66 | }; |
| 67 | |
| 68 | } // namespace media |
| 69 | |
| 70 | #endif // MEDIA_BASE_DECODER_BUFFER_QUEUE_H_ |