Skip to content

Commit 038d3ea

Browse files
committed
feat: added share module
1 parent b08c5fa commit 038d3ea

23 files changed

+1525
-27
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

.github/workflows/build_mac.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: macos-latest
2727
steps:
2828
- name: Install dependencies
29-
run: brew install pkg-config autoconf automake libtool tesseract leptonica gpac
29+
run: brew install pkg-config autoconf automake libtool tesseract leptonica gpac nanomsg
3030
- uses: actions/checkout@v4
3131
- name: build
3232
run: ./build.command
@@ -47,7 +47,7 @@ jobs:
4747
steps:
4848
- uses: actions/checkout@v4
4949
- name: Install dependencies
50-
run: brew install pkg-config autoconf automake libtool gpac
50+
run: brew install pkg-config autoconf automake libtool gpac nanomsg
5151
- name: run autogen
5252
run: ./autogen.sh
5353
working-directory: ./mac

.github/workflows/build_windows.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- "**.h"
1616
- "windows/**"
1717
pull_request:
18-
types: [opened, synchronize, reopened]
18+
types: [ opened, synchronize, reopened ]
1919
paths:
2020
- ".github/workflows/build_windows.yml"
2121
- "**.c"
@@ -85,6 +85,8 @@ jobs:
8585
msbuild-architecture: x64
8686
- name: Install gpac
8787
run: choco install gpac --version 2.4.0
88+
- name: Install nanomsg
89+
run: choco install nanomsg
8890
- name: Setup vcpkg
8991
run: mkdir C:\vcpkg\.cache
9092
- name: Cache vcpkg

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ 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
98-
BLD_LINKER="$BLD_LINKER ./libccx_rust.a"
97+
else
98+
BLD_LINKER="$BLD_LINKER ./libccx_rust.a -lnanomsg"
9999
echo "Checking for cargo..."
100100
if ! [ -x "$(command -v cargo)" ]; then
101101
echo 'Error: cargo is not installed.' >&2

mac/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,14 @@ endif
244244

245245
ccextractor_CFLAGS = -std=gnu99 -Wno-write-strings -Wno-pointer-sign -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP
246246

247-
ccextractor_LDFLAGS = $(shell pkg-config --libs gpac)
247+
ccextractor_LDFLAGS = $(shell pkg-config --libs gpac nanomsg)
248248
GPAC_CPPFLAGS = $(shell pkg-config --cflags gpac)
249+
NANOMSG_CPPFLAGS = $(shell pkg-config --cflags nanomsg)
249250

250251
ccextractor_CPPFLAGS =-I../src/lib_ccx/ -I../src/thirdparty/libpng/ -I../src/thirdparty/zlib/ -I../src/lib_ccx/zvbi/ -I../src/thirdparty/lib_hash/ -I../src/thirdparty/protobuf-c/ -I../src/thirdparty -I../src/ -I../src/thirdparty/freetype/include/
251252
ccextractor_CPPFLAGS += $(GPAC_CPPFLAGS)
252253
ccextractor_CPPFLAGS += $(FFMPEG_CPPFLAGS)
254+
ccextractor_CPPFLAGS += $(NANOMSG_CPPFLAGS)
253255

254256
ccextractor_LDADD=-lm -lpthread -ldl
255257

@@ -307,7 +309,7 @@ ccextractor_LDADD += $(LEPT_LIB)
307309
endif
308310

309311
if WITH_RUST
310-
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
312+
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a -lnanomsg
311313
else
312314
ccextractor_CFLAGS += -DDISABLE_RUST
313315
ccextractor_CPPFLAGS += -DDISABLE_RUST

mac/build.command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SRC_FREETYPE="../src/thirdparty/freetype/autofit/autofit.c \
5252
../src/thirdparty/freetype/type42/type42.c \
5353
../src/thirdparty/freetype/winfonts/winfnt.c"
5454
BLD_SOURCES="../src/ccextractor.c $SRC_API $SRC_CCX $SRC_LIB_HASH $SRC_LIBPNG $SRC_PROTOBUF $SRC_UTF8 $SRC_ZLIB $SRC_ZVBI $SRC_FREETYPE"
55-
BLD_LINKER="-lm -liconv -lpthread -ldl `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors gpac`"
55+
BLD_LINKER="-lm -liconv -lpthread -ldl `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors gpac` `pkg-config --libs --silence-errors nanomsg`"
5656
[[ $1 = "OCR" ]] && BLD_LINKER="$BLD_LINKER `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors lept`"
5757

5858
./pre-build.sh

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ else ()
263263
endif (PKG_CONFIG_FOUND AND NOT WITHOUT_RUST)
264264

265265

266+
266267
target_link_libraries (ccextractor ${EXTRA_LIBS})
267268
target_include_directories (ccextractor PUBLIC ${EXTRA_INCLUDES})
268269

src/lib_ccx/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pkg_check_modules (GPAC REQUIRED gpac)
1616
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS})
1717
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
1818

19+
1920
if (WITH_FFMPEG)
2021
find_package(PkgConfig)
2122

src/lib_ccx/ccx_share.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,40 @@
1515
#include <nanomsg/pubsub.h>
1616

1717
ccx_share_service_ctx ccx_share_ctx;
18+
#ifndef DISABLE_RUST
19+
extern void ccxr_sub_entry_msg_cleanup_c(CcxSubEntryMessage *msg);
20+
extern void ccxr_sub_entry_msg_print_c(const CcxSubEntryMessage *msg);
21+
extern void ccxr_sub_entries_cleanup_c(ccx_sub_entries *entries);
22+
extern void ccxr_sub_entries_print_c(const ccx_sub_entries *entries);
23+
extern ccx_share_status ccxr_share_start_c(const char *stream_name);
24+
extern ccx_share_status ccxr_share_stop_c(void);
25+
extern ccx_share_status _ccxr_share_send_c(const CcxSubEntryMessage *msg);
26+
extern ccx_share_status ccxr_share_send_c(const struct cc_subtitle *sub);
27+
extern ccx_share_status ccxr_share_stream_done_c(const char *stream_name);
28+
extern ccx_share_status _ccxr_share_sub_to_entries_c(const struct cc_subtitle *sub, ccx_sub_entries *entries);
29+
30+
#endif
1831

1932
void ccx_sub_entry_msg_cleanup(CcxSubEntryMessage *msg)
2033
{
34+
#ifndef DISABLE_RUST
35+
return ccxr_sub_entry_msg_cleanup_c(msg);
36+
#else
37+
2138
for (int i = 0; i < msg->n_lines; i++)
2239
{
2340
free(msg->lines[i]);
2441
}
2542
free(msg->lines);
2643
free(msg->stream_name);
44+
#endif
2745
}
2846

2947
void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
3048
{
49+
#ifndef DISABLE_RUST
50+
return ccxr_sub_entry_msg_print_c(msg);
51+
#else
3152
if (!msg)
3253
{
3354
dbg_print(CCX_DMT_SHARE, "[share] print(!msg)\n");
@@ -55,6 +76,7 @@ void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
5576
}
5677
dbg_print(CCX_DMT_SHARE, "[share] %s\n", msg->lines[i]);
5778
}
79+
#endif
5880
}
5981

6082
void ccx_sub_entries_init(ccx_sub_entries *entries)
@@ -65,26 +87,37 @@ void ccx_sub_entries_init(ccx_sub_entries *entries)
6587

6688
void ccx_sub_entries_cleanup(ccx_sub_entries *entries)
6789
{
90+
#ifndef DISABLE_RUST
91+
return ccxr_sub_entries_cleanup_c(entries);
92+
#else
6893
for (int i = 0; i < entries->count; i++)
6994
{
7095
ccx_sub_entry_msg_cleanup(entries->messages + i);
7196
}
7297
free(entries->messages);
7398
entries->messages = NULL;
7499
entries->count = 0;
100+
#endif
75101
}
76102

77103
void ccx_sub_entries_print(ccx_sub_entries *entries)
78104
{
105+
#ifndef DISABLE_RUST
106+
return ccxr_sub_entries_print_c(entries);
107+
#else
79108
dbg_print(CCX_DMT_SHARE, "[share] ccx_sub_entries_print (%u entries)\n", entries->count);
80109
for (int i = 0; i < entries->count; i++)
81110
{
82111
ccx_sub_entry_msg_print(entries->messages + i);
83112
}
113+
#endif
84114
}
85115

86116
ccx_share_status ccx_share_start(const char *stream_name) // TODO add stream
87117
{
118+
#ifndef DISABLE_RUST
119+
return ccxr_share_start_c(stream_name);
120+
#else
88121
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_start: starting service\n");
89122
// TODO for multiple files we have to move creation to ccx_share_init
90123
ccx_share_ctx.nn_sock = nn_socket(AF_SP, NN_PUB);
@@ -121,18 +154,26 @@ ccx_share_status ccx_share_start(const char *stream_name) // TODO add stream
121154

122155
sleep(1); // We have to sleep a while, because it takes some time for subscribers to subscribe
123156
return CCX_SHARE_OK;
157+
#endif
124158
}
125159

126160
ccx_share_status ccx_share_stop()
127161
{
162+
#ifndef DISABLE_RUST
163+
return ccxr_share_stop_c();
164+
#else
128165
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_stop: stopping service\n");
129166
nn_shutdown(ccx_share_ctx.nn_sock, ccx_share_ctx.nn_binder);
130167
free(ccx_share_ctx.stream_name);
131168
return CCX_SHARE_OK;
169+
#endif
132170
}
133171

134172
ccx_share_status ccx_share_send(struct cc_subtitle *sub)
135173
{
174+
#ifndef DISABLE_RUST
175+
return ccxr_share_send_c(sub);
176+
#else
136177
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_send: sending\n");
137178
ccx_sub_entries entries;
138179
ccx_sub_entries_init(&entries);
@@ -154,10 +195,14 @@ ccx_share_status ccx_share_send(struct cc_subtitle *sub)
154195
ccx_sub_entries_cleanup(&entries);
155196

156197
return CCX_SHARE_OK;
198+
#endif
157199
}
158200

159201
ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
160202
{
203+
#ifndef DISABLE_RUST
204+
return _ccxr_share_send_c(msg);
205+
#else
161206
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send\n");
162207
size_t len = ccx_sub_entry_message__get_packed_size(msg);
163208
void *buf = malloc(len);
@@ -175,10 +220,14 @@ ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
175220
free(buf);
176221
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send: sent\n");
177222
return CCX_SHARE_OK;
223+
#endif
178224
}
179225

180226
ccx_share_status ccx_share_stream_done(char *stream_name)
181227
{
228+
#ifndef DISABLE_RUST
229+
return ccxr_share_stream_done_c(stream_name);
230+
#else
182231
CcxSubEntryMessage msg = CCX_SUB_ENTRY_MESSAGE__INIT;
183232
msg.eos = 1;
184233
msg.stream_name = strdup(stream_name);
@@ -197,10 +246,14 @@ ccx_share_status ccx_share_stream_done(char *stream_name)
197246
ccx_sub_entry_msg_cleanup(&msg);
198247

199248
return CCX_SHARE_OK;
249+
#endif
200250
}
201251

202252
ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entries *entries)
203253
{
254+
#ifndef DISABLE_RUST
255+
return _ccxr_share_sub_to_entries_c(sub, entries);
256+
#else
204257
dbg_print(CCX_DMT_SHARE, "\n[share] _ccx_share_sub_to_entry\n");
205258
if (sub->type == CC_608)
206259
{
@@ -295,6 +348,7 @@ ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entr
295348
dbg_print(CCX_DMT_SHARE, "[share] done\n");
296349

297350
return CCX_SHARE_OK;
351+
#endif
298352
}
299353

300354
ccx_share_status ccx_share_launch_translator(char *langs, char *auth)

0 commit comments

Comments
 (0)