PlayerBase.h revision b5323222bd524876dda1ebf89694f186278e2229
1/* 2 * Copyright (C) 2017 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#ifndef __ANDROID_PLAYER_BASE_H__ 18#define __ANDROID_PLAYER_BASE_H__ 19 20#include <audiomanager/IPlayer.h> 21#include <audiomanager/AudioManager.h> 22#include <audiomanager/IAudioManager.h> 23 24 25namespace android { 26 27class PlayerBase : public BnPlayer 28{ 29public: 30 explicit PlayerBase(); 31 virtual ~PlayerBase(); 32 33 virtual void destroy() = 0; 34 35 //IPlayer implementation 36 virtual void start(); 37 virtual void pause(); 38 virtual void stop(); 39 virtual void setVolume(float vol); 40 virtual void setPan(float pan); 41 virtual void setStartDelayMs(int32_t delayMs); 42 virtual void applyVolumeShaper( 43 const sp<VolumeShaper::Configuration>& configuration, 44 const sp<VolumeShaper::Operation>& operation) override; 45 46 virtual status_t onTransact( 47 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); 48 49 50 //FIXME temporary method while some player state is outside of this class 51 void reportEvent(player_state_t event); 52 53protected: 54 55 void init(player_type_t playerType, audio_usage_t usage); 56 void baseDestroy(); 57 58 //IPlayer methods handlers for derived classes 59 virtual status_t playerStart() { return NO_ERROR; } 60 virtual status_t playerPause() { return NO_ERROR; } 61 virtual status_t playerStop() { return NO_ERROR; } 62 virtual status_t playerSetVolume() { return NO_ERROR; } 63 64 // mutex for IPlayer volume and pan, and player-specific volume 65 Mutex mSettingsLock; 66 67 // volume multipliers coming from the IPlayer volume and pan controls 68 float mPanMultiplierL, mPanMultiplierR; 69 float mVolumeMultiplierL, mVolumeMultiplierR; 70 71private: 72 // report events to AudioService 73 void servicePlayerEvent(player_state_t event); 74 void serviceReleasePlayer(); 75 76 // native interface to AudioService 77 android::sp<android::IAudioManager> mAudioManager; 78 79 // player interface ID, uniquely identifies the player in the system 80 audio_unique_id_t mPIId; 81 82 // Mutex for state reporting 83 Mutex mPlayerStateLock; 84 player_state_t mLastReportedEvent; 85}; 86 87} // namespace android 88 89#endif /* __ANDROID_PLAYER_BASE_H__ */ 90