Sunshine master
Self-hosted game stream host for Moonlight.
cbs.cpp File Reference

Definitions for FFmpeg Coded Bitstream API. More...

#include <libavcodec/avcodec.h>
#include <libavcodec/cbs_h264.h>
#include <libavcodec/cbs_h265.h>
#include <libavcodec/h264_levels.h>
#include <libavutil/pixdesc.h>
#include "cbs.h"
#include "logging.h"
#include "utility.h"
Include dependency graph for cbs.cpp:

Classes

class  cbs::frag_t
 Owns an FFmpeg coded bitstream fragment and frees fragment buffers on destruction. More...
 

Typedefs

using cbs::ctx_t = util::safe_ptr<CodedBitstreamContext, close>
 Owning coded bitstream context pointer that calls ff_cbs_close.
 

Functions

void cbs::close (CodedBitstreamContext *c)
 Release an FFmpeg coded bitstream context.
 
h264_t cbs::make_sps_h264 (const AVCodecContext *avctx, const AVPacket *packet)
 Build replacement H.264 SPS bytes with Sunshine-required VUI fields.
 
hevc_t cbs::make_sps_hevc (const AVCodecContext *avctx, const AVPacket *packet)
 Build replacement HEVC VPS/SPS bytes with Sunshine-required VUI fields.
 
bool cbs::validate_sps (const AVPacket *packet, int codec_id)
 Check whether an encoded H.264 or HEVC packet contains active SPS VUI metadata.
 
util::buffer_t< std::uint8_t > cbs::write (cbs::ctx_t &cbs_ctx, std::uint8_t nal, void *uh, AVCodecID codec_id)
 Serialize a prepared coded bitstream unit with an existing context.
 
util::buffer_t< std::uint8_t > cbs::write (std::uint8_t nal, void *uh, AVCodecID codec_id)
 Serialize a prepared coded bitstream unit with a temporary context.
 

Detailed Description

Definitions for FFmpeg Coded Bitstream API.

Function Documentation

◆ close()

void cbs::close ( CodedBitstreamContext * c)

Release an FFmpeg coded bitstream context.

Parameters
cContext pointer owned by the safe pointer wrapper.

◆ make_sps_h264()

h264_t cbs::make_sps_h264 ( const AVCodecContext * ctx,
const AVPacket * packet )

Build replacement H.264 SPS bytes with Sunshine-required VUI fields.

Build an H.264 replacement SPS for a packet.

Parameters
ctxFFmpeg codec context that provides colorimetry and reference-frame metadata.
packetEncoded packet containing the original SPS.
Returns
Original and rewritten SPS bytes.

◆ make_sps_hevc()

hevc_t cbs::make_sps_hevc ( const AVCodecContext * ctx,
const AVPacket * packet )

Build replacement HEVC VPS/SPS bytes with Sunshine-required VUI fields.

Build HEVC replacement parameter sets for a packet.

Parameters
ctxFFmpeg codec context that provides colorimetry and reference-frame metadata.
packetEncoded packet containing the original VPS and SPS.
Returns
Original and rewritten VPS/SPS bytes.

◆ validate_sps()

bool cbs::validate_sps ( const AVPacket * packet,
int codec_id )

Check whether an encoded H.264 or HEVC packet contains active SPS VUI metadata.

Parameters
packetEncoded packet to parse with FFmpeg's coded bitstream reader.
codec_idFFmpeg codec identifier; expected to be AV_CODEC_ID_H264 or AV_CODEC_ID_H265.
Returns
true when the packet's active SPS advertises VUI parameters.

◆ write() [1/2]

util::buffer_t< std::uint8_t > cbs::write ( cbs::ctx_t & cbs_ctx,
std::uint8_t nal,
void * uh,
AVCodecID codec_id )

Serialize a prepared coded bitstream unit with an existing context.

Parameters
cbs_ctxCoded bitstream context initialized for the codec.
nalNAL unit type to insert into the fragment.
uhPointer to the FFmpeg raw unit header/content structure.
codec_idFFmpeg codec identifier used by the context.
Returns
Serialized NAL unit bytes, or an empty buffer if FFmpeg rejects the fragment.

◆ write() [2/2]

util::buffer_t< std::uint8_t > cbs::write ( std::uint8_t nal,
void * uh,
AVCodecID codec_id )

Serialize a prepared coded bitstream unit with a temporary context.

Parameters
nalNAL unit type to insert into the fragment.
uhPointer to the FFmpeg raw unit header/content structure.
codec_idFFmpeg codec identifier used to initialize the temporary context.
Returns
Serialized NAL unit bytes, or an empty buffer if FFmpeg rejects the fragment.