10 #ifndef OPENSHOT_WAYLAND_BUFFER_UTILITIES_H
11 #define OPENSHOT_WAYLAND_BUFFER_UTILITIES_H
46 if (max_size == 0 || stream_width <= 0 || stream_height <= 0
47 || stream_width > std::numeric_limits<int>::max() / 4
48 || chunk_stride < 0) {
52 layout.
offset = chunk_offset % max_size;
53 layout.
valid_size = std::min(chunk_size, max_size);
54 layout.
stride = chunk_stride > 0 ? chunk_stride : stream_width * 4;
59 const int readable_width = std::min(
62 const int readable_height = std::min(
66 layout.
crop_x = std::max(0, crop_x);
67 layout.
crop_y = std::max(0, crop_y);
68 if (layout.
crop_x >= readable_width || layout.
crop_y >= readable_height) {
72 const int requested_width = crop_width > 0
74 : stream_width - layout.
crop_x;
75 const int requested_height = crop_height > 0
77 : stream_height - layout.
crop_y;
78 layout.
width = std::min(requested_width, readable_width - layout.
crop_x);
79 layout.
height = std::min(requested_height, readable_height - layout.
crop_y);
88 const size_t final_row_end =
90 +
static_cast<size_t>(layout.
crop_x + layout.
width) * 4;
101 if (!have_last_frame) {
104 const double fps = fps_num > 0 && fps_den > 0
105 ?
static_cast<double>(fps_num) / fps_den
107 return std::max(1,
static_cast<int>(1000.0 / std::max(1.0, fps)));
111 const uint8_t* source,
114 size_t logical_offset,
115 uint8_t* destination,
118 if (!source || !destination || max_size == 0 || byte_count > max_size) {
121 const size_t physical_offset = (
122 (chunk_offset % max_size) + (logical_offset % max_size)
124 const size_t first_size = std::min(byte_count, max_size - physical_offset);
125 std::memcpy(destination, source + physical_offset, first_size);
126 if (first_size < byte_count) {
127 std::memcpy(destination + first_size, source, byte_count - first_size);
bool CopyWrappedBytes(const uint8_t *source, size_t max_size, size_t chunk_offset, size_t logical_offset, uint8_t *destination, size_t byte_count)
PackedVideoLayout ResolvePackedVideoLayout(size_t max_size, size_t chunk_offset, size_t chunk_size, int chunk_stride, int stream_width, int stream_height, int crop_x, int crop_y, int crop_width, int crop_height)
int DamageFrameWaitMilliseconds(int fps_num, int fps_den, bool have_last_frame)