Eric Laurent | b532322 | 2017-05-31 15:01:56 -0700 | [diff] [blame] | 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | class PlayerBase : public BnPlayer |
| 28 | { |
| 29 | public: |
| 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 | |
Eric Laurent | 1d32e9f | 2017-06-02 14:01:32 -0700 | [diff] [blame] | 50 | status_t startWithStatus(); |
Eric Laurent | a2f296e | 2017-06-21 18:51:47 -0700 | [diff] [blame] | 51 | status_t pauseWithStatus(); |
| 52 | status_t stopWithStatus(); |
Eric Laurent | 1d32e9f | 2017-06-02 14:01:32 -0700 | [diff] [blame] | 53 | |
Eric Laurent | b532322 | 2017-05-31 15:01:56 -0700 | [diff] [blame] | 54 | //FIXME temporary method while some player state is outside of this class |
| 55 | void reportEvent(player_state_t event); |
| 56 | |
| 57 | protected: |
| 58 | |
| 59 | void init(player_type_t playerType, audio_usage_t usage); |
| 60 | void baseDestroy(); |
| 61 | |
| 62 | //IPlayer methods handlers for derived classes |
| 63 | virtual status_t playerStart() { return NO_ERROR; } |
| 64 | virtual status_t playerPause() { return NO_ERROR; } |
| 65 | virtual status_t playerStop() { return NO_ERROR; } |
| 66 | virtual status_t playerSetVolume() { return NO_ERROR; } |
| 67 | |
| 68 | // mutex for IPlayer volume and pan, and player-specific volume |
| 69 | Mutex mSettingsLock; |
| 70 | |
| 71 | // volume multipliers coming from the IPlayer volume and pan controls |
| 72 | float mPanMultiplierL, mPanMultiplierR; |
| 73 | float mVolumeMultiplierL, mVolumeMultiplierR; |
| 74 | |
| 75 | private: |
| 76 | // report events to AudioService |
| 77 | void servicePlayerEvent(player_state_t event); |
| 78 | void serviceReleasePlayer(); |
| 79 | |
| 80 | // native interface to AudioService |
| 81 | android::sp<android::IAudioManager> mAudioManager; |
| 82 | |
| 83 | // player interface ID, uniquely identifies the player in the system |
| 84 | audio_unique_id_t mPIId; |
| 85 | |
| 86 | // Mutex for state reporting |
| 87 | Mutex mPlayerStateLock; |
| 88 | player_state_t mLastReportedEvent; |
| 89 | }; |
| 90 | |
| 91 | } // namespace android |
| 92 | |
| 93 | #endif /* __ANDROID_PLAYER_BASE_H__ */ |