blob: 2a6dbc4943b698d9c95c056a3d8c41d8540100ea [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"
Andreas Huber6bce6d82009-11-03 16:00:58 -080020#include "include/WAVExtractor.h"
Andreas Huber57515f32009-10-23 09:55:10 -070021
Andreas Hubere46b7be2009-07-14 16:56:47 -070022#include <media/stagefright/DataSource.h>
23#include <media/stagefright/MediaErrors.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070024#include <utils/String8.h>
25
26namespace android {
27
Andreas Huberbe06d262009-08-14 14:37:10 -070028bool DataSource::getUInt16(off_t offset, uint16_t *x) {
29 *x = 0;
30
31 uint8_t byte[2];
Andreas Huber9a12baf2009-10-23 10:22:30 -070032 if (readAt(offset, byte, 2) != 2) {
Andreas Huberbe06d262009-08-14 14:37:10 -070033 return false;
34 }
35
36 *x = (byte[0] << 8) | byte[1];
37
38 return true;
39}
40
Andreas Hubere46b7be2009-07-14 16:56:47 -070041status_t DataSource::getSize(off_t *size) {
42 *size = 0;
43
44 return ERROR_UNSUPPORTED;
45}
46
47////////////////////////////////////////////////////////////////////////////////
48
49Mutex DataSource::gSnifferMutex;
50List<DataSource::SnifferFunc> DataSource::gSniffers;
51
52bool DataSource::sniff(String8 *mimeType, float *confidence) {
53 *mimeType = "";
54 *confidence = 0.0f;
55
56 Mutex::Autolock autoLock(gSnifferMutex);
57 for (List<SnifferFunc>::iterator it = gSniffers.begin();
58 it != gSniffers.end(); ++it) {
59 String8 newMimeType;
60 float newConfidence;
61 if ((*it)(this, &newMimeType, &newConfidence)) {
62 if (newConfidence > *confidence) {
63 *mimeType = newMimeType;
64 *confidence = newConfidence;
65 }
66 }
67 }
68
69 return *confidence > 0.0;
70}
71
72// static
73void DataSource::RegisterSniffer(SnifferFunc func) {
74 Mutex::Autolock autoLock(gSnifferMutex);
75
76 for (List<SnifferFunc>::iterator it = gSniffers.begin();
77 it != gSniffers.end(); ++it) {
78 if (*it == func) {
79 return;
80 }
81 }
82
83 gSniffers.push_back(func);
84}
85
86// static
87void DataSource::RegisterDefaultSniffers() {
88 RegisterSniffer(SniffMP3);
89 RegisterSniffer(SniffMPEG4);
Andreas Huber5a65a6e2009-09-08 16:07:15 -070090 RegisterSniffer(SniffAMR);
Andreas Huber6bce6d82009-11-03 16:00:58 -080091 RegisterSniffer(SniffWAV);
Andreas Hubere46b7be2009-07-14 16:56:47 -070092}
93
94} // namespace android