1 /*
2 * Copyright (c) 2022-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 #include "video_param.h"
16
17 #include "dscreen_constants.h"
18 #include "dscreen_json_util.h"
19
20 using json = nlohmann::json;
21
22 namespace OHOS {
23 namespace DistributedHardware {
SetScreenWidth(uint32_t screenWidth)24 void VideoParam::SetScreenWidth(uint32_t screenWidth)
25 {
26 screenWidth_ = screenWidth;
27 }
28
GetScreenWidth() const29 uint32_t VideoParam::GetScreenWidth() const
30 {
31 return screenWidth_;
32 }
33
SetScreenHeight(uint32_t screenHeight)34 void VideoParam::SetScreenHeight(uint32_t screenHeight)
35 {
36 screenHeight_ = screenHeight;
37 }
38
GetScreenHeight() const39 uint32_t VideoParam::GetScreenHeight() const
40 {
41 return screenHeight_;
42 }
43
SetVideoWidth(uint32_t videoWidth)44 void VideoParam::SetVideoWidth(uint32_t videoWidth)
45 {
46 videoWidth_ = videoWidth;
47 }
48
GetVideoWidth() const49 uint32_t VideoParam::GetVideoWidth() const
50 {
51 return videoWidth_;
52 }
53
SetPartialRefreshFlag(bool flag)54 void VideoParam::SetPartialRefreshFlag(bool flag)
55 {
56 isPartialRefresh_ = flag;
57 }
58
GetPartialRefreshFlag() const59 bool VideoParam::GetPartialRefreshFlag() const
60 {
61 return isPartialRefresh_;
62 }
63
SetVideoHeight(uint32_t videoHeight)64 void VideoParam::SetVideoHeight(uint32_t videoHeight)
65 {
66 videoHeight_ = videoHeight;
67 }
68
GetVideoHeight() const69 uint32_t VideoParam::GetVideoHeight() const
70 {
71 return videoHeight_;
72 }
73
SetFps(double fps)74 void VideoParam::SetFps(double fps)
75 {
76 fps_ = fps;
77 }
78
GetFps() const79 double VideoParam::GetFps() const
80 {
81 return fps_;
82 }
83
SetCodecType(uint8_t codecType)84 void VideoParam::SetCodecType(uint8_t codecType)
85 {
86 codecType_ = codecType;
87 }
88
GetCodecType() const89 uint8_t VideoParam::GetCodecType() const
90 {
91 return codecType_;
92 }
93
SetVideoFormat(uint8_t videoFormat)94 void VideoParam::SetVideoFormat(uint8_t videoFormat)
95 {
96 videoFormat_ = videoFormat;
97 }
98
GetVideoFormat() const99 uint8_t VideoParam::GetVideoFormat() const
100 {
101 return videoFormat_;
102 }
103
to_json(json & j,const DistributedHardware::VideoParam & videoParam)104 void to_json(json &j, const DistributedHardware::VideoParam &videoParam)
105 {
106 j = json {
107 {KEY_SCREEN_WIDTH, videoParam.screenWidth_},
108 {KEY_SCREEN_HEIGHT, videoParam.screenHeight_},
109 {KEY_VIDEO_WIDTH, videoParam.videoWidth_},
110 {KEY_VIDEO_HEIGHT, videoParam.videoHeight_},
111 {KEY_FPS, videoParam.fps_},
112 {KEY_CODECTYPE, videoParam.codecType_},
113 {KEY_COLOR_FORMAT, videoParam.videoFormat_},
114 {KEY_PARTIALREFREAH, videoParam.isPartialRefresh_}
115 };
116 }
117
from_json(const json & j,DistributedHardware::VideoParam & videoParam)118 void from_json(const json &j, DistributedHardware::VideoParam &videoParam)
119 {
120 if (!IsUInt32(j, KEY_SCREEN_WIDTH) || !IsUInt32(j, KEY_SCREEN_HEIGHT) ||
121 !IsUInt32(j, KEY_VIDEO_WIDTH) || !IsUInt32(j, KEY_VIDEO_HEIGHT) ||
122 !IsFloat(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) ||
123 !IsUInt8(j, KEY_COLOR_FORMAT)) {
124 return;
125 }
126
127 videoParam.screenWidth_ = j[KEY_SCREEN_WIDTH].get<uint32_t>();
128 videoParam.screenHeight_ = j[KEY_SCREEN_HEIGHT].get<uint32_t>();
129 videoParam.videoWidth_ = j[KEY_VIDEO_WIDTH].get<uint32_t>();
130 videoParam.videoHeight_ = j[KEY_VIDEO_HEIGHT].get<uint32_t>();
131 videoParam.fps_ = j[KEY_FPS].get<double>();
132 videoParam.codecType_ = j[KEY_CODECTYPE].get<uint8_t>();
133 videoParam.videoFormat_ = j[KEY_COLOR_FORMAT].get<uint8_t>();
134 videoParam.isPartialRefresh_ = false;
135 if (IsBool(j, KEY_PARTIALREFREAH)) {
136 videoParam.isPartialRefresh_ = j[KEY_PARTIALREFREAH].get<bool>();
137 }
138 }
139 } // namespace DistributedHardware
140 } // namespace OHOS
141