diff --git a/include/packager/live_packager.h b/include/packager/live_packager.h index 7b52ba6fe1..4f71cf1582 100644 --- a/include/packager/live_packager.h +++ b/include/packager/live_packager.h @@ -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); diff --git a/include/packager/live_packager_export.h b/include/packager/live_packager_export.h index 17e31dec25..bf238949a1 100644 --- a/include/packager/live_packager_export.h +++ b/include/packager/live_packager_export.h @@ -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); diff --git a/packager/live_packager.cc b/packager/live_packager.cc index 781a862144..e28f8b2d27 100644 --- a/packager/live_packager.cc +++ b/packager/live_packager.cc @@ -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_)); } @@ -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(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(data), size); @@ -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(data), size); - //} + // skip writing any init segment data return size; }; diff --git a/packager/live_packager_export.cc b/packager/live_packager_export.cc index a25da0acd9..a5fe5fb15a 100644 --- a/packager/live_packager_export.cc +++ b/packager/live_packager_export.cc @@ -57,7 +57,7 @@ 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); @@ -65,9 +65,9 @@ bool livepackager_package_init(LivePackager_t lp, } 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); @@ -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); @@ -85,13 +85,12 @@ bool livepackager_package_timedtext_init(LivePackager_t lp, return false; } - dest->inner = std::make_unique(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); @@ -100,7 +99,6 @@ bool livepackager_package_timedtext(LivePackager_t lp, return false; } - dest->inner = std::make_unique(out.SegmentData(), - out.SegmentSize()); + dest->inner->AppendData(out.SegmentData(), out.SegmentSize()); return true; } \ No newline at end of file