MCPcopy Create free account
hub / github.com/TelegramMessenger/tgcalls / genFrame

Method genFrame

tgcalls/FakeVideoTrackSource.cpp:46–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 std::vector<Frame> frames_;
45 size_t i = 0;
46 Frame genFrame(int i, int n) {
47 int width = WIDTH;
48 int height = HEIGHT;
49 auto bytes_ptr = std::make_unique<std::uint8_t[]>(width * height * 4);
50 auto bytes = bytes_ptr.get();
51 auto set_rgb = [&](int x, int y, std::uint8_t r, std::uint8_t g, std::uint8_t b) {
52 auto dest = bytes + (x * width + y) * 4;
53 dest[0] = r;
54 dest[1] = g;
55 dest[2] = b;
56 dest[3] = 0;
57 };
58 auto angle = (double)i / n * M_PI;
59 auto co = cos(angle);
60 auto si = sin(angle);
61
62 for (int i = 0; i < height; i++) {
63 for (int j = 0; j < width; j++) {
64 double sx = (i - height / 2) * 20.0 / HEIGHT;
65 double sy = (j - width / 2) * 20.0 / HEIGHT;
66
67 int x, y;
68 if (sx * sx + sy * sy < 10) {
69 x = int(floor(sx * co - sy * si));
70 y = int(floor(sx * si + sy * co));
71 } else {
72 x = int(floor(sx));
73 y = int(floor(sy));
74 }
75 std::uint8_t color = ((y & 1) ^ (x & 1)) * 255;
76 set_rgb(i, j, color, color, color);
77 }
78 }
79
80 webrtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create(width, height);
81
82 libyuv::RGBAToI420(bytes, width * 4, buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(),
83 buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), width, height);
84
85 return Frame{webrtc::VideoFrame::Builder().set_video_frame_buffer(buffer).build(), std::move(bytes_ptr)};
86 }
87
88};
89

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected