diff --git a/include/packager/live_packager_export.h b/include/packager/live_packager_export.h index a4deb59577..ee0ac92f18 100644 --- a/include/packager/live_packager_export.h +++ b/include/packager/live_packager_export.h @@ -6,33 +6,32 @@ #define PACKAGER_LIVE_PACKAGER_EXPORT_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include #include typedef enum OutputFormat { - OUTPUT_FORMAT_FMP4, - OUTPUT_FORMAT_TS, - OUTPUT_FORMAT_VTTMP4, - OUTPUT_FORMAT_TTMLMP4, - OUTPUT_FORMAT_TTML, + OUTPUT_FORMAT_FMP4, + OUTPUT_FORMAT_TS, + OUTPUT_FORMAT_VTTMP4, + OUTPUT_FORMAT_TTMLMP4, + OUTPUT_FORMAT_TTML, } OutputFormat_t; typedef enum TrackType { - TRACK_TYPE_AUDIO, - TRACK_TYPE_VIDEO, - TRACK_TYPE_TEXT, + TRACK_TYPE_AUDIO, + TRACK_TYPE_VIDEO, + TRACK_TYPE_TEXT, } TrackType_t; typedef enum EncryptionScheme { - ENCRYPTION_SCHEME_NONE, - ENCRYPTION_SCHEME_SAMPLE_AES, - ENCRYPTION_SCHEME_AES_128, - ENCRYPTION_SCHEME_CBCS, - ENCRYPTION_SCHEME_CENC, + ENCRYPTION_SCHEME_NONE, + ENCRYPTION_SCHEME_SAMPLE_AES, + ENCRYPTION_SCHEME_AES_128, + ENCRYPTION_SCHEME_CBCS, + ENCRYPTION_SCHEME_CENC, } EncryptionScheme_t; static const size_t kIvMaxSize = 16; @@ -40,33 +39,32 @@ static const size_t kKeySize = 16; static const size_t kKeyIdSize = 16; typedef struct LivePackagerConfig { - OutputFormat_t format; - TrackType_t track_type; + OutputFormat_t format; + TrackType_t track_type; - size_t iv_size; - uint8_t iv[kIvMaxSize]; - uint8_t key[kKeySize]; - uint8_t key_id[kKeyIdSize]; - EncryptionScheme_t protection_scheme; + size_t iv_size; + uint8_t iv[kIvMaxSize]; + uint8_t key[kKeySize]; + uint8_t key_id[kKeyIdSize]; + EncryptionScheme_t protection_scheme; /// User-specified segment number. /// For FMP4 output: /// It can be used to set the moof header sequence number if > 0. /// For M2TS output: /// It is be used to set the continuity counter. - uint32_t segment_number; + uint32_t segment_number; /// The offset to be applied to transport stream (e.g. MPEG2-TS, HLS packed /// audio) timestamps to compensate for possible negative timestamps in the /// input. - int32_t m2ts_offset_ms; + int32_t m2ts_offset_ms; /// Used for timed text packaging to set the fragment decode time when the /// output format is either VTT in MP4 or TTML in MP4. - int64_t timed_text_decode_time; + int64_t timed_text_decode_time; } LivePackagerConfig_t; - typedef struct LivePackager_buffer_s* LivePackagerBuffer_t; LivePackagerBuffer_t livepackager_buf_new(); @@ -75,19 +73,28 @@ void livepackager_buf_free(LivePackagerBuffer_t buf); const uint8_t* livepackager_buf_data(LivePackagerBuffer_t buf); size_t livepackager_buf_size(LivePackagerBuffer_t buf); - typedef struct LivePackager_instance_s* LivePackager_t; LivePackager_t livepackager_new(LivePackagerConfig_t cfg); void livepackager_free(LivePackager_t lp); -bool livepackager_package_init(LivePackager_t lp, uint8_t* init, size_t init_len, LivePackagerBuffer_t dest); -bool livepackager_package(LivePackager_t lp, uint8_t* init, size_t init_len, uint8_t* media, size_t media_len, LivePackagerBuffer_t dest); -bool livepackager_package_timedtext(LivePackager_t lp, uint8_t* seg, size_t seg_len, LivePackagerBuffer_t dest); +bool livepackager_package_init(LivePackager_t lp, + uint8_t* init, + size_t init_len, + LivePackagerBuffer_t dest); +bool livepackager_package(LivePackager_t lp, + uint8_t* init, + size_t init_len, + uint8_t* media, + size_t media_len, + LivePackagerBuffer_t dest); +bool livepackager_package_timedtext(LivePackager_t lp, + uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest); #ifdef __cplusplus } #endif - -#endif //PACKAGER_LIVE_PACKAGER_EXPORT_H +#endif // PACKAGER_LIVE_PACKAGER_EXPORT_H diff --git a/packager/live_packager.cc b/packager/live_packager.cc index d96d01dd0f..64d1889d9c 100644 --- a/packager/live_packager.cc +++ b/packager/live_packager.cc @@ -301,8 +301,8 @@ Status LivePackager::PackageInit(const Segment& init_segment, return reader.Read(buffer, size); }; - callback_params.write_func = [](const std::string& name, - const void* data, uint64_t size) { + callback_params.write_func = [](const std::string& name, const void* data, + uint64_t size) { // output.AppendData(reinterpret_cast(data), size); return size; }; @@ -367,14 +367,14 @@ 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) { + 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) { + // if (out.InitSegmentSize() == 0) { // out.SetInitSegment(reinterpret_cast(data), size); //} return size; @@ -414,8 +414,7 @@ Status LivePackager::Package(const Segment& init_segment, return packager.Run(); } -Status LivePackager::PackageTimedText(const Segment& in, - SegmentBuffer& out) { +Status LivePackager::PackageTimedText(const Segment& in, SegmentBuffer& out) { SegmentDataReader reader(in); shaka::BufferCallbackParams callback_params; callback_params.read_func = [&reader](const std::string& name, void* buffer, @@ -431,10 +430,10 @@ Status LivePackager::PackageTimedText(const Segment& in, shaka::BufferCallbackParams init_callback_params; init_callback_params.write_func = [](const std::string& name, - const void* data, uint64_t size) { - //if (out.InitSegmentSize() == 0) { - // out.SetInitSegment(reinterpret_cast(data), size); - //} + const void* data, uint64_t size) { + // if (out.InitSegmentSize() == 0) { + // out.SetInitSegment(reinterpret_cast(data), size); + // } return size; }; diff --git a/packager/live_packager_export.cc b/packager/live_packager_export.cc index 4de45d68bd..301bbeb2fe 100644 --- a/packager/live_packager_export.cc +++ b/packager/live_packager_export.cc @@ -7,24 +7,26 @@ struct LivePackager_instance_s { LivePackager_t livepackager_new(LivePackagerConfig_t cfg) { shaka::LiveConfig converted{ - .format = shaka::LiveConfig::OutputFormat(cfg.format), - .track_type = shaka::LiveConfig::TrackType(cfg.track_type), - .iv={}, - .key={}, - .key_id={}, - .protection_scheme=shaka::LiveConfig::EncryptionScheme(cfg.protection_scheme), - .segment_number = cfg.segment_number, - .m2ts_offset_ms = cfg.m2ts_offset_ms, - .timed_text_decode_time = cfg.timed_text_decode_time, + .format = shaka::LiveConfig::OutputFormat(cfg.format), + .track_type = shaka::LiveConfig::TrackType(cfg.track_type), + .iv = {}, + .key = {}, + .key_id = {}, + .protection_scheme = + shaka::LiveConfig::EncryptionScheme(cfg.protection_scheme), + .segment_number = cfg.segment_number, + .m2ts_offset_ms = cfg.m2ts_offset_ms, + .timed_text_decode_time = cfg.timed_text_decode_time, }; if (cfg.protection_scheme != ENCRYPTION_SCHEME_NONE) { - converted.iv=std::vector(cfg.iv, cfg.iv+cfg.iv_size); - converted.key=std::vector(cfg.key, cfg.key+KEY_SIZE); - converted.key_id=std::vector(cfg.key_id, cfg.key_id+KEY_ID_SIZE); + converted.iv = std::vector(cfg.iv, cfg.iv + cfg.iv_size); + converted.key = std::vector(cfg.key, cfg.key + kKeySize); + converted.key_id = std::vector(cfg.key_id, cfg.key_id + kKeyIdSize); } - return new LivePackager_instance_s{std::make_unique(converted)}; + return new LivePackager_instance_s{ + std::make_unique(converted)}; } void livepackager_free(LivePackager_t lp) { @@ -51,18 +53,29 @@ size_t livepackager_buf_size(LivePackagerBuffer_t buf) { return buf->inner->Size(); } -bool livepackager_package_init(LivePackager_t lp, uint8_t* init, size_t init_len, LivePackagerBuffer_t dest) { +bool livepackager_package_init(LivePackager_t lp, + 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, size_t init_len, uint8_t* media, size_t media_len, LivePackagerBuffer_t dest) { +bool livepackager_package(LivePackager_t lp, + uint8_t* init, + size_t init_len, + 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(); } -bool livepackager_package_timedtext(LivePackager_t lp, uint8_t* seg, size_t seg_len, LivePackagerBuffer_t dest) { +bool livepackager_package_timedtext(LivePackager_t lp, + uint8_t* seg, + size_t seg_len, + LivePackagerBuffer_t dest) { shaka::SegmentData input_seg(seg, seg_len); return lp->inner->PackageTimedText(input_seg, *dest->inner).ok(); } \ No newline at end of file diff --git a/packager/live_packager_test.cc b/packager/live_packager_test.cc index 592cce09de..e049348111 100644 --- a/packager/live_packager_test.cc +++ b/packager/live_packager_test.cc @@ -273,8 +273,7 @@ class MP4MediaParserTest { std::vector> samples_; }; -void CheckVideoInitSegment(const SegmentBuffer& buffer, - media::FourCC format) { +void CheckVideoInitSegment(const SegmentBuffer& buffer, media::FourCC format) { bool err(true); size_t bytes_to_read(buffer.Size()); const uint8_t* data(buffer.Data()); @@ -701,8 +700,7 @@ TEST_F(LivePackagerBaseTest, VerifyAes128WithDecryption) { ASSERT_FALSE(exp_segment_buffer.empty()); std::vector decrypted; - std::vector buffer(out.Data(), - out.Data() + out.Size()); + std::vector buffer(out.Data(), out.Data() + out.Size()); ASSERT_TRUE(decryptor.Crypt(buffer, &decrypted)); ASSERT_EQ(decrypted, exp_segment_buffer); @@ -1056,8 +1054,9 @@ TEST_P(TimedTextParameterizedTest, VerifyTimedText) { // TODO(sasha): must be checked separately when PackageTimedTextInit is // added. - //if (i == 0) { - // CheckTextInitSegment(out, GetParam().handler_type, GetParam().format); + // if (i == 0) { + // CheckTextInitSegment(out, GetParam().handler_type, + // GetParam().format); //} std::string expected_fname; @@ -1067,8 +1066,7 @@ TEST_P(TimedTextParameterizedTest, VerifyTimedText) { std::vector expected_buf(ReadTestDataFile(expected_fname)); ASSERT_FALSE(expected_buf.empty()); - std::vector actual_buf(out.Data(), - out.Data() + out.Size()); + std::vector actual_buf(out.Data(), out.Data() + out.Size()); ASSERT_EQ(expected_buf, actual_buf); } }