blob: 933c2f6350fe6658ac00633ec8a1297bd03fab17 [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
Andreas Huber57515f32009-10-23 09:55:10 -070017#include "include/AMRExtractor.h"
18#include "include/MP3Extractor.h"
19#include "include/MPEG4Extractor.h"
20
Andreas Hubere46b7be2009-07-14 16:56:47 -070021#include <media/stagefright/DataSource.h>
22#include <media/stagefright/MediaErrors.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070023#include <utils/String8.h>
24
25namespace android {
26
Andreas Huberbe06d262009-08-14 14:37:10 -070027bool DataSource::getUInt16(off_t offset, uint16_t *x) {
28 *x = 0;
29
30 uint8_t byte[2];
31 if (read_at(offset, byte, 2) != 2) {
32 return false;
33 }
34
35 *x = (byte[0] << 8) | byte[1];
36
37 return true;
38}
39
Andreas Hubere46b7be2009-07-14 16:56:47 -070040status_t DataSource::getSize(off_t *size) {
41 *size = 0;
42
43 return ERROR_UNSUPPORTED;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47
48Mutex DataSource::gSnifferMutex;
49List<DataSource::SnifferFunc> DataSource::gSniffers;
50
51bool DataSource::sniff(String8 *mimeType, float *confidence) {
52 *mimeType = "";
53 *confidence = 0.0f;
54
55 Mutex::Autolock autoLock(gSnifferMutex);
56 for (List<SnifferFunc>::iterator it = gSniffers.begin();
57 it != gSniffers.end(); ++it) {
58 String8 newMimeType;
59 float newConfidence;
60 if ((*it)(this, &newMimeType, &newConfidence)) {
61 if (newConfidence > *confidence) {
62 *mimeType = newMimeType;
63 *confidence = newConfidence;
64 }
65 }
66 }
67
68 return *confidence > 0.0;
69}
70
71// static
72void DataSource::RegisterSniffer(SnifferFunc func) {
73 Mutex::Autolock autoLock(gSnifferMutex);
74
75 for (List<SnifferFunc>::iterator it = gSniffers.begin();
76 it != gSniffers.end(); ++it) {
77 if (*it == func) {
78 return;
79 }
80 }
81
82 gSniffers.push_back(func);
83}
84
85// static
86void DataSource::RegisterDefaultSniffers() {
87 RegisterSniffer(SniffMP3);
88 RegisterSniffer(SniffMPEG4);
Andreas Huber5a65a6e2009-09-08 16:07:15 -070089 RegisterSniffer(SniffAMR);
Andreas Hubere46b7be2009-07-14 16:56:47 -070090}
91
92} // namespace android