UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
vf_split.cpp File Reference
#include <stdio.h>
#include <string.h>
#include "utils/vf_split.h"
#include "video.h"
#include "video_codec.h"
Include dependency graph for vf_split.cpp:

Go to the source code of this file.

Functions

shared_ptr< video_frame > vf_merge_tiles (std::vector< shared_ptr< video_frame > > const &tiles)
 
vector< shared_ptr< video_frame > > vf_separate_tiles (shared_ptr< video_frame > frame)
 
void vf_split (struct video_frame *out, struct video_frame *src, unsigned int x_count, unsigned int y_count, int preallocate)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file vf_split.cpp.

Function Documentation

◆ vf_merge_tiles()

shared_ptr< video_frame > vf_merge_tiles ( std::vector< shared_ptr< video_frame > > const & tiles)

Definition at line 135 of file vf_split.cpp.

136{
137 struct video_desc desc = video_desc_from_frame(tiles[0].get());
138 desc.tile_count = tiles.size();
139
140 auto holder = new decay<decltype(tiles)>::type(tiles);
141 shared_ptr<video_frame> ret(vf_alloc_desc(desc),
142 [holder](struct video_frame *frame) {
143 delete holder;
144 vf_free(frame);
145 });
146
147 int64_t t0 = INT64_MAX;
148 int64_t t1 = 0;
149 for (unsigned int i = 0; i < tiles.size(); ++i) {
150 ret->tiles[i].data = tiles[i]->tiles[0].data;
151 ret->tiles[i].data_len = tiles[i]->tiles[0].data_len;
152 t0 = tiles[i]->compress_start < t0 ? tiles[i]->compress_start : t0;
153 t1 = tiles[i]->compress_end > t1 ? tiles[i]->compress_end : t1;
154 }
155 vf_copy_metadata(ret.get(), tiles.at(0).get());
156 ret->compress_start = t0;
157 ret->compress_end = t1;
158
159 return ret;
160}
struct video_desc desc
struct video_frame * frame
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
Option::OptType type
Definition settings.cpp:194
unsigned int tile_count
Definition types.h:185
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
void vf_copy_metadata(struct video_frame *dest, const struct video_frame *src)

References desc, frame, video_desc::tile_count, type, vf_alloc_desc(), vf_copy_metadata(), vf_free(), and video_desc_from_frame().

Referenced by compress_frame_tiles().

Here is the call graph for this function:

◆ vf_separate_tiles()

vector< shared_ptr< video_frame > > vf_separate_tiles ( shared_ptr< video_frame > frame)

Definition at line 114 of file vf_split.cpp.

115{
116 vector<shared_ptr<video_frame>> ret(frame->tile_count);
118 desc.tile_count = 1;
119
120 for (unsigned int i = 0; i < frame->tile_count; ++i) {
121 auto holder = new shared_ptr<video_frame>(frame);
122 ret[i] = shared_ptr<video_frame>(vf_alloc_desc(desc), [holder](struct video_frame *frame) {
123 delete holder;
124 vf_free(frame);
125 });
126
127 ret[i]->tiles[0].data_len = frame->tiles[i].data_len;
128 ret[i]->tiles[0].data = frame->tiles[i].data;
129 vf_copy_metadata(ret[i].get(), frame.get());
130 }
131
132 return ret;
133}
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
unsigned int tile_count
Definition types.h:344

References tile::data, tile::data_len, desc, frame, video_desc::tile_count, video_frame::tile_count, video_frame::tiles, vf_alloc_desc(), vf_copy_metadata(), vf_free(), and video_desc_from_frame().

Referenced by compress_frame(), and compress_frame_tiles().

Here is the call graph for this function:

◆ vf_split()

void vf_split ( struct video_frame * out,
struct video_frame * src,
unsigned int x_count,
unsigned int y_count,
int preallocate )

vf_split splits the frame into multiple tiles. Caller is responsible for allocating memory for all of these: out (to hold all elements), out elements and theirs data member to hold tile data.

width must be divisible by x_count && heigth by y_count (!)

Parameters
outoutput video frames array the resulting matrix will be stored row-dominant
srcsource video frame
x_countnumber of columns
y_countnumber of rows
preallocateused for preallocating buffers because determining right size can be cumbersome. Anyway only .data are allocated.
Deprecated
this function should not be used

Definition at line 51 of file vf_split.cpp.

53{
54 unsigned int tile_idx, line_idx;
55 struct tile *cur_tiles;
56 unsigned int tile_line = 0;
57 int out_linesize = 0;
58 int src_linesize;
59
60 out->color_spec = src->color_spec;
61 out->fps = src->fps;
62 //out->aux = src->aux | AUX_TILED;
63
64 assert(vf_get_tile(src, 0)->width % x_count == 0u && vf_get_tile(src, 0)->height % y_count == 0u);
65
66 src_linesize = vc_get_linesize(src->tiles[0].width,
67 src->color_spec);
68
69 assert(x_count * y_count > 0);
70 for(tile_idx = 0u; tile_idx < x_count * y_count; ++tile_idx) {
71 out->tiles[tile_idx].width = vf_get_tile(src, 0)->width / x_count;
72 out->tiles[tile_idx].height = vf_get_tile(src, 0)->height / y_count;
73
74 out_linesize = vc_get_linesize(out->tiles[tile_idx].width,
75 src->color_spec);
76 out->tiles[tile_idx].data_len = out_linesize * out->tiles[tile_idx].height;
77 }
78
79 cur_tiles = &out->tiles[0];
80 for(line_idx = 0u; line_idx < vf_get_tile(src, 0)->height; ++line_idx, ++tile_line) {
81 unsigned int cur_tile_idx;
82 unsigned int byte = 0u;
83
84 if (line_idx % (vf_get_tile(src, 0)->height / y_count) == 0u) /* next tiles*/
85 {
86 tile_line = 0u;
87 if (line_idx != 0u)
88 cur_tiles += x_count;
89 if (preallocate) {
90 for (cur_tile_idx = 0u; cur_tile_idx < x_count;
91 ++cur_tile_idx) {
92 cur_tiles[cur_tile_idx].data = (char *)
93 malloc(cur_tiles[cur_tile_idx].
94 data_len);
95 }
96 }
97 }
98
99 for(cur_tile_idx = 0u; cur_tile_idx < x_count; ++cur_tile_idx) {
100 memcpy((void *) &cur_tiles[cur_tile_idx].data[
101 tile_line *
102 out_linesize],
103 (void *) &src->tiles[0].data[line_idx *
104 src_linesize + byte],
105 cur_tiles[cur_tile_idx].width *
106 get_bpp(src->color_spec));
107 byte += cur_tiles[cur_tile_idx].width * get_bpp(src->color_spec);
108 }
109 }
110}
int vc_get_linesize(unsigned int width, codec_t codec)
Struct tile is an area of video_frame.
Definition types.h:279
unsigned int width
Definition types.h:280
unsigned int height
Definition types.h:281
double fps
Definition types.h:308
codec_t color_spec
Definition types.h:306
double get_bpp(codec_t codec)
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].

References video_frame::color_spec, tile::data, tile::data_len, video_frame::fps, get_bpp(), tile::height, video_frame::tiles, vc_get_linesize(), vf_get_tile(), and tile::width.

Referenced by filter(), and split_postprocess().

Here is the call graph for this function: