android_GenericPlayer.cpp revision 70c49ae2867094072a4365423417ea452bf82231
113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi/* 213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project 313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * you may not use this file except in compliance with the License. 613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * You may obtain a copy of the License at 713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 1013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 1113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 1213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * See the License for the specific language governing permissions and 1413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * limitations under the License. 1513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi */ 1613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 1713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//#define USE_LOG SLAndroidLogLevel_Verbose 1813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 1913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi#include "sles_allinclusive.h" 2013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 2113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivinamespace android { 2213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 2313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------------------------------------------------------- 2413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel TriviGenericPlayer::GenericPlayer(const AudioPlayback_Parameters* params) : 2513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocatorType(kDataLocatorNone), 2613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mNotifyClient(NULL), 2713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mNotifyUser(NULL), 2813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mStateFlags(0), 2913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooperPriority(PRIORITY_DEFAULT), 3013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mPlaybackParams(*params) 3113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi{ 3213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::GenericPlayer()"); 3313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper = new android::ALooper(); 3513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 3713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel TriviGenericPlayer::~GenericPlayer() { 4013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::~GenericPlayer()"); 4113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 4213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper->stop(); 4313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper->unregisterHandler(id()); 4413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper.clear(); 4513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 4613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 4713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 4813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 4913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::init(const notif_cbf_t cbf, void* notifUser) { 5013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::init()"); 5113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mNotifyClient = cbf; 5313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mNotifyUser = notifUser; 5413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper->registerHandler(this); 5613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mLooper->start(false /*runOnCallingThread*/, false /*canCallJava*/, mLooperPriority); 5713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 5813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::setDataSource(const char *uri) { 6113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi resetDataLocator(); 6213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.uriRef = uri; 6413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocatorType = kDataLocatorUri; 6613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 6713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::setDataSource(int fd, int64_t offset, int64_t length) { 7013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi resetDataLocator(); 7113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.fdi.fd = fd; 7313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi struct stat sb; 7513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int ret = fstat(fd, &sb); 7613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (ret != 0) { 7713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGE("GenericPlayer::setDataSource: fstat(%d) failed: %d, %s", fd, ret, strerror(errno)); 7813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi return; 7913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 8013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 8113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (offset >= sb.st_size) { 8213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGE("SfPlayer::setDataSource: invalid offset"); 8313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi return; 8413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 8513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.fdi.offset = offset; 8613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 8713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (PLAYER_FD_FIND_FILE_SIZE == length) { 8813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.fdi.length = sb.st_size; 8913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } else if (offset + length > sb.st_size) { 9013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.fdi.length = sb.st_size - offset; 9113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } else { 9213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocator.fdi.length = length; 9313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 9413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocatorType = kDataLocatorFd; 9613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 9713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::prepare() { 10013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::prepare()"); 10113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatPrepare, id()); 10213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 10313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 10413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 10513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 10613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::play() { 10713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::play()"); 10813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatPlay, id()); 10913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 11013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 11113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::pause() { 11413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::prepare()"); 11513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatPause, id()); 11613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 11713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 11813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::stop() { 12113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::stop()"); 12213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi (new AMessage(kWhatPause, id()))->post(); 12313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // after a stop, playback should resume from the start. 12513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi seek(0); 12613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 12713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::seek(int64_t timeMsec) { 13013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGV("GenericPlayer::seek %lld", timeMsec); 13113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatSeek, id()); 13213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->setInt64(WHATPARAM_SEEK_SEEKTIME_MS, timeMsec); 13313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 13413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 13513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 13613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 13713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::loop(bool loop) { 13813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatLoop, id()); 13913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->setInt32(WHATPARAM_LOOP_LOOPING, (int32_t)loop); 14013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 14113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 14213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 14313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 14413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------- 14570c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivivoid GenericPlayer::getDurationMsec(int* msec) { 14670c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi // unknown duration 14770c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi *msec = -1; 14870c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi} 14970c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi 15070c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi 15170c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi//-------------------------------------------------- 15213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi/* 15313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * post-condition: mDataLocatorType == kDataLocatorNone 15413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 15513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi */ 15613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::resetDataLocator() { 15713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mDataLocatorType = kDataLocatorNone; 15813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 15913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 16013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 16113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::notify(const char* event, int data, bool async) { 16213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<AMessage> msg = new AMessage(kWhatNotif, id()); 16313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->setInt32(event, (int32_t)data); 16413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (async) { 16513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi msg->post(); 16613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } else { 16713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi this->onNotify(msg); 16813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 16913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 17013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 17113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 17213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------- 17313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi// AHandler implementation 17413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onMessageReceived(const sp<AMessage> &msg) { 17513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi switch (msg->what()) { 17613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatPrepare: 17713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onPrepare(); 17813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 17913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 18013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatNotif: 18113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onNotify(msg); 18213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 18313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 18413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatPlay: 18513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onPlay(); 18613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 18713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 18813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatPause: 18913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onPause(); 19013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 19113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 19213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatSeek: 19313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onSeek(msg); 19413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 19513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 19613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi case kWhatLoop: 19713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi onLoop(msg); 19813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi break; 19913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 20013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi default: 20113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi TRESPASS(); 20213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 20313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 20413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 20513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 20613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------- 20713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi// Event handlers 20813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onPrepare() { 20913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::onPrepare()"); 21013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (!(mStateFlags & kFlagPrepared)) { 21113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mStateFlags |= kFlagPrepared; 21213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi notify(PLAYEREVENT_PREPARED, PLAYER_SUCCESS, false /*async*/); 21313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 21413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::onPrepare() done, mStateFlags=0x%x", mStateFlags); 21513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 21613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 21713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 21813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onNotify(const sp<AMessage> &msg) { 21913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (NULL == mNotifyClient) { 22013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi return; 22113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 22213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 22313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int32_t val; 22413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if (msg->findInt32(PLAYEREVENT_PREPARED, &val)) { 22513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_PREPARED, val); 22613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mNotifyClient(kEventPrepared, val, mNotifyUser); 22713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 22813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 22913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 23013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 23113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onPlay() { 23213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::onPlay()"); 23313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if ((mStateFlags & kFlagPrepared)) { 23413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("starting player"); 23513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mStateFlags |= kFlagPlaying; 23613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } else { 23713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGV("NOT starting player mStateFlags=0x%x", mStateFlags); 23813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 23913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 24013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 24113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 24213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onPause() { 24313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGI("GenericPlayer::onPause()"); 24413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi if ((mStateFlags & kFlagPrepared)) { 24513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi mStateFlags &= ~kFlagPlaying; 24613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi } 24713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 24813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 24913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 25013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 25113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onSeek(const sp<AMessage> &msg) { 25213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGV("GenericPlayer::onSeek"); 25313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 25413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 25513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 25613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivivoid GenericPlayer::onLoop(const sp<AMessage> &msg) { 25713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi SL_LOGV("GenericPlayer::onLoop"); 25813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} 25913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 26013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} // namespace android 261