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