From 3594ee497fa5a1ed94dafcd9cbea28d82f580a08 Mon Sep 17 00:00:00 2001 From: "lee.fordyce" Date: Wed, 1 May 2024 15:51:54 -0600 Subject: [PATCH] feat: expose packaging status upon failure --- include/packager/live_packager_export.h | 48 +++++++------- packager/live_packager_export.cc | 83 +++++++++++++++++-------- 2 files changed, 83 insertions(+), 48 deletions(-) diff --git a/include/packager/live_packager_export.h b/include/packager/live_packager_export.h index 277507ca09..8473badce5 100644 --- a/include/packager/live_packager_export.h +++ b/include/packager/live_packager_export.h @@ -94,30 +94,36 @@ size_t livepackager_buf_size(LivePackagerBuffer_t buf); typedef struct LivePackager_instance_s* LivePackager_t; +typedef struct LivePackagerStatus_s* LivePackagerStatus_t; +void live_packager_status_free(LivePackagerStatus_t self); + +const char* status_get_error(LivePackagerStatus_t self); + LivePackager_t livepackager_new(LivePackagerConfig_t cfg); void livepackager_free(LivePackager_t lp); -bool livepackager_package_init(LivePackager_t lp, - const uint8_t* init, - size_t init_len, - LivePackagerBuffer_t dest); - -bool livepackager_package(LivePackager_t lp, - const uint8_t* init, - size_t init_len, - const uint8_t* media, - size_t media_len, - LivePackagerBuffer_t dest); - -bool livepackager_package_timedtext_init(LivePackager_t lp, - const uint8_t* seg, - size_t seg_len, - LivePackagerBuffer_t dest); - -bool livepackager_package_timedtext(LivePackager_t lp, - const uint8_t* seg, - size_t seg_len, - LivePackagerBuffer_t dest); +LivePackagerStatus_t livepackager_package_init(LivePackager_t lp, + const uint8_t* init, + size_t init_len, + LivePackagerBuffer_t dest); + +LivePackagerStatus_t livepackager_package(LivePackager_t lp, + const uint8_t* init, + size_t init_len, + const uint8_t* media, + size_t media_len, + LivePackagerBuffer_t dest); + +LivePackagerStatus_t livepackager_package_timedtext_init( + LivePackager_t lp, + const uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest); + +LivePackagerStatus_t livepackager_package_timedtext(LivePackager_t lp, + const uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest); #ifdef __cplusplus } diff --git a/packager/live_packager_export.cc b/packager/live_packager_export.cc index 355668584f..ca4421413a 100644 --- a/packager/live_packager_export.cc +++ b/packager/live_packager_export.cc @@ -7,6 +7,11 @@ struct LivePackager_instance_s { std::unique_ptr inner; }; +struct LivePackagerStatus_s { + const char* status_message; + bool ok; +}; + LivePackager_t livepackager_new(LivePackagerConfig_t cfg) { shaka::LiveConfig converted{ .format = shaka::LiveConfig::OutputFormat(cfg.format), @@ -49,6 +54,14 @@ void livepackager_free(LivePackager_t lp) { delete lp; } +void live_packager_status_free(LivePackagerStatus_t self) { + delete self; +} + +const char* status_get_error(LivePackagerStatus_t self) { + return self->status_message; +} + struct LivePackager_buffer_s { std::unique_ptr inner; }; @@ -70,49 +83,65 @@ size_t livepackager_buf_size(LivePackagerBuffer_t buf) { return buf->inner->Size(); } -bool livepackager_package_init(LivePackager_t lp, - const uint8_t* init, - size_t init_len, - LivePackagerBuffer_t dest) { +LivePackagerStatus_t livepackager_package_init(LivePackager_t lp, + const uint8_t* init, + size_t init_len, + LivePackagerBuffer_t dest) { shaka::SegmentData input(init, init_len); - return lp->inner->PackageInit(input, *dest->inner).ok(); + shaka::Status status = lp->inner->PackageInit(input, *dest->inner); + std::string status_message = status.ToString(); + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; } -bool livepackager_package(LivePackager_t lp, - const uint8_t* init, - size_t init_len, - const uint8_t* media, - size_t media_len, - LivePackagerBuffer_t dest) { +LivePackagerStatus_t livepackager_package(LivePackager_t lp, + const uint8_t* init, + size_t init_len, + const 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(); + shaka::Status status = + lp->inner->Package(input_init, input_media, *dest->inner); + std::string status_message = status.ToString(); + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; } -bool livepackager_package_timedtext_init(LivePackager_t lp, - const uint8_t* seg, - size_t seg_len, - LivePackagerBuffer_t dest) { +LivePackagerStatus_t livepackager_package_timedtext_init( + LivePackager_t lp, + const uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest) { shaka::SegmentData input_seg(seg, seg_len); shaka::FullSegmentBuffer out; - if (!lp->inner->PackageTimedText(input_seg, out).ok()) { - return false; + shaka::Status status = lp->inner->PackageTimedText(input_seg, out); + std::string status_message = status.ToString(); + if (!status.ok()) { + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; } dest->inner->AppendData(out.InitSegmentData(), out.InitSegmentSize()); - return true; + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; } -bool livepackager_package_timedtext(LivePackager_t lp, - const uint8_t* seg, - size_t seg_len, - LivePackagerBuffer_t dest) { +LivePackagerStatus_t livepackager_package_timedtext(LivePackager_t lp, + const uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest) { shaka::SegmentData input_seg(seg, seg_len); shaka::FullSegmentBuffer out; - if (!lp->inner->PackageTimedText(input_seg, out).ok()) { - return false; + shaka::Status status = lp->inner->PackageTimedText(input_seg, out); + std::string status_message = status.ToString(); + if (!status.ok()) { + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; } dest->inner->AppendData(out.SegmentData(), out.SegmentSize()); - return true; -} \ No newline at end of file + return new (std::nothrow) + LivePackagerStatus_s{status_message.c_str(), status.ok()}; +}