UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
src
playback.c
Go to the documentation of this file.
1
5
/*
6
* Copyright (c) 2019-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
*/
37
38
#ifdef HAVE_CONFIG_H
39
#include "config.h"
40
#include "
config_unix.h
"
41
#include "
config_win32.h
"
42
#endif
43
44
#include <sys/types.h>
45
#include <sys/stat.h>
46
#include <unistd.h>
47
48
#include "
debug.h
"
49
#include "
keyboard_control.h
"
50
#include "
playback.h
"
51
#include "
utils/color_out.h
"
52
#include "
utils/text.h
"
53
54
#define MOD_NAME "[playback] "
55
56
static
void
playback_usage
(
void
) {
57
char
desc
[] =
TBOLD
(
"playback"
)
" can capture data from locally "
58
"stored data, which can be either a regular video file, "
59
"or a directory with data recorded by UltraGrid itself "
60
"(--record option)."
;
61
color_printf
(
"%s\n\n"
,
wrap_paragraph
(
desc
));
62
color_printf
(
"Usage:\n"
);
63
color_printf
(
TBOLD
(
TRED
(
"\t--playback <file>|<dir>"
)
"[:loop]\n"
));
64
color_printf
(
TBOLD
(
TRED
(
"\t-I{<file>|<dir>}"
)
"[:loop]\n"
));
65
color_printf
(
TBOLD
(
"\t-Ihelp | --playback help"
)
"\n\n"
);
66
color_printf
(
"Use "
);
67
color_printf
(
TERM_BOLD
"-t file:help"
TERM_RESET
" or "
TERM_BOLD
"-t import:help"
TERM_RESET
" to see further specific configuration options.\n\n"
);
68
}
69
70
int
playback_set_device
(
char
*device_string,
size_t
buf_len,
const
char
*optarg) {
71
bool
is_import =
false
;
72
if
(strcmp(optarg,
"help"
) == 0) {
73
playback_usage
();
74
return
0;
75
}
76
char
*path = strdup(optarg);
77
if
(strchr(path,
':'
)) {
78
*strchr(path,
':'
) =
'\0'
;
79
}
80
81
struct
stat sb;
82
if
(stat(path, &sb) == -1) {
83
perror(
MOD_NAME
"stat"
);
84
log_msg
(
LOG_LEVEL_ERROR
,
MOD_NAME
"Cannot access file or directory '%s'\n"
, path);
85
log_msg
(
LOG_LEVEL_INFO
,
MOD_NAME
"Use '--playback help' to see usage.\n"
);
86
free(path);
87
return
-1;
88
}
89
90
if
(sb.st_mode & S_IFDIR || strstr(path,
"video.info"
) != NULL) {
91
is_import =
true
;
92
}
93
94
snprintf(device_string, buf_len,
"%s:%s:opportunistic_audio"
, is_import ?
"import"
:
"file"
, optarg);
95
free(path);
96
return
1;
97
}
98
102
void
playback_register_keyboard_ctl
(
struct
module
*mod) {
103
struct
{
int
key
;
const
char
*
msg
; } kb[] = {{
K_PGUP
,
"seek +600s"
}, {
K_PGDOWN
,
"seek -600s"
}, {
K_UP
,
"seek +60s"
}, {
K_DOWN
,
"seek -60s"
}, {
K_LEFT
,
"seek -10s"
}, {
K_RIGHT
,
"seek +10s"
}, {
' '
,
"pause"
}, {
'q'
,
"quit"
}};
104
for
(
size_t
i = 0; i <
sizeof
kb /
sizeof
kb[0]; ++i) {
105
char
description
[200];
106
snprintf(
description
,
sizeof
description
,
"playback %s"
, kb[i].
msg
);
107
if
(!
keycontrol_register_key
(mod, kb[i].
key
, kb[i].
msg
,
description
)) {
108
log_msg
(
LOG_LEVEL_ERROR
,
"Cannot register key %d control for playback!\n"
, kb[i].
key
);
109
}
110
}
111
}
112
desc
struct video_desc desc
Definition
aja_win32_stub.cpp:71
color_printf
int color_printf(const char *format,...)
Definition
color_out.cpp:220
color_out.h
TERM_BOLD
#define TERM_BOLD
Definition
color_out.h:48
TERM_RESET
#define TERM_RESET
Definition
color_out.h:47
TRED
#define TRED(x)
Definition
color_out.h:75
TBOLD
#define TBOLD(x)
Definition
color_out.h:70
config_unix.h
config_win32.h
log_msg
void log_msg(int level, const char *format,...)
Definition
debug.cpp:130
debug.h
LOG_LEVEL_INFO
#define LOG_LEVEL_INFO
normal reporting
Definition
debug.h:62
LOG_LEVEL_ERROR
#define LOG_LEVEL_ERROR
general errors
Definition
debug.h:59
keycontrol_register_key
bool keycontrol_register_key(struct module *receiver_mod, int64_t key, const char *message, const char *description)
Registers callback message for given key.
Definition
keyboard_control.cpp:1041
keyboard_control.h
K_LEFT
#define K_LEFT
Definition
keyboard_control.h:73
K_RIGHT
#define K_RIGHT
Definition
keyboard_control.h:72
K_PGDOWN
#define K_PGDOWN
Definition
keyboard_control.h:75
K_DOWN
#define K_DOWN
Definition
keyboard_control.h:71
K_PGUP
#define K_PGUP
Definition
keyboard_control.h:74
K_UP
#define K_UP
Definition
keyboard_control.h:70
playback_register_keyboard_ctl
void playback_register_keyboard_ctl(struct module *mod)
Definition
playback.c:102
playback_set_device
int playback_set_device(char *device_string, size_t buf_len, const char *optarg)
Definition
playback.c:70
MOD_NAME
#define MOD_NAME
Definition
playback.c:54
playback_usage
static void playback_usage(void)
Definition
playback.c:56
playback.h
msg
struct msghdr msg
Definition
rtp_callback.c:80
module
Definition
module.h:111
msg
Definition
synchronized_queue.h:46
text.h
wrap_paragraph
char * wrap_paragraph(char *text)
Definition
text.c:204
description
const char * description
Definition
cineform.cpp:126
key
const char * key
Definition
cineform.cpp:125
Generated on Wed Sep 25 2024 14:27:17 for UltraGrid by
1.12.0