Skip to content

Commit

Permalink
Appease linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jedekar committed Mar 27, 2024
1 parent 0bc0a65 commit 80d7c56
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 66 deletions.
71 changes: 39 additions & 32 deletions include/packager/live_packager_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,65 @@
#define PACKAGER_LIVE_PACKAGER_EXPORT_H

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>

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;
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();
Expand All @@ -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
19 changes: 9 additions & 10 deletions packager/live_packager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint8_t*>(data), size);
return size;
};
Expand Down Expand Up @@ -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<const uint8_t*>(data), size);
//}
return size;
Expand Down Expand Up @@ -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,
Expand All @@ -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<const uint8_t*>(data), size);
//}
const void* data, uint64_t size) {
// if (out.InitSegmentSize() == 0) {
// out.SetInitSegment(reinterpret_cast<const uint8_t*>(data), size);
// }
return size;
};

Expand Down
45 changes: 29 additions & 16 deletions packager/live_packager_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<shaka::LivePackager>(converted)};
return new LivePackager_instance_s{
std::make_unique<shaka::LivePackager>(converted)};
}

void livepackager_free(LivePackager_t lp) {
Expand All @@ -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();
}
14 changes: 6 additions & 8 deletions packager/live_packager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ class MP4MediaParserTest {
std::vector<std::shared_ptr<media::MediaSample>> 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());
Expand Down Expand Up @@ -701,8 +700,7 @@ TEST_F(LivePackagerBaseTest, VerifyAes128WithDecryption) {
ASSERT_FALSE(exp_segment_buffer.empty());

std::vector<uint8_t> decrypted;
std::vector<uint8_t> buffer(out.Data(),
out.Data() + out.Size());
std::vector<uint8_t> buffer(out.Data(), out.Data() + out.Size());

ASSERT_TRUE(decryptor.Crypt(buffer, &decrypted));
ASSERT_EQ(decrypted, exp_segment_buffer);
Expand Down Expand Up @@ -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;
Expand All @@ -1067,8 +1066,7 @@ TEST_P(TimedTextParameterizedTest, VerifyTimedText) {
std::vector<uint8_t> expected_buf(ReadTestDataFile(expected_fname));
ASSERT_FALSE(expected_buf.empty());

std::vector<uint8_t> actual_buf(out.Data(),
out.Data() + out.Size());
std::vector<uint8_t> actual_buf(out.Data(), out.Data() + out.Size());
ASSERT_EQ(expected_buf, actual_buf);
}
}
Expand Down

0 comments on commit 80d7c56

Please sign in to comment.