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 #include "iamf/cli/codec/encoder_base.h"
13
14 #include <cstdint>
15 #include <vector>
16
17 #include "absl/log/log.h"
18 #include "absl/status/status.h"
19 #include "absl/strings/str_cat.h"
20 #include "iamf/common/utils/macros.h"
21
22 namespace iamf_tools {
23
~EncoderBase()24 EncoderBase::~EncoderBase() {}
25
Initialize(bool validate_codec_delay)26 absl::Status EncoderBase::Initialize(bool validate_codec_delay) {
27 RETURN_IF_NOT_OK(InitializeEncoder());
28
29 // Some encoders depend on `InitializeEncoder` being called before
30 // `SetNumberOfSamplesToDelayAtStart`.
31 RETURN_IF_NOT_OK(SetNumberOfSamplesToDelayAtStart(validate_codec_delay));
32 return absl::OkStatus();
33 }
34
ValidateInputSamples(const std::vector<std::vector<int32_t>> & samples) const35 absl::Status EncoderBase::ValidateInputSamples(
36 const std::vector<std::vector<int32_t>>& samples) const {
37 if (samples.size() != num_samples_per_frame_) {
38 auto error_message = absl::StrCat("Found ", samples.size(),
39 " samples per channels. Expected ",
40 num_samples_per_frame_, ".");
41 return absl::InvalidArgumentError(error_message);
42 }
43 if (samples.empty()) {
44 return absl::InvalidArgumentError("samples cannot be empty.");
45 }
46 if (samples[0].size() != num_channels_) {
47 auto error_message =
48 absl::StrCat("Found ", samples[0].size(), " channels. Expected ",
49 num_channels_, ".");
50 return absl::InvalidArgumentError(error_message);
51 }
52
53 return absl::OkStatus();
54 }
55
56 } // namespace iamf_tools
57