Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Mar 28, 2024
1 parent aadf9be commit b277b87
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
1 change: 0 additions & 1 deletion include/packager/live_packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class SegmentData final : public Segment {
class SegmentBuffer final : public Segment {
public:
SegmentBuffer() = default;
SegmentBuffer(const uint8_t* data, size_t size);
~SegmentBuffer() = default;

void AppendData(const uint8_t* data, size_t size);
Expand Down
10 changes: 5 additions & 5 deletions include/packager/live_packager_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,24 @@ LivePackager_t livepackager_new(LivePackagerConfig_t cfg);
void livepackager_free(LivePackager_t lp);

bool livepackager_package_init(LivePackager_t lp,
uint8_t* init,
const uint8_t* init,
size_t init_len,
LivePackagerBuffer_t dest);

bool livepackager_package(LivePackager_t lp,
uint8_t* init,
const uint8_t* init,
size_t init_len,
uint8_t* media,
const uint8_t* media,
size_t media_len,
LivePackagerBuffer_t dest);

bool livepackager_package_timedtext_init(LivePackager_t lp,
uint8_t* seg,
const uint8_t* seg,
size_t seg_len,
LivePackagerBuffer_t dest);

bool livepackager_package_timedtext(LivePackager_t lp,
uint8_t* seg,
const uint8_t* seg,
size_t seg_len,
LivePackagerBuffer_t dest);

Expand Down
21 changes: 8 additions & 13 deletions packager/live_packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ size_t SegmentData::Size() const {
return size_;
}

SegmentBuffer::SegmentBuffer(const uint8_t* data, size_t size)
: buffer_(data, data + size) {}

void SegmentBuffer::AppendData(const uint8_t* data, size_t size) {
std::copy(data, data + size, std::back_inserter(buffer_));
}
Expand Down Expand Up @@ -306,13 +303,19 @@ Status LivePackager::PackageInit(const Segment& init_segment,

callback_params.write_func = [](const std::string& name, const void* data,
uint64_t size) {
// output.AppendData(reinterpret_cast<const uint8_t*>(data), size);
// skip writing any media segment data
return size;
};

shaka::BufferCallbackParams init_callback_params;
init_callback_params.write_func = [&output](const std::string& name,
const void* data, uint64_t size) {
// For live packaging it is observed that the init segment callback is
// invoked more than once. The initial callback does not contain the MEHD
// box data and furthermore does not contain fragment duration.
// If an MP4 file is created in real-time, such as used in live-streaming,
// it is not likely that the fragment_duration is known in advance and this
// box may be omitted.
if (output.Size() == 0) {
LOG(INFO) << "init segment callback, name: " << name << " size: " << size;
output.AppendData(reinterpret_cast<const uint8_t*>(data), size);
Expand Down Expand Up @@ -371,15 +374,7 @@ Status LivePackager::Package(const Segment& init_segment,
shaka::BufferCallbackParams init_callback_params;
init_callback_params.write_func = [](const std::string& name,
const void* data, uint64_t size) {
// For live packaging it is observed that the init segment callback is
// invoked more than once. The initial callback does not contain the MEHD
// box data and furthermore does not contain fragment duration.
// If an MP4 file is created in real-time, such as used in live-streaming,
// it is not likely that the fragment_duration is known in advance and this
// box may be omitted.
// if (out.InitSegmentSize() == 0) {
// out.SetInitSegment(reinterpret_cast<const uint8_t*>(data), size);
//}
// skip writing any init segment data
return size;
};

Expand Down
16 changes: 7 additions & 9 deletions packager/live_packager_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ size_t livepackager_buf_size(LivePackagerBuffer_t buf) {
}

bool livepackager_package_init(LivePackager_t lp,
uint8_t* init,
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();
}

bool livepackager_package(LivePackager_t lp,
uint8_t* init,
const uint8_t* init,
size_t init_len,
uint8_t* media,
const uint8_t* media,
size_t media_len,
LivePackagerBuffer_t dest) {
shaka::SegmentData input_init(init, init_len);
Expand All @@ -76,7 +76,7 @@ bool livepackager_package(LivePackager_t lp,
}

bool livepackager_package_timedtext_init(LivePackager_t lp,
uint8_t* seg,
const uint8_t* seg,
size_t seg_len,
LivePackagerBuffer_t dest) {
shaka::SegmentData input_seg(seg, seg_len);
Expand All @@ -85,13 +85,12 @@ bool livepackager_package_timedtext_init(LivePackager_t lp,
return false;
}

dest->inner = std::make_unique<shaka::SegmentBuffer>(out.InitSegmentData(),
out.InitSegmentSize());
dest->inner->AppendData(out.InitSegmentData(), out.InitSegmentSize());
return true;
}

bool livepackager_package_timedtext(LivePackager_t lp,
uint8_t* seg,
const uint8_t* seg,
size_t seg_len,
LivePackagerBuffer_t dest) {
shaka::SegmentData input_seg(seg, seg_len);
Expand All @@ -100,7 +99,6 @@ bool livepackager_package_timedtext(LivePackager_t lp,
return false;
}

dest->inner = std::make_unique<shaka::SegmentBuffer>(out.SegmentData(),
out.SegmentSize());
dest->inner->AppendData(out.SegmentData(), out.SegmentSize());
return true;
}

0 comments on commit b277b87

Please sign in to comment.