• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 protected:
57 
58             void init(player_type_t playerType, audio_usage_t usage, audio_session_t sessionId);
59             void baseDestroy();
60 
61     //IPlayer methods handlers for derived classes
playerStart()62     virtual status_t playerStart()  { return NO_ERROR; }
playerPause()63     virtual status_t playerPause()  { return NO_ERROR; }
playerStop()64     virtual status_t playerStop()  { return NO_ERROR; }
playerSetVolume()65     virtual status_t playerSetVolume()  { return NO_ERROR; }
66 
67     // mutex for IPlayer volume and pan, and player-specific volume
68     Mutex mSettingsLock;
69 
70     // volume multipliers coming from the IPlayer volume and pan controls
71     float mPanMultiplierL, mPanMultiplierR;
72     float mVolumeMultiplierL, mVolumeMultiplierR;
73 
74     // player interface ID, uniquely identifies the player in the system
75     // effectively const after PlayerBase::init().
76     audio_unique_id_t mPIId;
77 
78 private:
79             // report events to AudioService
80             void servicePlayerEvent(player_state_t event, audio_port_handle_t deviceId);
81             void serviceReleasePlayer();
82 
83     // native interface to AudioService
84     android::sp<android::IAudioManager> mAudioManager;
85 
86     // Mutex for state reporting
87     Mutex mPlayerStateLock;
88     player_state_t mLastReportedEvent;
89 
90     Mutex mDeviceIdLock;
91     audio_port_handle_t mLastReportedDeviceId;
92 };
93 
94 } // namespace android
95 
96 #endif /* __ANDROID_PLAYER_BASE_H__ */
97