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