1.3.8. Feed Stages
1.3.8.1. Overview
So far, feeds have a rather fixed structure, taking some kind of input (e.g. from a camera) and outputting it to some target, which could be a local output (e.g. a window) or to a remote recipient.
Feed “stages” allow additional processing to be applied to the feed - e.g. a video feed could be rotated and/or cropped before continuing its journey to the target. Importantly, the application can decide the order in which these stages are applied, allowing a chain of processing and feed modification to occur for any given feed.
1.3.8.2. Creating a feed stage
A feed stage is a special type of feed component that take a media type (e.g. video) and outputs the same media type. Depending on the stage’s purpose, it may modify the media in some way, but it could also be used to inspect the media and perform other processing or actions (e.g. analysing the feed media for some purpose).
In the following example, we create a stage that will:
Rotate the video feed by 90 degrees, then
Crop the video feed top and bottom by 128 pixels
using namespace Proximie;
// Create rotate & crop stages
PxMedia::VideoStageRotateFlip rotate;
rotate.method(PxMedia::VideoStageRotateFlip::Method::Clockwise90);
PxMedia::VideoStageCrop crop;
crop.cropRectangle().top(128).bottom(128);
1.3.8.3. Applying stages to a feed component
As mentioned above, certain feed components allow stages to be added to them. For example, most video sources allow stages to be applied for post-processing the source video.
Here we create an input feed as normal:
PxMedia::VideoInputFeedV4Linux2 video;
video.deviceProperties().device("/dev/video0");
video.videoCapabilities().frameRate(30);
Then, we can set the sequence of video stages:
video.videoStages().sequence({rotate, crop});
Note that the video stages sequence()
method takes a vector
of stages, allowing multiple stages to be applied in the
required order - in this case, rotate first and then crop.
Once the stages are added to the feed component, the application can use that component
to create a feed as normal.
The stages defined using sequence()
are inserted into the resulting feed’s pipeline.
auto created = PxMedia::MediaServerOutgoingVideoFeed::create(session, props, video, output);
if (created) {
// ...
See the process of creating feeds described in the section Managing feeds for more details.
1.3.8.4. Available feed stages
Video stages
All video feed stages are derived from VideoFeedStageComponent
.
For more details and a list of available stage subclasses, see the API documentation for
VideoFeedStageComponent
itself.
Audio stages
All audio feed stages are derived from AudioFeedStageComponent
.
For more details and a list of available stage subclasses, see the API documentation for
AudioFeedStageComponent
itself.
The following audio feed stages are now available:
AudioStageVolume
: Adjusts the volume of the audio feed.AudioStageWebRtcDsp
: Applies configurable WebRTC audio processing filters, such as automatic gain control (AGC), noise suppression, and high-pass filtering.
AudioStageWebRtcDsp is unavailable on Ubuntu 24.04
The
AudioStageWebRtcDsp
stage requires that thewebrtcdsp
gstreamer plugin is installed on the system. Seemingly due to an oversight, this plugin is not available on Ubuntu 24.04.
An example:
// Create media session audio feeds
PxMedia::MediaServerTwoWayAudioFeed::FeedProperties audio{"audio"};
// Create an audio input feed
PxMedia::AudioInputFeedAuto micInput;
PxMedia::AudioFeedStageSequence::ComponentSequence audioInputStages;
// Create and configure a DSP stage, and add it to the audio input feed
PxMedia::AudioStageWebRtcDsp webRtcDspStage;
webRtcDspStage.gainControl(true).noiseSuppression(false);
audioInputStages.push_back(webRtcDspStage);
micInput.audioStages().sequence(audioInputStages);
// Create an audio output feed
PxMedia::AudioOutputFeedAuto audioOutput;
PxMedia::AudioFeedStageSequence::ComponentSequence audioOutputStages;
// Create a volume stage to adjust the volume of the audio output feed
PxMedia::AudioStageVolume volumeStage;
volumeStage.volume(0.9F); // Decrease volume by 10%
audioOutputStages.push_back(volumeStage);
audioOutput.audioStages().sequence(audioOutputStages);
auto audioFeedCreated = PxMedia::MediaServerTwoWayAudioFeed::create(
mediaServerSession, audio, micInput, audioOutput);