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