mediaplayer.cpp revision 64760240f931714858a59c1579f07264d7182ba2
1/* mediaplayer.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "MediaPlayer"
20#include <utils/Log.h>
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <unistd.h>
25#include <fcntl.h>
26
27#include <binder/IServiceManager.h>
28#include <binder/IPCThreadState.h>
29
30#include <media/mediaplayer.h>
31#include <media/AudioTrack.h>
32
33#include <surfaceflinger/Surface.h>
34
35#include <binder/MemoryBase.h>
36
37#include <utils/KeyedVector.h>
38#include <utils/String8.h>
39
40#include <system/audio.h>
41
42namespace android {
43
44MediaPlayer::MediaPlayer()
45{
46    LOGV("constructor");
47    mListener = NULL;
48    mCookie = NULL;
49    mDuration = -1;
50    mStreamType = AUDIO_STREAM_MUSIC;
51    mCurrentPosition = -1;
52    mSeekPosition = -1;
53    mCurrentState = MEDIA_PLAYER_IDLE;
54    mPrepareSync = false;
55    mPrepareStatus = NO_ERROR;
56    mLoop = false;
57    mLeftVolume = mRightVolume = 1.0;
58    mVideoWidth = mVideoHeight = 0;
59    mLockThreadId = 0;
60    mAudioSessionId = AudioSystem::newAudioSessionId();
61    mSendLevel = 0;
62}
63
64MediaPlayer::~MediaPlayer()
65{
66    LOGV("destructor");
67    disconnect();
68    IPCThreadState::self()->flushCommands();
69}
70
71void MediaPlayer::disconnect()
72{
73    LOGV("disconnect");
74    sp<IMediaPlayer> p;
75    {
76        Mutex::Autolock _l(mLock);
77        p = mPlayer;
78        mPlayer.clear();
79    }
80
81    if (p != 0) {
82        p->disconnect();
83    }
84}
85
86// always call with lock held
87void MediaPlayer::clear_l()
88{
89    mDuration = -1;
90    mCurrentPosition = -1;
91    mSeekPosition = -1;
92    mVideoWidth = mVideoHeight = 0;
93}
94
95status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener)
96{
97    LOGV("setListener");
98    Mutex::Autolock _l(mLock);
99    mListener = listener;
100    return NO_ERROR;
101}
102
103
104status_t MediaPlayer::setDataSource(const sp<IMediaPlayer>& player)
105{
106    status_t err = UNKNOWN_ERROR;
107    sp<IMediaPlayer> p;
108    { // scope for the lock
109        Mutex::Autolock _l(mLock);
110
111        if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
112                (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
113            LOGE("setDataSource called in state %d", mCurrentState);
114            return INVALID_OPERATION;
115        }
116
117        clear_l();
118        p = mPlayer;
119        mPlayer = player;
120        if (player != 0) {
121            mCurrentState = MEDIA_PLAYER_INITIALIZED;
122            err = NO_ERROR;
123        } else {
124            LOGE("Unable to to create media player");
125        }
126    }
127
128    if (p != 0) {
129        p->disconnect();
130    }
131
132    return err;
133}
134
135status_t MediaPlayer::setDataSource(
136        const char *url, const KeyedVector<String8, String8> *headers)
137{
138    LOGV("setDataSource(%s)", url);
139    status_t err = BAD_VALUE;
140    if (url != NULL) {
141        const sp<IMediaPlayerService>& service(getMediaPlayerService());
142        if (service != 0) {
143            sp<IMediaPlayer> player(
144                    service->create(getpid(), this, url, headers, mAudioSessionId));
145            err = setDataSource(player);
146        }
147    }
148    return err;
149}
150
151status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
152{
153    LOGV("setDataSource(%d, %lld, %lld)", fd, offset, length);
154    status_t err = UNKNOWN_ERROR;
155    const sp<IMediaPlayerService>& service(getMediaPlayerService());
156    if (service != 0) {
157        sp<IMediaPlayer> player(service->create(getpid(), this, fd, offset, length, mAudioSessionId));
158        err = setDataSource(player);
159    }
160    return err;
161}
162
163status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply)
164{
165    Mutex::Autolock _l(mLock);
166    const bool hasBeenInitialized =
167            (mCurrentState != MEDIA_PLAYER_STATE_ERROR) &&
168            ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE);
169    if ((mPlayer != NULL) && hasBeenInitialized) {
170         LOGV("invoke %d", request.dataSize());
171         return  mPlayer->invoke(request, reply);
172    }
173    LOGE("invoke failed: wrong state %X", mCurrentState);
174    return INVALID_OPERATION;
175}
176
177status_t MediaPlayer::setMetadataFilter(const Parcel& filter)
178{
179    LOGD("setMetadataFilter");
180    Mutex::Autolock lock(mLock);
181    if (mPlayer == NULL) {
182        return NO_INIT;
183    }
184    return mPlayer->setMetadataFilter(filter);
185}
186
187status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
188{
189    LOGD("getMetadata");
190    Mutex::Autolock lock(mLock);
191    if (mPlayer == NULL) {
192        return NO_INIT;
193    }
194    return mPlayer->getMetadata(update_only, apply_filter, metadata);
195}
196
197status_t MediaPlayer::setVideoSurface(const sp<Surface>& surface)
198{
199    LOGV("setVideoSurface");
200    Mutex::Autolock _l(mLock);
201    if (mPlayer == 0) return NO_INIT;
202
203    return mPlayer->setVideoSurface(surface);
204}
205
206status_t MediaPlayer::setVideoSurfaceTexture(
207        const sp<ISurfaceTexture>& surfaceTexture)
208{
209    LOGV("setVideoSurfaceTexture");
210    Mutex::Autolock _l(mLock);
211    if (mPlayer == 0) return NO_INIT;
212
213    return mPlayer->setVideoSurfaceTexture(surfaceTexture);
214}
215
216// must call with lock held
217status_t MediaPlayer::prepareAsync_l()
218{
219    if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) {
220        mPlayer->setAudioStreamType(mStreamType);
221        mCurrentState = MEDIA_PLAYER_PREPARING;
222        return mPlayer->prepareAsync();
223    }
224    LOGE("prepareAsync called in state %d", mCurrentState);
225    return INVALID_OPERATION;
226}
227
228// TODO: In case of error, prepareAsync provides the caller with 2 error codes,
229// one defined in the Android framework and one provided by the implementation
230// that generated the error. The sync version of prepare returns only 1 error
231// code.
232status_t MediaPlayer::prepare()
233{
234    LOGV("prepare");
235    Mutex::Autolock _l(mLock);
236    mLockThreadId = getThreadId();
237    if (mPrepareSync) {
238        mLockThreadId = 0;
239        return -EALREADY;
240    }
241    mPrepareSync = true;
242    status_t ret = prepareAsync_l();
243    if (ret != NO_ERROR) {
244        mLockThreadId = 0;
245        return ret;
246    }
247
248    if (mPrepareSync) {
249        mSignal.wait(mLock);  // wait for prepare done
250        mPrepareSync = false;
251    }
252    LOGV("prepare complete - status=%d", mPrepareStatus);
253    mLockThreadId = 0;
254    return mPrepareStatus;
255}
256
257status_t MediaPlayer::prepareAsync()
258{
259    LOGV("prepareAsync");
260    Mutex::Autolock _l(mLock);
261    return prepareAsync_l();
262}
263
264status_t MediaPlayer::start()
265{
266    LOGV("start");
267    Mutex::Autolock _l(mLock);
268    if (mCurrentState & MEDIA_PLAYER_STARTED)
269        return NO_ERROR;
270    if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED |
271                    MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) {
272        mPlayer->setLooping(mLoop);
273        mPlayer->setVolume(mLeftVolume, mRightVolume);
274        mPlayer->setAuxEffectSendLevel(mSendLevel);
275        mCurrentState = MEDIA_PLAYER_STARTED;
276        status_t ret = mPlayer->start();
277        if (ret != NO_ERROR) {
278            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
279        } else {
280            if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) {
281                LOGV("playback completed immediately following start()");
282            }
283        }
284        return ret;
285    }
286    LOGE("start called in state %d", mCurrentState);
287    return INVALID_OPERATION;
288}
289
290status_t MediaPlayer::stop()
291{
292    LOGV("stop");
293    Mutex::Autolock _l(mLock);
294    if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR;
295    if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
296                    MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) {
297        status_t ret = mPlayer->stop();
298        if (ret != NO_ERROR) {
299            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
300        } else {
301            mCurrentState = MEDIA_PLAYER_STOPPED;
302        }
303        return ret;
304    }
305    LOGE("stop called in state %d", mCurrentState);
306    return INVALID_OPERATION;
307}
308
309status_t MediaPlayer::pause()
310{
311    LOGV("pause");
312    Mutex::Autolock _l(mLock);
313    if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE))
314        return NO_ERROR;
315    if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) {
316        status_t ret = mPlayer->pause();
317        if (ret != NO_ERROR) {
318            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
319        } else {
320            mCurrentState = MEDIA_PLAYER_PAUSED;
321        }
322        return ret;
323    }
324    LOGE("pause called in state %d", mCurrentState);
325    return INVALID_OPERATION;
326}
327
328bool MediaPlayer::isPlaying()
329{
330    Mutex::Autolock _l(mLock);
331    if (mPlayer != 0) {
332        bool temp = false;
333        mPlayer->isPlaying(&temp);
334        LOGV("isPlaying: %d", temp);
335        if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) {
336            LOGE("internal/external state mismatch corrected");
337            mCurrentState = MEDIA_PLAYER_PAUSED;
338        }
339        return temp;
340    }
341    LOGV("isPlaying: no active player");
342    return false;
343}
344
345status_t MediaPlayer::getVideoWidth(int *w)
346{
347    LOGV("getVideoWidth");
348    Mutex::Autolock _l(mLock);
349    if (mPlayer == 0) return INVALID_OPERATION;
350    *w = mVideoWidth;
351    return NO_ERROR;
352}
353
354status_t MediaPlayer::getVideoHeight(int *h)
355{
356    LOGV("getVideoHeight");
357    Mutex::Autolock _l(mLock);
358    if (mPlayer == 0) return INVALID_OPERATION;
359    *h = mVideoHeight;
360    return NO_ERROR;
361}
362
363status_t MediaPlayer::getCurrentPosition(int *msec)
364{
365    LOGV("getCurrentPosition");
366    Mutex::Autolock _l(mLock);
367    if (mPlayer != 0) {
368        if (mCurrentPosition >= 0) {
369            LOGV("Using cached seek position: %d", mCurrentPosition);
370            *msec = mCurrentPosition;
371            return NO_ERROR;
372        }
373        return mPlayer->getCurrentPosition(msec);
374    }
375    return INVALID_OPERATION;
376}
377
378status_t MediaPlayer::getDuration_l(int *msec)
379{
380    LOGV("getDuration");
381    bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE));
382    if (mPlayer != 0 && isValidState) {
383        status_t ret = NO_ERROR;
384        if (mDuration <= 0)
385            ret = mPlayer->getDuration(&mDuration);
386        if (msec)
387            *msec = mDuration;
388        return ret;
389    }
390    LOGE("Attempt to call getDuration without a valid mediaplayer");
391    return INVALID_OPERATION;
392}
393
394status_t MediaPlayer::getDuration(int *msec)
395{
396    Mutex::Autolock _l(mLock);
397    return getDuration_l(msec);
398}
399
400status_t MediaPlayer::seekTo_l(int msec)
401{
402    LOGV("seekTo %d", msec);
403    if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED |  MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) {
404        if ( msec < 0 ) {
405            LOGW("Attempt to seek to invalid position: %d", msec);
406            msec = 0;
407        } else if ((mDuration > 0) && (msec > mDuration)) {
408            LOGW("Attempt to seek to past end of file: request = %d, EOF = %d", msec, mDuration);
409            msec = mDuration;
410        }
411        // cache duration
412        mCurrentPosition = msec;
413        if (mSeekPosition < 0) {
414            getDuration_l(NULL);
415            mSeekPosition = msec;
416            return mPlayer->seekTo(msec);
417        }
418        else {
419            LOGV("Seek in progress - queue up seekTo[%d]", msec);
420            return NO_ERROR;
421        }
422    }
423    LOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState);
424    return INVALID_OPERATION;
425}
426
427status_t MediaPlayer::seekTo(int msec)
428{
429    mLockThreadId = getThreadId();
430    Mutex::Autolock _l(mLock);
431    status_t result = seekTo_l(msec);
432    mLockThreadId = 0;
433
434    return result;
435}
436
437status_t MediaPlayer::reset()
438{
439    LOGV("reset");
440    Mutex::Autolock _l(mLock);
441    mLoop = false;
442    if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR;
443    mPrepareSync = false;
444    if (mPlayer != 0) {
445        status_t ret = mPlayer->reset();
446        if (ret != NO_ERROR) {
447            LOGE("reset() failed with return code (%d)", ret);
448            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
449        } else {
450            mCurrentState = MEDIA_PLAYER_IDLE;
451        }
452        // setDataSource has to be called again to create a
453        // new mediaplayer.
454        mPlayer = 0;
455        return ret;
456    }
457    clear_l();
458    return NO_ERROR;
459}
460
461status_t MediaPlayer::setAudioStreamType(int type)
462{
463    LOGV("MediaPlayer::setAudioStreamType");
464    Mutex::Autolock _l(mLock);
465    if (mStreamType == type) return NO_ERROR;
466    if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
467                MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) {
468        // Can't change the stream type after prepare
469        LOGE("setAudioStream called in state %d", mCurrentState);
470        return INVALID_OPERATION;
471    }
472    // cache
473    mStreamType = type;
474    return OK;
475}
476
477status_t MediaPlayer::setLooping(int loop)
478{
479    LOGV("MediaPlayer::setLooping");
480    Mutex::Autolock _l(mLock);
481    mLoop = (loop != 0);
482    if (mPlayer != 0) {
483        return mPlayer->setLooping(loop);
484    }
485    return OK;
486}
487
488bool MediaPlayer::isLooping() {
489    LOGV("isLooping");
490    Mutex::Autolock _l(mLock);
491    if (mPlayer != 0) {
492        return mLoop;
493    }
494    LOGV("isLooping: no active player");
495    return false;
496}
497
498status_t MediaPlayer::setVolume(float leftVolume, float rightVolume)
499{
500    LOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume);
501    Mutex::Autolock _l(mLock);
502    mLeftVolume = leftVolume;
503    mRightVolume = rightVolume;
504    if (mPlayer != 0) {
505        return mPlayer->setVolume(leftVolume, rightVolume);
506    }
507    return OK;
508}
509
510status_t MediaPlayer::setAudioSessionId(int sessionId)
511{
512    LOGV("MediaPlayer::setAudioSessionId(%d)", sessionId);
513    Mutex::Autolock _l(mLock);
514    if (!(mCurrentState & MEDIA_PLAYER_IDLE)) {
515        LOGE("setAudioSessionId called in state %d", mCurrentState);
516        return INVALID_OPERATION;
517    }
518    if (sessionId < 0) {
519        return BAD_VALUE;
520    }
521    mAudioSessionId = sessionId;
522    return NO_ERROR;
523}
524
525int MediaPlayer::getAudioSessionId()
526{
527    Mutex::Autolock _l(mLock);
528    return mAudioSessionId;
529}
530
531status_t MediaPlayer::setAuxEffectSendLevel(float level)
532{
533    LOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level);
534    Mutex::Autolock _l(mLock);
535    mSendLevel = level;
536    if (mPlayer != 0) {
537        return mPlayer->setAuxEffectSendLevel(level);
538    }
539    return OK;
540}
541
542status_t MediaPlayer::attachAuxEffect(int effectId)
543{
544    LOGV("MediaPlayer::attachAuxEffect(%d)", effectId);
545    Mutex::Autolock _l(mLock);
546    if (mPlayer == 0 ||
547        (mCurrentState & MEDIA_PLAYER_IDLE) ||
548        (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) {
549        LOGE("attachAuxEffect called in state %d", mCurrentState);
550        return INVALID_OPERATION;
551    }
552
553    return mPlayer->attachAuxEffect(effectId);
554}
555
556status_t MediaPlayer::setParameter(int key, const Parcel& request)
557{
558    LOGV("MediaPlayer::setParameter(%d)", key);
559    Mutex::Autolock _l(mLock);
560    if (mPlayer != NULL) {
561        return  mPlayer->setParameter(key, request);
562    }
563    LOGV("setParameter: no active player");
564    return INVALID_OPERATION;
565}
566
567status_t MediaPlayer::getParameter(int key, Parcel *reply)
568{
569    LOGV("MediaPlayer::getParameter(%d)", key);
570    Mutex::Autolock _l(mLock);
571    if (mPlayer != NULL) {
572         return  mPlayer->getParameter(key, reply);
573    }
574    LOGV("getParameter: no active player");
575    return INVALID_OPERATION;
576}
577
578void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
579{
580    LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
581    bool send = true;
582    bool locked = false;
583
584    // TODO: In the future, we might be on the same thread if the app is
585    // running in the same process as the media server. In that case,
586    // this will deadlock.
587    //
588    // The threadId hack below works around this for the care of prepare
589    // and seekTo within the same process.
590    // FIXME: Remember, this is a hack, it's not even a hack that is applied
591    // consistently for all use-cases, this needs to be revisited.
592     if (mLockThreadId != getThreadId()) {
593        mLock.lock();
594        locked = true;
595    }
596
597    // Allows calls from JNI in idle state to notify errors
598    if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) {
599        LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
600        if (locked) mLock.unlock();   // release the lock when done.
601        return;
602    }
603
604    switch (msg) {
605    case MEDIA_NOP: // interface test message
606        break;
607    case MEDIA_PREPARED:
608        LOGV("prepared");
609        mCurrentState = MEDIA_PLAYER_PREPARED;
610        if (mPrepareSync) {
611            LOGV("signal application thread");
612            mPrepareSync = false;
613            mPrepareStatus = NO_ERROR;
614            mSignal.signal();
615        }
616        break;
617    case MEDIA_PLAYBACK_COMPLETE:
618        LOGV("playback complete");
619        if (mCurrentState == MEDIA_PLAYER_IDLE) {
620            LOGE("playback complete in idle state");
621        }
622        if (!mLoop) {
623            mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE;
624        }
625        break;
626    case MEDIA_ERROR:
627        // Always log errors.
628        // ext1: Media framework error code.
629        // ext2: Implementation dependant error code.
630        LOGE("error (%d, %d)", ext1, ext2);
631        mCurrentState = MEDIA_PLAYER_STATE_ERROR;
632        if (mPrepareSync)
633        {
634            LOGV("signal application thread");
635            mPrepareSync = false;
636            mPrepareStatus = ext1;
637            mSignal.signal();
638            send = false;
639        }
640        break;
641    case MEDIA_INFO:
642        // ext1: Media framework error code.
643        // ext2: Implementation dependant error code.
644        if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) {
645            LOGW("info/warning (%d, %d)", ext1, ext2);
646        }
647        break;
648    case MEDIA_SEEK_COMPLETE:
649        LOGV("Received seek complete");
650        if (mSeekPosition != mCurrentPosition) {
651            LOGV("Executing queued seekTo(%d)", mSeekPosition);
652            mSeekPosition = -1;
653            seekTo_l(mCurrentPosition);
654        }
655        else {
656            LOGV("All seeks complete - return to regularly scheduled program");
657            mCurrentPosition = mSeekPosition = -1;
658        }
659        break;
660    case MEDIA_BUFFERING_UPDATE:
661        LOGV("buffering %d", ext1);
662        break;
663    case MEDIA_SET_VIDEO_SIZE:
664        LOGV("New video size %d x %d", ext1, ext2);
665        mVideoWidth = ext1;
666        mVideoHeight = ext2;
667        break;
668    case MEDIA_TIMED_TEXT:
669        LOGV("Received timed text message");
670        break;
671    default:
672        LOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2);
673        break;
674    }
675
676    sp<MediaPlayerListener> listener = mListener;
677    if (locked) mLock.unlock();
678
679    // this prevents re-entrant calls into client code
680    if ((listener != 0) && send) {
681        Mutex::Autolock _l(mNotifyLock);
682        LOGV("callback application");
683        listener->notify(msg, ext1, ext2, obj);
684        LOGV("back from callback");
685    }
686}
687
688/*static*/ sp<IMemory> MediaPlayer::decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat)
689{
690    LOGV("decode(%s)", url);
691    sp<IMemory> p;
692    const sp<IMediaPlayerService>& service = getMediaPlayerService();
693    if (service != 0) {
694        p = service->decode(url, pSampleRate, pNumChannels, pFormat);
695    } else {
696        LOGE("Unable to locate media service");
697    }
698    return p;
699
700}
701
702void MediaPlayer::died()
703{
704    LOGV("died");
705    notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0);
706}
707
708/*static*/ sp<IMemory> MediaPlayer::decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat)
709{
710    LOGV("decode(%d, %lld, %lld)", fd, offset, length);
711    sp<IMemory> p;
712    const sp<IMediaPlayerService>& service = getMediaPlayerService();
713    if (service != 0) {
714        p = service->decode(fd, offset, length, pSampleRate, pNumChannels, pFormat);
715    } else {
716        LOGE("Unable to locate media service");
717    }
718    return p;
719
720}
721
722}; // namespace android
723