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 "audio_encoder_callback.h"
17
18 #include "daudio_log.h"
19 #include "audio_event.h"
20
21 #undef DH_LOG_TAG
22 #define DH_LOG_TAG "AudioEncoderCallback"
23
24 namespace OHOS {
25 namespace DistributedHardware {
OnError(Media::AVCodecErrorType errorType,int32_t errorCode)26 void AudioEncoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode)
27 {
28 DHLOGE("On error. Error type: %d, Error code: %d.", errorType, errorCode);
29 std::shared_ptr<AudioEncoder> encObj = audioEncoder_.lock();
30 if (encObj == nullptr) {
31 DHLOGE("Encoder is nullptr.");
32 return;
33 }
34 AudioEvent encoderErr = {AUDIO_ENCODER_ERR, ""};
35 encObj->OnError(encoderErr);
36 }
37
OnInputBufferAvailable(uint32_t index)38 void AudioEncoderCallback::OnInputBufferAvailable(uint32_t index)
39 {
40 DHLOGD("On input buffer available. index %u.", index);
41 std::shared_ptr<AudioEncoder> encObj = audioEncoder_.lock();
42 if (encObj == nullptr) {
43 DHLOGE("Encoder is nullptr.");
44 return;
45 }
46 encObj->OnInputBufferAvailable(index);
47 }
48
OnOutputFormatChanged(const Media::Format & format)49 void AudioEncoderCallback::OnOutputFormatChanged(const Media::Format &format)
50 {
51 DHLOGD("On output format changed.");
52 std::shared_ptr<AudioEncoder> encObj = audioEncoder_.lock();
53 if (encObj == nullptr) {
54 DHLOGE("Encoder is nullptr.");
55 return;
56 }
57 encObj->OnOutputFormatChanged(format);
58 }
59
OnOutputBufferAvailable(uint32_t index,Media::AVCodecBufferInfo info,Media::AVCodecBufferFlag flag)60 void AudioEncoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info,
61 Media::AVCodecBufferFlag flag)
62 {
63 DHLOGD("On output buffer available. index %u.", index);
64 std::shared_ptr<AudioEncoder> encObj = audioEncoder_.lock();
65 if (encObj == nullptr) {
66 DHLOGE("Encoder is nullptr.");
67 return;
68 }
69 encObj->OnOutputBufferAvailable(index, info, flag);
70 }
71 } // namespace DistributedHardware
72 } // namespace OHOS
73