/* * 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 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(); } bool isEncoded() const { return static_cast(*this).isEncodedImpl(); } ManifestEncoder &setType(ManifestType type) { return static_cast(*this).setTypeImpl(type); } ManifestEncoder &setMaxCapacity(uint8_t max_capacity) { return static_cast(*this).setMaxCapacityImpl( max_capacity); } ManifestEncoder &setHashAlgorithm(auth::CryptoHashType hash) { return static_cast(*this).setHashAlgorithmImpl(hash); } ManifestEncoder &setIsLast(bool is_last) { return static_cast(*this).setIsLastImpl(is_last); } template < typename T, typename = std::enable_if_t>, core::Name>::value>> ManifestEncoder &setBaseName(T &&name) { return static_cast(*this).setBaseNameImpl(name); } ManifestEncoder &setParamsBytestream(const ParamsBytestream ¶ms) { return static_cast(*this).setParamsBytestreamImpl(params); } ManifestEncoder &setParamsRTC(const ParamsRTC ¶ms) { return static_cast(*this).setParamsRTCImpl(params); } template ManifestEncoder &addEntry(uint32_t suffix, Hash &&hash) { return static_cast(*this).addEntryImpl( suffix, std::forward(hash)); } ManifestEncoder &removeEntry(uint32_t suffix) { return static_cast(*this).removeEntryImpl(suffix); } std::size_t manifestHeaderSize() const { return static_cast(*this).manifestHeaderSizeImpl(); } std::size_t manifestPayloadSize(size_t additional_entries = 0) const { return static_cast(*this).manifestPayloadSizeImpl( additional_entries); } std::size_t manifestSize(size_t additional_entries = 0) const { return static_cast(*this).manifestSizeImpl( additional_entries); } }; template class ManifestDecoder { public: virtual ~ManifestDecoder() = default; ManifestDecoder &decode() { return static_cast(*this).decodeImpl(); } ManifestDecoder &clear() { return static_cast(*this).clearImpl(); } bool isDecoded() const { return static_cast(*this).isDecodedImpl(); } ManifestType getType() const { return static_cast(*this).getTypeImpl(); } interface::ProductionProtocolAlgorithms getTransportType() const { return static_cast(*this).getTransportTypeImpl(); } uint8_t getMaxCapacity() const { return static_cast(*this).getMaxCapacityImpl(); } auth::CryptoHashType getHashAlgorithm() const { return static_cast(*this).getHashAlgorithmImpl(); } bool getIsLast() const { return static_cast(*this).getIsLastImpl(); } core::Name getBaseName() const { return static_cast(*this).getBaseNameImpl(); } ParamsBytestream getParamsBytestream() const { return static_cast(*this).getParamsBytestreamImpl(); } ParamsRTC getParamsRTC() const { return static_cast(*this).getParamsRTCImpl(); } auto getEntries() const { return static_cast(*this).getEntriesImpl(); } std::size_t manifestHeaderSize() const { return static_cast(*this).manifestHeaderSizeImpl(); } std::size_t manifestPayloadSize(size_t additional_entries = 0) const { return static_cast(*this).manifestPayloadSizeImpl( additional_entries); } std::size_t manifestSize(size_t additional_entries = 0) const { return static_cast(*this).manifestSizeImpl( additional_entries); } }; } // namespace core } // namespace transport