1 /*
2  * Copyright (C) 2019 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 __EXTRACTOR_H__
18 #define __EXTRACTOR_H__
19 
20 #include <media/NdkMediaExtractor.h>
21 
22 #include "BenchmarkCommon.h"
23 #include "Stats.h"
24 
25 class Extractor {
26   public:
Extractor()27     Extractor()
28         : mFormat(nullptr),
29           mExtractor(nullptr),
30           mStats(nullptr),
31           mFrameBuf{nullptr},
32           mDurationUs{0} {}
33 
~Extractor()34     ~Extractor() {
35         if (mStats) delete mStats;
36     }
37 
38     int32_t initExtractor(int32_t fd, size_t fileSize);
39 
40     int32_t setupTrackFormat(int32_t trackId);
41 
42     void *getCSDSample(AMediaCodecBufferInfo &frameInfo, int32_t csdIndex);
43 
44     int32_t getFrameSample(AMediaCodecBufferInfo &frameInfo);
45 
46     int32_t extract(int32_t trackId);
47 
48     void dumpStatistics(string inputReference, string componentName = "", string statsFile = "");
49 
50     void deInitExtractor();
51 
getFormat()52     AMediaFormat *getFormat() { return mFormat; }
53 
getFrameBuf()54     uint8_t *getFrameBuf() { return mFrameBuf; }
55 
getClipDuration()56     int64_t getClipDuration() { return mDurationUs; }
57 
58   private:
59     AMediaFormat *mFormat;
60     AMediaExtractor *mExtractor;
61     Stats *mStats;
62     uint8_t *mFrameBuf;
63     int64_t mDurationUs;
64 };
65 
66 #endif  // __EXTRACTOR_H__