• 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_OBU_SEQUENCER_IAMF_H_
13 #define CLI_OBU_SEQUENCER_IAMF_H_
14 
15 #include <cstdint>
16 #include <fstream>
17 #include <optional>
18 #include <string>
19 
20 #include "absl/status/status.h"
21 #include "absl/types/span.h"
22 #include "iamf/cli/obu_sequencer_base.h"
23 #include "iamf/common/leb_generator.h"
24 #include "iamf/common/write_bit_buffer.h"
25 
26 namespace iamf_tools {
27 
28 /*!\brief OBU sequencer for standalone .iamf files.
29  *
30  * Used via the abstract `ObuSequencerBase` interface.
31  */
32 class ObuSequencerIamf : public ObuSequencerBase {
33  public:
34   /*!\brief Constructor.
35    * \param iamf_filename Name of the output standalone .iamf file or an empty
36    *        string to disable output.
37    * \param include_temporal_delimiters Whether the serialized data should
38    *        include a temporal delimiter.
39    * \param leb_generator Leb generator to use when writing OBUs.
40    */
41   ObuSequencerIamf(const std::string& iamf_filename,
42                    bool include_temporal_delimiters,
43                    const LebGenerator& leb_generator);
44 
45   ~ObuSequencerIamf() override = default;
46 
47  private:
48   /*!\brief Pushes the descriptor OBUs to some output.
49    *
50    * \param common_samples_per_frame Ignored.
51    * \param common_sample_rate Ignored.
52    * \param common_bit_depth Ignored.
53    * \param first_untrimmed_timestamp Ignored.
54    * \param num_channels Ignored..
55    * \param descriptor_obus Serialized descriptor OBUs to write.
56    * \return `absl::OkStatus()` on success. A specific status on failure.
57    */
58   absl::Status PushSerializedDescriptorObus(
59       uint32_t /*common_samples_per_frame*/, uint32_t /*common_sample_rate*/,
60       uint8_t /*common_bit_depth*/,
61       std::optional<int64_t> /*first_untrimmed_timestamp*/,
62       int /*num_channels*/, absl::Span<const uint8_t> descriptor_obus) override;
63 
64   /*!\brief Pushes a single temporal unit to some output.
65    *
66    * \param timestamp Ignored.
67    * \param num_samples Ignored.
68    * \param temporal_unit Temporal unit to push.
69    * \return `absl::OkStatus()` on success. A specific status on failure.
70    */
71   absl::Status PushSerializedTemporalUnit(
72       int64_t /*timestamp*/, int /*num_samples*/,
73       absl::Span<const uint8_t> temporal_unit) override;
74 
75   /*!\brief Pushes the finalized descriptor OBUs to the IAMF file.
76    *
77    * \param descriptor_obus Serialized finalized descriptor OBUs to push.
78    * \return `absl::OkStatus()` on success. A specific status on failure.
79    */
80   absl::Status PushFinalizedDescriptorObus(
81       absl::Span<const uint8_t> descriptor_obus) override;
82 
83   /*!\brief Signals that no more data is coming. */
84   void CloseDerived() override;
85 
86   /*!\brief Aborts writing the output.
87    *
88    * Cleans up the output file if it exists.
89    */
90   void AbortDerived() override;
91 
92   const std::string iamf_filename_;
93   std::optional<std::fstream> output_iamf_;
94   // Reusable write buffer between calls.
95   WriteBitBuffer wb_;
96 };
97 
98 }  // namespace iamf_tools
99 
100 #endif  // CLI_OBU_SEQUENCER_H_
101