DataSource.cpp revision 20111aa043c5f404472bc63b90bc5aad906b1101
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#include <media/stagefright/DataSource.h>
18#include <media/stagefright/MediaErrors.h>
19#include <media/stagefright/MP3Extractor.h>
20#include <media/stagefright/MPEG4Extractor.h>
21#include <utils/String8.h>
22
23namespace android {
24
25status_t DataSource::getSize(off_t *size) {
26    *size = 0;
27
28    return ERROR_UNSUPPORTED;
29}
30
31////////////////////////////////////////////////////////////////////////////////
32
33Mutex DataSource::gSnifferMutex;
34List<DataSource::SnifferFunc> DataSource::gSniffers;
35
36bool DataSource::sniff(String8 *mimeType, float *confidence) {
37    *mimeType = "";
38    *confidence = 0.0f;
39
40    Mutex::Autolock autoLock(gSnifferMutex);
41    for (List<SnifferFunc>::iterator it = gSniffers.begin();
42         it != gSniffers.end(); ++it) {
43        String8 newMimeType;
44        float newConfidence;
45        if ((*it)(this, &newMimeType, &newConfidence)) {
46            if (newConfidence > *confidence) {
47                *mimeType = newMimeType;
48                *confidence = newConfidence;
49            }
50        }
51    }
52
53    return *confidence > 0.0;
54}
55
56// static
57void DataSource::RegisterSniffer(SnifferFunc func) {
58    Mutex::Autolock autoLock(gSnifferMutex);
59
60    for (List<SnifferFunc>::iterator it = gSniffers.begin();
61         it != gSniffers.end(); ++it) {
62        if (*it == func) {
63            return;
64        }
65    }
66
67    gSniffers.push_back(func);
68}
69
70// static
71void DataSource::RegisterDefaultSniffers() {
72    RegisterSniffer(SniffMP3);
73    RegisterSniffer(SniffMPEG4);
74}
75
76}  // namespace android
77