• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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     int32_t GetActivatedSessionDescriptors(std::vector<AVSessionDescriptor>& activatedSessions) override;
45 
46     int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) override;
47 
48     int32_t RegisterSessionListener(const std::shared_ptr<SessionListener>& listener) override;
49 
50     int32_t RegisterServiceDeathCallback(const DeathCallback& callback) override;
51 
52     int32_t UnregisterServiceDeathCallback() override;
53 
54     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override;
55 
56     int32_t SendSystemControlCommand(const AVControlCommand& command) override;
57 
58     int32_t CastAudio(const SessionToken& token,
59                       const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
60 
61     int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
62 
63 private:
64     sptr<AVSessionServiceProxy> GetService();
65 
66     void OnServiceDie();
67 
68     void RegisterClientDeathObserver();
69 
70     std::mutex lock_;
71     sptr<AVSessionServiceProxy> service_;
72     sptr<ISessionListener> listener_;
73     sptr<ClientDeathStub> clientDeath_;
74     DeathCallback deathCallback_;
75 };
76 
77 class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
78 public:
79     explicit ServiceDeathRecipient(const std::function<void()>& callback);
80 
81     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
82 
83 private:
84     std::function<void()> callback_;
85 };
86 } // namespace OHOS::AVSession
87 #endif // OHOS_AVSESSION_MANAGER_IMPL_H