1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AV_SESSION_BACKGROUND_AUDIO_CONTROLLER_H 17 #define AV_SESSION_BACKGROUND_AUDIO_CONTROLLER_H 18 19 #include <mutex> 20 #include <set> 21 #include "avsession_info.h" 22 #include "audio_adapter.h" 23 #include "app_manager_adapter.h" 24 25 namespace OHOS::AVSession { 26 class BackgroundAudioController : public SessionListener { 27 public: 28 BackgroundAudioController(); 29 ~BackgroundAudioController() override; 30 31 void OnSessionCreate(const AVSessionDescriptor& descriptor) override; 32 void OnSessionRelease(const AVSessionDescriptor& descriptor) override; OnTopSessionChange(const AVSessionDescriptor & descriptor)33 void OnTopSessionChange(const AVSessionDescriptor& descriptor) override {} 34 35 void Init(); 36 37 void HandleAudioStreamRendererStateChange(const AudioRendererChangeInfos& infos); 38 void HandleAppBackgroundState(int32_t uid) const; 39 40 private: 41 std::recursive_mutex lock_; 42 std::set<int32_t> sessionUIDs_; 43 }; 44 } 45 #endif // AV_SESSION_BACKGROUND_AUDIO_CONTROLLER_H