• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #ifndef OHOS_SHARING_AUDIO_AAC_CODEC_H
17 #define OHOS_SHARING_AUDIO_AAC_CODEC_H
18 
19 #include <cstdint>
20 #include <string.h>
21 #include "audio_decoder.h"
22 #include "audio_encoder.h"
23 #include "media_frame_pipeline.h"
24 
25 constexpr uint8_t numberOfLayers = 1;
26 constexpr uint8_t minChannelCount = 1;
27 constexpr uint8_t maxChannelCount = 8;
28 constexpr uint32_t maxConfigurationSize = 1024;
29 
30 namespace OHOS {
31 namespace Sharing {
32 
33 class AudioAACDecoder : public AudioDecoder {
34 public:
35     AudioAACDecoder();
36     ~AudioAACDecoder();
37 
38     int32_t Init() override;
39     void OnFrame(const Frame::Ptr &frame) override;
40 
41 private:
42     int32_t Decode(uint8_t *encoded, int32_t nSamples, int16_t *decoded);
43 
44 private:
45     char *outBuffer_ = nullptr;
46     int32_t errorCode_ = 0;
47     uint32_t flags_ = 0;
48     uint32_t channels_ = 2;
49     uint32_t concealMethod_ = 2;
50     uint32_t sampleRate_ = 48000;
51 };
52 
53 class AudioAACEncoder : public AudioEncoder {
54 public:
55     AudioAACEncoder();
56     ~AudioAACEncoder();
57 
58     int32_t Init() override;
59     void OnFrame(const Frame::Ptr &frame) override;
60 
61 private:
62     int32_t Encode(int16_t *decoded, int32_t nSamples, uint8_t *encoded);
63 
64 private:
65     char *outBuffer_ = nullptr;
66     uint32_t flags_ = 0;
67     uint32_t channels_ = 1;
68     uint32_t sampleRate_ = 48000;
69 };
70 
71 } // namespace Sharing
72 } // namespace OHOS
73 #endif
74