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/AudioManager.h> 21 #include <audiomanager/IAudioManager.h> 22 #include <utils/Mutex.h> 23 24 #include "android/media/BnPlayer.h" 25 26 namespace android { 27 28 class PlayerBase : public ::android::media::BnPlayer 29 { 30 public: 31 explicit PlayerBase(); 32 virtual ~PlayerBase() override; 33 34 virtual void destroy() = 0; 35 36 //IPlayer implementation 37 virtual binder::Status start() override; 38 virtual binder::Status pause() override; 39 virtual binder::Status stop() override; 40 virtual binder::Status setVolume(float vol) override; 41 virtual binder::Status setPan(float pan) override; 42 virtual binder::Status setStartDelayMs(int32_t delayMs) override; 43 virtual binder::Status applyVolumeShaper( 44 const media::VolumeShaperConfiguration& configuration, 45 const media::VolumeShaperOperation& operation) override; 46 47 status_t startWithStatus(audio_port_handle_t deviceId); 48 status_t pauseWithStatus(); 49 status_t stopWithStatus(); 50 51 //FIXME temporary method while some player state is outside of this class 52 void reportEvent(player_state_t event, audio_port_handle_t deviceId); 53 54 void baseUpdateDeviceId(audio_port_handle_t deviceId); 55 56 /** 57 * Updates the mapping in the AudioService between portId and piid 58 */ 59 void triggerPortIdUpdate(audio_port_handle_t portId) const; 60 protected: 61 62 void init(player_type_t playerType, audio_usage_t usage, audio_session_t sessionId); 63 void baseDestroy(); 64 65 //IPlayer methods handlers for derived classes playerStart()66 virtual status_t playerStart() { return NO_ERROR; } playerPause()67 virtual status_t playerPause() { return NO_ERROR; } playerStop()68 virtual status_t playerStop() { return NO_ERROR; } playerSetVolume()69 virtual status_t playerSetVolume() { return NO_ERROR; } 70 71 // mutex for IPlayer volume and pan, and player-specific volume 72 Mutex mSettingsLock; 73 74 // volume multipliers coming from the IPlayer volume and pan controls 75 float mPanMultiplierL, mPanMultiplierR; 76 float mVolumeMultiplierL, mVolumeMultiplierR; 77 78 // player interface ID, uniquely identifies the player in the system 79 // effectively const after PlayerBase::init(). 80 audio_unique_id_t mPIId; 81 private: 82 // report events to AudioService 83 void servicePlayerEvent(player_state_t event, audio_port_handle_t deviceId); 84 void serviceReleasePlayer(); 85 86 // native interface to AudioService 87 android::sp<android::IAudioManager> mAudioManager; 88 89 // Mutex for state reporting 90 Mutex mPlayerStateLock; 91 player_state_t mLastReportedEvent; 92 93 Mutex mDeviceIdLock; 94 audio_port_handle_t mLastReportedDeviceId; 95 }; 96 97 } // namespace android 98 99 #endif /* __ANDROID_PLAYER_BASE_H__ */ 100