180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
480922886Sopenharmony_ci * you may not use this file except in compliance with the License.
580922886Sopenharmony_ci * You may obtain a copy of the License at
680922886Sopenharmony_ci *
780922886Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
880922886Sopenharmony_ci *
980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1280922886Sopenharmony_ci * See the License for the specific language governing permissions and
1380922886Sopenharmony_ci * limitations under the License.
1480922886Sopenharmony_ci */
1580922886Sopenharmony_ci
1680922886Sopenharmony_ci#ifndef OHOS_AVROUTER_IMPL_H
1780922886Sopenharmony_ci#define OHOS_AVROUTER_IMPL_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include "av_router.h"
2080922886Sopenharmony_ci#include "avcast_provider_manager.h"
2180922886Sopenharmony_ci
2280922886Sopenharmony_cinamespace OHOS::AVSession {
2380922886Sopenharmony_ciclass AVRouterImpl : public AVRouter {
2480922886Sopenharmony_cipublic:
2580922886Sopenharmony_ci    AVRouterImpl();
2680922886Sopenharmony_ci
2780922886Sopenharmony_ci    void Init(IAVSessionServiceListener *servicePtr) override;
2880922886Sopenharmony_ci
2980922886Sopenharmony_ci    bool Release() override;
3080922886Sopenharmony_ci
3180922886Sopenharmony_ci    int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) override;
3280922886Sopenharmony_ci
3380922886Sopenharmony_ci    int32_t StopDeviceLogging() override;
3480922886Sopenharmony_ci
3580922886Sopenharmony_ci    int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes) override;
3680922886Sopenharmony_ci
3780922886Sopenharmony_ci    int32_t StopCastDiscovery() override;
3880922886Sopenharmony_ci
3980922886Sopenharmony_ci    int32_t SetDiscoverable(const bool enable) override;
4080922886Sopenharmony_ci
4180922886Sopenharmony_ci    int32_t OnDeviceAvailable(OutputDeviceInfo& castOutputDeviceInfo) override;
4280922886Sopenharmony_ci
4380922886Sopenharmony_ci    int32_t OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override;
4480922886Sopenharmony_ci
4580922886Sopenharmony_ci    int32_t OnDeviceOffline(const std::string& deviceId) override;
4680922886Sopenharmony_ci
4780922886Sopenharmony_ci    void ReleaseCurrentCastSession() override;
4880922886Sopenharmony_ci
4980922886Sopenharmony_ci    int32_t OnCastSessionCreated(const int32_t castId) override;
5080922886Sopenharmony_ci
5180922886Sopenharmony_ci    int32_t OnCastServerDied(int32_t providerNumber) override;
5280922886Sopenharmony_ci
5380922886Sopenharmony_ci    std::shared_ptr<IAVCastControllerProxy> GetRemoteController(const int64_t castHandle) override;
5480922886Sopenharmony_ci
5580922886Sopenharmony_ci    int64_t StartCast(const OutputDeviceInfo& outputDeviceInfo,
5680922886Sopenharmony_ci        std::map<std::string, std::string>& serviceNameMapState) override;
5780922886Sopenharmony_ci
5880922886Sopenharmony_ci    int32_t AddDevice(const int32_t castId, const OutputDeviceInfo& outputDeviceInfo) override;
5980922886Sopenharmony_ci
6080922886Sopenharmony_ci    int32_t StopCast(const int64_t castHandle, int32_t removeTimes) override;
6180922886Sopenharmony_ci
6280922886Sopenharmony_ci    int32_t StopCastSession(const int64_t castHandle) override;
6380922886Sopenharmony_ci
6480922886Sopenharmony_ci    int32_t RegisterCallback(int64_t castHandleconst,
6580922886Sopenharmony_ci        std::shared_ptr<IAVCastSessionStateListener> callback) override;
6680922886Sopenharmony_ci
6780922886Sopenharmony_ci    int32_t UnRegisterCallback(int64_t castHandleconst,
6880922886Sopenharmony_ci        std::shared_ptr<IAVCastSessionStateListener> callback) override;
6980922886Sopenharmony_ci
7080922886Sopenharmony_ci    int32_t SetServiceAllConnectState(int64_t castHandle, DeviceInfo deviceInfo) override;
7180922886Sopenharmony_ci
7280922886Sopenharmony_ci    int32_t GetRemoteNetWorkId(int64_t castHandle, std::string deviceId, std::string &networkId) override;
7380922886Sopenharmony_ci
7480922886Sopenharmony_ciprotected:
7580922886Sopenharmony_ci
7680922886Sopenharmony_ciprivate:
7780922886Sopenharmony_ci    std::recursive_mutex servicePtrLock_;
7880922886Sopenharmony_ci    IAVSessionServiceListener *servicePtr_ = nullptr;
7980922886Sopenharmony_ci    std::recursive_mutex providerManagerLock_;
8080922886Sopenharmony_ci    std::map<int32_t, std::shared_ptr<AVCastProviderManager>> providerManagerMap_;
8180922886Sopenharmony_ci    std::map<std::string, std::string> castServiceNameMapState_;
8280922886Sopenharmony_ci    const std::string deviceStateConnection = "CONNECT_SUCC";
8380922886Sopenharmony_ci    int32_t providerNumber_ = 0;
8480922886Sopenharmony_ci    std::map<int32_t, OutputDeviceInfo> castHandleToOutputDeviceMap_;
8580922886Sopenharmony_ci    bool hasSessionAlive_ = false;
8680922886Sopenharmony_ci    int32_t providerNumberEnableDefault_ = 1;
8780922886Sopenharmony_ci    int32_t providerNumberDisable_ = 0;
8880922886Sopenharmony_ci    OutputDeviceInfo castOutputDeviceInfo_;
8980922886Sopenharmony_ci    bool cacheStartDiscovery_ = false;
9080922886Sopenharmony_ci    bool cacheStartDeviceLogging_ = false;
9180922886Sopenharmony_ci    int32_t cacheCastDeviceCapability_ = -1;
9280922886Sopenharmony_ci    std::vector<std::string> cacheDrmSchemes_;
9380922886Sopenharmony_ci};
9480922886Sopenharmony_ci} // namespace OHOS::AVSession
9580922886Sopenharmony_ci#endif // OHOS_AVROUTER_IMPL_H
96