MediaExtractor.cpp revision 5561ccf4a8db88a2e44eac1b3ed13b4ff53a7f20
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 26#include <media/stagefright/DataSource.h> 27#include <media/stagefright/MediaDefs.h> 28#include <media/stagefright/MediaExtractor.h> 29#include <media/stagefright/MetaData.h> 30#include <utils/String8.h> 31 32namespace android { 33 34sp<MetaData> MediaExtractor::getMetaData() { 35 return new MetaData; 36} 37 38// static 39sp<MediaExtractor> MediaExtractor::Create( 40 const sp<DataSource> &source, const char *mime) { 41 String8 tmp; 42 if (mime == NULL) { 43 float confidence; 44 if (!source->sniff(&tmp, &confidence)) { 45 LOGV("FAILED to autodetect media content."); 46 47 return NULL; 48 } 49 50 mime = tmp.string(); 51 LOGV("Autodetected media content as '%s' with confidence %.2f", 52 mime, confidence); 53 } 54 55 if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4) 56 || !strcasecmp(mime, "audio/mp4")) { 57 return new MPEG4Extractor(source); 58 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) { 59 return new MP3Extractor(source); 60 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB) 61 || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) { 62 return new AMRExtractor(source); 63 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) { 64 return new WAVExtractor(source); 65 } 66 67 return NULL; 68} 69 70} // namespace android 71