UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
pano_gl.cpp File Reference
#include <cassert>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <queue>
#include "debug.h"
#include "host.h"
#include "keyboard_control.h"
#include "lib_common.h"
#include "messaging.h"
#include "module.h"
#include "video.h"
#include "video_display.h"
#include "video_display/splashscreen.h"
#include "opengl_utils.hpp"
#include "opengl_panorama.hpp"
#include "sdl_window.hpp"
#include "utils/profile_timer.hpp"
Include dependency graph for pano_gl.cpp:

Go to the source code of this file.

Classes

struct  state_vr
 

Macros

#define MAX_BUFFER_SIZE   1
 
#define MOD_NAME   "[pano gl] "
 

Functions

static void display_panogl_done (void *state)
 
static bool display_panogl_get_property (void *state, int property, void *val, size_t *len)
 
static struct video_frame * display_panogl_getf (void *state)
 
static void * display_panogl_init (struct module *parent, const char *fmt, unsigned int flags)
 
static void display_panogl_probe (struct device_info **available_cards, int *count, void(**deleter)(void *))
 
static bool display_panogl_putf (void *state, struct video_frame *frame, long long nonblock)
 
static bool display_panogl_reconfigure (void *state, struct video_desc desc)
 
static void display_panogl_run (void *state)
 
static void draw (state_vr *s)
 
static void handle_keyboard_event (state_vr *s, SDL_Event *event)
 
static void handle_user_event (state_vr *s, SDL_Event *event)
 
static void handle_window_event (state_vr *s, SDL_Event *event)
 
static void redraw (state_vr *s, bool video_framerate_over_threshold=false, bool triggered_by_frame=false)
 
static Uint32 redraw_callback (Uint32 interval, void *param)
 
 REGISTER_MODULE (pano_gl, &display_panogl_info, LIBRARY_CLASS_VIDEO_DISPLAY, VIDEO_DISPLAY_ABI_VERSION)
 

Variables

static const struct video_display_info display_panogl_info
 

Detailed Description

Author
Martin Piatka piatk.nosp@m.a@ce.nosp@m.snet..nosp@m.cz

Definition in file pano_gl.cpp.

Macro Definition Documentation

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   1

Definition at line 64 of file pano_gl.cpp.

Referenced by display_panogl_putf().

◆ MOD_NAME

#define MOD_NAME   "[pano gl] "

Definition at line 65 of file pano_gl.cpp.

Function Documentation

◆ display_panogl_done()

static void display_panogl_done ( void * state)
static

Definition at line 258 of file pano_gl.cpp.

258 {
259 state_vr *s = static_cast<state_vr *>(state);
260
261 delete s;
262}
void ** state

References state.

◆ display_panogl_get_property()

static bool display_panogl_get_property ( void * state,
int property,
void * val,
size_t * len )
static

Definition at line 317 of file pano_gl.cpp.

317 {
318 struct state_vr *s = static_cast<state_vr *>(state);
319 enum interlacing_t supported_il_modes[] = {PROGRESSIVE};
320 int rgb_shift[] = {0, 8, 16};
321
322 switch (property) {
324 auto codecs = s->scene.get_codecs();
325 size_t codecs_size = codecs.size() * sizeof(codec_t);
326 if(codecs_size <= *len) {
327 memcpy(val, codecs.data(), codecs_size);
328 } else {
329 return false;
330 }
331
332 *len = codecs_size;
333 break;
334 }
336 if(sizeof(rgb_shift) > *len) {
337 return false;
338 }
339 memcpy(val, rgb_shift, sizeof(rgb_shift));
340 *len = sizeof(rgb_shift);
341 break;
343 *(int *) val = PITCH_DEFAULT;
344 *len = sizeof(int);
345 break;
347 if(sizeof(supported_il_modes) <= *len) {
348 memcpy(val, supported_il_modes, sizeof(supported_il_modes));
349 } else {
350 return false;
351 }
352 *len = sizeof(supported_il_modes);
353 break;
354 default:
355 return false;
356 }
357 return true;
358}
int void * val
int void size_t * len
int property
#define PITCH_DEFAULT
default pitch, i. e. respective linesize
@ DISPLAY_PROPERTY_BUF_PITCH
requested framebuffer pitch - int (bytes), may be PITCH_DEFAULT
@ DISPLAY_PROPERTY_RGB_SHIFT
red,green,blue shift - int[3] (bits)
@ DISPLAY_PROPERTY_SUPPORTED_IL_MODES
display supported interlacing modes - enum interlacing_t[]
@ DISPLAY_PROPERTY_CODECS
list of natively supported codecs - codec_t[]
std::vector< codec_t > get_codecs()
PanoramaScene scene
Definition pano_gl.cpp:79
interlacing_t
Definition types.h:163
@ PROGRESSIVE
progressive frame
Definition types.h:164
codec_t
Definition types.h:65
static struct @76 codecs[]

References codecs, DISPLAY_PROPERTY_BUF_PITCH, DISPLAY_PROPERTY_CODECS, DISPLAY_PROPERTY_RGB_SHIFT, DISPLAY_PROPERTY_SUPPORTED_IL_MODES, PanoramaScene::get_codecs(), len, PITCH_DEFAULT, PROGRESSIVE, property, state_vr::scene, state, and val.

Here is the call graph for this function:

◆ display_panogl_getf()

static struct video_frame * display_panogl_getf ( void * state)
static

Definition at line 264 of file pano_gl.cpp.

264 {
265 struct state_vr *s = static_cast<state_vr *>(state);
266
267 std::lock_guard<std::mutex> lock(s->lock);
268
269 while (s->free_frame_queue.size() > 0) {
270 struct video_frame *buffer = s->free_frame_queue.front();
271 s->free_frame_queue.pop();
273 return buffer;
274 } else {
275 vf_free(buffer);
276 }
277 }
278
280}
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_data(struct video_desc desc)
std::mutex lock
Definition pano_gl.cpp:88
std::queue< video_frame * > free_frame_queue
Definition pano_gl.cpp:90
video_desc current_desc
Definition pano_gl.cpp:76
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
bool video_desc_eq(struct video_desc a, struct video_desc b)
Compares two video descriptions.

References state_vr::current_desc, state_vr::free_frame_queue, state_vr::lock, state, vf_alloc_desc_data(), vf_free(), video_desc_eq(), and video_desc_from_frame().

Here is the call graph for this function:

◆ display_panogl_init()

static void * display_panogl_init ( struct module * parent,
const char * fmt,
unsigned int flags )
static

Definition at line 93 of file pano_gl.cpp.

93 {
95 UNUSED(fmt);
97 state_vr *s = new state_vr();
98 s->sdl_frame_event = SDL_RegisterEvents(1);
99 s->sdl_redraw_event = SDL_RegisterEvents(1);
100
101 return s;
102}
#define UNUSED(x)
const char * fmt
const char unsigned int flags
const char * parent
Definition settings.cpp:198
unsigned sdl_frame_event
Definition pano_gl.cpp:73
unsigned sdl_redraw_event
Definition pano_gl.cpp:74

References flags, fmt, parent, state_vr::sdl_frame_event, state_vr::sdl_redraw_event, and UNUSED.

◆ display_panogl_probe()

static void display_panogl_probe ( struct device_info ** available_cards,
int * count,
void(** deleter )(void *) )
static

Definition at line 360 of file pano_gl.cpp.

360 {
362 *count = 1;
363 *available_cards = (struct device_info *) calloc(1, sizeof(struct device_info));
364 strcpy((*available_cards)[0].dev, "");
365 strcpy((*available_cards)[0].name, "Panorama Gl SW display");
366 (*available_cards)[0].repeatable = true;
367}
int void(** deleter)(void *))
int count
Definition hd-rum.c:44
const char * name
Definition settings.cpp:193
char dev[1024]
Definition types.h:383

References count, deleter, device_info::dev, name, and UNUSED.

◆ display_panogl_putf()

static bool display_panogl_putf ( void * state,
struct video_frame * frame,
long long nonblock )
static

Definition at line 282 of file pano_gl.cpp.

282 {
284 struct state_vr *s = static_cast<state_vr *>(state);
285
286 if (nonblock == PUTF_DISCARD) {
287 vf_free(frame);
288 return true;
289 }
290
291 std::unique_lock<std::mutex> lk(s->lock);
293 && frame != NULL) {
294 vf_free(frame);
295 printf("1 frame(s) dropped!\n");
296 return false;
297 }
298 s->frame_consumed_cv.wait(lk, [s]{return s->buffered_frames_count < MAX_BUFFER_SIZE;});
299 s->buffered_frames_count += 1;
300 lk.unlock();
301 SDL_Event event;
302 event.type = s->sdl_frame_event;
303 event.user.data1 = frame;
304 PROFILE_DETAIL("push frame event");
305 SDL_PushEvent(&event);
306
307 return true;
308}
struct video_frame long long nonblock
struct video_frame * frame
#define PUTF_DISCARD
#define PUTF_BLOCKING
#define MAX_BUFFER_SIZE
Definition pano_gl.cpp:64
#define PROFILE_FUNC
#define PROFILE_DETAIL(name)
int buffered_frames_count
Definition pano_gl.cpp:77
std::condition_variable frame_consumed_cv
Definition pano_gl.cpp:89

References state_vr::buffered_frames_count, frame, state_vr::frame_consumed_cv, state_vr::lock, MAX_BUFFER_SIZE, nonblock, PROFILE_DETAIL, PROFILE_FUNC, PUTF_BLOCKING, PUTF_DISCARD, state_vr::sdl_frame_event, state, and vf_free().

Here is the call graph for this function:

◆ display_panogl_reconfigure()

static bool display_panogl_reconfigure ( void * state,
struct video_desc desc )
static

Definition at line 310 of file pano_gl.cpp.

310 {
311 state_vr *s = static_cast<state_vr *>(state);
312
313 s->current_desc = desc;
314 return true;
315}
struct video_desc desc

References state_vr::current_desc, desc, and state.

◆ display_panogl_run()

static void display_panogl_run ( void * state)
static

Definition at line 216 of file pano_gl.cpp.

216 {
217 state_vr *s = static_cast<state_vr *>(state);
218
219 draw(s);
220
221 s->running = true;
222 while(s->running){
223 SDL_Event event;
224 if (!SDL_WaitEvent(&event)) {
225 continue;
226 }
227
228 switch(event.type){
229 case SDL_MOUSEMOTION:
230 if(event.motion.state & SDL_BUTTON_LMASK){
231 s->scene.rotate(event.motion.xrel / 8.f,
232 event.motion.yrel / 8.f);
233
234 redraw(s);
235 }
236 break;
237 case SDL_MOUSEWHEEL:
238 s->scene.fov -= event.wheel.y;
239 redraw(s);
240 break;
241 case SDL_WINDOWEVENT:
242 handle_window_event(s, &event);
243 break;
244 case SDL_KEYDOWN:
245 handle_keyboard_event(s, &event);
246 break;
247 case SDL_QUIT:
248 exit_uv(0);
249 break;
250 default:
251 if(event.type >= SDL_USEREVENT)
252 handle_user_event(s, &event);
253 break;
254 }
255 }
256}
void exit_uv(int status)
Definition host.cpp:625
static void handle_keyboard_event(state_vr *s, SDL_Event *event)
Definition pano_gl.cpp:166
static void handle_window_event(state_vr *s, SDL_Event *event)
Definition pano_gl.cpp:157
static void redraw(state_vr *s, bool video_framerate_over_threshold=false, bool triggered_by_frame=false)
Definition pano_gl.cpp:124
static void draw(state_vr *s)
Definition pano_gl.cpp:104
static void handle_user_event(state_vr *s, SDL_Event *event)
Definition pano_gl.cpp:183
void rotate(float dx, float dy)
bool running
Definition pano_gl.cpp:70

References draw(), exit_uv(), PanoramaScene::fov, handle_keyboard_event(), handle_user_event(), handle_window_event(), redraw(), PanoramaScene::rotate(), state_vr::running, state_vr::scene, and state.

Here is the call graph for this function:

◆ draw()

static void draw ( state_vr * s)
static

Definition at line 104 of file pano_gl.cpp.

104 {
106 auto now = std::chrono::steady_clock::now();
107 s->last_frame = now;
108
109 glClear(GL_COLOR_BUFFER_BIT);
111
112 SDL_GL_SwapWindow(s->window.sdl_window);
113}
void render(int width, int height)
SDL_Window * sdl_window
std::chrono::steady_clock::time_point last_frame
Definition pano_gl.cpp:86
Sdl_window window
Definition pano_gl.cpp:68

References Sdl_window::height, state_vr::last_frame, PROFILE_FUNC, PanoramaScene::render(), state_vr::scene, Sdl_window::sdl_window, Sdl_window::width, and state_vr::window.

Referenced by display_panogl_run(), handle_user_event(), and redraw().

Here is the call graph for this function:

◆ handle_keyboard_event()

static void handle_keyboard_event ( state_vr * s,
SDL_Event * event )
static

Definition at line 166 of file pano_gl.cpp.

166 {
167 if(event->key.type == SDL_KEYDOWN){
168 switch(event->key.keysym.sym){
169 case SDLK_f:
170 s->fs = !s->fs;
171 SDL_SetWindowFullscreen(s->window.sdl_window, s->fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
172 redraw(s);
173 break;
174 case SDLK_q:
175 exit_uv(0);
176 break;
177 default:
178 break;
179 }
180 }
181}
bool fs
Definition pano_gl.cpp:71

References exit_uv(), state_vr::fs, redraw(), Sdl_window::sdl_window, and state_vr::window.

Referenced by display_panogl_run().

Here is the call graph for this function:

◆ handle_user_event()

static void handle_user_event ( state_vr * s,
SDL_Event * event )
static

Definition at line 183 of file pano_gl.cpp.

183 {
184 if(event->type == s->sdl_frame_event){
185 std::unique_lock<std::mutex> lk(s->lock);
186 s->buffered_frames_count -= 1;
187 lk.unlock();
188 s->frame_consumed_cv.notify_one();
189
190 video_frame *frame = static_cast<video_frame *>(event->user.data1);
191
192 if(frame){
194
195 lk.lock();
197 s->free_frame_queue.push(frame);
198 lk.unlock();
199 } else {
200 //poison
201 s->running = false;
202 return;
203 }
204 redraw(s, frame->fps >= s->threshold_fps, true);
205 } else if(event->type == s->sdl_redraw_event){
206 if(s->redraw_needed){
207 draw(s);
208 s->redraw_needed = false;
209 } else {
210 SDL_RemoveTimer(s->redraw_timer);
211 s->redraw_timer = 0;
212 }
213 }
214}
void put_frame(video_frame *f, bool pbo_frame=false)
bool redraw_needed
Definition pano_gl.cpp:84
SDL_TimerID redraw_timer
Definition pano_gl.cpp:83
int threshold_fps
Definition pano_gl.cpp:81
double fps
Definition types.h:308
void vf_recycle(struct video_frame *buf)
This function should be called before returning a frame back to a frame pool. Currently this is used ...

References state_vr::buffered_frames_count, draw(), video_frame::fps, frame, state_vr::frame_consumed_cv, state_vr::free_frame_queue, state_vr::lock, PanoramaScene::put_frame(), redraw(), state_vr::redraw_needed, state_vr::redraw_timer, state_vr::running, state_vr::scene, state_vr::sdl_frame_event, state_vr::sdl_redraw_event, state_vr::threshold_fps, and vf_recycle().

Referenced by display_panogl_run().

Here is the call graph for this function:

◆ handle_window_event()

static void handle_window_event ( state_vr * s,
SDL_Event * event )
static

Definition at line 157 of file pano_gl.cpp.

157 {
158 if(event->window.event == SDL_WINDOWEVENT_RESIZED){
159 glViewport(0, 0, event->window.data1, event->window.data2);
160 s->window.width = event->window.data1;
161 s->window.height = event->window.data2;
162 redraw(s);
163 }
164}

References Sdl_window::height, redraw(), Sdl_window::width, and state_vr::window.

Referenced by display_panogl_run().

Here is the call graph for this function:

◆ redraw()

static void redraw ( state_vr * s,
bool video_framerate_over_threshold = false,
bool triggered_by_frame = false )
static

Definition at line 124 of file pano_gl.cpp.

127{
128 if(video_framerate_over_threshold && triggered_by_frame){
129 /* If video framerate is over the threshold we draw the
130 * incoming frames immediately. Since this draw already
131 * contains changes caused by interaction (e.g. moving the
132 * camera) we cancel the redraw timer
133 */
134 if(s->redraw_timer){
135 SDL_RemoveTimer(s->redraw_timer);
136 s->redraw_timer = 0;
137 s->redraw_needed = false;
138 }
139 draw(s);
140 } else {
141 if(!s->redraw_timer){
142 /* Redrawing due to interaction is delayed, so that if
143 * a fresh video frame arrives very soon after the
144 * interaction it can be drawn together with the
145 * changes caused by interaction
146 */
147 s->redraw_timer = SDL_AddTimer(1000 / s->threshold_fps,
149
150 if(triggered_by_frame)
151 draw(s);
152 }
153 s->redraw_needed = !triggered_by_frame;
154 }
155}
static Uint32 redraw_callback(Uint32 interval, void *param)
Definition pano_gl.cpp:115

References draw(), redraw_callback(), state_vr::redraw_needed, state_vr::redraw_timer, state_vr::sdl_redraw_event, and state_vr::threshold_fps.

Referenced by display_panogl_run(), handle_keyboard_event(), handle_user_event(), and handle_window_event().

Here is the call graph for this function:

◆ redraw_callback()

static Uint32 redraw_callback ( Uint32 interval,
void * param )
static

Definition at line 115 of file pano_gl.cpp.

115 {
116 int event_id = *static_cast<int *>(param);
117 SDL_Event event;
118 event.type = event_id;
119 SDL_PushEvent(&event);
120
121 return interval;
122}
const char * param
Definition settings.cpp:195

References param.

Referenced by redraw().

◆ REGISTER_MODULE()

REGISTER_MODULE ( pano_gl ,
& display_panogl_info,
LIBRARY_CLASS_VIDEO_DISPLAY ,
VIDEO_DISPLAY_ABI_VERSION  )

Variable Documentation

◆ display_panogl_info

const struct video_display_info display_panogl_info
static
Initial value:
= {
NULL,
NULL,
}
static void display_panogl_run(void *state)
Definition pano_gl.cpp:216
static void display_panogl_done(void *state)
Definition pano_gl.cpp:258
static bool display_panogl_reconfigure(void *state, struct video_desc desc)
Definition pano_gl.cpp:310
static bool display_panogl_putf(void *state, struct video_frame *frame, long long nonblock)
Definition pano_gl.cpp:282
static bool display_panogl_get_property(void *state, int property, void *val, size_t *len)
Definition pano_gl.cpp:317
#define MOD_NAME
Definition pano_gl.cpp:65
static struct video_frame * display_panogl_getf(void *state)
Definition pano_gl.cpp:264
static void * display_panogl_init(struct module *parent, const char *fmt, unsigned int flags)
Definition pano_gl.cpp:93
static void display_panogl_probe(struct device_info **available_cards, int *count, void(**deleter)(void *))
Definition pano_gl.cpp:360

Definition at line 369 of file pano_gl.cpp.