From a5f8c9ba191d137e2a6e26b2f7344de90922bed4 Mon Sep 17 00:00:00 2001 From: Lee Fordyce Date: Tue, 7 May 2024 10:32:19 -0600 Subject: [PATCH] feat: expose packaging status upon failure (#25) --- include/packager/live_packager_export.h | 51 ++++++++++++-------- packager/live_packager_export.cc | 64 ++++++++++++++----------- 2 files changed, 67 insertions(+), 48 deletions(-) diff --git a/include/packager/live_packager_export.h b/include/packager/live_packager_export.h index 277507ca09..7f94f228ee 100644 --- a/include/packager/live_packager_export.h +++ b/include/packager/live_packager_export.h @@ -94,30 +94,39 @@ size_t livepackager_buf_size(LivePackagerBuffer_t buf); typedef struct LivePackager_instance_s* LivePackager_t; +typedef struct LivePackagerStatus_s { + /// In the event of an error this field will not be NULL and contain error + /// message with status code. Clients will need to free this memory in the + /// event that error_message is not NULL. + const char* error_message; + bool ok; +} LivePackagerStatus_t; + 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..df9e3a34d7 100644 --- a/packager/live_packager_export.cc +++ b/packager/live_packager_export.cc @@ -1,5 +1,6 @@ #include #include +#include #include @@ -70,49 +71,58 @@ 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); + return LivePackagerStatus_s{ + status.ok() ? nullptr : strdup(status.ToString().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); + + return LivePackagerStatus_s{ + status.ok() ? nullptr : strdup(status.ToString().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); + if (!status.ok()) { + return LivePackagerStatus_s{strdup(status.ToString().c_str()), status.ok()}; } dest->inner->AppendData(out.InitSegmentData(), out.InitSegmentSize()); - return true; + return LivePackagerStatus_s{nullptr, 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); + if (!status.ok()) { + return LivePackagerStatus_s{strdup(status.ToString().c_str()), status.ok()}; } dest->inner->AppendData(out.SegmentData(), out.SegmentSize()); - return true; -} \ No newline at end of file + return LivePackagerStatus_s{nullptr, status.ok()}; +}