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