Skip to content

[FEAT] Add share module in lib_ccxr #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt update && sudo apt-get install libgpac-dev
run: sudo apt update && sudo apt-get install libgpac-dev libnanomsg-dev
- uses: actions/checkout@v4
- name: run autogen
run: ./autogen.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: brew install pkg-config autoconf automake libtool gpac
run: brew install pkg-config autoconf automake libtool gpac nanomsg
- name: run autogen
run: ./autogen.sh
working-directory: ./mac
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,4 @@ version of CCExtractor.
- Added video information (as extracted from sequence header).
- Some code clean-up.
- FF sanity check enabled by default.
- Added Share Module to lib_ccxr
2 changes: 1 addition & 1 deletion linux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ ccextractor_LDADD += $(LEPT_LIB)
endif

if WITH_RUST
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a -lnanomsg
else
ccextractor_CFLAGS += -DDISABLE_RUST
ccextractor_CPPFLAGS += -DDISABLE_RUST
Expand Down
2 changes: 1 addition & 1 deletion mac/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ endif

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

ccextractor_LDFLAGS = $(shell pkg-config --libs gpac)
ccextractor_LDFLAGS = $(shell pkg-config --libs gpac nanomsg)
GPAC_CPPFLAGS = $(shell pkg-config --cflags gpac)

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/
Expand Down
55 changes: 54 additions & 1 deletion src/lib_ccx/ccx_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,46 @@
#include "ccx_common_option.h"
#include "ccx_decoders_structs.h"
#include "lib_ccx.h"

#ifdef ENABLE_SHARING

#include <nanomsg/nn.h>
#include <nanomsg/pubsub.h>

ccx_share_service_ctx ccx_share_ctx;
#ifndef DISABLE_RUST
extern void ccxr_sub_entry_msg_cleanup_c(CcxSubEntryMessage *msg);
extern void ccxr_sub_entry_msg_print_c(const CcxSubEntryMessage *msg);
extern void ccxr_sub_entries_cleanup_c(ccx_sub_entries *entries);
extern void ccxr_sub_entries_print_c(const ccx_sub_entries *entries);
extern ccx_share_status ccxr_share_start_c(const char *stream_name);
extern ccx_share_status ccxr_share_stop_c(void);
extern ccx_share_status _ccxr_share_send_c(const CcxSubEntryMessage *msg);
extern ccx_share_status ccxr_share_send_c(const struct cc_subtitle *sub);
extern ccx_share_status ccxr_share_stream_done_c(const char *stream_name);
extern ccx_share_status _ccxr_share_sub_to_entries_c(const struct cc_subtitle *sub, ccx_sub_entries *entries);

#endif

void ccx_sub_entry_msg_cleanup(CcxSubEntryMessage *msg)
{
#ifndef DISABLE_RUST
return ccxr_sub_entry_msg_cleanup_c(msg);
#else

for (int i = 0; i < msg->n_lines; i++)
{
free(msg->lines[i]);
}
free(msg->lines);
free(msg->stream_name);
#endif
}

void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
{
#ifndef DISABLE_RUST
return ccxr_sub_entry_msg_print_c(msg);
#else
if (!msg)
{
dbg_print(CCX_DMT_SHARE, "[share] print(!msg)\n");
Expand Down Expand Up @@ -55,6 +75,7 @@ void ccx_sub_entry_msg_print(CcxSubEntryMessage *msg)
}
dbg_print(CCX_DMT_SHARE, "[share] %s\n", msg->lines[i]);
}
#endif
}

void ccx_sub_entries_init(ccx_sub_entries *entries)
Expand All @@ -65,26 +86,37 @@ void ccx_sub_entries_init(ccx_sub_entries *entries)

void ccx_sub_entries_cleanup(ccx_sub_entries *entries)
{
#ifndef DISABLE_RUST
return ccxr_sub_entries_cleanup_c(entries);
#else
for (int i = 0; i < entries->count; i++)
{
ccx_sub_entry_msg_cleanup(entries->messages + i);
}
free(entries->messages);
entries->messages = NULL;
entries->count = 0;
#endif
}

void ccx_sub_entries_print(ccx_sub_entries *entries)
{
#ifndef DISABLE_RUST
return ccxr_sub_entries_print_c(entries);
#else
dbg_print(CCX_DMT_SHARE, "[share] ccx_sub_entries_print (%u entries)\n", entries->count);
for (int i = 0; i < entries->count; i++)
{
ccx_sub_entry_msg_print(entries->messages + i);
}
#endif
}

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

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

ccx_share_status ccx_share_stop()
{
#ifndef DISABLE_RUST
return ccxr_share_stop_c();
#else
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_stop: stopping service\n");
nn_shutdown(ccx_share_ctx.nn_sock, ccx_share_ctx.nn_binder);
free(ccx_share_ctx.stream_name);
return CCX_SHARE_OK;
#endif
}

ccx_share_status ccx_share_send(struct cc_subtitle *sub)
{
#ifndef DISABLE_RUST
return ccxr_share_send_c(sub);
#else
dbg_print(CCX_DMT_SHARE, "[share] ccx_share_send: sending\n");
ccx_sub_entries entries;
ccx_sub_entries_init(&entries);
Expand All @@ -154,10 +194,14 @@ ccx_share_status ccx_share_send(struct cc_subtitle *sub)
ccx_sub_entries_cleanup(&entries);

return CCX_SHARE_OK;
#endif
}

ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
{
#ifndef DISABLE_RUST
return _ccxr_share_send_c(msg);
#else
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send\n");
size_t len = ccx_sub_entry_message__get_packed_size(msg);
void *buf = malloc(len);
Expand All @@ -175,10 +219,14 @@ ccx_share_status _ccx_share_send(CcxSubEntryMessage *msg)
free(buf);
dbg_print(CCX_DMT_SHARE, "[share] _ccx_share_send: sent\n");
return CCX_SHARE_OK;
#endif
}

ccx_share_status ccx_share_stream_done(char *stream_name)
{
#ifndef DISABLE_RUST
return ccxr_share_stream_done_c(stream_name);
#else
CcxSubEntryMessage msg = CCX_SUB_ENTRY_MESSAGE__INIT;
msg.eos = 1;
msg.stream_name = strdup(stream_name);
Expand All @@ -197,10 +245,14 @@ ccx_share_status ccx_share_stream_done(char *stream_name)
ccx_sub_entry_msg_cleanup(&msg);

return CCX_SHARE_OK;
#endif
}

ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entries *entries)
{
#ifndef DISABLE_RUST
return _ccxr_share_sub_to_entries_c(sub, entries);
#else
dbg_print(CCX_DMT_SHARE, "\n[share] _ccx_share_sub_to_entry\n");
if (sub->type == CC_608)
{
Expand Down Expand Up @@ -295,6 +347,7 @@ ccx_share_status _ccx_share_sub_to_entries(struct cc_subtitle *sub, ccx_sub_entr
dbg_print(CCX_DMT_SHARE, "[share] done\n");

return CCX_SHARE_OK;
#endif
}

ccx_share_status ccx_share_launch_translator(char *langs, char *auth)
Expand Down
1 change: 0 additions & 1 deletion src/lib_ccx/ccx_share.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//
// Created by Oleg Kisselef (olegkisselef at gmail dot com) on 6/21/15
//

#ifndef CCEXTRACTOR_CCX_SHARE_H
#define CCEXTRACTOR_CCX_SHARE_H

Expand Down
76 changes: 75 additions & 1 deletion src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading