Skip to content

Commit 69801bc

Browse files
committed
vcap/omt: Initial
1 parent d9182ff commit 69801bc

2 files changed

Lines changed: 154 additions & 1 deletion

File tree

configure.ac

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

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

src/video_capture/omt.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* @file video_capture/omt.cpp
3+
* @author Martin Piatka <piatka@cesnet.cz>
4+
*/
5+
/*
6+
* Copyright (c) 2026 CESNET, zájmové sdružení právnický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 <cassert>
39+
#include <memory>
40+
41+
#include "debug.h"
42+
#include "omt_common.hpp"
43+
#include "video_capture.h"
44+
#include "lib_common.h"
45+
#include "video_codec.h"
46+
#include "video_frame.h"
47+
#include "utils/color_out.h"
48+
#include "utils/string_view_utils.hpp"
49+
50+
#define MOD_NAME "[omt] "
51+
52+
namespace{
53+
using video_frame_uniq = std::unique_ptr<video_frame, deleter_from_fcn<vf_free>>;
54+
55+
struct state_omt_cap{
56+
omt_receive_uniq omt_h;
57+
58+
video_frame_uniq ug_frame;
59+
60+
std::string sender_addr = "localhost";
61+
int port = 6400;
62+
};
63+
64+
void capture_omt_probe(device_info **available_cards, int *count, void(** deleter)(void *)){
65+
*deleter = free;
66+
*available_cards = nullptr;
67+
*count = 0;
68+
}
69+
70+
void show_help(){
71+
color_printf("Open Media Transport\n");
72+
color_printf("Usage\n");
73+
color_printf(TERM_BOLD TERM_FG_RED "\t-t omt" TERM_FG_RESET "[:addr=<addr>][:port=<port>]\n" TERM_RESET);
74+
color_printf("\n");
75+
}
76+
77+
int parse_cfg(state_omt_cap& s, std::string_view cfg){
78+
while(!cfg.empty()){
79+
auto tok = tokenize(cfg, ':', '"');
80+
const auto key = tokenize(tok, '=', '"');
81+
const auto val = tokenize(tok, '=', '"');
82+
83+
if(key == "addr"){
84+
s.sender_addr = val;
85+
} else if(key == "port"){
86+
if(!parse_num(val, s.port)){
87+
log_msg(LOG_LEVEL_FATAL, "Failed to parse port: %s\n", std::string(val).c_str());
88+
return VIDCAP_INIT_FAIL;
89+
}
90+
} else if(key == "help"){
91+
show_help();
92+
return VIDCAP_INIT_NOERR;
93+
} else{
94+
log_msg(LOG_LEVEL_FATAL, "Unknown parameter: %s\n", std::string(key).c_str());
95+
return VIDCAP_INIT_FAIL;
96+
}
97+
}
98+
99+
return VIDCAP_INIT_OK;
100+
}
101+
102+
int capture_omt_init(const vidcap_params *params, void **state){
103+
auto s = std::make_unique<state_omt_cap>();
104+
105+
if(auto parse_ret = parse_cfg(*s, vidcap_params_get_fmt(params)); parse_ret != VIDCAP_INIT_OK){
106+
return parse_ret;
107+
}
108+
109+
std::string addr = "omt://" + s->sender_addr + ":" + std::to_string(s->port);
110+
111+
s->omt_h.reset(omt_receive_create(addr.c_str(), static_cast<OMTFrameType>(OMTFrameType_Audio | OMTFrameType_Video),
112+
OMTPreferredVideoFormat_UYVY, OMTReceiveFlags_None));
113+
114+
*state = s.release();
115+
return VIDCAP_INIT_OK;
116+
}
117+
118+
void capture_omt_done(void *state){
119+
auto s = static_cast<state_omt_cap *>(state);
120+
delete s;
121+
}
122+
123+
video_frame *capture_omt_grab(void *state, audio_frame **/*audio*/){
124+
auto s = static_cast<state_omt_cap *>(state);
125+
126+
const auto omt_frame = omt_receive(s->omt_h.get(), OMTFrameType_Video, 1000);
127+
if(!omt_frame){
128+
return nullptr;
129+
}
130+
131+
if(const video_desc incoming_desc = video_desc_from_omt_frame(omt_frame);
132+
!s->ug_frame || video_desc_eq(incoming_desc, video_desc_from_frame(s->ug_frame.get())))
133+
{
134+
s->ug_frame.reset(vf_alloc_desc(incoming_desc));
135+
}
136+
137+
assert(omt_frame->Stride == vc_get_linesize(s->ug_frame->tiles[0].width, s->ug_frame->color_spec));
138+
s->ug_frame->tiles[0].data = static_cast<char *>(omt_frame->Data);
139+
s->ug_frame->tiles[0].data_len = omt_frame->DataLength;
140+
141+
return s->ug_frame.get();
142+
}
143+
144+
constexpr video_capture_info vidcap_omt_info = {
145+
capture_omt_probe,
146+
capture_omt_init,
147+
capture_omt_done,
148+
capture_omt_grab,
149+
MOD_NAME,
150+
};
151+
}
152+
153+
REGISTER_MODULE(omt, &vidcap_omt_info, LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION);

0 commit comments

Comments
 (0)