Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_ANDROID_ACCESS_UNIT_QUEUE_H_ | |
| 6 #define MEDIA_BASE_ANDROID_ACCESS_UNIT_QUEUE_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "media/base/android/demuxer_stream_player_params.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 // The queue of incoming data for MediaCodecDecoder. | |
| 18 // | |
| 19 // The data comes in the form of access units. Each access unit has a type. | |
| 20 // If the type is |kConfigChanged| the access unit itself has no data, but | |
| 21 // is accompanied with DemuxerConfigs. | |
| 22 // The queue should be accessed on the Media thread that puts the incoming data | |
| 23 // in and on the Decoder thread that gets the next access unit and eventually | |
| 24 // removes it from the queue. | |
| 25 class AccessUnitQueue { | |
| 26 public: | |
| 27 // Information about the queue state and the access unit at the front. | |
| 28 struct Info { | |
| 29 // The unit at front. Null if the queue is empty. This pointer may be | |
| 30 // invalidated by the next Advance() or Flush() call and must be used | |
| 31 // before the caller calls these methods. | |
|
wolenetz
2015/06/12 22:05:19
nit: Clarify in comment(s) here and/or GetInfo() t
Tima Vaisburd
2015/06/12 22:44:01
Done.
| |
| 32 const AccessUnit* front_unit; | |
| 33 | |
| 34 // Configs for the front unit if it is |kConfigChanged|, null otherwise. | |
| 35 // The same validity rule applies: this pointer is only valid till the next | |
| 36 // Advance() or Flush() call. | |
| 37 const DemuxerConfigs* configs; | |
| 38 | |
| 39 // Number of access units in the queue. | |
| 40 int length; | |
| 41 | |
| 42 // Whether End Of Stream has been added to the queue. Cleared by Flush(). | |
| 43 bool has_eos; | |
| 44 | |
| 45 Info() : front_unit(nullptr), configs(nullptr), length(0), has_eos(false) {} | |
| 46 }; | |
| 47 | |
| 48 AccessUnitQueue(); | |
| 49 ~AccessUnitQueue(); | |
| 50 | |
| 51 // Appends the incoming data to the queue. | |
| 52 void PushBack(const DemuxerData& frames); | |
| 53 | |
| 54 // Advances the front position to next unit. Logically the preceding units | |
| 55 // do not exist, but they can be physically removed later. | |
| 56 void Advance(); | |
| 57 | |
| 58 // Clears the queue, resets the length to zero and clears EOS condition. | |
| 59 void Flush(); | |
| 60 | |
| 61 // Looks back for the first key frame starting from the current one (i.e. | |
| 62 // the look-back is inclusive of the current front position). | |
| 63 // If the key frame exists, sets the current access unit to it and returns | |
| 64 // true. Otherwise returns false. | |
| 65 bool RewindToLastKeyFrame(); | |
| 66 | |
| 67 // Returns the information about the queue. | |
| 68 // The result is invalidated by the following Advance() or Flush call. | |
| 69 // There must be only one |Info| consumer at a time. | |
| 70 Info GetInfo() const; | |
| 71 | |
| 72 // For unit tests only. These methods are not thread safe. | |
| 73 size_t NumChunksForTesting() const { return chunks_.size(); } | |
| 74 void SetHistorySizeForTesting(size_t number_of_history_chunks); | |
| 75 | |
| 76 private: | |
| 77 // Returns the amount of access units between the current one and the end, | |
| 78 // incuding current. Logically these are units that have not been consumed. | |
| 79 int GetUnconsumedAccessUnitLength() const; | |
| 80 | |
| 81 // The queue of data chunks. It owns the chunks. | |
| 82 typedef std::list<DemuxerData*> DataChunkQueue; | |
| 83 DataChunkQueue chunks_; | |
| 84 | |
| 85 // The chunk that contains the current access unit. | |
| 86 DataChunkQueue::iterator current_chunk_; | |
| 87 | |
| 88 // Index of the current access unit within the current chunk. | |
| 89 size_t index_in_chunk_; | |
| 90 | |
| 91 // Amount of chunks before the |current_chunk_| that's kept for history. | |
| 92 size_t history_chunks_amount_; | |
| 93 | |
| 94 // Indicates that a unit with End Of Stream flag has been appended. | |
| 95 bool has_eos_; | |
| 96 | |
| 97 // The lock protects all fields together. | |
| 98 mutable base::Lock lock_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(AccessUnitQueue); | |
| 101 }; | |
| 102 | |
| 103 } // namespace media | |
| 104 | |
| 105 #endif // MEDIA_BASE_ANDROID_ACCESS_UNIT_QUEUE_H_ | |
| OLD | NEW |