6767#define DEFAULT_SCALE_W 960
6868#define DEFAULT_SCALE_H 540
6969
70- using ipc_frame_conv_func_t = bool (*)(struct Ipc_frame *dst,
71- const struct video_frame *src,
70+ using ipc_frame_conv_func_t = bool (*)(Ipc_frame *dst,
71+ const video_frame *src,
7272 codec_t codec,
7373 unsigned scale_factor);
7474
7575static constexpr unsigned int IN_QUEUE_MAX_BUFFER_LEN = 5 ;
7676static constexpr int SKIP_FIRST_N_FRAMES_IN_STREAM = 5 ;
7777
78- static void display_unix_sock_run (void *state);
79-
8078namespace {
81- struct frame_deleter { void operator ()(video_frame *f){ vf_free (f); } };
82- using unique_frame = std::unique_ptr<video_frame, frame_deleter>;
83- }
79+ using unique_frame = std::unique_ptr<video_frame, deleter_from_fcn<vf_free>>;
8480
85- struct state_unix_sock {
81+ struct state_unix_sock {
8682 std::queue<unique_frame> incoming_queue;
8783 std::condition_variable frame_consumed_cv;
8884 std::condition_variable frame_available_cv;
8985 std::mutex lock;
9086
9187 video_desc desc = {};
92- video_desc display_desc = {};
9388
9489 Ipc_frame_uniq ipc_frame;
9590 Ipc_frame_writer_uniq frame_writer;
@@ -105,7 +100,7 @@ struct state_unix_sock {
105100 std::thread worker_thread;
106101};
107102
108- static void show_help (){
103+ void show_help (){
109104 col () << " unix_socket/preview display. The two display are identical apart from their defaults and the fact that preview never blocks on putf().\n " ;
110105 col () << " usage:\n " ;
111106 col () << TBOLD (TRED (" \t -d (unix_socket|preview)" ) << " [:path=<path>][:target_size=<w>x<h>]" )
@@ -119,7 +114,9 @@ static void show_help(){
119114 col () << TBOLD (" \t hq" ) << " \t Use higher quality downscale\n " ;
120115}
121116
122- static void *display_unix_sock_init (struct module *parent,
117+ void display_unix_sock_run (void *state);
118+
119+ void *display_unix_sock_init (module *parent,
123120 const char *fmt,
124121 unsigned int flags,
125122 bool is_preview)
@@ -128,7 +125,6 @@ static void *display_unix_sock_init(struct module *parent,
128125 UNUSED (fmt);
129126
130127 auto s = std::make_unique<state_unix_sock>();
131-
132128 std::string_view fmt_sv = fmt ? fmt : " " ;
133129
134130 std::string socket_path = get_temp_dir ();
@@ -158,7 +154,7 @@ static void *display_unix_sock_init(struct module *parent,
158154 } else if (key == " target_size" ){
159155 auto val = tokenize (tok, ' =' );
160156 if (!parse_num (tokenize (val, ' x' ), s->target_width )
161- || !parse_num (tokenize (val, ' x' ), s->target_height ))
157+ || !parse_num (tokenize (val, ' x' ), s->target_height ))
162158 {
163159 log_msg (LOG_LEVEL_ERROR, MOD_NAME " Failed to parse resolution\n " );
164160 return nullptr ;
@@ -178,38 +174,34 @@ static void *display_unix_sock_init(struct module *parent,
178174 return s.release ();
179175}
180176
181- static void display_unix_sock_run (void *state)
182- {
177+ void display_unix_sock_run (void *state){
183178 auto s = static_cast <state_unix_sock *>(state);
184179 int skipped = 0 ;
185180
186- while (true ) {
187- auto frame = [&]{
188- std::unique_lock<std::mutex> l (s->lock );
189- s->frame_available_cv .wait (l,
190- [s]{return !s->incoming_queue .empty ();});
191- auto frame = std::move (s->incoming_queue .front ());
192- s->incoming_queue .pop ();
193- s->frame_consumed_cv .notify_one ();
194- return frame;
195- }();
196-
197- if (!frame) {
181+ while (true ){
182+ std::unique_lock<std::mutex> l (s->lock );
183+ s->frame_available_cv .wait (l, [s]{ return !s->incoming_queue .empty (); });
184+ auto frame = std::move (s->incoming_queue .front ());
185+ s->incoming_queue .pop ();
186+ l.unlock ();
187+ s->frame_consumed_cv .notify_one ();
188+
189+ if (!frame){
198190 break ;
199191 }
200192
201- if (skipped < SKIP_FIRST_N_FRAMES_IN_STREAM){
193+ if (skipped < SKIP_FIRST_N_FRAMES_IN_STREAM){
202194 skipped++;
203195 continue ;
204196 }
205197
206198 const tile *tile = &frame->tiles [0 ];
207199
208200 int scale = ipc_frame_get_scale_factor (tile->width , tile->height ,
209- s->target_width , s->target_height );
201+ s->target_width , s->target_height );
210202
211203 if (!s->ipc_conv (s->ipc_frame .get (), frame.get (),
212- RGB, scale))
204+ RGB, scale))
213205 {
214206 log_msg (LOG_LEVEL_WARNING, MOD_NAME " Unable to convert\n " );
215207 continue ;
@@ -223,8 +215,7 @@ static void display_unix_sock_run(void *state)
223215 }
224216}
225217
226- static void display_unix_sock_done (void *state)
227- {
218+ void display_unix_sock_done (void *state){
228219 auto s = static_cast <state_unix_sock *>(state);
229220
230221 if (s->worker_thread .joinable ()){
@@ -234,23 +225,21 @@ static void display_unix_sock_done(void *state)
234225 delete s;
235226}
236227
237- static struct video_frame *display_unix_sock_getf (void *state)
238- {
228+ video_frame *display_unix_sock_getf (void *state){
239229 auto s = static_cast <state_unix_sock *>(state);
240230
241231 return vf_alloc_desc_data (s->desc );
242232}
243233
244- static bool display_unix_sock_putf (void *state, struct video_frame *frame, long long flags)
245- {
234+ bool display_unix_sock_putf (void *state, video_frame *frame, long long flags){
246235 auto s = static_cast <state_unix_sock *>(state);
247236 auto f = unique_frame (frame);
248237
249- if (flags == PUTF_DISCARD)
238+ if (flags == PUTF_DISCARD)
250239 return true ;
251240
252241 std::unique_lock<std::mutex> lg (s->lock );
253- if (s->incoming_queue .size () >= IN_QUEUE_MAX_BUFFER_LEN){
242+ if (s->incoming_queue .size () >= IN_QUEUE_MAX_BUFFER_LEN){
254243 if (flags != PUTF_BLOCKING){
255244 log_msg (LOG_LEVEL_WARNING, MOD_NAME " queue full!\n " );
256245 return false ;
@@ -260,78 +249,77 @@ static bool display_unix_sock_putf(void *state, struct video_frame *frame, long
260249 }
261250 }
262251
263- s->frame_consumed_cv .wait (lg, [s]{return s->incoming_queue .size () < IN_QUEUE_MAX_BUFFER_LEN;});
252+ s->frame_consumed_cv .wait (lg, [s]{ return s->incoming_queue .size () < IN_QUEUE_MAX_BUFFER_LEN; });
264253 s->incoming_queue .push (std::move (f));
265254 lg.unlock ();
266255 s->frame_available_cv .notify_one ();
267256
268257 return true ;
269258}
270259
271- static bool display_unix_sock_get_property (void *state, int property, void *val, size_t *len)
272- {
260+ bool display_unix_sock_get_property (void *state, int property, void *val, size_t *len){
273261 UNUSED (state);
274262 codec_t codecs[] = {UYVY, RGBA, RGB};
275- enum interlacing_t supported_il_modes[] = {PROGRESSIVE, INTERLACED_MERGED, SEGMENTED_FRAME};
263+ interlacing_t supported_il_modes[] = {PROGRESSIVE, INTERLACED_MERGED, SEGMENTED_FRAME};
276264 int rgb_shift[] = {0 , 8 , 16 };
277265
278- switch (property) {
279- case DISPLAY_PROPERTY_CODECS:
280- if (sizeof (codecs) <= *len) {
281- memcpy (val, codecs, sizeof (codecs));
282- } else {
283- return false ;
284- }
266+ switch (property){
267+ case DISPLAY_PROPERTY_CODECS:
268+ if (sizeof (codecs) <= *len){
269+ memcpy (val, codecs, sizeof (codecs));
270+ } else {
271+ return false ;
272+ }
285273
286- *len = sizeof (codecs);
287- break ;
288- case DISPLAY_PROPERTY_RGB_SHIFT:
289- if (sizeof (rgb_shift) > *len) {
290- return false ;
291- }
292- memcpy (val, rgb_shift, sizeof (rgb_shift));
293- *len = sizeof (rgb_shift);
294- break ;
295- case DISPLAY_PROPERTY_BUF_PITCH:
296- *(int *) val = PITCH_DEFAULT;
297- *len = sizeof (int );
298- break ;
299- case DISPLAY_PROPERTY_SUPPORTED_IL_MODES:
300- if (sizeof (supported_il_modes) <= *len) {
301- memcpy (val, supported_il_modes, sizeof (supported_il_modes));
302- } else {
303- return false ;
304- }
305- *len = sizeof (supported_il_modes);
306- break ;
307- default :
274+ *len = sizeof (codecs);
275+ break ;
276+ case DISPLAY_PROPERTY_RGB_SHIFT:
277+ if (sizeof (rgb_shift) > *len){
278+ return false ;
279+ }
280+ memcpy (val, rgb_shift, sizeof (rgb_shift));
281+ *len = sizeof (rgb_shift);
282+ break ;
283+ case DISPLAY_PROPERTY_BUF_PITCH:
284+ *static_cast <int *>(val) = PITCH_DEFAULT;
285+ *len = sizeof (int );
286+ break ;
287+ case DISPLAY_PROPERTY_SUPPORTED_IL_MODES:
288+ if (sizeof (supported_il_modes) <= *len){
289+ memcpy (val, supported_il_modes, sizeof (supported_il_modes));
290+ } else {
308291 return false ;
292+ }
293+ *len = sizeof (supported_il_modes);
294+ break ;
295+ default :
296+ return false ;
309297 }
310298 return true ;
311299}
312300
313- static bool display_unix_sock_reconfigure (void *state, struct video_desc desc)
314- {
301+ bool display_unix_sock_reconfigure (void *state, video_desc desc){
315302 auto s = static_cast <state_unix_sock *>(state);
316303
317304 s->desc = desc;
318305
319306 return true ;
320307}
321308
322- static void display_unix_sock_probe (struct device_info **available_cards, int *count, void (**deleter)(void *)) {
309+ void display_unix_sock_probe (device_info **available_cards, int *count, void (**deleter)(void *)){
323310 UNUSED (deleter);
324311 *available_cards = nullptr ;
325312 *count = 0 ;
326313}
327314
328- static void *display_unix_sock_init_preview (struct module *parent, const char *fmt, unsigned int flags) {
315+ void *display_unix_sock_init_preview (module *parent, const char *fmt, unsigned int flags){
329316 return display_unix_sock_init (parent, fmt, flags, true );
330317}
331318
332- static void *display_unix_sock_init_no_preview (struct module *parent, const char *fmt, unsigned int flags) {
319+ void *display_unix_sock_init_no_preview (module *parent, const char *fmt, unsigned int flags){
333320 return display_unix_sock_init (parent, fmt, flags, false );
334321}
322+ } // anon namespace
335323
336324constexpr video_display_info display_unix_sock_info = {
337325 display_unix_sock_probe,
0 commit comments