diff --git a/LICENSE.md b/LICENSE.md index b622626..2c6d711 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,25 +1,26 @@ -The MIT License (MIT) -===================== +BSD 2-clause license +==================== -Copyright © 2022 Lynne +Copyright © 2023, Lynne +All rights reserved. -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index f219713..a3665b1 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,33 @@ -AVTransport -=========== + +# AVTransport This repository hosts the AVTransport container/media transmission protocol, and the reference implementation code. Currently, the protocol is a draft, and its syntax is subject to change. You can read the current rendered draft by opening the [autogenerated webpage](https://cyanreg.github.io/avtransport/). -Links -===== +## Provisional information + +### URI Scheme +The URI scheme shall be `avt://[@]
[:]`. If `port` is not specified, the default port of `8212` shall be used. +If `transport` is not specified, the *udp* transport method shall be assumed. `transport` can be `udp`, `udplite` or `quic`. +Alternatively, for UDP-only, the `udp://
:` URI scheme can be used, at the risk of conflict with other protocols (`MPEG-TS`). + +### File extension +The `.at` or `.avt` file extensions shall be used. + +## Links You can talk about the project and get in touch with developers on: - IRC: **`#avtransport`** on the [Libera.Chat](ircs://irc.libera.chat:6697) network - [Libera.Chat’s guide on how to connect](https://libera.chat/guides/connect) - Or use the [Kiwi web client](https://kiwiirc.com/nextclient/irc.libera.chat/?#avtransport) -# Feature comparison between protocols and containers +## License +The [specifications document)(draft-avtransport-spec.bs), and generated [HTML](https://cyanreg.github.io/avtransport/) are licensed under the **MIT-Zero** license. + +The reference software (`libavtransport`) is licensed under the [**BSD 2-clause license**](LICENSE.md), in order to permit embedding, and free creation of alternative implementations. + +## Feature comparison between protocols and containers - Streamable - whether a protocol can be reliably streamed * AVTransport: Yes. As both a protocol and a container, it can be direcly streamed over networks, pipes, packets, or serial links. diff --git a/draft-avtransport-spec.bs b/draft-avtransport-spec.bs index fc59d49..70c681e 100644 --- a/draft-avtransport-spec.bs +++ b/draft-avtransport-spec.bs @@ -146,11 +146,11 @@ As a simple example, a possible structure of packets in a general AVTransport se ## Packet descriptor ## {#packet-descriptor} -Each packet MUST be prefixed with a 2-bytes descriptor to identify it. +Each packet must be prefixed with a 2-bytes descriptor to identify it. Below is a table of how they're allocated:
- +
@@ -164,27 +164,31 @@ Below is a table of how they're allocated: - + + + + + - + - + - + @@ -196,32 +200,32 @@ Below is a table of how they're allocated: - + - + + + + + - + - + - - - - - + @@ -238,6 +242,11 @@ Below is a table of how they're allocated:
Descriptor values Packet[[#stream-registration-packets]]
''0x0003'' to ''0x0007''[''0x0003'':''0x0005''] [[#stream-configuration-packets]]
''0x0008'' [[#video-information-packets]]
[''0x00A'':''0x000C''][[#metadata-packets]]
''0x0051'' [[#index-packets]]
''0x0010'' to ''0x0014''[''0x0010'':''0x0012''] [[#lut-icc-profile-packets]]
''0x0020'' to ''0x0024''[''0x0020'':''0x0023''] [[#font-data-packets]]
''0x0030'' to ''0x0031''[''0x0030'':''0x0031''] [[#fec-grouping-packets]]
[[#stream-duration-packets]]
''0x00FE'' to ''0x00FF''''0x00FE'' [[#stream-data-parity-packets]]
''0x0100'' to ''0x01FF''''0x00FF''[[#stream-data-segment-packets]]
[''0x0100'':''0x01FF''] [[#stream-data-packets]]
''0x0300'' to ''0x03FF''''0x0300'' [[#time-synchronization-packets]]
''0x0500'' to ''0x0602''[''0x0600'':''0x0602''] [[#user-data-packets]]
''0x0FFF'' [[#end-of-stream-packets]]
''0x8000'' to ''0x80FF''Reserved for [[#reverse-signalling]]
''0xF001''[[#control-data-packets]][[#session-control-data-packets]]
''0xF002''
+Note: range ''0x8000'' to ''0x80FF'' is reserved for [[#reverse-signalling]]. + +Note: the 16-bit descriptor may be split into two sections, a constant upper 8-bits +and variable bottom 8-bits, hence some descriptors are considered a range. + Anything not specified in the table is reserved and must not be used. Future additions will require a version bump of the protocol. @@ -350,7 +359,7 @@ Implementations should use the derived [=ts_clock_freq=] field from [[#time-synchronization-packets]] packets to perform jitter compensation of stream timestamps. -The ts_clock_id is a unique 8-bit identifier for the clock. +The [=ts_clock_id=] is a unique 8-bit identifier for the clock. It allows to associate a clock with a given stream. The [=ts_clock_id=]of the [[#stream-registration-packets]] packets @@ -482,61 +491,61 @@ as an AVTransport session. The syntax is as follows: Data Description - + b(16) - session_descriptor + session_start_descriptor ''0x4156'' Indicates this is a AVTransport session (`AV`). - + b(16) - session_version + session_version ''0x5430'' Indicates the session version. This document describes version `21552` (`T0`). - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + b(8) session_flags enum {{SessionFlags}} Session flags. - + b(8) - producer_name_len + producer_name_len Length of the string in [=producer_name=]. Must be less than or equal to 12. - - b(96) + + 12*b(8) producer_name zero-terminated string - 12-byte [[RFC3629|UTF-8]] string, containing the name of the producer. + 12-byte [[RFC3629|UTF-8]] zero-terminated string, containing the name of the producer. - + u(16) - producer_major + producer_major Major version of the producer. - + u(16) - producer_minor + producer_minor Minor version of the producer. - + u(16) - producer_micro + producer_micro Micro version of the producer. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] @@ -552,8 +561,8 @@ bytewise-identical. The [=session_flags=] field must be interpreted in the following way: -
- : SESSION_REVERSE_SIGNAL_READY = 0x1 +
+ : SESSION_REVERSE_SIGNAL_READY = 0x1 :: Indicates session is capable and ready to receive [[#reverse-signalling]] packets.
@@ -580,10 +589,16 @@ The structure of the data in a [[#time-synchronization-packets]] packet is as fo Description - b(16) - time_descriptor - ''0x03**'' - Indicates this is a Indicates this is a time synchronization packet. The lower 8 bits are used as the [=ts_clock_id=] field. + b(8) + time_sync_descriptor + ''0x03'' + Indicates this is a time synchronization packet. + + + b(8) + ts_clock_id + + Signals the clock ID for this clock. u(16) @@ -658,91 +673,91 @@ The layout of the data is as follows: Data Description - + b(16) - reg_descriptor + stream_registration_descriptor ''0x0002'' Indicates this is a Indicates this is a stream registration packet. - + b(16) [=stream_id=] Indicates the stream ID for the new stream to be registered. - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + b(16) related_stream_id Indicates the stream ID for which this stream is related to. - + b(16) derived_stream_id Indicates the stream ID for which this stream is derived from. - + u(64) bandwidth Average bitrate in bits per second. MAY be 0 to indicate VBR or unknown. - + b(64) stream_flags enum {{StreamFlags}} Flags to indicate the type of stream. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + b(32) codec_id Indicates the codec ID for the data packets in this stream. - + R(64) timebase Signals the timebase of the timestamps present in the [[#stream-data-packets]] packets. - + b(8) [=ts_clock_id=] An 8-bit clock ID identifier to associate a stream with a given clock. - + u(64) skip_preroll Amount of time in `timebase` units to skip immediately after seeking or reinitializing (algorithmic delay). - + u(64) init_packets enum {{StreamInitPackets}} Flags to indicate which packets should be received before decoding or presenting any stream data packets. - + b(40) [=padding=] Padding, reserved for future use. Must be 0x0. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] @@ -766,23 +781,23 @@ must be at least as long as the [=skip_preroll=]. The [=init_packets=] field indicates which packets are required, and will be transmitted, for the stream to be correctly decoded and presented. It MUST be interpreted as follows: -
- : STREAM_INIT_PKT_METADATA = 0x1 +
+ : STREAM_INIT_PKT_METADATA = 0x1 :: Stream requires a [[#metadata-packets]] packet in order to be fully initialized. - : STREAM_INIT_PKT_STREAM_DURATION = 0x2 + : STREAM_INIT_PKT_STREAM_DURATION = 0x2 :: Stream requires a [[#stream-duration-packets]] packet in order to be fully initialized. - : STREAM_INIT_PKT_CONFIG_DATA = 0x4 + : STREAM_INIT_PKT_CONFIG_DATA = 0x4 :: Stream requires a [[#stream-configuration-packets]] packet in order to be fully initialized. - : STREAM_INIT_PKT_VIDEO_INFO = 0x8 + : STREAM_INIT_PKT_VIDEO_INFO = 0x8 :: Stream requires a [[#video-information-packets]] packet in order to be fully initialized. - : STREAM_INIT_PKT_LUT_ICC = 0x10 + : STREAM_INIT_PKT_LUT_ICC = 0x10 :: Stream requires a [[#lut-icc-profile-packets]] packet in order to be fully initialized. - : STREAM_INIT_PKT_FONT_DATA = 0x20 + : STREAM_INIT_PKT_FONT_DATA = 0x20 :: Stream requires a [[#font-data-packets]] packet in order to be fully initialized.
@@ -795,57 +810,57 @@ new stream and decoding/presenting packets from it. The [=stream_flag=] field provides context for the stream. It MUST be interpreted in the following manner: -
- : STREAM_RESERVED = 0x1 - :: Reserved for future use. +
+ : STREAM_SUBTITLES = 0x1 + :: Stream contains timed text. - : STREAM_DEFAULT = 0x2 + : STREAM_DEFAULT = 0x2 :: Stream should be chosen by default amongst other streams of the same type, unless the user has specified otherwise. - : STREAM_STILL_PICTURE = 0x4 + : STREAM_STILL_PICTURE = 0x4 :: Stream is a still picture and only a single decodable frame will be sent. - : STREAM_COVER_ART = 0x8 + : STREAM_COVER_ART = 0x8 :: Stream is a cover art picture for the stream signalled in [=related_stream_id=]. - : SESSION_LOW_QUALITY = 0x10 + : SESSION_LOW_QUALITY = 0x10 :: Stream is a lower quality version of the stream signalled in [=related_stream_id=]. - : STREAM_DUB = 0x20 + : STREAM_DUB = 0x20 :: Stream is a dubbed version of the stream signalled in [=related_stream_id=]. - : STREAM_COMMENTARY = 0x40 + : STREAM_COMMENTARY = 0x40 :: Stream is a commentary track to the stream signalled in [=related_stream_id=]. - : STREAM_LYRICS = 0x80 + : STREAM_LYRICS = 0x80 :: Stream is a lyrics track to the stream signalled in [=related_stream_id=]. - : STREAM_KARAOKE = 0x100 + : STREAM_KARAOKE = 0x100 :: Stream is a karaoke track to the stream signalled in [=related_stream_id=]. : STREAM_HEARING_IMPAIRED = 0x200 :: Stream is intended for hearing impaired audiences. Note: If [=related_stream_id=] is not equal to [=stream_id=], both should be mixed in. - : STREAM_VISUALLY_IMPAIRED = 0x400 + : STREAM_VISUALLY_IMPAIRED = 0x400 :: Stream is intended for visually impaired audiences. Note: If [=related_stream_id=] is not equal to [=stream_id=], both should be mixed in. - : STREAM_NO_DIALOGUE = 0x800 + : STREAM_NO_DIALOGUE = 0x800 :: Stream contains music and sound effects without voice. - : STREAM_NON_DIEGETIC = 0x1000 + : STREAM_NON_DIEGETIC = 0x1000 :: Stream contains non-diegetic audio. Note: If [=related_stream_id=] is not equal to [=stream_id=], both should be mixed in. - : STREAM_DESCRIPTIONS = 0x2000 + : STREAM_DESCRIPTIONS = 0x2000 :: Stream contains textual or spoken descriptions to the stream signalled in [=related_stream_id=]. - : STREAM_TIMING_METADATA = 0x4000 + : STREAM_TIMING_METADATA = 0x4000 :: Stream contains timed metadata and is not intended to be directly presented to the user. - : STREAM_THUMBNAILS = 0x8000 + : STREAM_THUMBNAILS = 0x8000 :: Stream contains temporally sparse thumbnails to the stream signalled in [=related_stream_id=].
@@ -865,7 +880,7 @@ related different ID must exist. ## Generic data ## {#generic-data-packets} To ease parsing, the specification defines a common template for data that -requires no special treatment, but only differs by [=descriptor=]. +requires no special treatment, but only differ by [=descriptor=]. This way, any generic data can share a common code path, have parity data and be a part of an [[#fec-grouping-packets]] packet. @@ -873,51 +888,63 @@ of an [[#fec-grouping-packets]] packet. The following template shall be used for generic data packets:
- +
- + - + - + - + - - + + + + + + + + + + + + + + - - + + - + - - + + @@ -931,7 +958,7 @@ The following template shall be used for generic data packets: In case the data needs to be segmented, the following template has to be used for segments that follow the above: -
+
Type Name Data Description
b(16)generic_descriptorgeneric_data_descriptor as specified Indicates the data packet type. Defined in later sections.
b(16) [=stream_id=] Indicates the stream ID for which this packet is applicable.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
u(64)
u(32)total_payload_lengthThe total size of all data needed to receive the payload correctly. Must be either 0 if unknown, or the total size of the payload across all segments.
i(64)[=pts=]Indicates the presentation timestamp for when this data becomes valid at. To interpret the value, read the [[#timestamps]] section.
u(32) payload_length The size of the data in this packet.
b(128)
b(32) [=padding=] Padding, reserved for future use. MUST be 0x0.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
b([=payload_length=]*32)
[=payload_length=]*b(8) generic_payload The packet data itself.
@@ -939,62 +966,62 @@ has to be used for segments that follow the above: - + - + - + - + - + - + - + - + - + - + - - + + @@ -1015,7 +1042,7 @@ packet in order to determine the timestamps and data type. Finally, in case the data requires parity data (FEC, but only on the current packet), the following [[#generic-data-packets]] structure is to be used: -
+
TypeData Description
b(16) generic_segment_descriptor as specifiedIndicates the segment type. Defined in later sections along with [=generic_descriptor=].Indicates the segment type. Defined in later sections along with [=generic_data_descriptor=].
b(16) [=stream_id=] Indicates the stream ID for which this packet is applicable.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
b(32) target_seq The sequence number of the starting [[#generic-data-packets]] packet.
u(32) pkt_total_data Total number of data bytes, including the first data packet's, and ending segment's.
u(32) seg_offset The offset since the start of the data where the segment starts.
u(32) seg_length The size of the data segment.
b(32) header_7 A seventh of the starting [[#generic-data-packets]] header. The part taken is determined by [=global_seq=] % 7.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
b([=seg_length=]*32)
[=seg_length=]*b(8) generic_segment_payload The data for the segment.
@@ -1023,62 +1050,62 @@ the following [[#generic-data-packets]] structure is to be used: - + - + - + - + - + - + - + - + - + - + - - + + @@ -1090,7 +1117,7 @@ The data in an parity packet MUST be systematic RaptorQ, as per [[RFC6330]].
never used. -The symbol size MUST be 32-bits. +The FEC symbol size MUST be 32-bits. The [=header_7=] field can be used to reconstruct the header of the very first packet in order to determine the timestamps and data type. @@ -1107,31 +1134,25 @@ with the following descriptors:
TypeData Description
b(16) generic_parity_descriptor as specifiedIndicates this packet carries parity. Defined in later sections along with [=generic_descriptor=].Indicates this packet carries parity. Defined in later sections along with [=generic_data_descriptor=].
b(16) [=stream_id=] Indicates the stream ID for which this packet is applicable.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
b(32) [=target_seq=] The sequence number of the starting [[#generic-data-packets]] packet.
u(32) parity_data_offset The byte offset for the RaptorQ parity data for this parity data packet protects.
u(32) parity_data_length The length of the RaptorQ data in this packet.
u(32) parity_total The total amount of payload bytes across all parity data packets.
b(32) [=header_7=] A seventh of the starting [[#generic-data-packets]] header. The part taken is determined by [=global_seq=] % 7.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
b([=seg_length=]*32)
[=parity_data_length=]*b(8) parity_data_payload The RaptorQ parity data that can be used to check or correct the previous data packet's payload.
+ + - + - - - - - + - - - - - - + + @@ -1146,7 +1167,7 @@ However, in general, the data follows the same layout as what An implementation may error out in case it cannot handle the data in the payload. If so, when reading a file, it must stop, otherwise in a live scenario, -it must send an '''unsupported'' [[#control-data-packets]] packet, if such a +it must send an '''unsupported'' [[#session-control-data-packets]] packet, if such a connection is open. @@ -1165,56 +1186,81 @@ more [[#stream-data-segment-packets]]. It is laid out as follows: - - - + + - + - + - + - + - + - + - - + + @@ -1228,22 +1274,22 @@ the [[#codec-encapsulation]] addenda. ### Frame Type Enumeration (enum FrameType) ### {#enum-FrameType} -
- : FRAME_TYPE_KEY = 0x0 +
+ : FRAME_TYPE_KEY = 0x0 :: Packet data contains a keyframe, able to be decoded standalone. - : FRAME_TYPE_S = 0x1 + : FRAME_TYPE_S = 0x1 :: Packet data contains a scalable/switch frame, able to be decoded standalone with acceptable degradation. - : FRAME_TYPE_P = 0x2 + : FRAME_TYPE_P = 0x2 :: Packet data contains an inter frame, requiring additional reference frames in order to be validly decoded.
### Data Compression Enumeration (enum DataCompression) ### {#enum-DataCompression} -
- : DATA_COMPRESSION_NONE = 0x0 +
+ : DATA_COMPRESSION_NONE = 0x0 :: Packet data is uncompressed - : DATA_COMPRESSION_ZSTD = 0x1, + : DATA_COMPRESSION_ZSTD = 0x1 :: Packet data is compressed with Zstandard, defined in IETF [[RFC8878]].
@@ -1263,19 +1309,16 @@ The packet structure used for segments is the [[#generic-data-segment-packets]]
Descriptor valueName Structure Description
''0x0003''stream_config_descriptor [[#generic-data-packets]]Non-segmented codec initialization data.Codec initialization data.
''0x0004''[[#generic-data-packets]]First segment from a segmented codec configuration data, requiring more segments to be complete.
''0x0005''stream_config_segment_descriptor [[#generic-data-segment-packets]] Non-final segment for segmented codec configuration.
''0x0006''[[#generic-data-segment-packets]]Final segment of a segmented codec configuration.
''0x0007''''0x0005''stream_config_parity_descriptor [[#generic-data-parity-packets]] Parity data for codec configuration data.
b(16)data_descriptor''0x01**'' - Indicates the packet is a stream data packet. - - Bits 15-8: MUST be set to ''0x01'' - - Bits 5-7: MUST be interpreted as frame_type, using the [[#enum-FrameType]] definition. - - Bit 4: Indicates packet is incomplete and extra [[#stream-data-segment-packets]] packets are required. - - Bit 3: Indicates packet is part of an [[#fec-grouping-packets]] and must be retained. - - Bit 2: If [=interlaced=] is equal to {{ILACE_TFF}} or {{ILACE_BFF}}, this is the field_id bit. Otherwise, this field is free to use by users. - - Bit 1-0: MUST be interpreted as data_compression, using the [[#enum-DataCompression]] definition. + stream_data_descriptor_structure + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
b(8)stream_data_descriptor0x01
b(3)frame_typeenum {{FrameType}}
b(1)pkt_segmentedPacket is incomplete and extra segments are required.
b(1)pkt_in_fec_groupPacket is part of an FEC group and must be retained.
b(1)field_idAs defined in enum {{Interlacing}}.
b(2)pkt_compressionenum {{DataCompression}}
b(16) [=stream_id=] Indicates the stream ID for which this packet is applicable.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
i(64) [=pts=] Indicates the presentation timestamp for when this frame should be presented at. To interpret the value, read the [[#timestamps]] section.
i(64) [=duration=] The duration of this packet in stream timebase unis.
u(32) data_length The size of the data in this packet.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
b([=data_length=]*32)
[=data_length=]*b(8) packet_data The packet data itself.
+ - + + - - - - -
Descriptor valueName Structure Description
''0x00FF''stream_data_segment_descriptor [[#generic-data-segment-packets]] Non-final segment for segmented codec configuration.
''0x00FE''[[#generic-data-segment-packets]]Final segment of a segmented codec configuration.
@@ -1317,13 +1360,13 @@ FEC grouped streams MUST be registered first via a special packet: Data Description - + b(16) - fec_group_descriptor + fec_grouping_descriptor ''0x0030'' Indicates this is an FEC grouping packet. - + b(16) group_id @@ -1332,61 +1375,61 @@ FEC grouped streams MUST be registered first via a special packet: Note: Must not overlap with [=stream_id=]. - + u(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + u(8) fec_grouping_streams Number of streams in the FEC group. Must be less than or equal to 16. - + b(64) fec_common_oti [[RFC6330#section-3.3.2]] [[RFC6330]], RaptorQ Common FEC Object Transmission Information. - + b(32) fec_scheme_oti [[RFC6330#section-3.3.3]] [[RFC6330]], RaptorQ Scheme-Specific FEC Object Transmission Information. - + u(32) fec_start_global_seq The global sequence number of the very first packet in the FEC group. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + 16*u(32) fec_nb_packets Total number of packets for each stream in the FEC group. - + 16*u(32) fec_seq_number The sequence number of the first packet for the stream to be included in the group./td> - + b(480) [=padding=] Padding, reserved for future use. MUST be ''0x0''. - + b(768) [=ldpc_2784_2016=] [=LDPC(2784, 2016)=] @@ -1419,73 +1462,73 @@ FEC groups use a different packet for the FEC data. Data Description - + b(16) fec_group_data_descriptor ''0x0031'' Indicates this is an FEC group data packet. - + b(16) [=group_id=] Indicates the FEC grouping for which this packet has data for. - + u(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + u(32) fec_data_offset The byte offset for the FEC data for this FEC packet protects. - + u(32) fec_data_length The length of the FEC data in this packet. - + u(32) fec_total_data_length The total amount of bytes in the FEC grouping data. - + b(64) fec_source_1 [[#struct-FECSource]] Provides a single source packet which contains data to be forward error corrected. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + 3*b(64) fec_source_234 [[#struct-FECSource]] Provides another three source packet which contains data to be forward error corrected. - + b(32) [=padding=] Padding, reserved for future use. MUST be ''0x0''. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + [=fec_data_length=]*b(8) fec_data @@ -1503,7 +1546,7 @@ The `fec_source` data is defined as follows: Type Name - Data + Value Description @@ -1545,11 +1588,13 @@ from the [[#generic-data-packets]] section, with the following descriptor: + - - + + + @@ -1580,84 +1625,60 @@ or metadata changes, and the distance to the next index packet. - + - + - + - + - + - + - + - + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - -
Descriptor valueName Structure Description
''0x00FD''
''0x00FE''stream_data_parity_descriptor [[#generic-data-parity-packets]] Parity data segment for individual stream data packets.
Data Description
b(16)index_descriptorstream_index_descriptor ''0x0051'' Indicates this is an index packet.
b(16) [=stream_id=] Indicates the stream ID for the index. May be ''0xFFFF'', in which case, it applies to all streams.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
u(32) prev_idx Negative offset of the previous index packet, if any, in bytes, relative to the current position. If exactly ''0'', indicates no such index is available, or is out of scope.
u(32) next_idx Positive offset of the next index packet, if any, in bytes, relative to the current position. May be inexact, specifying the minimum distance to one. Users may search for it.
u(32) nb_indices The total number of indices present in this packet.
b(64) [=padding=] Padding, reserved for future use. MUST be 0x0.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
[=nb_indices=]*b(16)[=descriptor=]
[=nb_indices=]*b(144)index_entry_liststruct [[#index-entry-struct|IndexEntry]] [[#packet-descriptor|Descriptor]] of the packet that each index points to.
[=nb_indices=]*i(64)[=pts=]Timestamp of the packet that each index points to.
[=nb_indices=]*u(32)[=global_seq=]Sequence number of the packet pointed to by each index.
[=nb_indices=]*i(32)pkt_offsetThe offset of a decodable index relative to the current position in bytes. May be ''0'' if unavailable or not applicable.
[=nb_indices=]*u(16)pkt_chapterIf a value is greater than ''0'', demarks the start of a chapter with an index equal to the value.
@@ -1673,12 +1694,52 @@ first, most significant byte of the descriptor of the pointed packet. If [=stream_id=] is ''0xFFFF'', the timebase used for [=pts=] must be assumed to be 1 nanosecond, numerator of ''1'', denominator of ''1000000000''. -If a packet starts before the value of [=pts=] but has a duration that +When streaming, [=prev_idx=] and [=next_idx=] must be ''0''. + + +### Index entry (struct IndexEntry) ### {#index-entry-struct} + +The structure of the data for each index entry is as follows: + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeNameDataDescription
b(16)index_entry_descriptor[[#packet-descriptor|Descriptor]] of the packet that each index points to.
i(64)[=pts=]Timestamp of the packet that the index entry points to.
u(32)[=global_seq=]Sequence number of the packet pointed to by this index entry.
i(32)pkt_offsetThe offset of the index entry relative to the current position in bytes. May be ''0'' if unavailable or not applicable.
+
+ +Note: If a packet starts before the value of [=pts=] but has a duration that matches or exceeds the PTS, then it must be included. This is to permit correct subtitle presentation, or long duration still pictures like slideshows. -When streaming, [=prev_idx=] and [=next_idx=] must be ''0''. - ## Metadata ## {#metadata-packets} @@ -1690,31 +1751,25 @@ The metadata packets can be sent for the overall session, or for a specific + - + + - + - + - - - - - - - - - - + - - + + + @@ -1799,80 +1854,86 @@ The following structure MUST be followed: - + - - - + + + - + - + - + + + + + + + - + - + - + - + - + - + - - + + - + - - + + - - + + @@ -1888,39 +1949,45 @@ segmentation and parity packets is via the following [[#generic-data-packets]] t
Descriptor valueName Structure Description
''0x000A''metadata_descriptor [[#generic-data-packets]]Non-segmented metadata.First metadata segment.
''0x000B''[[#generic-data-packets]]First segment from segmented metadata, requiring more segments to be complete.
''0x000C''[[#generic-data-segment-packets]]Non-final segment for segmented metadata.
''0x000D''metadata_segment_descriptor [[#generic-data-segment-packets]] Final segment of segmented metadata.
''0x000E''
''0x000C''metadata_parity_descriptor [[#generic-data-parity-packets]] Parity data for metadata.
Data Description
b(16)lut_descriptor''0x0010'' or ''0x0011''Indicates this packet contains a complete LUT or ICC profile (''0x0010'') or the start of a segmented one (''0x0011'').lut_icc_descriptor''0x0010''Indicates this packet contains a complete LUT or ICC profile or the start of one.
b(16) [=stream_id=] The stream ID for which to apply the LUT/ICC profile.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
b(8)lut_flagsenum {{LutFlags}}Flags for the LUT/ICC profile packet.
u(8) lut_typeenum {{LUTType}}enum {{LutType}} The data type contained in the [=lut_data=].
b(8) lut_major_ver Major version of the file. Currently only applies to ICC profiles.
b(8) lut_minor_ver Minor version of the file. Currently only applies to ICC profiles.
u(8) lut_compression enum {{DataCompression}} LUT/ICC data compression.
b(8) lut_name_length The length of the LUT/ICC profile name.
b(8) lut_data_length The length of the LUT/ICC profile.
b(104)
b(96) [=padding=] Padding, reserved for future use. MUST be 0x0.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet.
b([=lut_name_length=]*8)
[=lut_name_length=]*b(8) lut_name zero-terminated string The full name of the LUT/ICC profile.
b([=lut_data_length=]*8)
[=lut_data_length=]*b(8) lut_data The LUT/ICC profile data
+ - + + - + + - - - - -
Descriptor valueName Structure Description
''0x0012''''0x0011''lut_icc_segment_descriptor [[#generic-data-segment-packets]] Non-final segment for segmented LUT/ICC profile.
''0x0013''''0x0012''lut_icc_parity_descriptor [[#generic-data-segment-packets]] Final segment of a segmented LUT/ICC profile.
''0x0014''[[#generic-data-parity-packets]]Parity data for LUT/ICC profile.
-If the [=lut_descriptor=] is ''0x0011'', then at least one ''0x0013'' segment must be received. +## LUT/ICC Profile Flags Enumeration (enum LutFlags) ## {#enum-LutFlags} -## LUT/ICC Profile Type Enumeration (enum LUTType) ## {#enum-LUTType} +The [=lut_flags=] field must be interpreted in the following way: + +
+ : CLUT_SEGMENTED = 0x1 + :: Indicates that tata contains an incomplete part of a LUT/ICC profile, and requires additional segment packets to complete. +
+ + +## LUT/ICC Profile Type Enumeration (enum LutType) ## {#enum-LutType} The [=lut_type=] field must be interpreted in the following way: -
- : CLUT_ICC_PROFILE = 0x1 - :: Indicates that tata contains a regular ICC profile, with version [=lut_major_ver=].[=lut_minor_ver=]. - : CLUT_ADOBE_CUBE = 0x2 - :: Indicates that tata contains an Adobe [[CUBE]] file. +
+ : CLUT_TYPE_ICC_PROFILE = 0x1 + :: Indicates that the data contains a regular ICC profile, with version [=lut_major_ver=].[=lut_minor_ver=]. + : CLUT_TYPE_ADOBE_CUBE = 0x2 + :: Indicates that the data contains an Adobe [[CUBE]] file.
Note: Lookup tables and ICC profiles must take precedence over the primaries and transfer @@ -1948,13 +2015,13 @@ The following structure MUST be followed: Data Description - + b(16) - font_descriptor - ''0x0020'' or ''0x0021'' - Indicates this packet contains a complete font file (''0x0020'') or the start of a segmented one (''0x0021''). + font_data_descriptor + ''0x0020'' + Indicates the payload contains a font. - + b(16) [=stream_id=] @@ -1963,56 +2030,68 @@ The following structure MUST be followed: Note: may be set to ''0xffff'' to make the font available for all streams. - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + + b(8) + font_segmented + + If non-zero, indicates the font payload is segmented. + + + b(8) + font_flags + enum {{FontFlags}} + Flags for the font packet. + + u(8) font_type enum {{FontType}} The data type contained in the [=font_data=]. - + u(8) font_compression enum {{DataCompression}} Font data compression. - + b(8) font_name_length The length of the font file name. - + b(8) font_data_length The length of the font file data. - - b(96) + + b(80) [=padding=] Padding, reserved for future use. MUST be 0x0. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - - b([=font_name_length=]*8) + + [=font_name_length=]*b(8) font_name zero-terminated string The name of the font file. - - b([=font_data_length=]*8) + + [=font_data_length=]*b(8) font_data The font data. @@ -2029,43 +2108,49 @@ templates: Descriptor value Structure + Name Description - - ''0x0022'' + + ''0x0021'' + font_data_segment_descriptor [[#generic-data-segment-packets]] Non-final segment for segmented font file. - - ''0x0023'' - [[#generic-data-segment-packets]] - Final segment of a segmented font file. - - - ''0x0024'' + + ''0x0022'' + font_data_parity_descriptor [[#generic-data-parity-packets]] Parity data for a font file. -If the [=font_descriptor=] is ''0x21'', then at least one ''0x23'' segment must be received. + +## Font Flags Enumeration (enum FontFlags) ## {#enum-FontFlags} + +The [=font_flags=] field must be interpreted in the following way: + +
+ : FONT_SEGMENTED = 0x1 + :: Indicates that tata contains an incomplete part of a font, and requires additional segment packets to complete. +
## Font Type Enumeration (enum FontType) ## {#enum-FontType} The [=font_type=] field must be interpreted in the following way: -
- : FONT_OTF = 0x0 +
+ : FONT_TYPE_OTF = 0x0 :: Indicates that the font data contained is an [[OpenType]] font. - : FONT_TTF = 0x1 + : FONT_TYPE_TTF = 0x1 :: Indicates that tata contains a [[TrueType]] font. - : FONT_WOFF2 = 0x2 + : FONT_TYPE_WOFF2 = 0x2 :: Indicates that tata contains a [[WOFF2]] (Web Open Font Format 2) font.
-Note: {{FONT_WOFF2}} fonts should not be compressed, as they're already compressed. +Note: {{FONT_TYPE_WOFF2}} fonts should not be compressed, as they're already compressed. ## Video information ## {#video-information-packets} @@ -2081,187 +2166,187 @@ stream after decoding. Data Description - + b(16) video_info_descriptor ''0x0008'' Indicates this packet contains video information. - + b(16) [=stream_id=] The stream ID for which to apply the video information to. - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + u(32) width Indicates the video width in pixels, before any cropping. - + u(32) height Indicates the video height in pixels, before any cropping - + R(64) signal_aspect Indicates the sample aspect ratio of the image. - + u(8) chroma_subsampling enum {{ChromaSubsampling}} Indicates the chroma subsampling being used. - + u(8) colorspace enum {{Colorspace}} Indicates the kind of colorspace the video is in. - + u(8) bit_depth Number of bits per output video sample. - + u(8) interlaced enum {{Interlacing}} Indicates the video interleaving. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + R(64) gamma Indicates the gamma power curve for the video sample values. - + R(64) framerate Indicates the framerate of the video. If it's variable, may be used to indicate the average bitrate. If the video is [=interlaced=], indicates the field rate. - + u(8) output_range enum {{ColorRange}} Indicates the range for the output video samples. - + u(8) chroma_pos enum {{ChromaPosition}} Chroma sample alignment for subsampled chroma. - + u(8) primaries - [[H.273]] ''ColourPrimaries'' + enum {{Primaries}} Video color primaries. Must be interpreted according to ITU Standard [[H.273]], ''ColourPrimaries'' field. - + u(8) transfer - [[H.273]], ''TransferCharacteristics'' + enum {{Transfer}} Video transfer characteristics. Must be interpreted according to ITU Standard [[H.273]], ''TransferCharacteristics'' field. - + u(8) matrix - [[H.273]], ''MatrixCoefficients'' + enum {{Matrix}} Video matrix coefficients. Must be interpreted according to ITU Standard [[H.273]], ''MatrixCoefficients'' field. - + u(8) has_mastering_primaries If ''1'', indicates that the following [=mastering_primaries=] and [=mastering_white_point=] contain valid data. Other values are reserved. - + u(8) has_luminance If ''1'', indicates that the following [=min_luminance=] and [=max_luminance=] contain valid data. Other values are reseved. - + 16*R(64) custom_matrix If the color [=matrix=] value is equal to ''0xFF'', use this custom matrix instead. Top left to bottom right, in "raster-order". Otherwise, must be set to ''0''. - + 6*R(64) mastering_primaries [[CIE1931]] X/Y chromacity coordinates of the color primaries, x value, then y value, for each r, g, b, in order. - + 2*R(64) mastering_white_point [[CIE1931]] X/Y chromacity coordinates of the white point, x value, then y value. - + R(64) min_luminance Minimal luminance of the mastering display, in cd/m2. - + R(64) max_luminance Maximum luminance of the mastering display, in cd/m2. - + u(32) cropped_width Indicates the presentable video width in samples. - + u(32) cropped_height Indicates the presentable video height in samples. - + u(32) crop_x_offset X offset for the location of the final presentation box. - + u(32) crop_y_offset Y offset for the location of the final presentation box. - + b(40) [=padding=] Padding, reserved for future use. Must be ''0x0''. - + b(64) [=ldpc_2784_2016=] [=LDPC(2784, 2016)=] @@ -2275,33 +2360,33 @@ stream after decoding. The [=colorspace=] field must be interpreted in the following way: -
- : CSP_MONO = 0x0 +
+ : CSP_MONO = 0x0 :: Video contains no chroma data. - : CSP_RGB = 0x1 + : CSP_RGB = 0x1 :: Video data contains a form of RGB. - : CSP_YUV = 0x2 + : CSP_YUV = 0x2 :: Video contains a form of YUV (YCbCr). - : CSP_YCOCGR = 0x3 + : CSP_YCOCGR = 0x3 :: Video contains a reversible form of YCoCg, as defined by [[H.273]], equations 47-50. - : CSP_YCGCOR = 0x4 + : CSP_YCGCOR = 0x4 :: Video contains a reversible form of YCgCo (same as above, with swapped chroma planes). - : CSP_XYZ = 0x5 + : CSP_XYZ = 0x5 :: Video contains [[CIE1931]] XYZ color data. - : CSP_XYB = 0x6 + : CSP_XYB = 0x6 :: Video contains XYB color data, as defined by [[ISO18181]]. Note: [matrix] must be equal to ''0xFF'' and the [=custom_matrix=] must be a valid matrix to transform XYB into RGB. - : CSP_ICTCP = 0x5 + : CSP_ICTCP = 0x5 :: Video contains [[BT2100]] ICtCp color data.
## Color Range Enumeration (enum ColorRange) ## {#enum-ColorRange} -
- : COLOR_RANGE_FULL = 0x0 +
+ : COLOR_RANGE_FULL = 0x0 :: Video sample values contains the full range of the [=bit_depth=]. - : COLOR_RANGE_LIMITED = 0x1 + : COLOR_RANGE_LIMITED = 0x1 :: Video sample values contains the limited range of the [=bit_depth=]. Note: this describes the cannonical limited range representation: @@ -2314,28 +2399,34 @@ The [=colorspace=] field must be interpreted in the following way: ## Chroma Subsampling Enumeration (enum ChromaSubsampling) ## {#enum-ChromaSubsampling} -
- : CHROMA_444 = 0x0 +
+ : CHROMA_444 = 0x0 :: Chromatic data is not subsampled, or subsampling does not apply. - : CHROMA_420 = 0x1 + : CHROMA_420 = 0x1 :: Chromatic data is subsampled at half the horizontal and vertical resolution of the luminance data. - : CHROMA_422 = 0x2 + : CHROMA_422 = 0x2 :: Chromatic data is subsampled at half the vertical resolution of the luminance data.
## Interlacing Enumeration (enum Interlacing) ## {#enum-Interlacing} -
- : ILACE_PROG = 0x0 +The value of [=interlaced=] determines whether the video is interlaced, as well as how +to interpret the value of [=field_id=] in stream data packet headers. + +
+ : ILACE_PROG = 0x0 :: Video contains progressive data, or interlacing does not apply. - : ILACE_TFF = 0x1 + + Note: in this mode, the [=field_id=] bit is free to use by users. Implementations must ignore it, and preserve it. + + : ILACE_TFF = 0x1 :: Video is interlaced. One [[#stream-data-packets]] packet per field. If the data packet's [=field_id=] bit is unset, indicates the field contained is the top field, otherwise it's the bottom field. - : ILACE_BFF = 0x2 + : ILACE_BFF = 0x2 :: Same as above, with reversed polarity, such that packets with [=field_id=] bit set contain the top field, otherwise it's the bottom. - : ILACE_TW = 0x3 + : ILACE_TW = 0x3 :: Video is interlaced. The [[#stream-data-packets]] packet contains both fields, weaved together, with the top field being on every even line. - : ILACE_BW = 0x4 + : ILACE_BW = 0x4 :: Same as above, but with reversed polarity, such that the bottom field is encountered first.
@@ -2346,29 +2437,29 @@ the setting used, if the codec supports this. ## Chroma Position Enumeration (enum ChromaPosition) ## {#enum-ChromaPosition} -
- : CHROMA_POS_UNSPEC = 0x0 +
+ : CHROMA_POS_UNSPEC = 0x0 :: Chroma position not specified or does not apply. - : CHROMA_POS_LEFT = 0x1 + : CHROMA_POS_LEFT = 0x1 :: Chroma position is between 2 luma samples on different lines. Note: This is the default chroma position for MPEG-2, H.263 with {{CHROMA_422}}, and H.264 with {{CHROMA_420}}. - : CHROMA_POS_CENTER = 0x2 + : CHROMA_POS_CENTER = 0x2 :: Chroma position is in the middle between all neighbouring luma samples on 2 lines. Note: This is the default chroma position for JPEG with {{CHROMA_420}}, and H.263 with {{CHROMA_420}}. - : CHROMA_POS_TOPLEFT = 0x3 + : CHROMA_POS_TOPLEFT = 0x3 :: Chroma position coincides with top left's luma sample position. Note: This is the default chroma position for MPEG-2 with {{CHROMA_422}}. - : CHROMA_POS_TOP = 0x4 + : CHROMA_POS_TOP = 0x4 :: Chroma position is between 2 luma samples on the same top line. - : CHROMA_POS_BOTTOMLEFT = 0x5 + : CHROMA_POS_BOTTOMLEFT = 0x5 :: Chroma position coincides with bottom left's luma sample position. - : CHROMA_POS_BOTTOM = 0x6 + : CHROMA_POS_BOTTOM = 0x6 :: Chroma position is between 2 luma samples on the same bottom line.
@@ -2404,6 +2495,122 @@ To illustrate: +## Primaries Enumeration (enum Primaries) ## {#enum-Primaries} + +These values are copied verbatim from [[H.273]]. + +
+ : PRIM_RESERVED_0 = 0x0 + :: For future use by ITU-T | ISO/IEC + : PRIM_BT709 = 0x1 + :: Rec. ITU-R BT.709-6 + :: IEC 61966-2-1 sRGB or sYCC + : PRIM_UNSPEC = 0x2 + :: Image characteristics are unknown or are determined by the application. + : PRIM_RESERVED_3 = 0x0 + :: For future use by ITU-T | ISO/IEC + : PRIM_BT470 = 0x4 + :: United States Federal Communications Commission (2003) Title 47 Code of Federal Regulations 73.682 (a) (20) + : PRIM_BT601_625 = 0x5 + :: Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM + : PRIM_BT601_525 = 0x6 + :: Rec. ITU-R BT.1700-0 NTSC + : PRIM_ST240 = 0x7 + :: SMPTE ST 240 (1999) (functionally the same as the value 6) + : PRIM_FILM = 0x8 + :: Generic film (colour filters using Illuminant C) + : PRIM_BT2020 = 0x9 + :: Rec. ITU-R BT.2100-2 + : PRIM_ST428 = 0xA + :: SMPTE ST 428-1 (2019) (CIE 1931 XYZ as in ISO 11664-1) + : PRIM_ST431 = 0xB + :: SMPTE RP 431-2 (2011) + : PRIM_ST432 = 0xC + :: SMPTE EG 432-2 (2010) +
+ +Note: this list may not be up to date in this version of the AVTransport specifications. +Users should consult [[H.273]] for up-to-date values and how to interpret them. + + +## Transfer Function Enumeration (enum Transfer) ## {#enum-Transfer} + +These values are copied verbatim from [[H.273]]. The same note applies. + +
+ : TRANSFER_RESERVED_0 = 0x0 + :: For future use by ITU-T | ISO/IEC + : TRANSFER_BT709 = 0x1 + :: Rec. ITU-R BT.709-6 + : TRANSFER_UNSPEC = 0x2 + :: Image characteristics are unknown or are determined by the application. + : TRANSFER_FCC = 0x4 + :: United States Federal Communications Commission (2003) Title 47 Code of Federal Regulations 73.682 (a) (20) + : TRANSFER_BT470 = 0x5 + :: Rec. ITU-R BT.470-6 System B, G (historical) + : TRANSFER_BT601 = 0x6 + :: Rec. ITU-R BT.601-7 525 or 625 + : TRANSFER_ST240 = 0x7 + :: SMPTE ST 240 (1999) + : TRANSFER_LINEAR = 0x8 + :: Linear transfer characteristics + : TRANSFER_LOG = 0x9 + :: Logarithmic transfer characteristic (100:1 range) + : TRANSFER_LOG_SQ = 0xA + :: Logarithmic transfer characteristic (100 * Sqrt( 10 ) : 1 range) + : TRANSFER_IEC61966_2_4 = 0xB + :: IEC 61966-2-4 + : TRANSFER_BT1361 = 0xC + :: Rec. ITU-R BT.1361-0 extended colour gamut system (historical) + : TRANSFER_IEC61966_2_1 = 0xD + :: IEC 61966-2-1 sRGB (with MatrixCoefficients equal to 0) or IEC 61966-2-1 sYCC (with MatrixCoefficients equal to 5) + : TRANSFER_BT2020_10 = 0xE + :: Rec. ITU-R BT.2020-2 (10-bit system) (functionally the same as the values 1, 6 and 15) + : TRANSFER_BT2020_12 = 0xF + :: Rec. ITU-R BT.2020-2 (12-bit system) (functionally the same as the values 1, 6 and 15) + : TRANSFER_BT2048 = 0x10 + :: Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system + : TRANSFER_ST428 = 0x11 + :: SMPTE ST 428-1 (2019) + : TRANSFER_HLG = 0x12 + :: Rec. ITU-R BT.2100-2 hybrid log- gamma (HLG) system +
+ + +## Matrix Enumeration (enum Matrix) ## {#enum-Matrix} + +These values are copied verbatim from [[H.273]]. The same note applies. + +
+ : MATRIX_IDENT = 0x0 + :: The identity matrix. Typically used for GBR (often referred to as RGB); however, may also be used for YZX (often referred to as XYZ); + : MATRIX_BT709 = 0x1 + :: Rec. ITU-R BT.709-6 + : MATRIX_UNSPEC = 0x2 + :: Image characteristics are unknown or are determined by the application + : MATRIX_RESERVED_3 = 0x3 + :: For future use by ITU-T | ISO/IEC + : MATRIX_FCC = 0x4 + :: United States Federal Communications Commission (2003) Title 47 Code of Federal Regulations 73.682 (a) (20) + : MATRIX_BT470 = 0x5 + :: Rec. ITU-R BT.470-6 System B, G (historical) (functionally the same as the value 6) + : MATRIX_BT601 = 0x6 + :: Rec. ITU-R BT.601-7 525 + : MATRIX_ST240 = 0x7 + :: SMPTE ST 240 (1999) + : MATRIX_YCGCO = 0x8 + :: See [[H.273]], equations 38 to 40 + : MATRIX_BT2020_NCL = 0x9 + :: Rec. ITU-R BT.2100-2 Y′CbCr + : MATRIX_BT2020_CL = 0xA + :: Rec. ITU-R BT.2020-2 (constant luminance) + : MATRIX_ST2085 = 0xB + :: SMPTE ST 2085 (2015) + : MATRIX_ST2100 = 0xE + :: Rec. ITU-R BT.2100-2 ICTCP +
+ + ## Video orientation ## {#video-orientation-packets} A standardized way to transmit orientation information is as follows: @@ -2416,49 +2623,49 @@ A standardized way to transmit orientation information is as follows: Data Description - + b(16) - orientation_descriptor + video_orientation_descriptor ''0x0040'' Indicates this is a video orientation packet. - + b(16) [=stream_id=] The stream ID for which to associate the video information with. - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + i(64) [=pts=] Timestamp (in stream [=timebase=] units) at which this orientation packet has to be applied at. - + u(8) reflection enum {{VideoReflection}} A fixed transposition that must occur before any arbitrary rotation. - + R(64) rotation A fixed-point rational number to indicate rotation in radians once multiplied by ''π''. - + b(24) [=padding=] Padding, reserved for future use. MUST be 0x0. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] @@ -2473,12 +2680,12 @@ until a new orientation packet is sent, or the stream is reinitialized. ## Video Reflection Enumeration (enum VideoReflection) ## {#enum-VideoReflection} -
- : VIDEO_REFLECT_NONE = 0x0 +
+ : VIDEO_REFLECT_NONE = 0x0 :: Video is not flipped. - : VIDEO_REFLECT_MIRROR = 0x1 + : VIDEO_REFLECT_MIRROR = 0x1 :: Video must be mirrored for correct presentation (flipped horizontally). - : VIDEO_REFLECT_FLIP = 0x2 + : VIDEO_REFLECT_FLIP = 0x2> :: Video must be flipped upside-down for correct presentation.
@@ -2503,49 +2710,55 @@ The user-specific data packet is laid out as follows: Data Description - + b(16) - userdata_descriptor - ''0x0500'' to ''0x05FF'' - Indicates this is an opaque user-specific data. The bottom byte is included and free to use. + user_data_descriptor + ''0x0600'' + Indicates this is an opaque user-specific data. - + b(16) user_field A free to use field for user data. - + b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number. - + b(8) userdata_segmented If set to ''1'', indicates that userdata is segmented, and additional packets will follow. - + u(32) userdata_length The length of the user data in this packet. - - b(120) + + b(64) + opaque + + Opaque data, available to users to set. + + + b(56) [=padding=] Padding, reserved for future use. MUST be 0x0. - + b(64) [=ldpc_288_224=] [=LDPC(288, 224)=] 64-bits of LDPC parity data to correct the previous 224 bits of the packet. - + [=userdata_length=]*b(8) userdata @@ -2560,21 +2773,19 @@ User data may be segmented: + - - - - - - + + - + - + + @@ -2595,37 +2806,37 @@ at the start of files to notify implementations of stream lengths. - + - + - + - + - + - + - + @@ -2661,31 +2872,31 @@ The EOS packet is laid out as follows: - + - + - + - + - + - + @@ -2731,7 +2942,7 @@ laid out in the following way: - + @@ -2953,6 +3164,8 @@ For DNG/TIFF encapsulation, the [=codec_id=] in [[#stream-registration-packets]] must be ''0x54494646'' (''TIFF''). +DNG/TIFF streams require no [[#stream-configuration-packets]]. + The [=packet_data=] must contain a raw TIFF file, with one packet being a single picture. @@ -2963,6 +3176,8 @@ For JPEG and Motion JPEG, the [=codec_id=] in the [[#stream-registration-packets]] must be ''0x4a504547'' (''JPEG''). +JPEG and Motion JPEG streams require no [[#stream-configuration-packets]]. + The [=packet_data=] must contain a raw JPEG file, with one packet being a single picture. @@ -2973,6 +3188,8 @@ For PNG, the [=codec_id=] in the [[#stream-registration-packets]] must be ''0x504e4730'' (''PNG0''). +PNG streams require no [[#stream-configuration-packets]]. + The [=packet_data=] must contain a raw PNG file. No support for Animated PNG is defined, but simply not flagging the still picture flag (`stream_flags & 0x04`) and sending @@ -2980,6 +3197,30 @@ a single picture per frame is sufficient to animate PNG, as this is allowed for any codec. +### SVG encapsulation ### {#svg-encapsulation} + +For [[SVG2]] (Scalable Vector Graphics), the [=codec_id=] in the +[[#stream-registration-packets]] must be ''0x53564732'' (''SVG2''). + +SVG streams require no [[#stream-configuration-packets]]. + +The [=packet_data=] must contain a raw SVG file. Compressed ''SVGZ'' +are explicitly not supported. Instead, the [=pkt_compression=] field +must be used if compression is to be used. This is due to DEFLATE +([[RFC1951]]) being potentially a bottleneck in decompression. + +No support for animated SVG ([[SVG2#animated-mode]]) is available, or any +SVG variant with ''Javascript'' embedded. Each SVG packet must be a raw and +standalone. Embedded images are, however, permitted. + +The width and height dimensions of [[#video-information-packets]] +shall be a suggested dimension, generally set upon creation time. + +Note: SVG streams may be either video streams or used as subtitles. +The {{STREAM_SUBTITLES}} flags must be set if the SVG stream is to be used as +subtitles. + + ### Raw audio encapsulation ### {#raw-audio-encapsulation} For raw audio encapsulation, the [=codec_id=] in @@ -2994,7 +3235,7 @@ laid out in the following way: - + @@ -3043,7 +3284,7 @@ laid out in the following way: - + @@ -3292,7 +3533,7 @@ packets to be sent without fragmentation. [[RFC2675|Jumbograms]] may be used where supported to reduce overhead and increase efficiency. -Data packets may be padded by appending random data or zeroes after the [=packet_data=] +Note: Data packets may be padded by appending random data or zeroes after the [=packet_data=] field up to the maximum MTU size. This permits constant bitrate operation, as well as preventing metadata leakage in the form of a packet size. @@ -3304,7 +3545,7 @@ sender using the same port number that the receiver is listening on. UDP-Lite ([[RFC3828]]) should be preferred to [[RFC768|UDP]], if support for it is available throughout the network.
-When using UDP-Lite, the same considerations as UDP apply. +When using UDP-Lite, the same considerations and notes as UDP apply. As UDP-Lite allows for variable checksum coverage, the minimum checksum coverage must be used, where only the UDP-Lite header (8 bytes) is checksummed. @@ -3385,68 +3626,68 @@ from a transmitter, with bit {{SESSION_REVERSE_SIGNAL_READY}} set in the [=sessi bitmask before they are allowed to send packets back. -### Control data ### {#control-data-packets} +### Session control data ### {#session-control-data-packets} The receiver can use this type to return errors and more to the sender in a one-to-one transmission. The following syntax is used:
-
Descriptor valueName Structure Description
''0x0600''[[#generic-data-segment-packets]]Non-final segment for segmented user data.
''0x0601''user_data_segment_descriptor [[#generic-data-segment-packets]]Final segment of segmented user data.Non-final segment for segmented user data.
''0x0602''user_data_parity_descriptor [[#generic-data-parity-packets]] Parity data for user data.
Data Description
b(16)duration_descriptorstream_duration_descriptor ''0x0050'' Indicates this is a stream duration packet.
b(16) [=stream_id=] Indicates the stream ID for the index. May be ''0xFFFF'', in which case, it applies to all streams.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
i(64) total_duration The total duration of the stream(s).
b(96) [=padding=] Padding, reserved for future use. Must be 0x0.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=]Data Description
b(16)eos_descriptorstream_end_descriptor ''0x0FFF'' Indicates this is a stream duration packet.
b(16) [=stream_id=] Indicates the stream ID for the index. May be ''0xFFFF'', in which case, it applies to all streams.
b(32) [=global_seq=] Monotonically incrementing per-packet global sequence number.
b(160) [=padding=] Padding, reserved for future use. Must be 0x0.
b(64) [=ldpc_288_224=] [=LDPC(288, 224)=]
Type NameDataValue Description
Type NameDataValue Description
Type NameDataValue Description
+
- + - + - + - + - + - + - + - + - + - + @@ -3479,9 +3720,9 @@ The following error values are allowed: ## Error Code Enumeration (enum ErrorCode) ## {#enum-ErrorCode}
- : ERROR_CODE_GENERIC = 0x1 + : ERROR_CODE_GENERIC = 0x1 :: Signals a generic error. - : ERROR_CODE_UNSUPPORTED = 0x2 + : ERROR_CODE_UNSUPPORTED = 0x2 :: Unsupported data. May be sent after the sender sends a [[#stream-registration-packets]] to indicate that the receiver does not support this codec. The sender may send another packet of this type with the same [=stream_id=] to attempt reinitialization with different parameters.
@@ -3498,43 +3739,43 @@ The following packet MAY be sent from the receiver to the sender. - + - + - + - + - + - + - + - + @@ -3561,19 +3802,19 @@ that was likely dropped. - + - + - + - + @@ -3595,19 +3836,19 @@ The receiver can use this type to subscribe or unsubscribe from streams. - + - + - + - + diff --git a/libavtransport/buffer.c b/libavtransport/buffer.c index 81cea3b..145f28b 100644 --- a/libavtransport/buffer.c +++ b/libavtransport/buffer.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -100,7 +101,7 @@ AVTBuffer *avt_buffer_reference(AVTBuffer *buffer, ptrdiff_t offset, int64_t len return ret; } -int pq_buffer_offset(AVTBuffer *buf, ptrdiff_t offset) +int avt_buffer_offset(AVTBuffer *buf, ptrdiff_t offset) { if (buf->base_data + offset > buf->end_data) return AVT_ERROR(EINVAL); @@ -110,7 +111,7 @@ int pq_buffer_offset(AVTBuffer *buf, ptrdiff_t offset) return 0; } -int pq_buffer_quick_ref(AVTBuffer *dst, AVTBuffer *buffer, +int avt_buffer_quick_ref(AVTBuffer *dst, AVTBuffer *buffer, ptrdiff_t offset, int64_t len) { if (!buffer) @@ -133,7 +134,7 @@ int pq_buffer_quick_ref(AVTBuffer *dst, AVTBuffer *buffer, return 0; } -void pq_buffer_quick_unref(AVTBuffer *buf) +void avt_buffer_quick_unref(AVTBuffer *buf) { if (!buf) return; @@ -177,7 +178,7 @@ void avt_buffer_unref(AVTBuffer **buffer) if (!buffer) return; - pq_buffer_quick_unref(buf); + avt_buffer_quick_unref(buf); free(buf); } diff --git a/libavtransport/buffer.h b/libavtransport/buffer.h index 9e39681..0d15147 100644 --- a/libavtransport/buffer.h +++ b/libavtransport/buffer.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_BUFFER @@ -42,11 +43,11 @@ struct AVTBuffer { atomic_int *refcnt; }; -int pq_buffer_quick_ref(AVTBuffer *dst, AVTBuffer *buffer, +int avt_buffer_quick_ref(AVTBuffer *dst, AVTBuffer *buffer, ptrdiff_t offset, int64_t len); -void pq_buffer_quick_unref(AVTBuffer *buf); +void avt_buffer_quick_unref(AVTBuffer *buf); -int pq_buffer_offset(AVTBuffer *buf, ptrdiff_t offset); +int avt_buffer_offset(AVTBuffer *buf, ptrdiff_t offset); #endif diff --git a/libavtransport/bytestream.h b/libavtransport/bytestream.h new file mode 100644 index 0000000..4c19a23 --- /dev/null +++ b/libavtransport/bytestream.h @@ -0,0 +1,315 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_BYTESTREAM +#define LIBAVTRANSPORT_BYTESTREAM + +#include +#include + +#include "utils.h" + +#ifndef PQ_RB8 +#define PQ_RB8(x) \ + (((const uint8_t *)(x))[0]) +#endif + +#ifndef PQ_RL8 +#define PQ_RL8(x) \ + (((const uint8_t *)(x))[0]) +#endif + +#ifndef PQ_WB8 +#define PQ_WB8(p, val) \ + do { \ + uint8_t d = (val); \ + ((uint8_t *)(p))[0] = (d); \ + } while(0) +#endif + +#ifndef PQ_WL8 +#define PQ_WL8(p, val) \ + do { \ + uint8_t d = (val); \ + ((uint8_t *)(p))[0] = (d); \ + } while(0) +#endif + +#ifndef PQ_RB16 +#define PQ_RB16(x) \ + ((((const uint8_t *)(x))[0] << 8) | ((const uint8_t *)(x))[1]) +#endif + +#ifndef PQ_RL16 +#define PQ_RL16(x) \ + ((((const uint8_t *)(x))[1] << 8) | ((const uint8_t *)(x))[0]) +#endif + +#ifndef PQ_WB16 +#define PQ_WB16(p, val) \ + do { \ + uint16_t d = (val); \ + ((uint8_t *)(p))[1] = (d) >> 0; \ + ((uint8_t *)(p))[0] = (d) >> 8; \ + } while(0) +#endif + +#ifndef PQ_WL16 +#define PQ_WL16(p, val) \ + do { \ + uint16_t d = (val); \ + ((uint8_t *)(p))[0] = (d) >> 0; \ + ((uint8_t *)(p))[1] = (d) >> 8; \ + } while(0) +#endif + +#ifndef PQ_RB32 +#define PQ_RB32(x) \ + ((uint32_t)((((uint32_t)(((const uint8_t *)(x))[0])) << 24) | \ + (((uint32_t)(((const uint8_t *)(x))[1])) << 16) | \ + (((uint32_t)(((const uint8_t *)(x))[2])) << 8) | \ + (((uint32_t)(((const uint8_t *)(x))[3])) << 0))) +#endif + +#ifndef PQ_RL32 +#define PQ_RL32(x) \ + ((uint32_t)((((uint32_t)(((const uint8_t *)(x))[3])) << 24) | \ + (((uint32_t)(((const uint8_t *)(x))[2])) << 16) | \ + (((uint32_t)(((const uint8_t *)(x))[1])) << 8) | \ + (((uint32_t)(((const uint8_t *)(x))[0])) << 0))) +#endif + +#ifndef PQ_WB32 +#define PQ_WB32(p, val) \ + do { \ + uint32_t d = (val); \ + ((uint8_t *)(p))[3] = (d) >> 0; \ + ((uint8_t *)(p))[2] = (d) >> 8; \ + ((uint8_t *)(p))[1] = (d) >> 16; \ + ((uint8_t *)(p))[0] = (d) >> 24; \ + } while(0) +#endif + +#ifndef PQ_WL32 +#define PQ_WL32(p, val) \ + do { \ + uint32_t d = (val); \ + ((uint8_t *)(p))[0] = (d) >> 0; \ + ((uint8_t *)(p))[1] = (d) >> 8; \ + ((uint8_t *)(p))[2] = (d) >> 16; \ + ((uint8_t *)(p))[3] = (d) >> 24; \ + } while(0) +#endif + +#ifndef PQ_RB64 +#define PQ_RB64(x) \ + ((uint64_t)((((uint64_t)(((const uint8_t *)(x))[0])) << 56) | \ + (((uint64_t)(((const uint8_t *)(x))[1])) << 48) | \ + (((uint64_t)(((const uint8_t *)(x))[2])) << 40) | \ + (((uint64_t)(((const uint8_t *)(x))[3])) << 32) | \ + (((uint64_t)(((const uint8_t *)(x))[4])) << 24) | \ + (((uint64_t)(((const uint8_t *)(x))[5])) << 16) | \ + (((uint64_t)(((const uint8_t *)(x))[6])) << 8) | \ + (((uint64_t)(((const uint8_t *)(x))[7])) << 0))) +#endif + +#ifndef PQ_RL64 +#define PQ_RL64(x) \ + ((uint64_t)((((uint64_t)(((const uint8_t *)(x))[7])) << 56) | \ + (((uint64_t)(((const uint8_t *)(x))[6])) << 48) | \ + (((uint64_t)(((const uint8_t *)(x))[5])) << 40) | \ + (((uint64_t)(((const uint8_t *)(x))[4])) << 32) | \ + (((uint64_t)(((const uint8_t *)(x))[3])) << 24) | \ + (((uint64_t)(((const uint8_t *)(x))[2])) << 16) | \ + (((uint64_t)(((const uint8_t *)(x))[1])) << 8) | \ + (((uint64_t)(((const uint8_t *)(x))[0])) << 0))) +#endif + +#ifndef PQ_WB64 +#define PQ_WB64(p, val) \ + do { \ + uint64_t d = (val); \ + ((uint8_t *)(p))[7] = (d) >> 0; \ + ((uint8_t *)(p))[6] = (d) >> 8; \ + ((uint8_t *)(p))[5] = (d) >> 16; \ + ((uint8_t *)(p))[4] = (d) >> 24; \ + ((uint8_t *)(p))[3] = (d) >> 32; \ + ((uint8_t *)(p))[2] = (d) >> 40; \ + ((uint8_t *)(p))[1] = (d) >> 48; \ + ((uint8_t *)(p))[0] = (d) >> 56; \ + } while(0) +#endif + +#ifndef PQ_WL64 +#define PQ_WL64(p, val) \ + do { \ + uint64_t d = (val); \ + ((uint8_t *)(p))[0] = (d) >> 0; \ + ((uint8_t *)(p))[1] = (d) >> 8; \ + ((uint8_t *)(p))[2] = (d) >> 16; \ + ((uint8_t *)(p))[3] = (d) >> 24; \ + ((uint8_t *)(p))[4] = (d) >> 32; \ + ((uint8_t *)(p))[5] = (d) >> 40; \ + ((uint8_t *)(p))[6] = (d) >> 48; \ + ((uint8_t *)(p))[7] = (d) >> 56; \ + } while(0) +#endif + +#if CONFIG_BIG_ENDIAN +#define PQ_RN(p, l) PQ_RB##l(p) +#define PQ_WN(p, l, v) PQ_WB##l(p, v) +#else +#define PQ_RN(p, l) PQ_RL##l(p) +#define PQ_WN(p, l, v) PQ_WL##l(p, v) +#endif + +typedef struct PQByteStream { + uint8_t *start; + uint8_t *ptr; + uint8_t *end; +} PQByteStream; + +/* Initialize bytestream for reading or writing */ +PQByteStream *pq_bs_init(uint8_t *buf, size_t len) +{ + return (PQByteStream) { + .start = buf, + .ptr = buf, + .end = buf + len, + }; +} + +/* Reset bytestream reader/writer */ +void inline pq_bs_reset(PQByteStream *bs) +{ + bs->ptr = bs->start; +} + +#define PQ_WRITE(en, n, len) \ +void inline pq_bsw_u##len##n(PQByteStream *bs, uint##len_t val) \ +{ \ + pq_assert1(((bs->ptr) + (l >> 3)) <= bs->end); \ + en##l(bs->ptr, t.val); \ + bs->ptr += l >> 3; \ +} \ + \ +void inline pq_bsw_i##len##n(PQByteStream *bs, int##len_t _val) \ +{ \ + pq_assert1(((bs->ptr) + (l >> 3)) <= bs->end); \ + union t { int##len_t _val, uint##len_t val }; \ + en##l(bs->ptr, t.val); \ + bs->ptr += l >> 3; \ +} + +PQ_WRITE_FN(PQ_WB, b, 8) +PQ_WRITE_FN(PQ_WB, b, 16) +PQ_WRITE_FN(PQ_WB, b, 32) +PQ_WRITE_FN(PQ_WB, b, 64) + +PQ_WRITE_FN(PQ_LB, l, 8) +PQ_WRITE_FN(PQ_LB, l, 16) +PQ_WRITE_FN(PQ_LB, l, 32) +PQ_WRITE_FN(PQ_LB, l, 64) + +#define PQ_WRITE_RATIONAL(en, n) \ +void inline pq_bsw_rt##n(PQByteStream *bs, AVTRational *r) \ +{ \ + pq_assert1(((bs->ptr) + 8) <= bs->end); \ + union { int##len_t _val, uint##len_t val } t[2]; \ + t[0]._val = r.num; \ + t[1]._val = r.den; \ + en##32(bs->ptr, t[0].val); \ + en##32(bs->ptr, t[1].val); \ + bs->ptr += 8; \ +} + +PQ_WRITE_RATIONAL(PQ_WB, be) +PQ_WRITE_RATIONAL(PQ_WB, le) + +/* Write padding */ +void inline pq_bsw_zpad(PQByteStream *bs, size_t len) +{ + pq_assert1(((bs->ptr) + len) <= bs->end); + memset(bs->ptr, 0, len); + bs->ptr += len; +} + +/* Write buffer to bytestream */ +void inline pq_bsw_sbuf(PQByteStream *bs, void *buf, size_t len) +{ + pq_assert1(((bs->ptr) + len) <= bs->end); + memcpy(bs->ptr, buf, len); + bs->ptr += len; +} + +/* Write fixed-length zero-terminated string to bytestream */ +void inline pq_bsw_fstr(PQByteStream *bs, const char *str, size_t fixed_len) +{ + size_t lens = AVTMIN(strlen(str), fixed_len - 1); + pq_assert1(((bs->ptr) + fixed_len) <= bs->end); + memcpy(bs->ptr, str, lens); + memset(bs->ptr, 0, fixed_len - lens); + bs->ptr += fixed_len; +} + +uint8_t *pq_bs_pos(PQByteStream *bs) +{ + return bs->ptr; +} + +size_t pq_bs_offs(PQByteStream *bs) +{ + return bs->ptr - bs->start; +} + +#define PQ_RDR(base_read, e, len, s) \ +static inline uint ##len## _t pq_bs_read_##e##len(PQByteStream *bs) \ +{ \ + uint ##len## _t v; \ + if ((bs)->ptr + (len >> 3) <= (bs)->end) { \ + v = base_read##len((bs)->ptr); \ + (bs)->ptr += len >> 3; \ + } \ + return v; \ +} + +static inline void pq_bs_skip(PQByteStream *bs, size_t len) +{ + if (bs->ptr + (len >> 3) <= bs->end) + bs->ptr += len >> 3; +} + +PQ_RDR(PQ_RB, b, 8, i) +PQ_RDR(PQ_RL, l, 8, i) +PQ_RDR(PQ_RB, b, 16, i) +PQ_RDR(PQ_RL, l, 16, i) +PQ_RDR(PQ_RB, b, 32, i) +PQ_RDR(PQ_RL, l, 32, i) +PQ_RDR(PQ_RB, b, 64, i) +PQ_RDR(PQ_RL, l, 64, i) + +#endif + diff --git a/libavtransport/common.c b/libavtransport/common.c index 9f89b51..821d447 100644 --- a/libavtransport/common.c +++ b/libavtransport/common.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -54,18 +55,20 @@ int avt_init(AVTContext **ctx, AVTContextOptions *opts) void avt_close(AVTContext **ctx) { if (ctx) { - pq_reorder_uninit(*ctx); + avt_reorder_uninit(*ctx); free(*ctx); *ctx = NULL; } } -int pq_parse_address(const char *path, enum PQProtocolType *proto, - uint8_t dst_ip[16], uint16_t *dst_port) +int avt_parse_address(const char *path, enum AVTProtocolType *proto, + uint8_t dst_ip[16], uint16_t *dst_port) { + int native_uri = 0; + /* Zero out output */ - *proto = PQ_UNKNOWN; + *proto = AVT_UNKNOWN; dst_ip = (uint8_t [16]){ 0 }; *dst_port = 0; @@ -74,25 +77,35 @@ int pq_parse_address(const char *path, enum PQProtocolType *proto, return AVT_ERROR(ENOMEM); char *tmp = NULL; - char *protocol = strtok_r(dup, ":", &tmp); /* Protocol */ - if (!strcmp(protocol, "udp")) { - *proto = PQ_UDP; - } else if (!strcmp(protocol, "quic")) { - *proto = PQ_QUIC; + char *scheme = strtok_r(dup, ":", &tmp); + if (!strcmp(scheme, "avt")) { + native_uri = 1; + } else if (!strcmp(scheme, "udp")) { /* Unofficial and conflicting, but let's accept it */ + *proto = AVT_UDP; + } else if (!strcmp(scheme, "quic")) { /* Unofficial, but let's accept it */ + *proto = AVT_QUIC; } else { free(dup); return AVT_ERROR(ENOTSUP); } - char *addr_pre = strtok_r(protocol, ":", &tmp); + char *addr_pre = strtok_r(scheme, ":", &tmp); if (!strcmp(addr_pre, "//") && (addr_pre[2])) { addr_pre += 2; - } else { + } else { /* Error out if there's no :// */ free(dup); return AVT_ERROR(ENOTSUP); } - if (addr_pre[0] == '[') { + if (native_uri) { + char *transport = strtok_r(addr_pre, "@", &tmp); + char *serv = strtok_r(transport, "@", &tmp); + if (!serv) + addr_pre = transport; + } + + if (addr_pre[0]) { + } else if (addr_pre[0] == '[') { tmp = NULL; char *endb = strtok_r(addr_pre, "]", &tmp); @@ -195,7 +208,7 @@ AVTStream *avt_find_stream(AVTContext *ctx, uint16_t id) return ctx->stream[i]; } -void pq_log(void *ctx, enum AVTLogLevel level, const char *fmt, ...) +void avt_log(void *ctx, enum AVTLogLevel level, const char *fmt, ...) { va_list args; va_start(args, fmt); diff --git a/libavtransport/common.h b/libavtransport/common.h index 9c4a4fb..e4cbfd4 100644 --- a/libavtransport/common.h +++ b/libavtransport/common.h @@ -1,64 +1,65 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_COMMON #define LIBAVTRANSPORT_COMMON -#include -#include -#include #include -enum PQProtocolType { - PQ_UNKNOWN, - PQ_UDP, - PQ_QUIC, +#include +#include + +enum AVTProtocolType { + AVT_UNKNOWN, + AVT_UDP, + AVT_QUIC, }; -typedef struct PQStreamPriv { +typedef struct AVTStreamPriv { enum AVTCodecID codec_id; -} PQStreamPriv; +} AVTStreamPriv; struct AVTContext { struct { - AVTOutputDestination dst; - const struct PQOutput *cb; - struct PQOutputContext *ctx; +// AVTOutputDestination dst; + const struct AVTOutput *cb; + struct AVTOutputContext *ctx; atomic_uint seq; uint64_t epoch; } dst; struct { - AVTInputSource src; - const struct PQInput *cb; - struct PQInputContext *ctx; - AVTInputCallbacks proc; +// AVTInputSource src; + const struct AVTInput *cb; + struct AVTInputContext *ctx; +// AVTInputCallbacks proc; void *cb_opaque; atomic_uint seq; uint64_t epoch; - struct PQReorder *rctx; + struct AVTReorder *rctx; } src; AVTStream **stream; @@ -67,78 +68,18 @@ struct AVTContext { AVTContextOptions opts; }; -enum PQPacketType { - /* Indicates the 8 least significant bits are a mask */ - AVT_PKT_FLAG_LSB_MASK = (1 << 31), - - AVT_PKT_SESSION_START = 0x4156, - - AVT_PKT_STREAM_REG = 0x2, - - AVT_PKT_STREAM_INIT = 0x3, - AVT_PKT_STREAM_INIT_PRT = 0x4, - AVT_PKT_STREAM_INIT_SEG = 0x5, - AVT_PKT_STREAM_INIT_END = 0x6, - AVT_PKT_STREAM_INIT_FEC = 0x7, - - AVT_PKT_VIDEO_INFO = 0x8, - AVT_PKT_INDEX = 0x9, - AVT_PKT_TIME_SYNC = 0, - - AVT_PKT_METADATA = 0xA, - AVT_PKT_METADATA_PRT = 0xB, - AVT_PKT_METADATA_SEG = 0xC, - AVT_PKT_METADATA_END = 0xD, - AVT_PKT_METADATA_FEC = 0xE, - - AVT_PKT_ICC = 0x10, - AVT_PKT_ICC_PRT = 0x11, - AVT_PKT_ICC_SEG = 0x12, - AVT_PKT_ICC_END = 0x13, - AVT_PKT_ICC_FEC = 0x14, - - AVT_PKT_FONT = 0x20, - AVT_PKT_FONT_PRT = 0x21, - AVT_PKT_FONT_SEG = 0x22, - AVT_PKT_FONT_END = 0x23, - AVT_PKT_FONT_FEC = 0x24, - - AVT_PKT_FEC_GROUP_REG = 0x30, - AVT_PKT_FEC_GROUP_DATA = 0x31, - - AVT_PKT_VIDEO_ORIENTATION = 0x40, - - AVT_PKT_STREAM_FEC_DATA = 0xFC, - AVT_PKT_STREAM_FEC_END = 0xFD, - - AVT_PKT_STREAM_SEG_DATA = 0xFE, - AVT_PKT_STREAM_SEG_END = 0xFF, - - AVT_PKT_STREAM_DATA = 0x01FF | AVT_PKT_FLAG_LSB_MASK, - AVT_PKT_USER_DATA = 0x40FF | AVT_PKT_FLAG_LSB_MASK, - - AVT_PKT_STREAM_DURATION = 0xF000, - AVT_PKT_EOS = 0xFFFF, - - AVT_PKT_REV_USER_DATA = 0x50FF | AVT_PKT_FLAG_LSB_MASK, - AVT_PKT_REV_CONTROL = 0x8001, - AVT_PKT_REV_FEEDBACK = 0x8002, - AVT_PKT_REV_RESEND = 0x8003, - AVT_PKT_REV_STREAM_CONTROL = 0x8004, -}; - -int pq_parse_address(const char *path, enum PQProtocolType *proto, - uint8_t dst_ip[16], uint16_t *dst_port); +int avt_parse_address(const char *path, enum AVTProtocolType *proto, + uint8_t dst_ip[16], uint16_t *dst_port); AVTStream *avt_alloc_stream(AVTContext *ctx, uint16_t id); AVTStream *avt_find_stream(AVTContext *ctx, uint16_t id); #if defined(__GNUC__) || defined(__clang__) -#define pq_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos))) +#define avt_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos))) #else -#define pq_printf_format(fmtpos, attrpos) +#define avt_printf_format(fmtpos, attrpos) #endif -void pq_log(void *ctx, enum AVTLogLevel level, const char *fmt, ...) pq_printf_format(3, 4); +void avt_log(void *ctx, enum AVTLogLevel level, const char *fmt, ...) avt_printf_format(3, 4); #endif diff --git a/libavtransport/include/libavtransport/avtransport.h b/libavtransport/include/libavtransport/avtransport.h new file mode 100644 index 0000000..a694f18 --- /dev/null +++ b/libavtransport/include/libavtransport/avtransport.h @@ -0,0 +1,87 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_VIDEO_HEADER +#define LIBAVTRANSPORT_VIDEO_HEADER + +typedef struct AVTContext AVTContext; +typedef struct AVTMetadata AVTMetadata; + +#include + +/* Connection type */ +enum AVTConnectionType { + /* URL address in the form of: + * avt://[@]
[:] + * - may be either missing (fallback to UDP), + * "udp", "udplite", or "quic" + * -
of the remote host, or multicast group + * - on which to listen to/transmit on + */ + AVT_CONNECTION_URL, + + /* Reverse connectivity for senders/receivers. + * The context MUST already have an output or input initialized. */ + AVT_CONNECTION_REVERSE, + + /* File path */ + AVT_CONNECTION_FILE, + + /* Socket */ + AVT_CONNECTION_SOCKET, + + /* File descriptor */ + AVT_CONNECTION_FD, + + /* Raw reader/writer using callbacks. */ + AVT_CONNECTION_CALLBACKS, +}; + +enum AVTLogLevel { + AVT_LOG_QUIET = -(1 << 0), + AVT_LOG_FATAL = (0 << 0), + AVT_LOG_ERROR = +(1 << 0), + AVT_LOG_WARN = +(1 << 1), + AVT_LOG_INFO = +(1 << 2), + AVT_LOG_VERBOSE = +(1 << 3), + AVT_LOG_DEBUG = +(1 << 4), + AVT_LOG_TRACE = +(1 << 5), +}; + +typedef struct AVTContextOptions { + void *log_opaque; + void (*log_cb)(void *log_opaque, enum AVTLogLevel level, + const char *format, va_list args, int error); +} AVTContextOptions; + +/* Allocate an AVTransport context with the given context options. */ +AVT_API int avt_init(AVTContext **ctx, AVTContextOptions *opts); + +/* Uninitialize a context, closing all connections and files gracefully, + * and free all memory used. */ +AVT_API void avt_close(AVTContext **ctx); + +#endif /* LIBAVTRANSPORT_VIDEO_HEADER */ diff --git a/libavtransport/include/libavtransport/common.h b/libavtransport/include/libavtransport/common.h index a1ce59b..d863f5a 100644 --- a/libavtransport/include/libavtransport/common.h +++ b/libavtransport/include/libavtransport/common.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_COMMON_HEADER @@ -32,51 +33,10 @@ #include #include -#include #include - -typedef struct AVTContext AVTContext; -typedef struct AVTMetadata AVTMetadata; - -enum AVTConnectionType { - /* Reverse connectivity for senders/receivers. - * The context MUST already have an output or input initialized. */ - AVT_CONNECTION_REVERSE = 1, - - /* URL address in the form of: - * ://
: - * MUST be "udp", "udplite" OR "quic" */ - AVT_CONNECTION_URL, - - /* File path */ - AVT_CONNECTION_FILE, - - /* Socket */ - AVT_CONNECTION_SOCKET, - - /* File descriptor */ - AVT_CONNECTION_FD, - - /* Raw reader/writer using callbacks. */ - AVT_CONNECTION_CALLBACKS, -}; - -enum AVTLogLevel { - AVT_LOG_QUIET = -(1 << 0), - AVT_LOG_FATAL = (0 << 0), - AVT_LOG_ERROR = +(1 << 0), - AVT_LOG_WARN = +(1 << 1), - AVT_LOG_INFO = +(1 << 2), - AVT_LOG_VERBOSE = +(1 << 3), - AVT_LOG_DEBUG = +(1 << 4), - AVT_LOG_TRACE = +(1 << 5), -}; - -typedef struct AVTContextOptions { - void *log_opaque; - void (*log_cb)(void *log_opaque, enum AVTLogLevel level, - const char *format, va_list args, int error); -} AVTContextOptions; +#include +#include +#include enum AVTCodecID { AVT_CODEC_RAW_VIDEO = 1, @@ -91,6 +51,7 @@ enum AVTCodecID { AVT_CODEC_ASS = 65536, }; +#if 0 enum AVTFrameType { AVT_KEYFRAME = 0x80, AVT_S_FRAME = 0x40, @@ -99,6 +60,7 @@ enum AVTFrameType { enum AVTStreamFlags { AVT_STREAM_STILL_PICTURE = 1, }; +#endif typedef struct AVTStream { uint32_t id; @@ -108,7 +70,7 @@ typedef struct AVTStream { /* Duration in nanoseconds, if known. */ uint64_t duration; - AVTStreamVideoInfo video_info; + AVTVideoInfo video_info; AVTBuffer *icc_profile; enum AVTStreamFlags flags; @@ -121,7 +83,7 @@ typedef struct AVTStream { struct AVTStream *derived_from; /* libavtransport private stream data. Do not use. */ - struct PQStreamPriv *private; + struct AVTStreamPriv *private; } AVTStream; typedef struct AVTPacket { @@ -133,11 +95,4 @@ typedef struct AVTPacket { int64_t duration; } AVTPacket; -/* Allocate an AVTransport context with the given context options. */ -int avt_init(AVTContext **ctx, AVTContextOptions *opts); - -/* Uninitialize a context, closing all connections and files gracefully, - * and free all memory used. */ -void avt_close(AVTContext **ctx); - #endif diff --git a/libavtransport/include/libavtransport/input.h b/libavtransport/include/libavtransport/input.h index 88d6ecc..3517d71 100644 --- a/libavtransport/include/libavtransport/input.h +++ b/libavtransport/include/libavtransport/input.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_INPUT_HEADER @@ -87,27 +88,27 @@ typedef struct AVTInputOptions { } AVTInputOptions; /* Open an AVTransport stream or a file for reading. */ -int avt_input_open(AVTContext *ctx, AVTInputSource *src, - AVTInputCallbacks *cb, void *cb_opaque, - AVTInputOptions *opts); +AVT_API int avt_input_open(AVTContext *ctx, AVTInputSource *src, + AVTInputCallbacks *cb, void *cb_opaque, + AVTInputOptions *opts); /* Adjusts input options on the fly. */ -int avt_input_set_options(AVTContext *ctx, AVTInputOptions *opts); +AVT_API int avt_input_set_options(AVTContext *ctx, AVTInputOptions *opts); /* Seek into the stream, if possible. */ -int avt_input_seek(AVTContext *ctx, AVTStream *st, int64_t offset, int absolute); +AVT_API int avt_input_seek(AVTContext *ctx, AVTStream *st, int64_t offset, int absolute); /* Process a single packet and call its relevant callback. If no input is * available within the timeout duration (nanoseconds), * will return AVT_ERROR(EAGAIN). * Can be called multiple times from different threads. */ -int avt_input_process(AVTContext *ctx, int64_t timeout); +AVT_API int avt_input_process(AVTContext *ctx, int64_t timeout); /* Start a thread that will call avt_input_process as data becomes available. * Otherwise, avt_input_process() may be called manually. */ -int avt_input_start_thread(AVTContext *ctx); +AVT_API int avt_input_start_thread(AVTContext *ctx); /* Close input and free all associated data with it. */ -int avt_input_close(AVTContext *ctx); +AVT_API int avt_input_close(AVTContext *ctx); #endif diff --git a/libavtransport/include/libavtransport/meson.build b/libavtransport/include/libavtransport/meson.build new file mode 100644 index 0000000..7b79e81 --- /dev/null +++ b/libavtransport/include/libavtransport/meson.build @@ -0,0 +1,8 @@ +inc_dir = get_option('includedir') + '/libavtransport' + +conv_spec_headers = custom_target('packet*', + install: true, + install_dir: [ inc_dir, inc_dir ], + input: spec_file, + output: ['packet_enums.h', 'packet_data.h'], + command: [python_exe, spec2c, 'packet_enums,packet_data', '@INPUT@', '@OUTPUT0@', '@OUTPUT1@']) diff --git a/libavtransport/include/libavtransport/output.h b/libavtransport/include/libavtransport/output.h index a317806..02df9e4 100644 --- a/libavtransport/include/libavtransport/output.h +++ b/libavtransport/include/libavtransport/output.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_OUTPUT_HEADER @@ -78,45 +79,45 @@ typedef struct AVTOutputOptions { } AVTOutputOptions; /* Open an output and immediately send a stream session packet */ -int avt_output_open(AVTContext *ctx, AVTOutputDestination *dst, - AVTOutputOptions *opts); +AVT_API int avt_output_open(AVTContext *ctx, AVTOutputDestination *dst, + AVTOutputOptions *opts); /* Send an epoch packet and set the epoch to use. */ -int avt_output_set_epoch(AVTContext *ctx, uint64_t epoch); +AVT_API int avt_output_set_epoch(AVTContext *ctx, uint64_t epoch); /* Register a stream and allocate internal state for it. * To automatically assign a stream ID, set id to 65536. * If there's an existing stream with the same ID, will return NULL. */ -AVTStream *avt_output_add_stream(AVTContext *ctx, uint16_t id); +AVT_API AVTStream *avt_output_add_stream(AVTContext *ctx, uint16_t id); /* Update a stream, (re-)emmitting a stream registration packet. * The id MUST match the one from avt_output_add_stream(). */ -int avt_output_update_stream(AVTContext *ctx, AVTStream *st); +AVT_API int avt_output_update_stream(AVTContext *ctx, AVTStream *st); -int avt_output_add_font(AVTContext *ctx, AVTBuffer *data, const char *name); +AVT_API int avt_output_add_font(AVTContext *ctx, AVTBuffer *data, const char *name); /* Write data to output. Can be called from multiple threads at once. * If compiled with threads, actual output happens in a different thread. */ -int avt_output_write_stream_data(AVTContext *ctx, AVTStream *st, - AVTPacket *pkt); +AVT_API int avt_output_write_stream_data(AVTContext *ctx, AVTStream *st, + AVTPacket *pkt); /* Write user data packets */ -int avt_output_write_user_data(AVTContext *ctx, AVTBuffer *data, - uint8_t descriptor_flags, uint16_t user, - int prioritize); +AVT_API int avt_output_write_user_data(AVTContext *ctx, AVTBuffer *data, + uint8_t descriptor_flags, uint16_t user, + int prioritize); -int avt_output_close_stream(AVTContext *ctx, AVTStream *st); +AVT_API int avt_output_close_stream(AVTContext *ctx, AVTStream *st); -int avt_output_control(AVTContext *ctx, void *opaque, int cease, - int resend_init, int error, uint8_t redirect[16], - uint16_t redirect_port, int seek_requested, - int64_t seek_offset, uint32_t seek_seq); +AVT_API int avt_output_control(AVTContext *ctx, void *opaque, int cease, + int resend_init, int error, uint8_t redirect[16], + uint16_t redirect_port, int seek_requested, + int64_t seek_offset, uint32_t seek_seq); -int avt_output_feedback(AVTContext *ctx, void *opaque, AVTStream *st, - uint64_t epoch_offset, uint64_t bandwidth, - uint32_t fec_corrections, uint32_t corrupt_packets, - uint32_t missing_packets); +AVT_API int avt_output_feedback(AVTContext *ctx, void *opaque, AVTStream *st, + uint64_t epoch_offset, uint64_t bandwidth, + uint32_t fec_corrections, uint32_t corrupt_packets, + uint32_t missing_packets); -int avt_output_close(AVTContext *ctx); +AVT_API int avt_output_close(AVTContext *ctx); #endif diff --git a/libavtransport/include/libavtransport/rational.h b/libavtransport/include/libavtransport/rational.h new file mode 100644 index 0000000..699437b --- /dev/null +++ b/libavtransport/include/libavtransport/rational.h @@ -0,0 +1,36 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_RATIONAL_HEADER +#define LIBAVTRANSPORT_RATIONAL_HEADER + +/* Rational data type structure. */ +typedef struct AVTRational { + int num; + int den; +} AVTRational; + +#endif diff --git a/libavtransport/include/libavtransport/utils.h b/libavtransport/include/libavtransport/utils.h index 796d0ca..b068e21 100644 --- a/libavtransport/include/libavtransport/utils.h +++ b/libavtransport/include/libavtransport/utils.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_UTILS_HEADER @@ -29,39 +30,54 @@ #include #include -/* Rational data type structure. */ -typedef struct AVTRational { - int num; - int den; -} AVTRational; +#include + +/* Any function flagged with AVT_API is exported as a symbol */ +#ifndef AVT_API + #if defined _WIN32 + #if defined AVT_BUILDING_DLL + #define AVT_API __declspec(dllexport) + #else + #define AVT_API + #endif + #else + #if __GNUC__ >= 4 + #define AVT_API __attribute__ ((visibility ("default"))) + #else + #define AVT_API + #endif + #endif +#endif + +typedef struct AVTMetadata AVTMetadata; typedef struct AVTBuffer AVTBuffer; /* Create a reference counted buffer from existing data. */ -AVTBuffer *avt_buffer_create(uint8_t *data, size_t len, - void *opaque, void (*free_fn)(void *opaque, void *base_data)); +AVT_API AVTBuffer *avt_buffer_create(uint8_t *data, size_t len, + void *opaque, void (*free_fn)(void *opaque, void *base_data)); /* Default freeing callback for buffers that simply calls free(base_data) */ -void avt_buffer_default_free(void *opaque, void *base_data); +AVT_API void avt_buffer_default_free(void *opaque, void *base_data); /* Create and allocate a reference counted buffer. */ -AVTBuffer *avt_buffer_alloc(size_t len); +AVT_API AVTBuffer *avt_buffer_alloc(size_t len); /* References the buffer. Returns a new reference at the offset and length requested. * If offset AND length are 0, references the whole buffer. */ -AVTBuffer *avt_buffer_reference(AVTBuffer *buffer, ptrdiff_t offset, int64_t len); +AVT_API AVTBuffer *avt_buffer_reference(AVTBuffer *buffer, ptrdiff_t offset, int64_t len); /* Returns the current numer of references */ -int avt_buffer_get_refcount(AVTBuffer *buffer); +AVT_API int avt_buffer_get_refcount(AVTBuffer *buffer); /* Access the data in a buffer. Does not reference it. */ -void *avt_buffer_get_data(AVTBuffer *buffer, size_t *len); +AVT_API void *avt_buffer_get_data(AVTBuffer *buffer, size_t *len); /* Get the data length */ -size_t avt_buffer_get_data_len(AVTBuffer *buffer); +AVT_API size_t avt_buffer_get_data_len(AVTBuffer *buffer); /* Unreference a reference counted buffer. */ -void avt_buffer_unref(AVTBuffer **buffer); +AVT_API void avt_buffer_unref(AVTBuffer **buffer); /* All functions return negative values for errors. * This is a wrapper that's used to convert standard stderr values into diff --git a/libavtransport/include/libavtransport/video.h b/libavtransport/include/libavtransport/video.h deleted file mode 100644 index 1d8bd2c..0000000 --- a/libavtransport/include/libavtransport/video.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright © 2022 Lynne - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef LIBAVTRANSPORT_VIDEO_HEADER -#define LIBAVTRANSPORT_VIDEO_HEADER - -#include -#include - -#include - -enum AVTSubsampling { - AVT_SUB_444 = 0, - AVT_SUB_420 = 1, - AVT_SUB_422 = 2, -}; - -enum AVTColorspace { - AVT_COL_MONOCHROME = 0, - AVT_COL_RGB = 1, - AVT_COL_YUV = 2, - AVT_COL_YCOCGR = 3, - AVT_COL_YCGCOR = 4, - AVT_COL_XYZ = 5, - AVT_COL_XYB = 6, - AVT_COL_ICTCP = 7, -}; - -enum AVTChromaPos { - AVT_CHROMA_UNSPEC = 0, - AVT_CHROMA_LEFT = 1, - AVT_CHROMA_CENTER = 2, - AVT_CHROMA_TOPLEFT = 3, - AVT_CHROMA_TOP = 4, - AVT_CHROMA_BOTTOMLEFT = 5, - AVT_CHROMA_BOTTOM = 6, -}; - -enum AVTPrimaries { - AVT_PRIM_BT709 = 1, - AVT_PRIM_UNSPEC = 2, - AVT_PRIM_BT470 = 4, - AVT_PRIM_BT601_625 = 5, - AVT_PRIM_BT601_525 = 6, - AVT_PRIM_ST240 = 7, - AVT_PRIM_FILM = 8, - AVT_PRIM_BT2020 = 9, - AVT_PRIM_ST428 = 10, -}; - -enum AVTTransfer { - AVT_TRANSFER_BT709 = 1, - AVT_TRANSFER_UNSPEC = 2, - AVT_TRANSFER_FCC = 4, - AVT_TRANSFER_BT470 = 5, - AVT_TRANSFER_BT601 = 6, - AVT_TRANSFER_ST240 = 7, - AVT_TRANSFER_LINEAR = 8, - AVT_TRANSFER_LOG = 9, - AVT_TRANSFER_LOG_SQ = 10, - AVT_TRANSFER_BT1361 = 12, - AVT_TRANSFER_BT2020 = 14, - AVT_TRANSFER_ST2084 = 16, - AVT_TRANSFER_HLG = 18, -}; - -enum AVTMatrix { - AVT_MATRIX_IDENT = 0, - AVT_MATRIX_BT709 = 1, - AVT_MATRIX_UNSPEC = 2, - AVT_MATRIX_FCC = 4, - AVT_MATRIX_BT470 = 5, - AVT_MATRIX_BT601 = 6, - AVT_MATRIX_ST240 = 7, - AVT_MATRIX_YCGCO = 8, - AVT_MATRIX_BT2020_CL = 9, - AVT_MATRIX_BT2020_NCL = 10, - AVT_MATRIX_ST2085 = 11, - AVT_MATRIX_BT2100 = 14, -}; - -typedef struct AVTStreamVideoInfo { - uint32_t width; - uint32_t height; - AVTRational signal_aspect; - enum AVTSubsampling subsampling; - enum AVTColorspace colorspace; - uint8_t bit_depth; - uint8_t interlaced; - AVTRational gamma; - AVTRational framerate; - uint16_t limited_range; - enum AVTChromaPos chroma_pos; - enum AVTPrimaries primaries; - enum AVTTransfer transfer; - enum AVTMatrix matrix; - bool has_mastering_primaries; - - AVTRational custom_matrix[16]; - AVTRational custom_primaries[6]; - AVTRational white_point[2]; - - bool has_luminance; - AVTRational min_luminance; - AVTRational max_luminance; -} AVTStreamVideoInfo; - -#endif diff --git a/libavtransport/input.c b/libavtransport/input.c index f1c24b8..bb9b2cc 100644 --- a/libavtransport/input.c +++ b/libavtransport/input.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "common.h" diff --git a/libavtransport/input.h b/libavtransport/input.h index 95c9926..cee5201 100644 --- a/libavtransport/input.h +++ b/libavtransport/input.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_INPUT diff --git a/libavtransport/input_file.c b/libavtransport/input_file.c index 95cfd25..419d3e6 100644 --- a/libavtransport/input_file.c +++ b/libavtransport/input_file.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/libavtransport/ldpc.c b/libavtransport/ldpc.c new file mode 100644 index 0000000..7c94088 --- /dev/null +++ b/libavtransport/ldpc.c @@ -0,0 +1,27 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ldpc.h" diff --git a/libavtransport/ldpc.h b/libavtransport/ldpc.h new file mode 100644 index 0000000..32a8d6e --- /dev/null +++ b/libavtransport/ldpc.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_LDPC +#define LIBAVTRANSPORT_LDPC + +#endif diff --git a/libavtransport/ldpc_decode.c b/libavtransport/ldpc_decode.c new file mode 100644 index 0000000..7c94088 --- /dev/null +++ b/libavtransport/ldpc_decode.c @@ -0,0 +1,27 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ldpc.h" diff --git a/libavtransport/ldpc_decode.h b/libavtransport/ldpc_decode.h new file mode 100644 index 0000000..26845d3 --- /dev/null +++ b/libavtransport/ldpc_decode.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_LDPC_DECODE +#define LIBAVTRANSPORT_LDPC_DECODE + +#endif diff --git a/libavtransport/ldpc_encode.c b/libavtransport/ldpc_encode.c new file mode 100644 index 0000000..7c94088 --- /dev/null +++ b/libavtransport/ldpc_encode.c @@ -0,0 +1,27 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ldpc.h" diff --git a/libavtransport/ldpc_encode.h b/libavtransport/ldpc_encode.h new file mode 100644 index 0000000..48da345 --- /dev/null +++ b/libavtransport/ldpc_encode.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2023, Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBAVTRANSPORT_LDPC_ENCODE +#define LIBAVTRANSPORT_LDPC_ENCODE + +#endif diff --git a/libavtransport/meson.build b/libavtransport/meson.build index 8c4e916..7dddce8 100644 --- a/libavtransport/meson.build +++ b/libavtransport/meson.build @@ -6,7 +6,8 @@ build_opts = [ '-Wpointer-arith', '-Wno-pointer-sign', # Warnings to treat as errors - '-Werror=implicit-function-declaration', + '-Werror=implicit-function-declaration', '-Werror=missing-prototypes', + '-Werror=vla', ] # Required dependencies @@ -18,19 +19,24 @@ dependencies = [ # Headers headers = [ - 'common.h', - 'input.h', - 'output.h' +# 'common.h', +# 'input.h', +# 'output.h' ] +subdir('include/libavtransport') + # Base files sources = [ 'common.c', 'buffer.c', - 'input.c', - 'output.c', - 'raptor.c', +# 'input.c', +# 'output.c', +# 'raptor.c', + + conv_spec, + conv_spec_headers, # Version vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], @@ -39,13 +45,13 @@ sources = [ ] if get_option('input').auto() - sources += 'input_file.c' +# sources += 'input_file.c' sources += 'reorder.c' endif if get_option('output').auto() - sources += 'output_file.c' - sources += 'output_socket.c' +# sources += 'output_file.c' +# sources += 'output_socket.c' endif # Check for wmain support (Windows/MinGW) diff --git a/libavtransport/output.c b/libavtransport/output.c index da48fd5..5999b48 100644 --- a/libavtransport/output.c +++ b/libavtransport/output.c @@ -1,36 +1,38 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include +#include "../packet_encode.h" #include "common.h" #include "output.h" -#include "utils.h" +#include "bytestream.h" #include "buffer.h" #include "raptor.h" @@ -44,6 +46,7 @@ static const PQOutput *pq_output_list[] = { NULL, }; +#if 0 int avt_output_open(AVTContext *ctx, AVTOutputDestination *dst, AVTOutputOptions *opts) { @@ -437,3 +440,4 @@ uint32_t pq_unlim_pkt_len(AVTContext *ctx, PQOutputContext *pc) { return UINT32_MAX; } +#endif diff --git a/libavtransport/output.h b/libavtransport/output.h index 374d010..e7055c8 100644 --- a/libavtransport/output.h +++ b/libavtransport/output.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_OUTPUT @@ -30,23 +31,23 @@ #include "common.h" -typedef struct PQOutputContext PQOutputContext; +typedef struct AVTOutputContext AVTOutputContext; -typedef struct PQOutput { +typedef struct AVTOutput { const char *name; enum AVTConnectionType type; - int (*init)(AVTContext *ctx, PQOutputContext **pc, + int (*init)(AVTContext *ctx, AVTOutputContext **pc, AVTOutputDestination *dst, AVTOutputOptions *opts); - uint32_t (*max_pkt_len)(AVTContext *ctx, PQOutputContext *pc); + uint32_t (*max_pkt_len)(AVTContext *ctx, AVTOutputContext *pc); - int (*output)(AVTContext *ctx, PQOutputContext *pc, + int (*output)(AVTContext *ctx, AVTOutputContext *pc, uint8_t *hdr, size_t hdr_len, AVTBuffer *buf); - int (*close)(AVTContext *ctx, PQOutputContext **pc); -} PQOutput; + int (*close)(AVTContext *ctx, AVTOutputContext **pc); +} AVTOutput; -uint32_t pq_unlim_pkt_len(AVTContext *ctx, PQOutputContext *pc); +uint32_t avt_unlim_pkt_len(AVTContext *ctx, AVTOutputContext *pc); #endif diff --git a/libavtransport/output_file.c b/libavtransport/output_file.c index 421fab3..9a5acc4 100644 --- a/libavtransport/output_file.c +++ b/libavtransport/output_file.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/libavtransport/output_socket.c b/libavtransport/output_socket.c index 2371572..b67fc17 100644 --- a/libavtransport/output_socket.c +++ b/libavtransport/output_socket.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/libavtransport/raptor.c b/libavtransport/raptor.c index 58f06ce..db6430a 100644 --- a/libavtransport/raptor.c +++ b/libavtransport/raptor.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/libavtransport/raptor.h b/libavtransport/raptor.h index 2871424..0d40eaf 100644 --- a/libavtransport/raptor.h +++ b/libavtransport/raptor.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_RAPTOR diff --git a/libavtransport/reorder.c b/libavtransport/reorder.c index a723dda..fe261c6 100644 --- a/libavtransport/reorder.c +++ b/libavtransport/reorder.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -29,45 +30,45 @@ #include "common.h" #include "buffer.h" -typedef struct PQBufEntry { +typedef struct AVTBufEntry { uint32_t seq; ptrdiff_t seg_offset; size_t seg_len; AVTBuffer data; - struct PQBufEntry *start; - struct PQBufEntry *prev; - struct PQBufEntry *next; -} PQBufEntry; + struct AVTBufEntry *start; + struct AVTBufEntry *prev; + struct AVTBufEntry *next; +} AVTBufEntry; -typedef struct PQReorder { - PQBufEntry *stream_data; +typedef struct AVTReorder { + AVTBufEntry *stream_data; - PQBufEntry **avail; + AVTBufEntry **avail; int nb_avail; - PQBufEntry **used; + AVTBufEntry **used; int nb_used; -} PQReorder; +} AVTReorder; -int pq_reorder_init(AVTContext *ctx, size_t max_buffer) +int avt_reorder_init(AVTContext *ctx, size_t max_buffer) { - PQReorder *reorder = ctx->src.rctx = calloc(1, sizeof(PQReorder)); + AVTReorder *reorder = ctx->src.rctx = calloc(1, sizeof(AVTReorder)); if (!ctx) return AVT_ERROR(ENOMEM); reorder->nb_avail = 32; - reorder->avail = calloc(reorder->nb_avail, sizeof(PQBufEntry *)); + reorder->avail = calloc(reorder->nb_avail, sizeof(AVTBufEntry *)); if (!reorder->avail) return AVT_ERROR(ENOMEM); - reorder->used = calloc(reorder->nb_avail, sizeof(PQBufEntry *)); + reorder->used = calloc(reorder->nb_avail, sizeof(AVTBufEntry *)); if (!reorder->used) return AVT_ERROR(ENOMEM); for (int i = 0; i < reorder->nb_avail; i++) { - reorder->avail[i] = calloc(1, sizeof(PQBufEntry)); + reorder->avail[i] = calloc(1, sizeof(AVTBufEntry)); if (!reorder->avail[i]) return AVT_ERROR(ENOMEM); } @@ -75,21 +76,21 @@ int pq_reorder_init(AVTContext *ctx, size_t max_buffer) return 0; } -static int pq_reorder_alloc(PQReorder *reorder) +static int avt_reorder_alloc(AVTReorder *reorder) { - PQBufEntry **atmp = realloc(reorder->avail, (reorder->nb_avail + 1)*sizeof(PQBufEntry *)); + AVTBufEntry **atmp = realloc(reorder->avail, (reorder->nb_avail + 1)*sizeof(AVTBufEntry *)); if (!atmp) return AVT_ERROR(ENOMEM); reorder->avail = atmp; - atmp = realloc(reorder->used, (reorder->nb_used + 1)*sizeof(PQBufEntry *)); + atmp = realloc(reorder->used, (reorder->nb_used + 1)*sizeof(AVTBufEntry *)); if (!atmp) return AVT_ERROR(ENOMEM); reorder->used = atmp; - atmp[reorder->nb_avail] = calloc(1, sizeof(PQBufEntry)); + atmp[reorder->nb_avail] = calloc(1, sizeof(AVTBufEntry)); if (!atmp[reorder->nb_avail]) return AVT_ERROR(ENOMEM); @@ -98,24 +99,23 @@ static int pq_reorder_alloc(PQReorder *reorder) return 0; } -int pq_reorder_push_pkt(AVTContext *ctx, AVTBuffer *data, +int avt_reorder_push_pkt(AVTContext *ctx, AVTBuffer *data, ptrdiff_t offset, uint32_t seq, - enum PQPacketType type) + enum AVTPktDescriptors pkt) { int ret; - PQReorder *reorder = ctx->src.rctx; - PQBufEntry *ins, *tmp, *entry = NULL; + AVTReorder *reorder = ctx->src.rctx; + AVTBufEntry *ins, *tmp, *entry = NULL; - if (type == (AVT_PKT_STREAM_DATA & 0xFF00) || - type == (AVT_PKT_STREAM_SEG_DATA) || - type == (AVT_PKT_STREAM_SEG_END)) + if (pkt == (AVT_PKT_STREAM_DATA & 0xFF00) || + pkt == (AVT_PKT_STREAM_DATA_SEGMENT)) entry = ctx->src.rctx->stream_data; while (entry->next && (entry->seq < seq) && (entry->seg_offset < offset)) entry = entry->next; if (!reorder->nb_avail) { - ret = pq_reorder_alloc(reorder); + ret = avt_reorder_alloc(reorder); if (ret < 0) return ret; } @@ -137,12 +137,12 @@ int pq_reorder_push_pkt(AVTContext *ctx, AVTBuffer *data, return 0; } -void pq_reorder_uninit(AVTContext *ctx) +void avt_reorder_uninit(AVTContext *ctx) { - PQReorder *reorder = ctx->src.rctx; + AVTReorder *reorder = ctx->src.rctx; for (int i = 0; i < reorder->nb_used; i++) { - pq_buffer_quick_unref(&reorder->used[i]->data); + avt_buffer_quick_unref(&reorder->used[i]->data); free(reorder->used[i]); } for (int i = 0; i < reorder->nb_avail; i++) diff --git a/libavtransport/reorder.h b/libavtransport/reorder.h index f4df31b..24ba4b2 100644 --- a/libavtransport/reorder.h +++ b/libavtransport/reorder.h @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_REORDER @@ -29,25 +30,25 @@ #include "common.h" #include "buffer.h" -typedef struct PQPktChain PQPktChain; +typedef struct AVTPktChain AVTPktChain; -enum PQPktChainStatus { - PQ_PKT_CHAIN_COMPLETE, - PQ_PKT_CHAIN_INCOMPLETE, +enum AVTPktChainStatus { + AVT_PKT_CHAIN_COMPLETE, + AVT_PKT_CHAIN_INCOMPLETE, }; -int pq_reorder_init(AVTContext *ctx, size_t max_buffer); +int avt_reorder_init(AVTContext *ctx, size_t max_buffer); -int pq_reorder_push_pkt(AVTContext *ctx, AVTBuffer *data, +int avt_reorder_push_pkt(AVTContext *ctx, AVTBuffer *data, ptrdiff_t offset, uint32_t seq, - enum PQPacketType type); + enum AVTPktDescriptors pkt); -enum PQPktChainStatus pq_chain_get_status(AVTContext *ctx, PQPktChain *chain); +enum AVTPktChainStatus avt_chain_get_status(AVTContext *ctx, AVTPktChain *chain); -AVTBuffer *pq_chain_get_buffer(AVTContext *ctx, PQPktChain *chain); +AVTBuffer *avt_chain_get_buffer(AVTContext *ctx, AVTPktChain *chain); -void pq_reorder_pop_chain(AVTContext *ctx, PQPktChain *chain); +void avt_reorder_pop_chain(AVTContext *ctx, AVTPktChain *chain); -void pq_reorder_uninit(AVTContext *ctx); +void avt_reorder_uninit(AVTContext *ctx); #endif diff --git a/libavtransport/utils.h b/libavtransport/utils.h index 900c02c..e3dae90 100644 --- a/libavtransport/utils.h +++ b/libavtransport/utils.h @@ -1,272 +1,45 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBAVTRANSPORT_UTILS #define LIBAVTRANSPORT_UTILS -#include -#include - +#include #include "../config.h" -#ifndef PQ_RB8 -#define PQ_RB8(x) \ - (((const uint8_t *)(x))[0]) -#endif - -#ifndef PQ_RL8 -#define PQ_RL8(x) \ - (((const uint8_t *)(x))[0]) -#endif - -#ifndef PQ_WB8 -#define PQ_WB8(p, val) \ - do { \ - uint8_t d = (val); \ - ((uint8_t *)(p))[0] = (d); \ - } while(0) -#endif - -#ifndef PQ_WL8 -#define PQ_WL8(p, val) \ - do { \ - uint8_t d = (val); \ - ((uint8_t *)(p))[0] = (d); \ - } while(0) -#endif - -#ifndef PQ_RB16 -#define PQ_RB16(x) \ - ((((const uint8_t *)(x))[0] << 8) | ((const uint8_t *)(x))[1]) -#endif - -#ifndef PQ_RL16 -#define PQ_RL16(x) \ - ((((const uint8_t *)(x))[1] << 8) | ((const uint8_t *)(x))[0]) -#endif - -#ifndef PQ_WB16 -#define PQ_WB16(p, val) \ - do { \ - uint16_t d = (val); \ - ((uint8_t *)(p))[1] = (d) >> 0; \ - ((uint8_t *)(p))[0] = (d) >> 8; \ - } while(0) -#endif - -#ifndef PQ_WL16 -#define PQ_WL16(p, val) \ - do { \ - uint16_t d = (val); \ - ((uint8_t *)(p))[0] = (d) >> 0; \ - ((uint8_t *)(p))[1] = (d) >> 8; \ - } while(0) -#endif - -#ifndef PQ_RB32 -#define PQ_RB32(x) \ - ((uint32_t)((((uint32_t)(((const uint8_t *)(x))[0])) << 24) | \ - (((uint32_t)(((const uint8_t *)(x))[1])) << 16) | \ - (((uint32_t)(((const uint8_t *)(x))[2])) << 8) | \ - (((uint32_t)(((const uint8_t *)(x))[3])) << 0))) -#endif - -#ifndef PQ_RL32 -#define PQ_RL32(x) \ - ((uint32_t)((((uint32_t)(((const uint8_t *)(x))[3])) << 24) | \ - (((uint32_t)(((const uint8_t *)(x))[2])) << 16) | \ - (((uint32_t)(((const uint8_t *)(x))[1])) << 8) | \ - (((uint32_t)(((const uint8_t *)(x))[0])) << 0))) -#endif - -#ifndef PQ_WB32 -#define PQ_WB32(p, val) \ - do { \ - uint32_t d = (val); \ - ((uint8_t *)(p))[3] = (d) >> 0; \ - ((uint8_t *)(p))[2] = (d) >> 8; \ - ((uint8_t *)(p))[1] = (d) >> 16; \ - ((uint8_t *)(p))[0] = (d) >> 24; \ - } while(0) -#endif - -#ifndef PQ_WL32 -#define PQ_WL32(p, val) \ - do { \ - uint32_t d = (val); \ - ((uint8_t *)(p))[0] = (d) >> 0; \ - ((uint8_t *)(p))[1] = (d) >> 8; \ - ((uint8_t *)(p))[2] = (d) >> 16; \ - ((uint8_t *)(p))[3] = (d) >> 24; \ - } while(0) -#endif - -#ifndef PQ_RB64 -#define PQ_RB64(x) \ - ((uint64_t)((((uint64_t)(((const uint8_t *)(x))[0])) << 56) | \ - (((uint64_t)(((const uint8_t *)(x))[1])) << 48) | \ - (((uint64_t)(((const uint8_t *)(x))[2])) << 40) | \ - (((uint64_t)(((const uint8_t *)(x))[3])) << 32) | \ - (((uint64_t)(((const uint8_t *)(x))[4])) << 24) | \ - (((uint64_t)(((const uint8_t *)(x))[5])) << 16) | \ - (((uint64_t)(((const uint8_t *)(x))[6])) << 8) | \ - (((uint64_t)(((const uint8_t *)(x))[7])) << 0))) -#endif - -#ifndef PQ_RL64 -#define PQ_RL64(x) \ - ((uint64_t)((((uint64_t)(((const uint8_t *)(x))[7])) << 56) | \ - (((uint64_t)(((const uint8_t *)(x))[6])) << 48) | \ - (((uint64_t)(((const uint8_t *)(x))[5])) << 40) | \ - (((uint64_t)(((const uint8_t *)(x))[4])) << 32) | \ - (((uint64_t)(((const uint8_t *)(x))[3])) << 24) | \ - (((uint64_t)(((const uint8_t *)(x))[2])) << 16) | \ - (((uint64_t)(((const uint8_t *)(x))[1])) << 8) | \ - (((uint64_t)(((const uint8_t *)(x))[0])) << 0))) -#endif - -#ifndef PQ_WB64 -#define PQ_WB64(p, val) \ - do { \ - uint64_t d = (val); \ - ((uint8_t *)(p))[7] = (d) >> 0; \ - ((uint8_t *)(p))[6] = (d) >> 8; \ - ((uint8_t *)(p))[5] = (d) >> 16; \ - ((uint8_t *)(p))[4] = (d) >> 24; \ - ((uint8_t *)(p))[3] = (d) >> 32; \ - ((uint8_t *)(p))[2] = (d) >> 40; \ - ((uint8_t *)(p))[1] = (d) >> 48; \ - ((uint8_t *)(p))[0] = (d) >> 56; \ - } while(0) -#endif - -#ifndef PQ_WL64 -#define PQ_WL64(p, val) \ - do { \ - uint64_t d = (val); \ - ((uint8_t *)(p))[0] = (d) >> 0; \ - ((uint8_t *)(p))[1] = (d) >> 8; \ - ((uint8_t *)(p))[2] = (d) >> 16; \ - ((uint8_t *)(p))[3] = (d) >> 24; \ - ((uint8_t *)(p))[4] = (d) >> 32; \ - ((uint8_t *)(p))[5] = (d) >> 40; \ - ((uint8_t *)(p))[6] = (d) >> 48; \ - ((uint8_t *)(p))[7] = (d) >> 56; \ - } while(0) -#endif - -#if CONFIG_BIG_ENDIAN -#define PQ_RN(p, l) PQ_RB##l(p) -#define PQ_WN(p, l, v) PQ_WB##l(p, v) -#else -#define PQ_RN(p, l) PQ_RL##l(p) -#define PQ_WN(p, l, v) PQ_WL##l(p, v) -#endif - -typedef struct PQByteStream { - uint8_t *start; - uint8_t *ptr; - uint8_t *end; -} PQByteStream; - -#define PQ_INIT(bs, buf, len) \ - PQByteStream bs = { \ - .start = buf, \ - .ptr = buf, \ - .end = buf + len, \ - }; - -#define PQ_RESET(bs) \ - do { \ - (bs).ptr = (bs).start; \ - } while (0) - -#define PQ_WBL(bs, l, v) \ - do { \ - if ((((bs).ptr) + (l >> 3)) <= (bs).end) { \ - PQ_WL##l((bs).ptr, (v)); \ - (bs).ptr += l >> 3; \ - } \ - } while (0) - -#define PQ_WLL(bs, l, v) \ - do { \ - if ((((bs).ptr) + (l >> 3)) <= (bs).end) { \ - PQ_WL##l((bs).ptr, (v)); \ - (bs).ptr += l >> 3; \ - } \ - } while (0) - -#define PQ_WPD(bs, len) \ - do { \ - memset((bs).ptr, 0, AVTMIN(len >> 3, (bs).end - (bs).ptr)); \ - (bs).ptr += AVTMIN(len >> 3, (bs).end - (bs).ptr); \ - } while (0) - -#define PQ_WDT(bs, buf, len) \ - do { \ - memcpy((bs).ptr, buf, AVTMIN(len, (bs).end - (bs).ptr)); \ - (bs).ptr += AVTMIN(len, (bs).end - (bs).ptr); \ - } while (0) - -#define PQ_WST(bs, fixed_len, str) \ - do { \ - PQ_WDT(bs, str, AVTMIN(strlen(str), fixed_len)); \ - PQ_WPD(bs, AVTMAX(fixed_len - strlen(str), 0) << 3); \ - } while (0) - -#define PQ_GETLAST(bs, len) \ - (AVTMAX((bs).start, (bs).ptr - len)) - -#define PQ_WLEN(bs) \ - ((bs).ptr - (bs).start) - -#define PQ_RDR(base_read, e, len) \ -static inline uint ##len## _t pq_bs_read_##e##len(PQByteStream *bs) \ -{ \ - uint ##len## _t v; \ - if ((bs)->ptr + (len >> 3) <= (bs)->end) { \ - v = base_read##len((bs)->ptr); \ - (bs)->ptr += len >> 3; \ - } \ - return v; \ +static inline void sp_assert0(int cond) +{ + assert(cond); } -static inline void pq_bs_skip(PQByteStream *bs, size_t len) +static inline void sp_assert1(int cond) { - if (bs->ptr + (len >> 3) <= bs->end) - bs->ptr += len >> 3; +#if CONFIG_ASSERT_LEVEL > 0 + assert(cond); +#endif } -PQ_RDR(PQ_RB, b, 8) -PQ_RDR(PQ_RL, l, 8) -PQ_RDR(PQ_RB, b, 16) -PQ_RDR(PQ_RL, l, 16) -PQ_RDR(PQ_RB, b, 32) -PQ_RDR(PQ_RL, l, 32) -PQ_RDR(PQ_RB, b, 64) -PQ_RDR(PQ_RL, l, 64) - #endif diff --git a/libavtransport/version.h b/libavtransport/version.h index cb30a78..0c06c94 100644 --- a/libavtransport/version.h +++ b/libavtransport/version.h @@ -1,19 +1,27 @@ /* - * This file is part of cyanrip. + * Copyright © 2023, Lynne + * All rights reserved. * - * cyanrip is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * cyanrip is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * You should have received a copy of the GNU Lesser General Public - * License along with cyanrip; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ extern const char *vcstag; diff --git a/meson.build b/meson.build index 1c65632..c3ba6d1 100644 --- a/meson.build +++ b/meson.build @@ -1,8 +1,9 @@ project('libavtransport', 'c', - license: 'MIT', - default_options: [ 'buildtype=debugoptimized', 'c_std=c99', 'warning_level=1' ], - version: '0.0.1', - meson_version: '>=0.54.0', + license: 'BSD-2-Clause', + license_files: ['LICENSE.md'], + default_options: [ 'buildtype=debugoptimized', 'c_std=c2x', 'warning_level=1' ], + version: '0.0.2', + meson_version: '>=1.1.0', ) conf = configuration_data() @@ -37,6 +38,21 @@ else endif cc = meson.get_compiler('c') +if cc.has_argument('-fvisibility=hidden') + add_project_arguments('-fvisibility=hidden', language: 'c') +else + warning('Compiler does not support -fvisibility=hidden, all symbols will be public!') +endif + +pymod = import('python') +python_exe = pymod.find_installation() +spec2c = files('tools/spec2c.py') +spec_file = files('draft-avtransport-spec.bs') + +conv_spec = custom_target('packet encode/decode', + input: spec_file, + output: ['packet_encode.h', 'packet_decode.h'], + command: [python_exe, spec2c, 'packet_encode,packet_decode', '@INPUT@', '@OUTPUT0@', '@OUTPUT1@']) subdir('libavtransport') diff --git a/meson_options.txt b/meson_options.txt index 841a44d..f326e61 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,5 @@ +option('assert', type: 'integer', min : 0, max : 2, value : 0, description: 'Assert level with which to build the library') + option('output', type: 'feature', value: 'auto', description: 'Build libavtransport with output support') option('input', type: 'feature', value: 'auto', description: 'Build libavtransport with input support') diff --git a/tools/avcat.c b/tools/avcat.c index 39a6c3c..f69230c 100644 --- a/tools/avcat.c +++ b/tools/avcat.c @@ -1,26 +1,27 @@ /* - * Copyright © 2022 Lynne + * Copyright © 2023, Lynne + * All rights reserved. * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the “Software”), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ int main(int argc, char **argv) diff --git a/tools/spec2c.py b/tools/spec2c.py new file mode 100755 index 0000000..84d5594 --- /dev/null +++ b/tools/spec2c.py @@ -0,0 +1,592 @@ +#!/usr/bin/env python3 +# +# Copyright © 2023 Lynne +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the “Software”), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +import itertools +import re +import sys +import datetime +import math +from bs4 import BeautifulSoup + +f_input = None +f_packet_enums = None +f_packet_data = None +f_packet_encode = None +f_packet_decode = None + +# Convert '/', '$' and '.' to '_', +# or if this is stdin just use "stdin" as the name. +argc = len(sys.argv) +if argc < 4: + print("Invalid arguments: need ", file=sys.stderr) + exit(1) + +f_input = sys.argv[2] + +mode = sys.argv[1].split(",") +for i, m in enumerate(mode): + if (3 + i) >= len(sys.argv): + print("Invalid arguments: need !", file=sys.stderr) + exit(22) + if m == "packet_enums": + f_packet_enums = sys.argv[3 + i] + elif m == "packet_data": + f_packet_data = sys.argv[3 + i] + elif m == "packet_encode": + f_packet_encode = sys.argv[3 + i] + elif m == "packet_decode": + f_packet_decode = sys.argv[3 + i] + else: + print("Invalid list: expected 'packet_enums', 'packet_data', 'packet_encode', 'packet_decode'") + exit(22) + +# Parse spec +with open(f_input) as text: + soup = BeautifulSoup(text, "html.parser") + +# Get the list of descriptor ranges +desc_list_tab = soup.find(id="descriptors_list") +desc_pairs = desc_list_tab.find_all('tr') + +MAX_BITFIELD_LEN = 8 + +# Struct/function prefix +data_prefix = "AVT" +fn_prefix = "avt_" +bsw = { + "pad": "avt_bsw_zpad", + "buf": "avt_bsw_sbuf", + "rat": "avt_bsw_rtbe", + "int": "avt_bsw_", + "str": "avt_bsw_fstr", + "len": "avt_bs_offs", + "ldpc": "avt_bsw_ldpc_" +} + +bsr = { + "pad": "avt_bsr_skip", + "buf": "avt_bsr_sbuf", + "rat": "avt_bsr_rtbe", + "int": "avt_bsr_", + "str": "avt_bsr_fstr", + "len": "avt_bs_offs", + "ldpc": "avt_bsr_ldpc_" +} + +enums = {} +descriptors = { "FLAG_LSB_BITMASK": (1 << 31) } +packet_structs = { } +templated_structs = { } +templates = { } +orig_desc_names = { } +struct_sizes = { } + +def iter_enum_fields(target_id): + if target_id in enums: + return + + enum = soup.find(id=target_id) + if enum == None: + print("Unknown enum:", target_id) + exit(22) + + enum_vals = { } + dfns = enum.find_all('dfn') + for name in dfns: + enum_vals[name.string] = int(name.find_next("i").string, 16) + + print("Parsed enum", target_id) + enums[target_id] = enum_vals + +# Iterate over each field of a data structure +def iter_data_fields(target_id, struct_name): + total_bits = 0 + original_desc_name = None + original_struct_name = struct_name + struct_fields = { } + for i in itertools.count(): + field_tab = soup.find(id=target_id + "+" + str(i)) + if field_tab == None: + break + + fields = field_tab.find_all('td') + + if i == 0 and struct_name == None: + original_desc_name = fields[1].string[:-11] + original_struct_name = ''.join(original_desc_name.title().split("_")) + struct_name = data_prefix + original_struct_name + elif i == 0: + original_desc_name = fields[1].string[:-11] + original_struct_name = struct_name + struct_name = data_prefix + original_struct_name + + if fields[2].string and fields[2].string.startswith("[[#generic"): + template_descriptor = int(fields[0].string.strip("'"), 16) + descriptors[fields[1].string[:-11].upper()] = template_descriptor + print("Parsed templated struct", original_struct_name) + templated_structs[struct_name] = dict({ + "name": fields[1].string[:-11], + "descriptor": template_descriptor, + "template": fields[1].string.strip("[]"), + }) + return templated_structs[struct_name] + + fixed_number = None + ldpc = None + enum = None + template = None + struct = None + string = False + + if len(fields[2]) > 0: + data = fields[2].string.strip("'[=]") + if data.startswith("0x"): + fixed_number = int(data, 16); + elif data.startswith("LDPC("): + ldpc = [int(x) for x in data[5:-1].split(',')] + elif data.startswith("enum"): + enum = data[5:].strip("{}") + iter_enum_fields(enum) + elif data.startswith("struct"): + struct = data[7:].strip("{}") + if iter_data_fields(struct, struct) == None: + print("Unknown struct:", struct) + exit(22) + elif 'string' in data: + string = True + + datatype = None + size_bits = 0 + bytestream = 0 + array_len = 0 + type_str = fields[0].string + type_mult = type_str[0:-1].split('*') + if len(type_mult) > 1: + if type_mult[0].startswith("[="): + array_len = type_mult[0][2:-2] + elif type_mult[0][0].isdigit(): + array_len = int(re.search('[0-9]+', type_mult[0]).group()) + else: + print("Unknown multiplier in:", fields[0]) + exit(22) + + datapart = type_mult[-1].split("(") + size_bits = int(datapart[1]) + + if all(x in "uibR" for x in datapart[0]) == False: + print("Unknown data type in:", fields[0]) + exit(22) + elif struct != None: + datatype = data_prefix + struct + bytestream = size_bits // 8 + elif ((size_bits & (size_bits - 1) != 0) and ((datapart[0] != "b") or (array_len > 0))): + print("Invalid data type in:", fields[0]) + exit(22) + elif string: + datatype = "char8_t" + bytestream = 1 + elif enum != None: + datatype = "enum " + data_prefix + enum + bytestream = size_bits // 8 + elif size_bits <= 8: + datatype = "uint8_t" + if size_bits < 8: + bytestream = 0 + else: + bytestream = 1 + elif (size_bits & (size_bits - 1) != 0) and array_len > 0: + datatype = "uint8_t" + array_len = size_bits // 8 + bytestream = size_bits // 8 + elif datapart[0] == "R" and size_bits == 64: + datatype = data_prefix + "Rational" + bytestream = 64 // 8 + elif datapart[0] == "b" or datapart[0] == "u" and \ + ((size_bits == 8 and array_len == 0) or \ + (size_bits >= 8 and (size_bits & (size_bits - 1) == 0))): + datatype = "uint" + str(size_bits) + "_t" + bytestream = size_bits // 8 + elif datapart[0] == "i" and \ + ((size_bits == 8 and array_len == 0) or \ + (size_bits >= 8 and (size_bits & (size_bits - 1) == 0))): + datatype = "int" + str(size_bits) + "_t" + bytestream = size_bits // 8 + else: + print("Unknown data type in:", fields[0]) + exit(22) + + if i == 0 and fixed_number != None: # Descriptor + if size_bits == 16: + descriptors[fields[1].string.upper()[:-11]] = fixed_number + elif size_bits == 8: + descriptors[fields[1].string.upper()[:-11]] = (fixed_number << 8) | descriptors["FLAG_LSB_BITMASK"] + elif target_id[0].isdigit(): + print("Unknown descriptor in:", fields[0]) + exit(22) + + field_name = fields[1].string.strip("[=]") + if field_name in struct_fields: + field_name += "_2" + struct_fields[field_name] = dict({ + "type": fields[0].string, + "fixed": fixed_number, + "ldpc": ldpc, + "enum": enum, + "size_bits": size_bits, + "bytestream": bytestream, + "datatype": datatype, + "struct": struct, + "array_len": array_len, + "string": string, + }) + total_bits += size_bits + + if total_bits == 0: + return None + + print("Parsed struct", original_struct_name) + + if struct_name.startswith("generic") == False: + packet_structs[struct_name] = struct_fields + orig_desc_names[struct_name] = original_desc_name + struct_sizes[struct_name] = total_bits + + return struct_fields + +# Load all templates +templates = { + "#generic-data-packets": iter_data_fields("GenericData", None), + "#generic-data-segment-packets": iter_data_fields("GenericDataSegment", None), + "#generic-data-parity-packets": iter_data_fields("GenericDataParity", None), +} + +for desc_pair in desc_pairs[1:]: # Skip table header + pair = desc_pair.find_all('td') + val = pair[0].string.split(":") + pkt = pair[1].string.strip("[#]").split('-') + pkt = map(str.title, pkt) + desc_start = None + desc_end = None + + if len(val) == 1: + desc_end = desc_start = int(val[0].strip("'"), 16) + elif len(val) == 2: + desc_start = int(val[0].strip("[']"), 16) + desc_end = int(val[1].strip("[']"), 16) + + for i in range(desc_start, desc_end + 1): + if iter_data_fields("0x" + format(i, '04X'), None) == None: + break; + +copyright_header = "/*\n * Copyright © " + datetime.datetime.now().date().strftime("%Y") + ''', Lynne + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +''' + +autogenerate_note = "/* This file is automatically generated from " + f_input + ", do not edit */\n" + +if f_packet_enums != None: + file_enums = open(f_packet_enums, "w+") + file_enums.write(copyright_header + "\n") + file_enums.write(autogenerate_note) + file_enums.write("#ifndef LIBAVTRANSPORT_PACKET_ENUMS\n") + file_enums.write("#define LIBAVTRANSPORT_PACKET_ENUMS\n") + + file_enums.write("enum " + data_prefix + "PktDescriptors {\n") + for name, desc in descriptors.items(): + add_flag = False + if desc > descriptors["FLAG_LSB_BITMASK"]: + desc &= ~descriptors["FLAG_LSB_BITMASK"] + add_flag = True; + file_enums.write(" " + data_prefix + "_PKT_" + name + " = " + "0x" + format(desc, "X")) + if add_flag: + file_enums.write(" | AVT_PKT_FLAG_LSB_BITMASK") + file_enums.write(",\n") + file_enums.write("};\n") + + for enum, dfns in enums.items(): + file_enums.write("\nenum " + data_prefix + enum + " {\n") + for name, val in dfns.items(): + file_enums.write(" " + data_prefix + "_" + name + " = 0x" + format(val, "X") + ",\n") + file_enums.write("};\n") + file_enums.write("\n#endif\n") + +if f_packet_data != None: + file_structs = open(f_packet_data, "w+") + file_structs.write(copyright_header + "\n") + file_structs.write("#ifndef LIBAVTRANSPORT_PACKET_DATA\n") + file_structs.write("#define LIBAVTRANSPORT_PACKET_DATA\n" + "\n") + file_structs.write(autogenerate_note + "\n") + file_structs.write("#include \n") + file_structs.write("#include \n") + file_structs.write("#include \n\n") + if f_packet_enums != None: + file_structs.write("#include \"" + f_packet_enums + "\"\n") + else: + file_structs.write("#include \n") + file_structs.write("#include \n") + for struct, fields in packet_structs.items(): + file_structs.write("\ntypedef struct " + struct + " {\n") + + newline_carryover = False; + for name, field in fields.items(): + if name == "padding": + continue + if newline_carryover: + file_structs.write("\n") + newline_carryover = False; + if field["ldpc"] != None: + newline_carryover = True + continue + + file_structs.write(" " + field["datatype"] + " ") + if type(field["array_len"]) != int: + file_structs.write("*") + file_structs.write(name) + if type(field["array_len"]) == int: + if type(field["array_len"]) == str: + file_structs.write("[" + "" + "]") + elif field["array_len"] > 0: + file_structs.write("[" + str(field["array_len"]) + "]") + file_structs.write(";\n") + + file_structs.write("} " + struct + ";\n") + file_structs.write("\n#endif\n") + +if f_packet_encode != None: + file_encode = open(f_packet_encode, "w+") + file_encode.write(copyright_header + "\n") + file_encode.write(autogenerate_note + "\n") + if f_packet_enums != None: + file_encode.write("#include \"" + f_packet_data + "\"\n") + else: + file_encode.write("#include \n") + for struct, fields in packet_structs.items(): + had_bitfield = False + bitfield = False + newline_carryover = False; + bitfield_bit = 0 + indent = " " + file_encode.write("\nint " + fn_prefix + "encode_" + orig_desc_names[struct] + "(" + data_prefix + "Bytestream *bs, " + struct + " *p)" + "\n{\n") + def wsym(indent, sym, name, field): + # Start + if field["struct"] != None: + file_encode.write(indent + fn_prefix + "encode_" + orig_desc_names[data_prefix + field["struct"]]) + elif sym == bsw["int"]: + file_encode.write(indent + sym) + if field["datatype"][0] == i: + file_encode.write("i" + str(field["bytestream"]*8) + "b") + else: + file_encode.write("u" + str(field["bytestream"]*8) + "b") + elif sym == bsw["ldpc"]: + file_encode.write(indent + sym + str(field["ldpc"][0]) + "_" + str(field["ldpc"][1])) + else: + file_encode.write(indent + sym) + + if field["bytestream"] == 1 and sym == bsw["int"]: + file_encode.write(" ") + file_encode.write("(bs") + + # Length + if sym == bsw["buf"]: + if field["array_len"]: + file_encode.write(", p->" + str(field["array_len"])) + else: + file_encode.write(", " + str(field["bytestream"])) + if sym == bsw["pad"]: + file_encode.write(", " + str(field["bytestream"])) + + # Name + if sym != bsw["pad"] and sym != bsw["ldpc"]: + file_encode.write(", p->" + name) + + # Array index + if (type(field["array_len"]) == int and field["array_len"] > 1) or \ + (type(field["array_len"]) == str and field["bytestream"] > 1): + file_encode.write("[i]") + file_encode.write(");\n") + + for name, field in fields.items(): + indent = " " + write_sym = bsw["int"] + if field["datatype"] == data_prefix + "Rational": + write_sym = bsw["rat"] + elif field["ldpc"] != None: + write_sym = bsw["ldpc"] + elif name == "padding" and field["bytestream"] > 0: + write_sym = bsw["pad"] + elif (type(field["array_len"]) == str and field["bytestream"] == 1) or field["ldpc"] != None: + write_sym = bsw["buf"] + + if newline_carryover: + file_encode.write("\n") + newline_carryover = False; + if field["ldpc"] != None: + newline_carryover = True + + if field["bytestream"] == 0 and bitfield == False: # Setup bitfield writing + if had_bitfield == False: + file_encode.write(indent + "uint32_t bitfield;\n"); + bitfield = True + had_bitfield = True + bitfield_bit = (MAX_BITFIELD_LEN - 1) + + if bitfield: + if bitfield_bit == (MAX_BITFIELD_LEN - 1): + file_encode.write(indent + "bitfield = ") + else: + file_encode.write(indent + "bitfield |= ") + file_encode.write(name + " << (" + str(bitfield_bit) + " - " + str(field["size_bits"]) + ");\n") + bitfield_bit -= field["size_bits"] + else: + if (type(field["array_len"]) == int and field["array_len"] > 1) or \ + (type(field["array_len"]) == str and field["bytestream"] > 1): + file_encode.write(indent + "for (int i = 0; i < " + str(field["array_len"]) + "; i++)\n") + indent = indent + " " + wsym(indent, write_sym, name, field) + + if bitfield and (MAX_BITFIELD_LEN - bitfield_bit - 1) >= 8 and \ + math.log2(MAX_BITFIELD_LEN - bitfield_bit - 1).is_integer(): # Terminate bitfield + file_encode.write(indent + bsw["int"] + "u" + str(MAX_BITFIELD_LEN - bitfield_bit - 1) + "b (bs, bitfield);\n") + bitfield = False + file_encode.write("}\n") + +if f_packet_decode != None: + file_decode = open(f_packet_decode, "w+") + file_decode.write(copyright_header + "\n") + file_decode.write(autogenerate_note + "\n") + if f_packet_enums != None: + file_decode.write("#include \"" + f_packet_data + "\"\n") + else: + file_decode.write("#include \n") + for struct, fields in packet_structs.items(): + had_bitfield = False + bitfield = False + newline_carryover = False; + bitfield_bit = 0 + indent = " " + file_decode.write("\nint " + fn_prefix + "decode_" + orig_desc_names[struct] + "(" + data_prefix + "Bytestream *bs, " + struct + " *p)" + "\n{\n") + def rsym(indent, sym, name, field): + # Start + if (sym == bsr["int"] or sym == bsr["rat"]) and field["struct"] == None: + file_decode.write(indent + "p->" + name + " = ") + else: + file_decode.write(indent) + + if field["struct"] != None: + file_decode.write(fn_prefix + "decode_" + orig_desc_names[data_prefix + field["struct"]]) + elif sym == bsr["int"]: + file_decode.write(sym) + if field["datatype"][0] == i: + file_decode.write("i" + str(field["bytestream"]*8) + "b") + else: + file_decode.write("u" + str(field["bytestream"]*8) + "b") + elif sym == bsr["ldpc"]: + file_decode.write(sym + str(field["ldpc"][0]) + "_" + str(field["ldpc"][1])) + else: + file_decode.write(sym) + + file_decode.write("(bs") + if field["struct"] != None: + file_decode.write(", p->" + name) + + # Length + if sym == bsr["buf"]: + if field["array_len"]: + file_decode.write(", p->" + str(field["array_len"])) + else: + file_decode.write(", " + str(field["bytestream"])) + if sym == bsr["pad"]: + file_decode.write(", " + str(field["bytestream"])) + + # Array index + if (type(field["array_len"]) == int and field["array_len"] > 1) or \ + (type(field["array_len"]) == str and field["bytestream"] > 1): + file_decode.write("[i]") + file_decode.write(");\n") + + for name, field in fields.items(): + indent = " " + read_sym = bsr["int"] + if field["datatype"] == data_prefix + "Rational": + read_sym = bsr["rat"] + elif field["ldpc"] != None: + read_sym = bsr["ldpc"] + elif name == "padding" and field["bytestream"] > 0: + read_sym = bsr["pad"] + elif (type(field["array_len"]) == str and field["bytestream"] == 1) or field["ldpc"] != None: + read_sym = bsr["buf"] + + if newline_carryover: + file_decode.write("\n") + newline_carryover = False; + if field["ldpc"] != None: + newline_carryover = True + + if field["bytestream"] == 0 and bitfield == False: # Setup bitfield writing + file_decode.write("\n") + if had_bitfield == False: + file_decode.write(indent + "uint32_t "); + file_decode.write("bitfield = " + bsr["int"] + "u8b(bs);\n") + bitfield = True + had_bitfield = True + bitfield_bit = (MAX_BITFIELD_LEN - 1) + + if bitfield: + bitfield_bit -= field["size_bits"] + file_decode.write(indent + name + " = (bitfield >> " + str(bitfield_bit + 1) + ") & ((1 << " + str(field["size_bits"]) + ") - 1);\n") + else: + if (type(field["array_len"]) == int and field["array_len"] > 1) or \ + (type(field["array_len"]) == str and field["bytestream"] > 1): + file_decode.write(indent + "for (int i = 0; i < " + str(field["array_len"]) + "; i++)\n") + indent = indent + " " + rsym(indent, read_sym, name, field) + + if bitfield and (MAX_BITFIELD_LEN - bitfield_bit - 1) >= 8 and \ + math.log2(MAX_BITFIELD_LEN - bitfield_bit - 1).is_integer(): # Terminate bitfield + bitfield = False + file_decode.write("\n") + file_decode.write("}\n")
Type Name Data Description
b(16)ctrl_descriptorsession_control_descriptor ''0x8001'' Indicates this is a control data packet.
b(8) cease If not equal to ''0x0'', indicates a fatal error, and senders MUST NOT sent any more data.
u(8) resend_init If nonzero, asks the sender to resend all [[#time-synchronization-packets]], all [[#stream-registration-packets]] and all required packets for them.
u(32) error enum {{ErrorCode}} Indicates an error code, if not equal to ''0x0''.
b(128) uplink_ip Reports the upstream address to stream to.
u(16) uplink_port Reports the upstream port to stream on to the [=uplink_ip=].
b(8) seek If ''1'', Asks the sender to seek to the position given by [=seek_pts=] and/or [=seek_seq=].
i(64) seek_pts The [=pts=] value to seek to.
u(32) seek_seq Data Description
b(16)feedback_descriptorstream_feedback_descriptor ''0x8002'' Indicates this is a statistics packet.
b(16) [=stream_id=] Indicates the stream ID for which this packet is relevant to. May be ''0xFFFF'' to indicate all streams.
u(64) epoch_offset Time since [=epoch=]. May be 0. Can be used to estimate the latency.
u(64) [=bandwidth=] Hint that indicates the available receiver bandwith, in bits per second. May be 0, in which case infinite must be assumed. Senders should respect it. The figure should include all headers and associated overhead.
u(64) fec_corrections A counter that indicates the total amount of repaired packets (packets with errors that FEC was able to correct).
u(64) corrupt_packets Indicates the total number of corrupt packets. This also counts corrupt packets FEC was not able to correct.
u(64) dropped_packets Data Description
b(16)resend_descriptorpacket_resend_descriptor ''0x8003'' Indicates this is a stream data resend packet.
b(16) [=padding=] Padding, reserved for future use. Must be 0x0.
b(32) [=global_seq=] Data Description
b(16)stream_ctrl_descriptorstream_control_descriptor ''0x8004'' Indicates this is a stream control data packet.
b(16) [=stream_id=] The stream ID for which this packet applies to. MUST NOT be ''0xFFFF''.
u(32) [=global_seq=]