Skip to content

Commit

Permalink
Separate implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Mar 26, 2024
1 parent 9ec8745 commit f029673
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 66 deletions.
1 change: 1 addition & 0 deletions packager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ set(libpackager_sources
app/single_thread_job_manager.h
packager.cc
live_packager.cc
live_packager_export.cc
../include/packager/packager.h
../include/packager/live_packager.h
../include/packager/live_packager_export.h
Expand Down
66 changes: 0 additions & 66 deletions packager/live_packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,69 +660,3 @@ Status GeneratePSSHData(const PSSHGeneratorInput& in, PSSHData* out) {
return Status::OK;
}
} // namespace shaka

struct LivePackager_instance_s {
std::unique_ptr<shaka::LivePackager> inner;
};

LivePackager_t livepackager_new(LivePackagerConfig_t cfg) {
shaka::LiveConfig converted{
.format = shaka::LiveConfig::OutputFormat(cfg.format),
.track_type = shaka::LiveConfig::TrackType(cfg.track_type),
.iv={},
.key={},
.key_id={},
.protection_scheme=shaka::LiveConfig::EncryptionScheme(cfg.protection_scheme),
.segment_number = cfg.segment_number,
.m2ts_offset_ms = cfg.m2ts_offset_ms,
.timed_text_decode_time = cfg.timed_text_decode_time,
};

if (cfg.protection_scheme != ENCRYPTION_SCHEME_NONE) {
converted.iv=std::vector(cfg.iv, cfg.iv+cfg.iv_size);
converted.key=std::vector(cfg.key, cfg.key+KEY_SIZE);
converted.key_id=std::vector(cfg.key_id, cfg.key_id+KEY_ID_SIZE);
}

return new LivePackager_instance_s{std::make_unique<shaka::LivePackager>(converted)};
}

void livepackager_free(LivePackager_t lp) {
delete lp;
}

struct LivePackager_buffer_s {
std::unique_ptr<shaka::SegmentBuffer> inner;
};

LivePackagerBuffer_t livepackager_buf_new() {
return new LivePackager_buffer_s{std::make_unique<shaka::SegmentBuffer>()};
}

void livepackager_buf_free(LivePackagerBuffer_t buf) {
delete buf;
}

const uint8_t* livepackager_buf_data(LivePackagerBuffer_t buf) {
return buf->inner->Data();
}

size_t livepackager_buf_size(LivePackagerBuffer_t buf) {
return buf->inner->Size();
}

bool livepackager_package_init(LivePackager_t lp, uint8_t* init, size_t init_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input(init, init_len);
return lp->inner->PackageInit(input, *dest->inner).ok();
}

bool livepackager_package(LivePackager_t lp, uint8_t* init, size_t init_len, uint8_t* media, size_t media_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input_init(init, init_len);
shaka::SegmentData input_media(media, media_len);
return lp->inner->Package(input_init, input_media, *dest->inner).ok();
}

bool livepackager_package_timedtext(LivePackager_t lp, uint8_t* seg, size_t seg_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input_seg(seg, seg_len);
return lp->inner->PackageTimedText(input_seg, *dest->inner).ok();
}
68 changes: 68 additions & 0 deletions packager/live_packager_export.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <packager/live_packager.h>
#include <packager/live_packager_export.h>

struct LivePackager_instance_s {
std::unique_ptr<shaka::LivePackager> inner;
};

LivePackager_t livepackager_new(LivePackagerConfig_t cfg) {
shaka::LiveConfig converted{
.format = shaka::LiveConfig::OutputFormat(cfg.format),
.track_type = shaka::LiveConfig::TrackType(cfg.track_type),
.iv={},
.key={},
.key_id={},
.protection_scheme=shaka::LiveConfig::EncryptionScheme(cfg.protection_scheme),
.segment_number = cfg.segment_number,
.m2ts_offset_ms = cfg.m2ts_offset_ms,
.timed_text_decode_time = cfg.timed_text_decode_time,
};

if (cfg.protection_scheme != ENCRYPTION_SCHEME_NONE) {
converted.iv=std::vector(cfg.iv, cfg.iv+cfg.iv_size);
converted.key=std::vector(cfg.key, cfg.key+KEY_SIZE);
converted.key_id=std::vector(cfg.key_id, cfg.key_id+KEY_ID_SIZE);
}

return new LivePackager_instance_s{std::make_unique<shaka::LivePackager>(converted)};
}

void livepackager_free(LivePackager_t lp) {
delete lp;
}

struct LivePackager_buffer_s {
std::unique_ptr<shaka::SegmentBuffer> inner;
};

LivePackagerBuffer_t livepackager_buf_new() {
return new LivePackager_buffer_s{std::make_unique<shaka::SegmentBuffer>()};
}

void livepackager_buf_free(LivePackagerBuffer_t buf) {
delete buf;
}

const uint8_t* livepackager_buf_data(LivePackagerBuffer_t buf) {
return buf->inner->Data();
}

size_t livepackager_buf_size(LivePackagerBuffer_t buf) {
return buf->inner->Size();
}

bool livepackager_package_init(LivePackager_t lp, uint8_t* init, size_t init_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input(init, init_len);
return lp->inner->PackageInit(input, *dest->inner).ok();
}

bool livepackager_package(LivePackager_t lp, uint8_t* init, size_t init_len, uint8_t* media, size_t media_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input_init(init, init_len);
shaka::SegmentData input_media(media, media_len);
return lp->inner->Package(input_init, input_media, *dest->inner).ok();
}

bool livepackager_package_timedtext(LivePackager_t lp, uint8_t* seg, size_t seg_len, LivePackagerBuffer_t dest) {
shaka::SegmentData input_seg(seg, seg_len);
return lp->inner->PackageTimedText(input_seg, *dest->inner).ok();
}

0 comments on commit f029673

Please sign in to comment.