android_LocAVPlayer.cpp revision 833251ab9e5e59a6ea5ac325122cf3abdf7cd944
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define USE_LOG SLAndroidLogLevel_Verbose 18 19#include "sles_allinclusive.h" 20#include <media/IMediaPlayerService.h> 21#include "android_LocAVPlayer.h" 22 23 24namespace android { 25 26//-------------------------------------------------------------------------------------------------- 27LocAVPlayer::LocAVPlayer(AudioPlayback_Parameters* params, bool hasVideo) : 28 GenericMediaPlayer(params, hasVideo) 29{ 30 SL_LOGD("LocAVPlayer::LocAVPlayer()"); 31 32} 33 34 35LocAVPlayer::~LocAVPlayer() { 36 SL_LOGD("LocAVPlayer::~LocAVPlayer()"); 37 38} 39 40 41//-------------------------------------------------- 42// Event handlers 43void LocAVPlayer::onPrepare() { 44 SL_LOGD("LocAVPlayer::onPrepare()"); 45 sp<IMediaPlayerService> mediaPlayerService(getMediaPlayerService()); 46 if (mediaPlayerService != NULL) { 47 switch (mDataLocatorType) { 48 case kDataLocatorUri: 49 mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/, 50 mDataLocator.uriRef /*url*/, NULL /*headers*/, mPlaybackParams.sessionId); 51 if (mPlayer == NULL) { 52 SL_LOGE("media player service failed to create player by URI"); 53 } 54 break; 55 case kDataLocatorFd: 56 mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/, 57 mDataLocator.fdi.fd, mDataLocator.fdi.offset, mDataLocator.fdi.length, 58 mPlaybackParams.sessionId); 59 if (mPlayer == NULL) { 60 SL_LOGE("media player service failed to create player by FD"); 61 } 62 // Binder dups the fd for use by mediaserver, so if we own the fd then OK to close now 63 if (mDataLocator.fdi.mCloseAfterUse) { 64 (void) ::close(mDataLocator.fdi.fd); 65 mDataLocator.fdi.fd = -1; 66 mDataLocator.fdi.mCloseAfterUse = false; 67 } 68 break; 69 case kDataLocatorNone: 70 SL_LOGE("no data locator for MediaPlayer object"); 71 break; 72 default: 73 SL_LOGE("unsupported data locator %d for MediaPlayer object", mDataLocatorType); 74 break; 75 } 76 } 77 if (mPlayer == NULL) { 78 mStateFlags |= kFlagPreparedUnsuccessfully; 79 } 80 // blocks until mPlayer is prepared 81 GenericMediaPlayer::onPrepare(); 82 SL_LOGD("LocAVPlayer::onPrepare() done"); 83} 84 85} // namespace android 86