• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ES_QUEUE_H_
18 
19 #define ES_QUEUE_H_
20 
21 #include <media/stagefright/foundation/ABase.h>
22 #include <utils/Errors.h>
23 #include <utils/List.h>
24 #include <utils/RefBase.h>
25 
26 namespace android {
27 
28 struct ABuffer;
29 class MetaData;
30 
31 struct ElementaryStreamQueue {
32     enum Mode {
33         H264,
34         AAC,
35         AC3,
36         MPEG_AUDIO,
37         MPEG_VIDEO,
38         MPEG4_VIDEO,
39         PCM_AUDIO,
40         METADATA,
41     };
42 
43     enum Flags {
44         // Data appended to the queue is always at access unit boundaries.
45         kFlag_AlignedData = 1,
46     };
47     ElementaryStreamQueue(Mode mode, uint32_t flags = 0);
48 
49     status_t appendData(const void *data, size_t size, int64_t timeUs);
50     void signalEOS();
51     void clear(bool clearFormat);
52 
53     sp<ABuffer> dequeueAccessUnit();
54 
55     sp<MetaData> getFormat();
56 
57 private:
58     struct RangeInfo {
59         int64_t mTimestampUs;
60         size_t mLength;
61     };
62 
63     Mode mMode;
64     uint32_t mFlags;
65     bool mEOSReached;
66 
67     sp<ABuffer> mBuffer;
68     List<RangeInfo> mRangeInfos;
69 
70     sp<MetaData> mFormat;
71 
72     sp<ABuffer> dequeueAccessUnitH264();
73     sp<ABuffer> dequeueAccessUnitAAC();
74     sp<ABuffer> dequeueAccessUnitAC3();
75     sp<ABuffer> dequeueAccessUnitMPEGAudio();
76     sp<ABuffer> dequeueAccessUnitMPEGVideo();
77     sp<ABuffer> dequeueAccessUnitMPEG4Video();
78     sp<ABuffer> dequeueAccessUnitPCMAudio();
79     sp<ABuffer> dequeueAccessUnitMetadata();
80 
81     // consume a logical (compressed) access unit of size "size",
82     // returns its timestamp in us (or -1 if no time information).
83     int64_t fetchTimestamp(size_t size);
84 
85     DISALLOW_EVIL_CONSTRUCTORS(ElementaryStreamQueue);
86 };
87 
88 }  // namespace android
89 
90 #endif  // ES_QUEUE_H_
91