• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
SetVideoHeight(uint32_t videoHeight)54 void VideoParam::SetVideoHeight(uint32_t videoHeight)
55 {
56     videoHeight_ = videoHeight;
57 }
58 
GetVideoHeight() const59 uint32_t VideoParam::GetVideoHeight() const
60 {
61     return videoHeight_;
62 }
63 
SetFps(uint32_t fps)64 void VideoParam::SetFps(uint32_t fps)
65 {
66     fps_ = fps;
67 }
68 
GetFps() const69 uint32_t VideoParam::GetFps() const
70 {
71     return fps_;
72 }
73 
SetCodecType(uint8_t codecType)74 void VideoParam::SetCodecType(uint8_t codecType)
75 {
76     codecType_ = codecType;
77 }
78 
GetCodecType() const79 uint8_t VideoParam::GetCodecType() const
80 {
81     return codecType_;
82 }
83 
SetVideoFormat(uint8_t videoFormat)84 void VideoParam::SetVideoFormat(uint8_t videoFormat)
85 {
86     videoFormat_ = videoFormat;
87 }
88 
GetVideoFormat() const89 uint8_t VideoParam::GetVideoFormat() const
90 {
91     return videoFormat_;
92 }
93 
to_json(json & j,const DistributedHardware::VideoParam & videoParam)94 void to_json(json &j, const DistributedHardware::VideoParam &videoParam)
95 {
96     j = json {
97         {KEY_SCREEN_WIDTH, videoParam.screenWidth_},
98         {KEY_SCREEN_HEIGHT, videoParam.screenHeight_},
99         {KEY_VIDEO_WIDTH, videoParam.videoWidth_},
100         {KEY_VIDEO_HEIGHT, videoParam.videoHeight_},
101         {KEY_FPS, videoParam.fps_},
102         {KEY_CODECTYPE, videoParam.codecType_},
103         {KEY_COLOR_FORMAT, videoParam.videoFormat_}
104     };
105 }
106 
from_json(const json & j,DistributedHardware::VideoParam & videoParam)107 void from_json(const json &j, DistributedHardware::VideoParam &videoParam)
108 {
109     if (!IsUInt32(j, KEY_SCREEN_WIDTH) || !IsUInt32(j, KEY_SCREEN_HEIGHT) ||
110         !IsUInt32(j, KEY_VIDEO_WIDTH) || !IsUInt32(j, KEY_VIDEO_HEIGHT) ||
111         !IsUInt32(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || !IsUInt8(j, KEY_COLOR_FORMAT)) {
112         return;
113     }
114 
115     videoParam.screenWidth_ = j[KEY_SCREEN_WIDTH].get<uint32_t>();
116     videoParam.screenHeight_ = j[KEY_SCREEN_HEIGHT].get<uint32_t>();
117     videoParam.videoWidth_ = j[KEY_VIDEO_WIDTH].get<uint32_t>();
118     videoParam.videoHeight_ = j[KEY_VIDEO_HEIGHT].get<uint32_t>();
119     videoParam.fps_ = j[KEY_FPS].get<uint32_t>();
120     videoParam.codecType_ = j[KEY_CODECTYPE].get<uint8_t>();
121     videoParam.videoFormat_ = j[KEY_COLOR_FORMAT].get<uint8_t>();
122 }
123 } // namespace DistributedHardware
124 } // namespace OHOS
125