• 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_LPCM_ENCODER_H_
13 #define CLI_LPCM_ENCODER_H_
14 
15 #include <cstdint>
16 #include <memory>
17 #include <vector>
18 
19 #include "absl/status/status.h"
20 #include "iamf/cli/audio_frame_with_data.h"
21 #include "iamf/cli/codec/encoder_base.h"
22 #include "iamf/obu/codec_config.h"
23 #include "iamf/obu/decoder_config/lpcm_decoder_config.h"
24 
25 namespace iamf_tools {
26 
27 class LpcmEncoder : public EncoderBase {
28  public:
LpcmEncoder(const CodecConfigObu & codec_config,int num_channels)29   LpcmEncoder(const CodecConfigObu& codec_config, int num_channels)
30       : EncoderBase(codec_config, num_channels),
31         decoder_config_(std::get<LpcmDecoderConfig>(
32             codec_config.GetCodecConfig().decoder_config)) {}
33 
34   ~LpcmEncoder() override = default;
35 
36  private:
37   /*!\brief Initializes the underlying encoder.
38    *
39    * \return `absl::OkStatus()` on success. A specific status on failure.
40    */
41   absl::Status InitializeEncoder() override;
42 
43   /*!\brief Encodes an audio frame.
44    *
45    * \param input_bit_depth Ignored.
46    * \param samples Samples arranged in (time x channel) axes. The samples are
47    *        left-justified and stored in the upper `input_bit_depth` bits.
48    *
49    * \param partial_audio_frame_with_data Unique pointer to take ownership of.
50    *        The underlying `audio_frame_` is modified. All other fields are
51    *        blindly passed along.
52    * \return `absl::OkStatus()` on success. A specific status on failure.
53    */
54   absl::Status EncodeAudioFrame(
55       int /*input_bit_depth*/, const std::vector<std::vector<int32_t>>& samples,
56       std::unique_ptr<AudioFrameWithData> partial_audio_frame_with_data)
57       override;
58 
59   const LpcmDecoderConfig decoder_config_;
60 };
61 }  // namespace iamf_tools
62 
63 #endif  // CLI_LPCM_ENCODER_H_
64