Skip to content

Commit

Permalink
Add MixPresentationObu::CreateFromBuffer.
Browse files Browse the repository at this point in the history
This function will call a private explicit constructor which uses defaults to create an instance of the class. It will then call ValidateAndReadPayload, which will read from the provided buffer and fill in the appropriate fields within the AudioElementObu instance. This call must succeed - if it does not, we will return an error status which will signal to the caller that we were not able to read the OBU properly.

This function will be called in ProcessDescriptorObus.

PiperOrigin-RevId: 627764777
  • Loading branch information
Googler authored and jwcullen committed Apr 24, 2024
1 parent 57d8168 commit 15c626e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions iamf/obu/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ cc_library(
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
],
)
Expand Down
8 changes: 8 additions & 0 deletions iamf/obu/mix_presentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "iamf/common/read_bit_buffer.h"
#include "iamf/common/write_bit_buffer.h"
#include "iamf/obu/leb128.h"
#include "iamf/obu/obu_header.h"
#include "iamf/obu/param_definitions.h"

namespace iamf_tools {
Expand Down Expand Up @@ -308,6 +309,13 @@ absl::Status MixPresentationObu::ValidateAndWritePayload(
return absl::OkStatus();
}

absl::StatusOr<MixPresentationObu> MixPresentationObu::CreateFromBuffer(
const ObuHeader& header, ReadBitBuffer& rb) {
MixPresentationObu mix_presentation_obu(header);
RETURN_IF_NOT_OK(mix_presentation_obu.ValidateAndReadPayload(rb));
return mix_presentation_obu;
}

absl::Status MixPresentationObu::ValidateAndReadPayload(ReadBitBuffer& rb) {
return absl::UnimplementedError(
"MixPresentationObu ValidateAndReadPayload not yet implemented.");
Expand Down
24 changes: 24 additions & 0 deletions iamf/obu/mix_presentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "iamf/common/read_bit_buffer.h"
#include "iamf/common/write_bit_buffer.h"
#include "iamf/obu/leb128.h"
Expand Down Expand Up @@ -338,6 +339,20 @@ class MixPresentationObu : public ObuBase {
num_sub_mixes_(num_sub_mixes),
sub_mixes_(std::move(sub_mixes)) {}

/*!\brief Creates a `MixPresentationObu` from a `ReadBitBuffer`.
*
* This function is designed to be used from the perspective of the decoder.
* It will call `ValidateAndReadPayload` in order to read from the buffer;
* therefore it can fail.
*
* \param header `ObuHeader` of the OBU.
* \param rb `ReadBitBuffer` where the `MixPresentationObu` data is stored.
* Data read from the buffer is consumed.
* \return an `MixPresentationObu` on success. A specific status on failure.
*/
static absl::StatusOr<MixPresentationObu> CreateFromBuffer(
const ObuHeader& header, ReadBitBuffer& rb);

/*!\brief Move Constructor. */
MixPresentationObu(MixPresentationObu&& other) = default;

Expand Down Expand Up @@ -365,6 +380,15 @@ class MixPresentationObu : public ObuBase {
std::vector<MixPresentationSubMix> sub_mixes_;

private:
// Used only by the factory create function.
explicit MixPresentationObu(const ObuHeader& header)
: ObuBase(header, kObuIaAudioElement),
mix_presentation_id_(DecodedUleb128()),
count_label_(DecodedUleb128()),
language_labels_({}),
mix_presentation_annotations_({}),
num_sub_mixes_(DecodedUleb128()),
sub_mixes_({}) {}
/*\!brief Writes the OBU payload to the buffer.
*
* \param wb Buffer to write to.
Expand Down
1 change: 1 addition & 0 deletions iamf/obu/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ cc_test(
deps = [
":obu_test_base",
"//iamf/cli:leb_generator",
"//iamf/common:read_bit_buffer",
"//iamf/common:write_bit_buffer",
"//iamf/obu:leb128",
"//iamf/obu:mix_presentation",
Expand Down
10 changes: 10 additions & 0 deletions iamf/obu/tests/mix_presentation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "absl/status/status.h"
#include "gtest/gtest.h"
#include "iamf/cli/leb_generator.h"
#include "iamf/common/read_bit_buffer.h"
#include "iamf/common/write_bit_buffer.h"
#include "iamf/obu/leb128.h"
#include "iamf/obu/obu_header.h"
Expand Down Expand Up @@ -870,5 +871,14 @@ TEST_F(GetNumChannelsFromLayoutTest, ErrorBeyondReservedSoundSystem) {
.ok());
}

// --- Begin CreateFromBuffer tests ---
// TODO(b/329706068): Update test once ValidateAndReadPayload is implemented.
TEST(CreateFromBuffer, IsNotSupported) {
std::vector<uint8_t> source;
ReadBitBuffer buffer(1024, &source);
ObuHeader header;
EXPECT_FALSE(MixPresentationObu::CreateFromBuffer(header, buffer).ok());
}

} // namespace
} // namespace iamf_tools

0 comments on commit 15c626e

Please sign in to comment.