Skip to content

Commit 8ce4b0c

Browse files
committed
d
1 parent 9d80576 commit 8ce4b0c

File tree

9 files changed

+74
-70
lines changed

9 files changed

+74
-70
lines changed

.github/workflows/build_linux.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- name: Install dependencies
29-
run: sudo apt update && sudo apt-get install libgpac-dev libtesseract-dev
29+
run: sudo apt update && sudo apt-get install libgpac-dev libtesseract-dev libnanomsg-dev
3030
- uses: actions/checkout@v4
3131
- name: build
3232
run: ./build
@@ -46,7 +46,7 @@ jobs:
4646
runs-on: ubuntu-latest
4747
steps:
4848
- name: Install dependencies
49-
run: sudo apt update && sudo apt-get install libgpac-dev
49+
run: sudo apt update && sudo apt-get install libgpac-dev libnanomsg-dev
5050
- uses: actions/checkout@v4
5151
- name: run autogen
5252
run: ./autogen.sh
@@ -64,7 +64,7 @@ jobs:
6464
runs-on: ubuntu-latest
6565
steps:
6666
- name: Install dependencies
67-
run: sudo apt update && sudo apt-get install libgpac-dev
67+
run: sudo apt update && sudo apt-get install libgpac-dev libnanomsg-dev
6868
- uses: actions/checkout@v4
6969
- name: cmake
7070
run: mkdir build && cd build && cmake ../src
@@ -78,7 +78,7 @@ jobs:
7878
steps:
7979
- uses: actions/checkout@v4
8080
- name: Install dependencies
81-
run: sudo apt update && sudo apt install libgpac-dev libtesseract-dev libavformat-dev libavdevice-dev libswscale-dev yasm
81+
run: sudo apt update && sudo apt install libgpac-dev libtesseract-dev libavformat-dev libavdevice-dev libswscale-dev yasm libnanomsg-dev
8282
- name: cmake
8383
run: |
8484
mkdir build && cd build

linux/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ ccextractor_LDADD += $(LEPT_LIB)
334334
endif
335335

336336
if WITH_RUST
337-
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
337+
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a -lnanomsg
338338
else
339339
ccextractor_CFLAGS += -DDISABLE_RUST
340340
ccextractor_CPPFLAGS += -DDISABLE_RUST

linux/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ echo "Trying to compile..."
9494
if [ "$WITHOUT_RUST" = true ]; then
9595
echo "Building without rust files..."
9696
BLD_FLAGS="$BLD_FLAGS -DDISABLE_RUST"
97-
else
97+
else
9898
BLD_LINKER="$BLD_LINKER ./libccx_rust.a -lnanomsg"
9999
echo "Checking for cargo..."
100100
if ! [ -x "$(command -v cargo)" ]; then

mac/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ ccextractor_LDADD += $(LEPT_LIB)
307307
endif
308308

309309
if WITH_RUST
310-
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
310+
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a -lnanomsg
311311
else
312312
ccextractor_CFLAGS += -DDISABLE_RUST
313313
ccextractor_CPPFLAGS += -DDISABLE_RUST

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ add_subdirectory (lib_ccx)
152152
aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE)
153153
set (EXTRA_LIBS ${EXTRA_LIBS} ccx)
154154
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
155+
set (EXTRA_LIBS ${EXTRA_LIBS} ${NANOMSG_LIBRARIES})
155156
# set (EXTRA_LIBS ${EXTRA_LIBS} m)
156157

157158
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -262,6 +263,10 @@ else ()
262263
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_RUST")
263264
endif (PKG_CONFIG_FOUND AND NOT WITHOUT_RUST)
264265

266+
pkg_check_modules(NANOMSG REQUIRED nanomsg)
267+
268+
set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${NANOMSG_INCLUDE_DIR})
269+
set(EXTRA_LIBS ${EXTRA_LIBS} ${NANOMSG_LIBRARIES})
265270

266271
target_link_libraries (ccextractor ${EXTRA_LIBS})
267272
target_include_directories (ccextractor PUBLIC ${EXTRA_INCLUDES})

src/lib_ccx/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ pkg_check_modules (GPAC REQUIRED gpac)
1515

1616
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS})
1717
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
18+
##new
19+
pkg_check_modules(NANOMSG REQUIRED nanomsg)
20+
21+
set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${NANOMSG_INCLUDE_DIRS})
22+
set(EXTRA_LIBS ${EXTRA_LIBS} ${NANOMSG_LIBRARIES})
23+
##new
1824

1925
if (WITH_FFMPEG)
2026
find_package(PkgConfig)

src/rust/lib_ccxr/src/share/share.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
use std::{ptr, thread, time::Duration, ffi::{CString, CStr}};
2-
use std::any::Any;
1+
extern crate libc;
32
use std::cmp::PartialEq;
43
use std::io::Write;
4+
use std::{ffi::{CStr, CString}, time::Duration};
55

6-
extern crate libc;
7-
use std::os::raw::{c_char, c_int, c_void};
8-
use std::sync::{Mutex, Once};
9-
use std::thread::sleep;
10-
use crate::util::log::{debug, info, DebugMessageFlag};
116
use crate::share::ccxr_sub_entry_message::CcxSubEntryMessage;
12-
use nanomsg::{Endpoint, Protocol, Socket};
7+
use crate::util::log::{debug, DebugMessageFlag};
138
use lazy_static::lazy_static;
9+
use nanomsg::{Endpoint, Protocol, Socket};
1410
use prost::Message;
11+
use std::os::raw::{c_char, c_int};
12+
use std::sync::Mutex;
13+
use std::thread::sleep;
1514

1615
// use crate::bindings::{cc_subtitle, ccx_output_format};
1716

@@ -119,7 +118,7 @@ impl Eia608Screen {
119118
pub fn free_xds_str(&mut self) {
120119
if !self.xds_str.is_null() {
121120
unsafe {
122-
CString::from_raw(self.xds_str);
121+
let _ = CString::from_raw(self.xds_str);
123122
}
124123
self.xds_str = std::ptr::null_mut();
125124
self.xds_len = 0;
@@ -134,41 +133,41 @@ impl Drop for Eia608Screen {
134133
}
135134

136135

137-
pub type subdatatype = ::std::os::raw::c_uint;
136+
pub type SubDataType = std::os::raw::c_uint;
138137
pub type LLONG = i64;
139-
pub const subtype_CC_BITMAP: subtype = 0;
140-
pub const subtype_CC_608: subtype = 1;
141-
pub const subtype_CC_TEXT: subtype = 2;
142-
pub const subtype_CC_RAW: subtype = 3;
143-
pub type subtype = ::std::os::raw::c_uint;
138+
pub const SUBTYPE_CC_BITMAP: Subtype = 0;
139+
pub const SUBTYPE_CC_608: Subtype = 1;
140+
pub const SUBTYPE_CC_TEXT: Subtype = 2;
141+
pub const SUBTYPE_CC_RAW: Subtype = 3;
142+
pub type Subtype = std::os::raw::c_uint;
144143

145-
pub type ccx_encoding_type = ::std::os::raw::c_uint;
144+
pub type CcxEncodingType = std::os::raw::c_uint;
146145

147146
pub struct CcSubtitle {
148147
#[doc = " A generic data which contain data according to decoder\n @warn decoder cant output multiple types of data"]
149-
pub data: *mut ::std::os::raw::c_void,
150-
pub datatype: subdatatype,
148+
pub data: *mut std::os::raw::c_void,
149+
pub datatype: SubDataType,
151150
#[doc = " number of data"]
152-
pub nb_data: ::std::os::raw::c_uint,
151+
pub nb_data: std::os::raw::c_uint,
153152
#[doc = " type of subtitle"]
154-
pub type_: subtype,
153+
pub type_: Subtype,
155154
#[doc = " Encoding type of Text, must be ignored in case of subtype as bitmap or cc_screen"]
156-
pub enc_type: ccx_encoding_type,
155+
pub enc_type: CcxEncodingType,
157156
pub start_time: LLONG,
158157
pub end_time: LLONG,
159-
pub flags: ::std::os::raw::c_int,
160-
pub lang_index: ::std::os::raw::c_int,
158+
pub flags: c_int,
159+
pub lang_index: c_int,
161160
#[doc = " flag to tell that decoder has given output"]
162-
pub got_output: ::std::os::raw::c_int,
163-
pub mode: [::std::os::raw::c_char; 5usize],
164-
pub info: [::std::os::raw::c_char; 4usize],
161+
pub got_output: c_int,
162+
pub mode: [c_char; 5usize],
163+
pub info: [c_char; 4usize],
165164
#[doc = " Used for DVB end time in ms"]
166-
pub time_out: ::std::os::raw::c_int,
165+
pub time_out: c_int,
167166
pub next: *mut CcSubtitle,
168167
pub prev: *mut CcSubtitle,
169168
}
170169

171-
170+
#[repr(C)]
172171
#[derive(Debug)]
173172
pub enum CcxShareStatus {
174173
Ok = 0,
@@ -256,7 +255,6 @@ pub fn ccxr_sub_entry_msg_print(msg: &CcxSubEntryMessage) {
256255
}
257256

258257

259-
260258
pub fn ccxr_sub_entries_cleanup(entries: &mut CcxSubEntries) {
261259
entries.messages.clear();
262260
}
@@ -272,16 +270,16 @@ pub fn ccxr_share_start(stream_name: &str) -> CcxShareStatus {
272270
debug!(msg_type = DebugMessageFlag::SHARE; "[share] ccx_share_start: starting service\n");
273271
let mut ctx = CCX_SHARE_CTX.lock().unwrap();
274272
ctx.nn_sock = Some(Socket::new(Protocol::Pub).unwrap());
275-
if (ctx.nn_sock.is_none()) {
273+
if ctx.nn_sock.is_none() {
276274
debug!(msg_type = DebugMessageFlag::SHARE; "[share] ccx_share_start: can't nn_socket()\n");
277275
return CcxShareStatus::Fail;
278276
}
279-
/// TODO translating this line
280-
/// if (!ccx_options.sharing_url)
281-
/// {
282-
/// ccx_options.sharing_url = "tcp://*:3269";
283-
/// }
284-
/// dbg_print(CCX_DMT_SHARE, "[share] ccx_share_start: url=%s\n", ccx_options.sharing_url);
277+
// TODO translating this line
278+
// if (!ccx_options.sharing_url)
279+
// {
280+
// ccx_options.sharing_url = "tcp://*:3269";
281+
// }
282+
// dbg_print(CCX_DMT_SHARE, "[share] ccx_share_start: url=%s\n", ccx_options.sharing_url);
285283
let sharing_url = "tcp://*:3269"; // Default URL if none is provided
286284
debug!(msg_type = DebugMessageFlag::SHARE; "[share] ccx_share_start: url={}", sharing_url);
287285
let binder = match ctx.nn_sock.as_mut().unwrap().bind(sharing_url) {
@@ -371,7 +369,8 @@ pub fn _ccxr_share_send(msg: &CcxSubEntryMessage) -> CcxShareStatus {
371369
let len = ccxr_sub_entry_message_get_packed_size(msg);
372370
let mut buf = Vec::with_capacity(len);
373371
debug!(msg_type = DebugMessageFlag::SHARE; "[share] _ccx_share_send: packing");
374-
ccxr_sub_entry_message_pack(msg, &mut buf);
372+
#[allow(unused)]
373+
let _ = ccxr_sub_entry_message_pack(msg, &mut buf);
375374
debug!(msg_type = DebugMessageFlag::SHARE; "[share] _ccx_share_send: sending");
376375
let mut ctx = CCX_SHARE_CTX.lock().unwrap();
377376
if let Some(sock) = ctx.nn_sock.as_mut() {
@@ -409,8 +408,7 @@ pub fn ccxr_share_stream_done(stream_name: &str) -> CcxShareStatus {
409408
end_time: 0,
410409
lines: Vec::new(),
411410
};
412-
413-
411+
#[allow(unused)]
414412
let mut ctx = CCX_SHARE_CTX.lock().unwrap();
415413

416414
if _ccxr_share_send(&msg) != CcxShareStatus::Ok {
@@ -428,7 +426,7 @@ pub fn ccxr_share_sub_to_entries(sub: &CcSubtitle, entries: &mut CcxSubEntries)
428426

429427
debug!(msg_type = DebugMessageFlag::SHARE; "[share] _ccx_share_sub_to_entries");
430428

431-
if sub.type_ == subtype_CC_608 {
429+
if sub.type_ == SUBTYPE_CC_608 {
432430
debug!(msg_type = DebugMessageFlag::SHARE; "[share] CC_608");
433431

434432
let data_ptr = sub.data as *const Eia608Screen;
@@ -489,13 +487,13 @@ pub fn ccxr_share_sub_to_entries(sub: &CcSubtitle, entries: &mut CcxSubEntries)
489487
}
490488
} else {
491489
match sub.type_ {
492-
subtype_CC_BITMAP => {
490+
SUBTYPE_CC_BITMAP => {
493491
debug!(msg_type = DebugMessageFlag::SHARE; "[share] CC_BITMAP. Skipping");
494492
}
495-
subtype_CC_RAW => {
493+
SUBTYPE_CC_RAW => {
496494
debug!(msg_type = DebugMessageFlag::SHARE; "[share] CC_RAW. Skipping");
497495
}
498-
subtype_CC_TEXT => {
496+
SUBTYPE_CC_TEXT => {
499497
debug!(msg_type = DebugMessageFlag::SHARE; "[share] CC_TEXT. Skipping");
500498
}
501499
_ => {

src/rust/lib_ccxr/src/share/tests.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
mod test {
2-
use libc::c_char;
3-
use crate::share::share::*;
4-
use crate::share::ccxr_sub_entry_message::*;
5-
use std::sync::Once;
6-
use crate::util::log::{set_logger, CCExtractorLogger, DebugMessageFlag, DebugMessageMask, OutputTarget};
7-
1+
#![allow(unused_imports)]
2+
#![allow(unused)]
3+
use libc::c_char;
4+
use crate::share::share::*;
5+
use crate::share::ccxr_sub_entry_message::*;
6+
use std::sync::Once;
7+
use crate::util::log::{set_logger, CCExtractorLogger, DebugMessageFlag, DebugMessageMask, OutputTarget};
88

9+
mod test {
910
use super::*;
1011

1112
static INIT: Once = Once::new();
@@ -114,7 +115,6 @@ mod test {
114115
unsafe {
115116
ccxr_sub_entries_print(&*(&entries as *const CcxSubEntries));
116117
}
117-
118118
}
119119
#[test]
120120
fn test_ccxr_share_stop() {
@@ -148,11 +148,6 @@ mod test {
148148
assert!(matches!(status, CcxShareStatus::Ok | CcxShareStatus::Fail));
149149
}
150150

151-
#[test]
152-
fn test_ccxr_share_stream_done() {
153-
let status = ccxr_share_stream_done("test_stream");
154-
assert_eq!(status, CcxShareStatus::Ok);
155-
}
156151
#[test]
157152
fn test_ccxr_share_send_c() {
158153
initialize_logger();
@@ -202,10 +197,10 @@ mod test {
202197
screen.my_field = 42;
203198

204199
let sub = CcSubtitle {
205-
data: &screen as *const _ as *mut ::std::os::raw::c_void,
200+
data: &screen as *const _ as *mut std::os::raw::c_void,
206201
datatype: 1,
207202
nb_data: 1,
208-
type_: subtype_CC_608,
203+
type_: SUBTYPE_CC_608,
209204
enc_type: 1,
210205
start_time: 0,
211206
end_time: 0,
@@ -241,10 +236,10 @@ mod test {
241236
screen.end_time = 2000;
242237

243238
let sub = CcSubtitle {
244-
data: &screen as *const _ as *mut ::std::os::raw::c_void,
239+
data: &screen as *const _ as *mut std::os::raw::c_void,
245240
datatype: 1,
246241
nb_data: 1,
247-
type_: subtype_CC_608,
242+
type_: SUBTYPE_CC_608,
248243
enc_type: 1,
249244
start_time: 0,
250245
end_time: 0,

src/rust/src/libccxr_exports/share.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::ffi::CStr;
2-
use lib_ccxr::share::share::*;
31
use lib_ccxr::share::ccxr_sub_entry_message::*;
4-
use lib_ccxr::util::log::{debug, info, DebugMessageFlag};
2+
use lib_ccxr::share::share::*;
3+
use lib_ccxr::util::log::{debug, DebugMessageFlag};
4+
use std::ffi::CStr;
55
/// C-compatible function to clean up a `CcxSubEntryMessage`.
66
#[no_mangle]
77
pub extern "C" fn ccxr_sub_entry_msg_cleanup_c(msg: *mut CcxSubEntryMessage) {

0 commit comments

Comments
 (0)