Subscribing to a stream

In this guide you will learn to subscribe users to a stream within your application.

The on_stream_received callback function (see the previous section) includes a stream parameter, which is a pointer to an otc_stream struct representing the new stream. To subscribe to the stream, instantiate a otc_subscriber_callbacks instance, set some callback functions for subscriber-related events, and then call the otc_subscriber_new() function passing in the otc_stream and otc_subscriber_callbacks instances

Use the user_data member of the otc_subscriber_callbacks structure to set data you may want to reference in the callback functions. In this example, we set it to a pointer to a string object. But it could be a pointer to an instance of some other type that contains meaningful information.

The other members of the otc_subscriber_callbacks structure are each callback functions that are invoked when events related to the subscriber occur:

  • on_connected — Called when the subscriber connects to the audio-video stream.
  • on_render_frame — Called each time the subscriber is ready to render a new video frame.
  • on_error — Called when a subscriber error occurs.

All callbacks will not be made on the application or main thread but on an internal thread. The application should return the callback as quickly as possible to avoid blocking the internal thread.

See otc_subscriber_callbacks in the Vonage Video Linux SDK reference for details on each of the callback functions.

Unsubscribing from a stream

To stop playing a stream you are subscribed to, call the otc_session_unsubscribe() function, passing in the otc_session and otc_subscriber instances:

Call the otc_subscriber_delete() function to release the subscriber instance, including all hardware and UI resources bound to it.