Skip to content

Commit 9d80576

Browse files
committed
feat: added share module
1 parent b08c5fa commit 9d80576

File tree

14 files changed

+1505
-14
lines changed

14 files changed

+1505
-14
lines changed

linux/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if [ "$WITHOUT_RUST" = true ]; then
9595
echo "Building without rust files..."
9696
BLD_FLAGS="$BLD_FLAGS -DDISABLE_RUST"
9797
else
98-
BLD_LINKER="$BLD_LINKER ./libccx_rust.a"
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/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 -lnanomsg `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors gpac`"
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/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)