UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_rxtx.cpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2013-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#include <sstream>
39#include <stdexcept>
40#include <string>
41#include <utility>
42
43#include "debug.h"
44#include "export.h"
45#include "host.h"
46#include "lib_common.h"
47#include "messaging.h"
48#include "module.h"
49#include "pdb.h"
50#include "rtp/rtp.h"
51#include "rtp/video_decoders.h"
52#include "rtp/pbuf.h"
53#include "tfrc.h"
54#include "transmit.h"
55#include "tv.h"
56#include "utils/thread.h"
57#include "utils/vf_split.h"
58#include "video.h"
59#include "video_compress.h"
60#include "video_decompress.h"
61#include "video_display.h"
62#include "video_rxtx.hpp"
63
64#define MOD_NAME "[vrxtx] "
65
66using std::map;
67using std::shared_ptr;
68using std::string;
69
70video_rxtx::video_rxtx(map<string, param_u> const &params): m_port_id("default"),
71 m_rxtx_mode(params.at("rxtx_mode").i),
72 m_frames_sent(0ull),
73 m_common(*static_cast<struct common_opts const *>(params.at("common").cptr)),
74 m_thread_id(), m_poisoned(false), m_joined(true) {
75
79
83
84 try {
85 int ret = compress_init(&m_sender_mod, static_cast<const char *>(params.at("compression").ptr),
87 if(ret != 0) {
88 if(ret < 0) {
89 throw string("Error initializing compression.");
90 }
91 if(ret > 0) {
92 throw EXIT_SUCCESS;
93 }
94 }
95
96 pthread_mutex_init(&m_lock, NULL);
97
98 } catch (...) {
99 if (m_compression) {
101 }
102
105
106 throw;
107 }
108}
109
111 video_rxtx *s = (video_rxtx *) state;
112 s->m_should_exit = true;
113}
114
125
128 this);
129 if (pthread_create(&m_thread_id, NULL, video_rxtx::sender_thread,
130 (void *) this) != 0) {
131 throw string("Unable to create sender thread!\n");
132 }
133 m_joined = false;
134}
135
137 if (m_joined) {
138 return;
139 }
140 send(NULL); // pass poisoned pill
141 pthread_join(m_thread_id, NULL);
143 m_joined = true;
144}
145
146const char *video_rxtx::get_long_name(string const & short_name) {
147 auto vri = static_cast<const video_rxtx_info *>(load_library(short_name.c_str(), LIBRARY_CLASS_VIDEO_RXTX, VIDEO_RXTX_ABI_VERSION));
148 if (vri) {
149 return vri->long_name;
150 } else {
151 return "";
152 }
153}
154
155void video_rxtx::send(shared_ptr<video_frame> frame) {
156 if (!frame && m_poisoned) {
157 return;
158 }
160 if (!frame) {
161 m_poisoned = true;
162 }
163}
164
165void *video_rxtx::sender_thread(void *args) {
166 return static_cast<video_rxtx *>(args)->sender_loop();
167}
168
170 // process external messages
171 struct message *msg_external;
172 while((msg_external = check_message(&m_sender_mod))) {
173 struct response *r = process_sender_message((struct msg_sender *) msg_external);
174 free_message(msg_external, r);
175 }
176}
177
179 set_thread_name(__func__);
180 struct video_desc saved_vid_desc;
181
182 memset(&saved_vid_desc, 0, sizeof(saved_vid_desc));
183
184 while(1) {
186
187 shared_ptr<video_frame> tx_frame;
188
189 tx_frame = compress_pop(m_compression);
190 if (!tx_frame) {
191 break;
192 }
193
194 export_video(m_common.exporter, tx_frame.get());
195
196 send_frame(std::move(tx_frame));
197 m_frames_sent += 1;
198 }
199
201 return NULL;
202}
203
204video_rxtx *video_rxtx::create(string const & proto, std::map<std::string, param_u> const &params)
205{
206 auto vri = static_cast<const video_rxtx_info *>(load_library(proto.c_str(), LIBRARY_CLASS_VIDEO_RXTX, VIDEO_RXTX_ABI_VERSION));
207 if (!vri) {
208 return nullptr;
209 }
210 auto ret = vri->create(params);
211 if (!ret) {
212 return nullptr;
213 }
214 ret->start();
215 return ret;
216}
217
218void video_rxtx::list(bool full)
219{
220 printf("Available TX protocols:\n");
222}
223
224void
225video_rxtx::set_audio_spec(const struct audio_desc * /* desc */,
226 int /* audio_rx_port */, int /* audio_tx_port */,
227 bool /* ipv6 */)
228{
229 MSG(INFO, "video RXTX not h264_rtp, not setting audio...\n");
230}
void ** state
struct video_frame * frame
#define MSG(l, fmt,...)
Definition debug.h:96
void export_video(struct exporter *s, struct video_frame *frame)
Definition export.c:356
void module_init_default(struct module *module_data)
Definition module.c:48
void module_register(struct module *module_data, struct module *parent)
Definition module.c:82
void module_done(struct module *module_data)
Definition module.c:93
@ MODULE_CLASS_RECEIVER
Definition module.h:88
@ MODULE_CLASS_SENDER
Definition module.h:87
shared_ptr< video_frame > compress_pop(struct compress_state *proxy)
void compress_frame(struct compress_state *proxy, shared_ptr< video_frame > frame)
int compress_init(struct module *parent, const char *config_string, struct compress_state **state)
This function initializes video compression.
void compress_done(struct compress_state *proxy)
Video compression cleanup function.
void register_should_exit_callback(struct module *mod, void(*callback)(void *), void *udata)
Definition host.cpp:1144
void unregister_should_exit_callback(struct module *mod, void(*callback)(void *), void *udata)
Definition host.cpp:1158
void list_modules(enum library_class cls, int abi_version, bool full)
const void * load_library(const char *name, enum library_class cls, int abi_version)
@ LIBRARY_CLASS_VIDEO_RXTX
Definition lib_common.h:84
void free_message(struct message *msg, struct response *r)
struct message * check_message(struct module *mod)
struct module * parent
Definition host.h:171
struct exporter * exporter
Definition host.h:177
enum module_class cls
Definition module.h:115
struct video_rxtx *(* create)(std::map< std::string, param_u > const &params)
static void * sender_thread(void *args)
bool m_should_exit
struct compress_state * m_compression
pthread_t m_thread_id
unsigned long long int m_frames_sent
struct module m_sender_mod
static video_rxtx * create(std::string const &name, std::map< std::string, param_u > const &)
virtual struct response * process_sender_message(struct msg_sender *)
struct module m_receiver_mod
void check_sender_messages()
void * sender_loop()
void send(std::shared_ptr< struct video_frame >)
static void should_exit(void *state)
virtual void send_frame(std::shared_ptr< video_frame >) noexcept=0
video_rxtx(std::map< std::string, param_u > const &)
virtual void set_audio_spec(const struct audio_desc *desc, int audio_rx_port, int audio_tx_port, bool ipv6)
virtual void join()
static void list(bool full)
static const char * get_long_name(std::string const &short_name)
pthread_mutex_t m_lock
struct common_opts m_common
virtual ~video_rxtx()
void set_thread_name(const char *name)
Definition thread.c:72
This is an umbrella header for video functions.
API for video compress drivers.
Video RTP decoder.
API for video decompress drivers.
#define VIDEO_RXTX_ABI_VERSION