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