1 /*
2 * Copyright (c) 2023-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 #if defined(VIDEO_SUPPORT)
16
17 #define HST_LOG_TAG "CodecPort"
18
19 #include "codec_port.h"
20 #include "codec_utils.h"
21 #include "foundation/log.h"
22 #include "hdf_base.h"
23 #include "plugin/common/plugin_buffer.h"
24
25 namespace {
26 constexpr uint32_t HDI_FRAME_RATE_MOVE = 16; // hdi frame rate need move 16
27 constexpr uint32_t HDI_VIDEO_ALIGNMENT = 16;
28 }
29 namespace OHOS {
30 namespace Media {
31 namespace Plugin {
32 namespace CodecAdapter {
CodecPort(CodecComponentType * component,uint32_t portIndex,const CompVerInfo & verInfo)33 CodecPort::CodecPort(CodecComponentType* component, uint32_t portIndex, const CompVerInfo& verInfo)
34 : codecComp_(component), verInfo_(verInfo)
35 {
36 InitOmxParam(portDef_, verInfo_);
37 portDef_.nPortIndex = portIndex;
38 verInfo_ = verInfo;
39 }
40
Config(Meta & meta)41 Status CodecPort::Config(Meta& meta)
42 {
43 MEDIA_LOG_D("Config Start");
44 auto ret = HdiGetParameter(codecComp_, OMX_IndexParamPortDefinition, portDef_);
45 FALSE_RETURN_V_MSG(ret == HDF_SUCCESS, Status::ERROR_INVALID_PARAMETER, "HdiGetParameter portDef failed");
46 std::string mime;
47 uint32_t height;
48 uint32_t width;
49 uint32_t frameRate;
50 int64_t bitRate;
51 Plugin::VideoPixelFormat vdecFormat;
52 FALSE_LOG(meta.Get<Tag::MIME>(mime));
53 FALSE_LOG(meta.Get<Tag::VIDEO_PIXEL_FORMAT>(vdecFormat));
54 FALSE_LOG(meta.Get<Tag::VIDEO_HEIGHT>(height));
55 FALSE_LOG(meta.Get<Tag::VIDEO_WIDTH>(width));
56 FALSE_LOG(meta.Get<Tag::VIDEO_FRAME_RATE>(frameRate));
57 FALSE_LOG(meta.Get<Tag::MEDIA_BITRATE>(bitRate));
58 portDef_.format.video.eCompressionFormat = CodingTypeHstToHdi(mime);
59 portDef_.format.video.eColorFormat = FormatHstToOmx(vdecFormat);
60 portDef_.format.video.nFrameHeight = AlignUp(height, HDI_VIDEO_ALIGNMENT);
61 portDef_.format.video.nSliceHeight = AlignUp(height, HDI_VIDEO_ALIGNMENT);
62 portDef_.format.video.nFrameWidth = AlignUp(width, HDI_VIDEO_ALIGNMENT);
63 portDef_.format.video.nStride = static_cast<int32_t>(AlignUp(width, HDI_VIDEO_ALIGNMENT));
64 portDef_.format.video.xFramerate = frameRate << HDI_FRAME_RATE_MOVE;
65 MEDIA_LOG_D("frame_rate: " PUBLIC_LOG_U32, portDef_.format.video.xFramerate);
66 portDef_.format.video.nBitrate = static_cast<uint32_t>(bitRate);
67 ret = HdiSetParameter(codecComp_, OMX_IndexParamPortDefinition, portDef_);
68 FALSE_RETURN_V_MSG(ret == HDF_SUCCESS, Status::ERROR_INVALID_PARAMETER, "HdiSetParameter failed");
69 return Status::OK;
70 }
71
QueryParam(PortInfo & portInfo)72 Status CodecPort::QueryParam(PortInfo& portInfo)
73 {
74 MEDIA_LOG_D("QueryParam Start");
75 auto ret = HdiGetParameter(codecComp_, OMX_IndexParamPortDefinition, portDef_);
76 FALSE_RETURN_V_MSG(ret == HDF_SUCCESS, Status::ERROR_INVALID_PARAMETER, "HdiGetParameter failed");
77 portInfo.bufferCount = portDef_.nBufferCountActual;
78 portInfo.bufferSize = portDef_.nBufferSize;
79 portInfo.enabled = portDef_.bEnabled;
80 return Status::OK;
81 }
82 } // namespace CodecAdapter
83 } // namespace Plugin
84 } // namespace Media
85 } // namespace OHOS
86 #endif