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