xref: /aosp_15_r20/frameworks/av/media/libaudioclient/include/media/TrackPlayerBase.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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_TRACK_PLAYER_BASE_H__
18 #define __ANDROID_TRACK_PLAYER_BASE_H__
19 
20 #include <media/AudioTrack.h>
21 #include <media/PlayerBase.h>
22 #include <mediautils/Synchronization.h>
23 
24 namespace android {
25 
26 class TrackPlayerBase : public PlayerBase
27 {
28 public:
29     explicit TrackPlayerBase();
30     virtual ~TrackPlayerBase();
31 
32     void init(const sp<AudioTrack>& pat, const sp<AudioTrack::IAudioTrackCallback>& callback,
33               player_type_t playerType, audio_usage_t usage, audio_session_t sessionId);
34     virtual void destroy();
35 
36     //IPlayer implementation
37     virtual binder::Status applyVolumeShaper(
38             const media::VolumeShaperConfiguration& configuration,
39             const media::VolumeShaperOperation& operation);
40 
getAudioTrack()41     sp<AudioTrack> getAudioTrack() { return mAudioTrack.load(); }
42 
clearAudioTrack()43     void clearAudioTrack() { mAudioTrack.store(nullptr); }
44 
45     void setPlayerVolume(float vl, float vr);
46 
47 protected:
48 
49     //PlayerBase virtuals
50     virtual status_t playerStart();
51     virtual status_t playerPause();
52     virtual status_t playerStop();
53     virtual status_t playerSetVolume();
54 
55 private:
56             void doDestroy();
57             status_t doSetVolume();
58 
59             class SelfAudioDeviceCallback : public AudioSystem::AudioDeviceCallback {
60             public:
61                 SelfAudioDeviceCallback(PlayerBase& self);
62                 virtual void onAudioDeviceUpdate(audio_io_handle_t audioIo,
63                                                  const DeviceIdVector& deviceIds);
64             private:
65                 virtual ~SelfAudioDeviceCallback();
66                 PlayerBase& mSelf;
67             };
68 
69     // volume coming from the player volume API
70     float mPlayerVolumeL, mPlayerVolumeR;
71     sp<AudioTrack::IAudioTrackCallback> mCallbackHandle;
72     sp<SelfAudioDeviceCallback> mSelfAudioDeviceCallback;
73     mediautils::atomic_sp<AudioTrack> mAudioTrack;
74 };
75 
76 } // namespace android
77 
78 #endif /* __ANDROID_TRACK_PLAYER_BASE_H__ */
79