blob: dfddbe0b132e443b8940ba0a3914c013daec1b37 [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"
Andreas Huber6bce6d82009-11-03 16:00:58 -080024#include "include/WAVExtractor.h"
Andreas Hubereb5eef32010-05-04 11:46:42 -070025#include "include/VorbisExtractor.h"
Andreas Huber57515f32009-10-23 09:55:10 -070026
Andreas Hubere46b7be2009-07-14 16:56:47 -070027#include <media/stagefright/DataSource.h>
Andreas Hubere6c40962009-09-10 14:13:30 -070028#include <media/stagefright/MediaDefs.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070029#include <media/stagefright/MediaExtractor.h>
Andreas Huberaee3c632010-01-11 15:35:19 -080030#include <media/stagefright/MetaData.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070031#include <utils/String8.h>
32
33namespace android {
34
Andreas Huberaee3c632010-01-11 15:35:19 -080035sp<MetaData> MediaExtractor::getMetaData() {
36 return new MetaData;
37}
38
Andreas Huber62f7ffe2010-05-06 10:18:05 -070039uint32_t MediaExtractor::flags() const {
40 return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE;
41}
42
Andreas Hubere46b7be2009-07-14 16:56:47 -070043// static
Andreas Huberbe06d262009-08-14 14:37:10 -070044sp<MediaExtractor> MediaExtractor::Create(
45 const sp<DataSource> &source, const char *mime) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070046 String8 tmp;
47 if (mime == NULL) {
48 float confidence;
49 if (!source->sniff(&tmp, &confidence)) {
Andreas Huberaee3c632010-01-11 15:35:19 -080050 LOGV("FAILED to autodetect media content.");
Andreas Hubere46b7be2009-07-14 16:56:47 -070051
52 return NULL;
53 }
54
55 mime = tmp.string();
Andreas Huberad285432009-10-22 09:44:00 -070056 LOGV("Autodetected media content as '%s' with confidence %.2f",
Andreas Hubere46b7be2009-07-14 16:56:47 -070057 mime, confidence);
58 }
59
Andreas Hubere6c40962009-09-10 14:13:30 -070060 if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)
61 || !strcasecmp(mime, "audio/mp4")) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070062 return new MPEG4Extractor(source);
Andreas Hubere6c40962009-09-10 14:13:30 -070063 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070064 return new MP3Extractor(source);
Andreas Hubere6c40962009-09-10 14:13:30 -070065 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)
66 || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
Andreas Huber5a65a6e2009-09-08 16:07:15 -070067 return new AMRExtractor(source);
Andreas Huber6bce6d82009-11-03 16:00:58 -080068 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) {
69 return new WAVExtractor(source);
Andreas Hubereb5eef32010-05-04 11:46:42 -070070 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_VORBIS)) {
71 return new VorbisExtractor(source);
Andreas Hubere46b7be2009-07-14 16:56:47 -070072 }
73
74 return NULL;
75}
76
Andreas Hubere46b7be2009-07-14 16:56:47 -070077} // namespace android