• 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 HW_CAST_PROVIDER_H
17 #define HW_CAST_PROVIDER_H
18 
19 #include <mutex>
20 #include "cast_session_manager.h"
21 #include "i_avcast_controller_proxy.h"
22 #include "i_cast_session.h"
23 #include "i_stream_player.h"
24 #include "i_cast_session_manager_listener.h"
25 #include "hw_cast_provider_session.h"
26 #include "avsession_info.h"
27 #include "av_cast_provider.h"
28 
29 namespace OHOS::AVSession {
30 class HwCastProvider : public AVCastProvider, public CastEngine::ICastSessionManagerListener,
31     public std::enable_shared_from_this<HwCastProvider> {
32 public:
33     HwCastProvider() = default;
34     ~HwCastProvider() override;
35 
36     void Init() override;
37     bool StartDiscovery(int castCapability) override;
38     void StopDiscovery() override;
39     int32_t SetDiscoverable(const bool enable) override;
40     void Release() override;
41     int StartCastSession() override;
42     void StopCastSession(int castId) override;
43     bool AddCastDevice(int castId, DeviceInfo deviceInfo) override;
44     bool RemoveCastDevice(int castId, DeviceInfo deviceInfo) override;
45     std::shared_ptr<IAVCastControllerProxy> GetRemoteController(int castId) override;
46     bool RegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) override;
47     bool UnRegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) override;
48     bool RegisterCastSessionStateListener(int castId, std::shared_ptr<IAVCastSessionStateListener> listener) override;
49     bool UnRegisterCastSessionStateListener(int castId, std::shared_ptr<IAVCastSessionStateListener> listener) override;
50 
51     void OnDeviceFound(const std::vector<CastEngine::CastRemoteDevice> &deviceList) override;
52     void OnDeviceOffline(const std::string &deviceId) override;
53     void OnSessionCreated(const std::shared_ptr<CastEngine::ICastSession> &castSession) override;
54     void OnServiceDied() override;
55 
56 private:
57     void WaitSessionRelease();
58     static const int MAX_CAST_SESSION_SIZE = 16;
59     std::vector<bool> castFlag_ = std::vector<bool>(MAX_CAST_SESSION_SIZE, false);
60     std::map<int, std::shared_ptr<HwCastProviderSession>> hwCastProviderSessionMap_;
61     std::map<int, std::shared_ptr<IAVCastControllerProxy>> avCastControllerMap_;
62     std::vector<std::shared_ptr<IAVCastStateListener>> castStateListenerList_;
63     std::recursive_mutex mutexLock_;
64     bool isRelease_ = false;
65     int lastCastId_ = -1;
66     std::shared_ptr<HwCastProviderSession> lastCastSession;
67 };
68 } // namespace OHOS::AVSession
69 
70 #endif