Skip to content

Instantly share code, notes, and snippets.

@alexivaner
Created July 20, 2022 07:06
Show Gist options
  • Save alexivaner/956ae7a9f8c02cad16d54ddd6c84ad97 to your computer and use it in GitHub Desktop.
Save alexivaner/956ae7a9f8c02cad16d54ddd6c84ad97 to your computer and use it in GitHub Desktop.
#include "api/frame_transformer_interface.h"
#include "call/ExampleTransformer.h"
namespace webrtc {
// WebRTC 只会在 webrtc::RTPSenderVideo 的构造方法中注册一个 callback,
// 具体可以参见 rtp_sender_video.cc frame_transformer_delegate_->Init()
void ExampleTransformer::RegisterTransformedFrameSinkCallback(
rtc::scoped_refptr<webrtc::TransformedFrameCallback> callback,
uint32_t ssrc) {
webrtc::MutexLock lock(&mutex_);
sink_callback_ = callback;
}
void ExampleTransformer::UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {
webrtc::MutexLock lock(&mutex_);
sink_callback_ = nullptr;
}
void ExampleTransformer::Transform(
std::unique_ptr<webrtc::TransformableFrameInterface> frame) {
webrtc::MutexLock lock(&mutex_);
if (sink_callback_ == nullptr)
return;
// 在这里处理 frame 的二进制数据...
// 处理完毕后务必调用 sink_callback_ 将帧数据传递给上层
for (size_t i = 0; i < frame.size(); i++) {
frame[i] = frame[i] ^ 2301;
}
sink_callback_->OnTransformedFrame(std::move(frame));
}
} // namespace webrtc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment