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