1 /*
2  * Copyright (C) 2021 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 VIDEO_CALL_STATE_H
17 #define VIDEO_CALL_STATE_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 
23 #include "refbase.h"
24 #include "net_call_base.h"
25 #include "call_manager_inner_type.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 enum VideoUpdateStatus {
30     STATUS_NONE,
31     STATUS_SEND_REQUEST,
32     STATUS_RECV_REQUEST,
33     STATUS_RECV_RESPONSE,
34     STATUS_SEND_RESPONSE,
35 };
36 
37 class VideoCallState : public virtual RefBase {
38 public:
39     VideoCallState(sptr<NetCallBase> callPtr);
40     virtual ~VideoCallState() = default;
41     bool IsCallSupportVideoCall();
42     void SetVideoUpdateStatus(VideoUpdateStatus status);
43     VideoUpdateStatus GetVideoUpdateStatus();
44     int32_t SwitchCallVideoState(ImsCallMode mode);
45     int32_t DispatchUpdateVideoRequest(ImsCallMode mode);
46     int32_t DispatchUpdateVideoResponse(ImsCallMode mode);
47     int32_t DispatchReportVideoCallInfo(CallMediaModeInfo &imsCallModeInfo);
48     virtual int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) = 0;
49     virtual int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) = 0;
50     virtual int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) = 0;
51     virtual int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) = 0;
52     sptr<VideoCallState> GetCallVideoState(ImsCallMode mode);
53 
54 protected:
55     sptr<NetCallBase> call_;
56     VideoUpdateStatus updateStatus_;
57 };
58 
59 class AudioOnlyState : public VideoCallState {
60 public:
61     AudioOnlyState(sptr<NetCallBase> callPtr);
62     ~AudioOnlyState() = default;
63     int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) override;
64     int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) override;
65     int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) override;
66     int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) override;
67 };
68 
69 class VideoSendState : public VideoCallState {
70 public:
71     VideoSendState(sptr<NetCallBase> callPtr);
72     ~VideoSendState() = default;
73     int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) override;
74     int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) override;
75     int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) override;
76     int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) override;
77 };
78 
79 class VideoReceiveState : public VideoCallState {
80 public:
81     VideoReceiveState(sptr<NetCallBase> callPtr);
82     ~VideoReceiveState() = default;
83     int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) override;
84     int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) override;
85     int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) override;
86     int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) override;
87 };
88 
89 class VideoSendReceiveState : public VideoCallState {
90 public:
91     VideoSendReceiveState(sptr<NetCallBase> callPtr);
92     ~VideoSendReceiveState() = default;
93     int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) override;
94     int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) override;
95     int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) override;
96     int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) override;
97 };
98 
99 class VideoPauseState : public VideoCallState {
100 public:
101     VideoPauseState(sptr<NetCallBase> callPtr);
102     ~VideoPauseState() = default;
103     int32_t SendUpdateCallMediaModeRequest(ImsCallMode mode) override;
104     int32_t RecieveUpdateCallMediaModeRequest(CallMediaModeInfo &imsCallModeInfo) override;
105     int32_t SendUpdateCallMediaModeResponse(ImsCallMode mode) override;
106     int32_t ReceiveUpdateCallMediaModeResponse(CallMediaModeInfo &imsCallModeInfo) override;
107 };
108 } // namespace Telephony
109 } // namespace OHOS
110 #endif