blob: e63090b725da3d4a594c364a34005b824bb1b766 [file] [log] [blame]
Eric Laurentb5323222017-05-31 15:01:56 -07001/*
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
25namespace android {
26
27class PlayerBase : public BnPlayer
28{
29public:
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 Laurent1d32e9f2017-06-02 14:01:32 -070050 status_t startWithStatus();
Eric Laurenta2f296e2017-06-21 18:51:47 -070051 status_t pauseWithStatus();
52 status_t stopWithStatus();
Eric Laurent1d32e9f2017-06-02 14:01:32 -070053
Eric Laurentb5323222017-05-31 15:01:56 -070054 //FIXME temporary method while some player state is outside of this class
55 void reportEvent(player_state_t event);
56
57protected:
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
75private:
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__ */