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 is accessed on the Media thread that puts the incoming data in and | |
23 // the Decoder thread that gets the next access unit and eventually removes it | |
24 // 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. | |
30 const AccessUnit* front_unit; | |
31 | |
32 // Configs for the front unit if it is |kConfigChanged|, null otherwise. | |
33 const DemuxerConfigs* configs; | |
34 | |
35 // Number of access units in the queue. | |
36 int length; | |
37 | |
38 // Whether the queue contains End Of Stream. | |
39 bool has_eos; | |
40 | |
41 Info() | |
42 : front_unit(nullptr), configs(nullptr), length(0), has_eos(false) {} | |
43 }; | |
44 | |
45 AccessUnitQueue(); | |
46 ~AccessUnitQueue(); | |
47 | |
48 // Appends the incoming data to the queue. | |
49 void PushBack(const DemuxerData& frames); | |
50 | |
51 // Advances the front position to next unit. Logically the preceding units | |
watk
2015/06/04 20:56:43
s/units/unit
Tima Vaisburd
2015/06/05 04:17:46
Actually s/does/do because there could be several
| |
52 // does not exist, but they can be physically removed later. | |
53 void Advance(); | |
54 | |
55 // Clears the queue. | |
56 void Flush(); | |
57 | |
58 // Looks back for the first key frame and if it exists, sets the current | |
59 // access unit to it and returns true. Otherwise returns false. | |
60 bool SkipToKeyFrame(); | |
61 | |
62 // Returns the information about the queue. | |
63 void GetInfo(Info* info) const; | |
64 | |
65 // For unit tests only. | |
66 size_t NumChunksForTesting() const { return chunks_.size(); } | |
67 | |
68 private: | |
69 // Returns the amount of access units that has not been passed to decoder yet. | |
70 int GetUndecodedAccessUnitLength() const; | |
71 | |
72 // The queue of data chunks. | |
73 typedef std::list< scoped_ptr<DemuxerData> > DataChunkQueue; | |
watk
2015/06/04 20:56:43
Spaces around the template param is unconventional
Tima Vaisburd
2015/06/05 04:17:46
Done.
| |
74 DataChunkQueue chunks_; | |
75 | |
76 // The chunk that contains the current access unit. | |
77 DataChunkQueue::iterator current_chunk_; | |
78 | |
79 // Index of the current access unit within the current chunk. | |
80 size_t index_in_chunk_; | |
81 | |
82 // Indicates that a unit with End Of Stream flag has been appended. | |
83 bool has_eos_; | |
84 | |
85 // The queue works on two threads. | |
watk
2015/06/04 20:56:43
I suggest saying instead what the lock protects.
Tima Vaisburd
2015/06/05 04:17:46
Wrote "The lock protects all fields together".
| |
86 mutable base::Lock lock_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(AccessUnitQueue); | |
89 }; | |
90 | |
91 } // namespace media | |
92 | |
93 #endif // MEDIA_BASE_ANDROID_ACCESS_UNIT_QUEUE_H_ | |
OLD | NEW |