| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_FORMATS_BMFF_OFFSET_ADJUSTMENT_H_ | |
| #define THIRD_PARTY_CREDENTIO_FORMATS_BMFF_OFFSET_ADJUSTMENT_H_ | |
| #include <cstdint> | |
| #include <vector> | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "formats/bmff/box_header.h" | |
| #include "riegeli/bytes/reader.h" | |
| #include "riegeli/bytes/writer.h" | |
| namespace credentio { | |
| struct IlocExtent { | |
| uint64_t index = 0; | |
| uint64_t offset = 0; | |
| uint64_t length = 0; | |
| }; | |
| struct IlocItem { | |
| uint32_t item_id = 0; | |
| uint16_t construction_method = 0; // Present if version 1 or 2 | |
| uint16_t data_reference_index = 0; | |
| uint64_t base_offset = 0; | |
| std::vector<IlocExtent> extents; | |
| }; | |
| struct IlocBox { | |
| uint8_t offset_size = 0; | |
| uint8_t length_size = 0; | |
| uint8_t base_offset_size = 0; | |
| uint8_t index_size = 0; | |
| std::vector<IlocItem> items; | |
| }; | |
| struct StcoBox { | |
| std::vector<uint32_t> offsets; | |
| }; | |
| struct Co64Box { | |
| std::vector<uint64_t> offsets; | |
| }; | |
| struct SaioBox { | |
| uint32_t aux_info_type = 0; | |
| uint32_t aux_info_type_parameter = 0; | |
| std::vector<uint64_t> offsets; | |
| }; | |
| // Parses the ILOC box payload from the reader. | |
| // The reader should be positioned at the start of the box payload (after the | |
| // header). | |
| absl::StatusOr<IlocBox> ParseIloc(riegeli::Reader& reader, | |
| const BmffBoxHeader& header); | |
| // Serializes the ILOC box payload to the writer. | |
| absl::Status SerializeIloc(const IlocBox& box, const BmffBoxHeader& header, | |
| riegeli::Writer& writer); | |
| // Adjusts the offsets in the ILOC box. | |
| // Only extents with data_reference_index == 0 are adjusted. | |
| void AdjustOffsets(IlocBox& box, int64_t adjustment); | |
| // Parses the STCO box payload from the reader. | |
| absl::StatusOr<StcoBox> ParseStco(riegeli::Reader& reader); | |
| // Serializes the STCO box payload to the writer. | |
| absl::Status SerializeStco(const StcoBox& box, riegeli::Writer& writer); | |
| // Adjusts the offsets in the STCO box. | |
| void AdjustOffsets(StcoBox& box, int64_t adjustment); | |
| // Parses the CO64 box payload from the reader. | |
| absl::StatusOr<Co64Box> ParseCo64(riegeli::Reader& reader); | |
| // Serializes the CO64 box payload to the writer. | |
| absl::Status SerializeCo64(const Co64Box& box, riegeli::Writer& writer); | |
| // Adjusts the offsets in the CO64 box. | |
| void AdjustOffsets(Co64Box& box, int64_t adjustment); | |
| // Parses the SAIO box payload from the reader. | |
| absl::StatusOr<SaioBox> ParseSaio(riegeli::Reader& reader, | |
| const BmffBoxHeader& header); | |
| // Serializes the SAIO box payload to the writer. | |
| absl::Status SerializeSaio(const SaioBox& box, const BmffBoxHeader& header, | |
| riegeli::Writer& writer); | |
| // Adjusts the offsets in the SAIO box. | |
| void AdjustOffsets(SaioBox& box, int64_t adjustment); | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_BMFF_OFFSET_ADJUSTMENT_H_ |