11 #include <api/video/i420_buffer.h>
12 #include <libyuv/convert.h>
13 #include <libyuv/video_common.h>
14 #include <media/base/video_broadcaster.h>
15 #include <media/base/video_common.h>
22 namespace visualization {
23 namespace webrtc_server {
26 const std::map<std::string, std::string>& opts)
32 const std::string& url,
33 const std::map<std::string, std::string>& opts) {
34 std::unique_ptr<ImageCapturer> image_capturer(
new ImageCapturer(url, opts));
35 return image_capturer.release();
39 : width_(0), height_(0) {
40 if (opts.find(
"width") != opts.end()) {
41 width_ = std::stoi(opts.at(
"width"));
43 if (opts.find(
"height") != opts.end()) {
44 height_ = std::stoi(opts.at(
"height"));
49 const std::shared_ptr<core::Tensor>&
frame) {
53 rtc::scoped_refptr<webrtc::I420Buffer> i420_buffer =
57 const int conversion_result = libyuv::ConvertToI420(
58 frame->GetDataPtr<uint8_t>(), 0, i420_buffer->MutableDataY(),
59 i420_buffer->StrideY(), i420_buffer->MutableDataU(),
60 i420_buffer->StrideU(), i420_buffer->MutableDataV(),
61 i420_buffer->StrideV(), 0, 0,
width,
height, i420_buffer->width(),
62 i420_buffer->height(), libyuv::kRotate0, ::libyuv::FOURCC_RAW);
64 if (conversion_result >= 0) {
65 webrtc::VideoFrame video_frame(i420_buffer,
66 webrtc::VideoRotation::kVideoRotation_0,
74 height = (video_frame.height() *
width) / video_frame.width();
75 }
else if (
width == 0) {
76 width = (video_frame.width() *
height) / video_frame.height();
79 int stride_uv = (
width + 1) / 2;
80 rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer =
82 stride_uv, stride_uv);
83 scaled_buffer->ScaleFrom(
84 *video_frame.video_frame_buffer()->ToI420());
85 webrtc::VideoFrame
frame = webrtc::VideoFrame(
86 scaled_buffer, webrtc::kVideoRotation_0, rtc::TimeMicros());
98 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
99 const rtc::VideoSinkWants& wants) {
104 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) {
static ImageCapturer * Create(const std::string &url, const std::map< std::string, std::string > &opts)
ImageCapturer(const std::string &url_, const std::map< std::string, std::string > &opts)
virtual void RemoveSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink) override
virtual void AddOrUpdateSink(rtc::VideoSinkInterface< webrtc::VideoFrame > *sink, const rtc::VideoSinkWants &wants) override
rtc::VideoBroadcaster broadcaster_
void OnCaptureResult(const std::shared_ptr< core::Tensor > &frame)
Generic file read and write utility for python interface.