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

#include <streamer.h>

Inheritance diagram for ttv::broadcast::Streamer:
ttv::UserComponent ttv::Component ttv::IComponent

Classes

class  IListener
 
struct  StartParams
 

Public Types

enum  StreamerState { StreamerState::Stopped, StreamerState::Starting, StreamerState::Started, StreamerState::Stopping }
 
using StartCallback = std::function< void(TTV_ErrorCode ec)>
 
using StopCallback = std::function< void(TTV_ErrorCode ec)>
 
using FrameWriterDelayStateChangedCallback = std::function< void(FrameWriter::DelayState state)>
 
enum  State { State::Uninitialized, State::Initialized, State::ShuttingDown, State::Inert }
 

Public Member Functions

 Streamer (const std::shared_ptr< User > &user, const std::shared_ptr< StreamerContext > &context)
 
virtual ~Streamer ()
 
void AddListener (const std::shared_ptr< IListener > &listener)
 
void RemoveListener (const std::shared_ptr< IListener > &listener)
 
void AddBandwidthStatListener (const std::shared_ptr< IBandwidthStatListener > &listener)
 
void RemoveBandwidthStatListener (const std::shared_ptr< IBandwidthStatListener > &listener)
 
TTV_ErrorCode SetVideoEncoder (const std::shared_ptr< IVideoEncoder > &encoder)
 
TTV_ErrorCode SetAudioEncoder (const std::shared_ptr< IAudioEncoder > &encoder)
 
TTV_ErrorCode SetCustomMuxer (const std::shared_ptr< IMuxer > &muxer)
 
void SetBroadcasterSoftware (const std::string &str)
 
void SetForceArchiveBroadcast (bool forceArchive)
 
void SetFrameWriterDelayStateChangedCallback (const FrameWriterDelayStateChangedCallback &callback)
 
virtual void SetTaskRunner (std::shared_ptr< TaskRunner > taskRunner) override
 
virtual TTV_ErrorCode Initialize () override
 
virtual void Update () override
 
virtual TTV_ErrorCode Shutdown () override
 
virtual std::string GetLoggerName () const override
 
virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
TTV_ErrorCode Start (const StartParams &params, StartCallback &&callback)
 
TTV_ErrorCode Stop (const std::string &reason, StopCallback &&callback)
 
TTV_ErrorCode GetVolume (AudioLayerId layer, float &volume) const
 
TTV_ErrorCode SetVolume (AudioLayerId layer, float volume)
 
void SetAudioCapturer (AudioLayerId layerId, const std::shared_ptr< IAudioCapture > &capturer)
 
void SetAudioCapturerEnabled (AudioLayerId layer, bool enabled)
 
void GetAudioCapturers (std::vector< std::shared_ptr< IAudioCapture >> &result) const
 
std::shared_ptr< IAudioCaptureGetAudioCapturer (AudioLayerId layer) const
 
void SetVideoCapturer (std::shared_ptr< IVideoCapture > capturer)
 
std::shared_ptr< IVideoCaptureGetVideoCapturer () const
 
uint64_t GetStreamTime () const
 
std::shared_ptr< StreamStatsGetStreamStats ()
 
std::shared_ptr< const StreamStatsGetStreamStats () const
 
VideoParams GetVideoParams () const
 
TTV_ErrorCode ValidateParams (const VideoParams &videoParams, const IngestServer &ingestServer) const
 
StreamerState GetStreamerState () const
 
std::shared_ptr< TaskRunnerGetTaskRunner ()
 
virtual State GetState () const override
 

Static Public Member Functions

static std::string GetComponentName ()
 
static void GetRequiredAuthScopes (std::vector< std::string > &scopes)
 

Protected Member Functions

virtual void OnUserLogInComplete (TTV_ErrorCode ec)
 
virtual void OnUserLogOutComplete (TTV_ErrorCode ec)
 
virtual void OnUserInfoFetchComplete (TTV_ErrorCode ec)
 
virtual void OnUserAuthenticationIssue (std::shared_ptr< const OAuthToken > oauthToken, TTV_ErrorCode ec)
 
void Log (TTV_MessageLevel level, const char *format,...)
 
TTV_ErrorCode StartTask (std::shared_ptr< Task > task)
 
void CompleteTask (Task *task)
 
bool IsTaskRunning (Task *task) const
 
virtual void SetState (State state)
 
virtual void SetClientState (State state)
 
virtual void SetServerState (State state)
 

Protected Attributes

std::weak_ptr< UsermUser
 
bool mOAuthIssue
 Whether or not the internal updates of the component are on hold because of an issue with the OAuth token. More...
 
ClientServerValue< StatemState
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::vector< std::shared_ptr< Task > > mRunningTasks
 
std::mutex mTaskMutex
 
uint64_t mShutdownTimeMilliseconds
 

Private Member Functions

TTV_ErrorCode FetchChannelInfo (std::function< void(TTV_ErrorCode ec)> &&callback)
 
TTV_ErrorCode AddVideoFrame (const std::shared_ptr< VideoFrame > &frame)
 
TTV_ErrorCode GetStreamInfo ()
 
TTV_ErrorCode SetIngestServer (const IngestServer &ingestServer)
 
TTV_ErrorCode SetStreamName (const std::string &streamKey, bool absEnabled)
 
TTV_ErrorCode KickOffStart (const StartParams &params, StartCallback &&callback)
 
TTV_ErrorCode InternalStart (const StartParams &params)
 
TTV_ErrorCode InternalStop (TTV_ErrorCode ec, bool solicited, StopCallback &&callback)
 
TTV_ErrorCode UpdateBandwidthWarningState ()
 
TTV_ErrorCode TrackStartFailure (TTV_ErrorCode ec, bool synchronous)
 
TTV_ErrorCode TrackMinuteBroadcast ()
 
void NotifyStreamerStateChanged ()
 

Private Attributes

std::unique_ptr< StreamInfomStreamInfo
 
StartParams mStartParams
 
AudioParams mAudioParams
 
IngestServer mSelectedIngestServer
 
std::shared_ptr< StreamerContextmContext
 
std::string mOutputStreamName
 
std::shared_ptr< FlvMuxermFlvMuxer
 
std::shared_ptr< FrameWritermFrameWriter
 
std::shared_ptr< StreamStatsmStreamStats
 
std::shared_ptr< VideoStreamermVideoStreamer
 
std::shared_ptr< AudioStreamermAudioStreamer
 
EventSource< IListenermListeners
 
ttv::ConcurrentQueue< BandwidthStatmStatQueue
 
EventSource< IBandwidthStatListenermBandwidthStatListeners
 
ChannelId mChannelId
 The name of the channel to broadcast to. More...
 
std::string mStreamKey
 The key that grants stream access to the channel. More...
 
std::string mBroadcasterSoftware
 The broadcaster_software parameter to send over RTMP. More...
 
uint64_t mInitialTime
 The number of system ticks at the time of stream start. More...
 
std::mutex mStateMutex
 
StreamerState mStreamerState
 
RetryTimer mStreamInfoFetchTimer
 
StreamerState mLastReportedStreamerState
 The state last reported to the client. More...
 
TTV_ErrorCode mStateChangeError
 The cause of the last state change. More...
 
WaitForExpiry mBandwidthWarningTimer
 
TTV_ErrorCode mBandwidthWarningState
 
WaitForExpiry mMinuteBroadcastTrackingTimer
 
std::shared_ptr< IVideoEncodermVideoEncoder
 
std::shared_ptr< IAudioEncodermAudioEncoder
 
std::shared_ptr< IVideoCapturemVideoCapturer
 
std::shared_ptr< IMuxermCustomMuxer
 
std::shared_ptr< TrackingContextmTrackingContext
 
FrameWriterDelayStateChangedCallback mFrameWriterDelayStateChangedCallback
 
bool mFirstFrameSubmitted
 
bool mBandwidthTestMode
 
bool mForceArchiveBroadcast
 If true appends recorder=1 to the RTMP URL forcing the server to record the broadcast. More...
 

Detailed Description

The following must be set before initialization:

The starting and stopping of the broadcast is always asynchronous. When stopping a broadcast it is possible that the stop may not complete immediately of the network has backed up and encoded frames are still being sent to the ingest server. Wait for the stop callback.


Class Documentation

◆ ttv::broadcast::Streamer::StartParams

struct ttv::broadcast::Streamer::StartParams
Class Members
StreamStartFlags flags
IngestServer ingestServer
wstring outputFile
VideoParams videoParams

Member Typedef Documentation

◆ FrameWriterDelayStateChangedCallback

◆ StartCallback

using ttv::broadcast::Streamer::StartCallback = std::function<void(TTV_ErrorCode ec)>

◆ StopCallback

using ttv::broadcast::Streamer::StopCallback = std::function<void(TTV_ErrorCode ec)>

Member Enumeration Documentation

◆ State

enum ttv::IComponent::State
stronginherited
Enumerator
Uninitialized 
Initialized 
ShuttingDown 
Inert 

The component doesn't require shutting down.

◆ StreamerState

Enumerator
Stopped 
Starting 
Started 
Stopping 

Constructor & Destructor Documentation

◆ Streamer()

ttv::broadcast::Streamer::Streamer ( const std::shared_ptr< User > &  user,
const std::shared_ptr< StreamerContext > &  context 
)

◆ ~Streamer()

virtual ttv::broadcast::Streamer::~Streamer ( )
virtual

Member Function Documentation

◆ AddBandwidthStatListener()

void ttv::broadcast::Streamer::AddBandwidthStatListener ( const std::shared_ptr< IBandwidthStatListener > &  listener)

◆ AddListener()

void ttv::broadcast::Streamer::AddListener ( const std::shared_ptr< IListener > &  listener)

◆ AddVideoFrame()

TTV_ErrorCode ttv::broadcast::Streamer::AddVideoFrame ( const std::shared_ptr< VideoFrame > &  frame)
private

◆ CheckShutdown()

virtual bool ttv::broadcast::Streamer::CheckShutdown ( )
overridevirtual

Reimplemented from ttv::Component.

◆ CompleteShutdown()

virtual void ttv::broadcast::Streamer::CompleteShutdown ( )
overridevirtual

Reimplemented from ttv::UserComponent.

◆ CompleteTask()

void ttv::Component::CompleteTask ( Task task)
protectedinherited

◆ FetchChannelInfo()

TTV_ErrorCode ttv::broadcast::Streamer::FetchChannelInfo ( std::function< void(TTV_ErrorCode ec)> &&  callback)
private

◆ GetAudioCapturer()

std::shared_ptr<IAudioCapture> ttv::broadcast::Streamer::GetAudioCapturer ( AudioLayerId  layer) const

◆ GetAudioCapturers()

void ttv::broadcast::Streamer::GetAudioCapturers ( std::vector< std::shared_ptr< IAudioCapture >> &  result) const

◆ GetComponentName()

static std::string ttv::broadcast::Streamer::GetComponentName ( )
inlinestatic

◆ GetLoggerName()

virtual std::string ttv::broadcast::Streamer::GetLoggerName ( ) const
overridevirtual

Implements ttv::Component.

◆ GetRequiredAuthScopes()

static void ttv::broadcast::Streamer::GetRequiredAuthScopes ( std::vector< std::string > &  scopes)
static

◆ GetState()

virtual State ttv::Component::GetState ( ) const
overridevirtualinherited

Implements ttv::IComponent.

◆ GetStreamerState()

StreamerState ttv::broadcast::Streamer::GetStreamerState ( ) const

◆ GetStreamInfo()

TTV_ErrorCode ttv::broadcast::Streamer::GetStreamInfo ( )
private

◆ GetStreamStats() [1/2]

std::shared_ptr<StreamStats> ttv::broadcast::Streamer::GetStreamStats ( )
inline

◆ GetStreamStats() [2/2]

std::shared_ptr<const StreamStats> ttv::broadcast::Streamer::GetStreamStats ( ) const
inline

◆ GetStreamTime()

uint64_t ttv::broadcast::Streamer::GetStreamTime ( ) const

◆ GetTaskRunner()

std::shared_ptr<TaskRunner> ttv::Component::GetTaskRunner ( )
inlineinherited

◆ GetVideoCapturer()

std::shared_ptr<IVideoCapture> ttv::broadcast::Streamer::GetVideoCapturer ( ) const

◆ GetVideoParams()

VideoParams ttv::broadcast::Streamer::GetVideoParams ( ) const
inline

◆ GetVolume()

TTV_ErrorCode ttv::broadcast::Streamer::GetVolume ( AudioLayerId  layer,
float &  volume 
) const

◆ Initialize()

virtual TTV_ErrorCode ttv::broadcast::Streamer::Initialize ( )
overridevirtual

Reimplemented from ttv::UserComponent.

◆ InternalStart()

TTV_ErrorCode ttv::broadcast::Streamer::InternalStart ( const StartParams params)
private

◆ InternalStop()

TTV_ErrorCode ttv::broadcast::Streamer::InternalStop ( TTV_ErrorCode  ec,
bool  solicited,
StopCallback &&  callback 
)
private

◆ IsTaskRunning()

bool ttv::Component::IsTaskRunning ( Task task) const
protectedinherited

◆ KickOffStart()

TTV_ErrorCode ttv::broadcast::Streamer::KickOffStart ( const StartParams params,
StartCallback &&  callback 
)
private

◆ Log()

void ttv::UserComponent::Log ( TTV_MessageLevel  level,
const char *  format,
  ... 
)
protectedinherited

◆ NotifyStreamerStateChanged()

void ttv::broadcast::Streamer::NotifyStreamerStateChanged ( )
private

◆ OnUserAuthenticationIssue()

virtual void ttv::UserComponent::OnUserAuthenticationIssue ( std::shared_ptr< const OAuthToken oauthToken,
TTV_ErrorCode  ec 
)
protectedvirtualinherited

◆ OnUserInfoFetchComplete()

virtual void ttv::UserComponent::OnUserInfoFetchComplete ( TTV_ErrorCode  ec)
protectedvirtualinherited

◆ OnUserLogInComplete()

virtual void ttv::UserComponent::OnUserLogInComplete ( TTV_ErrorCode  ec)
protectedvirtualinherited

◆ OnUserLogOutComplete()

virtual void ttv::UserComponent::OnUserLogOutComplete ( TTV_ErrorCode  ec)
protectedvirtualinherited

◆ RemoveBandwidthStatListener()

void ttv::broadcast::Streamer::RemoveBandwidthStatListener ( const std::shared_ptr< IBandwidthStatListener > &  listener)

◆ RemoveListener()

void ttv::broadcast::Streamer::RemoveListener ( const std::shared_ptr< IListener > &  listener)

◆ SetAudioCapturer()

void ttv::broadcast::Streamer::SetAudioCapturer ( AudioLayerId  layerId,
const std::shared_ptr< IAudioCapture > &  capturer 
)

◆ SetAudioCapturerEnabled()

void ttv::broadcast::Streamer::SetAudioCapturerEnabled ( AudioLayerId  layer,
bool  enabled 
)

◆ SetAudioEncoder()

TTV_ErrorCode ttv::broadcast::Streamer::SetAudioEncoder ( const std::shared_ptr< IAudioEncoder > &  encoder)

◆ SetBroadcasterSoftware()

void ttv::broadcast::Streamer::SetBroadcasterSoftware ( const std::string &  str)
inline

Sets the broadcaster_software value for the stream.

◆ SetClientState()

virtual void ttv::Component::SetClientState ( State  state)
protectedvirtualinherited

◆ SetCustomMuxer()

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

◆ SetForceArchiveBroadcast()

void ttv::broadcast::Streamer::SetForceArchiveBroadcast ( bool  forceArchive)
inline

Sets the force archive flag for the stream

◆ SetFrameWriterDelayStateChangedCallback()

void ttv::broadcast::Streamer::SetFrameWriterDelayStateChangedCallback ( const FrameWriterDelayStateChangedCallback callback)
inline

◆ SetIngestServer()

TTV_ErrorCode ttv::broadcast::Streamer::SetIngestServer ( const IngestServer ingestServer)
private

◆ SetServerState()

virtual void ttv::Component::SetServerState ( State  state)
protectedvirtualinherited

◆ SetState()

virtual void ttv::Component::SetState ( State  state)
protectedvirtualinherited

◆ SetStreamName()

TTV_ErrorCode ttv::broadcast::Streamer::SetStreamName ( const std::string &  streamKey,
bool  absEnabled 
)
private

◆ SetTaskRunner()

virtual void ttv::broadcast::Streamer::SetTaskRunner ( std::shared_ptr< TaskRunner taskRunner)
overridevirtual

Reimplemented from ttv::Component.

◆ SetVideoCapturer()

void ttv::broadcast::Streamer::SetVideoCapturer ( std::shared_ptr< IVideoCapture capturer)

◆ SetVideoEncoder()

TTV_ErrorCode ttv::broadcast::Streamer::SetVideoEncoder ( const std::shared_ptr< IVideoEncoder > &  encoder)

These must be set before calling Initialize().

◆ SetVolume()

TTV_ErrorCode ttv::broadcast::Streamer::SetVolume ( AudioLayerId  layer,
float  volume 
)

◆ Shutdown()

virtual TTV_ErrorCode ttv::broadcast::Streamer::Shutdown ( )
overridevirtual

Reimplemented from ttv::Component.

◆ Start()

TTV_ErrorCode ttv::broadcast::Streamer::Start ( const StartParams params,
StartCallback &&  callback 
)

Performs an asynchronous start.

◆ StartTask()

TTV_ErrorCode ttv::Component::StartTask ( std::shared_ptr< Task task)
protectedinherited

◆ Stop()

TTV_ErrorCode ttv::broadcast::Streamer::Stop ( const std::string &  reason,
StopCallback &&  callback 
)

Performs an asynchronous stop.

◆ TrackMinuteBroadcast()

TTV_ErrorCode ttv::broadcast::Streamer::TrackMinuteBroadcast ( )
private

◆ TrackStartFailure()

TTV_ErrorCode ttv::broadcast::Streamer::TrackStartFailure ( TTV_ErrorCode  ec,
bool  synchronous 
)
private

Sends a tracking event indicating that we failed to start the broadcast.

Parameters
[in]ecThe error that occurred when trying to start.
[in]synchronousIf this is true, the failure occurred synchronously and an error was immediately returned to the client. If this is false, the error was delivered asynchronously in the client's callback.

◆ Update()

virtual void ttv::broadcast::Streamer::Update ( )
overridevirtual

Reimplemented from ttv::Component.

◆ UpdateBandwidthWarningState()

TTV_ErrorCode ttv::broadcast::Streamer::UpdateBandwidthWarningState ( )
private

◆ ValidateParams()

TTV_ErrorCode ttv::broadcast::Streamer::ValidateParams ( const VideoParams videoParams,
const IngestServer ingestServer 
) const

Member Data Documentation

◆ mAudioEncoder

std::shared_ptr<IAudioEncoder> ttv::broadcast::Streamer::mAudioEncoder
private

◆ mAudioParams

AudioParams ttv::broadcast::Streamer::mAudioParams
private

◆ mAudioStreamer

std::shared_ptr<AudioStreamer> ttv::broadcast::Streamer::mAudioStreamer
private

◆ mBandwidthStatListeners

EventSource<IBandwidthStatListener> ttv::broadcast::Streamer::mBandwidthStatListeners
private

◆ mBandwidthTestMode

bool ttv::broadcast::Streamer::mBandwidthTestMode
private

◆ mBandwidthWarningState

TTV_ErrorCode ttv::broadcast::Streamer::mBandwidthWarningState
private

◆ mBandwidthWarningTimer

WaitForExpiry ttv::broadcast::Streamer::mBandwidthWarningTimer
private

◆ mBroadcasterSoftware

std::string ttv::broadcast::Streamer::mBroadcasterSoftware
private

The broadcaster_software parameter to send over RTMP.

◆ mChannelId

ChannelId ttv::broadcast::Streamer::mChannelId
private

The name of the channel to broadcast to.

◆ mContext

std::shared_ptr<StreamerContext> ttv::broadcast::Streamer::mContext
private

◆ mCustomMuxer

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

◆ mFirstFrameSubmitted

bool ttv::broadcast::Streamer::mFirstFrameSubmitted
private

◆ mFlvMuxer

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

◆ mForceArchiveBroadcast

bool ttv::broadcast::Streamer::mForceArchiveBroadcast
private

If true appends recorder=1 to the RTMP URL forcing the server to record the broadcast.

◆ mFrameWriter

std::shared_ptr<FrameWriter> ttv::broadcast::Streamer::mFrameWriter
private

◆ mFrameWriterDelayStateChangedCallback

FrameWriterDelayStateChangedCallback ttv::broadcast::Streamer::mFrameWriterDelayStateChangedCallback
private

◆ mInitialTime

uint64_t ttv::broadcast::Streamer::mInitialTime
private

The number of system ticks at the time of stream start.

◆ mLastReportedStreamerState

StreamerState ttv::broadcast::Streamer::mLastReportedStreamerState
private

The state last reported to the client.

◆ mListeners

EventSource<IListener> ttv::broadcast::Streamer::mListeners
private

◆ mMinuteBroadcastTrackingTimer

WaitForExpiry ttv::broadcast::Streamer::mMinuteBroadcastTrackingTimer
private

◆ mOAuthIssue

bool ttv::UserComponent::mOAuthIssue
protectedinherited

Whether or not the internal updates of the component are on hold because of an issue with the OAuth token.

◆ mOutputStreamName

std::string ttv::broadcast::Streamer::mOutputStreamName
private

◆ mRunningTasks

std::vector<std::shared_ptr<Task> > ttv::Component::mRunningTasks
protectedinherited

◆ mSelectedIngestServer

IngestServer ttv::broadcast::Streamer::mSelectedIngestServer
private

◆ mShutdownTimeMilliseconds

uint64_t ttv::Component::mShutdownTimeMilliseconds
protectedinherited

◆ mStartParams

StartParams ttv::broadcast::Streamer::mStartParams
private

◆ mState

ClientServerValue<State> ttv::Component::mState
protectedinherited

◆ mStateChangeError

TTV_ErrorCode ttv::broadcast::Streamer::mStateChangeError
private

The cause of the last state change.

◆ mStateMutex

std::mutex ttv::broadcast::Streamer::mStateMutex
mutableprivate

◆ mStatQueue

ttv::ConcurrentQueue<BandwidthStat> ttv::broadcast::Streamer::mStatQueue
private

◆ mStreamerState

StreamerState ttv::broadcast::Streamer::mStreamerState
private

◆ mStreamInfo

std::unique_ptr<StreamInfo> ttv::broadcast::Streamer::mStreamInfo
private

◆ mStreamInfoFetchTimer

RetryTimer ttv::broadcast::Streamer::mStreamInfoFetchTimer
private

◆ mStreamKey

std::string ttv::broadcast::Streamer::mStreamKey
private

The key that grants stream access to the channel.

◆ mStreamStats

std::shared_ptr<StreamStats> ttv::broadcast::Streamer::mStreamStats
private

◆ mTaskMutex

std::mutex ttv::Component::mTaskMutex
mutableprotectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::Component::mTaskRunner
protectedinherited

◆ mTrackingContext

std::shared_ptr<TrackingContext> ttv::broadcast::Streamer::mTrackingContext
private

◆ mUser

std::weak_ptr<User> ttv::UserComponent::mUser
protectedinherited

◆ mVideoCapturer

std::shared_ptr<IVideoCapture> ttv::broadcast::Streamer::mVideoCapturer
private

◆ mVideoEncoder

std::shared_ptr<IVideoEncoder> ttv::broadcast::Streamer::mVideoEncoder
private

◆ mVideoStreamer

std::shared_ptr<VideoStreamer> ttv::broadcast::Streamer::mVideoStreamer
private

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