1 /*
2  * Copyright (C) 2009 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 MEDIA_EXTRACTOR_H_
18 
19 #define MEDIA_EXTRACTOR_H_
20 
21 #include <stdio.h>
22 #include <vector>
23 
24 #include <utils/Errors.h>
25 #include <utils/Log.h>
26 #include <utils/RefBase.h>
27 #include <media/MediaExtractorPluginApi.h>
28 #include <media/MediaExtractorPluginHelper.h>
29 
30 namespace android {
31 
32 class DataSourceBase;
33 class MetaDataBase;
34 struct MediaTrack;
35 
36 
37 class ExtractorAllocTracker {
38 public:
ExtractorAllocTracker()39     ExtractorAllocTracker() {
40         ALOGD("extractor allocated: %p", this);
41     }
~ExtractorAllocTracker()42     virtual ~ExtractorAllocTracker() {
43         ALOGD("extractor freed: %p", this);
44     }
45 };
46 
47 class MediaExtractor
48 // : public ExtractorAllocTracker
49 {
50 public:
51     virtual ~MediaExtractor();
52     virtual size_t countTracks() = 0;
53     virtual MediaTrack *getTrack(size_t index) = 0;
54 
55     enum GetTrackMetaDataFlags {
56         kIncludeExtensiveMetaData = 1
57     };
58     virtual status_t getTrackMetaData(
59             MetaDataBase& meta,
60             size_t index, uint32_t flags = 0) = 0;
61 
62     // Return container specific meta-data. The default implementation
63     // returns an empty metadata object.
64     virtual status_t getMetaData(MetaDataBase& meta) = 0;
65 
66     enum Flags {
67         CAN_SEEK_BACKWARD  = 1,  // the "seek 10secs back button"
68         CAN_SEEK_FORWARD   = 2,  // the "seek 10secs forward button"
69         CAN_PAUSE          = 4,
70         CAN_SEEK           = 8,  // the "seek bar"
71     };
72 
73     // If subclasses do _not_ override this, the default is
74     // CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_SEEK | CAN_PAUSE
75     virtual uint32_t flags() const;
76 
setMediaCas(const uint8_t *,size_t)77     virtual status_t setMediaCas(const uint8_t* /*casToken*/, size_t /*size*/) {
78         return INVALID_OPERATION;
79     }
80 
name()81     virtual const char * name() { return "<unspecified>"; }
82 
83 protected:
84     MediaExtractor();
85 
86 private:
87     MediaExtractor(const MediaExtractor &);
88     MediaExtractor &operator=(const MediaExtractor &);
89 };
90 
91 class MediaExtractorCUnwrapper : public MediaExtractor {
92 public:
93     explicit MediaExtractorCUnwrapper(CMediaExtractor *plugin);
94     virtual size_t countTracks();
95     virtual MediaTrack *getTrack(size_t index);
96     virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags = 0);
97     virtual status_t getMetaData(MetaDataBase& meta);
98     virtual const char * name();
99     virtual uint32_t flags() const;
100     virtual status_t setMediaCas(const uint8_t* casToken, size_t size);
101 protected:
102     virtual ~MediaExtractorCUnwrapper();
103 private:
104     CMediaExtractor *plugin;
105 };
106 
107 }  // namespace android
108 
109 #endif  // MEDIA_EXTRACTOR_H_
110