• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
26 namespace android {
27 
clearMetadataValues()28 void VorbisMetadataRetriever::clearMetadataValues()
29 {
30     LOGV("cleearMetadataValues");
31     mMetadataValues[0][0] = '\0';
32 }
33 
setDataSource(const char * url)34 status_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     }
42     return mVorbisPlayer->setDataSource(url);
43 }
44 
setDataSource(int fd,int64_t offset,int64_t length)45 status_t VorbisMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length)
46 {
47     LOGV("setDataSource: fd(%d), offset(%lld), and length(%lld)", fd, offset, length);
48     Mutex::Autolock lock(mLock);
49     clearMetadataValues();
50     if (mVorbisPlayer == 0) {
51         mVorbisPlayer = new VorbisPlayer();
52     }
53     return mVorbisPlayer->setDataSource(fd, offset, length);
54 }
55 
extractMetadata(int keyCode)56 const char* VorbisMetadataRetriever::extractMetadata(int keyCode)
57 {
58     LOGV("extractMetadata: key(%d)", keyCode);
59     Mutex::Autolock lock(mLock);
60     if (mVorbisPlayer == 0 || mVorbisPlayer->initCheck() != NO_ERROR) {
61         LOGE("no vorbis player is initialized yet");
62         return NULL;
63     }
64     switch (keyCode) {
65     case METADATA_KEY_DURATION:
66         {
67             if (mMetadataValues[0][0] == '\0') {
68                 int duration = -1;
69                 if (mVorbisPlayer->getDuration(&duration) != NO_ERROR) {
70                     LOGE("failed to get duration");
71                     return NULL;
72                 }
73                 snprintf(mMetadataValues[0], MAX_METADATA_STRING_LENGTH, "%d", duration);
74             }
75             LOGV("duration: %s ms", mMetadataValues[0]);
76             return mMetadataValues[0];
77         }
78     default:
79         LOGE("Unsupported key code (%d)", keyCode);
80         return NULL;
81     }
82     return NULL;
83 }
84 
85 };
86 
87