• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_G711_CODEC_H
17 #define OHOS_SHARING_AUDIO_G711_CODEC_H
18 
19 #include "audio_decoder.h"
20 #include "audio_encoder.h"
21 #include "media_frame_pipeline.h"
22 
23 namespace OHOS {
24 namespace Sharing {
25 enum G711_TYPE { G711_ALAW, G711_ULAW };
26 
27 class AudioG711Encoder : public AudioEncoder {
28 public:
29     AudioG711Encoder(G711_TYPE type);
30     ~AudioG711Encoder();
31 
32     int Init(uint32_t channels = 2, uint32_t sampleBit = 16, uint32_t sampleRate = 44100) override;
33     void OnFrame(const Frame::Ptr &frame) override;
34 
35 private:
36     int Encode(int16_t *decoded, int nSamples, uint8_t *encoded);
37 
38 private:
39     std::vector<uint8_t> outBuffer_;
40 
41     G711_TYPE type_;
42 };
43 
44 class AudioG711Decoder : public AudioDecoder {
45 public:
46     AudioG711Decoder(G711_TYPE type);
47     ~AudioG711Decoder();
48 
49     int Init() override;
50     void OnFrame(const Frame::Ptr &frame) override;
51 
52 private:
53     int Decode(uint8_t *encoded, int nSamples, int16_t *decoded);
54 
55 private:
56     std::vector<uint8_t> outBuffer_;
57 
58     G711_TYPE type_ = G711_ALAW;
59 };
60 } // namespace Sharing
61 } // namespace OHOS
62 #endif