• 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_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 #include "avsession_utils.h"
25 
26 namespace OHOS::AVSession {
27 class HwCastProviderSession : public CastEngine::ICastSessionListener,
28     public std::enable_shared_from_this<HwCastProviderSession> {
29 public:
HwCastProviderSession(std::shared_ptr<CastEngine::ICastSession> castSession)30     explicit HwCastProviderSession(std::shared_ptr<CastEngine::ICastSession> castSession) : castSession_(castSession) {}
31     ~HwCastProviderSession() override;
32 
33     void OnDeviceState(const CastEngine::DeviceStateInfo &stateInfo) override;
34     void OnEvent(const CastEngine::EventId &eventId, const std::string &jsonParam) override;
35 
36     int32_t Init();
37     void Release();
38     bool AddDevice(const std::string deviceId, uint32_t spid);
39     bool RemoveDevice(std::string deviceId, bool continuePlay = false);
40     std::shared_ptr<CastEngine::IStreamPlayer> CreateStreamPlayer();
41     bool RegisterCastSessionStateListener(std::shared_ptr<IAVCastSessionStateListener> listener);
42     bool UnRegisterCastSessionStateListener(std::shared_ptr<IAVCastSessionStateListener> listener);
43     bool SetStreamState(DeviceInfo deviceInfo);
44     bool GetRemoteNetWorkId(std::string deviceId, std::string &networkId);
45     bool GetRemoteDrmCapabilities(std::string deviceId, std::vector<std::string> &drmCapabilities);
46     void SetProtocolType(CastEngine::ProtocolType);
47     void OnDeviceStateChange(const CastEngine::DeviceStateInfo &stateInfo);
48 
49 private:
50     void computeToastOnDeviceState(CastEngine::DeviceState state);
51 
52     std::shared_ptr<CastEngine::ICastSession> castSession_;
53     std::vector<std::shared_ptr<IAVCastSessionStateListener>> castSessionStateListenerList_;
54     std::recursive_mutex mutex_;
55     int32_t stashDeviceState_ = -1;
56     std::string stashDeviceId_;
57     CastEngine::ProtocolType protocolType_ = CastEngine::ProtocolType::CAST_PLUS_STREAM;
58     int32_t avToastDeviceState_ = ConnectionState::STATE_DISCONNECTED;
59 
60     const int32_t deviceStateConnection = 6;
61     const int32_t eventIdStart = 2000;
62     const int32_t eventIdEnd = 2999;
63     const std::string MEDIA_CAST_DISCONNECT = "usual.event.MEDIA_CAST_DISCONNECT";
64     const std::string MEDIA_CAST_ERROR = "usual.event.MEDIA_CAST_ERROR";
65 };
66 } // namespace OHOS::AVSession
67 
68 #endif
69