Skip to content

Commit c302d73

Browse files
committed
replaced nanomsg with nanomsg_sys
1 parent 888ffa4 commit c302d73

File tree

13 files changed

+1165
-4
lines changed

13 files changed

+1165
-4
lines changed

src/lib_ccx/ccx_share.c

+54-1
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,46 @@
88
#include "ccx_common_option.h"
99
#include "ccx_decoders_structs.h"
1010
#include "lib_ccx.h"
11-
1211
#ifdef ENABLE_SHARING
1312

1413
#include <nanomsg/nn.h>
1514
#include <nanomsg/pubsub.h>
1615

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

1931
void ccx_sub_entry_msg_cleanup(CcxSubEntryMessage *msg)
2032
{
33+
#ifndef DISABLE_RUST
34+
return ccxr_sub_entry_msg_cleanup_c(msg);
35+
#else
36+
2137
for (int i = 0; i < msg->n_lines; i++)
2238
{
2339
free(msg->lines[i]);
2440
}
2541
free(msg->lines);
2642
free(msg->stream_name);
43+
#endif
2744
}
2845

2946
void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
3047
{
48+
#ifndef DISABLE_RUST
49+
return ccxr_sub_entry_msg_print_c(msg);
50+
#else
3151
if (!msg)
3252
{
3353
dbg_print(CCX_DMT_SHARE, "[share] print(!msg)\n");
@@ -55,6 +75,7 @@ void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
5575
}
5676
dbg_print(CCX_DMT_SHARE, "[share] %s\n", msg->lines[i]);
5777
}
78+
#endif
5879
}
5980

6081
void ccx_sub_entries_init(ccx_sub_entries *entries)
@@ -65,26 +86,37 @@ void ccx_sub_entries_init(ccx_sub_entries *entries)
6586

6687
void ccx_sub_entries_cleanup(ccx_sub_entries *entries)
6788
{
89+
#ifndef DISABLE_RUST
90+
return ccxr_sub_entries_cleanup_c(entries);
91+
#else
6892
for (int i = 0; i < entries->count; i++)
6993
{
7094
ccx_sub_entry_msg_cleanup(entries->messages + i);
7195
}
7296
free(entries->messages);
7397
entries->messages = NULL;
7498
entries->count = 0;
99+
#endif
75100
}
76101

77102
void ccx_sub_entries_print(ccx_sub_entries *entries)
78103
{
104+
#ifndef DISABLE_RUST
105+
return ccxr_sub_entries_print_c(entries);
106+
#else
79107
dbg_print(CCX_DMT_SHARE, "[share] ccx_sub_entries_print (%u entries)\n", entries->count);
80108
for (int i = 0; i < entries->count; i++)
81109
{
82110
ccx_sub_entry_msg_print(entries->messages + i);
83111
}
112+
#endif
84113
}
85114

86115
ccx_share_status ccx_share_start(const char *stream_name) // TODO add stream
87116
{
117+
#ifndef DISABLE_RUST
118+
return ccxr_share_start_c(stream_name);
119+
#else
88120
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_start: starting service\n");
89121
// TODO for multiple files we have to move creation to ccx_share_init
90122
ccx_share_ctx.nn_sock = nn_socket(AF_SP, NN_PUB);
@@ -121,18 +153,26 @@ ccx_share_status ccx_share_start(const char *stream_name) // TODO add stream
121153

122154
sleep(1); // We have to sleep a while, because it takes some time for subscribers to subscribe
123155
return CCX_SHARE_OK;
156+
#endif
124157
}
125158

126159
ccx_share_status ccx_share_stop()
127160
{
161+
#ifndef DISABLE_RUST
162+
return ccxr_share_stop_c();
163+
#else
128164
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_stop: stopping service\n");
129165
nn_shutdown(ccx_share_ctx.nn_sock, ccx_share_ctx.nn_binder);
130166
free(ccx_share_ctx.stream_name);
131167
return CCX_SHARE_OK;
168+
#endif
132169
}
133170

134171
ccx_share_status ccx_share_send(struct cc_subtitle *sub)
135172
{
173+
#ifndef DISABLE_RUST
174+
return ccxr_share_send_c(sub);
175+
#else
136176
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_send: sending\n");
137177
ccx_sub_entries entries;
138178
ccx_sub_entries_init(&entries);
@@ -154,10 +194,14 @@ ccx_share_status ccx_share_send(struct cc_subtitle *sub)
154194
ccx_sub_entries_cleanup(&entries);
155195

156196
return CCX_SHARE_OK;
197+
#endif
157198
}
158199

159200
ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
160201
{
202+
#ifndef DISABLE_RUST
203+
return _ccxr_share_send_c(msg);
204+
#else
161205
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send\n");
162206
size_t len = ccx_sub_entry_message__get_packed_size(msg);
163207
void *buf = malloc(len);
@@ -175,10 +219,14 @@ ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
175219
free(buf);
176220
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send: sent\n");
177221
return CCX_SHARE_OK;
222+
#endif
178223
}
179224

180225
ccx_share_status ccx_share_stream_done(char *stream_name)
181226
{
227+
#ifndef DISABLE_RUST
228+
return ccxr_share_stream_done_c(stream_name);
229+
#else
182230
CcxSubEntryMessage msg = CCX_SUB_ENTRY_MESSAGE__INIT;
183231
msg.eos = 1;
184232
msg.stream_name = strdup(stream_name);
@@ -197,10 +245,14 @@ ccx_share_status ccx_share_stream_done(char *stream_name)
197245
ccx_sub_entry_msg_cleanup(&msg);
198246

199247
return CCX_SHARE_OK;
248+
#endif
200249
}
201250

202251
ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entries *entries)
203252
{
253+
#ifndef DISABLE_RUST
254+
return _ccxr_share_sub_to_entries_c(sub, entries);
255+
#else
204256
dbg_print(CCX_DMT_SHARE, "\n[share] _ccx_share_sub_to_entry\n");
205257
if (sub->type == CC_608)
206258
{
@@ -295,6 +347,7 @@ ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entr
295347
dbg_print(CCX_DMT_SHARE, "[share] done\n");
296348

297349
return CCX_SHARE_OK;
350+
#endif
298351
}
299352

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

src/lib_ccx/ccx_share.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//
22
// Created by Oleg Kisselef (olegkisselef at gmail dot com) on 6/21/15
33
//
4-
54
#ifndef CCEXTRACTOR_CCX_SHARE_H
65
#define CCEXTRACTOR_CCX_SHARE_H
76

src/rust/Cargo.lock

+78-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cfg-if = "1.0.0"
2828
num-integer = "0.1.46"
2929
lib_ccxr = { path = "lib_ccxr" }
3030
url = "2.5.4"
31+
libc = "0.2.172"
3132

3233
[build-dependencies]
3334
bindgen = "0.64.0"

0 commit comments

Comments
 (0)