blob: 5e1270af496f76ae5847e1aef5e91541dbaa122a [file] [log] [blame]
Andreas Hubere46b7be2009-07-14 16:56:47 -07001/*
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
Andreas Huber57515f32009-10-23 09:55:10 -070021#include "include/AMRExtractor.h"
22#include "include/MP3Extractor.h"
23#include "include/MPEG4Extractor.h"
24
Andreas Hubere46b7be2009-07-14 16:56:47 -070025#include <media/stagefright/DataSource.h>
Andreas Hubere6c40962009-09-10 14:13:30 -070026#include <media/stagefright/MediaDefs.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070027#include <media/stagefright/MediaExtractor.h>
28#include <utils/String8.h>
29
30namespace android {
31
32// static
Andreas Huberbe06d262009-08-14 14:37:10 -070033sp<MediaExtractor> MediaExtractor::Create(
34 const sp<DataSource> &source, const char *mime) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070035 String8 tmp;
36 if (mime == NULL) {
37 float confidence;
38 if (!source->sniff(&tmp, &confidence)) {
39 LOGE("FAILED to autodetect media content.");
40
41 return NULL;
42 }
43
44 mime = tmp.string();
Andreas Huberad285432009-10-22 09:44:00 -070045 LOGV("Autodetected media content as '%s' with confidence %.2f",
Andreas Hubere46b7be2009-07-14 16:56:47 -070046 mime, confidence);
47 }
48
Andreas Hubere6c40962009-09-10 14:13:30 -070049 if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)
50 || !strcasecmp(mime, "audio/mp4")) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070051 return new MPEG4Extractor(source);
Andreas Hubere6c40962009-09-10 14:13:30 -070052 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070053 return new MP3Extractor(source);
Andreas Hubere6c40962009-09-10 14:13:30 -070054 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)
55 || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
Andreas Huber5a65a6e2009-09-08 16:07:15 -070056 return new AMRExtractor(source);
Andreas Hubere46b7be2009-07-14 16:56:47 -070057 }
58
59 return NULL;
60}
61
62} // namespace android