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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "MediaExtractor"
19 #include <utils/Log.h>
20 #include <pwd.h>
21 
22 #include <media/stagefright/foundation/ADebug.h>
23 #include <media/stagefright/MediaExtractor.h>
24 #include <media/stagefright/MetaData.h>
25 #include <media/stagefright/Utils.h>
26 #include <media/NdkMediaFormatPriv.h>
27 #include <media/NdkMediaErrorPriv.h>
28 
29 namespace android {
30 
MediaExtractor()31 MediaExtractor::MediaExtractor() {
32     if (!LOG_NDEBUG) {
33         uid_t uid = getuid();
34         struct passwd *pw = getpwuid(uid);
35         ALOGV("extractor created in uid: %d (%s)", getuid(), pw->pw_name);
36     }
37 }
38 
~MediaExtractor()39 MediaExtractor::~MediaExtractor() {}
40 
flags() const41 uint32_t MediaExtractor::flags() const {
42     return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE | CAN_SEEK;
43 }
44 
45 // --------------------------------------------------------------------------------
MediaExtractorCUnwrapper(CMediaExtractor * plugin)46 MediaExtractorCUnwrapper::MediaExtractorCUnwrapper(CMediaExtractor *plugin) {
47     this->plugin = plugin;
48 }
49 
~MediaExtractorCUnwrapper()50 MediaExtractorCUnwrapper::~MediaExtractorCUnwrapper() {
51     plugin->free(plugin->data);
52     free(plugin);
53 }
54 
countTracks()55 size_t MediaExtractorCUnwrapper::countTracks() {
56     return plugin->countTracks(plugin->data);
57 }
58 
getTrack(size_t index)59 MediaTrack *MediaExtractorCUnwrapper::getTrack(size_t index) {
60     return MediaTrackCUnwrapper::create(plugin->getTrack(plugin->data, index));
61 }
62 
getTrackMetaData(MetaDataBase & meta,size_t index,uint32_t flags)63 status_t MediaExtractorCUnwrapper::getTrackMetaData(
64         MetaDataBase& meta, size_t index, uint32_t flags) {
65     sp<AMessage> msg = new AMessage();
66     AMediaFormat *format =  AMediaFormat_fromMsg(&msg);
67     media_status_t ret = plugin->getTrackMetaData(plugin->data, format, index, flags);
68     sp<MetaData> newMeta = new MetaData();
69     convertMessageToMetaData(msg, newMeta);
70     delete format;
71     meta = *newMeta;
72     return reverse_translate_error(ret);
73 }
74 
getMetaData(MetaDataBase & meta)75 status_t MediaExtractorCUnwrapper::getMetaData(MetaDataBase& meta) {
76     sp<AMessage> msg = new AMessage();
77     AMediaFormat *format =  AMediaFormat_fromMsg(&msg);
78     media_status_t ret = plugin->getMetaData(plugin->data, format);
79     sp<MetaData> newMeta = new MetaData();
80     convertMessageToMetaData(msg, newMeta);
81     delete format;
82     meta = *newMeta;
83     return reverse_translate_error(ret);
84 }
85 
name()86 const char * MediaExtractorCUnwrapper::name() {
87     return plugin->name(plugin->data);
88 }
89 
flags() const90 uint32_t MediaExtractorCUnwrapper::flags() const {
91     return plugin->flags(plugin->data);
92 }
93 
setMediaCas(const uint8_t * casToken,size_t size)94 status_t MediaExtractorCUnwrapper::setMediaCas(const uint8_t* casToken, size_t size) {
95     return plugin->setMediaCas(plugin->data, casToken, size);
96 }
97 
98 }  // namespace android
99