• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_AVROUTER_IMPL_H
17 #define OHOS_AVROUTER_IMPL_H
18 
19 #include "av_router.h"
20 #include "avcast_provider_manager.h"
21 #include "hw_cast_provider.h"
22 
23 namespace OHOS::AVSession {
24 class AVRouterImpl : public AVRouter {
25 public:
26     AVRouterImpl();
27 
28     void Init(IAVSessionServiceListener *servicePtr) override;
29 
30     bool Release() override;
31 
32     int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) override;
33 
34     int32_t StopDeviceLogging() override;
35 
36     int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes) override;
37 
38     int32_t StopCastDiscovery() override;
39 
40     int32_t SetDiscoverable(const bool enable) override;
41 
42     int32_t OnDeviceAvailable(OutputDeviceInfo& castOutputDeviceInfo) override;
43 
44     int32_t OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override;
45 
46     int32_t OnDeviceOffline(const std::string& deviceId) override;
47 
48     void ReleaseCurrentCastSession() override;
49 
50     int32_t OnCastSessionCreated(const int32_t castId) override;
51 
52     int32_t OnCastServerDied(int32_t providerNumber) override;
53 
54     std::shared_ptr<IAVCastControllerProxy> GetRemoteController(const int64_t castHandle) override;
55 
56     int64_t StartCast(const OutputDeviceInfo& outputDeviceInfo,
57         std::map<std::string, std::string>& serviceNameMapState) override;
58 
59     int32_t AddDevice(const int32_t castId, const OutputDeviceInfo& outputDeviceInfo) override;
60 
61     int32_t StopCast(const int64_t castHandle, int32_t removeTimes) override;
62 
63     int32_t StopCastSession(const int64_t castHandle) override;
64 
65     int32_t RegisterCallback(int64_t castHandleconst,
66         std::shared_ptr<IAVCastSessionStateListener> callback) override;
67 
68     int32_t UnRegisterCallback(int64_t castHandleconst,
69         std::shared_ptr<IAVCastSessionStateListener> callback) override;
70 
71     int32_t SetServiceAllConnectState(int64_t castHandle, DeviceInfo deviceInfo) override;
72 
73     int32_t GetRemoteNetWorkId(int64_t castHandle, std::string deviceId, std::string &networkId) override;
74 
75 protected:
76 
77 private:
78     std::recursive_mutex servicePtrLock_;
79     IAVSessionServiceListener *servicePtr_ = nullptr;
80     std::recursive_mutex providerManagerLock_;
81     std::map<int32_t, std::shared_ptr<AVCastProviderManager>> providerManagerMap_;
82     std::map<std::string, std::string> castServiceNameMapState_;
83     const std::string deviceStateConnection = "CONNECT_SUCC";
84     int32_t providerNumber_ = 0;
85     std::map<int32_t, OutputDeviceInfo> castHandleToOutputDeviceMap_;
86     bool hasSessionAlive_ = false;
87     int32_t providerNumberEnableDefault_ = 1;
88     int32_t providerNumberDisable_ = 0;
89     OutputDeviceInfo castOutputDeviceInfo_;
90     bool cacheStartDiscovery_ = false;
91     bool cacheStartDeviceLogging_ = false;
92     int32_t cacheCastDeviceCapability_ = -1;
93     std::vector<std::string> cacheDrmSchemes_;
94 };
95 } // namespace OHOS::AVSession
96 #endif // OHOS_AVROUTER_IMPL_H
97