• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
16 #include "hdi_codec.h"
17 #include <unordered_map>
18 #include <hdf_base.h>
19 #include "codec_callback_type_stub.h"
20 #include "media_log.h"
21 #include "media_errors.h"
22 #include "hdi_init.h"
23 #include "hdi_codec_util.h"
24 #include "securec.h"
25 #include "media_dfx.h"
26 
27 using namespace std;
28 namespace {
29     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "HdiCodec"};
30     static const std::unordered_map<OMX_EVENTTYPE, std::string> OMX_EVENT_TO_STRING = {
31         {OMX_EventCmdComplete, "OMX_EventCmdComplete"},
32         {OMX_EventError, "OMX_EventError"},
33         {OMX_EventMark, "OMX_EventMark"},
34         {OMX_EventPortSettingsChanged, "OMX_EventPortSettingsChanged"},
35         {OMX_EventBufferFlag, "OMX_EventBufferFlag"},
36         {OMX_EventResourcesAcquired, "OMX_EventResourcesAcquired"},
37         {OMX_EventComponentResumed, "OMX_EventComponentResumed"},
38         {OMX_EventPortFormatDetected, "OMX_EventPortFormatDetected"},
39         {OMX_EventDynamicResourcesAvailable, "OMX_EventDynamicResourcesAvailable"},
40         {OMX_EventVendorStartUnused, "OMX_EventVendorStartUnused"},
41         {OMX_EventMax, "OMX_EventMax"},
42     };
43 }
44 namespace OHOS {
45 namespace Media {
HdiCodec(const string & component)46 HdiCodec::HdiCodec(const string& component)
47     : componentName_(component)
48 {
49     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
50 }
51 
~HdiCodec()52 HdiCodec::~HdiCodec()
53 {
54     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
55     if (handle_) {
56         MEDIA_LOGE("FreeHandle");
57         (void)HdiInit::GetInstance().FreeHandle(handle_, id_);
58     }
59     if (appData_) {
60         delete appData_;
61         appData_ = nullptr;
62     }
63     if (callback_) {
64         CodecCallbackTypeStubRelease(callback_);
65         callback_ = nullptr;
66     }
67 }
68 
InitVersion()69 void HdiCodec::InitVersion()
70 {
71     (void)memset_s(&verInfo_, sizeof(verInfo_), 0, sizeof(verInfo_));
72     auto ret = handle_->GetComponentVersion(handle_, &verInfo_);
73     CHECK_AND_RETURN_LOG(ret == HDF_SUCCESS, "get version failed");
74 }
75 
Init()76 int32_t HdiCodec::Init()
77 {
78     MEDIA_LOGD("Init");
79     callback_ = CodecCallbackTypeStubGetInstance();
80     CHECK_AND_RETURN_RET_LOG(callback_ != nullptr, GST_CODEC_ERROR, "GetCallBack failed");
81     callback_->EventHandler = &HdiCodec::Event;
82     callback_->EmptyBufferDone = &HdiCodec::EmptyBufferDone;
83     callback_->FillBufferDone = &HdiCodec::FillBufferDone;
84     appData_ = new AppData();
85     appData_->instance = weak_from_this();
86     int32_t ret;
87     {
88         MediaTrace trace("HdiCodec::Init");
89         ret = HdiInit::GetInstance().GetHandle(&handle_, id_, componentName_, appData_, callback_);
90         CHECK_AND_RETURN_RET_LOG(ret == HDF_SUCCESS, GST_CODEC_ERROR, "GetHandle failed");
91         CHECK_AND_RETURN_RET_LOG(handle_ != nullptr, GST_CODEC_ERROR, "Handle is nullptr");
92         InitVersion();
93         InitParam(portParam_, verInfo_);
94         ret = HdiGetParameter(handle_, OMX_IndexParamVideoInit, portParam_);
95     }
96     CHECK_AND_RETURN_RET_LOG(ret == HDF_SUCCESS, GST_CODEC_ERROR, "VideoInit failed");
97     inPortIndex_ = portParam_.nStartPortNumber;
98     outPortIndex_ = portParam_.nStartPortNumber + 1;
99     return GST_CODEC_OK;
100 }
101 
Deinit()102 void HdiCodec::Deinit()
103 {
104     MEDIA_LOGD("Deinit");
105     if (curState_ > OMX_StateLoaded) {
106         (void)WaitForState(OMX_StateLoaded);
107     }
108     int32_t ret;
109     {
110         MediaTrace trace("HdiCodec::Deinit");
111         ret = HdiInit::GetInstance().FreeHandle(handle_, id_);
112     }
113     handle_ = nullptr;
114     if (ret != HDF_SUCCESS) {
115         MEDIA_LOGE("hdi freehandle failed");
116     }
117     delete appData_;
118     appData_ = nullptr;
119     CodecCallbackTypeStubRelease(callback_);
120     callback_ = nullptr;
121 }
122 
SetHdiInBufferMgr(shared_ptr<HdiBufferMgr> bufferMgr)123 void HdiCodec::SetHdiInBufferMgr(shared_ptr<HdiBufferMgr> bufferMgr)
124 {
125     inBufferMgr_ = bufferMgr;
126     inBufferMgr_->Init(handle_, inPortIndex_, verInfo_);
127 }
128 
SetHdiOutBufferMgr(shared_ptr<HdiBufferMgr> bufferMgr)129 void HdiCodec::SetHdiOutBufferMgr(shared_ptr<HdiBufferMgr> bufferMgr)
130 {
131     outBufferMgr_ = bufferMgr;
132     outBufferMgr_->Init(handle_, outPortIndex_, verInfo_);
133 }
134 
SetHdiParamsMgr(shared_ptr<HdiParamsMgr> paramsMgr)135 void HdiCodec::SetHdiParamsMgr(shared_ptr<HdiParamsMgr> paramsMgr)
136 {
137     paramsMgr_ = paramsMgr;
138     paramsMgr_->Init(handle_, portParam_, verInfo_);
139 }
140 
SetParameter(GstCodecParamKey key,GstElement * element)141 int32_t HdiCodec::SetParameter(GstCodecParamKey key, GstElement *element)
142 {
143     return paramsMgr_->SetParameter(key, element);
144 }
145 
GetParameter(GstCodecParamKey key,GstElement * element)146 int32_t HdiCodec::GetParameter(GstCodecParamKey key, GstElement *element)
147 {
148     return paramsMgr_->GetParameter(key, element);
149 }
150 
Start()151 int32_t HdiCodec::Start()
152 {
153     MEDIA_LOGD("Start begin");
154     if (curState_ != OMX_StateExecuting) {
155         CHECK_AND_RETURN_RET_LOG(ChangeState(OMX_StateExecuting) == GST_CODEC_OK, GST_CODEC_ERROR, "Change failed");
156         CHECK_AND_RETURN_RET_LOG(WaitForState(OMX_StateExecuting) == GST_CODEC_OK, GST_CODEC_ERROR, "Wait failed");
157     }
158     {
159         MediaTrace trace("HdiCodec::Start");
160         inBufferMgr_->Start();
161         outBufferMgr_->Start();
162     }
163     unique_lock<mutex> lock(mutex_);
164     start_ = true;
165     MEDIA_LOGD("Start end");
166     return GST_CODEC_OK;
167 }
168 
Stop()169 int32_t HdiCodec::Stop()
170 {
171     {
172         MediaTrace trace("HdiCodec::Stop");
173         inBufferMgr_->Stop(false);
174         outBufferMgr_->Stop(false);
175     }
176     if (curState_ == OMX_StateExecuting) {
177         CHECK_AND_RETURN_RET_LOG(ChangeState(OMX_StateIdle) == GST_CODEC_OK, GST_CODEC_ERROR, "ChangeState failed");
178         CHECK_AND_RETURN_RET_LOG(WaitForState(OMX_StateIdle) == GST_CODEC_OK, GST_CODEC_ERROR, "Wait failed");
179     }
180     if (curState_ == OMX_StateIdle) {
181         CHECK_AND_RETURN_RET_LOG(ChangeState(OMX_StateLoaded) == GST_CODEC_OK, GST_CODEC_ERROR, "ChangeState failed");
182     }
183     unique_lock<mutex> lock(mutex_);
184     start_ = false;
185     return GST_CODEC_OK;
186 }
187 
ChangeState(OMX_STATETYPE state)188 int32_t HdiCodec::ChangeState(OMX_STATETYPE state)
189 {
190     MEDIA_LOGD("Change state from %{public}u to %{public}u", targetState_, state);
191     if (targetState_ != state && curState_ != state) {
192         auto ret = HdiSendCommand(handle_, OMX_CommandStateSet, state, 0);
193         CHECK_AND_RETURN_RET_LOG(ret == HDF_SUCCESS, GST_CODEC_ERROR, "HdiSendCommand failed");
194         targetState_ = state;
195     }
196     return GST_CODEC_OK;
197 }
198 
AllocateInputBuffers()199 int32_t HdiCodec::AllocateInputBuffers()
200 {
201     return inBufferMgr_->AllocateBuffers();
202 }
203 
UseInputBuffers(std::vector<GstBuffer * > buffers)204 int32_t HdiCodec::UseInputBuffers(std::vector<GstBuffer*> buffers)
205 {
206     MediaTrace trace("HdiCodec::UseInputBuffers");
207     return inBufferMgr_->UseBuffers(buffers);
208 }
209 
PushInputBuffer(GstBuffer * buffer)210 int32_t HdiCodec::PushInputBuffer(GstBuffer *buffer)
211 {
212     return inBufferMgr_->PushBuffer(buffer);
213 }
214 
PullInputBuffer(GstBuffer ** buffer)215 int32_t HdiCodec::PullInputBuffer(GstBuffer **buffer)
216 {
217     return inBufferMgr_->PullBuffer(buffer);
218 }
219 
Flush(GstCodecDirect direct)220 int32_t HdiCodec::Flush(GstCodecDirect direct)
221 {
222     MEDIA_LOGD("Flush start");
223     if (!start_) {
224         return GST_CODEC_OK;
225     }
226     CHECK_AND_RETURN_RET_LOG(handle_ != nullptr, GST_CODEC_ERROR, "Handle is nullptr");
227     switch (direct) {
228         case GST_CODEC_INPUT:
229             inBufferMgr_->Flush(true);
230             HdiSendCommand(handle_, OMX_CommandFlush, inPortIndex_, 0);
231             break;
232         case GST_CODEC_OUTPUT:
233             outBufferMgr_->Flush(true);
234             HdiSendCommand(handle_, OMX_CommandFlush, outPortIndex_, 0);
235             break;
236         default:
237             inBufferMgr_->Flush(true);
238             outBufferMgr_->Flush(true);
239             HdiSendCommand(handle_, OMX_CommandFlush, -1, 0);
240             break;
241     }
242     inBufferMgr_->WaitFlushed();
243     outBufferMgr_->WaitFlushed();
244     MEDIA_LOGD("Flush end");
245     return GST_CODEC_OK;
246 }
247 
ActiveBufferMgr(GstCodecDirect direct,bool active)248 int32_t HdiCodec::ActiveBufferMgr(GstCodecDirect direct, bool active)
249 {
250     CHECK_AND_RETURN_RET_LOG(handle_ != nullptr, GST_CODEC_ERROR, "Handle is nullptr");
251     int32_t ret = HDF_SUCCESS;
252     if (direct == GST_CODEC_INPUT || direct == GST_CODEC_ALL) {
253         if (active) {
254             ret = HdiSendCommand(handle_, OMX_CommandPortEnable, inPortIndex_, 0);
255             unique_lock<mutex> lock(mutex_);
256             inState_ = ACTIVING;
257         } else {
258             ret = HdiSendCommand(handle_, OMX_CommandPortDisable, inPortIndex_, 0);
259             unique_lock<mutex> lock(mutex_);
260             inState_ = DEACTIVING;
261         }
262     }
263     CHECK_AND_RETURN_RET_LOG(ret == HDF_SUCCESS, GST_CODEC_ERROR, "port change fail");
264     if (direct == GST_CODEC_OUTPUT || direct == GST_CODEC_ALL) {
265         if (active) {
266             ret = HdiSendCommand(handle_, OMX_CommandPortEnable, outPortIndex_, 0);
267             unique_lock<mutex> lock(mutex_);
268             outState_ = ACTIVING;
269         } else {
270             MEDIA_LOGD("OMX_CommandPortDisable out %{public}u", outPortIndex_);
271             ret = HdiSendCommand(handle_, OMX_CommandPortDisable, outPortIndex_, 0);
272             unique_lock<mutex> lock(mutex_);
273             outState_ = DEACTIVING;
274         }
275     }
276     CHECK_AND_RETURN_RET_LOG(ret == HDF_SUCCESS, GST_CODEC_ERROR, "port change fail");
277     return GST_CODEC_OK;
278 }
279 
FreeInputBuffers()280 int32_t HdiCodec::FreeInputBuffers()
281 {
282     CHECK_AND_RETURN_RET_LOG(inBufferMgr_->FreeBuffers() == GST_CODEC_OK, GST_CODEC_ERROR, "Freebuffer fail");
283     if (inState_ == DEACTIVING) {
284         WaitForEvent(OMX_CommandPortDisable);
285     }
286     return GST_CODEC_OK;
287 }
288 
AllocateOutputBuffers()289 int32_t HdiCodec::AllocateOutputBuffers()
290 {
291     if (curState_ < OMX_StateIdle) {
292         CHECK_AND_RETURN_RET_LOG(ChangeState(OMX_StateIdle) == GST_CODEC_OK, GST_CODEC_ERROR, "ChangeState failed");
293         // some omx need input and output allocate or use common
294         CHECK_AND_RETURN_RET_LOG(inBufferMgr_->Preprocessing() == GST_CODEC_OK, GST_CODEC_ERROR, "Allocatebuffer fail");
295     }
296     CHECK_AND_RETURN_RET_LOG(outBufferMgr_->AllocateBuffers() == GST_CODEC_OK, GST_CODEC_ERROR, "Allocatebuffer fail");
297     CHECK_AND_RETURN_RET_LOG(WaitForState(OMX_StateIdle) == GST_CODEC_OK, GST_CODEC_ERROR, "Wait failed");
298     return GST_CODEC_OK;
299 }
300 
UseOutputBuffers(std::vector<GstBuffer * > buffers)301 int32_t HdiCodec::UseOutputBuffers(std::vector<GstBuffer*> buffers)
302 {
303     MEDIA_LOGD("UseOutputBuffers");
304     MediaTrace trace("HdiCodec::UseOutputBuffers");
305     if (curState_ < OMX_StateIdle) {
306         CHECK_AND_RETURN_RET_LOG(ChangeState(OMX_StateIdle) == GST_CODEC_OK,
307             GST_CODEC_ERROR, "ChangeState failed");
308         // m40 need input and output allocate or use common
309         CHECK_AND_RETURN_RET_LOG(inBufferMgr_->Preprocessing() == GST_CODEC_OK,
310             GST_CODEC_ERROR, "Allocatebuffer fail");
311         CHECK_AND_RETURN_RET_LOG(outBufferMgr_->UseBuffers(buffers) == GST_CODEC_OK,
312             GST_CODEC_ERROR, "UseBuffers fail");
313         CHECK_AND_RETURN_RET_LOG(WaitForState(OMX_StateIdle) == GST_CODEC_OK,
314             GST_CODEC_ERROR, "Wait failed");
315     } else if (outState_ == ACTIVING) {
316         CHECK_AND_RETURN_RET_LOG(outBufferMgr_->UseBuffers(buffers) == GST_CODEC_OK,
317             GST_CODEC_ERROR, "Usebuffer fail");
318         WaitForEvent(OMX_CommandPortEnable);
319     }
320     return GST_CODEC_OK;
321 }
322 
PushOutputBuffer(GstBuffer * buffer)323 int32_t HdiCodec::PushOutputBuffer(GstBuffer *buffer)
324 {
325     return outBufferMgr_->PushBuffer(buffer);
326 }
327 
PullOutputBuffer(GstBuffer ** buffer)328 int32_t HdiCodec::PullOutputBuffer(GstBuffer **buffer)
329 {
330     int32_t ret = GST_CODEC_OK;
331     {
332         unique_lock<mutex> lock(mutex_);
333         if (ret_ != GST_CODEC_OK) {
334             MEDIA_LOGD("change ret from ret %{public}d to ret %{public}d", ret, ret_);
335             ret = ret_;
336             ret_ = GST_CODEC_OK;
337             return ret;
338         }
339     }
340     ret = outBufferMgr_->PullBuffer(buffer);
341     MEDIA_LOGD("ret %{public}d", ret);
342     {
343         unique_lock<mutex> lock(mutex_);
344         if (ret_ != GST_CODEC_OK) {
345             MEDIA_LOGD("change ret from ret %{public}d to ret %{public}d", ret, ret_);
346             ret = ret_;
347             ret_ = GST_CODEC_OK;
348             return ret;
349         }
350     }
351     return ret;
352 }
353 
FreeOutputBuffers()354 int32_t HdiCodec::FreeOutputBuffers()
355 {
356     MEDIA_LOGD("FreeOutputBuffers");
357     CHECK_AND_RETURN_RET_LOG(outBufferMgr_->FreeBuffers() == GST_CODEC_OK, GST_CODEC_ERROR, "Freebuffers fail");
358     if (outState_ == DEACTIVING) {
359         WaitForEvent(OMX_CommandPortDisable);
360     }
361     return GST_CODEC_OK;
362 }
363 
Event(CodecCallbackType * self,OMX_EVENTTYPE event,EventInfo * info)364 int32_t HdiCodec::Event(CodecCallbackType *self, OMX_EVENTTYPE event, EventInfo *info)
365 {
366     (void)self;
367     CHECK_AND_RETURN_RET_LOG(info != nullptr, HDF_ERR_INVALID_PARAM, "appData is null");
368     if (OMX_EVENT_TO_STRING.find(event) != OMX_EVENT_TO_STRING.end()) {
369         MEDIA_LOGD("Event %{public}s %{public}d data1 %{public}d data2 %{public}d",
370             OMX_EVENT_TO_STRING.at(event).c_str(), event, info->data1, info->data2);
371     } else {
372         MEDIA_LOGW("Unknown event %{public}d data1 %{public}d data2 %{public}d",
373             event, info->data1, info->data2);
374     }
375     AppData *mAppData = reinterpret_cast<AppData *>(info->appData);
376     auto instance = mAppData->instance.lock();
377     CHECK_AND_RETURN_RET_LOG(instance != nullptr, HDF_ERR_INVALID_PARAM, "HdiCodec is null");
378     switch (event) {
379         case OMX_EventCmdComplete:
380             instance->HandelEventCmdComplete(info->data1, info->data2);
381             break;
382         case OMX_EventPortSettingsChanged:
383             instance->HandleEventPortSettingsChanged(info->data1, info->data2);
384             break;
385         case OMX_EventBufferFlag:
386             instance->HandleEventBufferFlag(info->data1, info->data2);
387             break;
388         case OMX_EventError:
389             instance->HandleEventError(info->data1);
390             break;
391         default:
392             break;
393     }
394     return HDF_SUCCESS;
395 }
396 
WaitForState(OMX_STATETYPE state)397 int32_t HdiCodec::WaitForState(OMX_STATETYPE state)
398 {
399     WaitForEvent(OMX_CommandStateSet);
400     if (curState_ != state) {
401         MEDIA_LOGW("Wait state failed");
402         return GST_CODEC_ERROR;
403     }
404     return GST_CODEC_OK;
405 }
406 
WaitForEvent(OMX_U32 cmd)407 void HdiCodec::WaitForEvent(OMX_U32 cmd)
408 {
409     unique_lock<mutex> lock(mutex_);
410     int32_t newCmd = static_cast<int32_t>(cmd);
411     MEDIA_LOGD("wait eventdone %{public}d lastcmd %{public}d cmd %{public}u", eventDone_, lastCmd_, cmd);
412     static constexpr int32_t timeout = 2;
413     cond_.wait_for(lock, std::chrono::seconds(timeout),
414         [this, &newCmd]() { return eventDone_ && (lastCmd_ == newCmd || lastCmd_ == -1); });
415     eventDone_ = false;
416 }
417 
HandelEventStateSet(OMX_U32 data)418 void HdiCodec::HandelEventStateSet(OMX_U32 data)
419 {
420     MEDIA_LOGD("change curState_ from %{public}u to %{public}u", curState_, data);
421     curState_ = static_cast<OMX_STATETYPE>(data);
422     eventDone_ = true;
423 }
424 
HandelEventFlush(OMX_U32 data)425 void HdiCodec::HandelEventFlush(OMX_U32 data)
426 {
427     if (data == inPortIndex_) {
428         inBufferMgr_->Flush(false);
429     } else {
430         outBufferMgr_->Flush(false);
431     }
432 }
433 
HandelEventPortDisable(OMX_U32 data)434 void HdiCodec::HandelEventPortDisable(OMX_U32 data)
435 {
436     if (data == inPortIndex_) {
437         inState_ = DEACTIVATED;
438     } else {
439         outState_ = DEACTIVATED;
440     }
441     eventDone_ = true;
442 }
443 
HandelEventPortEnable(OMX_U32 data)444 void HdiCodec::HandelEventPortEnable(OMX_U32 data)
445 {
446     if (data == inPortIndex_) {
447         inState_ = ACTIVATED;
448     } else {
449         outState_ = ACTIVATED;
450     }
451     eventDone_ = true;
452 }
453 
HandelEventCmdComplete(OMX_U32 data1,OMX_U32 data2)454 void HdiCodec::HandelEventCmdComplete(OMX_U32 data1, OMX_U32 data2)
455 {
456     unique_lock<mutex> lock(mutex_);
457     lastCmd_ = (int32_t)data1;
458     switch (data1) {
459         case OMX_CommandStateSet:
460             HandelEventStateSet(data2);
461             break;
462         case OMX_CommandFlush:
463             HandelEventFlush(data2);
464             break;
465         case OMX_CommandPortDisable:
466             HandelEventPortDisable(data2);
467             break;
468         case OMX_CommandPortEnable:
469             HandelEventPortEnable(data2);
470             break;
471         default:
472             break;
473     }
474     cond_.notify_all();
475 }
476 
HandleEventPortSettingsChanged(OMX_U32 data1,OMX_U32 data2)477 void HdiCodec::HandleEventPortSettingsChanged(OMX_U32 data1, OMX_U32 data2)
478 {
479     MEDIA_LOGD("handle change");
480     unique_lock<mutex> lock(mutex_);
481     if (data2 == OMX_IndexParamPortDefinition) {
482         MEDIA_LOGD("GST_CODEC_FORMAT_CHANGE");
483         ret_ = GST_CODEC_FORMAT_CHANGE;
484         if (data1 == inPortIndex_) {
485             inBufferMgr_->Stop(true);
486         } else {
487             outBufferMgr_->Stop(true);
488         }
489     } else if (data2 == OMX_IndexConfigCommonOutputCrop) {
490         needCrop_ = true;
491     }
492     MEDIA_LOGD("handle change end");
493 }
494 
HandleEventBufferFlag(OMX_U32 data1,OMX_U32 data2)495 void HdiCodec::HandleEventBufferFlag(OMX_U32 data1, OMX_U32 data2)
496 {
497     unique_lock<mutex> lock(mutex_);
498     if (data1 == 1 && (data2 & OMX_BUFFERFLAG_EOS)) {
499         MEDIA_LOGD("it is eos, wait buffer eos");
500     }
501 }
502 
HandleEventError(OMX_U32 data)503 void HdiCodec::HandleEventError(OMX_U32 data)
504 {
505     (void)data;
506     unique_lock<mutex> lock(mutex_);
507     ret_ = GST_CODEC_ERROR;
508     eventDone_ = true;
509     lastCmd_ = -1;
510     cond_.notify_all();
511 }
512 
EmptyBufferDone(CodecCallbackType * self,int64_t appData,const OmxCodecBuffer * buffer)513 int32_t HdiCodec::EmptyBufferDone(CodecCallbackType *self, int64_t appData, const OmxCodecBuffer *buffer)
514 {
515     MEDIA_LOGD("EmptyBufferDone");
516     (void)self;
517     AppData *mAppData = reinterpret_cast<AppData *>(appData);
518     CHECK_AND_RETURN_RET_LOG(mAppData != nullptr, HDF_ERR_INVALID_PARAM, "appData is null");
519     auto instance = mAppData->instance.lock();
520     CHECK_AND_RETURN_RET_LOG(instance != nullptr, HDF_ERR_INVALID_PARAM, "HdiCodec is null");
521     if (instance->inBufferMgr_->CodecBufferAvailable(buffer) != GST_CODEC_OK) {
522         MEDIA_LOGE("empty buffer done failed");
523         return OMX_ErrorBadParameter;
524     }
525     return HDF_SUCCESS;
526 }
527 
FillBufferDone(CodecCallbackType * self,int64_t appData,const OmxCodecBuffer * buffer)528 int32_t HdiCodec::FillBufferDone(CodecCallbackType *self, int64_t appData, const OmxCodecBuffer *buffer)
529 {
530     MEDIA_LOGD("FillBufferDone");
531     (void)self;
532     AppData *mAppData = reinterpret_cast<AppData *>(appData);
533     CHECK_AND_RETURN_RET_LOG(mAppData != nullptr, OMX_ErrorBadParameter, "appData is null");
534     auto instance = mAppData->instance.lock();
535     CHECK_AND_RETURN_RET_LOG(instance != nullptr, OMX_ErrorBadParameter, "HdiCodec is null");
536     if (instance->outBufferMgr_->CodecBufferAvailable(buffer) != GST_CODEC_OK) {
537         MEDIA_LOGE("fill buffer done failed");
538         return OMX_ErrorBadParameter;
539     }
540     return HDF_SUCCESS;
541 }
542 }  // namespace Media
543 }  // namespace OHOS
544