libflute
File.h
Go to the documentation of this file.
1 // libflute - FLUTE/ALC library
2 //
3 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
4 //
5 // Licensed under the License terms and conditions for use, reproduction, and
6 // distribution of 5G-MAG software (the “License”). You may not use this file
7 // except in compliance with the License. You may obtain a copy of the License at
8 // https://www.5g-mag.com/reference-tools. Unless required by applicable law or
9 // agreed to in writing, software distributed under the License is distributed on
10 // an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 // or implied.
12 //
13 // See the License for the specific language governing permissions and limitations
14 // under the License.
15 //
16 #pragma once
17 #include <stddef.h>
18 #include <stdint.h>
19 #include <map>
20 #include <memory>
21 #include "AlcPacket.h"
22 #include "FileDeliveryTable.h"
23 #include "EncodingSymbol.h"
24 #include "Transmitter.h"
25 
26 namespace LibFlute {
30  class File {
31  public:
38 
44  File(const std::shared_ptr<Transmitter::FileDescription> &file_description);
45 
58  File(uint32_t toi,
60  std::string content_location,
61  std::string content_type,
62  uint64_t expires,
63  char* data,
64  size_t length,
65  bool copy_data = false);
66 
70  virtual ~File();
71 
75  void put_symbol(const EncodingSymbol& symbol);
76 
80  bool complete() const { return _complete; };
81 
85  char* buffer() const { return _buffer; };
86 
90  size_t length() const { return _been_decoded?_meta.content_length:_meta.fec_oti.transfer_length; };
91 
95  void encode();
96 
102  void decode();
103 
107  bool is_encoded() const { return _been_encoded || !_been_decoded; };
108 
112  const FecOti& fec_oti() const { return _meta.fec_oti; };
113 
117  const LibFlute::FileDeliveryTable::FileEntry& meta() const { return _meta; };
118 
122  unsigned long received_at() const { return _received_at; };
123 
127  void log_access() { _access_count++; };
128 
132  unsigned access_count() const { return _access_count; };
133 
137  std::vector<EncodingSymbol> get_next_symbols(size_t max_size);
138 
142  void mark_completed(const std::vector<EncodingSymbol>& symbols, bool success);
143 
147  void set_fdt_instance_id( uint16_t id) { _fdt_instance_id = id; };
148 
152  uint16_t fdt_instance_id() { return _fdt_instance_id; };
153 
154  private:
155  void calculate_partitioning();
156  void create_blocks();
157 
158  struct SourceBlock {
159  bool complete = false;
160  struct Symbol {
161  char* data;
162  size_t length;
163  bool complete = false;
164  bool queued = false;
165  };
166  std::map<uint16_t, Symbol> symbols;
167  };
168 
169  void check_source_block_completion(SourceBlock& block);
170  void check_file_completion();
171 
172  std::map<uint16_t, SourceBlock> _source_blocks;
173 
174  bool _complete = false;;
175 
176  uint32_t _nof_source_symbols = 0;
177  uint32_t _nof_source_blocks = 0;
178  uint32_t _nof_large_source_blocks = 0;
179  uint32_t _large_source_block_length = 0;
180  uint32_t _small_source_block_length = 0;
181 
182  char* _buffer = nullptr;
183  bool _own_buffer = false;
184  bool _been_encoded = false;
185  bool _been_decoded = false;
186 
188  unsigned long _received_at;
189  unsigned _access_count = 0;
190 
191  uint16_t _fdt_instance_id = 0;
192 
193  std::shared_ptr<Transmitter::FileDescription> _file_description;
194  };
195 };
A class for handling FEC encoding symbols.
Represents a file being transmitted or received.
Definition: File.h:30
const FecOti & fec_oti() const
Get the FEC OTI values.
Definition: File.h:112
bool complete() const
Check if the file is complete.
Definition: File.h:80
void put_symbol(const EncodingSymbol &symbol)
Write the data from an encoding symbol into the appropriate place in the buffer.
Definition: File.cpp:142
unsigned access_count() const
Get the access counter value.
Definition: File.h:132
size_t length() const
Get the data buffer length.
Definition: File.h:90
virtual ~File()
Default destructor.
Definition: File.cpp:132
char * buffer() const
Get the data buffer.
Definition: File.h:85
void encode()
Encode the buffer using the Content-Encoding.
Definition: File.cpp:274
uint16_t fdt_instance_id()
Get the FDT instance ID.
Definition: File.h:152
File(LibFlute::FileDeliveryTable::FileEntry entry)
Create a file from an FDT entry (used for reception)
Definition: File.cpp:36
void mark_completed(const std::vector< EncodingSymbol > &symbols, bool success)
Mark encoding symbols as completed.
Definition: File.cpp:258
void log_access()
Log access to the file by incrementing a counter.
Definition: File.h:127
void set_fdt_instance_id(uint16_t id)
Set the FDT instance ID.
Definition: File.h:147
std::vector< EncodingSymbol > get_next_symbols(size_t max_size)
Get the next encoding symbols that fit in max_size bytes.
Definition: File.cpp:233
unsigned long received_at() const
Timestamp of file reception.
Definition: File.h:122
void decode()
Decode the buffer using the Content-Encoding.
Definition: File.cpp:329
const LibFlute::FileDeliveryTable::FileEntry & meta() const
Get the file metadata from its FDT entry.
Definition: File.h:117
bool is_encoded() const
Check if the buffer is content encoded.
Definition: File.h:107
OTI values struct.
Definition: flute_types.h:51
uint64_t transfer_length
Definition: flute_types.h:54
An entry for a file in the FDT.