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::BroadcastAPI Class Reference

#include <broadcastapi.h>

Inheritance diagram for ttv::broadcast::BroadcastAPI:
ttv::ModuleBase ttv::IModule

Classes

class  CoreApiClient
 

Public Types

using StartBroadcastCallback = std::function< void(TTV_ErrorCode ec)>
 
using StopBroadcastCallback = std::function< void(TTV_ErrorCode ec)>
 
using FetchIngestListCallback = std::function< void(TTV_ErrorCode ec, std::vector< IngestServer > &&result)>
 
using RunCommercialCallback = std::function< void(TTV_ErrorCode ec)>
 
using SetStreamInfoCallback = std::function< void(TTV_ErrorCode ec)>
 
enum  State { State::Uninitialized, State::Initializing, State::Initialized, State::ShuttingDown }
 
using InitializeCallback = std::function< void(TTV_ErrorCode ec)>
 
using ShutdownCallback = std::function< void(TTV_ErrorCode ec)>
 

Public Member Functions

 BroadcastAPI ()
 
virtual ~BroadcastAPI ()
 
virtual std::string GetModuleName () const override
 
virtual TTV_ErrorCode Initialize (const InitializeCallback &callback) override
 
virtual TTV_ErrorCode Shutdown (const ShutdownCallback &callback) override
 
virtual TTV_ErrorCode Update () override
 
TTV_ErrorCode SetCoreApi (const std::shared_ptr< CoreAPI > &coreApi)
 
TTV_ErrorCode SetListener (const std::shared_ptr< IBroadcastAPIListener > &listener)
 
TTV_ErrorCode SetCustomMuxer (const std::shared_ptr< IMuxer > &muxer)
 
TTV_ErrorCode SetBroadcasterSoftware (const std::string &str)
 
TTV_ErrorCode SetForceArchiveBroadcast (bool forceArchive)
 
TTV_ErrorCode SetActiveUser (UserId userId)
 
TTV_ErrorCode SetVideoEncoder (const std::shared_ptr< IVideoEncoder > &encoder)
 
TTV_ErrorCode SetAudioEncoder (const std::shared_ptr< IAudioEncoder > &encoder)
 
TTV_ErrorCode SetVideoCapturer (const std::shared_ptr< IVideoCapture > &capturer)
 
TTV_ErrorCode SetAudioCapturer (AudioLayerId layer, const std::shared_ptr< IAudioCapture > &capturer)
 
TTV_ErrorCode RemoveAudioCapturer (AudioLayerId layer)
 
TTV_ErrorCode SetAudioLayerVolume (AudioLayerId layer, float volume)
 
TTV_ErrorCode SetAudioLayerMuted (AudioLayerId layer, bool muted)
 
TTV_ErrorCode SetAudioLayerEnabled (AudioLayerId layer, bool enabled)
 
TTV_ErrorCode SetVideoParams (const VideoParams &videoParams)
 
TTV_ErrorCode GetVideoParams (VideoParams &videoParams)
 
TTV_ErrorCode SetOutputPath (const std::wstring &outputPath)
 
TTV_ErrorCode SetConnectionType (ConnectionType connectionType)
 
TTV_ErrorCode SetSessionId (const std::string &sessionId)
 
TTV_ErrorCode AddBandwidthStatListener (const std::shared_ptr< IBandwidthStatListener > &listener)
 
TTV_ErrorCode RemoveBandwidthStatListener (const std::shared_ptr< IBandwidthStatListener > &listener)
 
TTV_ErrorCode StartBroadcast (StartBroadcastCallback &&callback)
 
TTV_ErrorCode StopBroadcast (const std::string &reason, StopBroadcastCallback &&callback)
 
TTV_ErrorCode GetCurrentBroadcastTime (uint64_t &broadcastTime)
 
TTV_ErrorCode FetchIngestServerList (FetchIngestListCallback &&callback)
 
TTV_ErrorCode GetSelectedIngestServer (IngestServer &result)
 
TTV_ErrorCode SetSelectedIngestServer (const IngestServer &server)
 
TTV_ErrorCode GetBroadcastState (BroadcastState &result) const
 
TTV_ErrorCode RunCommercial (UserId userId, ChannelId channelId, uint32_t timebreakSeconds, RunCommercialCallback &&callback)
 
TTV_ErrorCode SetStreamInfo (UserId userId, ChannelId channelId, const std::string &game, const std::string &title, SetStreamInfoCallback &&callback)
 
TTV_ErrorCode CreateIngestTester (UserId userId, const std::shared_ptr< IIngestTesterListener > &listener, const uint8_t *testDataBuffer, uint32_t testDataLength, std::shared_ptr< IIngestTester > &result)
 
TTV_ErrorCode DisposeIngestTester (const std::shared_ptr< IIngestTester > &ingestTester)
 
virtual State GetState () const override
 

Static Public Member Functions

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

Protected Member Functions

void NotifyStateChange ()
 
void RegisterInitializeCallback (const InitializeCallback &callback)
 
void RegisterShutdownCallback (const ShutdownCallback &callback)
 
template<typename T >
void Invoke (std::function< void(std::shared_ptr< T >)> callback)
 
std::shared_ptr< ComponentContainerGetComponentContainer ()
 

Protected Attributes

EventSource< IModuleListenermListeners
 
State mState
 
State mLastReportedState
 

Private Member Functions

void CoreUserLoggedIn (std::shared_ptr< User > user)
 
void CoreUserLoggedOut (std::shared_ptr< User > user)
 
virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
std::shared_ptr< StreamerCreateStreamer (const std::shared_ptr< User > &user)
 
std::shared_ptr< TwitchAPICreateTwitchAPI (const std::shared_ptr< User > &user)
 
TTV_ErrorCode GetStreamer (std::shared_ptr< Streamer > &result)
 
TTV_ErrorCode EnsureBroadcastingAndGetStreamer (std::shared_ptr< Streamer > &result)
 
TTV_ErrorCode EnsureNotBroadcastingAndGetStreamer (std::shared_ptr< Streamer > &result)
 
TTV_ErrorCode BindToUser (const std::shared_ptr< User > &user)
 
void SetBroadcastState (TTV_ErrorCode ec, BroadcastState state)
 

Private Attributes

std::shared_ptr< BroadcastApiInternalData > mInternalData
 
std::shared_ptr< CoreApiClientmCoreApiClient
 The client instance registered with CoreAPI. More...
 

Detailed Description

This module provides the ability to broadcast to Twitch by accepting video and audio data from a game/app, encoding it and sending it to the Twitch backend in realtime.

The following properties must be set before calling Initialize().

In order to broadcast several services must be configured using the following methods.

The video parameters must also be set via one of the 2 following methods.

Currently, only one user may be broadcasting at a time. In order to specify which user will broadcast SetActiveUser() must be used. The active user must be set and the user logged in before configuring any of the encoders, capturers and other settings. If the active user is changed or logged out then the configuration is lost.

If you have a custom application which has a need to access the raw encoded data then see the SetCustomMuxer() method.

Member Typedef Documentation

◆ FetchIngestListCallback

using ttv::broadcast::BroadcastAPI::FetchIngestListCallback = std::function<void(TTV_ErrorCode ec, std::vector<IngestServer>&& result)>

◆ InitializeCallback

using ttv::IModule::InitializeCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ RunCommercialCallback

◆ SetStreamInfoCallback

◆ ShutdownCallback

using ttv::IModule::ShutdownCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ StartBroadcastCallback

◆ StopBroadcastCallback

Member Enumeration Documentation

◆ State

enum ttv::IModule::State
stronginherited
Enumerator
Uninitialized 
Initializing 
Initialized 
ShuttingDown 

Constructor & Destructor Documentation

◆ BroadcastAPI()

ttv::broadcast::BroadcastAPI::BroadcastAPI ( )

◆ ~BroadcastAPI()

virtual ttv::broadcast::BroadcastAPI::~BroadcastAPI ( )
virtual

Member Function Documentation

◆ AddBandwidthStatListener()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::AddBandwidthStatListener ( const std::shared_ptr< IBandwidthStatListener > &  listener)

Adds a listener that will be periodically called back with statistics about network usage. This should not be invoked while broadcasting.

◆ BindToUser()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::BindToUser ( const std::shared_ptr< User > &  user)
private

◆ CheckShutdown()

virtual bool ttv::broadcast::BroadcastAPI::CheckShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ CompleteShutdown()

virtual void ttv::broadcast::BroadcastAPI::CompleteShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ CoreUserLoggedIn()

void ttv::broadcast::BroadcastAPI::CoreUserLoggedIn ( std::shared_ptr< User user)
private

◆ CoreUserLoggedOut()

void ttv::broadcast::BroadcastAPI::CoreUserLoggedOut ( std::shared_ptr< User user)
private

◆ CreateIngestTester()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::CreateIngestTester ( UserId  userId,
const std::shared_ptr< IIngestTesterListener > &  listener,
const uint8_t *  testDataBuffer,
uint32_t  testDataLength,
std::shared_ptr< IIngestTester > &  result 
)

Returns an implementation of IIngestTester for the given owning user. When done with the implementation it must be released via DisposeIngestTester().

◆ CreateStreamer()

std::shared_ptr<Streamer> ttv::broadcast::BroadcastAPI::CreateStreamer ( const std::shared_ptr< User > &  user)
private

◆ CreateTwitchAPI()

std::shared_ptr<TwitchAPI> ttv::broadcast::BroadcastAPI::CreateTwitchAPI ( const std::shared_ptr< User > &  user)
private

◆ DisposeIngestTester()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::DisposeIngestTester ( const std::shared_ptr< IIngestTester > &  ingestTester)

Releases the given IIngestTester implementation that was returned by CreateIngestTester().

◆ EnsureBroadcastingAndGetStreamer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::EnsureBroadcastingAndGetStreamer ( std::shared_ptr< Streamer > &  result)
private

◆ EnsureNotBroadcastingAndGetStreamer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::EnsureNotBroadcastingAndGetStreamer ( std::shared_ptr< Streamer > &  result)
private

◆ FetchIngestServerList()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::FetchIngestServerList ( FetchIngestListCallback &&  callback)

Fetches the list of available ingest servers that can be used for broadcasting.

◆ GetBroadcastState()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::GetBroadcastState ( BroadcastState result) const

Retrieves the current state of broadcasting.

◆ GetComponentContainer()

std::shared_ptr<ComponentContainer> ttv::ModuleBase::GetComponentContainer ( )
inlineprotectedinherited

Returns the common ComponentContainer which hosts all components which live at the module level.

◆ GetCurrentBroadcastTime()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::GetCurrentBroadcastTime ( uint64_t &  broadcastTime)

Retrieves the current time in the live broadcast.

◆ GetModuleName()

virtual std::string ttv::broadcast::BroadcastAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetRequiredAuthScopes()

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

Retrieves the OAuth token scopes required to support all features in this module.

◆ GetSelectedIngestServer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::GetSelectedIngestServer ( IngestServer result)

Retrieves the currently selected ingest server. It's possible that none is selected and will contain empty values.

◆ GetState()

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

Returns the current state of the module.

Implements ttv::IModule.

◆ GetStreamer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::GetStreamer ( std::shared_ptr< Streamer > &  result)
private

◆ GetVideoParams()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::GetVideoParams ( VideoParams videoParams)

Retrieves the currently set VideoParams.

◆ Initialize()

virtual TTV_ErrorCode ttv::broadcast::BroadcastAPI::Initialize ( const InitializeCallback callback)
overridevirtual

Initializes the module asynchronously. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Invoke()

template<typename T >
void ttv::ModuleBase::Invoke ( std::function< void(std::shared_ptr< T >)>  callback)
inlineprotectedinherited

Invokes the callback for the module listeners.

◆ NotifyStateChange()

void ttv::ModuleBase::NotifyStateChange ( )
protectedinherited

◆ RegisterInitializeCallback()

void ttv::ModuleBase::RegisterInitializeCallback ( const InitializeCallback callback)
inlineprotectedinherited

◆ RegisterShutdownCallback()

void ttv::ModuleBase::RegisterShutdownCallback ( const ShutdownCallback callback)
inlineprotectedinherited

◆ RemoveAudioCapturer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::RemoveAudioCapturer ( AudioLayerId  layer)

Removes a previously added audio capturer for the given layer.

◆ RemoveBandwidthStatListener()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::RemoveBandwidthStatListener ( const std::shared_ptr< IBandwidthStatListener > &  listener)

Removes a previously added bandwidth stat listener. This should not be invoked while broadcasting.

◆ RunCommercial()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::RunCommercial ( UserId  userId,
ChannelId  channelId,
uint32_t  timebreakSeconds,
RunCommercialCallback &&  callback 
)

Triggers a commercial of the specified duration in seconds. This may be triggered independently from whether or not a broadcast is in progress. Note that only partnered users may run commercials.

◆ SetActiveUser()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetActiveUser ( UserId  userId)

Sets the userid of the user who will be broadcasting. This must be set before attempting to broadcast and cannot be changed while broadcasting. See the class description for more details.

◆ SetAudioCapturer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetAudioCapturer ( AudioLayerId  layer,
const std::shared_ptr< IAudioCapture > &  capturer 
)

Sets the source of audio samples for the given layer. The layer ids are up to the client but generally start at 0 and increment for each layer the application adds. For instance, a capturer for system audio could be added for layer 0 and a microphone capturer added for layer 1.

◆ SetAudioEncoder()

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

Sets the desired audio encoder to use.

◆ SetAudioLayerEnabled()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetAudioLayerEnabled ( AudioLayerId  layer,
bool  enabled 
)

This will enable or disable the associated capturer for the entire broadcast. This cannot be changed while broadcasting. The IAudioCapture for the layer must already be set via SetAudioCapturer().

◆ SetAudioLayerMuted()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetAudioLayerMuted ( AudioLayerId  layer,
bool  muted 
)

This mutes the audio for the given audio layer and can be toggled freely during a stream. The IAudioCapture for the layer must already be set via SetAudioCapturer().

◆ SetAudioLayerVolume()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetAudioLayerVolume ( AudioLayerId  layer,
float  volume 
)

Sets the volume of given audio layer and can be toggled freely during a stream. The IAudioCapture for the layer must already be set via SetAudioCapturer().

◆ SetBroadcasterSoftware()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetBroadcasterSoftware ( const std::string &  str)

Sets the broadcaster_software value associated with the stream so the software used can be identified.

◆ SetBroadcastState()

void ttv::broadcast::BroadcastAPI::SetBroadcastState ( TTV_ErrorCode  ec,
BroadcastState  state 
)
private

◆ SetConnectionType()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetConnectionType ( ConnectionType  connectionType)

Sets the type of connection that will be used to broadcast. This value is used when sending tracking events.

◆ SetCoreApi()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetCoreApi ( const std::shared_ptr< CoreAPI > &  coreApi)

Sets the CoreAPI instance to use for low level services. This must be set before Initialize() is called.

◆ SetCustomMuxer()

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

Sets an optional receiver of post-encoded video and audio data. This can only be called before starting a broadcast.

Parameters
muxerA custom IMuxer implementation which allow an application to obtain the raw encoded data.

◆ SetForceArchiveBroadcast()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetForceArchiveBroadcast ( bool  forceArchive)

Sets the flag which forces the recording of the broadcast on the server (recorder=1 in the RTMP URL)

◆ SetListener()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetListener ( const std::shared_ptr< IBroadcastAPIListener > &  listener)

Sets the client listener implementation. This must be set before Initialize() is called.

◆ SetOutputPath()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetOutputPath ( const std::wstring &  outputPath)

Sets the output FLV file path for saving a broadcast locally for debugging and verification.

◆ SetSelectedIngestServer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetSelectedIngestServer ( const IngestServer server)

Sets the selected ingest server to use when initiating broadcasts.

◆ SetSessionId()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetSessionId ( const std::string &  sessionId)

Sets a unique ID for the broadcasting session, which can span multiple starts/stops. This value is used when sending tracking events.

◆ SetStreamInfo()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetStreamInfo ( UserId  userId,
ChannelId  channelId,
const std::string &  game,
const std::string &  title,
SetStreamInfoCallback &&  callback 
)

Sets the current game and stream title for a channel. These values may be set independently from whether or not a broadcast is in progress.

◆ SetVideoCapturer()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetVideoCapturer ( const std::shared_ptr< IVideoCapture > &  capturer)

Sets the source of video frames.

◆ SetVideoEncoder()

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

Sets the desired video encoder to use.

◆ SetVideoParams()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::SetVideoParams ( const VideoParams videoParams)

Sets the VideoParams to use for the broadcast. This cannot be set while a stream is in progress.

◆ Shutdown()

virtual TTV_ErrorCode ttv::broadcast::BroadcastAPI::Shutdown ( const ShutdownCallback callback)
overridevirtual

Initiates an asynchronous shutdown of the module. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. All modules that depend on this module need to be shutdown first. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ StartBroadcast()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::StartBroadcast ( StartBroadcastCallback &&  callback)

Initiates broadcasting for the active user.

◆ StopBroadcast()

TTV_ErrorCode ttv::broadcast::BroadcastAPI::StopBroadcast ( const std::string &  reason,
StopBroadcastCallback &&  callback 
)

Gracefully stops broadcasting.

Parameters
[in]reasonA string describing why the stream is being stopped, used for tracking. Pass in "user_ended" if this was an explicit action from the user.

◆ Update()

virtual TTV_ErrorCode ttv::broadcast::BroadcastAPI::Update ( )
overridevirtual

Updates the internal state of the module and fires any pending callbacks.

Reimplemented from ttv::ModuleBase.

Member Data Documentation

◆ mCoreApiClient

std::shared_ptr<CoreApiClient> ttv::broadcast::BroadcastAPI::mCoreApiClient
private

The client instance registered with CoreAPI.

◆ mInternalData

std::shared_ptr<BroadcastApiInternalData> ttv::broadcast::BroadcastAPI::mInternalData
private

◆ mLastReportedState

State ttv::ModuleBase::mLastReportedState
protectedinherited

◆ mListeners

EventSource<IModuleListener> ttv::ModuleBase::mListeners
protectedinherited

The registered listeners. These listeners extend IModuleListener and will be of the type required for the module.

◆ mState

State ttv::ModuleBase::mState
protectedinherited

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