blob: 9bc94de7902f6f13c05ddb5c68350c3933bf193a [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 Huber388379f2010-05-07 10:35:13 -070025#include "include/OggExtractor.h"
Andreas Hubera557b242010-06-07 13:05:37 -070026#include "include/MPEG2TSExtractor.h"
Andreas Huber57515f32009-10-23 09:55:10 -070027
Andreas Huber072f5242010-05-20 14:56:53 -070028#include "matroska/MatroskaExtractor.h"
29
Andreas Huberefdd0882010-08-25 11:09:41 -070030#include <media/stagefright/foundation/AMessage.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070031#include <media/stagefright/DataSource.h>
Andreas Hubere6c40962009-09-10 14:13:30 -070032#include <media/stagefright/MediaDefs.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070033#include <media/stagefright/MediaExtractor.h>
Andreas Huberaee3c632010-01-11 15:35:19 -080034#include <media/stagefright/MetaData.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070035#include <utils/String8.h>
36
37namespace android {
38
Andreas Huberaee3c632010-01-11 15:35:19 -080039sp<MetaData> MediaExtractor::getMetaData() {
40 return new MetaData;
41}
42
Andreas Huber62f7ffe2010-05-06 10:18:05 -070043uint32_t MediaExtractor::flags() const {
44 return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE;
45}
46
Andreas Hubere46b7be2009-07-14 16:56:47 -070047// static
Andreas Huberbe06d262009-08-14 14:37:10 -070048sp<MediaExtractor> MediaExtractor::Create(
49 const sp<DataSource> &source, const char *mime) {
Andreas Huberefdd0882010-08-25 11:09:41 -070050 sp<AMessage> meta;
51
Andreas Hubere46b7be2009-07-14 16:56:47 -070052 String8 tmp;
53 if (mime == NULL) {
54 float confidence;
Andreas Huberefdd0882010-08-25 11:09:41 -070055 if (!source->sniff(&tmp, &confidence, &meta)) {
Andreas Huberaee3c632010-01-11 15:35:19 -080056 LOGV("FAILED to autodetect media content.");
Andreas Hubere46b7be2009-07-14 16:56:47 -070057
58 return NULL;
59 }
60
61 mime = tmp.string();
Andreas Huberad285432009-10-22 09:44:00 -070062 LOGV("Autodetected media content as '%s' with confidence %.2f",
Andreas Hubere46b7be2009-07-14 16:56:47 -070063 mime, confidence);
64 }
65
Andreas Hubere6c40962009-09-10 14:13:30 -070066 if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)
67 || !strcasecmp(mime, "audio/mp4")) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070068 return new MPEG4Extractor(source);
Andreas Hubere6c40962009-09-10 14:13:30 -070069 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
Andreas Huberefdd0882010-08-25 11:09:41 -070070 return new MP3Extractor(source, meta);
Andreas Hubere6c40962009-09-10 14:13:30 -070071 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)
72 || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
Andreas Huber5a65a6e2009-09-08 16:07:15 -070073 return new AMRExtractor(source);
Andreas Huber6bce6d82009-11-03 16:00:58 -080074 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV)) {
75 return new WAVExtractor(source);
Andreas Huber388379f2010-05-07 10:35:13 -070076 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_OGG)) {
77 return new OggExtractor(source);
Andreas Huber072f5242010-05-20 14:56:53 -070078 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA)) {
79 return new MatroskaExtractor(source);
Andreas Hubera557b242010-06-07 13:05:37 -070080 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2TS)) {
81 return new MPEG2TSExtractor(source);
Andreas Hubere46b7be2009-07-14 16:56:47 -070082 }
83
84 return NULL;
85}
86
Andreas Hubere46b7be2009-07-14 16:56:47 -070087} // namespace android