UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ihdtv.cpp
Go to the documentation of this file.
1/*
2 * FILE: ihdtv.cpp
3 * AUTHORS: Colin Perkins <csp@csperkins.org>
4 * Ladan Gharai <ladan@isi.edu>
5 * Martin Benes <martinbenesh@gmail.com>
6 * Lukas Hejtmanek <xhejtman@ics.muni.cz>
7 * Petr Holub <hopet@ics.muni.cz>
8 * Milos Liska <xliska@fi.muni.cz>
9 * Jiri Matela <matela@ics.muni.cz>
10 * Dalibor Matura <255899@mail.muni.cz>
11 * Ian Wesley-Smith <iwsmith@cct.lsu.edu>
12 *
13 * Copyright (c) 2005-2023 CESNET z.s.p.o.
14 * Copyright (c) 2001-2004 University of Southern California
15 * Copyright (c) 2003-2004 University of Glasgow
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, is permitted provided that the following conditions
19 * are met:
20 *
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 *
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * 3. All advertising materials mentioning features or use of this software
29 * must display the following acknowledgement:
30 *
31 * This product includes software developed by the University of Southern
32 * California Information Sciences Institute. This product also includes
33 * software developed by CESNET z.s.p.o.
34 *
35 * 4. Neither the name of the University nor of the Institute may be used
36 * to endorse or promote products derived from this software without
37 * specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
40 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
41 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
42 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
43 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
44 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
50 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 *
52 */
53
54#ifdef HAVE_CONFIG_H
55#include "config.h"
56#include "config_unix.h"
57#include "config_win32.h"
58#endif // HAVE_CONFIG_H
59
60#include <string>
61
62#include "debug.h"
63#include "host.h" // for common_opts, uv_argc, uv_argv
64#include "lib_common.h"
65#include "ihdtv/ihdtv.h"
66#include "video_display.h"
67#include "video_capture.h"
68#include "video_rxtx.hpp"
69#include "video_rxtx/ihdtv.hpp"
70#include "video.h"
71
72using namespace std;
73
74void
75ihdtv_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
76{
77#ifdef HAVE_IHDTV
78 ihdtv_send(&m_tx_connection, tx_frame.get(), 9000000); // FIXME: fix the use of frame size!!
79#else // IHDTV
80 UNUSED(tx_frame);
81#endif // IHDTV
82}
83
85{
86#ifdef HAVE_IHDTV
87 ihdtv_connection *connection = &m_rx_connection;
88
89 struct video_frame *frame_buffer = NULL;
90
91 while (!m_should_exit) {
92 frame_buffer = display_get_frame(m_display_device);
94 (connection, frame_buffer->tiles[0].data, frame_buffer->tiles[0].data_len))
95 return 0; // we've got some error. probably empty buffer
96 display_put_frame(m_display_device, frame_buffer, PUTF_BLOCKING);
97 }
98#endif // IHDTV
99 return NULL;
100}
101
102#if 0
103static void *ihdtv_sender_thread(void *arg)
104{
105 ihdtv_connection *connection = (ihdtv_connection *) ((void **)arg)[0];
106 struct vidcap *capture_device = (struct vidcap *)((void **)arg)[1];
107 struct video_frame *tx_frame;
108 struct audio_frame *audio;
109
110 while (1) {
111 if ((tx_frame = vidcap_grab(capture_device, &audio)) != NULL) {
112 ihdtv_send(connection, tx_frame, 9000000); // FIXME: fix the use of frame size!!
113 free(tx_frame);
114 } else {
115 fprintf(stderr,
116 "Error receiving frame from capture device\n");
117 return 0;
118 }
119 }
120
121 return 0;
122}
123#endif
124
125ihdtv_video_rxtx::ihdtv_video_rxtx(map<string, param_u> const &params) :
127#ifdef HAVE_IHDTV
128 , m_tx_connection(), m_rx_connection()
129#endif
130
131{
132#ifdef HAVE_IHDTV
133 int argc = uv_argc;
134 char **argv = uv_argv;
135 if ((argc != 0) && (argc != 1) && (argc != 2)) {
136 throw string("Wrong number of parameters");
137 }
138
139 printf("Initializing ihdtv protocol\n");
140
141 // we cannot act as both together, because parameter parsing would have to be revamped
142 if (params.at("capture_device").ptr && params.at("display_device").ptr) {
143 throw string
144 ("Error: cannot act as both sender and receiver together in ihdtv mode");
145 }
146
147 m_display_device = static_cast<struct display *>(params.at("display_device").ptr);
148
149 if (m_display_device) {
151 (&m_rx_connection, (argc == 0) ? NULL : argv[0],
152 (argc ==
153 0) ? NULL : ((argc == 1) ? argv[0] : argv[1]),
154 3000, 3001, m_common.mtu) != 0) {
155 throw string("Error initializing receiver session");
156 }
157 }
158
159 if (static_cast<struct display *>(params.at("capture_device").ptr) != 0) {
160 if (argc == 0) {
161 throw string("Error: specify the destination address");
162 }
163
165 (&m_tx_connection, argv[0],
166 (argc == 2) ? argv[1] : argv[0],
167 m_common.mtu) != 0) {
168 throw string("Error initializing sender session");
169 }
170 }
171#else
172 throw string("Support for iHDTV not compiled in");
173#endif // HAVE_IHDTV
174}
175
179
180static video_rxtx *create_video_rxtx_ihdtv(std::map<std::string, param_u> const &params)
181{
182 log_msg(LOG_LEVEL_WARNING, "Warning: iHDTV support may be currently broken.\n"
183 "Please contact %s if you need this.\n", PACKAGE_BUGREPORT);
184
185 return new ihdtv_video_rxtx(params);
186}
187
189 "iHDTV",
191};
192
194
#define UNUSED(x)
struct audio_frame ** audio
void send_frame(std::shared_ptr< video_frame >) noexcept override
Definition ihdtv.cpp:75
void * receiver_loop()
Definition ihdtv.cpp:84
ihdtv_video_rxtx(std::map< std::string, param_u > const &)
Definition ihdtv.cpp:125
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
bool display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns)
Puts filled video frame. After calling this function, video frame cannot be used.
#define PUTF_BLOCKING
struct video_frame * display_get_frame(struct display *d)
Returns video framebuffer which will be written to.
struct video_frame * vidcap_grab(struct vidcap *state, struct audio_frame **audio)
Grabs video frame. This function may block for a short period if waiting for incoming frame....
char ** uv_argv
Definition host.cpp:174
int uv_argc
Definition host.cpp:173
int ihdtv_receive(ihdtv_connection *connection, char *buffer, const unsigned long buffer_length)
Definition ihdtv.c:392
int ihdtv_init_rx_session(ihdtv_connection *connection, const char *address_1, const char *address_2, unsigned int port1, unsigned int port2, long mtu)
Definition ihdtv.c:67
int ihdtv_init_tx_session(ihdtv_connection *connection, const char *address_1, const char *address_2, long mtu)
Definition ihdtv.c:190
int ihdtv_send(ihdtv_connection *connection, struct video_frame *tx_frame, unsigned long buffer_length)
Definition ihdtv.c:269
static video_rxtx * create_video_rxtx_ihdtv(std::map< std::string, param_u > const &params)
Definition ihdtv.cpp:180
static const struct video_rxtx_info ihdtv_video_rxtx_info
Definition ihdtv.cpp:188
@ LIBRARY_CLASS_VIDEO_RXTX
Definition lib_common.h:84
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
struct used to comunicate with audio capture/playback device
Definition types.h:99
int mtu
Definition host.h:174
This struct represents initialized video display state.
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
This struct represents video capture state.
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
bool m_should_exit
struct common_opts m_common
This is an umbrella header for video functions.
#define VIDEO_RXTX_ABI_VERSION