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