Skip to content

Commit 0683686

Browse files
committed
omt: Move some functions to omt_common.hpp
1 parent a8ff874 commit 0683686

4 files changed

Lines changed: 147 additions & 36 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,7 @@ fi
34673467
if test "${omt_req?}" != no && test "${FOUND_LIBOMT_H?}" && test "${FOUND_LIBOMT_LIB?}" = yes
34683468
then
34693469
omt=yes
3470-
add_module rxtx_omt "src/video_rxtx/omt.o" "-lomt"
3470+
add_module rxtx_omt "src/omt_common.o src/video_rxtx/omt.o" "-lomt"
34713471
fi
34723472

34733473
ENSURE_FEATURE_PRESENT([${omt_req?}], [${omt?}], [libomt not found])

src/omt_common.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @file omt_common.cpp
3+
* @author Martin Piatka <piatka@cesnet.cz>
4+
*/
5+
/*
6+
* Copyright (c) 2026 CESNET, zájmové sdružení právických osob
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 "omt_common.hpp"
39+
40+
#include <cassert>
41+
#include <config.h> //for VERSION
42+
43+
#include "debug.h"
44+
#include "types.h"
45+
#include "video_codec.h"
46+
#define MOD_NAME "[omt] "
47+
48+
void omt_log_callback(const char *msg){
49+
log_msg(LOG_LEVEL_INFO, MOD_NAME "[libomt] %s\n", msg);
50+
}
51+
52+
void set_omt_sender_info(omt_send_t *send_handle){
53+
OMTSenderInfo info = {};
54+
std::string productName = "UltraGrid";
55+
std::string manufacturer = "CESNET";
56+
std::string version = VERSION;
57+
productName.copy(info.ProductName, OMT_MAX_STRING_LENGTH, 0);
58+
manufacturer.copy(info.Manufacturer, OMT_MAX_STRING_LENGTH, 0);
59+
version.copy(info.Version, OMT_MAX_STRING_LENGTH, 0);
60+
omt_send_setsenderinformation(send_handle, &info);
61+
}
62+
63+
bool omt_frame_init_from_desc(OMTMediaFrame& f, const video_desc& frame_desc){
64+
f.Width = frame_desc.width;
65+
f.Height = frame_desc.height;
66+
if(frame_desc.color_spec != UYVY){
67+
log_msg(LOG_LEVEL_FATAL, MOD_NAME "Codec %s not supported\n", get_codec_name(frame_desc.color_spec));
68+
return false;
69+
}
70+
f.Codec = OMTCodec_UYVY;
71+
f.ColorSpace = OMTColorSpace_BT709;
72+
f.FrameRateN = frame_desc.fps * 1000.0;
73+
f.FrameRateD = 1000;
74+
return true;
75+
}
76+
77+
void omt_frame_set_data(OMTMediaFrame& f, const video_frame& ug_frame){
78+
assert(ug_frame.tile_count == 1);
79+
f.Stride = vc_get_linesize(ug_frame.tiles[0].width, ug_frame.color_spec);
80+
f.Data = ug_frame.tiles[0].data;
81+
f.DataLength = ug_frame.tiles[0].data_len;
82+
}
83+

src/omt_common.hpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @file omt_common.hpp
3+
* @author Martin Piatka <piatka@cesnet.cz>
4+
*/
5+
/*
6+
* Copyright (c) 2026 CESNET, zájmové sdružení právických osob
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+
#ifndef OMT_COMMON_HPP_5963748ABF904BA79B6C22CAC8500636
39+
#define OMT_COMMON_HPP_5963748ABF904BA79B6C22CAC8500636
40+
41+
#include <libomt.h>
42+
#include <memory>
43+
44+
#include "types.h"
45+
#include "utils/misc.h"
46+
47+
using omt_receive_uniq = std::unique_ptr<omt_receive_t, deleter_from_fcn<omt_receive_destroy>>;
48+
using omt_send_uniq = std::unique_ptr<omt_send_t, deleter_from_fcn<omt_send_destroy>>;
49+
50+
void omt_log_callback(const char *msg);
51+
void set_omt_sender_info(omt_send_t *send_handle);
52+
bool omt_frame_init_from_desc(OMTMediaFrame& f, const video_desc& frame_desc);
53+
void omt_frame_set_data(OMTMediaFrame& f, const video_frame& ug_frame);
54+
55+
#endif //OMT_COMMON_HPP_5963748ABF904BA79B6C22CAC8500636

src/video_rxtx/omt.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <config.h>
4040
#include <libomt.h>
4141

42+
#include "omt_common.hpp"
4243
#include "debug.h"
4344
#include "lib_common.h"
4445
#include "video_rxtx.h"
@@ -51,13 +52,6 @@
5152
#define MOD_NAME "[OMT] "
5253

5354
namespace{
54-
using omt_receive_uniq = std::unique_ptr<omt_receive_t, deleter_from_fcn<omt_receive_destroy>>;
55-
using omt_send_uniq = std::unique_ptr<omt_send_t, deleter_from_fcn<omt_send_destroy>>;
56-
57-
void omt_log_callback(const char *msg){
58-
log_msg(LOG_LEVEL_INFO, MOD_NAME "[libomt] %s\n", msg);
59-
}
60-
6155
struct omt_rxtx_state{
6256
module *parent = nullptr;
6357
omt_receive_uniq omt_recv_handle;
@@ -80,17 +74,6 @@ void omt_should_exit_callback(void *state){
8074
s->should_exit = true;
8175
}
8276

83-
void set_omt_sender_info(omt_rxtx_state *s){
84-
OMTSenderInfo info = {};
85-
std::string productName = "UltraGrid";
86-
std::string manufacturer = "CESNET";
87-
std::string version = VERSION;
88-
productName.copy(info.ProductName, OMT_MAX_STRING_LENGTH, 0);
89-
manufacturer.copy(info.Manufacturer, OMT_MAX_STRING_LENGTH, 0);
90-
version.copy(info.Version, OMT_MAX_STRING_LENGTH, 0);
91-
omt_send_setsenderinformation(s->omt_send_handle.get(), &info);
92-
}
93-
9477
void print_help(){
9578
color_printf("Open Media Transport\n");
9679
color_printf("Usage\n");
@@ -136,7 +119,7 @@ void init_recv(const vrxtx_params *params, omt_rxtx_state *s){
136119

137120
void init_send(omt_rxtx_state *s){
138121
s->omt_send_handle.reset(omt_send_create(s->sender_name.c_str(), s->quality));
139-
set_omt_sender_info(s);
122+
set_omt_sender_info(s->omt_send_handle.get());
140123
s->send_video_frame.Type = OMTFrameType_Video;
141124
s->send_video_frame.Timestamp = -1;
142125
}
@@ -165,19 +148,11 @@ void omt_rxtx_done(void *state){
165148
delete s;
166149
}
167150

168-
bool send_reconfigure(omt_rxtx_state *s, struct video_desc frame_desc){
169-
s->send_video_frame.Width = frame_desc.width;
170-
s->send_video_frame.Height = frame_desc.height;
171-
if(frame_desc.color_spec != UYVY){
172-
log_msg(LOG_LEVEL_FATAL, MOD_NAME "Codec %s not supported\n", get_codec_name(frame_desc.color_spec));
173-
return false;
174-
}
175-
s->send_video_frame.Codec = OMTCodec_UYVY;
176-
s->send_video_frame.ColorSpace = OMTColorSpace_BT709;
177-
s->send_video_frame.FrameRateN = frame_desc.fps * 1000.0;
178-
s->send_video_frame.FrameRateD = 1000;
179-
s->send_desc = frame_desc;
180-
return true;
151+
bool send_reconfigure(omt_rxtx_state *s, const video_desc& frame_desc){
152+
bool ret = omt_frame_init_from_desc(s->send_video_frame, frame_desc);
153+
if(ret)
154+
s->send_desc = frame_desc;
155+
return ret;
181156
}
182157

183158
void omt_rxtx_send_frame(void *state, std::shared_ptr<video_frame> f){
@@ -188,9 +163,7 @@ void omt_rxtx_send_frame(void *state, std::shared_ptr<video_frame> f){
188163
return;
189164
}
190165

191-
s->send_video_frame.Stride = vc_get_linesize(f->tiles[0].width, f->color_spec);
192-
s->send_video_frame.Data = f->tiles[0].data;
193-
s->send_video_frame.DataLength = f->tiles[0].data_len;
166+
omt_frame_set_data(s->send_video_frame, *f);
194167

195168
omt_send(s->omt_send_handle.get(), &s->send_video_frame);
196169
}

0 commit comments

Comments
 (0)