blob: 598d573c13d621adae4b85bc127da30941f29758 [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
Glenn Kastencc562a32011-02-08 17:26:17 -080072status_t StagefrightPlayer::setVideoSurfaceTexture(
73 const sp<ISurfaceTexture> &surfaceTexture) {
74 LOGV("setVideoSurfaceTexture");
75
Andreas Huber07754c52011-08-29 13:01:23 -070076 return mPlayer->setSurfaceTexture(surfaceTexture);
Glenn Kastencc562a32011-02-08 17:26:17 -080077}
78
Andreas Hubere46b7be2009-07-14 16:56:47 -070079status_t StagefrightPlayer::prepare() {
Andreas Huber6be780e2010-02-08 14:40:30 -080080 return mPlayer->prepare();
Andreas Hubere46b7be2009-07-14 16:56:47 -070081}
82
83status_t StagefrightPlayer::prepareAsync() {
Andreas Huber6be780e2010-02-08 14:40:30 -080084 return mPlayer->prepareAsync();
Andreas Hubere46b7be2009-07-14 16:56:47 -070085}
86
87status_t StagefrightPlayer::start() {
88 LOGV("start");
89
Andreas Huber27366fc2009-11-20 09:32:46 -080090 return mPlayer->play();
Andreas Hubere46b7be2009-07-14 16:56:47 -070091}
92
93status_t StagefrightPlayer::stop() {
94 LOGV("stop");
95
Andreas Huber27366fc2009-11-20 09:32:46 -080096 return pause(); // what's the difference?
Andreas Hubere46b7be2009-07-14 16:56:47 -070097}
98
99status_t StagefrightPlayer::pause() {
100 LOGV("pause");
101
Andreas Huber27366fc2009-11-20 09:32:46 -0800102 return mPlayer->pause();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700103}
104
105bool StagefrightPlayer::isPlaying() {
106 LOGV("isPlaying");
Andreas Huber27366fc2009-11-20 09:32:46 -0800107 return mPlayer->isPlaying();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700108}
109
110status_t StagefrightPlayer::seekTo(int msec) {
Andreas Huber8e64c312011-04-04 09:12:56 -0700111 LOGV("seekTo %.2f secs", msec / 1E3);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700112
Andreas Hubere46b7be2009-07-14 16:56:47 -0700113 status_t err = mPlayer->seekTo((int64_t)msec * 1000);
114
Andreas Hubere46b7be2009-07-14 16:56:47 -0700115 return err;
116}
117
118status_t StagefrightPlayer::getCurrentPosition(int *msec) {
119 LOGV("getCurrentPosition");
120
Andreas Huber27366fc2009-11-20 09:32:46 -0800121 int64_t positionUs;
122 status_t err = mPlayer->getPosition(&positionUs);
123
124 if (err != OK) {
125 return err;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700126 }
127
Andreas Huber27366fc2009-11-20 09:32:46 -0800128 *msec = (positionUs + 500) / 1000;
129
Andreas Hubere46b7be2009-07-14 16:56:47 -0700130 return OK;
131}
132
133status_t StagefrightPlayer::getDuration(int *msec) {
134 LOGV("getDuration");
135
Andreas Huber27366fc2009-11-20 09:32:46 -0800136 int64_t durationUs;
137 status_t err = mPlayer->getDuration(&durationUs);
138
139 if (err != OK) {
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700140 *msec = 0;
141 return OK;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700142 }
143
Andreas Huber27366fc2009-11-20 09:32:46 -0800144 *msec = (durationUs + 500) / 1000;
145
Andreas Hubere46b7be2009-07-14 16:56:47 -0700146 return OK;
147}
148
149status_t StagefrightPlayer::reset() {
150 LOGV("reset");
151
Andreas Huber27366fc2009-11-20 09:32:46 -0800152 mPlayer->reset();
Andreas Hubere46b7be2009-07-14 16:56:47 -0700153
154 return OK;
155}
156
157status_t StagefrightPlayer::setLooping(int loop) {
158 LOGV("setLooping");
Andreas Huber27366fc2009-11-20 09:32:46 -0800159
160 return mPlayer->setLooping(loop);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700161}
162
163player_type StagefrightPlayer::playerType() {
164 LOGV("playerType");
165 return STAGEFRIGHT_PLAYER;
166}
167
168status_t StagefrightPlayer::invoke(const Parcel &request, Parcel *reply) {
169 return INVALID_OPERATION;
170}
171
172void StagefrightPlayer::setAudioSink(const sp<AudioSink> &audioSink) {
173 MediaPlayerInterface::setAudioSink(audioSink);
174
Andreas Huber27366fc2009-11-20 09:32:46 -0800175 mPlayer->setAudioSink(audioSink);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700176}
177
Gloria Wangd01ec6e2011-04-25 17:28:22 -0700178status_t StagefrightPlayer::setParameter(int key, const Parcel &request) {
179 LOGV("setParameter");
180 return mPlayer->setParameter(key, request);
181}
182
183status_t StagefrightPlayer::getParameter(int key, Parcel *reply) {
184 LOGV("getParameter");
185 return mPlayer->getParameter(key, reply);
186}
187
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700188status_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 Huber10b9b3f2010-10-08 10:16:24 -0700208 metadata.appendBool(
209 Metadata::kSeekAvailable,
210 flags & MediaExtractor::CAN_SEEK);
211
Andreas Huber62f7ffe2010-05-06 10:18:05 -0700212 return OK;
213}
214
Andreas Huberfddf5d92011-06-07 15:52:25 -0700215status_t StagefrightPlayer::dump(int fd, const Vector<String16> &args) const {
216 return mPlayer->dump(fd, args);
217}
218
Andreas Hubere46b7be2009-07-14 16:56:47 -0700219} // namespace android