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