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 "image_encoder_callback.h"
17 
18 #include "dscreen_log.h"
19 #include "image_source_encoder.h"
20 
21 namespace OHOS {
22 namespace DistributedHardware {
OnError(MediaAVCodec::AVCodecErrorType errorType,int32_t errorCode)23 void ImageEncoderCallback::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode)
24 {
25     DHLOGD("%{public}s: OnError.", DSCREEN_LOG_TAG);
26     std::shared_ptr<ImageSourceEncoder> encoder = videoEncoder_.lock();
27     if (encoder == nullptr) {
28         DHLOGE("encoder is nullptr.");
29         return;
30     }
31     encoder->OnError(errorType, errorCode);
32 }
33 
OnOutputBufferAvailable(uint32_t index,MediaAVCodec::AVCodecBufferInfo info,MediaAVCodec::AVCodecBufferFlag flag,std::shared_ptr<Media::AVSharedMemory> buffer)34 void ImageEncoderCallback::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info,
35     MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr<Media::AVSharedMemory> buffer)
36 {
37     DHLOGD("%{public}s: OnOutputBufferAvailable.", DSCREEN_LOG_TAG);
38     std::shared_ptr<ImageSourceEncoder> encoder = videoEncoder_.lock();
39     if (encoder == nullptr) {
40         DHLOGE("encoder is nullptr.");
41         return;
42     }
43     encoder->OnOutputBufferAvailable(index, info, flag, buffer);
44 }
45 
OnInputBufferAvailable(uint32_t index,std::shared_ptr<Media::AVSharedMemory> buffer)46 void ImageEncoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr<Media::AVSharedMemory> buffer)
47 {
48     DHLOGD("%{public}s: OnInputBufferAvailable.", DSCREEN_LOG_TAG);
49     std::shared_ptr<ImageSourceEncoder> encoder = videoEncoder_.lock();
50     if (encoder == nullptr) {
51         DHLOGE("encoder is nullptr.");
52         return;
53     }
54     encoder->OnInputBufferAvailable(index, buffer);
55 }
56 
OnOutputFormatChanged(const Media::Format & format)57 void ImageEncoderCallback::OnOutputFormatChanged(const Media::Format &format)
58 {
59     DHLOGD("%{public}s: OnOutputFormatChanged.", DSCREEN_LOG_TAG);
60     std::shared_ptr<ImageSourceEncoder> encoder = videoEncoder_.lock();
61     if (encoder == nullptr) {
62         DHLOGE("encoder is nullptr.");
63         return;
64     }
65     encoder->OnOutputFormatChanged(format);
66 }
67 } // namespace DistributedHardware
68 } // namespace OHOS