/* * Copyright (c) 2021 Cisco and/or its affiliates. * 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: * * http://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. */ #pragma once #include #include #include #include #include #include #include namespace transport { namespace core { enum class ManifestVersion : uint8_t { VERSION_1 = 1, }; enum class ManifestType : uint8_t { INLINE_MANIFEST = 1, FINAL_CHUNK_NUMBER = 2, FLIC_MANIFEST = 3, }; struct ParamsRTC { std::uint64_t timestamp; std::uint32_t prod_rate; std::uint32_t prod_seg; protocol::fec::FECType fec_type; bool operator==(const ParamsRTC &other) const { return (timestamp == other.timestamp && prod_rate == other.prod_rate && prod_seg == other.prod_seg && fec_type == other.fec_type); } }; struct ParamsBytestream { std::uint32_t final_segment; bool operator==(const ParamsBytestream &other) const { return (final_segment == other.final_segment); } }; template struct format_traits { using Encoder = typename T::Encoder; using Decoder = typename T::Decoder; using Hash = typename T::Hash; using HashType = typename T::HashType; using Suffix = typename T::Suffix; using SuffixList = typename T::SuffixList; }; class Packet; template class ManifestEncoder { public: virtual ~ManifestEncoder() = default; ManifestEncoder encode() { return static_cast(*this).encodeImpl(); } ManifestEncoder &clear() { return static_cast(*this).clearImpl(); } ManifestEncoder &setType(ManifestType type) { return static_cast(*this).setTypeImpl(type); } ManifestEncoder &setHashAlgorithm(auth::CryptoHashType hash) { return static_cast(*this).setHashAlgorithmImpl(hash); } template < typename T, typename = std::enable_if_t>, core::Name>::value>> ManifestEncoder &setBaseName(T &&name) { return static_cast(*this).setBaseNameImpl(name); } template ManifestEncoder &addSuffixAndHash(uint32_t suffix, Hash &&hash) { return static_cast(*this).addSuffixAndHashImpl( suffix, std::forward(hash)); } ManifestEncoder &setIsLast(bool is_last) { return static_cast(*this).setIsLastImpl(is_last); } ManifestEncoder &setVersion(ManifestVersion version) { return static_cast(*this).setVersionImpl(version); } std::size_t estimateSerializedLength(std::size_t number_of_entries) { return static_cast(*this).estimateSerializedLengthImpl( number_of_entries); } ManifestEncoder &update() { return static_cast(*this).updateImpl(); } ManifestEncoder &setParamsBytestream(const ParamsBytestream ¶ms) { return static_cast(*this).setParamsBytestreamImpl(params); } ManifestEncoder &setParamsRTC(const ParamsRTC ¶ms) { return static_cast(*this).setParamsRTCImpl(params); } static std::size_t manifestHeaderSize( interface::ProductionProtocolAlgorithms transport_type = interface::ProductionProtocolAlgorithms::UNKNOWN) { return Implementation::manifestHeaderSizeImpl(transport_type); } static std::size_t manifestEntrySize() { return Implementation::manifestEntrySizeImpl(); } }; template class ManifestDecoder { public: virtual ~ManifestDecoder() = default; ManifestDecoder &clear() { return static_cast(*this).clearImpl(); } void decode() { static_cast(*this).decodeImpl(); } ManifestType getType() const { return static_cast(*this).getTypeImpl(); } interface::ProductionProtocolAlgorithms getTransportType() const { return static_cast(*this).getTransportTypeImpl(); } auth::CryptoHashType getHashAlgorithm() const { return static_cast(*this).getHashAlgorithmImpl(); } core::Name getBaseName() const { return static_cast(*this).getBaseNameImpl(); } auto getSuffixHashList() { return static_cast(*this).getSuffixHashListImpl(); } bool getIsLast() const { return static_cast(*this).getIsLastImpl(); } ManifestVersion getVersion() const { return static_cast(*this).getVersionImpl(); } std::size_t estimateSerializedLength(std::size_t number_of_entries) const { return static_cast(*this) .estimateSerializedLengthImpl(number_of_entries); } ParamsBytestream getParamsBytestream() const { return static_cast(*this).getParamsBytestreamImpl(); } ParamsRTC getParamsRTC() const { return static_cast(*this).getParamsRTCImpl(); } }; } // namespace core } // namespace transport