15e81a82fSopenharmony_ci/* 25e81a82fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35e81a82fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45e81a82fSopenharmony_ci * you may not use this file except in compliance with the License. 55e81a82fSopenharmony_ci * You may obtain a copy of the License at 65e81a82fSopenharmony_ci * 75e81a82fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85e81a82fSopenharmony_ci * 95e81a82fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105e81a82fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115e81a82fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125e81a82fSopenharmony_ci * See the License for the specific language governing permissions and 135e81a82fSopenharmony_ci * limitations under the License. 145e81a82fSopenharmony_ci * Description: Cast session implement class. 155e81a82fSopenharmony_ci * Author: zhangge 165e81a82fSopenharmony_ci * Create: 2022-07-19 175e81a82fSopenharmony_ci */ 185e81a82fSopenharmony_ci 195e81a82fSopenharmony_ci#ifndef CAST_SESSION_IMPL_H 205e81a82fSopenharmony_ci#define CAST_SESSION_IMPL_H 215e81a82fSopenharmony_ci#include "cast_session_impl_class.h" 225e81a82fSopenharmony_ci 235e81a82fSopenharmony_cinamespace OHOS { 245e81a82fSopenharmony_cinamespace CastEngine { 255e81a82fSopenharmony_cinamespace CastEngineService { 265e81a82fSopenharmony_ciusing CastSessionRtsp::IRtspController; 275e81a82fSopenharmony_ciusing CastSessionRtsp::IRtspListener; 285e81a82fSopenharmony_ciusing CastSessionRtsp::ParamInfo; 295e81a82fSopenharmony_ciusing CastSessionEnums::MessageId; 305e81a82fSopenharmony_ci 315e81a82fSopenharmony_ciclass CastSessionImpl::ChannelManagerListenerImpl : public IChannelManagerListener { 325e81a82fSopenharmony_cipublic: 335e81a82fSopenharmony_ci explicit ChannelManagerListenerImpl(sptr<CastSessionImpl> session) : session_(session) {} 345e81a82fSopenharmony_ci 355e81a82fSopenharmony_ci void OnChannelCreated(std::shared_ptr<Channel> channel) override; 365e81a82fSopenharmony_ci void OnChannelOpenFailed(ChannelRequest &channelRequest, int errorCode) override; 375e81a82fSopenharmony_ci void OnChannelRemoved(std::shared_ptr<Channel> channel) override; 385e81a82fSopenharmony_ci void OnChannelError(std::shared_ptr<Channel> channel, int errorCode) override; 395e81a82fSopenharmony_ci bool IsMediaChannelReady(); 405e81a82fSopenharmony_ci void SetMediaChannel(ModuleType moduleType); 415e81a82fSopenharmony_ci 425e81a82fSopenharmony_ciprivate: 435e81a82fSopenharmony_ci const static unsigned int UNCONNECTED_STATE = 0; 445e81a82fSopenharmony_ci const static unsigned int VIDEO_CHANNEL_CONNECTED = 1; 455e81a82fSopenharmony_ci const static unsigned int AUDIO_CHANNEL_CONNECTED = 2; 465e81a82fSopenharmony_ci 475e81a82fSopenharmony_ci wptr<CastSessionImpl> session_; 485e81a82fSopenharmony_ci unsigned int mediaChannelState_{ UNCONNECTED_STATE }; 495e81a82fSopenharmony_ci}; 505e81a82fSopenharmony_ci 515e81a82fSopenharmony_ciclass CastSessionImpl::RtspListenerImpl : public IRtspListener { 525e81a82fSopenharmony_cipublic: 535e81a82fSopenharmony_ci explicit RtspListenerImpl(sptr<CastSessionImpl> session) : session_(session) {} 545e81a82fSopenharmony_ci 555e81a82fSopenharmony_ci void OnSetup(const ParamInfo ¶m, int mediaPort, int remoteControlPort, const std::string &deviceId) override; 565e81a82fSopenharmony_ci bool OnPlay(const ParamInfo ¶m, int port, const std::string &deviceId) override; 575e81a82fSopenharmony_ci bool OnPause() override; 585e81a82fSopenharmony_ci void OnTearDown() override; 595e81a82fSopenharmony_ci void OnError(int errCode) override; 605e81a82fSopenharmony_ci bool OnPlayerReady(const ParamInfo &clientParam, const std::string &deviceId, int readyFlag) override; 615e81a82fSopenharmony_ci 625e81a82fSopenharmony_ci void NotifyTrigger(int trigger) override; 635e81a82fSopenharmony_ci void NotifyEventChange(int moduleId, int event, const std::string ¶m) override; 645e81a82fSopenharmony_ci void NotifyModuleCustomParamsNegotiation(const std::string &mediaParams, 655e81a82fSopenharmony_ci const std::string &controllerParams) override; 665e81a82fSopenharmony_ci bool NotifyEvent(int event) override; 675e81a82fSopenharmony_ci 685e81a82fSopenharmony_ci int StartMediaVtp(const ParamInfo ¶m) override; 695e81a82fSopenharmony_ci void ProcessStreamMode(const ParamInfo ¶m, const std::string &deviceId) override; 705e81a82fSopenharmony_ci 715e81a82fSopenharmony_ciprivate: 725e81a82fSopenharmony_ci wptr<CastSessionImpl> session_; 735e81a82fSopenharmony_ci}; 745e81a82fSopenharmony_ci 755e81a82fSopenharmony_ciclass CastSessionImpl::ConnectManagerListenerImpl : public IConnectManagerSessionListener { 765e81a82fSopenharmony_cipublic: 775e81a82fSopenharmony_ci explicit ConnectManagerListenerImpl(sptr<CastSessionImpl> session) : session_(session) {} 785e81a82fSopenharmony_ci 795e81a82fSopenharmony_ci void NotifySessionEvent(const std::string &deviceId, int result) override; 805e81a82fSopenharmony_ci 815e81a82fSopenharmony_ciprivate: 825e81a82fSopenharmony_ci wptr<CastSessionImpl> session_; 835e81a82fSopenharmony_ci}; 845e81a82fSopenharmony_ci 855e81a82fSopenharmony_ciclass CastSessionImpl::CastStreamListenerImpl : public ICastStreamListener { 865e81a82fSopenharmony_cipublic: 875e81a82fSopenharmony_ci explicit CastStreamListenerImpl(sptr<CastSessionImpl> session) : session_(session) {} 885e81a82fSopenharmony_ci ~CastStreamListenerImpl() override; 895e81a82fSopenharmony_ci bool SendActionToPeers(int action, const std::string ¶m) override; 905e81a82fSopenharmony_ci void OnRenderReady(bool isReady) override; 915e81a82fSopenharmony_ci void OnEvent(EventId eventId, const std::string &data) override; 925e81a82fSopenharmony_ci 935e81a82fSopenharmony_ciprivate: 945e81a82fSopenharmony_ci wptr<CastSessionImpl> session_; 955e81a82fSopenharmony_ci}; 965e81a82fSopenharmony_ci 975e81a82fSopenharmony_ciclass CastSessionImpl::BaseState : public State { 985e81a82fSopenharmony_cipublic: 995e81a82fSopenharmony_ci BaseState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1005e81a82fSopenharmony_ci : State(parentState), session_(session), stateId_(stateId) {}; 1015e81a82fSopenharmony_ci 1025e81a82fSopenharmony_ci void Enter(SessionState state); 1035e81a82fSopenharmony_ci void Exit() override; 1045e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1055e81a82fSopenharmony_ci SessionState GetStateId() const; 1065e81a82fSopenharmony_ci 1075e81a82fSopenharmony_ciprotected: 1085e81a82fSopenharmony_ci wptr<CastSessionImpl> session_; 1095e81a82fSopenharmony_ci SessionState stateId_; 1105e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(BaseState); 1115e81a82fSopenharmony_ci 1125e81a82fSopenharmony_ciprivate: 1135e81a82fSopenharmony_ci void Enter() override {} 1145e81a82fSopenharmony_ci}; 1155e81a82fSopenharmony_ci 1165e81a82fSopenharmony_ciclass CastSessionImpl::DefaultState : public BaseState { 1175e81a82fSopenharmony_cipublic: 1185e81a82fSopenharmony_ci DefaultState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1195e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1205e81a82fSopenharmony_ci 1215e81a82fSopenharmony_ciprotected: 1225e81a82fSopenharmony_ci void Enter() override; 1235e81a82fSopenharmony_ci void Exit() override; 1245e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1255e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(DefaultState); 1265e81a82fSopenharmony_ci}; 1275e81a82fSopenharmony_ci 1285e81a82fSopenharmony_ciclass CastSessionImpl::DisconnectedState : public BaseState { 1295e81a82fSopenharmony_cipublic: 1305e81a82fSopenharmony_ci DisconnectedState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1315e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1325e81a82fSopenharmony_ci 1335e81a82fSopenharmony_ciprotected: 1345e81a82fSopenharmony_ci void Enter() override; 1355e81a82fSopenharmony_ci void Exit() override; 1365e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1375e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(DisconnectedState); 1385e81a82fSopenharmony_ci}; 1395e81a82fSopenharmony_ci 1405e81a82fSopenharmony_ciclass CastSessionImpl::AuthingState : public BaseState { 1415e81a82fSopenharmony_cipublic: 1425e81a82fSopenharmony_ci AuthingState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1435e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1445e81a82fSopenharmony_ci 1455e81a82fSopenharmony_ciprotected: 1465e81a82fSopenharmony_ci void Enter() override; 1475e81a82fSopenharmony_ci void Exit() override; 1485e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1495e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(AuthingState); 1505e81a82fSopenharmony_ci}; 1515e81a82fSopenharmony_ci 1525e81a82fSopenharmony_ciclass CastSessionImpl::ConnectingState : public BaseState { 1535e81a82fSopenharmony_cipublic: 1545e81a82fSopenharmony_ci ConnectingState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1555e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1565e81a82fSopenharmony_ci 1575e81a82fSopenharmony_ciprotected: 1585e81a82fSopenharmony_ci void Enter() override; 1595e81a82fSopenharmony_ci void Exit() override; 1605e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1615e81a82fSopenharmony_ci void HandleSetupMessage(const Message &msg, sptr<CastSessionImpl> session); 1625e81a82fSopenharmony_ci void HandleSetupSuccessMessage(const Message &msg, const MessageId &msgId, sptr<CastSessionImpl> session); 1635e81a82fSopenharmony_ci void HandleDisconnectMessage(const Message &msg, sptr<CastSessionImpl> session); 1645e81a82fSopenharmony_ci void HandleErrorMessage(const Message &msg, sptr<CastSessionImpl> session); 1655e81a82fSopenharmony_ci void HandleRenderReadyMessage(const Message &msg, sptr<CastSessionImpl> session); 1665e81a82fSopenharmony_ci void HandleConnectMessage(const Message &msg, const MessageId &msgId, sptr<CastSessionImpl> session); 1675e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(ConnectingState); 1685e81a82fSopenharmony_ci}; 1695e81a82fSopenharmony_ci 1705e81a82fSopenharmony_ciclass CastSessionImpl::ConnectedState : public BaseState { 1715e81a82fSopenharmony_cipublic: 1725e81a82fSopenharmony_ci ConnectedState(SessionState stateId, sptr<CastSessionImpl> session, std::shared_ptr<State> parentState = nullptr) 1735e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1745e81a82fSopenharmony_ci 1755e81a82fSopenharmony_ciprotected: 1765e81a82fSopenharmony_ci void Enter() override; 1775e81a82fSopenharmony_ci void Exit() override; 1785e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1795e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(ConnectedState); 1805e81a82fSopenharmony_ci}; 1815e81a82fSopenharmony_ci 1825e81a82fSopenharmony_ciclass CastSessionImpl::PausedState : public BaseState { 1835e81a82fSopenharmony_cipublic: 1845e81a82fSopenharmony_ci explicit PausedState(SessionState stateId, sptr<CastSessionImpl> session, 1855e81a82fSopenharmony_ci std::shared_ptr<State> parentState = nullptr) 1865e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 1875e81a82fSopenharmony_ci 1885e81a82fSopenharmony_ciprotected: 1895e81a82fSopenharmony_ci void Enter() override; 1905e81a82fSopenharmony_ci void Exit() override; 1915e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 1925e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(PausedState); 1935e81a82fSopenharmony_ci}; 1945e81a82fSopenharmony_ci 1955e81a82fSopenharmony_ciclass CastSessionImpl::PlayingState : public BaseState { 1965e81a82fSopenharmony_cipublic: 1975e81a82fSopenharmony_ci explicit PlayingState(SessionState stateId, sptr<CastSessionImpl> session, 1985e81a82fSopenharmony_ci std::shared_ptr<State> parentState = nullptr) 1995e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 2005e81a82fSopenharmony_ci 2015e81a82fSopenharmony_ciprotected: 2025e81a82fSopenharmony_ci void Enter() override; 2035e81a82fSopenharmony_ci void Exit() override; 2045e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 2055e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(PlayingState); 2065e81a82fSopenharmony_ci bool RecvActionEventFromPeers(const Message &msg); 2075e81a82fSopenharmony_ci}; 2085e81a82fSopenharmony_ci 2095e81a82fSopenharmony_ciclass CastSessionImpl::StreamState : public BaseState { 2105e81a82fSopenharmony_cipublic: 2115e81a82fSopenharmony_ci explicit StreamState(SessionState stateId, sptr<CastSessionImpl> session, 2125e81a82fSopenharmony_ci std::shared_ptr<State> parentState = nullptr) 2135e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 2145e81a82fSopenharmony_ci 2155e81a82fSopenharmony_ciprotected: 2165e81a82fSopenharmony_ci void Enter() override; 2175e81a82fSopenharmony_ci void Exit() override; 2185e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 2195e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(StreamState); 2205e81a82fSopenharmony_ci}; 2215e81a82fSopenharmony_ci 2225e81a82fSopenharmony_ciclass CastSessionImpl::DisconnectingState : public BaseState { 2235e81a82fSopenharmony_cipublic: 2245e81a82fSopenharmony_ci explicit DisconnectingState(SessionState stateId, sptr<CastSessionImpl> session, 2255e81a82fSopenharmony_ci std::shared_ptr<State> parentState = nullptr) 2265e81a82fSopenharmony_ci : BaseState(stateId, session, parentState) {}; 2275e81a82fSopenharmony_ci 2285e81a82fSopenharmony_ciprotected: 2295e81a82fSopenharmony_ci void Enter() override; 2305e81a82fSopenharmony_ci void Exit() override; 2315e81a82fSopenharmony_ci bool HandleMessage(const Message &msg) override; 2325e81a82fSopenharmony_ci DISALLOW_EVIL_CONSTRUCTORS(DisconnectingState); 2335e81a82fSopenharmony_ci}; 2345e81a82fSopenharmony_ci} // namespace CastEngineService 2355e81a82fSopenharmony_ci} // namespace CastEngine 2365e81a82fSopenharmony_ci} // namespace OHOS 2375e81a82fSopenharmony_ci 2385e81a82fSopenharmony_ci#endif 239