blob: 40e055cc5aca33a356c91bd4c7c646a15f8a59fa [file] [log] [blame]
James Dong2f1f2242011-03-17 11:02:04 -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 Hubere46b7be2009-07-14 16:56:47 -070017//#define LOG_NDEBUG 0
18#define LOG_TAG "StagefrightPlayer"
19#include <utils/Log.h>
20
21#include "StagefrightPlayer.h"
Andreas Huber27366fc2009-11-20 09:32:46 -080022
23#include "AwesomePlayer.h"
Andreas Hubere46b7be2009-07-14 16:56:47 -070024
Andreas Huber62f7ffe2010-05-06 10:18:05 -070025#include <media/Metadata.h>
26#include <media/stagefright/MediaExtractor.h>
27
Andreas Hubere46b7be2009-07-14 16:56:47 -070028namespace android {
29
30StagefrightPlayer::StagefrightPlayer()
Andreas Huber27366fc2009-11-20 09:32:46 -080031 : mPlayer(new AwesomePlayer) {
Andreas Hubere46b7be2009-07-14 16:56:47 -070032 LOGV("StagefrightPlayer");
Andreas Huber27366fc2009-11-20 09:32:46 -080033
34 mPlayer->setListener(this);
Andreas Hubere46b7be2009-07-14 16:56:47 -070035}
36
37StagefrightPlayer::~StagefrightPlayer() {
38 LOGV("~StagefrightPlayer");
39 reset();
Andreas Huber27366fc2009-11-20 09:32:46 -080040
41 delete mPlayer;
42 mPlayer = NULL;
Andreas Hubere46b7be2009-07-14 16:56:47 -070043}
44
45status_t StagefrightPlayer::initCheck() {
46 LOGV("initCheck");
47 return OK;
48}
49
Andreas Huber603d7392011-06-30 15:47:02 -070050status_t StagefrightPlayer::setUID(uid_t uid) {
51 mPlayer->setUID(uid);
52
53 return OK;
54}
55
Andreas Huber25643002010-01-28 11:19:57 -080056status_t StagefrightPlayer::setDataSource(
Andreas Huber433c9ac2010-01-27 16:49:05 -080057 const char *url, const KeyedVector<String8, String8> *headers) {
Andreas Huber433c9ac2010-01-27 16:49:05 -080058 return mPlayer->setDataSource(url, headers);
Andreas Hubere46b7be2009-07-14 16:56:47 -070059}
60
Andreas Huberda440f12009-11-10 11:51:43 -080061// 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 Hubere46b7be2009-07-14 16:56:47 -070063status_t StagefrightPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
64 LOGV("setDataSource(%d, %lld, %lld)", fd, offset, length);
Andreas Huber27366fc2009-11-20 09:32:46 -080065 return mPlayer->setDataSource(dup(fd), offset, length);
Andreas Hubere46b7be2009-07-14 16:56:47 -070066}
67
Andreas Huber52b52cd2010-11-23 11:41:34 -080068status_t StagefrightPlayer::setDataSource(const sp<IStreamSource> &source) {
69 return mPlayer->setDataSource(source);
70}
71
Andreas Hubere3c01832010-08-16 08:49:37 -070072status_t StagefrightPlayer::setVideoSurface(const sp<Surface> &surface) {
73 LOGV("setVideoSurface");
74
75 mPlayer->setSurface(surface);
76 return OK;
77}
78
Glenn Kastencc562a32011-02-08 17:26:17 -080079status_t StagefrightPlayer::setVideoSurfaceTexture(
80 const sp<ISurfaceTexture> &surfaceTexture) {
81 LOGV("setVideoSurfaceTexture");
82
83 mPlayer->setSurfaceTexture(surfaceTexture);
84 return OK;
85}
86
Andreas Hubere46b7be2009-07-14 16:56:47 -070087status_t StagefrightPlayer::prepare() {
Andreas Huber6be780e2010-02-08 14:40:30 -080088 return mPlayer->prepare();
Andreas Hubere46b7be2009-07-14 16:56:47 -070089}
90
91status_t StagefrightPlayer::prepareAsync() {
Andreas Huber6be780e2010-02-08 14:40:30 -080092 return mPlayer->prepareAsync();
Andreas Hubere46b7be2009-07-14 16:56:47 -070093}
94
95status_t StagefrightPlayer::start() {
96 LOGV("start");
97
Andreas Huber27366fc2009-11-20 09:32:46 -080098 return mPlayer->play();
Andreas Hubere46b7be2009-07-14 16:56:47 -070099}
100
101status_t StagefrightPlayer::stop() {
102 LOGV("stop");
103
Andreas Huber27366fc2009-11-20 09:32:46 -0800104 return pause(); // what's the difference?
Andreas Hubere46b7be2009-07-14 16:56:47 -0700105}
106
107status_t StagefrightPlayer::pause() {
108 LOGV("pause");
109
Andreas Huber27366fc2009-11-20 09:32:46 -0800110 return mPlayer->pause();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700111}
112
113bool StagefrightPlayer::isPlaying() {
114 LOGV("isPlaying");
Andreas Huber27366fc2009-11-20 09:32:46 -0800115 return mPlayer->isPlaying();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700116}
117
118status_t StagefrightPlayer::seekTo(int msec) {
Andreas Huber8e64c312011-04-04 09:12:56 -0700119 LOGV("seekTo %.2f secs", msec / 1E3);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700120
Andreas Hubere46b7be2009-07-14 16:56:47 -0700121 status_t err = mPlayer->seekTo((int64_t)msec * 1000);
122
Andreas Hubere46b7be2009-07-14 16:56:47 -0700123 return err;
124}
125
126status_t StagefrightPlayer::getCurrentPosition(int *msec) {
127 LOGV("getCurrentPosition");
128
Andreas Huber27366fc2009-11-20 09:32:46 -0800129 int64_t positionUs;
130 status_t err = mPlayer->getPosition(&positionUs);
131
132 if (err != OK) {
133 return err;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700134 }
135
Andreas Huber27366fc2009-11-20 09:32:46 -0800136 *msec = (positionUs + 500) / 1000;
137
Andreas Hubere46b7be2009-07-14 16:56:47 -0700138 return OK;
139}
140
141status_t StagefrightPlayer::getDuration(int *msec) {
142 LOGV("getDuration");
143
Andreas Huber27366fc2009-11-20 09:32:46 -0800144 int64_t durationUs;
145 status_t err = mPlayer->getDuration(&durationUs);
146
147 if (err != OK) {
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700148 *msec = 0;
149 return OK;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700150 }
151
Andreas Huber27366fc2009-11-20 09:32:46 -0800152 *msec = (durationUs + 500) / 1000;
153
Andreas Hubere46b7be2009-07-14 16:56:47 -0700154 return OK;
155}
156
157status_t StagefrightPlayer::reset() {
158 LOGV("reset");
159
Andreas Huber27366fc2009-11-20 09:32:46 -0800160 mPlayer->reset();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700161
162 return OK;
163}
164
165status_t StagefrightPlayer::setLooping(int loop) {
166 LOGV("setLooping");
Andreas Huber27366fc2009-11-20 09:32:46 -0800167
168 return mPlayer->setLooping(loop);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700169}
170
171player_type StagefrightPlayer::playerType() {
172 LOGV("playerType");
173 return STAGEFRIGHT_PLAYER;
174}
175
176status_t StagefrightPlayer::invoke(const Parcel &request, Parcel *reply) {
177 return INVALID_OPERATION;
178}
179
180void StagefrightPlayer::setAudioSink(const sp<AudioSink> &audioSink) {
181 MediaPlayerInterface::setAudioSink(audioSink);
182
Andreas Huber27366fc2009-11-20 09:32:46 -0800183 mPlayer->setAudioSink(audioSink);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700184}
185
Gloria Wangd01ec6e2011-04-25 17:28:22 -0700186status_t StagefrightPlayer::setParameter(int key, const Parcel &request) {
187 LOGV("setParameter");
188 return mPlayer->setParameter(key, request);
189}
190
191status_t StagefrightPlayer::getParameter(int key, Parcel *reply) {
192 LOGV("getParameter");
193 return mPlayer->getParameter(key, reply);
194}
195
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700196status_t StagefrightPlayer::getMetadata(
197 const media::Metadata::Filter& ids, Parcel *records) {
198 using media::Metadata;
199
200 uint32_t flags = mPlayer->flags();
201
202 Metadata metadata(records);
203
204 metadata.appendBool(
205 Metadata::kPauseAvailable,
206 flags & MediaExtractor::CAN_PAUSE);
207
208 metadata.appendBool(
209 Metadata::kSeekBackwardAvailable,
210 flags & MediaExtractor::CAN_SEEK_BACKWARD);
211
212 metadata.appendBool(
213 Metadata::kSeekForwardAvailable,
214 flags & MediaExtractor::CAN_SEEK_FORWARD);
215
Andreas Huber10b9b3f2010-10-08 10:16:24 -0700216 metadata.appendBool(
217 Metadata::kSeekAvailable,
218 flags & MediaExtractor::CAN_SEEK);
219
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700220 return OK;
221}
222
Andreas Huberfddf5d92011-06-07 15:52:25 -0700223status_t StagefrightPlayer::dump(int fd, const Vector<String16> &args) const {
224 return mPlayer->dump(fd, args);
225}
226
Andreas Hubere46b7be2009-07-14 16:56:47 -0700227} // namespace android