• 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 #include "iamf/cli/renderer/audio_element_renderer_base.h"
13 
14 #include <cstddef>
15 #include <vector>
16 
17 #include "absl/log/check.h"
18 #include "absl/status/status.h"
19 #include "absl/synchronization/mutex.h"
20 #include "absl/types/span.h"
21 #include "iamf/cli/demixing_module.h"
22 #include "iamf/cli/renderer/renderer_utils.h"
23 #include "iamf/common/utils/macros.h"
24 #include "iamf/obu/types.h"
25 
26 namespace iamf_tools {
27 
~AudioElementRendererBase()28 AudioElementRendererBase::~AudioElementRendererBase() {}
29 
RenderLabeledFrame(const LabeledFrame & labeled_frame)30 absl::StatusOr<size_t> AudioElementRendererBase::RenderLabeledFrame(
31     const LabeledFrame& labeled_frame) {
32   absl::MutexLock lock(&mutex_);
33 
34   size_t num_valid_samples = 0;
35   RETURN_IF_NOT_OK(iamf_tools::renderer_utils::ArrangeSamplesToRender(
36       labeled_frame, ordered_labels_, samples_to_render_, num_valid_samples));
37 
38   // Render samples in concrete subclasses.
39   current_labeled_frame_ = &labeled_frame;
40 
41   std::vector<InternalSampleType> rendered_samples(
42       num_output_channels_ * num_valid_samples, 0);
43   RETURN_IF_NOT_OK(RenderSamples(
44       absl::MakeConstSpan(samples_to_render_).first(num_valid_samples),
45       rendered_samples));
46 
47   // Copy rendered samples to the output.
48   rendered_samples_.insert(rendered_samples_.end(), rendered_samples.begin(),
49                            rendered_samples.end());
50 
51   return num_valid_samples;
52 }
53 
Flush(std::vector<InternalSampleType> & rendered_samples)54 absl::Status AudioElementRendererBase::Flush(
55     std::vector<InternalSampleType>& rendered_samples) {
56   absl::MutexLock lock(&mutex_);
57   rendered_samples.insert(rendered_samples.end(), rendered_samples_.begin(),
58                           rendered_samples_.end());
59   rendered_samples_.clear();
60   return absl::OkStatus();
61 }
62 
63 }  // namespace iamf_tools
64