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