44#include <condition_variable>
68#define MOD_NAME "[unix sock disp] "
70#define DEFAULT_PREVIEW_FILENAME "ug_preview_disp_unix"
71#define DEFAULT_DISP_FILENAME "ug_unix"
73#define DEFAULT_SCALE_W 960
74#define DEFAULT_SCALE_H 540
79 unsigned scale_factor);
88using unique_frame = std::unique_ptr<video_frame, frame_deleter>;
115 col() <<
"unix_socket/preview display. The two display are identical apart from their defaults and the fact that preview never blocks on putf().\n";
117 col() <<
TBOLD(
TRED(
"\t-d (unix_socket|preview)") <<
"[:path=<path>][:target_size=<w>x<h>]")
119 col() <<
"options:\n";
120 col() <<
TBOLD(
"\tpath=<path>") <<
"\tpath to unix socket to connect to. Defaults are \""
123 col() <<
TBOLD(
"\ttarget_size=<w>x<h>")<<
"\tScales the video frame so that the total number of pixel is around <w>x<h>. If -1x-1 is passed, no scaling takes place."
125 col() <<
TBOLD(
"\thq") <<
"\tUse higher quality downscale\n";
136 auto s = std::make_unique<state_unix_sock>();
138 std::string_view fmt_sv =
fmt ?
fmt :
"";
148 s->ignore_putf_blocking =
true;
151 while(!fmt_sv.empty()){
152 auto tok =
tokenize(fmt_sv,
':',
'"');
158 }
else if(
key ==
"path"){
160 }
else if(
key ==
"key"){
162 }
else if(
key ==
"hq"){
164 }
else if(
key ==
"target_size"){
178 if(!s->frame_writer){
194 std::unique_lock<std::mutex> l(s->lock);
195 s->frame_available_cv.wait(l,
196 [s]{
return s->incoming_queue.size() > 0;});
197 auto frame = std::move(s->incoming_queue.front());
198 s->incoming_queue.pop();
199 s->frame_consumed_cv.notify_one();
215 s->target_width, s->target_height);
217 if(!s->ipc_conv(s->ipc_frame.get(),
frame.get(),
226 perror(
MOD_NAME "Unable to send frame");
255 std::unique_lock<std::mutex> lg(s->lock);
261 if(s->ignore_putf_blocking){
267 s->incoming_queue.push(std::move(f));
269 s->frame_available_cv.notify_one();
279 int rgb_shift[] = {0, 8, 16};
292 if(
sizeof(rgb_shift) > *
len) {
295 memcpy(
val, rgb_shift,
sizeof(rgb_shift));
296 *
len =
sizeof(rgb_shift);
303 if(
sizeof(supported_il_modes) <= *
len) {
304 memcpy(
val, supported_il_modes,
sizeof(supported_il_modes));
308 *
len =
sizeof(supported_il_modes);
344 *available_cards =
nullptr;
381 "[unix sock preview] ",
struct video_frame * frame
const char unsigned int flags
int void(** deleter)(void *))
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_ERROR
general errors
#define LOG_LEVEL_WARNING
less severe errors
#define PITCH_DEFAULT
default pitch, i. e. respective linesize
#define VIDEO_DISPLAY_ABI_VERSION
@ 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[]
Ipc_frame * ipc_frame_new()
std::unique_ptr< Ipc_frame, Ipc_frame_deleter > Ipc_frame_uniq
bool ipc_frame_from_ug_frame_hq(struct Ipc_frame *dst, const struct video_frame *src, codec_t codec, unsigned scale_factor)
Same as ipc_frame_from_ug_frame, but convert pixfmt first and scale later.
bool ipc_frame_from_ug_frame(struct Ipc_frame *dst, const struct video_frame *src, codec_t codec, unsigned scale_factor)
Make an ipc frame from ultragrid frame.
int ipc_frame_get_scale_factor(int src_w, int src_h, int target_w, int target_h)
bool ipc_frame_writer_write(struct Ipc_frame_writer *writer, const struct Ipc_frame *f)
Ipc_frame_writer * ipc_frame_writer_new(const char *path)
std::unique_ptr< Ipc_frame_writer, Ipc_frame_writer_deleter > Ipc_frame_writer_uniq
@ LIBRARY_CLASS_VIDEO_DISPLAY
#define REGISTER_HIDDEN_MODULE(name, info, lclass, abi)
bool(*)(struct Ipc_frame *dst, const struct video_frame *src, codec_t codec, unsigned scale_factor) ipc_frame_conv_func_t
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.
bool parse_num(std::string_view sv, T &res, int base=10)
struct used to comunicate with audio capture/playback device
void operator()(video_frame *f)
ipc_frame_conv_func_t ipc_conv
std::condition_variable frame_available_cv
Ipc_frame_writer_uniq frame_writer
struct video_desc display_desc
std::condition_variable frame_consumed_cv
bool ignore_putf_blocking
std::queue< unique_frame > incoming_queue
Struct tile is an area of video_frame.
Struct video_frame represents a video frame and contains video description.
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
@ PROGRESSIVE
progressive frame
@ SEGMENTED_FRAME
Segmented frame. Contains the same data as progressive frame.
@ INTERLACED_MERGED
Columngs of both fields are interlaced together.
@ RGB
RGB 8-bit (packed into 24-bit word)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
@ RGBA
RGBA 8-bit, big-endian.
static bool display_unix_sock_reconfigure_audio(void *state, int quant_samples, int channels, int sample_rate)
static void * display_unix_sock_init_preview(struct module *parent, const char *fmt, unsigned int flags)
static constexpr unsigned int IN_QUEUE_MAX_BUFFER_LEN
static void display_unix_sock_probe(struct device_info **available_cards, int *count, void(**deleter)(void *))
static void display_unix_sock_done(void *state)
static bool display_unix_sock_reconfigure(void *state, struct video_desc desc)
bool(*)(struct Ipc_frame *dst, const struct video_frame *src, codec_t codec, unsigned scale_factor) ipc_frame_conv_func_t
static const struct video_display_info display_preview_info
static constexpr int SKIP_FIRST_N_FRAMES_IN_STREAM
#define DEFAULT_PREVIEW_FILENAME
static void display_unix_sock_run(void *state)
static bool display_unix_sock_putf(void *state, struct video_frame *frame, long long flags)
static bool display_unix_sock_get_property(void *state, int property, void *val, size_t *len)
static struct video_frame * display_unix_sock_getf(void *state)
static void display_unix_sock_put_audio_frame(void *state, const struct audio_frame *frame)
static void * display_unix_sock_init_no_preview(struct module *parent, const char *fmt, unsigned int flags)
#define DEFAULT_DISP_FILENAME
static void * display_unix_sock_init(struct module *parent, const char *fmt, unsigned int flags, bool is_preview)
static const struct video_display_info display_unix_sock_info
This is an umbrella header for video functions.
std::unique_ptr< video_frame, frame_deleter > unique_frame