• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Shenzhen Kaihong DID 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 
16 #include "codec_handle_buffer.h"
17 #include <hdf_base.h>
18 #include <securec.h>
19 #include <unistd.h>
20 #include "codec_log_wrapper.h"
21 #include "v4_0/codec_types.h"
22 using namespace OHOS::HDI::Codec::V4_0;
23 namespace OHOS {
24 namespace Codec {
25 namespace Omx {
26 
UseBuffer(OMX_HANDLETYPE comp,uint32_t portIndex,OmxCodecBuffer & codecBuffer,OMX_BUFFERHEADERTYPE * & header)27 sptr<ICodecBuffer> CodecHandleBuffer::UseBuffer(OMX_HANDLETYPE comp, uint32_t portIndex,
28     OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE *&header)
29 {
30     CHECK_AND_RETURN_RET_LOG(comp != nullptr, nullptr, "null component");
31     CHECK_AND_RETURN_RET_LOG(codecBuffer.bufferhandle != nullptr, nullptr, "null nativebuffer");
32     BufferHandle *bufferHandle = codecBuffer.bufferhandle->GetBufferHandle();
33     CHECK_AND_RETURN_RET_LOG(bufferHandle != nullptr, nullptr, "null bufferhandle");
34 
35     int32_t err = OMX_UseBuffer(comp, &header, portIndex, nullptr, codecBuffer.allocLen,
36         reinterpret_cast<OMX_U8 *>(bufferHandle));
37     if (err != OMX_ErrorNone) {
38         CODEC_LOGE("OMX_UseBuffer ret = [%{public}x]", err);
39         return nullptr;
40     }
41     sptr<HDI::Base::NativeBuffer> nativebuffer = codecBuffer.bufferhandle;
42     codecBuffer.bufferhandle = nullptr;
43     codecBuffer.fd.reset();
44     codecBuffer.fenceFd.reset();
45     return sptr<ICodecBuffer>(new CodecHandleBuffer(InitInfo{comp, portIndex, codecBuffer, header}, nativebuffer));
46 }
47 
FillThisBuffer(OmxCodecBuffer & codecBuffer)48 int32_t CodecHandleBuffer::FillThisBuffer(OmxCodecBuffer &codecBuffer)
49 {
50     if (codecBuffer.fenceFd != nullptr) {
51         auto ret = SyncWait(codecBuffer.fenceFd->Get(), TIME_WAIT_MS);
52         if (ret != EOK) {
53             CODEC_LOGE("SyncWait ret err [%{public}d]", ret);
54         }
55     }
56     return ICodecBuffer::FillThisBuffer(codecBuffer);
57 }
58 
EmptyThisBuffer(OmxCodecBuffer & codecBuffer)59 int32_t CodecHandleBuffer::EmptyThisBuffer(OmxCodecBuffer &codecBuffer)
60 {
61     CODEC_LOGE("bufferHandle is not support in EmptyThisBuffer");
62     (void)codecBuffer;
63     return OMX_ErrorNotImplemented;
64 }
65 
66 }  // namespace Omx
67 }  // namespace Codec
68 }  // namespace OHOS