199e53b86eebb605b70dd7591b89bf61a9414ed0eGlenn Kasten/*
289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** Copyright 2006, The Android Open Source Project
489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");
689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** you may not use this file except in compliance with the License.
789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** You may obtain a copy of the License at
889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**     http://www.apache.org/licenses/LICENSE-2.0
1089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
1189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** Unless required by applicable law or agreed to in writing, software
1289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** distributed under the License is distributed on an "AS IS" BASIS,
1389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** See the License for the specific language governing permissions and
1589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** limitations under the License.
1689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project*/
1789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project//#define LOG_NDEBUG 0
1989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define LOG_TAG "MediaPlayer"
2089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2134fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn#include <fcntl.h>
2234fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn#include <inttypes.h>
2389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <sys/stat.h>
2434fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn#include <sys/types.h>
2589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <unistd.h>
2634fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn
2734fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn#include <utils/Log.h>
2889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
297562408b2261d38415453378b6188f74fda99d88Mathias Agopian#include <binder/IServiceManager.h>
307562408b2261d38415453378b6188f74fda99d88Mathias Agopian#include <binder/IPCThreadState.h>
3189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
32b1e7cd156ca3e1747374e0d20cdd1ce467210453Mathias Agopian#include <gui/Surface.h>
3361c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis
3489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <media/mediaplayer.h>
35a3f1fa308728976fc9ca1b4f37d26e633b32b9acGlenn Kasten#include <media/AudioSystem.h>
3689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
377562408b2261d38415453378b6188f74fda99d88Mathias Agopian#include <binder/MemoryBase.h>
3889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
392db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber#include <utils/KeyedVector.h>
402db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber#include <utils/String8.h>
412db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber
4264760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
4361c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis#include <system/window.h>
44fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
4589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectnamespace android {
4689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
4789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source ProjectMediaPlayer::MediaPlayer()
4889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("constructor");
5089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mListener = NULL;
5189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mCookie = NULL;
52fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mStreamType = AUDIO_STREAM_MUSIC;
53640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    mAudioAttributesParcel = NULL;
5489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mCurrentPosition = -1;
5589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mSeekPosition = -1;
5689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mCurrentState = MEDIA_PLAYER_IDLE;
5789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mPrepareSync = false;
5889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mPrepareStatus = NO_ERROR;
5989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mLoop = false;
6089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mLeftVolume = mRightVolume = 1.0;
6189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mVideoWidth = mVideoHeight = 0;
621af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    mLockThreadId = 0;
63de3f8392fbf380ba6f09d009b00d7172477389a2Eric Laurent    mAudioSessionId = AudioSystem::newAudioUniqueId();
64d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen    AudioSystem::acquireAudioSessionId(mAudioSessionId, -1);
658c563ed9ca8a863a66965330b5d14bb4b4ab59d4Eric Laurent    mSendLevel = 0;
66c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpointValid = false;
6789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
6889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
6989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source ProjectMediaPlayer::~MediaPlayer()
7089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("destructor");
72640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    if (mAudioAttributesParcel != NULL) {
73640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        delete mAudioAttributesParcel;
74640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        mAudioAttributesParcel = NULL;
75640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    }
76d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen    AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
7789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    disconnect();
7889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    IPCThreadState::self()->flushCommands();
7989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
8089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
8189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectvoid MediaPlayer::disconnect()
8289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("disconnect");
8489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    sp<IMediaPlayer> p;
8589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
8689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        Mutex::Autolock _l(mLock);
8789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        p = mPlayer;
8889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer.clear();
8989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
9089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
9189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (p != 0) {
9289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        p->disconnect();
9389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
9489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
9589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
9689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// always call with lock held
9789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectvoid MediaPlayer::clear_l()
9889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
9989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mCurrentPosition = -1;
10089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mSeekPosition = -1;
10189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mVideoWidth = mVideoHeight = 0;
102c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpointValid = false;
10389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
10489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
10589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener)
10689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
1073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setListener");
10889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
10989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mListener = listener;
11089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return NO_ERROR;
11189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
11289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
11389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
114d681bbb1767bed09415e050ba78975df214bcd68Dave Burkestatus_t MediaPlayer::attachNewPlayer(const sp<IMediaPlayer>& player)
11589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
11689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    status_t err = UNKNOWN_ERROR;
11789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    sp<IMediaPlayer> p;
11889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    { // scope for the lock
11989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        Mutex::Autolock _l(mLock);
12089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
12183ff1438d2d1d5dbf39ca5e6f2e4fa1799e7ba80Marco Nelissen        if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
12283ff1438d2d1d5dbf39ca5e6f2e4fa1799e7ba80Marco Nelissen                (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
12329357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("attachNewPlayer called in state %d", mCurrentState);
12489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return INVALID_OPERATION;
12589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
12689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
12789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        clear_l();
12889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        p = mPlayer;
12989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer = player;
13089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (player != 0) {
13189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_INITIALIZED;
13289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            err = NO_ERROR;
13389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } else {
134f65fa170b28f97503df3c309ecdaab377a042ba6Masaki Muranaka            ALOGE("Unable to create media player");
13589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
13689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
13789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
13889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (p != 0) {
13989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        p->disconnect();
14089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
14189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
14289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return err;
14389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
14489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1452db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huberstatus_t MediaPlayer::setDataSource(
1461b86fe063badb5f28c467ade39be0f4008688947Andreas Huber        const sp<IMediaHTTPService> &httpService,
1472db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber        const char *url, const KeyedVector<String8, String8> *headers)
14889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
1493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setDataSource(%s)", url);
15089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    status_t err = BAD_VALUE;
15189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (url != NULL) {
15289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        const sp<IMediaPlayerService>& service(getMediaPlayerService());
15389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (service != 0) {
154f37971f624164c3ed185d3f976404a6f60f49b9aGlenn Kasten            sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
155c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman            if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
1561b86fe063badb5f28c467ade39be0f4008688947Andreas Huber                (NO_ERROR != player->setDataSource(httpService, url, headers))) {
1570662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke                player.clear();
158d681bbb1767bed09415e050ba78975df214bcd68Dave Burke            }
1590662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke            err = attachNewPlayer(player);
16089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
16189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
16289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return err;
16389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
16489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
16589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
16689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
16734fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn    ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length);
16889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    status_t err = UNKNOWN_ERROR;
16989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    const sp<IMediaPlayerService>& service(getMediaPlayerService());
17089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (service != 0) {
171f37971f624164c3ed185d3f976404a6f60f49b9aGlenn Kasten        sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
172c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
173c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman            (NO_ERROR != player->setDataSource(fd, offset, length))) {
1740662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke            player.clear();
175d681bbb1767bed09415e050ba78975df214bcd68Dave Burke        }
1760662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke        err = attachNewPlayer(player);
177d681bbb1767bed09415e050ba78975df214bcd68Dave Burke    }
178d681bbb1767bed09415e050ba78975df214bcd68Dave Burke    return err;
179d681bbb1767bed09415e050ba78975df214bcd68Dave Burke}
180d681bbb1767bed09415e050ba78975df214bcd68Dave Burke
181d681bbb1767bed09415e050ba78975df214bcd68Dave Burkestatus_t MediaPlayer::setDataSource(const sp<IStreamSource> &source)
182d681bbb1767bed09415e050ba78975df214bcd68Dave Burke{
1833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setDataSource");
184d681bbb1767bed09415e050ba78975df214bcd68Dave Burke    status_t err = UNKNOWN_ERROR;
185d681bbb1767bed09415e050ba78975df214bcd68Dave Burke    const sp<IMediaPlayerService>& service(getMediaPlayerService());
186d681bbb1767bed09415e050ba78975df214bcd68Dave Burke    if (service != 0) {
187f37971f624164c3ed185d3f976404a6f60f49b9aGlenn Kasten        sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
188c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
189c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman            (NO_ERROR != player->setDataSource(source))) {
1900662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke            player.clear();
191d681bbb1767bed09415e050ba78975df214bcd68Dave Burke        }
1920662067b06658a4a56a8416c676f6cce8ccddb53Dave Burke        err = attachNewPlayer(player);
19389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
19489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return err;
19589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
19689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1971d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Cataniastatus_t MediaPlayer::invoke(const Parcel& request, Parcel *reply)
1981d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania{
1991d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    Mutex::Autolock _l(mLock);
2004023493a827bc9751d8e40795516d0d536a53348Nicolas Catania    const bool hasBeenInitialized =
2014023493a827bc9751d8e40795516d0d536a53348Nicolas Catania            (mCurrentState != MEDIA_PLAYER_STATE_ERROR) &&
2024023493a827bc9751d8e40795516d0d536a53348Nicolas Catania            ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE);
2034023493a827bc9751d8e40795516d0d536a53348Nicolas Catania    if ((mPlayer != NULL) && hasBeenInitialized) {
20434fb29696b0f3abf61b10f8d053b1f33d501de0aMark Salyzyn        ALOGV("invoke %zu", request.dataSize());
205e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten        return  mPlayer->invoke(request, reply);
2061d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    }
20729357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("invoke failed: wrong state %X", mCurrentState);
2081d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    return INVALID_OPERATION;
2091d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania}
2101d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania
211a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Cataniastatus_t MediaPlayer::setMetadataFilter(const Parcel& filter)
212a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Catania{
213b8a805261bf0282e992d3608035e47d05a898710Steve Block    ALOGD("setMetadataFilter");
2148e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    Mutex::Autolock lock(mLock);
2158e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    if (mPlayer == NULL) {
216a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Catania        return NO_INIT;
217a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Catania    }
218a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Catania    return mPlayer->setMetadataFilter(filter);
219a7e0e8b4c429fc68eb1bd5b5a30f5b91352288f9Nicolas Catania}
2201d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania
2218e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Cataniastatus_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
2228e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania{
223b8a805261bf0282e992d3608035e47d05a898710Steve Block    ALOGD("getMetadata");
2248e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    Mutex::Autolock lock(mLock);
2258e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    if (mPlayer == NULL) {
2268e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania        return NO_INIT;
2278e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    }
2288e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania    return mPlayer->getMetadata(update_only, apply_filter, metadata);
2298e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania}
2308e1b6cce24574b9ecd5b0300155776bd0b4ef756Nicolas Catania
2311173118eace0e9e347cb007f0da817cee87579edGlenn Kastenstatus_t MediaPlayer::setVideoSurfaceTexture(
232484566c410afdfbc4b6bc5aa1732aef37428a5b8Andy McFadden        const sp<IGraphicBufferProducer>& bufferProducer)
2331173118eace0e9e347cb007f0da817cee87579edGlenn Kasten{
2343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setVideoSurfaceTexture");
2351173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    Mutex::Autolock _l(mLock);
2361173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    if (mPlayer == 0) return NO_INIT;
237484566c410afdfbc4b6bc5aa1732aef37428a5b8Andy McFadden    return mPlayer->setVideoSurfaceTexture(bufferProducer);
2381173118eace0e9e347cb007f0da817cee87579edGlenn Kasten}
2391173118eace0e9e347cb007f0da817cee87579edGlenn Kasten
24089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// must call with lock held
24189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::prepareAsync_l()
24289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
24389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) {
24489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer->setAudioStreamType(mStreamType);
245640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        if (mAudioAttributesParcel != NULL) {
246640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi            mPlayer->setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, *mAudioAttributesParcel);
247640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        }
24889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mCurrentState = MEDIA_PLAYER_PREPARING;
24989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return mPlayer->prepareAsync();
25089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
25129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("prepareAsync called in state %d", mCurrentState);
25289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
25389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
25489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
25565e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project// TODO: In case of error, prepareAsync provides the caller with 2 error codes,
25665e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project// one defined in the Android framework and one provided by the implementation
25765e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project// that generated the error. The sync version of prepare returns only 1 error
25865e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project// code.
25989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::prepare()
26089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
2613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("prepare");
26289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
2631af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    mLockThreadId = getThreadId();
2641af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    if (mPrepareSync) {
2651af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        mLockThreadId = 0;
2661af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        return -EALREADY;
2671af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    }
26889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mPrepareSync = true;
26989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    status_t ret = prepareAsync_l();
2701af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    if (ret != NO_ERROR) {
2711af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        mLockThreadId = 0;
2721af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        return ret;
2731af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    }
27489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
27589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPrepareSync) {
27689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mSignal.wait(mLock);  // wait for prepare done
27789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPrepareSync = false;
27889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
2793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("prepare complete - status=%d", mPrepareStatus);
2801af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    mLockThreadId = 0;
28189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return mPrepareStatus;
28289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
28389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
28489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::prepareAsync()
28589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
2863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("prepareAsync");
28789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
28889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return prepareAsync_l();
28989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
29089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
29189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::start()
29289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
2933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("start");
294d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang
295d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    status_t ret = NO_ERROR;
29689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
297d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang
298d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    mLockThreadId = getThreadId();
299d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang
300d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    if (mCurrentState & MEDIA_PLAYER_STARTED) {
301d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang        ret = NO_ERROR;
302d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    } else if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED |
30389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project                    MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) {
30489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer->setLooping(mLoop);
30589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer->setVolume(mLeftVolume, mRightVolume);
3062beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent        mPlayer->setAuxEffectSendLevel(mSendLevel);
30789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mCurrentState = MEDIA_PLAYER_STARTED;
308d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang        ret = mPlayer->start();
30989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (ret != NO_ERROR) {
31089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
31189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } else {
31289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) {
3133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("playback completed immediately following start()");
31489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            }
31589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
316d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    } else {
317d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang        ALOGE("start called in state %d", mCurrentState);
318d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang        ret = INVALID_OPERATION;
31989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
320d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang
321d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    mLockThreadId = 0;
322d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang
323d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    return ret;
32489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
32589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
32689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::stop()
32789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("stop");
32989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
33089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR;
33189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
33289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project                    MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) {
33389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        status_t ret = mPlayer->stop();
33489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (ret != NO_ERROR) {
33589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
33689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } else {
33789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_STOPPED;
33889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
33989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return ret;
34089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
34129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("stop called in state %d", mCurrentState);
34289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
34389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
34489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
34589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::pause()
34689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("pause");
34889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
349698f476590bc9e38d4d1d4155da9efdbedd357c4Marco Nelissen    if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE))
35089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return NO_ERROR;
35189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) {
35289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        status_t ret = mPlayer->pause();
35389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (ret != NO_ERROR) {
35489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
35589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } else {
35689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_PAUSED;
35789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
35889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return ret;
35989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
36029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("pause called in state %d", mCurrentState);
36189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
36289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
36389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
36489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectbool MediaPlayer::isPlaying()
36589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
36689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
36789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
36889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        bool temp = false;
36989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mPlayer->isPlaying(&temp);
3703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("isPlaying: %d", temp);
37189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) {
37229357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("internal/external state mismatch corrected");
37389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_PAUSED;
37489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
37589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return temp;
37689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
3773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("isPlaying: no active player");
37889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return false;
37989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
38089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
38189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::getVideoWidth(int *w)
38289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getVideoWidth");
38489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
38589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer == 0) return INVALID_OPERATION;
38689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    *w = mVideoWidth;
38789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return NO_ERROR;
38889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
38989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
39089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::getVideoHeight(int *h)
39189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getVideoHeight");
39389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
39489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer == 0) return INVALID_OPERATION;
39589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    *h = mVideoHeight;
39689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return NO_ERROR;
39789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
39889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
39989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::getCurrentPosition(int *msec)
40089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
4013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getCurrentPosition");
40289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
40389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
40489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (mCurrentPosition >= 0) {
4053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("Using cached seek position: %d", mCurrentPosition);
40689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            *msec = mCurrentPosition;
40789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return NO_ERROR;
40889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
40989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return mPlayer->getCurrentPosition(msec);
41089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
41189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
41289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
41389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
41489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::getDuration_l(int *msec)
41589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
416a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber    ALOGV("getDuration_l");
41789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE));
41889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0 && isValidState) {
419a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        int durationMs;
420a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        status_t ret = mPlayer->getDuration(&durationMs);
4212070254f241f52cadb69bc2323f56df72704f1caAndreas Huber
4222070254f241f52cadb69bc2323f56df72704f1caAndreas Huber        if (ret != OK) {
4232070254f241f52cadb69bc2323f56df72704f1caAndreas Huber            // Do not enter error state just because no duration was available.
4242070254f241f52cadb69bc2323f56df72704f1caAndreas Huber            durationMs = -1;
4252070254f241f52cadb69bc2323f56df72704f1caAndreas Huber            ret = OK;
4262070254f241f52cadb69bc2323f56df72704f1caAndreas Huber        }
4272070254f241f52cadb69bc2323f56df72704f1caAndreas Huber
428a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        if (msec) {
429a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber            *msec = durationMs;
430a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        }
43189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return ret;
43289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
43329357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("Attempt to call getDuration without a valid mediaplayer");
43489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
43589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
43689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
43789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::getDuration(int *msec)
43889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
43989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
44089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return getDuration_l(msec);
44189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
44289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
44389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::seekTo_l(int msec)
44489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
4453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("seekTo %d", msec);
44689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED |  MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) {
44789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if ( msec < 0 ) {
4485ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block            ALOGW("Attempt to seek to invalid position: %d", msec);
44989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            msec = 0;
45089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
451a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber
452a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        int durationMs;
453a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        status_t err = mPlayer->getDuration(&durationMs);
454a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber
455a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        if (err != OK) {
456a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber            ALOGW("Stream has no duration and is therefore not seekable.");
457a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber            return err;
458a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        }
459a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber
460a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        if (msec > durationMs) {
461a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber            ALOGW("Attempt to seek to past end of file: request = %d, "
462a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber                  "durationMs = %d",
463a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber                  msec,
464a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber                  durationMs);
465a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber
466a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber            msec = durationMs;
467a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber        }
468a4c5bc0f18fe272146426ab2eccad6215279c9f3Andreas Huber
46989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        // cache duration
47089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mCurrentPosition = msec;
47189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (mSeekPosition < 0) {
47289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mSeekPosition = msec;
47389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return mPlayer->seekTo(msec);
47489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
47589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        else {
4763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("Seek in progress - queue up seekTo[%d]", msec);
47789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return NO_ERROR;
47889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
47989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
48029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState);
48189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return INVALID_OPERATION;
48289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
48389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
48489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::seekTo(int msec)
48589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
4865cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    mLockThreadId = getThreadId();
48789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
4885cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    status_t result = seekTo_l(msec);
4895cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    mLockThreadId = 0;
4905cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber
4915cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    return result;
49289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
49389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
49461c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennisstatus_t MediaPlayer::reset_l()
49589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
49689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mLoop = false;
49789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR;
49889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mPrepareSync = false;
49989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
50089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        status_t ret = mPlayer->reset();
50189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (ret != NO_ERROR) {
50229357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("reset() failed with return code (%d)", ret);
50389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_STATE_ERROR;
50489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } else {
50589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_IDLE;
50689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
507a1680bce73ea1b051cc92e0df651a53944b104eeJames Dong        // setDataSource has to be called again to create a
508a1680bce73ea1b051cc92e0df651a53944b104eeJames Dong        // new mediaplayer.
509a1680bce73ea1b051cc92e0df651a53944b104eeJames Dong        mPlayer = 0;
51089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return ret;
51189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
51289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    clear_l();
51389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return NO_ERROR;
51489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
51589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
516c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossmanstatus_t MediaPlayer::doSetRetransmitEndpoint(const sp<IMediaPlayer>& player) {
517c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    Mutex::Autolock _l(mLock);
518c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
519c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    if (player == NULL) {
520c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        return UNKNOWN_ERROR;
521c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    }
522c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
523c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    if (mRetransmitEndpointValid) {
524c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        return player->setRetransmitEndpoint(&mRetransmitEndpoint);
525c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    }
526c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
527c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    return OK;
528c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman}
529c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
53061c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennisstatus_t MediaPlayer::reset()
53161c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis{
5323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("reset");
53361c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis    Mutex::Autolock _l(mLock);
53461c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis    return reset_l();
53561c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis}
53661c7ef5bde2c7ed94a078396aa65da67b47e5402Jamie Gennis
537fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenstatus_t MediaPlayer::setAudioStreamType(audio_stream_type_t type)
53889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
5393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setAudioStreamType");
54089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
54189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mStreamType == type) return NO_ERROR;
54289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
54389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project                MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) {
54489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        // Can't change the stream type after prepare
54529357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block        ALOGE("setAudioStream called in state %d", mCurrentState);
54689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return INVALID_OPERATION;
54789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
54889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // cache
54989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mStreamType = type;
55089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return OK;
55189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
55289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
553de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlockstatus_t MediaPlayer::getAudioStreamType(audio_stream_type_t *type)
554de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock{
555de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock    ALOGV("getAudioStreamType");
556de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock    Mutex::Autolock _l(mLock);
557de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock    *type = mStreamType;
558de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock    return OK;
559de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock}
560de9453fb5cbc9cd69fd1ea45d577851e3aa3b8c9John Spurlock
56189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::setLooping(int loop)
56289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
5633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setLooping");
56489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
56589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mLoop = (loop != 0);
56689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
56789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return mPlayer->setLooping(loop);
56889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
56989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return OK;
57089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
57189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
57289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectbool MediaPlayer::isLooping() {
5733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("isLooping");
57489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
57589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
57689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return mLoop;
57789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
5783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("isLooping: no active player");
57989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return false;
58089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
58189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
58289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t MediaPlayer::setVolume(float leftVolume, float rightVolume)
58389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
5843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume);
58589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    Mutex::Autolock _l(mLock);
58689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mLeftVolume = leftVolume;
58789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    mRightVolume = rightVolume;
58889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    if (mPlayer != 0) {
58989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return mPlayer->setVolume(leftVolume, rightVolume);
59089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
59189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    return OK;
59289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
59389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
594a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurentstatus_t MediaPlayer::setAudioSessionId(int sessionId)
595a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent{
5963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setAudioSessionId(%d)", sessionId);
597a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    Mutex::Autolock _l(mLock);
598a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    if (!(mCurrentState & MEDIA_PLAYER_IDLE)) {
59929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block        ALOGE("setAudioSessionId called in state %d", mCurrentState);
600a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent        return INVALID_OPERATION;
601a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    }
602a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    if (sessionId < 0) {
603a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent        return BAD_VALUE;
604a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    }
6053a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    if (sessionId != mAudioSessionId) {
606d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen        AudioSystem::acquireAudioSessionId(sessionId, -1);
607d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen        AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
608e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten        mAudioSessionId = sessionId;
6093a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    }
610a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    return NO_ERROR;
611a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent}
612a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent
613a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurentint MediaPlayer::getAudioSessionId()
614a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent{
615a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    Mutex::Autolock _l(mLock);
616a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent    return mAudioSessionId;
617a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent}
618a514bdb58b5de4986679f72b7204b4764f7a2778Eric Laurent
6192beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurentstatus_t MediaPlayer::setAuxEffectSendLevel(float level)
6202beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent{
6213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level);
6222beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    Mutex::Autolock _l(mLock);
6232beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    mSendLevel = level;
6242beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    if (mPlayer != 0) {
6252beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent        return mPlayer->setAuxEffectSendLevel(level);
6262beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    }
6272beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    return OK;
6282beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent}
6292beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent
6302beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurentstatus_t MediaPlayer::attachAuxEffect(int effectId)
6312beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent{
6323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::attachAuxEffect(%d)", effectId);
6332beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    Mutex::Autolock _l(mLock);
6342beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    if (mPlayer == 0 ||
6352beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent        (mCurrentState & MEDIA_PLAYER_IDLE) ||
6362beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent        (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) {
63729357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block        ALOGE("attachAuxEffect called in state %d", mCurrentState);
6382beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent        return INVALID_OPERATION;
6392beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    }
6402beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent
6412beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent    return mPlayer->attachAuxEffect(effectId);
6422beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent}
6432beeb50b1bba9e92f6cacfeca37fe9fa9d36ead1Eric Laurent
644d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi// always call with lock held
645d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivistatus_t MediaPlayer::checkStateForKeySet_l(int key)
646d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi{
647d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    switch(key) {
648d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    case KEY_PARAMETER_AUDIO_ATTRIBUTES:
649d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
650d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi                MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) {
651d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi            // Can't change the audio attributes after prepare
652d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi            ALOGE("trying to set audio attributes called in state %d", mCurrentState);
653d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi            return INVALID_OPERATION;
654d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        }
655d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        break;
656d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    default:
657d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        // parameter doesn't require player state check
658d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        break;
659d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    }
660d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    return OK;
661d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi}
662d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi
6634f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wangstatus_t MediaPlayer::setParameter(int key, const Parcel& request)
6644f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang{
6653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::setParameter(%d)", key);
6664f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    Mutex::Autolock _l(mLock);
667d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    if (checkStateForKeySet_l(key) != OK) {
668d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi        return INVALID_OPERATION;
669d9d7fa0873796ac661c44a7fcd6ad5ff697ff01fJean-Michel Trivi    }
6704f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    if (mPlayer != NULL) {
6714f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang        return  mPlayer->setParameter(key, request);
6724f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    }
673640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    switch (key) {
674640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    case KEY_PARAMETER_AUDIO_ATTRIBUTES:
675640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        // no player, save the marshalled audio attributes
676640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        if (mAudioAttributesParcel != NULL) { delete mAudioAttributesParcel; };
677640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        mAudioAttributesParcel = new Parcel();
678640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        mAudioAttributesParcel->appendFrom(&request, 0, request.dataSize());
679640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        return OK;
680640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    default:
681640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        ALOGV("setParameter: no active player");
682640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi        return INVALID_OPERATION;
683640adb3cf89cc9b826372009fad8c9b3d120482eJean-Michel Trivi    }
6844f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang}
6854f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang
6864f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wangstatus_t MediaPlayer::getParameter(int key, Parcel *reply)
6874f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang{
6883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("MediaPlayer::getParameter(%d)", key);
6894f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    Mutex::Autolock _l(mLock);
6904f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    if (mPlayer != NULL) {
691e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten        return  mPlayer->getParameter(key, reply);
6924f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    }
6933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getParameter: no active player");
6944f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    return INVALID_OPERATION;
6954f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang}
6964f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang
697c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossmanstatus_t MediaPlayer::setRetransmitEndpoint(const char* addrString,
698c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman                                            uint16_t port) {
699c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    ALOGV("MediaPlayer::setRetransmitEndpoint(%s:%hu)",
700c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman            addrString ? addrString : "(null)", port);
701c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
702c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    Mutex::Autolock _l(mLock);
703c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    if ((mPlayer != NULL) || (mCurrentState != MEDIA_PLAYER_IDLE))
704c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        return INVALID_OPERATION;
705c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
706c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    if (NULL == addrString) {
707c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        mRetransmitEndpointValid = false;
708c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        return OK;
709c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    }
710c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
711c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    struct in_addr saddr;
712c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    if(!inet_aton(addrString, &saddr)) {
713c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman        return BAD_VALUE;
714c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    }
715c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
716be08f6a6688f3b1ae6914fbe800953c9bfb13c45Glenn Kasten    memset(&mRetransmitEndpoint, 0, sizeof(mRetransmitEndpoint));
717c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpoint.sin_family = AF_INET;
718c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpoint.sin_addr   = saddr;
719c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpoint.sin_port   = htons(port);
720c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    mRetransmitEndpointValid       = true;
721c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
722c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman    return OK;
723c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman}
724c795b64060c3af9d7961fc1371e4ccfa8ee3e450John Grossman
725b483c4724846c0b8d4e82afcbb7c17f671bae81cGloria Wangvoid MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
72689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
7273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
72889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    bool send = true;
7291af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams    bool locked = false;
73089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
73189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // TODO: In the future, we might be on the same thread if the app is
73289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // running in the same process as the media server. In that case,
73389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // this will deadlock.
734660951867e959ebe98612742ef1f72d33ea7e9a3Nicolas Catania    //
735d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    // The threadId hack below works around this for the care of prepare,
736d88adb96ec867ed1b629c434f87514d2fabaf5e9Chong Zhang    // seekTo and start within the same process.
7375cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    // FIXME: Remember, this is a hack, it's not even a hack that is applied
7385cb07aa071b43a214e4c880b3b7852714e06451bAndreas Huber    // consistently for all use-cases, this needs to be revisited.
739e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten    if (mLockThreadId != getThreadId()) {
7401af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        mLock.lock();
7411af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        locked = true;
742660951867e959ebe98612742ef1f72d33ea7e9a3Nicolas Catania    }
7431af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams
7443b26844e60f8487388e7e62709faf0dada86e7e1Eric Laurent    // Allows calls from JNI in idle state to notify errors
7453b26844e60f8487388e7e62709faf0dada86e7e1Eric Laurent    if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) {
7463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
7471af452f333664e8b0a61d96a9b3bb682d8b9a00fJason Sams        if (locked) mLock.unlock();   // release the lock when done.
74889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        return;
74989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
75089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
75189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    switch (msg) {
75289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    case MEDIA_NOP: // interface test message
75389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        break;
75489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    case MEDIA_PREPARED:
7553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("prepared");
75689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mCurrentState = MEDIA_PLAYER_PREPARED;
75789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (mPrepareSync) {
7583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("signal application thread");
75989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mPrepareSync = false;
76089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mPrepareStatus = NO_ERROR;
76189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mSignal.signal();
76289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
76389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        break;
76489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    case MEDIA_PLAYBACK_COMPLETE:
7653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("playback complete");
7661c1503cf47c0a37a30e7acac2c5d29140fc61a5fMarco Nelissen        if (mCurrentState == MEDIA_PLAYER_IDLE) {
76729357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block            ALOGE("playback complete in idle state");
7681c1503cf47c0a37a30e7acac2c5d29140fc61a5fMarco Nelissen        }
76989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (!mLoop) {
77089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE;
77189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
77289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        break;
77389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    case MEDIA_ERROR:
77465e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project        // Always log errors.
77565e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project        // ext1: Media framework error code.
77665e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project        // ext2: Implementation dependant error code.
77729357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block        ALOGE("error (%d, %d)", ext1, ext2);
77889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        mCurrentState = MEDIA_PLAYER_STATE_ERROR;
77989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        if (mPrepareSync)
78089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        {
7813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("signal application thread");
78289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mPrepareSync = false;
78389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mPrepareStatus = ext1;
78489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            mSignal.signal();
78589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            send = false;
78689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
78789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        break;
78865e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project    case MEDIA_INFO:
78965e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project        // ext1: Media framework error code.
79065e731f393f704eedab6fbe0af7f8a580c8d4617The Android Open Source Project        // ext2: Implementation dependant error code.
791145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber        if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) {
7925ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block            ALOGW("info/warning (%d, %d)", ext1, ext2);
793145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber        }
79465e731f393f704eedab6fbe0af7f8a580c8d4617