UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
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
56static 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).";
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
70int playback_set_device(char *device_string, size_t buf_len, const char *optarg) {
71 bool is_import = false;
72 if (strcmp(optarg, "help") == 0) {
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
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
struct video_desc desc
int color_printf(const char *format,...)
#define TERM_BOLD
Definition color_out.h:48
#define TERM_RESET
Definition color_out.h:47
#define TRED(x)
Definition color_out.h:75
#define TBOLD(x)
Definition color_out.h:70
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
bool keycontrol_register_key(struct module *receiver_mod, int64_t key, const char *message, const char *description)
Registers callback message for given key.
#define K_LEFT
#define K_RIGHT
#define K_PGDOWN
#define K_DOWN
#define K_PGUP
#define K_UP
void playback_register_keyboard_ctl(struct module *mod)
Definition playback.c:102
int playback_set_device(char *device_string, size_t buf_len, const char *optarg)
Definition playback.c:70
#define MOD_NAME
Definition playback.c:54
static void playback_usage(void)
Definition playback.c:56
struct msghdr msg
char * wrap_paragraph(char *text)
Definition text.c:204
const char * description
Definition cineform.cpp:126
const char * key
Definition cineform.cpp:125