UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dump.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2016-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
41#include "config.h"
42#include "config_unix.h"
43#include "config_win32.h"
44
45#include <stdint.h>
46
47#include "compat/time.h"
48#include "debug.h"
49#include "export.h"
50#include "host.h"
51#include "lib_common.h"
52#include "utils/color_out.h"
53#include "utils/macros.h"
54#include "video.h"
55#include "video_display.h"
56
57#define MOD_NAME "[dump] "
58
66
67static void usage()
68{
69 color_printf("Usage:\n");
70 color_printf(TERM_BOLD TERM_FG_RED "\t-d dump" TERM_FG_RESET "[:<directory>] [--param decoder-use-codec=<c>]\n" TERM_RESET);
71 color_printf("where\n");
72 color_printf(TERM_BOLD "\t<directory>" TERM_RESET " - directory to save the dumped stream\n");
73 color_printf(TERM_BOLD "\t<c>" TERM_RESET " - codec to use instead of the received (default), must be a way to convert\n");
74}
75
76static void *display_dump_init(struct module *parent, const char *cfg, unsigned int flags)
77{
78 (void) parent, (void) flags;
79 if (strcmp(cfg, "help") == 0) {
80 usage();
81 return INIT_NOERR;
82 }
83 struct dump_display_state *s = calloc(1, sizeof *s);
84 char dirname[128];
85 if (strlen(cfg) == 0) {
86 time_t t = time(NULL);
87 struct tm tm_buf = { 0 };
88 localtime_s(&t, &tm_buf);
89 strftime(dirname, sizeof dirname, "dump.%Y%m%dT%H%M%S",
90 &tm_buf);
91 cfg = dirname;
92 }
93 s->e = export_init(NULL, cfg, true);
94 if (s->e == NULL) {
95 log_msg(LOG_LEVEL_ERROR, "[dump] Failed to create export instance!\n");
96 free(s);
97 return NULL;
98 }
99 return s;
100}
101
102static void display_dump_done(void *state)
103{
104 struct dump_display_state *s = state;
105
106 vf_free(s->f);
107 export_destroy(s->e);
108 free(s);
109}
110
112{
113 struct dump_display_state *s = state;
114 for (unsigned int i = 0; i < s->f->tile_count; ++i) {
115 if (is_codec_opaque(s->f->color_spec)) {
116 s->f->tiles[i].data_len = s->max_tile_data_len;
117 }
118 }
119 return s->f;
120}
121
122static bool display_dump_putf(void *state, struct video_frame *frame, long long flags)
123{
124 struct dump_display_state *s = state;
125 if (frame == NULL || flags == PUTF_DISCARD) {
126 return true;
127 }
128 assert(frame == s->f);
129 export_video(s->e, frame);
130
131 return true;
132}
133
134static bool display_dump_get_property(void *state, int property, void *val, size_t *len)
135{
136 (void) state;
138
139 for (int i = 0; i < VIDEO_CODEC_COUNT - 1; ++i) {
140 codecs[i] = (codec_t) (i + 1); // all codecs (exclude VIDEO_CODEC_NONE)
141 }
142
143 switch (property) {
145 if (sizeof(codecs) <= *len) {
146 memcpy(val, codecs, sizeof(codecs));
147 *len = sizeof(codecs);
148 } else {
149 return FALSE;
150 }
151 break;
154 *len = sizeof(int);
155 break;
156 default:
157 return false;
158 }
159 return true;
160}
161
163{
164 struct dump_display_state *s = state;
165 vf_free(s->f);
166 s->f = vf_alloc_desc(desc);
168 s->max_tile_data_len = MAX(8 * desc.width * desc.height, 1000000UL);
169 for (unsigned int i = 0; i < s->f->tile_count; ++i) {
171 s->f->tiles[i].data_len = s->max_tile_data_len;
172 }
173 s->f->tiles[i].data = (char *) malloc(s->f->tiles[i].data_len);
174 }
176
177 return true;
178}
179
180static void display_dump_probe(struct device_info **available_cards, int *count, void (**deleter)(void *)) {
182 *available_cards = NULL;
183 *count = 0;
184}
185
189 NULL, // _run
195 NULL, // _put_audio_frame
196 NULL, // _reconfigure_audio,
197 MOD_NAME,
198};
199
201
#define UNUSED(x)
void ** state
int void * val
struct video_desc desc
struct video_frame * frame
int void size_t * len
const char unsigned int flags
int void(** deleter)(void *))
int property
void vf_free(struct video_frame *buf)
Frees video_frame structure.
void vf_data_deleter(struct video_frame *buf)
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
int color_printf(const char *format,...)
#define TERM_BOLD
Definition color_out.h:48
#define TERM_FG_RED
Definition color_out.h:50
#define TERM_RESET
Definition color_out.h:47
#define TERM_FG_RESET
Definition color_out.h:59
#define localtime_s
Definition time.h:51
#define TRUE
#define FALSE
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
static void display_dump_probe(struct device_info **available_cards, int *count, void(**deleter)(void *))
Definition dump.c:180
static void display_dump_done(void *state)
Definition dump.c:102
static void usage()
Definition dump.c:67
static bool display_dump_reconfigure(void *state, struct video_desc desc)
Definition dump.c:162
static bool display_dump_get_property(void *state, int property, void *val, size_t *len)
Definition dump.c:134
static void * display_dump_init(struct module *parent, const char *cfg, unsigned int flags)
Definition dump.c:76
static struct video_frame * display_dump_getf(void *state)
Definition dump.c:111
#define MOD_NAME
Definition dump.c:57
static bool display_dump_putf(void *state, struct video_frame *frame, long long flags)
Definition dump.c:122
static const struct video_display_info display_dump_info
Definition dump.c:186
void export_video(struct exporter *s, struct video_frame *frame)
Definition export.c:356
void export_destroy(struct exporter *s)
Definition export.c:308
struct exporter * export_init(struct module *parent, const char *cfg, bool should_export)
Definition export.c:149
#define PUTF_DISCARD
#define VIDEO_DISPLAY_ABI_VERSION
@ DISPLAY_PROPERTY_VIDEO_MODE
requested video mode - int (one of display_prop_vid_mode)
@ DISPLAY_PROPERTY_CODECS
list of natively supported codecs - codec_t[]
@ DISPLAY_PROPERTY_VIDEO_SEPARATE_TILES
framebuffer consists of separate tiles
int count
Definition hd-rum.c:44
#define INIT_NOERR
Definition host.h:73
@ LIBRARY_CLASS_VIDEO_DISPLAY
Definition lib_common.h:79
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
#define MAX(a, b)
Definition macros.h:65
const char * parent
Definition settings.cpp:198
codec_t requested_codec
Definition dump.c:64
struct exporter * e
Definition dump.c:62
size_t max_tile_data_len
Definition dump.c:63
struct video_frame * f
Definition dump.c:60
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
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
void(* data_deleter)(struct video_frame *)
Definition types.h:256
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
unsigned int decoder_overrides_data_len
Definition types.h:322
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
unsigned int tile_count
Definition types.h:344
struct video_frame_callbacks callbacks
Definition types.h:324
codec_t color_spec
Definition types.h:306
codec_t
Definition types.h:65
@ VIDEO_CODEC_COUNT
count of known video codecs (including VIDEO_CODEC_NONE)
Definition types.h:108
This is an umbrella header for video functions.
bool is_codec_opaque(codec_t codec)
static struct @76 codecs[]