SmolRTSP  0.1.3
A small, portable, extensible RTSP 1.0 implementation in C99
nal.h File Reference

A generic NAL (Network Abstraction Layer) representation. More...

#include <smolrtsp/nal/h264.h>
#include <smolrtsp/nal/h265.h>
#include <stdbool.h>
#include <stdint.h>
#include <datatype99.h>
#include <slice99.h>
#include <smolrtsp/priv/compiler_attrs.h>
Include dependency graph for nal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SmolRTSP_NalUnit
 A generic NAL unit (either H.264 or H.265). More...
 

Typedefs

typedef size_t(* SmolRTSP_NalStartCodeTester) (U8Slice99 data)
 A function that tests whether data starts with some start code. More...
 

Functions

 datatype99 (SmolRTSP_NalHeader,(SmolRTSP_NalHeader_H264, SmolRTSP_H264NalHeader),(SmolRTSP_NalHeader_H265, SmolRTSP_H265NalHeader))
 A generic NAL header (either H.264 or H.265). More...
 
uint8_t SmolRTSP_NalHeader_unit_type (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Returns the NAL unit type of self.
 
size_t SmolRTSP_NalHeader_size (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Computes the size of self in bytes.
 
size_t SmolRTSP_NalHeader_fu_size (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Computes the size of a fragmentation unit (FU) header self. More...
 
bool SmolRTSP_NalHeader_is_vps (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Checks whether self is VPS.
 
bool SmolRTSP_NalHeader_is_sps (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Checks whether self is SPS.
 
bool SmolRTSP_NalHeader_is_pps (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Checks whether self is PPS.
 
bool SmolRTSP_NalHeader_is_coded_slice_idr (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Checks whether self is a coded slice IDR.
 
bool SmolRTSP_NalHeader_is_coded_slice_non_idr (SmolRTSP_NalHeader self) SMOLRTSP_PRIV_MUST_USE
 Checks whether self is a coded slice non-IDR.
 
void SmolRTSP_NalHeader_serialize (SmolRTSP_NalHeader self, uint8_t buffer[restrict])
 Writes the binary representation of self into buffer. More...
 
void SmolRTSP_NalHeader_write_fu_header (SmolRTSP_NalHeader self, uint8_t buffer[restrict], bool is_first_fragment, bool is_last_fragment)
 Writes a FU header of self to buffer. More...
 
uint8_t smolrtsp_nal_fu_header (bool is_first_fragment, bool is_last_fragment, uint8_t unit_type) SMOLRTSP_PRIV_MUST_USE
 Creates a generic NAL FU header.
 
SmolRTSP_NalStartCodeTester smolrtsp_determine_start_code (U8Slice99 data) SMOLRTSP_PRIV_MUST_USE
 Returns a start code tester for data. More...
 
size_t smolrtsp_test_start_code_3b (U8Slice99 data)
 The 3-byte start code tester (0x000001).
 
size_t smolrtsp_test_start_code_4b (U8Slice99 data)
 The 3-byte start code tester (0x00000001).
 

Detailed Description

A generic NAL (Network Abstraction Layer) representation.

Typedef Documentation

◆ SmolRTSP_NalStartCodeTester

typedef size_t(* SmolRTSP_NalStartCodeTester) (U8Slice99 data)

A function that tests whether data starts with some start code.

Returns
The number of start code bytes. If there is no start code in the beginning of data, returns 0.
See also
smolrtsp_test_start_code_3b
smolrtsp_test_start_code_4b

Function Documentation

◆ datatype99()

datatype99 ( SmolRTSP_NalHeader  ,
(SmolRTSP_NalHeader_H264, SmolRTSP_H264NalHeader ,
(SmolRTSP_NalHeader_H265, SmolRTSP_H265NalHeader  
)

A generic NAL header (either H.264 or H.265).

See Datatype99 for the macro usage.

◆ smolrtsp_determine_start_code()

SmolRTSP_NalStartCodeTester smolrtsp_determine_start_code ( U8Slice99  data)

Returns a start code tester for data.

If data does not begin with a start code (either 0x000001 or 0x00000001), returns NULL.

This function is useful when you have some *.h264 bitstream file and you want to determine what start code it uses – just pass the beginning of this file to smolrtsp_determine_start_code and invoke the returned tester multiple times afterwards.

◆ SmolRTSP_NalHeader_fu_size()

size_t SmolRTSP_NalHeader_fu_size ( SmolRTSP_NalHeader  self)

Computes the size of a fragmentation unit (FU) header self.

See also
H.264 Fragmentation Units (FUs): https://datatracker.ietf.org/doc/html/rfc6184#section-5.8
H.265 Fragmentation Units (FUs): https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3

◆ SmolRTSP_NalHeader_serialize()

void SmolRTSP_NalHeader_serialize ( SmolRTSP_NalHeader  self,
uint8_t  buffer[restrict] 
)

Writes the binary representation of self into buffer.

Parameters
[in]selfThe header to write.
[out]bufferThe memory area capable of storing SmolRTSP_NalHeader_size(self) bytes.

◆ SmolRTSP_NalHeader_write_fu_header()

void SmolRTSP_NalHeader_write_fu_header ( SmolRTSP_NalHeader  self,
uint8_t  buffer[restrict],
bool  is_first_fragment,
bool  is_last_fragment 
)

Writes a FU header of self to buffer.

Parameters
[in]selfThe header to write.
[out]bufferThe memory area capable of storing SmolRTSP_NalHeader_fu_size(self) bytes.
[in]is_first_fragmentThe indication of a start of the FU.
[in]is_last_fragmentThe indication of an end of the FU.
See also
H.264 Fragmentation Units (FUs): https://datatracker.ietf.org/doc/html/rfc6184#section-5.8
H.265 Fragmentation Units (FUs): https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3