• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024, 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 
13 #ifndef CLI_CODEC_LPCM_DECODER_H_
14 #define CLI_CODEC_LPCM_DECODER_H_
15 
16 #include <cstdint>
17 #include <vector>
18 
19 #include "absl/status/status.h"
20 #include "iamf/cli/codec/decoder_base.h"
21 #include "iamf/obu/codec_config.h"
22 #include "iamf/obu/decoder_config/lpcm_decoder_config.h"
23 
24 namespace iamf_tools {
25 
26 /*!brief Decoder for LPCM audio streams.
27  *
28  * Class designed to decode one audio substream per instance when the
29  * `codec_config_id` is "ipcm" and formatted as per IAMF Spec §3.5 and §3.11.4.
30  * See https://aomediacodec.github.io/iamf/#lpcm-specific.
31  */
32 class LpcmDecoder : public DecoderBase {
33  public:
34   /*!brief Constructor.
35    *
36    * \param codec_config_obu Codec Config OBU with initialization settings.
37    * \param num_channels Number of channels for this stream.
38    */
39   LpcmDecoder(const CodecConfigObu& codec_config_obu, int num_channels);
40 
41   /*!brief Destructor. */
42   ~LpcmDecoder() override = default;
43 
44   /*!\brief Initializes the underlying decoder.
45    *
46    * \return `absl::OkStatus()` on success. A specific status on failure.
47    */
48   absl::Status Initialize() override;
49 
50   /*!\brief Decodes an LPCM audio frame.
51    *
52    * \param encoded_frame Frame to decode.
53    * \return `absl::OkStatus()` on success. A specific status on failure.
54    */
55   absl::Status DecodeAudioFrame(
56       const std::vector<uint8_t>& encoded_frame) override;
57 
58  private:
59   const LpcmDecoderConfig decoder_config_;
60 
61   // We don't need the audio_roll_distance_ for decoding, but needed to validate
62   // the LpcmDecoderConfig.
63   int16_t audio_roll_distance_;
64 };
65 
66 }  // namespace iamf_tools
67 
68 #endif  // CLI_CODEC_LPCM_DECODER_H_
69