Skip to content

Commit

Permalink
feat: expose packaging status upon failure (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
lfordyce authored May 7, 2024
1 parent 09b3ff6 commit a5f8c9b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 48 deletions.
51 changes: 30 additions & 21 deletions include/packager/live_packager_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
64 changes: 37 additions & 27 deletions packager/live_packager_export.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <packager/live_packager.h>
#include <packager/live_packager_export.h>
#include <cstring>

#include <memory>

Expand Down Expand Up @@ -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;
}
return LivePackagerStatus_s{nullptr, status.ok()};
}

0 comments on commit a5f8c9b

Please sign in to comment.