• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 3-Clause Clear License
5  * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6  * License was not distributed with this source code in the LICENSE file, you
7  * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the
8  * Alliance for Open Media Patent License 1.0 was not distributed with this
9  * source code in the PATENTS file, you can obtain it at
10  * www.aomedia.org/license/patent.
11  */
12 #ifndef CLI_OPUS_ENCODER_DECODER_H_
13 #define CLI_OPUS_ENCODER_DECODER_H_
14 
15 #include <cstdint>
16 #include <vector>
17 
18 #include "absl/status/status.h"
19 #include "iamf/cli/codec/decoder_base.h"
20 #include "iamf/obu/codec_config.h"
21 #include "iamf/obu/decoder_config/opus_decoder_config.h"
22 #include "include/opus.h"
23 
24 namespace iamf_tools {
25 
26 class OpusDecoder : public DecoderBase {
27  public:
28   /*!\brief Constructor
29    *
30    * \param codec_config_obu Codec Config OBU with initialization settings.
31    * \param num_channels Number of channels for this stream.
32    */
33   OpusDecoder(const CodecConfigObu& codec_config_obu, int num_channels);
34 
35   /*!\brief Destructor
36    */
37   ~OpusDecoder() override;
38 
39   /*!\brief Initializes the underlying decoder.
40    *
41    * \return `absl::OkStatus()` on success. A specific status on failure.
42    */
43   absl::Status Initialize() override;
44 
45   /*!\brief Decodes an Opus audio frame.
46    *
47    * \param encoded_frame Frame to decode.
48    * \return `absl::OkStatus()` on success. A specific status on failure.
49    */
50   absl::Status DecodeAudioFrame(
51       const std::vector<uint8_t>& encoded_frame) override;
52 
53  private:
54   // The decoder from `libopus` is in the global namespace.
55   typedef ::OpusDecoder LibOpusDecoder;
56 
57   const OpusDecoderConfig& opus_decoder_config_;
58   const uint32_t output_sample_rate_;
59 
60   LibOpusDecoder* decoder_ = nullptr;
61 };
62 
63 }  // namespace iamf_tools
64 
65 #endif  // CLI_OPUS_ENCODER_DECODER_H_
66