• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 OHOS_AVSESSION_MANAGER_IMPL_H
17 #define OHOS_AVSESSION_MANAGER_IMPL_H
18 
19 #include <string>
20 #include <memory>
21 #include <mutex>
22 
23 #include "iremote_object.h"
24 #include "av_session.h"
25 #include "avsession_service_proxy.h"
26 #include "avsession_info.h"
27 #include "client_death_stub.h"
28 #include "isession_listener.h"
29 #include "avsession_manager.h"
30 #include "avsession_controller.h"
31 
32 namespace OHOS::AVSession {
33 class AVSessionManagerImpl : public AVSessionManager {
34 public:
35     AVSessionManagerImpl();
36 
37     std::shared_ptr<AVSession> CreateSession(const std::string& tag, int32_t type,
38                                              const AppExecFwk::ElementName& elementName) override;
39 
40     int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) override;
41 
42     int32_t CreateController(const std::string& sessionId, std::shared_ptr<AVSessionController>& controller) override;
43 
44 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
45     int32_t GetAVCastController(const std::string& sessionId,
46         std::shared_ptr<AVCastController>& castController) override;
47 #endif
48 
49     int32_t GetActivatedSessionDescriptors(std::vector<AVSessionDescriptor>& activatedSessions) override;
50 
51     int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) override;
52 
53     int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) override;
54 
55     int32_t RegisterSessionListener(const std::shared_ptr<SessionListener>& listener) override;
56 
57     int32_t RegisterServiceDeathCallback(const DeathCallback& callback) override;
58 
59     int32_t UnregisterServiceDeathCallback() override;
60 
61     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override;
62 
63     int32_t SendSystemControlCommand(const AVControlCommand& command) override;
64 
65     int32_t CastAudio(const SessionToken& token,
66                       const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
67 
68     int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
69 
70 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
71     int32_t StartCastDiscovery(int32_t castDeviceCapability) override;
72 
73     int32_t StopCastDiscovery() override;
74 
75     int32_t SetDiscoverable(const bool enable) override;
76 
77     int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) override;
78 
79     int32_t StopCast(const SessionToken& sessionToken) override;
80 #endif
81 
82 private:
83     sptr<AVSessionServiceProxy> GetService();
84 
85     void OnServiceDie();
86 
87     void RegisterClientDeathObserver();
88 
89     std::mutex lock_;
90     sptr<AVSessionServiceProxy> service_;
91     sptr<ISessionListener> listener_;
92     sptr<ClientDeathStub> clientDeath_;
93     DeathCallback deathCallback_;
94 };
95 
96 class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
97 public:
98     explicit ServiceDeathRecipient(const std::function<void()>& callback);
99 
100     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
101 
102 private:
103     std::function<void()> callback_;
104 };
105 } // namespace OHOS::AVSession
106 #endif // OHOS_AVSESSION_MANAGER_IMPL_H
107