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