MediaExtractor.cpp revision 5a1c3529e4fa2f8a11054181294e0ce79fff8dd3
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 21#include "include/AMRExtractor.h" 22#include "include/MP3Extractor.h" 23#include "include/MPEG4Extractor.h" 24#include "include/WAVExtractor.h" 25#include "include/OggExtractor.h" 26#include "include/MPEG2TSExtractor.h" 27 28#include "matroska/MatroskaExtractor.h" 29 30#include <media/stagefright/foundation/AMessage.h> 31#include <media/stagefright/DataSource.h> 32#include <media/stagefright/MediaDefs.h> 33#include <media/stagefright/MediaExtractor.h> 34#include <media/stagefright/MetaData.h> 35#include <utils/String8.h> 36 37namespace android { 38 39sp<MetaData> MediaExtractor::getMetaData() { 40 return new MetaData; 41} 42 43uint32_t MediaExtractor::flags() const { 44 return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE; 45} 46 47// static 48sp<MediaExtractor> MediaExtractor::Create( 49 const sp<DataSource> &source, const char *mime) { 50 sp<AMessage> meta; 51 52 String8 tmp; 53 if (mime == NULL) { 54 float confidence; 55 if (!source->sniff(&tmp, &confidence, &meta)) { 56 LOGV("FAILED to autodetect media content."); 57 58 return NULL; 59 } 60 61 mime = tmp.string(); 62 LOGV("Autodetected media content as '%s' with confidence %.2f", 63 mime, confidence); 64 } 65 66 if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4) 67 || !strcasecmp(mime, "audio/mp4")) { 68 return new MPEG4Extractor(source); 69 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) { 70 return new MP3Extractor(source, meta); 71 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB) 72 || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) { 73 return new AMRExtractor(source); 74 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) { 75 return new WAVExtractor(source); 76 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_OGG)) { 77 return new OggExtractor(source); 78 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA)) { 79 return new MatroskaExtractor(source); 80 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2TS)) { 81 return new MPEG2TSExtractor(source); 82 } 83 84 return NULL; 85} 86 87} // namespace android 88