• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_WFD_SESSION_DEF_H
17 #define OHOS_SHARING_WFD_SESSION_DEF_H
18 
19 #include "avcodec_info.h"
20 #include "common/event_comm.h"
21 #include "impl/scene/wfd/wfd_def.h"
22 
23 namespace OHOS {
24 namespace Sharing {
25 
26 constexpr uint16_t MAX_RTSP_TIMEOUT_COUNTS = 3;
27 
28 constexpr uint32_t WFD_SEC_TO_MSEC = 1000;
29 constexpr uint32_t P2P_CONNECT_TIMEOUT = 60;
30 constexpr uint32_t P2P_DISCONNECT_TIMEOUT = 3;
31 constexpr uint32_t RTSP_SESSION_TIMEOUT = 30;
32 constexpr uint32_t RTSP_INTERACTION_TIMEOUT = 10;
33 constexpr uint32_t RTSP_TCP_CONNECT_TIMEOUT = 5;
34 constexpr uint32_t MINIMAL_VIDEO_FORMAT_SIZE = 54;
35 constexpr uint32_t VIDEO_RESOLUTION_TABLE_LENGTH = 34;
36 constexpr uint32_t AUDIO_MODES_TABLE_LENGTH = 10;
37 constexpr uint32_t TYPE_CEA = 0;
38 constexpr uint32_t TYPE_VESA = 1;
39 constexpr uint32_t TYPE_HH = 2;
40 constexpr uint32_t INDEX_CEA = 4;
41 constexpr uint32_t INDEX_VESA = 5;
42 constexpr uint32_t INDEX_HH = 6;
43 constexpr uint32_t HEX_LENGTH = 16;
44 constexpr uint32_t MAX_CEA_INDEX = 26;
45 constexpr uint32_t MAX_VESA_INDEX = 33;
46 constexpr uint32_t MAX_HH_INDEX = 11;
47 constexpr uint32_t VIDEO_R1_RESOLUTION_SIZE = 17;
48 constexpr uint32_t VIDEO_R2_RESOLUTION_SIZE = 27;
49 constexpr uint32_t TYPE_LPCM = 0;
50 constexpr uint32_t TYPE_AAC = 1;
51 constexpr uint32_t TYPE_AC3 = 2;
52 constexpr uint32_t LOG_BASE = 2;
53 constexpr uint32_t VIDEO_AVC_TYPE = 1;
54 constexpr uint32_t VIDEO_HEVC_TYPE = 2;
55 constexpr uint32_t AUDIO_MODE_BIT_LENGTH = 32;
56 constexpr uint32_t AUDIO_TYPE_INDEX = 0;
57 constexpr uint32_t AUDIO_MODE_INDEX = 1;
58 constexpr uint32_t AUDIO_LPCM_MODE_LENGTH = 2;
59 constexpr uint32_t AUDIO_AAC_MODE_LENGTH = 4;
60 constexpr uint32_t AUDIO_AAC3_MODE_LENGTH = 3;
61 
62 const std::string LPCM = "LPCM";
63 const std::string AAC = "AAC";
64 const std::string AC3 = "AC3";
65 const std::string RTSP_METHOD_WFD = "org.wfa.wfd1.0";
66 const std::string WFD_PARAM_3D_FORMATS = "wfd_3d_formats";
67 const std::string WFD_PARAM_TRIGGER = "wfd_trigger_method";
68 const std::string WFD_PARAM_IDR_REQUEST = "wfd_idr_request";
69 const std::string WFD_PARAM_DISPLAY_EDID = "wfd_display_edid";
70 const std::string WFD_PARAM_COUPLED_SINK = "wfd_coupled_sink";
71 const std::string WFD_PARAM_AUDIO_CODECS = "wfd_audio_codecs";
72 const std::string WFD_PARAM_AUDIO_CODECS_2 = "wfd2_audio_codecs";
73 const std::string WFD_PARAM_RTP_PORTS = "wfd_client_rtp_ports";
74 const std::string WFD_PARAM_VIDEO_FORMATS = "wfd_video_formats";
75 const std::string WFD_PARAM_VIDEO_FORMATS_2 = "wfd2_video_formats";
76 const std::string WFD_PARAM_TRIGGER_METHOD = "wfd_trigger_method";
77 const std::string WFD_RTSP_URL_DEFAULT = "rtsp://localhost/wfd1.0";
78 const std::string WFD_PARAM_UIBC_CAPABILITY = "wfd_uibc_capability";
79 const std::string WFD_PARAM_PRESENTATION_URL = "wfd_presentation_URL";
80 const std::string WFD_PARAM_CONTENT_PROTECTION = "wfd_content_protection";
81 const std::string WFD_PARAM_STANDBY_RESUME = "wfd_standby_resume_capability";
82 const std::string WFD_PARAM_HWE_VERSION = "wfd_hwe_version";
83 const std::string WFD_PARAM_HWE_VENDER_ID = "wfd_hwe_vender_id";
84 const std::string WFD_PARAM_HWE_PRODUCT_ID = "wfd_hwe_product_id";
85 const std::string WFD_PARAM_HWE_VTP = "wfd_hwe_vtp";
86 const std::string WFD_PARAM_HWE_VIDEO_60FPS = "wfd_hwe_video_60fps";
87 const std::string WFD_PARAM_HWE_HEVC_FORMATS = "wfd_hwe_hevc_formats";
88 const std::string WFD_PARAM_HWE_VERIFICATION_CODE = "wfd_hwe_version";
89 const std::string WFD_PARAM_HWE_AVSYNC_SINK = "wfd_hwe_avsync_sink";
90 const std::string WFD_PARAM_CONNECTOR_TYPE = "wfd_connector_type";
91 const std::string WFD_PARAM_IDR_REQUEST_CAPABILITY = "wfd_idr_request_capability";
92 const std::string WFD_PARAM_RTCP_CAPABILITY = "microsoft_rtcp_capability";
93 
94 struct VideoConfigTable {
95     int32_t width;
96     int32_t height;
97     int32_t frameRate;
98     bool interlaced;
99 };
100 
101 struct AudioConfigTable {
102     int32_t sampleRate;
103     int32_t sampleFormat;
104     int32_t channels;
105 };
106 
107 const VideoConfigTable VIDEO_RESOLUTION_TABLE[][VIDEO_RESOLUTION_TABLE_LENGTH] = {
108     {
109         // CEA Resolution
110         {640, 480, 60, false},   {720, 480, 60, false},   {720, 480, 60, true},    {720, 576, 50, false},
111         {720, 576, 50, true},    {1280, 720, 30, false},  {1280, 720, 60, false},  {1920, 1080, 30, false},
112         {1920, 1080, 60, false}, {1920, 1080, 60, true},  {1280, 720, 25, false},  {1280, 720, 50, false},
113         {1920, 1080, 25, false}, {1920, 1080, 50, false}, {1920, 1080, 50, true},  {1280, 720, 24, false},
114         {1920, 1080, 24, false}, {3840, 2160, 24, false}, {3840, 2160, 25, false}, {3840, 2160, 30, false},
115         {3840, 2160, 50, false}, {3840, 2160, 60, false}, {4096, 2160, 24, false}, {4096, 2160, 25, false},
116         {4096, 2160, 30, false}, {4096, 2160, 50, false}, {4096, 2160, 60, false},
117     },
118     {
119         // VESA Resolutions
120         {800, 600, 30, false},   {800, 600, 60, false},   {1024, 768, 30, false},  {1024, 768, 60, false},
121         {1152, 864, 30, false},  {1152, 864, 60, false},  {1280, 768, 30, false},  {1280, 768, 60, false},
122         {1280, 800, 30, false},  {1280, 800, 60, false},  {1360, 768, 30, false},  {1360, 768, 60, false},
123         {1366, 768, 30, false},  {1366, 768, 60, false},  {1280, 1024, 30, false}, {1280, 1024, 60, false},
124         {1440, 1050, 30, false}, {1440, 1050, 60, false}, {1440, 900, 30, false},  {1440, 900, 60, false},
125         {1600, 900, 30, false},  {1600, 900, 60, false},  {1600, 1200, 30, false}, {1600, 1200, 60, false},
126         {1680, 1024, 30, false}, {1680, 1024, 60, false}, {1680, 1050, 30, false}, {1680, 1050, 60, false},
127         {1920, 1200, 30, false}, {1920, 1200, 60, false}, {2560, 1440, 30, false}, {2560, 1440, 60, false},
128         {2560, 1600, 30, false}, {2560, 1600, 60, false},
129     },
130     {
131         // HH Resolutions
132         {800, 480, 30, false},
133         {800, 480, 60, false},
134         {854, 480, 30, false},
135         {854, 480, 60, false},
136         {864, 480, 30, false},
137         {864, 480, 60, false},
138         {640, 360, 30, false},
139         {640, 360, 60, false},
140         {960, 540, 30, false},
141         {960, 540, 60, false},
142         {848, 480, 30, false},
143         {848, 480, 60, false},
144     }};
145 
146 const AudioConfigTable AUDIO_CONFIG_TABLE[][AUDIO_MODES_TABLE_LENGTH] = {
147     {
148         // LPCM
149         {44100, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 2},
150         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 2},
151         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 1},
152         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 6},
153         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 8},
154         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S24LE, 2},
155         {96000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 2},
156         {96000, MediaAVCodec::AudioSampleFormat::SAMPLE_S24LE, 2},
157         {96000, MediaAVCodec::AudioSampleFormat::SAMPLE_S24LE, 6},
158         {96000, MediaAVCodec::AudioSampleFormat::SAMPLE_S24LE, 8},
159     },
160     {
161         // AAC
162         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 2},
163         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 4},
164         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 6},
165         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 8},
166     },
167     {
168         // AC3
169         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 2},
170         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 4},
171         {48000, MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE, 6},
172     }
173 
174 };
175 
176 struct WfdSceneEventMsg : public InteractionEventMsg {
177     using Ptr = std::shared_ptr<WfdSceneEventMsg>;
178 
179     std::string mac;
180 };
181 
182 struct WfdSinkSessionEventMsg : public SessionEventMsg {
183     using Ptr = std::shared_ptr<WfdSinkSessionEventMsg>;
184 
185     uint16_t localPort = 0;
186     uint16_t remotePort = 0;
187 
188     std::string remoteIp;
189     std::string localIp;
190     std::string mac;
191 
192     AudioFormat audioFormat = AUDIO_NONE;
193     VideoFormat videoFormat = VIDEO_NONE;
194     WfdParamsInfo wfdParamsInfo;
195 };
196 
197 struct WfdSourceSessionEventMsg : public SessionEventMsg {
198     using Ptr = std::shared_ptr<WfdSourceSessionEventMsg>;
199 
200     uint32_t sinkAgentId;
201     uint16_t localPort = 0;
202     uint16_t remotePort = 0;
203 
204     std::string ip;
205     std::string mac;
206 
207     AudioFormat audioFormat = AUDIO_48000_16_2;
208     VideoFormat videoFormat = VIDEO_1920X1080_30;
209 };
210 
211 // Table 34. Supported CEA Resolution/Refresh Rates
212 enum WfdCeaResolution {
213     CEA_640_480_P60 = 0,
214     CEA_720_480_P60,
215     CEA_720_480_I60,
216     CEA_720_576_P50,
217     CEA_720_576_I50,
218     CEA_1280_720_P30 = 5,
219     CEA_1280_720_P60,
220     CEA_1920_1080_P30 = 7,
221     CEA_1920_1080_P60,
222     CEA_1920_1080_I60,
223     CEA_1280_720_P25 = 10,
224     CEA_1280_720_P50,
225     CEA_1920_1080_P25 = 12,
226     CEA_1920_1080_P50,
227     CEA_1920_1080_I50,
228     CEA_1280_720_P24 = 15,
229     CEA_1920_1080_P24 = 16
230 };
231 
232 // Table 35. Supported VESA Resolution/Refresh Rates
233 enum WfdVesaResolution {
234     VESA_800_600_P30 = 0,
235     VESA_800_600_P60,
236     VESA_1366_768_P30 = 12,
237     VESA_1366_768_P60,
238     VESA_1280_1024_P30,
239     VESA_1280_1024_P60 = 15,
240     VESA_1920_1200_P30 = 28
241 };
242 
243 // Table 36. Supported HH Resolutions/Refresh Rates
244 enum WfdHhResolution {
245     HH_800_480_P30 = 0,
246     HH_800_480_P60 = 1,
247     HH_960_540_P30 = 8,
248     HH_960_540_P60,
249     HH_848_480_P60 = 11
250 };
251 
252 // Table 37. Display Native Resolution Refresh Rate
253 enum class WfdResolutionType : uint8_t {
254     RESOLUTION_CEA,  // 0b000
255     RESOLUTION_VESA, // 0b001
256     RESOLUTION_HH    // 0b010
257 };
258 
259 // Table 38. Profiles Bitmap
260 enum class WfdH264Profile {
261     PROFILE_CBP = 0, // 0 0b0: CBP not supported; 0b1: CBP supported;
262     PROFILE_CHP,     // 1 0b0: CHP not supported; 0b1: CHP supported;
263     PROFILE_RHP,
264     PROFILE_BP,
265     PROFILE_MP,
266     PROFILE_HIP,
267 };
268 
269 // Table 39. Maximum H.264 Level Supported
270 enum class WfdH264Level {
271     LEVEL_31 = 0,
272     LEVEL_32,
273     LEVEL_40,
274     LEVEL_41,
275     LEVEL_42,
276     LEVEL_50,
277     LEVEL_51,
278     LEVEL_52,
279 };
280 
281 // Table 76. Video codec Type field values in WFD R2
282 enum class WfdVideoCodec {
283     CODEC_H264 = 0,
284     CODEC_H265,
285 };
286 
287 enum WfdAACMode {
288     AAC_48000_16_2 = 0,
289     AAC_48000_16_4,
290     AAC_48000_16_6,
291     AAC_48000_16_8,
292 };
293 
294 enum WfdLPCMMode {
295     LPCM_44100_16_2 = 0,
296     LPCM_48000_16_2,
297 };
298 
299 } // namespace Sharing
300 } // namespace OHOS
301 #endif
302