UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
delay.c File Reference
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "debug.h"
#include "lib_common.h"
#include "types.h"
#include "utils/color_out.h"
#include "utils/list.h"
#include "utils/macros.h"
#include "video_codec.h"
#include "video_display.h"
#include "video_frame.h"
#include "vo_postprocess.h"
Include dependency graph for delay.c:

Go to the source code of this file.

Classes

struct  state_delay
 

Macros

#define MOD_NAME   "[vpp/delay] "
 

Functions

static void delay_done (void *state)
 
static void delay_get_out_desc (void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
 
static bool delay_get_property (void *state, int property, void *val, size_t *len)
 
static struct video_frame * delay_getf (void *state)
 
static void * delay_init (const char *config)
 
static bool delay_postprocess (void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
 
static bool delay_reconfigure (void *state, struct video_desc desc)
 
 REGISTER_MODULE (delay, &vo_pp_delay_info, LIBRARY_CLASS_VIDEO_POSTPROCESS, VO_PP_ABI_VERSION)
 
static void usage ()
 

Variables

static const struct vo_postprocess_info vo_pp_delay_info
 

Detailed Description

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

Definition in file delay.c.

Macro Definition Documentation

◆ MOD_NAME

#define MOD_NAME   "[vpp/delay] "

Definition at line 54 of file delay.c.

Function Documentation

◆ delay_done()

static void delay_done ( void * state)
static

Definition at line 183 of file delay.c.

184{
185 struct state_delay *s = state;
186
187 struct video_frame *f = NULL;
188 while ((f = simple_linked_list_pop(s->cached_frames)) != NULL) {
189 vf_free(f);
190 }
192 free(s);
193}
void ** state
void vf_free(struct video_frame *buf)
Frees video_frame structure.
void simple_linked_list_destroy(struct simple_linked_list *l)
Definition list.cpp:58
void * simple_linked_list_pop(struct simple_linked_list *l)
Definition list.cpp:82
struct simple_linked_list * cached_frames
Definition delay.c:60
Struct video_frame represents a video frame and contains video description.
Definition types.h:305

References state_delay::cached_frames, simple_linked_list_destroy(), simple_linked_list_pop(), state, and vf_free().

Here is the call graph for this function:

◆ delay_get_out_desc()

static void delay_get_out_desc ( void * state,
struct video_desc * out,
int * in_display_mode,
int * out_frames )
static

Definition at line 196 of file delay.c.

198{
199 struct state_delay *s = state;
200
201 *out = s->desc;
202 *in_display_mode = DISPLAY_PROPERTY_VIDEO_MERGED;
203 *out_frames = 1;
204}
@ DISPLAY_PROPERTY_VIDEO_MERGED
monolithic framebuffer
struct video_desc desc
Definition delay.c:59

References state_delay::desc, DISPLAY_PROPERTY_VIDEO_MERGED, and state.

◆ delay_get_property()

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

Definition at line 64 of file delay.c.

65{
66 (void) state;
68 return false;
69 }
70 const size_t codecs_len = (VC_END - VC_FIRST) * sizeof(codec_t);
71 assert(codecs_len <= *len);
72 *len = codecs_len;
74 for (int i = VC_FIRST; i < VC_END; ++i) {
75 codecs[i] = i;
76 }
77 return true;
78}
int void * val
int void size_t * len
int property
codec_t
Definition types.h:65
@ VC_FIRST
Definition types.h:69
@ VC_END
Definition types.h:110
static struct @76 codecs[]
#define VO_PP_PROPERTY_CODECS

References codecs, len, property, state, val, VC_END, VC_FIRST, and VO_PP_PROPERTY_CODECS.

◆ delay_getf()

static struct video_frame * delay_getf ( void * state)
static

Definition at line 146 of file delay.c.

147{
148 struct state_delay *s = state;
149
150 return vf_alloc_desc_data(s->desc);
151}
struct video_frame * vf_alloc_desc_data(struct video_desc desc)

References state_delay::desc, state, and vf_alloc_desc_data().

Here is the call graph for this function:

◆ delay_init()

static void * delay_init ( const char * config)
static

Definition at line 92 of file delay.c.

93{
94 enum {
95 MAX_VAL_FRM = 2000,
96 MAX_VAL_SEC = 60,
97 };
98 if (!IS_KEY_PREFIX(config, "seconds") &&
99 !IS_KEY_PREFIX(config, "frames")) {
100 usage();
101 return NULL;
102 }
103
104 const char *val_s = strchr(config, '=') + 1;
105 double val = strtod(val_s, NULL);
106 if (val <= 0 || val > MAX_VAL_FRM ||
107 (IS_KEY_PREFIX(config, "seconds") && val > MAX_VAL_SEC)) {
108 MSG(ERROR, "Wrong delay value: %s\n", val_s);
109 return NULL;
110 }
111 if (IS_KEY_PREFIX(config, "frames") && fabs(round(val) - val) > 0.0) {
112 MSG(ERROR, "Number of frames should be an integer, given: %s\n",
113 val_s);
114 return NULL;
115 }
116
117 struct state_delay *s = calloc(1, sizeof(struct state_delay));
118 assert(s != NULL);
119 if (IS_KEY_PREFIX(config, "seconds")) {
120 s->delay_sec = val;
121 } else {
122 s->delay_frames = (int) val;
123 }
124 MSG(INFO, "Delay set to %g %s.\n", val,
125 s->delay_sec ? "seconds" : "frames");
127
128 return s;
129}
static __device__ vec3 round(const vec3 &v)
Definition cuda_dxt.cu:122
#define MSG(l, fmt,...)
Definition debug.h:96
static void usage()
Definition delay.c:81
struct simple_linked_list * simple_linked_list_init(void)
Definition list.cpp:53
#define IS_KEY_PREFIX(tok, key)
expands to true value if <k> from tok in format <k>=<v> is prefix of key
Definition macros.h:138
int delay_frames
Definition delay.c:58
double delay_sec
Definition delay.c:57

References state_delay::cached_frames, state_delay::delay_frames, state_delay::delay_sec, IS_KEY_PREFIX, MSG, round(), simple_linked_list_init(), usage(), and val.

Here is the call graph for this function:

◆ delay_postprocess()

static bool delay_postprocess ( void * state,
struct video_frame * in,
struct video_frame * out,
int req_pitch )
static

Definition at line 154 of file delay.c.

156{
157 struct state_delay *s = state;
158
160
161 const int list_size = simple_linked_list_size(s->cached_frames);
162 if (s->delay_frames >= 0 && list_size < s->delay_frames) {
163 return false;
164 }
165
166 if (list_size / s->desc.fps < s->delay_sec) {
167 return false;
168 }
169
171 const size_t linesize =
173 for (size_t i = 0; i < s->desc.height; ++i) {
174 memcpy(out->tiles[0].data + i * req_pitch,
175 f->tiles[0].data + i * linesize, linesize);
176 }
177 vf_free(f);
178
179 return true;
180}
int vc_get_linesize(unsigned int width, codec_t codec)
void simple_linked_list_append(struct simple_linked_list *l, void *data)
Definition list.cpp:68
int simple_linked_list_size(struct simple_linked_list *l)
Definition list.cpp:93
unsigned int width
Definition types.h:280
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
double fps
Definition types.h:183
unsigned int height
height of every tile (!)
Definition types.h:180
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
codec_t color_spec
Definition types.h:306

References state_delay::cached_frames, video_frame::color_spec, tile::data, state_delay::delay_frames, state_delay::delay_sec, state_delay::desc, video_desc::fps, video_desc::height, simple_linked_list_append(), simple_linked_list_pop(), simple_linked_list_size(), state, video_frame::tiles, vc_get_linesize(), vf_free(), and tile::width.

Here is the call graph for this function:

◆ delay_reconfigure()

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

Definition at line 132 of file delay.c.

133{
134 struct state_delay *s = (struct state_delay *) state;
135 s->desc = desc;
136
137 struct video_frame *f = NULL;
138 while ((f = simple_linked_list_pop(s->cached_frames)) != NULL) {
139 vf_free(f);
140 }
141
142 return true;
143}
struct video_desc desc

References state_delay::cached_frames, desc, state_delay::desc, simple_linked_list_pop(), state, and vf_free().

Here is the call graph for this function:

◆ REGISTER_MODULE()

REGISTER_MODULE ( delay ,
& vo_pp_delay_info,
LIBRARY_CLASS_VIDEO_POSTPROCESS ,
VO_PP_ABI_VERSION  )

◆ usage()

static void usage ( void )
static

Definition at line 81 of file delay.c.

82{
83 color_printf(TBOLD("delay") " postprocessor settings:\n");
85 TBOLD(TRED("\t-p delay:[seconds=<s>|frames=<f>]")) " | " TBOLD(
86 "-p delay:help") "\n");
87 color_printf("\nSeconds can be given as a decimal number.\n");
88 color_printf("\n");
89}
int color_printf(const char *format,...)
#define TRED(x)
Definition color_out.h:75
#define TBOLD(x)
Definition color_out.h:70

References color_printf(), TBOLD, and TRED.

Referenced by delay_init().

Here is the call graph for this function:

Variable Documentation

◆ vo_pp_delay_info

const struct vo_postprocess_info vo_pp_delay_info
static
Initial value:
= {
}
static void delay_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
Definition delay.c:196
static void delay_done(void *state)
Definition delay.c:183
static bool delay_get_property(void *state, int property, void *val, size_t *len)
Definition delay.c:64
static void * delay_init(const char *config)
Definition delay.c:92
static bool delay_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
Definition delay.c:154
static bool delay_reconfigure(void *state, struct video_desc desc)
Definition delay.c:132
static struct video_frame * delay_getf(void *state)
Definition delay.c:146

Definition at line 206 of file delay.c.