1 /*
2  * Copyright (c) 2024-2024 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 "sample_callback.h"
17 #include "sample_info.h"
18 #include "camera_log.h"
19 
20 namespace OHOS {
21 namespace CameraStandard {
OnCodecError(OH_AVCodec * codec,int32_t errorCode,void * userData)22 void SampleCallback::OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData)
23 {
24     (void)codec;
25     (void)errorCode;
26     (void)userData;
27     MEDIA_ERR_LOG("On decoder error, error code: %{public}d", errorCode);
28 }
29 
OnCodecFormatChange(OH_AVCodec * codec,OH_AVFormat * format,void * userData)30 void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
31 {
32     CHECK_ERROR_RETURN(userData == nullptr);
33     (void)codec;
34     MEDIA_ERR_LOG("OnCodecFormatChange");
35 }
36 
37 
OnNeedInputBuffer(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)38 void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
39 {
40     MEDIA_DEBUG_LOG("OnNeedInputBuffer");
41     CHECK_ERROR_RETURN(userData == nullptr);
42     (void)codec;
43     CodecUserData *codecUserData = static_cast<CodecUserData *>(userData);
44     std::unique_lock<std::mutex> lock(codecUserData->inputMutex_);
45     codecUserData->inputBufferInfoQueue_.emplace(new CodecAVBufferInfo(index, buffer));
46     codecUserData->inputCond_.notify_all();
47 }
48 
OnNewOutputBuffer(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)49 void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
50 {
51     MEDIA_DEBUG_LOG("OnNewOutputBuffer");
52     (void)codec;
53     CHECK_ERROR_RETURN(userData == nullptr);
54     CodecUserData *codecUserData = static_cast<CodecUserData *>(userData);
55     std::unique_lock<std::mutex> lock(codecUserData->outputMutex_);
56     codecUserData->outputBufferInfoQueue_.emplace(new CodecAVBufferInfo(index, buffer));
57     codecUserData->outputCond_.notify_all();
58 }
59 
OnOutputFormatChanged(OH_AVCodec * codec,OH_AVFormat * format,void * userData)60 void SampleCallback::OnOutputFormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
61 {
62     (void)codec;
63     (void)format;
64     (void)userData;
65     MEDIA_DEBUG_LOG("OnOutputFormatChanged received");
66 }
67 
OnInputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)68 void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
69 {
70     CAMERA_SYNC_TRACE;
71     MEDIA_DEBUG_LOG("OnInputBufferAvailable %{public}d", index);
72     CHECK_ERROR_RETURN(userData == nullptr);
73     (void)codec;
74     sptr<CodecUserData> codecAudioData = static_cast<CodecUserData *>(userData);
75     std::unique_lock<std::mutex> lock(codecAudioData->inputMutex_);
76     codecAudioData->inputBufferInfoQueue_.emplace(new CodecAVBufferInfo(index, buffer));
77     codecAudioData->inputCond_.notify_all();
78 }
79 
OnOutputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)80 void SampleCallback::OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
81 {
82     CAMERA_SYNC_TRACE;
83     MEDIA_DEBUG_LOG("OnOutputBufferAvailable");
84     (void)codec;
85     CHECK_ERROR_RETURN(userData == nullptr);
86     sptr<CodecUserData> codecAudioData = static_cast<CodecUserData *>(userData);
87     std::unique_lock<std::mutex> lock(codecAudioData->outputMutex_);
88     codecAudioData->outputBufferInfoQueue_.emplace(new CodecAVBufferInfo(index, buffer));
89     codecAudioData->outputCond_.notify_all();
90 }
91 } // CameraStandard
92 } // OHOS