Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
icomposer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_packet/icomposer.h
10 //! @brief Packet composer interface.
11 
12 #ifndef ROC_PACKET_ICOMPOSER_H_
13 #define ROC_PACKET_ICOMPOSER_H_
14 
15 #include "roc_core/slice.h"
16 #include "roc_packet/packet.h"
17 
18 namespace roc {
19 namespace packet {
20 
21 //! Packet composer interface.
22 class IComposer {
23 public:
24  virtual ~IComposer();
25 
26  //! Adjust buffer to align payload.
27  //! @remarks
28  //! Adjusts the given @p buffer so that the payload of the most inner composer
29  //! will have @p payload_alignment. The @p header_size parameter defines the
30  //! total size of all headers before the payload.
31  //! @returns
32  //! true if the buffer was successfully adjusted or false if the @p buffer
33  //! capacity is not enough.
34  virtual bool
35  align(core::Slice<uint8_t>& buffer, size_t header_size, size_t payload_alignment) = 0;
36 
37  //! Prepare buffer for composing a packet.
38  //! @remarks
39  //! Resizes the given @p buffer so that it can fit the @p packet headers and
40  //! payload. If the packet payload contains an inner packet, calls the inner
41  //! composer as well The @p payload_size refers to the payload of the most
42  //! inner packet. Modifies the @p packet so that its payload fields point to
43  //! the appropriate parts of the @p buffer.
44  //! @returns
45  //! true if the packet was successfully prepared or false if the @p buffer
46  //! capacity is not enough.
47  virtual bool
48  prepare(Packet& packet, core::Slice<uint8_t>& buffer, size_t payload_size) = 0;
49 
50  //! Pad packet.
51  //! @remarks
52  //! Cuts from the right the given number of bytes from the packet payload of
53  //! the most inner composer and marks them as padding. The @p padding_size
54  //! parameter should be less than or equal to the packet payload size.
55  //! @returns
56  //! true if the packet was successfully padded or false if parameters
57  //! are invalid or padding is not supported.
58  virtual bool pad(Packet& packet, size_t padding_size) = 0;
59 
60  //! Compose packet to buffer.
61  //! @remarks
62  //! Formats @p packet headers and payloads to the buffer attached to it during
63  //! a previous prepare() call.
64  //! @returns
65  //! true if the packet was successfully composed or false if an error occurred.
66  virtual bool compose(Packet& packet) = 0;
67 };
68 
69 } // namespace packet
70 } // namespace roc
71 
72 #endif // ROC_PACKET_ICOMPOSER_H_
Packet composer interface.
Definition: icomposer.h:22
virtual bool align(core::Slice< uint8_t > &buffer, size_t header_size, size_t payload_alignment)=0
Adjust buffer to align payload.
virtual bool pad(Packet &packet, size_t padding_size)=0
Pad packet.
virtual bool prepare(Packet &packet, core::Slice< uint8_t > &buffer, size_t payload_size)=0
Prepare buffer for composing a packet.
virtual bool compose(Packet &packet)=0
Compose packet to buffer.
Root namespace.
Packet.
Slice.