Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ttv::broadcast::FrameWriter Class Reference

#include <framewriter.h>

Inheritance diagram for ttv::broadcast::FrameWriter:
ttv::broadcast::IFrameWriter

Classes

struct  TrackedStatsRunningTotals
 

Public Types

enum  DelayState { DelayState::Okay, DelayState::Warning, DelayState::Error }
 
using StreamAbortFunc = std::function< void(FrameWriter *source, TTV_ErrorCode ec)>
 
using DelayStateChangedCallback = std::function< void(FrameWriter *source, DelayState state)>
 
using BandwidthStatCallback = std::function< void(FrameWriter *source, const BandwidthStat &stat)>
 

Public Member Functions

 FrameWriter (bool audioEnabled)
 
virtual ~FrameWriter ()
 
TTV_ErrorCode SetFlvMuxer (const std::shared_ptr< FlvMuxer > &flvMuxer)
 
TTV_ErrorCode SetCustomMuxer (const std::shared_ptr< IMuxer > &muxer)
 
TTV_ErrorCode Start (const VideoParams &videoParams)
 
TTV_ErrorCode GetLastError ()
 
uint64_t GetQueueDelayInMilliseconds () const
 
uint32_t GetQueueDelayInBytes () const
 
uint32_t GetRecommendedBitRate () const
 
void SetWarningDelayThresholdMilliseconds (uint64_t warningThreshHold)
 
void SetErrorDelayThresholdMilliseconds (uint64_t errorThreshold)
 
DelayState GetDelayState () const
 
void SetDelayStateChangedCallback (const DelayStateChangedCallback &callback)
 
void Shutdown ()
 
void SetStreamAbortCallback (StreamAbortFunc func)
 
void SetBandwidthStatCallback (const BandwidthStatCallback &callback)
 
TTV_ErrorCode GatherTrackingStats (uint64_t &averageRecommendedKbps, uint64_t &averageEncodedKbps)
 
virtual TTV_ErrorCode WritePacket (std::unique_ptr< Packet > &&packet) override
 

Private Member Functions

void TransferPacketToOutputQueues (std::unique_ptr< Packet > &&packet)
 
TTV_ErrorCode SendDataToMuxers ()
 
void UpdateRecommendedBitRate ()
 
void UpdateDelayState ()
 

Private Attributes

std::mutex mMutex
 
std::condition_variable mCondition
 
std::queue< std::unique_ptr< Packet > > mPacketQueue
 
bool mWriteFrameThreadProceed
 Flag to indicate that the write thread should continue processing and will be true until the writer is shutdown. More...
 
std::shared_ptr< IThreadmWriteFrameThread
 The thread that does the writing. More...
 
std::shared_ptr< FlvMuxermFlvMuxer
 
std::shared_ptr< IMuxermCustomMuxer
 
StreamAbortFunc mStreamAbortCallback
 The function to call if the stream goes down. More...
 
std::queue< std::unique_ptr< Packet > > mAudioPacketQueue
 
std::queue< std::unique_ptr< Packet > > mVideoPacketQueue
 
VideoParams mVideoParams
 
std::atomic< uint64_t > mLastSentPacketTimestamp
 
std::atomic< uint64_t > mLastReceivedPacketTimestamp
 
DelayStateChangedCallback mDelayStateChangedCallback
 
uint64_t mWarningDelayThreshold
 
uint64_t mErrorDelayThreshold
 
std::atomic< uint32_t > mNumQueuedBytes
 The number of bytes that are in the audio and video packet queues. More...
 
std::atomic< uint64_t > mEncodedBitCounter
 The number of bytes output by the necoder since the last adjustment time. More...
 
uint64_t mStreamStartSystemTime
 The system clock time at the start of the stream. More...
 
uint64_t mLastStatTime
 The last time a bandwidth stat was emitted. More...
 
TrackedStatsRunningTotals mRunningTotals
 
std::mutex mRunningTotalsMutex
 
BandwidthStatCallback mBandwidthStatCallback
 Callback that is invoked when a new bandwidth stat is generated. More...
 
WaitForExpiry mBitrateUpdateTimer
 Timer for periodically updating the recommended bit rate. More...
 
WaitForExpiry mBitrateIncreaseTimer
 Timer that enforces the frequency at which we can increase the bit rate. More...
 
uint32_t mRecommendedBitRate
 The last recommended bitrate in bits per second. More...
 
TTV_ErrorCode mLastError
 
DelayState mDelayState
 
bool mAudioEnabled
 

Detailed Description

Responsible for gathering data packets from multiple sources and writing them to the FLV stream.

Member Typedef Documentation

◆ BandwidthStatCallback

using ttv::broadcast::FrameWriter::BandwidthStatCallback = std::function<void(FrameWriter* source, const BandwidthStat& stat)>

◆ DelayStateChangedCallback

◆ StreamAbortFunc

Member Enumeration Documentation

◆ DelayState

Enumerator
Okay 
Warning 
Error 

Constructor & Destructor Documentation

◆ FrameWriter()

ttv::broadcast::FrameWriter::FrameWriter ( bool  audioEnabled)

◆ ~FrameWriter()

virtual ttv::broadcast::FrameWriter::~FrameWriter ( )
virtual

Member Function Documentation

◆ GatherTrackingStats()

TTV_ErrorCode ttv::broadcast::FrameWriter::GatherTrackingStats ( uint64_t &  averageRecommendedKbps,
uint64_t &  averageEncodedKbps 
)

Returns the average recommended kbps and the average encoded kbps since the last time this method was called.

Parameters
[out]averageRecommendedKbpsThe average bit rate recommended by the ABS algorithm since the last time this method was called.
[out]averageEncodedKbpsThe actual bit rate output by the video encoder since the last time this method was called.

◆ GetDelayState()

DelayState ttv::broadcast::FrameWriter::GetDelayState ( ) const
inline

◆ GetLastError()

TTV_ErrorCode ttv::broadcast::FrameWriter::GetLastError ( )

◆ GetQueueDelayInBytes()

uint32_t ttv::broadcast::FrameWriter::GetQueueDelayInBytes ( ) const
inline

Determines how many bytes of data are backed up on the send queue.

◆ GetQueueDelayInMilliseconds()

uint64_t ttv::broadcast::FrameWriter::GetQueueDelayInMilliseconds ( ) const

Determines how many milliseconds of data is backed up on the send queue.

◆ GetRecommendedBitRate()

uint32_t ttv::broadcast::FrameWriter::GetRecommendedBitRate ( ) const

Determines the bitrate in bits per second that should be used to maintain optimal stream health. This value will change frequently and may drop dramatically if bandwidth conditions worsen.

◆ SendDataToMuxers()

TTV_ErrorCode ttv::broadcast::FrameWriter::SendDataToMuxers ( )
private

◆ SetBandwidthStatCallback()

void ttv::broadcast::FrameWriter::SetBandwidthStatCallback ( const BandwidthStatCallback callback)
inline

◆ SetCustomMuxer()

TTV_ErrorCode ttv::broadcast::FrameWriter::SetCustomMuxer ( const std::shared_ptr< IMuxer > &  muxer)

◆ SetDelayStateChangedCallback()

void ttv::broadcast::FrameWriter::SetDelayStateChangedCallback ( const DelayStateChangedCallback callback)
inline

◆ SetErrorDelayThresholdMilliseconds()

void ttv::broadcast::FrameWriter::SetErrorDelayThresholdMilliseconds ( uint64_t  errorThreshold)
inline

◆ SetFlvMuxer()

TTV_ErrorCode ttv::broadcast::FrameWriter::SetFlvMuxer ( const std::shared_ptr< FlvMuxer > &  flvMuxer)

◆ SetStreamAbortCallback()

void ttv::broadcast::FrameWriter::SetStreamAbortCallback ( StreamAbortFunc  func)
inline

◆ SetWarningDelayThresholdMilliseconds()

void ttv::broadcast::FrameWriter::SetWarningDelayThresholdMilliseconds ( uint64_t  warningThreshHold)
inline

◆ Shutdown()

void ttv::broadcast::FrameWriter::Shutdown ( )

◆ Start()

TTV_ErrorCode ttv::broadcast::FrameWriter::Start ( const VideoParams videoParams)

◆ TransferPacketToOutputQueues()

void ttv::broadcast::FrameWriter::TransferPacketToOutputQueues ( std::unique_ptr< Packet > &&  packet)
private

◆ UpdateDelayState()

void ttv::broadcast::FrameWriter::UpdateDelayState ( )
private

◆ UpdateRecommendedBitRate()

void ttv::broadcast::FrameWriter::UpdateRecommendedBitRate ( )
private

◆ WritePacket()

virtual TTV_ErrorCode ttv::broadcast::FrameWriter::WritePacket ( std::unique_ptr< Packet > &&  packet)
overridevirtual

Adds a packet to be written to the network that contains video or audio data.

Implements ttv::broadcast::IFrameWriter.

Member Data Documentation

◆ mAudioEnabled

bool ttv::broadcast::FrameWriter::mAudioEnabled
private

◆ mAudioPacketQueue

std::queue<std::unique_ptr<Packet> > ttv::broadcast::FrameWriter::mAudioPacketQueue
private

◆ mBandwidthStatCallback

BandwidthStatCallback ttv::broadcast::FrameWriter::mBandwidthStatCallback
private

Callback that is invoked when a new bandwidth stat is generated.

◆ mBitrateIncreaseTimer

WaitForExpiry ttv::broadcast::FrameWriter::mBitrateIncreaseTimer
private

Timer that enforces the frequency at which we can increase the bit rate.

◆ mBitrateUpdateTimer

WaitForExpiry ttv::broadcast::FrameWriter::mBitrateUpdateTimer
private

Timer for periodically updating the recommended bit rate.

◆ mCondition

std::condition_variable ttv::broadcast::FrameWriter::mCondition
private

◆ mCustomMuxer

std::shared_ptr<IMuxer> ttv::broadcast::FrameWriter::mCustomMuxer
private

◆ mDelayState

DelayState ttv::broadcast::FrameWriter::mDelayState
private

◆ mDelayStateChangedCallback

DelayStateChangedCallback ttv::broadcast::FrameWriter::mDelayStateChangedCallback
private

◆ mEncodedBitCounter

std::atomic<uint64_t> ttv::broadcast::FrameWriter::mEncodedBitCounter
private

The number of bytes output by the necoder since the last adjustment time.

◆ mErrorDelayThreshold

uint64_t ttv::broadcast::FrameWriter::mErrorDelayThreshold
private

◆ mFlvMuxer

std::shared_ptr<FlvMuxer> ttv::broadcast::FrameWriter::mFlvMuxer
private

◆ mLastError

TTV_ErrorCode ttv::broadcast::FrameWriter::mLastError
private

◆ mLastReceivedPacketTimestamp

std::atomic<uint64_t> ttv::broadcast::FrameWriter::mLastReceivedPacketTimestamp
private

◆ mLastSentPacketTimestamp

std::atomic<uint64_t> ttv::broadcast::FrameWriter::mLastSentPacketTimestamp
private

◆ mLastStatTime

uint64_t ttv::broadcast::FrameWriter::mLastStatTime
private

The last time a bandwidth stat was emitted.

◆ mMutex

std::mutex ttv::broadcast::FrameWriter::mMutex
private

◆ mNumQueuedBytes

std::atomic<uint32_t> ttv::broadcast::FrameWriter::mNumQueuedBytes
private

The number of bytes that are in the audio and video packet queues.

◆ mPacketQueue

std::queue<std::unique_ptr<Packet> > ttv::broadcast::FrameWriter::mPacketQueue
private

◆ mRecommendedBitRate

uint32_t ttv::broadcast::FrameWriter::mRecommendedBitRate
private

The last recommended bitrate in bits per second.

◆ mRunningTotals

TrackedStatsRunningTotals ttv::broadcast::FrameWriter::mRunningTotals
private

◆ mRunningTotalsMutex

std::mutex ttv::broadcast::FrameWriter::mRunningTotalsMutex
private

◆ mStreamAbortCallback

StreamAbortFunc ttv::broadcast::FrameWriter::mStreamAbortCallback
private

The function to call if the stream goes down.

◆ mStreamStartSystemTime

uint64_t ttv::broadcast::FrameWriter::mStreamStartSystemTime
private

The system clock time at the start of the stream.

◆ mVideoPacketQueue

std::queue<std::unique_ptr<Packet> > ttv::broadcast::FrameWriter::mVideoPacketQueue
private

◆ mVideoParams

VideoParams ttv::broadcast::FrameWriter::mVideoParams
private

◆ mWarningDelayThreshold

uint64_t ttv::broadcast::FrameWriter::mWarningDelayThreshold
private

◆ mWriteFrameThread

std::shared_ptr<IThread> ttv::broadcast::FrameWriter::mWriteFrameThread
private

The thread that does the writing.

◆ mWriteFrameThreadProceed

bool ttv::broadcast::FrameWriter::mWriteFrameThreadProceed
private

Flag to indicate that the write thread should continue processing and will be true until the writer is shutdown.


The documentation for this class was generated from the following file: