OSDN Git Service

fix audio crash
[android-x86/external-stagefright-plugins.git] / libstagefright / NamExtractor.cpp
1 /*
2  * Copyright 2012 Michael Chen <omxcodec@gmail.com>
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 "NamExtractor"
19 #include <utils/Log.h>
20
21 #include <media/stagefright/foundation/AMessage.h>
22 #include <media/stagefright/DataSource.h>
23 #include <media/stagefright/MediaDefs.h>
24 #include <media/stagefright/MediaExtractor.h>
25 #include <media/stagefright/MetaData.h>
26 #include <utils/String8.h>
27
28 #include "FFmpegExtractor/FFmpegExtractor.h"
29 #undef strcasecmp
30 #include <strings.h>
31
32 namespace android {
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 // TODO, SniffFFMPEG, SniffVLC, SniffMPLAYER
39 static const DataSource::SnifferFunc gNamSniffers[] = {
40     SniffFFMPEG,
41 };
42
43 // static
44 void snifferArray(const DataSource::SnifferFunc *snifferArray[], int *count)
45 {
46     *count = sizeof(gNamSniffers) / sizeof(gNamSniffers[0]);
47     *snifferArray = gNamSniffers;
48 }
49
50 // static
51 MediaExtractor *createExtractor(const sp<DataSource> &source, const char *mime) {
52     MediaExtractor *ret = NULL;
53
54     if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)     ||
55         !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)          ||
56         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MOV)       ||
57         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA)  ||
58         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_TS)        ||
59         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_AVI)       ||
60         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_ASF)       ||
61         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WEBM)      ||
62         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WMV)       ||
63         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPG)       ||
64         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_FLV)       ||
65         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_DIVX)      ||
66         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_RM)        ||
67         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_FLAC)      ||
68         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_APE)       ||
69         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MP2)       ||
70         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_RA)        ||
71         !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WMA)) {
72         ret = new FFmpegExtractor(source);
73     }
74
75     if (ret)
76         LOGI("NamExtractor support the mime: %s", mime);
77     else
78         LOGI("NamExtractor don't support the mime: %s", mime);
79
80     return ret;
81 }
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 }   //namespace android