Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Adjusting audio and video — Linux

You can make audio and video adjustments to published and subscribed streams:

Publishing audio or video only

You can toggle audio and video on or off, by calling the otc_publisher_set_publish_audio() and otc_publisher_set_publish_video() functions, passing in `OTC_FALSE` or `OTC_FALSE` as the `publish_audio` and `publish_audio` parameters. For example, the following code turns audio off:

otc_publisher_set_publish_audio(publisher, OTC_FALSE);

Publishing in a voice-only session

To set up a voice-only session, instantiate an otc_publisher_settings struct, call the otc_publisher_settings_set_video_track() function, passing in OTC_FALSE as the enabled parameter. Then use the otc_publisher_new_with_settings() function to create. For example, the following code creates a publisher for a voice-only session:


otc_publisher_settings publisher_settings = otc_publisher_settings_new();
otc_publisher_settings_set_video_track(publisher_settings, OTC_FALSE);
otc_publisher_callbacks publisher_callbacks = {0};
// Set callbacks for the publisher. Then:
otc_publisher publisher = otc_publisher_new_with_settings(publisher_callbacks, publisher_settings);

Using a custom video capturer

The otc_publisher_new() function includes a capturer parameter. If you set this to NULL, the SDK uses the default system camera as the source for the published video stream. However, you can use a custom video capturer for the publisher by defining a otc_video_capturer_callbacks struct and passing it in as the capturer parameter of the otc_publisher_new() function. The otc_video_capturer_callbacks struct includes function pointers to callback functions that are invoked upon events related to the publisher video, such as when the video capturer needs a new video frame.

To see an example, see the Custom Video Capturer sample of the opentok-linux-sdk-samples repo.

Using a custom audio driver

You can define a custom audio device, to supply audio to all publishers in the client and to handle the mixed audio stream from all streams the client subscribes to.

A custom audio device is represented by an otc_audio_device struct. And an otc_audio_device_callbacks struct includes function pointers to functions that act as the audio-related callbacks that the OpenTok Linux SDK invokes.

To see an example, see the Custom Audio Device sample in the opentok-linux-sdk-samples repo.

Subscribing to audio or video only

By default, a subscriber is initialized to subscribe to audio and video, if they are available. You can toggle audio on or off by calling the otc_subscriber_set_subscribe_to_audio(otc_subscriber *subscriber, otc_bool subscribe_to_audio) :

// audio off:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_FALSE);
// audio on:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_TRUE);

You can toggle video on or off by calling the otc_subscriber_set_subscribe_to_video(otc_subscriber *subscriber, otc_bool subscribe_to_video) :

// video off:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_FALSE);
// video on:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_TRUE);

Detecting whether a stream has audio or video

You can call the otc_stream_has_audio() and otc_stream_has_audio() member functions of an otc_stream instance to see if it has audio or video.