166f3657fSopenharmony_ci/* 266f3657fSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 366f3657fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 466f3657fSopenharmony_ci * you may not use this file except in compliance with the License. 566f3657fSopenharmony_ci * You may obtain a copy of the License at 666f3657fSopenharmony_ci * 766f3657fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 866f3657fSopenharmony_ci * 966f3657fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1066f3657fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1166f3657fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1266f3657fSopenharmony_ci * See the License for the specific language governing permissions and 1366f3657fSopenharmony_ci * limitations under the License. 1466f3657fSopenharmony_ci */ 1566f3657fSopenharmony_ci#include "video_param.h" 1666f3657fSopenharmony_ci 1766f3657fSopenharmony_ci#include "dscreen_constants.h" 1866f3657fSopenharmony_ci#include "dscreen_json_util.h" 1966f3657fSopenharmony_ci#include "dscreen_log.h" 2066f3657fSopenharmony_ci 2166f3657fSopenharmony_ciusing json = nlohmann::json; 2266f3657fSopenharmony_ci 2366f3657fSopenharmony_cinamespace OHOS { 2466f3657fSopenharmony_cinamespace DistributedHardware { 2566f3657fSopenharmony_civoid VideoParam::SetScreenWidth(uint32_t screenWidth) 2666f3657fSopenharmony_ci{ 2766f3657fSopenharmony_ci screenWidth_ = screenWidth; 2866f3657fSopenharmony_ci} 2966f3657fSopenharmony_ci 3066f3657fSopenharmony_ciuint32_t VideoParam::GetScreenWidth() const 3166f3657fSopenharmony_ci{ 3266f3657fSopenharmony_ci return screenWidth_; 3366f3657fSopenharmony_ci} 3466f3657fSopenharmony_ci 3566f3657fSopenharmony_civoid VideoParam::SetScreenHeight(uint32_t screenHeight) 3666f3657fSopenharmony_ci{ 3766f3657fSopenharmony_ci screenHeight_ = screenHeight; 3866f3657fSopenharmony_ci} 3966f3657fSopenharmony_ci 4066f3657fSopenharmony_ciuint32_t VideoParam::GetScreenHeight() const 4166f3657fSopenharmony_ci{ 4266f3657fSopenharmony_ci return screenHeight_; 4366f3657fSopenharmony_ci} 4466f3657fSopenharmony_ci 4566f3657fSopenharmony_civoid VideoParam::SetVideoWidth(uint32_t videoWidth) 4666f3657fSopenharmony_ci{ 4766f3657fSopenharmony_ci videoWidth_ = videoWidth; 4866f3657fSopenharmony_ci} 4966f3657fSopenharmony_ci 5066f3657fSopenharmony_ciuint32_t VideoParam::GetVideoWidth() const 5166f3657fSopenharmony_ci{ 5266f3657fSopenharmony_ci return videoWidth_; 5366f3657fSopenharmony_ci} 5466f3657fSopenharmony_ci 5566f3657fSopenharmony_civoid VideoParam::SetPartialRefreshFlag(bool flag) 5666f3657fSopenharmony_ci{ 5766f3657fSopenharmony_ci isPartialRefresh_ = flag; 5866f3657fSopenharmony_ci} 5966f3657fSopenharmony_ci 6066f3657fSopenharmony_cibool VideoParam::GetPartialRefreshFlag() const 6166f3657fSopenharmony_ci{ 6266f3657fSopenharmony_ci return isPartialRefresh_; 6366f3657fSopenharmony_ci} 6466f3657fSopenharmony_ci 6566f3657fSopenharmony_civoid VideoParam::SetVideoHeight(uint32_t videoHeight) 6666f3657fSopenharmony_ci{ 6766f3657fSopenharmony_ci videoHeight_ = videoHeight; 6866f3657fSopenharmony_ci} 6966f3657fSopenharmony_ci 7066f3657fSopenharmony_ciuint32_t VideoParam::GetVideoHeight() const 7166f3657fSopenharmony_ci{ 7266f3657fSopenharmony_ci return videoHeight_; 7366f3657fSopenharmony_ci} 7466f3657fSopenharmony_ci 7566f3657fSopenharmony_civoid VideoParam::SetFps(double fps) 7666f3657fSopenharmony_ci{ 7766f3657fSopenharmony_ci fps_ = fps; 7866f3657fSopenharmony_ci} 7966f3657fSopenharmony_ci 8066f3657fSopenharmony_cidouble VideoParam::GetFps() const 8166f3657fSopenharmony_ci{ 8266f3657fSopenharmony_ci return fps_; 8366f3657fSopenharmony_ci} 8466f3657fSopenharmony_ci 8566f3657fSopenharmony_civoid VideoParam::SetCodecType(uint8_t codecType) 8666f3657fSopenharmony_ci{ 8766f3657fSopenharmony_ci codecType_ = codecType; 8866f3657fSopenharmony_ci} 8966f3657fSopenharmony_ci 9066f3657fSopenharmony_ciuint8_t VideoParam::GetCodecType() const 9166f3657fSopenharmony_ci{ 9266f3657fSopenharmony_ci return codecType_; 9366f3657fSopenharmony_ci} 9466f3657fSopenharmony_ci 9566f3657fSopenharmony_civoid VideoParam::SetVideoFormat(uint8_t videoFormat) 9666f3657fSopenharmony_ci{ 9766f3657fSopenharmony_ci videoFormat_ = videoFormat; 9866f3657fSopenharmony_ci} 9966f3657fSopenharmony_ci 10066f3657fSopenharmony_ciuint8_t VideoParam::GetVideoFormat() const 10166f3657fSopenharmony_ci{ 10266f3657fSopenharmony_ci return videoFormat_; 10366f3657fSopenharmony_ci} 10466f3657fSopenharmony_ci 10566f3657fSopenharmony_civoid to_json(json &j, const DistributedHardware::VideoParam &videoParam) 10666f3657fSopenharmony_ci{ 10766f3657fSopenharmony_ci j = json { 10866f3657fSopenharmony_ci {KEY_SCREEN_WIDTH, videoParam.screenWidth_}, 10966f3657fSopenharmony_ci {KEY_SCREEN_HEIGHT, videoParam.screenHeight_}, 11066f3657fSopenharmony_ci {KEY_VIDEO_WIDTH, videoParam.videoWidth_}, 11166f3657fSopenharmony_ci {KEY_VIDEO_HEIGHT, videoParam.videoHeight_}, 11266f3657fSopenharmony_ci {KEY_FPS, videoParam.fps_}, 11366f3657fSopenharmony_ci {KEY_CODECTYPE, videoParam.codecType_}, 11466f3657fSopenharmony_ci {KEY_COLOR_FORMAT, videoParam.videoFormat_}, 11566f3657fSopenharmony_ci {KEY_PARTIALREFRESH, videoParam.isPartialRefresh_} 11666f3657fSopenharmony_ci }; 11766f3657fSopenharmony_ci} 11866f3657fSopenharmony_ci 11966f3657fSopenharmony_civoid from_json(const json &j, DistributedHardware::VideoParam &videoParam) 12066f3657fSopenharmony_ci{ 12166f3657fSopenharmony_ci if (!IsUInt32(j, KEY_SCREEN_WIDTH) || !IsUInt32(j, KEY_SCREEN_HEIGHT) || 12266f3657fSopenharmony_ci !IsUInt32(j, KEY_VIDEO_WIDTH) || !IsUInt32(j, KEY_VIDEO_HEIGHT) || 12366f3657fSopenharmony_ci !IsFloat(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || 12466f3657fSopenharmony_ci !IsUInt8(j, KEY_COLOR_FORMAT)) { 12566f3657fSopenharmony_ci DHLOGE("Invalid JSON value for one or more keys."); 12666f3657fSopenharmony_ci return; 12766f3657fSopenharmony_ci } 12866f3657fSopenharmony_ci 12966f3657fSopenharmony_ci const uint32_t screenWidth = j[KEY_SCREEN_WIDTH].get<uint32_t>(); 13066f3657fSopenharmony_ci const uint32_t screenHeight = j[KEY_SCREEN_HEIGHT].get<uint32_t>(); 13166f3657fSopenharmony_ci const uint32_t videoWidth = j[KEY_VIDEO_WIDTH].get<uint32_t>(); 13266f3657fSopenharmony_ci const uint32_t videoHeight = j[KEY_VIDEO_HEIGHT].get<uint32_t>(); 13366f3657fSopenharmony_ci 13466f3657fSopenharmony_ci if ((screenWidth > DSCREEN_MAX_SCREEN_DATA_WIDTH) || (screenHeight > DSCREEN_MAX_SCREEN_DATA_HEIGHT)) { 13566f3657fSopenharmony_ci DHLOGE("Screen width or height exceeds the maximum limit."); 13666f3657fSopenharmony_ci return; 13766f3657fSopenharmony_ci } 13866f3657fSopenharmony_ci 13966f3657fSopenharmony_ci if ((videoWidth > DSCREEN_MAX_VIDEO_DATA_WIDTH) || (videoHeight > DSCREEN_MAX_VIDEO_DATA_HEIGHT)) { 14066f3657fSopenharmony_ci DHLOGE("Video width or height exceeds the maximum limit."); 14166f3657fSopenharmony_ci return; 14266f3657fSopenharmony_ci } 14366f3657fSopenharmony_ci 14466f3657fSopenharmony_ci videoParam.screenWidth_ = screenWidth; 14566f3657fSopenharmony_ci videoParam.screenHeight_ = screenHeight; 14666f3657fSopenharmony_ci videoParam.videoWidth_ = videoWidth; 14766f3657fSopenharmony_ci videoParam.videoHeight_ = videoHeight; 14866f3657fSopenharmony_ci videoParam.fps_ = j[KEY_FPS].get<double>(); 14966f3657fSopenharmony_ci videoParam.codecType_ = j[KEY_CODECTYPE].get<uint8_t>(); 15066f3657fSopenharmony_ci videoParam.videoFormat_ = j[KEY_COLOR_FORMAT].get<uint8_t>(); 15166f3657fSopenharmony_ci videoParam.isPartialRefresh_ = false; 15266f3657fSopenharmony_ci if (IsBool(j, KEY_PARTIALREFRESH)) { 15366f3657fSopenharmony_ci videoParam.isPartialRefresh_ = j[KEY_PARTIALREFRESH].get<bool>(); 15466f3657fSopenharmony_ci } 15566f3657fSopenharmony_ci} 15666f3657fSopenharmony_ci} // namespace DistributedHardware 15766f3657fSopenharmony_ci} // namespace OHOS 158