1 /*
2  * Copyright (C) 2011 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 AAC_ADTS_EXTRACTOR_H_
18 #define AAC_ADTS_EXTRACTOR_H_
19 
20 #include <utils/Vector.h>
21 
22 #include <media/DataSource.h>
23 #include <media/stagefright/foundation/ABuffer.h>
24 #include <media/stagefright/foundation/ADebug.h>
25 #include <media/stagefright/MediaBufferGroup.h>
26 #include <media/stagefright/MediaDefs.h>
27 #include <media/stagefright/MediaErrors.h>
28 #include <media/stagefright/MediaSource.h>
29 #include <media/stagefright/MetaData.h>
30 #include <utils/String8.h>
31 
32 namespace android {
33 
34 struct AMessage;
35 class String8;
36 
37 
38 class AacAdtsSource : public MediaSource {
39 public:
40     AacAdtsSource(const sp<DataSource> &source,
41               const sp<MetaData> &meta,
42               //const Vector<uint64_t> &offset_vector,
43               int64_t frame_duration_us);
44 
45     virtual status_t start(MetaData *params = NULL);
46     virtual status_t stop();
47 
48     virtual sp<MetaData> getFormat();
49 
50     virtual status_t read(
51             MediaBufferBase **buffer, const ReadOptions *options = NULL);
52 
53 protected:
54     virtual ~AacAdtsSource();
55 
56 private:
57     static const size_t kMaxFrameSize;
58     sp<DataSource> mDataSource;
59     sp<MetaData> mMeta;
60 
61     off64_t mOffset;
62     int64_t mCurrentTimeUs;
63     bool mStarted;
64     MediaBufferGroup *mGroup;
65 
66     int64_t mFrameDurationUs;
67 
68     AacAdtsSource(const AacAdtsSource &);
69     AacAdtsSource &operator=(const AacAdtsSource &);
70 };
71 
72 
73 class AacAdtsExtractor : public RefBase {
74 public:
75     explicit AacAdtsExtractor(const sp<DataSource> &source);
76 
77     virtual sp<MediaSource> getTrack(size_t index);
78 
79 
80 protected:
81     virtual ~AacAdtsExtractor();
82 
83 private:
84     sp<DataSource> mDataSource;
85     sp<MetaData> mMeta;
86     status_t mInitCheck;
87 
88     int64_t mFrameDurationUs;
89 
90     AacAdtsExtractor(const AacAdtsExtractor &);
91     AacAdtsExtractor &operator=(const AacAdtsExtractor &);
92 
93 };
94 
95 }  // namespace android
96 
97 #endif  // AAC_ADTS_EXTRACTOR_H_
98