Windows
Updated at:
By reading this article, you can learn how to output audio and video data.
Output video data
- When an application needs to output video media data, it must first inherit the AliRtcEventListener interface to implement onCaptureVideoSample and onRemoteVideoSample callbacks to receive locally collected video naked data and subscribed remote video naked data.
// Callback for receiving bare data. void onCaptureVideoSample(AliRtcVideoSource videoSource, AliRtcVideoDataSample *videoSample) { // Process locally collected video data. } void onRemoteVideoSample(const AliRtc::String &uid, AliRtcVideoSource videoSource, AliRtcVideoDataSample *videoSample) { // Process remote video data. }Note Currently, Windows data output only supports YUV(I420) format data. The application side can convert data to RGBA format by using AliConvertVideoData static interface provided by SDK. - After an application creates an AliRtcEngine engine instance, it calls the operation to registerVideoSampleObserver register the output of bare video data. After registration, when preview is enabled or stream pulling is subscribed to, the video data is continuously called back through onCaptureVideoSample and onRemoteVideoSample.
AliRtcEngine *pEngine = AliRtcEngine::sharedInstance(this, ""); // Register the bare data output of the video. pEngine->registerVideoSampleObserver(); // Start previewing, streaming, and subscribe to videos of other users. .....Note To collect video data locally, you must enable the camera to preview or push the video stream. To collect video data locally, you must enable the camera to preview or push the video stream. To generate the callback, you must also enable the remote video data to subscribe to the video stream of another user. - To stop receiving bare video data, you can call the unRegisterVideoSampleObserver operation to disable the output of bare video data.
// Stop the output of bare video data. pEngine->unRegisterVideoSampleObserver();
Output audio data
- When an application needs to output audio media data, it first needs to inherit the AliRtcEventListener interface and implement onAudioSampleCallback callback to receive audio media data.
Audio data is returned by using the audioSample parameter in the callback. The data format is PCM data. Currently, the SDK supports outputting audio data of different links. In the callback, the type parameter is used to specify the type of the current callback audio data.
The specific meaning is as follows:- AliRtcAudiosourceRawData: raw audio data collected locally.
- AliRtcAudiosourcePub: Audio data processed by Audio 3A.
- AliRtcAudiosourceRawData: the audio data of the current subscribed remote user after mixing.
// The audio media data structure. typedef struct tagAliRtcAudioDataSample { unsigned char *data{nullptr}; // Audio data int numOfSamples{0}; // Number of samples int bytesPerSample{0}; // The number of sampled bits (bytes) int numOfChannels{0}; // Number of channels int samplesPerSec{0}; // sample rate}AliRtcAudioDataSample; // Receive and process audio data callback void void onAudioSampleCallback(AliRtcAudioSource type, AliRtcAudioDataSample *audioSample) { }; - After an AliRtcEngine instance is created, an application registers an audio data callback. The AliAudioType parameter specifies the type of audio data to be output. For more information about the type of audio data to be output, see the previous step. After the registration is complete, the audio data will be continuously called back through the AliAudioObserver.
AliRtcEngine mAliRtcEngine = AliRtcEngine.getInstance(getApplicationContext()); // Start local audio data collection and output. For more information about other types of type output, see enumerated AliAudioType. mAliRtcEngine.registerAudioObserver(type, new AliRtcEngine.AliAudioObserver() { @Override public void onCaptureRawData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec) { } @Override public void onCaptureData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec) { } @Override public void onRenderData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec) { } }); // Start audio streaming and subscribe to videos from other users. .....Note- The callback output is only available when the microphone is turned on to start pushing audio streams for local audio data collection. The callback output is also available when the remote video data is subscribed to the audio streams of other users.
- The AliRtcAudioSourceVolume type in the audio type enumeration AliRtcAudioSource is the registered user volume value callback. When you register a subscription to this type, the user volume will be returned through the onAudioVolumeCallback callback, which is different from the audio data output callback.
- When you need to stop receiving bare video data, call the operation unsubscribeAudioData to disable audio data output. The stop type must correspond to the audio data type registered in Step 2.
// Stop local audio data collection and output. pEngine->unsubscribeAudioData(AliRtcAudiosourceRawData);
Is this page helpful?