diff --git a/iamf/obu/arbitrary_obu.cc b/iamf/obu/arbitrary_obu.cc index b2543ef9..d21fe7cb 100644 --- a/iamf/obu/arbitrary_obu.cc +++ b/iamf/obu/arbitrary_obu.cc @@ -43,9 +43,9 @@ absl::Status ArbitraryObu::ValidateAndWritePayload(WriteBitBuffer& wb) const { : absl::OkStatus(); } -absl::Status ArbitraryObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status ArbitraryObu::ReadAndValidatePayload(ReadBitBuffer& rb) { return absl::UnimplementedError( - "ArbitraryOBU ValidateAndReadPayload not yet implemented."); + "ArbitraryOBU ReadAndValidatePayload not yet implemented."); } void ArbitraryObu::PrintObu() const { diff --git a/iamf/obu/arbitrary_obu.h b/iamf/obu/arbitrary_obu.h index 69d5f80d..197ee8d6 100644 --- a/iamf/obu/arbitrary_obu.h +++ b/iamf/obu/arbitrary_obu.h @@ -115,7 +115,7 @@ class ArbitraryObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/audio_element.cc b/iamf/obu/audio_element.cc index 23df8809..7178826d 100644 --- a/iamf/obu/audio_element.cc +++ b/iamf/obu/audio_element.cc @@ -217,7 +217,7 @@ absl::Status ValidateAndWriteScalableChannelLayout( } // Reads the `ScalableChannelLayoutConfig` of an `AudioElementObu`. -absl::Status ValidateAndReadScalableChannelLayout( +absl::Status ReadAndValidateScalableChannelLayout( ScalableChannelLayoutConfig& layout, const DecodedUleb128 num_substreams, ReadBitBuffer& rb) { // Read the main portion of the `ScalableChannelLayoutConfig`. @@ -573,7 +573,7 @@ AudioElementObu::AudioElementObu(const ObuHeader& header, absl::StatusOr AudioElementObu::CreateFromBuffer( const ObuHeader& header, ReadBitBuffer& rb) { AudioElementObu audio_element_obu(header); - RETURN_IF_NOT_OK(audio_element_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(audio_element_obu.ReadAndValidatePayload(rb)); return audio_element_obu; } @@ -788,7 +788,7 @@ absl::Status AudioElementObu::ValidateAndWritePayload( return absl::OkStatus(); } -absl::Status AudioElementObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status AudioElementObu::ReadAndValidatePayload(ReadBitBuffer& rb) { RETURN_IF_NOT_OK(rb.ReadULeb128(audio_element_id_)); uint8_t audio_element_type; RETURN_IF_NOT_OK(rb.ReadUnsignedLiteral(3, audio_element_type)); @@ -822,7 +822,7 @@ absl::Status AudioElementObu::ValidateAndReadPayload(ReadBitBuffer& rb) { switch (audio_element_type_) { case kAudioElementChannelBased: config_ = ScalableChannelLayoutConfig(); - return ValidateAndReadScalableChannelLayout( + return ReadAndValidateScalableChannelLayout( std::get(config_), num_substreams_, rb); case kAudioElementSceneBased: config_ = AmbisonicsConfig(); diff --git a/iamf/obu/audio_element.h b/iamf/obu/audio_element.h index eed30f94..ab92dd3c 100644 --- a/iamf/obu/audio_element.h +++ b/iamf/obu/audio_element.h @@ -243,7 +243,7 @@ class AudioElementObu : public ObuBase { /*!\brief Creates a `AudioElementObu` 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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -383,7 +383,7 @@ class AudioElementObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/audio_frame.cc b/iamf/obu/audio_frame.cc index 60b53782..7cfe718e 100644 --- a/iamf/obu/audio_frame.cc +++ b/iamf/obu/audio_frame.cc @@ -52,7 +52,7 @@ absl::StatusOr AudioFrameObu::CreateFromBuffer( ReadBitBuffer& rb) { AudioFrameObu audio_frame_obu(header); audio_frame_obu.payload_serialized_size_ = obu_payload_serialized_size; - RETURN_IF_NOT_OK(audio_frame_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(audio_frame_obu.ReadAndValidatePayload(rb)); return audio_frame_obu; } @@ -67,7 +67,7 @@ absl::Status AudioFrameObu::ValidateAndWritePayload(WriteBitBuffer& wb) const { return absl::OkStatus(); } -absl::Status AudioFrameObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status AudioFrameObu::ReadAndValidatePayload(ReadBitBuffer& rb) { int8_t encoded_uleb128_size = 0; if (header_.obu_type == kObuIaAudioFrame) { // The ID is explicitly in the bitstream when `kObuIaAudioFrame`. Otherwise diff --git a/iamf/obu/audio_frame.h b/iamf/obu/audio_frame.h index 0561eeec..b2fe7782 100644 --- a/iamf/obu/audio_frame.h +++ b/iamf/obu/audio_frame.h @@ -41,7 +41,7 @@ class AudioFrameObu : public ObuBase { /*!\brief Creates an `AudioFrameObu` 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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -107,7 +107,7 @@ class AudioFrameObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/codec_config.cc b/iamf/obu/codec_config.cc index 9276dbd7..2326e03c 100644 --- a/iamf/obu/codec_config.cc +++ b/iamf/obu/codec_config.cc @@ -108,7 +108,7 @@ CodecConfigObu::CodecConfigObu(const ObuHeader& header, absl::StatusOr CodecConfigObu::CreateFromBuffer( const ObuHeader& header, ReadBitBuffer& rb) { CodecConfigObu codec_config_obu(header); - RETURN_IF_NOT_OK(codec_config_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(codec_config_obu.ReadAndValidatePayload(rb)); RETURN_IF_NOT_OK(codec_config_obu.Initialize()); return codec_config_obu; } @@ -161,7 +161,7 @@ absl::Status CodecConfigObu::ValidateAndWritePayload(WriteBitBuffer& wb) const { return absl::OkStatus(); } -absl::Status CodecConfigObu::ValidateAndReadDecoderConfig(ReadBitBuffer& rb) { +absl::Status CodecConfigObu::ReadAndValidateDecoderConfig(ReadBitBuffer& rb) { const int16_t audio_roll_distance = codec_config_.audio_roll_distance; const uint32_t num_samples_per_frame = codec_config_.num_samples_per_frame; // Read the `decoder_config` struct portion. This is codec specific. @@ -169,7 +169,7 @@ absl::Status CodecConfigObu::ValidateAndReadDecoderConfig(ReadBitBuffer& rb) { using enum CodecConfig::CodecId; case kCodecIdOpus: return std::get(codec_config_.decoder_config) - .ValidateAndRead(num_samples_per_frame, audio_roll_distance, rb); + .ReadAndValidate(num_samples_per_frame, audio_roll_distance, rb); case kCodecIdLpcm: LpcmDecoderConfig lpcm_decoder_config; RETURN_IF_NOT_OK( @@ -187,7 +187,7 @@ absl::Status CodecConfigObu::ValidateAndReadDecoderConfig(ReadBitBuffer& rb) { return absl::OkStatus(); } -absl::Status CodecConfigObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status CodecConfigObu::ReadAndValidatePayload(ReadBitBuffer& rb) { RETURN_IF_NOT_OK(rb.ReadULeb128(codec_config_id_)); uint64_t codec_id; RETURN_IF_NOT_OK(rb.ReadUnsignedLiteral(32, codec_id)); @@ -198,7 +198,7 @@ absl::Status CodecConfigObu::ValidateAndReadPayload(ReadBitBuffer& rb) { RETURN_IF_NOT_OK(rb.ReadSigned16(codec_config_.audio_roll_distance)); // Read the `decoder_config_`. This is codec specific. - RETURN_IF_NOT_OK(ValidateAndReadDecoderConfig(rb)); + RETURN_IF_NOT_OK(ReadAndValidateDecoderConfig(rb)); return absl::OkStatus(); } diff --git a/iamf/obu/codec_config.h b/iamf/obu/codec_config.h index c5485b08..8f2c16f9 100644 --- a/iamf/obu/codec_config.h +++ b/iamf/obu/codec_config.h @@ -70,7 +70,7 @@ class CodecConfigObu : public ObuBase { /*!\brief Creates a `CodecConfigObu` 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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -115,7 +115,7 @@ class CodecConfigObu : public ObuBase { * \param rb Buffer to read from. * \return `absl::OkStatus()` on success. A specific status on failure. */ - absl::Status ValidateAndReadDecoderConfig(ReadBitBuffer& rb); + absl::Status ReadAndValidateDecoderConfig(ReadBitBuffer& rb); /*!\brief Gets the output sample rate associated with the OBU. * @@ -199,7 +199,7 @@ class CodecConfigObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/decoder_config/opus_decoder_config.cc b/iamf/obu/decoder_config/opus_decoder_config.cc index fd5fab3d..9c089f65 100644 --- a/iamf/obu/decoder_config/opus_decoder_config.cc +++ b/iamf/obu/decoder_config/opus_decoder_config.cc @@ -114,7 +114,7 @@ absl::Status OpusDecoderConfig::ValidateAndWrite(uint32_t num_samples_per_frame, return absl::OkStatus(); } -absl::Status OpusDecoderConfig::ValidateAndRead(uint32_t num_samples_per_frame, +absl::Status OpusDecoderConfig::ReadAndValidate(uint32_t num_samples_per_frame, int16_t audio_roll_distance, ReadBitBuffer& rb) { RETURN_IF_NOT_OK( diff --git a/iamf/obu/decoder_config/opus_decoder_config.h b/iamf/obu/decoder_config/opus_decoder_config.h index 581b231d..a584702c 100644 --- a/iamf/obu/decoder_config/opus_decoder_config.h +++ b/iamf/obu/decoder_config/opus_decoder_config.h @@ -65,7 +65,7 @@ class OpusDecoderConfig { * \return `absl::OkStatus()` if the decoder config is valid. A specific error * code on failure. */ - absl::Status ValidateAndRead(uint32_t num_samples_per_frame, + absl::Status ReadAndValidate(uint32_t num_samples_per_frame, int16_t audio_roll_distance, ReadBitBuffer& rb); /*!\brief Gets the output sample rate represented within the decoder config. diff --git a/iamf/obu/decoder_config/tests/opus_decoder_config_test.cc b/iamf/obu/decoder_config/tests/opus_decoder_config_test.cc index c6cc26ac..7ec25de5 100644 --- a/iamf/obu/decoder_config/tests/opus_decoder_config_test.cc +++ b/iamf/obu/decoder_config/tests/opus_decoder_config_test.cc @@ -272,9 +272,9 @@ TEST_F(OpusTest, IllegalMappingFamilyNotZero) { TestWriteDecoderConfig(); } -// --- Begin ValidateAndRead Tests --- +// --- Begin ReadAndValidate Tests --- -TEST(ValidateAndRead, VaryAllLegalFields) { +TEST(ReadAndValidate, VaryAllLegalFields) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -291,7 +291,7 @@ TEST(ValidateAndRead, VaryAllLegalFields) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); @@ -300,7 +300,7 @@ TEST(ValidateAndRead, VaryAllLegalFields) { EXPECT_EQ(opus_decoder_config.input_sample_rate_, 4); } -TEST(ValidateAndRead, MaxAllLegalFields) { +TEST(ReadAndValidate, MaxAllLegalFields) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -317,7 +317,7 @@ TEST(ValidateAndRead, MaxAllLegalFields) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); @@ -326,7 +326,7 @@ TEST(ValidateAndRead, MaxAllLegalFields) { EXPECT_EQ(opus_decoder_config.input_sample_rate_, 0xffffffff); } -TEST(ValidateAndRead, MinorVersion) { +TEST(ReadAndValidate, MinorVersion) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -343,14 +343,14 @@ TEST(ValidateAndRead, MinorVersion) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); EXPECT_EQ(opus_decoder_config.version_, 2); } -TEST(ValidateAndRead, IllegalVersionZero) { +TEST(ReadAndValidate, IllegalVersionZero) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -368,12 +368,12 @@ TEST(ValidateAndRead, IllegalVersionZero) { OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); EXPECT_FALSE(opus_decoder_config - .ValidateAndRead(num_samples_per_frame, audio_roll_distance, + .ReadAndValidate(num_samples_per_frame, audio_roll_distance, read_buffer) .ok()); } -TEST(ValidateAndRead, IllegalVersionFuture) { +TEST(ReadAndValidate, IllegalVersionFuture) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -391,12 +391,12 @@ TEST(ValidateAndRead, IllegalVersionFuture) { OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); EXPECT_FALSE(opus_decoder_config - .ValidateAndRead(num_samples_per_frame, audio_roll_distance, + .ReadAndValidate(num_samples_per_frame, audio_roll_distance, read_buffer) .ok()); } -TEST(ValidateAndRead, IllegalVersionmax) { +TEST(ReadAndValidate, IllegalVersionmax) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -414,12 +414,12 @@ TEST(ValidateAndRead, IllegalVersionmax) { OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); EXPECT_FALSE(opus_decoder_config - .ValidateAndRead(num_samples_per_frame, audio_roll_distance, + .ReadAndValidate(num_samples_per_frame, audio_roll_distance, read_buffer) .ok()); } -TEST(ValidateAndRead, IllegalChannelCountZero) { +TEST(ReadAndValidate, IllegalChannelCountZero) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -437,12 +437,12 @@ TEST(ValidateAndRead, IllegalChannelCountZero) { OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); EXPECT_FALSE(opus_decoder_config - .ValidateAndRead(num_samples_per_frame, audio_roll_distance, + .ReadAndValidate(num_samples_per_frame, audio_roll_distance, read_buffer) .ok()); } -TEST(ValidateAndRead, ReadPreSkip312) { +TEST(ReadAndValidate, ReadPreSkip312) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -459,7 +459,7 @@ TEST(ValidateAndRead, ReadPreSkip312) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); @@ -467,7 +467,7 @@ TEST(ValidateAndRead, ReadPreSkip312) { EXPECT_EQ(opus_decoder_config.pre_skip_, 312); } -TEST(ValidateAndRead, ReadSampleRate48kHz) { +TEST(ReadAndValidate, ReadSampleRate48kHz) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -484,7 +484,7 @@ TEST(ValidateAndRead, ReadSampleRate48kHz) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); @@ -492,7 +492,7 @@ TEST(ValidateAndRead, ReadSampleRate48kHz) { EXPECT_EQ(opus_decoder_config.input_sample_rate_, 48000); } -TEST(ValidateAndRead, ReadSampleRate192kHz) { +TEST(ReadAndValidate, ReadSampleRate192kHz) { OpusDecoderConfig opus_decoder_config; uint32_t num_samples_per_frame = 960; int16_t audio_roll_distance = -4; @@ -509,7 +509,7 @@ TEST(ValidateAndRead, ReadSampleRate192kHz) { // `mapping_family`. OpusDecoderConfig::kMappingFamily}; ReadBitBuffer read_buffer(1024, &source); - EXPECT_THAT(opus_decoder_config.ValidateAndRead( + EXPECT_THAT(opus_decoder_config.ReadAndValidate( num_samples_per_frame, audio_roll_distance, read_buffer), IsOk()); diff --git a/iamf/obu/ia_sequence_header.cc b/iamf/obu/ia_sequence_header.cc index 041715ed..48dd4f3b 100644 --- a/iamf/obu/ia_sequence_header.cc +++ b/iamf/obu/ia_sequence_header.cc @@ -52,7 +52,7 @@ absl::Status IASequenceHeaderObu::Validate() const { absl::StatusOr IASequenceHeaderObu::CreateFromBuffer( const ObuHeader& header, ReadBitBuffer& rb) { IASequenceHeaderObu ia_sequence_header_obu(header); - RETURN_IF_NOT_OK(ia_sequence_header_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(ia_sequence_header_obu.ReadAndValidatePayload(rb)); return ia_sequence_header_obu; } @@ -75,7 +75,7 @@ absl::Status IASequenceHeaderObu::ValidateAndWritePayload( return absl::OkStatus(); } -absl::Status IASequenceHeaderObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status IASequenceHeaderObu::ReadAndValidatePayload(ReadBitBuffer& rb) { RETURN_IF_NOT_OK(rb.ReadUnsignedLiteral(32, ia_code_)); uint8_t primary_profile; RETURN_IF_NOT_OK(rb.ReadUnsignedLiteral(8, primary_profile)); diff --git a/iamf/obu/ia_sequence_header.h b/iamf/obu/ia_sequence_header.h index 236bb48b..1f68f7ff 100644 --- a/iamf/obu/ia_sequence_header.h +++ b/iamf/obu/ia_sequence_header.h @@ -53,7 +53,7 @@ class IASequenceHeaderObu : public ObuBase { /*!\brief Creates a `IASequenceHeaderObu` 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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -119,7 +119,7 @@ class IASequenceHeaderObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/mix_presentation.cc b/iamf/obu/mix_presentation.cc index 845d87b9..0c9541f8 100644 --- a/iamf/obu/mix_presentation.cc +++ b/iamf/obu/mix_presentation.cc @@ -446,11 +446,11 @@ absl::Status MixPresentationObu::ValidateAndWritePayload( absl::StatusOr MixPresentationObu::CreateFromBuffer( const ObuHeader& header, ReadBitBuffer& rb) { MixPresentationObu mix_presentation_obu(header); - RETURN_IF_NOT_OK(mix_presentation_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(mix_presentation_obu.ReadAndValidatePayload(rb)); return mix_presentation_obu; } -absl::Status MixPresentationObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status MixPresentationObu::ReadAndValidatePayload(ReadBitBuffer& rb) { // Read the main portion of the OBU. RETURN_IF_NOT_OK(rb.ReadULeb128(mix_presentation_id_)); RETURN_IF_NOT_OK(rb.ReadULeb128(count_label_)); diff --git a/iamf/obu/mix_presentation.h b/iamf/obu/mix_presentation.h index 4b9b0268..3f979af9 100644 --- a/iamf/obu/mix_presentation.h +++ b/iamf/obu/mix_presentation.h @@ -363,7 +363,7 @@ class MixPresentationObu : public ObuBase { /*!\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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -431,7 +431,7 @@ class MixPresentationObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; }; } // namespace iamf_tools diff --git a/iamf/obu/obu_base.h b/iamf/obu/obu_base.h index ba0fedb0..a04ed4fc 100644 --- a/iamf/obu/obu_base.h +++ b/iamf/obu/obu_base.h @@ -76,7 +76,7 @@ class ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - virtual absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) = 0; + virtual absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) = 0; /*!\brief Prints logging information about the OBU Header. * diff --git a/iamf/obu/obu_header.cc b/iamf/obu/obu_header.cc index aa7e9f39..78d23218 100644 --- a/iamf/obu/obu_header.cc +++ b/iamf/obu/obu_header.cc @@ -232,7 +232,7 @@ absl::Status ObuHeader::ValidateAndWrite(int64_t payload_serialized_size, // instead use `output_obu_type` and `output_payload_serialized_size` as output // parameters. Note that `output_payload_serialized_size` is a derived value // from `obu_size`, as this is the value the caller is more interested in. -absl::Status ObuHeader::ValidateAndRead( +absl::Status ObuHeader::ReadAndValidate( ReadBitBuffer& rb, int64_t& output_payload_serialized_size) { uint64_t obu_type_uint64_t = 0; RETURN_IF_NOT_OK(rb.ReadUnsignedLiteral(5, obu_type_uint64_t)); diff --git a/iamf/obu/obu_header.h b/iamf/obu/obu_header.h index e7f7533e..c4255e6e 100644 --- a/iamf/obu/obu_header.h +++ b/iamf/obu/obu_header.h @@ -87,7 +87,7 @@ struct ObuHeader { * the fields are invalid or set in a manner that is inconsistent with * the IAMF specification. */ - absl::Status ValidateAndRead(ReadBitBuffer& rb, + absl::Status ReadAndValidate(ReadBitBuffer& rb, int64_t& output_payload_serialized_size); /*!\brief Prints logging information about an `ObuHeader`. diff --git a/iamf/obu/parameter_block.cc b/iamf/obu/parameter_block.cc index c1d8282f..ed0f23bc 100644 --- a/iamf/obu/parameter_block.cc +++ b/iamf/obu/parameter_block.cc @@ -265,7 +265,7 @@ absl::StatusOr ParameterBlockObu::CreateFromBuffer( } ParameterBlockObu parameter_block_obu(header, parameter_id, it->second); - RETURN_IF_NOT_OK(parameter_block_obu.ValidateAndReadPayload(rb)); + RETURN_IF_NOT_OK(parameter_block_obu.ReadAndValidatePayload(rb)); return parameter_block_obu; } @@ -642,7 +642,7 @@ absl::Status ParameterBlockObu::ValidateAndWritePayload( return absl::OkStatus(); } -absl::Status ParameterBlockObu::ValidateAndReadPayload(ReadBitBuffer& rb) { +absl::Status ParameterBlockObu::ReadAndValidatePayload(ReadBitBuffer& rb) { // Validate the associated `param_definition`. RETURN_IF_NOT_OK(metadata_.param_definition.Validate()); diff --git a/iamf/obu/parameter_block.h b/iamf/obu/parameter_block.h index 9475cdff..471c610f 100644 --- a/iamf/obu/parameter_block.h +++ b/iamf/obu/parameter_block.h @@ -226,7 +226,7 @@ class ParameterBlockObu : public ObuBase { /*!\brief Creates a `ParameterBlockObu` 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; + * It will call `ReadAndValidatePayload` in order to read from the buffer; * therefore it can fail. * * \param header `ObuHeader` of the OBU. @@ -389,7 +389,7 @@ class ParameterBlockObu : public ObuBase { * \return `absl::OkStatus()` if the payload is valid. A specific status on * failure. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override; + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override; // `duration` and `constant_subblock_duration` are conditionally included // based on `param_definition_mode`. diff --git a/iamf/obu/temporal_delimiter.h b/iamf/obu/temporal_delimiter.h index e39c1d11..970f01aa 100644 --- a/iamf/obu/temporal_delimiter.h +++ b/iamf/obu/temporal_delimiter.h @@ -72,7 +72,7 @@ class TemporalDelimiterObu : public ObuBase { * \param rb Buffer to read from. * \return `absl::OkStatus()` always. */ - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override { + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override { return absl::OkStatus(); }; }; diff --git a/iamf/obu/tests/audio_element_test.cc b/iamf/obu/tests/audio_element_test.cc index fa239a10..ab18ec1f 100644 --- a/iamf/obu/tests/audio_element_test.cc +++ b/iamf/obu/tests/audio_element_test.cc @@ -1407,7 +1407,7 @@ TEST(ReadAudioElementParamTest, ValidDemixingParamDefinition) { DemixingInfoParameterData::kDMixPMode2); } -TEST(AudioElementParam, ValidateAndReadReadsReservedParamDefinition3) { +TEST(AudioElementParam, ReadAndValidateReadsReservedParamDefinition3) { constexpr uint32_t kAudioElementId = 1; constexpr auto kExpectedParamDefinitionType = ParamDefinition::kParameterDefinitionReservedStart; @@ -1435,8 +1435,7 @@ TEST(AudioElementParam, ValidateAndReadReadsReservedParamDefinition3) { } // --- Begin CreateFromBuffer tests --- -// TODO(b/329700768): Update test once ValidateAndReadPayload is implemented. -TEST(CreateFromBuffer, IsNotSupported) { +TEST(CreateFromBuffer, InvalidWhenPayloadIsEmpty) { std::vector source; ReadBitBuffer buffer(1024, &source); ObuHeader header; diff --git a/iamf/obu/tests/obu_base_test.cc b/iamf/obu/tests/obu_base_test.cc index e77f962c..90633b0a 100644 --- a/iamf/obu/tests/obu_base_test.cc +++ b/iamf/obu/tests/obu_base_test.cc @@ -37,7 +37,7 @@ class ImaginaryObuNonIntegerBytes : public ObuBase { return wb.WriteUnsignedLiteral(0, 1); } - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override { + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override { return absl::OkStatus(); } }; @@ -65,7 +65,7 @@ class OneByteObu : public ObuBase { return wb.WriteUnsignedLiteral(255, 8); } - absl::Status ValidateAndReadPayload(ReadBitBuffer& rb) override { + absl::Status ReadAndValidatePayload(ReadBitBuffer& rb) override { return absl::OkStatus(); } }; diff --git a/iamf/obu/tests/obu_header_test.cc b/iamf/obu/tests/obu_header_test.cc index e77027df..0be8259c 100644 --- a/iamf/obu/tests/obu_header_test.cc +++ b/iamf/obu/tests/obu_header_test.cc @@ -509,8 +509,8 @@ TEST_F(ObuHeaderTest, ObuSizeIncludesAllConditionalFields) { TestGenerateAndWrite(); } -// --- Begin ValidateAndRead Tests --- -TEST_F(ObuHeaderTest, ValidateAndReadIncludeAllConditionalFields) { +// --- Begin ReadAndValidate Tests --- +TEST_F(ObuHeaderTest, ReadAndValidateIncludeAllConditionalFields) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -527,7 +527,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIncludeAllConditionalFields) { 100, 101, 102}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -550,7 +550,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIncludeAllConditionalFields) { } } -TEST_F(ObuHeaderTest, ValidateAndReadImplicitAudioFrameId17) { +TEST_F(ObuHeaderTest, ReadAndValidateImplicitAudioFrameId17) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -559,7 +559,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadImplicitAudioFrameId17) { 0x80, 0x08}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -578,7 +578,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadImplicitAudioFrameId17) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderNoConditionalFields) { +TEST_F(ObuHeaderTest, ReadAndValidateIaSequenceHeaderNoConditionalFields) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -587,7 +587,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderNoConditionalFields) { 0x80, 0x08}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -606,7 +606,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderNoConditionalFields) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderRedundantCopy) { +TEST_F(ObuHeaderTest, ReadAndValidateIaSequenceHeaderRedundantCopy) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -615,7 +615,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderRedundantCopy) { 0x80, 0x08}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -634,7 +634,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadIaSequenceHeaderRedundantCopy) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeOneByteLeb128) { +TEST_F(ObuHeaderTest, ReadAndValidateUpperEdgeObuSizeOneByteLeb128) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -643,7 +643,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeOneByteLeb128) { 0x7f}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -662,7 +662,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeOneByteLeb128) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeTwoByteLeb128) { +TEST_F(ObuHeaderTest, ReadAndValidateLowerEdgeObuSizeTwoByteLeb128) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -671,7 +671,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeTwoByteLeb128) { 0x80, 0x01}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -690,7 +690,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeTwoByteLeb128) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeFourByteLeb128) { +TEST_F(ObuHeaderTest, ReadAndValidateUpperEdgeObuSizeFourByteLeb128) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -699,7 +699,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeFourByteLeb128) { 0xff, 0xff, 0xff, 0x7f}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -717,7 +717,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadUpperEdgeObuSizeFourByteLeb128) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeFiveByteLeb128) { +TEST_F(ObuHeaderTest, ReadAndValidateLowerEdgeObuSizeFiveByteLeb128) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -726,7 +726,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeFiveByteLeb128) { 0x80, 0x80, 0x80, 0x80, 0x01}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -744,7 +744,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadLowerEdgeObuSizeFiveByteLeb128) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeFullPayload) { +TEST_F(ObuHeaderTest, ReadAndValidateMaxObuSizeFullPayload) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -753,7 +753,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeFullPayload) { 0xff, 0xff, 0xff, 0xff, 0x0f}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -771,7 +771,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeFullPayload) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeWithMinimalTrim) { +TEST_F(ObuHeaderTest, ReadAndValidateMaxObuSizeWithMinimalTrim) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -784,7 +784,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeWithMinimalTrim) { 0x00}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -804,7 +804,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadMaxObuSizeWithMinimalTrim) { } TEST_F(ObuHeaderTest, - ValidateAndReadIllegalTrimmingStatusFlagIaSequenceHeader) { + ReadAndValidateIllegalTrimmingStatusFlagIaSequenceHeader) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -817,11 +817,11 @@ TEST_F(ObuHeaderTest, 0x00}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_FALSE( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_) + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_) .ok()); } -TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtEnd) { +TEST_F(ObuHeaderTest, ReadAndValidateTrimmingStatusFlagNonZeroTrimAtEnd) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -834,7 +834,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtEnd) { 0x00}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -853,7 +853,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtEnd) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtStart) { +TEST_F(ObuHeaderTest, ReadAndValidateTrimmingStatusFlagNonZeroTrimAtStart) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -866,7 +866,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtStart) { 0x02}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields. @@ -885,7 +885,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroTrimAtStart) { EXPECT_TRUE(obu_header_.extension_header_bytes.empty()); } -TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroBothTrims) { +TEST_F(ObuHeaderTest, ReadAndValidateTrimmingStatusFlagNonZeroBothTrims) { std::vector source_data = { // `obu type`, `obu_redundant_copy`, `obu_trimming_status_flag`, // `obu_extension_flag` @@ -898,7 +898,7 @@ TEST_F(ObuHeaderTest, ValidateAndReadTrimmingStatusFlagNonZeroBothTrims) { 0x02}; ReadBitBuffer read_bit_buffer = ReadBitBuffer(1024, &source_data); EXPECT_THAT( - obu_header_.ValidateAndRead(read_bit_buffer, payload_serialized_size_), + obu_header_.ReadAndValidate(read_bit_buffer, payload_serialized_size_), IsOk()); // Validate all OBU Header fields.