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_SESSION_H
17 #define HW_CAST_PROVIDER_SESSION_H
18 
19 #include <mutex>
20 
21 #include "i_cast_session.h"
22 #include "cast_engine_common.h"
23 #include "avsession_info.h"
24 
25 namespace OHOS::AVSession {
26 class HwCastProviderSession : public CastEngine::ICastSessionListener,
27     public std::enable_shared_from_this<HwCastProviderSession> {
28 public:
HwCastProviderSession(std::shared_ptr<CastEngine::ICastSession> castSession)29     explicit HwCastProviderSession(std::shared_ptr<CastEngine::ICastSession> castSession) : castSession_(castSession) {}
30     ~HwCastProviderSession() override;
31 
32     void OnDeviceState(const CastEngine::DeviceStateInfo &stateInfo) override;
33     void OnEvent(const CastEngine::EventId &eventId, const std::string &jsonParam) override;
34 
35     int32_t Init();
36     void Release();
37     bool AddDevice(const std::string deviceId);
38     bool RemoveDevice(std::string deviceId);
39     std::shared_ptr<CastEngine::IStreamPlayer> CreateStreamPlayer();
40     bool RegisterCastSessionStateListener(std::shared_ptr<IAVCastSessionStateListener> listener);
41     bool UnRegisterCastSessionStateListener(std::shared_ptr<IAVCastSessionStateListener> listener);
42     bool SetStreamState(DeviceInfo deviceInfo);
43     bool GetRemoteNetWorkId(std::string deviceId, std::string &networkId);
44 
45 private:
46     std::shared_ptr<CastEngine::ICastSession> castSession_;
47     std::vector<std::shared_ptr<IAVCastSessionStateListener>> castSessionStateListenerList_;
48     std::recursive_mutex mutex_;
49     int32_t stashDeviceState_ = -1;
50     std::string stashDeviceId_;
51 
52     const int32_t deviceStateConnection = 6;
53 };
54 } // namespace OHOS::AVSession
55 
56 #endif
57