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 #include "encode_video_callback.h"
16 
17 #include "distributed_hardware_log.h"
18 
19 namespace OHOS {
20 namespace DistributedHardware {
OnError(MediaAVCodec::AVCodecErrorType errorType,int32_t errorCode)21 void EncodeVideoCallback::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode)
22 {
23     DHLOGD("EncodeVideoCallback : OnError. Error type: %{public}d. Error code: %{public}d ", errorType, errorCode);
24     std::shared_ptr<EncodeDataProcess> targetEncoderNode = encodeVideoNode_.lock();
25     CHECK_AND_RETURN_LOG(targetEncoderNode == nullptr, "%{public}s", "encodeVideoNode_ is nullptr.");
26     targetEncoderNode->OnError();
27 }
28 
OnInputBufferAvailable(uint32_t index,std::shared_ptr<Media::AVSharedMemory> buffer)29 void EncodeVideoCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr<Media::AVSharedMemory> buffer)
30 {
31     DHLOGD("EncodeVideoCallback : OnInputBufferAvailable. No operation when using surface input.");
32     std::shared_ptr<EncodeDataProcess> targetEncoderNode = encodeVideoNode_.lock();
33     if (targetEncoderNode == nullptr) {
34         DHLOGE("encodeVideoNode_ is nullptr.");
35         return;
36     }
37     targetEncoderNode->OnInputBufferAvailable(index, buffer);
38 }
39 
OnOutputFormatChanged(const Media::Format & format)40 void EncodeVideoCallback::OnOutputFormatChanged(const Media::Format &format)
41 {
42     DHLOGD("EncodeVideoCallback : OnOutputFormatChanged.");
43     std::shared_ptr<EncodeDataProcess> targetEncoderNode = encodeVideoNode_.lock();
44     if (targetEncoderNode == nullptr) {
45         DHLOGE("encodeVideoNode_ is nullptr.");
46         return;
47     }
48     targetEncoderNode->OnOutputFormatChanged(format);
49 }
50 
OnOutputBufferAvailable(uint32_t index,MediaAVCodec::AVCodecBufferInfo info,MediaAVCodec::AVCodecBufferFlag flag,std::shared_ptr<Media::AVSharedMemory> buffer)51 void EncodeVideoCallback::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info,
52     MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr<Media::AVSharedMemory> buffer)
53 {
54     DHLOGD("EncodeVideoCallback : OnOutputBufferAvailable.");
55     std::shared_ptr<EncodeDataProcess> targetEncoderNode = encodeVideoNode_.lock();
56     if (targetEncoderNode == nullptr) {
57         DHLOGE("encodeVideoNode_ is nullptr.");
58         return;
59     }
60     targetEncoderNode->OnOutputBufferAvailable(index, info, flag, buffer);
61 }
62 } // namespace DistributedHardware
63 } // namespace OHOS
64