MediaExtractor.cpp revision f75978f63a25e79c683e96611f95cb5cd49efd3d
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 <media/stagefright/AMRExtractor.h> 22#include <media/stagefright/DataSource.h> 23#include <media/stagefright/MP3Extractor.h> 24#include <media/stagefright/MPEG4Extractor.h> 25#include <media/stagefright/MediaExtractor.h> 26#include <utils/String8.h> 27 28namespace android { 29 30// static 31sp<MediaExtractor> MediaExtractor::Create( 32 const sp<DataSource> &source, const char *mime) { 33 String8 tmp; 34 if (mime == NULL) { 35 float confidence; 36 if (!source->sniff(&tmp, &confidence)) { 37 LOGE("FAILED to autodetect media content."); 38 39 return NULL; 40 } 41 42 mime = tmp.string(); 43 LOGI("Autodetected media content as '%s' with confidence %.2f", 44 mime, confidence); 45 } 46 47 if (!strcasecmp(mime, "video/mp4") || !strcasecmp(mime, "audio/mp4")) { 48 return new MPEG4Extractor(source); 49 } else if (!strcasecmp(mime, "audio/mpeg")) { 50 return new MP3Extractor(source); 51 } else if (!strcasecmp(mime, "audio/3gpp") 52 || !strcasecmp(mime, "audio/amr-wb")) { 53 return new AMRExtractor(source); 54 } 55 56 return NULL; 57} 58 59} // namespace android 60