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