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 //#define LOG_NDEBUG 0 18 #define LOG_TAG "StagefrightPlayer" 19 #include <utils/Log.h> 20 21 #include "StagefrightPlayer.h" 22 23 #include "AwesomePlayer.h" 24 25 #include <media/Metadata.h> 26 #include <media/stagefright/MediaExtractor.h> 27 28 namespace android { 29 30 StagefrightPlayer::StagefrightPlayer() 31 : mPlayer(new AwesomePlayer) { 32 ALOGV("StagefrightPlayer"); 33 34 mPlayer->setListener(this); 35 } 36 37 StagefrightPlayer::~StagefrightPlayer() { 38 ALOGV("~StagefrightPlayer"); 39 reset(); 40 41 delete mPlayer; 42 mPlayer = NULL; 43 } 44 45 status_t StagefrightPlayer::initCheck() { 46 ALOGV("initCheck"); 47 return OK; 48 } 49 50 status_t StagefrightPlayer::setUID(uid_t uid) { 51 mPlayer->setUID(uid); 52 53 return OK; 54 } 55 56 status_t StagefrightPlayer::setDataSource( 57 const char *url, const KeyedVector<String8, String8> *headers) { 58 return mPlayer->setDataSource(url, headers); 59 } 60 61 // Warning: The filedescriptor passed into this method will only be valid until 62 // the method returns, if you want to keep it, dup it! 63 status_t StagefrightPlayer::setDataSource(int fd, int64_t offset, int64_t length) { 64 ALOGV("setDataSource(%d, %lld, %lld)", fd, offset, length); 65 return mPlayer->setDataSource(dup(fd), offset, length); 66 } 67 68 status_t StagefrightPlayer::setDataSource(const sp<IStreamSource> &source) { 69 return mPlayer->setDataSource(source); 70 } 71 72 status_t StagefrightPlayer::setVideoSurfaceTexture( 73 const sp<IGraphicBufferProducer> &bufferProducer) { 74 ALOGV("setVideoSurfaceTexture"); 75 76 return mPlayer->setSurfaceTexture(bufferProducer); 77 } 78 79 status_t StagefrightPlayer::prepare() { 80 return mPlayer->prepare(); 81 } 82 83 status_t StagefrightPlayer::prepareAsync() { 84 return mPlayer->prepareAsync(); 85 } 86 87 status_t StagefrightPlayer::start() { 88 ALOGV("start"); 89 90 return mPlayer->play(); 91 } 92 93 status_t StagefrightPlayer::stop() { 94 ALOGV("stop"); 95 96 return pause(); // what's the difference? 97 } 98 99 status_t StagefrightPlayer::pause() { 100 ALOGV("pause"); 101 102 return mPlayer->pause(); 103 } 104 105 bool StagefrightPlayer::isPlaying() { 106 ALOGV("isPlaying"); 107 return mPlayer->isPlaying(); 108 } 109 110 status_t StagefrightPlayer::seekTo(int msec) { 111 ALOGV("seekTo %.2f secs", msec / 1E3); 112 113 status_t err = mPlayer->seekTo((int64_t)msec * 1000); 114 115 return err; 116 } 117 118 status_t StagefrightPlayer::getCurrentPosition(int *msec) { 119 ALOGV("getCurrentPosition"); 120 121 int64_t positionUs; 122 status_t err = mPlayer->getPosition(&positionUs); 123 124 if (err != OK) { 125 return err; 126 } 127 128 *msec = (positionUs + 500) / 1000; 129 130 return OK; 131 } 132 133 status_t StagefrightPlayer::getDuration(int *msec) { 134 ALOGV("getDuration"); 135 136 int64_t durationUs; 137 status_t err = mPlayer->getDuration(&durationUs); 138 139 if (err != OK) { 140 *msec = 0; 141 return OK; 142 } 143 144 *msec = (durationUs + 500) / 1000; 145 146 return OK; 147 } 148 149 status_t StagefrightPlayer::reset() { 150 ALOGV("reset"); 151 152 mPlayer->reset(); 153 154 return OK; 155 } 156 157 status_t StagefrightPlayer::setLooping(int loop) { 158 ALOGV("setLooping"); 159 160 return mPlayer->setLooping(loop); 161 } 162 163 player_type StagefrightPlayer::playerType() { 164 ALOGV("playerType"); 165 return STAGEFRIGHT_PLAYER; 166 } 167 168 status_t StagefrightPlayer::invoke(const Parcel &request, Parcel *reply) { 169 ALOGV("invoke()"); 170 return mPlayer->invoke(request, reply); 171 } 172 173 void StagefrightPlayer::setAudioSink(const sp<AudioSink> &audioSink) { 174 MediaPlayerInterface::setAudioSink(audioSink); 175 176 mPlayer->setAudioSink(audioSink); 177 } 178 179 status_t StagefrightPlayer::setParameter(int key, const Parcel &request) { 180 ALOGV("setParameter(key=%d)", key); 181 return mPlayer->setParameter(key, request); 182 } 183 184 status_t StagefrightPlayer::getParameter(int key, Parcel *reply) { 185 ALOGV("getParameter"); 186 return mPlayer->getParameter(key, reply); 187 } 188 189 status_t StagefrightPlayer::getMetadata( 190 const media::Metadata::Filter& ids, Parcel *records) { 191 using media::Metadata; 192 193 uint32_t flags = mPlayer->flags(); 194 195 Metadata metadata(records); 196 197 metadata.appendBool( 198 Metadata::kPauseAvailable, 199 flags & MediaExtractor::CAN_PAUSE); 200 201 metadata.appendBool( 202 Metadata::kSeekBackwardAvailable, 203 flags & MediaExtractor::CAN_SEEK_BACKWARD); 204 205 metadata.appendBool( 206 Metadata::kSeekForwardAvailable, 207 flags & MediaExtractor::CAN_SEEK_FORWARD); 208 209 metadata.appendBool( 210 Metadata::kSeekAvailable, 211 flags & MediaExtractor::CAN_SEEK); 212 213 return OK; 214 } 215 216 status_t StagefrightPlayer::dump(int fd, const Vector<String16> &args) const { 217 return mPlayer->dump(fd, args); 218 } 219 220 } // namespace android 221