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