UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_frame_pool::impl Struct Reference
Collaboration diagram for video_frame_pool::impl:
Collaboration graph

Classes

struct  m_desc
 

Public Member Functions

 impl (unsigned int max_used_frames=0, video_frame_pool_allocator const &alloc=default_data_allocator())
 
 ~impl ()
 
video_frame_pool_allocator const & get_allocator ()
 
struct video_frame * get_disposable_frame ()
 
std::shared_ptr< video_frame > get_frame ()
 
struct video_frame * get_pod_frame ()
 
void reconfigure (struct video_desc new_desc, size_t new_size=SIZE_MAX)
 

Private Member Functions

void deallocate_frame (struct video_frame *frame)
 
void remove_free_frames ()
 

Private Attributes

std::unique_ptr< video_frame_pool_allocator > m_allocator = std::unique_ptr<video_frame_pool_allocator>(new default_data_allocator)
 
std::condition_variable m_frame_returned
 
std::queue< struct video_frame * > m_free_frames
 
int m_generation = 0
 
std::mutex m_lock
 
size_t m_max_data_len = 0
 
unsigned int m_max_used_frames
 
unsigned int m_unreturned_frames = 0
 

Detailed Description

Definition at line 57 of file video_frame_pool.cpp.

Constructor & Destructor Documentation

◆ impl()

video_frame_pool::impl::impl ( unsigned int max_used_frames = 0,
video_frame_pool_allocator const & alloc = default_data_allocator() )
explicit

Definition at line 140 of file video_frame_pool.cpp.

142 : m_allocator(alloc.clone()), m_max_used_frames(max_used_frames)
143{
144}
std::unique_ptr< video_frame_pool_allocator > m_allocator

◆ ~impl()

video_frame_pool::impl::~impl ( )

Definition at line 146 of file video_frame_pool.cpp.

146 {
147 std::unique_lock<std::mutex> lk(m_lock);
149 // wait also for all frames we gave out to return us
150 m_frame_returned.wait(lk, [this] {return m_unreturned_frames == 0;});
151}
std::condition_variable m_frame_returned

Member Function Documentation

◆ deallocate_frame()

void video_frame_pool::impl::deallocate_frame ( struct video_frame * frame)
private

Definition at line 242 of file video_frame_pool.cpp.

242 {
243 if (frame == NULL)
244 return;
245 for (unsigned int i = 0; i < frame->tile_count; ++i) {
246 m_allocator->deallocate(frame->tiles[i].data);
247 }
248 vf_free(frame);
249}
struct video_frame * frame
void vf_free(struct video_frame *buf)
Frees video_frame structure.
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
unsigned int tile_count
Definition types.h:344

References tile::data, frame, video_frame::tile_count, video_frame::tiles, and vf_free().

Here is the call graph for this function:

◆ get_allocator()

video_frame_pool_allocator const & video_frame_pool::impl::get_allocator ( )

Definition at line 230 of file video_frame_pool.cpp.

230 {
231 return *m_allocator;
232}

◆ get_disposable_frame()

struct video_frame * video_frame_pool::impl::get_disposable_frame ( )

Definition at line 207 of file video_frame_pool.cpp.

207 {
208 auto && frame = get_frame();
209 struct video_frame *out = frame.get();
211 new std::shared_ptr<video_frame>(std::move(frame));
212 static auto dispose = [](video_frame *f) { delete static_cast<std::shared_ptr<video_frame> *>(f->callbacks.dispose_udata); };
213 out->callbacks.dispose = dispose;
214 return out;
215}
void(* dispose)(struct video_frame *)
Definition types.h:245
std::shared_ptr< video_frame > get_frame()
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct video_frame_callbacks callbacks
Definition types.h:324

References video_frame::callbacks, video_frame_callbacks::dispose, video_frame_callbacks::dispose_udata, frame, and video_frame_pool::get_frame().

Here is the call graph for this function:

◆ get_frame()

std::shared_ptr< video_frame > video_frame_pool::impl::get_frame ( )

Definition at line 161 of file video_frame_pool.cpp.

161 {
162 struct video_frame *ret = NULL;
163 std::unique_lock<std::mutex> lk(m_lock);
164 assert(m_generation != 0);
165 if (!m_free_frames.empty()) {
166 ret = m_free_frames.front();
167 m_free_frames.pop();
169 m_frame_returned.wait(lk, [this] {return m_unreturned_frames < m_max_used_frames;});
170 assert(!m_free_frames.empty());
171 ret = m_free_frames.front();
172 m_free_frames.pop();
173 } else {
174 try {
175 ret = vf_alloc_desc(m_desc);
176 for (unsigned int i = 0; i < m_desc.tile_count; ++i) {
177 ret->tiles[i].data =
178 (char *) m_allocator->allocate(
180 if (ret->tiles[i].data == NULL) {
181 throw std::runtime_error("Cannot allocate data");
182 }
183 ret->tiles[i].data_len = m_max_data_len;
184 }
185 } catch (std::exception &e) {
186 std::cerr << e.what() << std::endl;
187 deallocate_frame(ret);
188 throw e;
189 }
190 }
192 return std::shared_ptr<video_frame>(ret, std::bind([this](struct video_frame *frame, int generation) {
193 std::unique_lock<std::mutex> lk(m_lock);
194
195 assert(m_unreturned_frames > 0);
197 m_frame_returned.notify_one();
198
199 if (this->m_generation != generation) {
200 this->deallocate_frame(frame);
201 } else {
202 m_free_frames.push(frame);
203 }
204 }, std::placeholders::_1, m_generation));
205}
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
unsigned int data_len
length of the data
Definition types.h:288
std::queue< struct video_frame * > m_free_frames
void deallocate_frame(struct video_frame *frame)
#define MAX_PADDING
Definition video_codec.h:63

References tile::data, tile::data_len, frame, MAX_PADDING, video_frame::tiles, and vf_alloc_desc().

Here is the call graph for this function:

◆ get_pod_frame()

struct video_frame * video_frame_pool::impl::get_pod_frame ( )

Definition at line 217 of file video_frame_pool.cpp.

217 {
218 auto && frame = get_frame();
220 for (unsigned int i = 0; i < frame->tile_count; ++i) {
221 out->tiles[i].data = frame->tiles[i].data;
222 }
224 new std::shared_ptr<video_frame>(std::move(frame));
225 static auto deleter = [](video_frame *f) { delete static_cast<std::shared_ptr<video_frame> *>(f->callbacks.dispose_udata); };
227 return out;
228}
int void(** deleter)(void *))
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
void(* data_deleter)(struct video_frame *)
Definition types.h:256

References video_frame::callbacks, tile::data, video_frame_callbacks::data_deleter, deleter, video_frame_callbacks::dispose_udata, frame, video_frame_pool::get_frame(), video_frame::tile_count, video_frame::tiles, vf_alloc_desc(), and video_desc_from_frame().

Here is the call graph for this function:

◆ reconfigure()

void video_frame_pool::impl::reconfigure ( struct video_desc new_desc,
size_t new_size = SIZE_MAX )

Definition at line 153 of file video_frame_pool.cpp.

153 {
154 std::unique_lock<std::mutex> lk(m_lock);
155 m_desc = new_desc;
156 m_max_data_len = new_size != SIZE_MAX ? new_size : new_desc.height * vc_get_linesize(new_desc.width, new_desc.color_spec);
158 m_generation++;
159}
int vc_get_linesize(unsigned int width, codec_t codec)
codec_t color_spec
Definition types.h:182
unsigned int width
width of every tile (!)
Definition types.h:179
unsigned int height
height of every tile (!)
Definition types.h:180

References video_desc::color_spec, video_desc::height, vc_get_linesize(), and video_desc::width.

Here is the call graph for this function:

◆ remove_free_frames()

void video_frame_pool::impl::remove_free_frames ( )
private

Definition at line 234 of file video_frame_pool.cpp.

234 {
235 while (!m_free_frames.empty()) {
236 struct video_frame *frame = m_free_frames.front();
237 m_free_frames.pop();
239 }
240}

References frame.

Member Data Documentation

◆ m_allocator

std::unique_ptr<video_frame_pool_allocator> video_frame_pool::impl::m_allocator = std::unique_ptr<video_frame_pool_allocator>(new default_data_allocator)
private

Definition at line 74 of file video_frame_pool.cpp.

◆ m_frame_returned

std::condition_variable video_frame_pool::impl::m_frame_returned
private

Definition at line 77 of file video_frame_pool.cpp.

◆ m_free_frames

std::queue<struct video_frame *> video_frame_pool::impl::m_free_frames
private

Definition at line 75 of file video_frame_pool.cpp.

◆ m_generation

int video_frame_pool::impl::m_generation = 0
private

Definition at line 78 of file video_frame_pool.cpp.

◆ m_lock

std::mutex video_frame_pool::impl::m_lock
private

Definition at line 76 of file video_frame_pool.cpp.

◆ m_max_data_len

size_t video_frame_pool::impl::m_max_data_len = 0
private

Definition at line 80 of file video_frame_pool.cpp.

◆ m_max_used_frames

unsigned int video_frame_pool::impl::m_max_used_frames
private

Definition at line 82 of file video_frame_pool.cpp.

◆ m_unreturned_frames

unsigned int video_frame_pool::impl::m_unreturned_frames = 0
private

Definition at line 81 of file video_frame_pool.cpp.


The documentation for this struct was generated from the following file: