blob: eac74fc04bf5a8c7d2410dfe82d93c41a32421e3 [file] [log] [blame]
James Dong148c1a22009-09-06 14:29:45 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "VorbisMetadataRetriever"
20#include <utils/Log.h>
21
22#include "VorbisMetadataRetriever.h"
23#include <media/mediametadataretriever.h>
24#
25
26namespace android {
27
28void VorbisMetadataRetriever::clearMetadataValues()
29{
30 LOGV("cleearMetadataValues");
31 mMetadataValues[0][0] = '\0';
32}
33
34status_t VorbisMetadataRetriever::setDataSource(const char *url)
35{
36 LOGV("setDataSource: url(%s)", url? url: "NULL pointer");
37 Mutex::Autolock lock(mLock);
38 clearMetadataValues();
39 if (mVorbisPlayer == 0) {
40 mVorbisPlayer = new VorbisPlayer();
41 }
Andreas Huber2db84552010-01-28 11:19:57 -080042 // TODO: support headers in MetadataRetriever interface!
43 return mVorbisPlayer->setDataSource(url, NULL /* headers */);
James Dong148c1a22009-09-06 14:29:45 -070044}
45
46status_t VorbisMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length)
47{
48 LOGV("setDataSource: fd(%d), offset(%lld), and length(%lld)", fd, offset, length);
49 Mutex::Autolock lock(mLock);
50 clearMetadataValues();
51 if (mVorbisPlayer == 0) {
52 mVorbisPlayer = new VorbisPlayer();
53 }
54 return mVorbisPlayer->setDataSource(fd, offset, length);
55}
56
57const char* VorbisMetadataRetriever::extractMetadata(int keyCode)
58{
59 LOGV("extractMetadata: key(%d)", keyCode);
60 Mutex::Autolock lock(mLock);
61 if (mVorbisPlayer == 0 || mVorbisPlayer->initCheck() != NO_ERROR) {
62 LOGE("no vorbis player is initialized yet");
63 return NULL;
64 }
65 switch (keyCode) {
66 case METADATA_KEY_DURATION:
67 {
68 if (mMetadataValues[0][0] == '\0') {
69 int duration = -1;
70 if (mVorbisPlayer->getDuration(&duration) != NO_ERROR) {
71 LOGE("failed to get duration");
72 return NULL;
73 }
74 snprintf(mMetadataValues[0], MAX_METADATA_STRING_LENGTH, "%d", duration);
75 }
76 LOGV("duration: %s ms", mMetadataValues[0]);
77 return mMetadataValues[0];
78 }
79 default:
80 LOGE("Unsupported key code (%d)", keyCode);
81 return NULL;
82 }
83 return NULL;
84}
85
86};
87