UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
sage.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
39#ifdef HAVE_CONFIG_H
40#include "config.h"
41#include "config_unix.h"
42#include "config_win32.h"
43#endif // HAVE_CONFIG_H
44
45#include <string>
46#include <sstream>
47
48#include "host.h"
49#include "lib_common.h"
50#include "video_display.h"
51#include "video_rxtx/sage.hpp"
52#include "video_rxtx.hpp"
53#include "video.h"
54
55using namespace std;
56
57sage_video_rxtx::sage_video_rxtx(map<string, param_u> const &params) :
59{
60 ostringstream oss;
61
62 if (params.at("opts").str) {
63 oss << params.at("opts").str << ":";
64 }
65
66 oss << "fs=" << params.at("receiver").str;
67 oss << ":tx"; // indicates that we are in tx mode
68 int ret = initialize_video_display(&m_sender_mod, "sage",
69 oss.str().c_str(), 0, NULL, &m_sage_tx_device);
70 if(ret != 0) {
71 throw string("Unable to initialize SAGE TX.");
72 }
74 memset(&m_saved_video_desc, 0, sizeof(m_saved_video_desc));
75}
76
77void
78sage_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
79{
80 if (!video_desc_eq(m_saved_video_desc,
81 video_desc_from_frame(tx_frame.get()))) {
82 display_reconfigure(m_sage_tx_device,
83 video_desc_from_frame(tx_frame.get()), VIDEO_NORMAL);
84 m_saved_video_desc = video_desc_from_frame(tx_frame.get());
85 }
86 struct video_frame *frame =
87 display_get_frame(m_sage_tx_device);
88 memcpy(frame->tiles[0].data, tx_frame->tiles[0].data,
89 tx_frame->tiles[0].data_len);
90 display_put_frame(m_sage_tx_device, frame, PUTF_NONBLOCK);
91}
92
101
102static video_rxtx *create_video_rxtx_sage(std::map<std::string, param_u> const &params)
103{
104 return new sage_video_rxtx(params);
105}
106
108 "SAGE",
110};
111
113
struct video_frame * frame
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
struct video_desc m_saved_video_desc
Definition sage.hpp:58
void send_frame(std::shared_ptr< video_frame >) noexcept override
Definition sage.cpp:78
sage_video_rxtx(std::map< std::string, param_u > const &)
Definition sage.cpp:57
struct display * m_sage_tx_device
Definition sage.hpp:59
#define PUTF_NONBLOCK
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.
void display_run_new_thread(struct display *d)
void display_done(struct display *d)
This function performs cleanup after done.
void display_join(struct display *d)
int initialize_video_display(struct module *parent, const char *requested_display, const char *fmt, unsigned int flags, const char *postprocess, struct display **out)
Initializes video display.
struct video_frame * display_get_frame(struct display *d)
Returns video framebuffer which will be written to.
@ 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
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
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
struct module m_sender_mod
@ VIDEO_NORMAL
normal video (one tile)
Definition types.h:356
This is an umbrella header for video functions.
bool display_reconfigure(struct display *d, struct video_desc desc, enum video_mode video_mode)
Reconfigure display to new video format.
bool video_desc_eq(struct video_desc a, struct video_desc b)
Compares two video descriptions.
static video_rxtx * create_video_rxtx_sage(std::map< std::string, param_u > const &params)
Definition sage.cpp:102
static const struct video_rxtx_info sage_video_rxtx_info
Definition sage.cpp:107
#define VIDEO_RXTX_ABI_VERSION