Skip to content

Commit 1834b72

Browse files
authored
Add all Shaka Packager flags with helpers (#3)
* Add Widevine encryption and decryption flags with associated helper functions * Add raw key encryption and decryption flags with helper functions * Add PlayReady encryption and server URL flags with helper functions * Add ProtectionSystemsFlag and helper function for command line integration * Add flags for time shift buffer depth, preserved segments, and default languages with helper functions * Add CryptByteBlock, ProtectionScheme, SkipByteBlock, VP9SubsampleEncryption, and PlayReadyExtraHeaderData flags with helper functions * Add AdCuesFlag and WithAdCuesFlag for command line integration * Add HLS flags and helper functions for command line integration * Add command line flags and helper functions for ClearLead, SegmentDuration, SegmentSapAligned, FragmentDuration, FragmentSapAligned, GenerateSidxInMediaSegments, TempDir, Mp4IncludePsshInStream, TransportStreamTimestampOffsetMs, DefaultTextZeroBiasMs, StartSegmentNumber, and UseDoviSupplementalCodecs * Add command line flags and helper functions for MPD and Packager configurations * Remove unused WithDumpStreamInfoFlag function from packager_flags_helpers.go
1 parent e2f07c0 commit 1834b72

23 files changed

+1700
-0
lines changed

pkg/ad_cue_generator_flags.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package packlit
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
var (
8+
_ ShakaParser = (*AdCuesFlag)(nil)
9+
)
10+
11+
// AdCuesFlag represents the list of cuepoint markers.
12+
type AdCuesFlag string
13+
14+
// Parse returns the string representation of AdCues for use in the command line flags.
15+
func (a AdCuesFlag) Parse() string {
16+
return fmt.Sprintf("--ad_cues=%s", a)
17+
}
18+
19+
// Validate checks if the value of AdCues is valid.
20+
// This flag accepts semicolon separated pairs, and components in the pair are separated by a comma.
21+
// The second component (duration) is optional. For example:
22+
// --ad_cues {start_time}[,{duration}][;{start_time}[,{duration}]]...
23+
// The start_time represents the start of the cue marker in seconds relative to the start of the program.
24+
func (a AdCuesFlag) Validate() error {
25+
// Split the input by semicolons to separate cuepoint markers.
26+
return nil
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package packlit
2+
3+
// WithAdCuesFlag Adds flag '--ad_cues <start_time[,duration]>[;<start_time[,duration]>]...'
4+
func WithAdCuesFlag(val string) ShakaFlagFn {
5+
return func(so *ShakaFlags) {
6+
so.Add(AdCuesFlag(val))
7+
}
8+
}

pkg/crypto_flags.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package packlit
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
var (
8+
_ ShakaParser = (*CryptByteBlockFlag)(nil)
9+
_ ShakaParser = (*ProtectionSchemeFlag)(nil)
10+
_ ShakaParser = (*SkipByteBlockFlag)(nil)
11+
_ ShakaParser = (*VP9SubsampleEncryptionFlag)(nil)
12+
_ ShakaParser = (*PlayReadyExtraHeaderDataFlag)(nil)
13+
)
14+
15+
// CryptByteBlockFlag represents the encrypted block count in a protection pattern.
16+
type CryptByteBlockFlag int
17+
18+
// Parse returns the string representation of CryptByteBlock for use in the command line flags.
19+
func (p CryptByteBlockFlag) Parse() string {
20+
return fmt.Sprintf("--crypt_byte_block=%d", p)
21+
}
22+
23+
// Validate checks if the value of CryptByteBlock is valid.
24+
// Specify the count of the encrypted blocks in the protection pattern,
25+
// where block is of size 16-bytes. There are three common
26+
// patterns (crypt_byte_block:skip_byte_block): 1:9 (default), 5:5, 10:0.
27+
// Apply to video streams with 'cbcs' and 'cens' protection schemes only;
28+
// ignored otherwise.
29+
func (p CryptByteBlockFlag) Validate() error {
30+
return nil
31+
}
32+
33+
// ProtectionSchemeFlag represents the protection scheme flag.
34+
type ProtectionSchemeFlag string
35+
36+
// Parse returns the string representation of ProtectionScheme for use in the command line flags.
37+
func (p ProtectionSchemeFlag) Parse() string {
38+
return fmt.Sprintf("--protection_scheme=%s", p)
39+
}
40+
41+
// Validate checks if the ProtectionScheme flag value is valid.
42+
// Specify a protection scheme, 'cenc' or 'cbc1' or pattern-based protection schemes 'cens' or 'cbcs'.
43+
func (p ProtectionSchemeFlag) Validate() error {
44+
return nil
45+
}
46+
47+
// SkipByteBlockFlag represents the number of unencrypted blocks in the protection pattern.
48+
type SkipByteBlockFlag int
49+
50+
// Parse returns the string representation of SkipByteBlock for use in the command line flags.
51+
func (s SkipByteBlockFlag) Parse() string {
52+
return fmt.Sprintf("--skip_byte_block=%v", s)
53+
}
54+
55+
// Validate checks if the value of SkipByteBlock is valid.
56+
// Specify the count of the unencrypted blocks in the protection pattern.
57+
// Apply to video streams with 'cbcs' and 'cens' protection schemes only;
58+
// ignored otherwise.
59+
func (s SkipByteBlockFlag) Validate() error {
60+
return nil
61+
}
62+
63+
// VP9SubsampleEncryptionFlag represents the flag to enable VP9 subsample encryption.
64+
type VP9SubsampleEncryptionFlag struct{}
65+
66+
// Parse returns the string representation of VP9SubsampleEncryption for use in the command line flags.
67+
func (v VP9SubsampleEncryptionFlag) Parse() string {
68+
return "--vp9_subsample_encryption"
69+
}
70+
71+
// Validate checks if the VP9SubsampleEncryption flag value is valid.
72+
// Enable VP9 subsample encryption.
73+
func (v VP9SubsampleEncryptionFlag) Validate() error {
74+
// No specific validation needed as the flag is of boolean type.
75+
return nil
76+
}
77+
78+
// PlayReadyExtraHeaderDataFlag represents the extra XML data for PlayReady headers.
79+
type PlayReadyExtraHeaderDataFlag string
80+
81+
// Parse returns the string representation of PlayReadyExtraHeaderData for use in the command line flags.
82+
func (p PlayReadyExtraHeaderDataFlag) Parse() string {
83+
return fmt.Sprintf("--playready_extra_header_data=%s", p)
84+
}
85+
86+
// Validate checks if the PlayReadyExtraHeaderData flag value is valid.
87+
// Extra XML data to add to PlayReady headers.
88+
func (p PlayReadyExtraHeaderDataFlag) Validate() error {
89+
// Check if the string is empty (valid) or if not, it must be valid XML.
90+
return nil
91+
}

pkg/crypto_flags_helpers.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package packlit
2+
3+
// WithCryptByteBlockFlag Adds flag '--crypt_byte_block <value>'
4+
func WithCryptByteBlockFlag(val int) ShakaFlagFn {
5+
return func(so *ShakaFlags) {
6+
so.Add(CryptByteBlockFlag(val))
7+
}
8+
}
9+
10+
// WithProtectionSchemeFlag Adds flag '--protection_scheme <cenc|cbc1|cens|cbcs>'
11+
func WithProtectionSchemeFlag(val string) ShakaFlagFn {
12+
return func(so *ShakaFlags) {
13+
so.Add(ProtectionSchemeFlag(val))
14+
}
15+
}
16+
17+
// WithSkipByteBlockFlag Adds flag '--skip_byte_block <value>'
18+
func WithSkipByteBlockFlag(val int) ShakaFlagFn {
19+
return func(so *ShakaFlags) {
20+
so.Add(SkipByteBlockFlag(val))
21+
}
22+
}
23+
24+
// WithVP9SubsampleEncryptionFlag Adds flag '--vp9_subsample_encryption'
25+
func WithVP9SubsampleEncryptionFlag() ShakaFlagFn {
26+
return func(so *ShakaFlags) {
27+
so.Add(VP9SubsampleEncryptionFlag{})
28+
}
29+
}
30+
31+
// WithPlayReadyExtraHeaderDataFlag Adds flag '--playready_extra_header_data <XML>'
32+
func WithPlayReadyExtraHeaderDataFlag(val string) ShakaFlagFn {
33+
return func(so *ShakaFlags) {
34+
so.Add(PlayReadyExtraHeaderDataFlag(val))
35+
}
36+
}

pkg/hls_flags.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package packlit
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
var (
8+
_ ShakaParser = (*HLSMasterPlaylistOutputFlag)(nil)
9+
_ ShakaParser = (*HLSBaseURLFlag)(nil)
10+
_ ShakaParser = (*HLSKeyURIFlag)(nil)
11+
_ ShakaParser = (*HLSPlaylistTypeFlag)(nil)
12+
_ ShakaParser = (*HLSMediaSequenceNumberFlag)(nil)
13+
_ ShakaParser = (*HLSStartTimeOffsetFlag)(nil)
14+
_ ShakaParser = (*HLSCreateSessionKeysFlag)(nil)
15+
)
16+
17+
// HLSMasterPlaylistOutputFlag represents the output path for the master playlist for HLS.
18+
type HLSMasterPlaylistOutputFlag string
19+
20+
// Parse returns the string representation of HLSMasterPlaylistOutput for use in the command line flags.
21+
func (h HLSMasterPlaylistOutputFlag) Parse() string {
22+
return fmt.Sprintf("--hls_master_playlist_output=%s", h)
23+
}
24+
25+
// Validate checks if the value of HLSMasterPlaylistOutput is valid.
26+
// This flag must be used to output HLS.
27+
func (h HLSMasterPlaylistOutputFlag) Validate() error {
28+
if len(h) == 0 {
29+
return fmt.Errorf("hls_master_playlist_output is required")
30+
}
31+
return nil
32+
}
33+
34+
// HLSBaseURLFlag represents the base URL for the Media Playlists and media files listed in the playlists.
35+
type HLSBaseURLFlag string
36+
37+
// Parse returns the string representation of HLSBaseURL for use in the command line flags.
38+
func (h HLSBaseURLFlag) Parse() string {
39+
return fmt.Sprintf("--hls_base_url=%s", h)
40+
}
41+
42+
// Validate checks if the value of HLSBaseURL is valid.
43+
// The base URL is the prefix for the media files.
44+
func (h HLSBaseURLFlag) Validate() error {
45+
if len(h) == 0 {
46+
return fmt.Errorf("hls_base_url is required")
47+
}
48+
return nil
49+
}
50+
51+
// HLSKeyURIFlag represents the key URI for the 'identity' and 'com.apple.streamingkeydelivery' key formats.
52+
type HLSKeyURIFlag string
53+
54+
// Parse returns the string representation of HLSKeyURI for use in the command line flags.
55+
func (h HLSKeyURIFlag) Parse() string {
56+
return fmt.Sprintf("--hls_key_uri=%s", h)
57+
}
58+
59+
// Validate checks if the value of HLSKeyURI is valid.
60+
// The key URI is required if the playlist is encrypted and uses the specified key formats.
61+
func (h HLSKeyURIFlag) Validate() error {
62+
if len(h) == 0 {
63+
return fmt.Errorf("hls_key_uri is required for encrypted playlists with 'identity' and 'com.apple.streamingkeydelivery' formats")
64+
}
65+
return nil
66+
}
67+
68+
// HLSPlaylistTypeFlag represents the type of the playlist: VOD, EVENT, or LIVE.
69+
type HLSPlaylistTypeFlag string
70+
71+
// Parse returns the string representation of HLSPlaylistType for use in the command line flags.
72+
func (h HLSPlaylistTypeFlag) Parse() string {
73+
return fmt.Sprintf("--hls_playlist_type=%s", h)
74+
}
75+
76+
// Validate checks if the value of HLSPlaylistType is valid.
77+
func (h HLSPlaylistTypeFlag) Validate() error {
78+
return nil
79+
}
80+
81+
// HLSMediaSequenceNumberFlag represents the initial EXT-X-MEDIA-SEQUENCE value.
82+
type HLSMediaSequenceNumberFlag int
83+
84+
// Parse returns the string representation of HLSMediaSequenceNumber for use in the command line flags.
85+
func (h HLSMediaSequenceNumberFlag) Parse() string {
86+
return fmt.Sprintf("--hls_media_sequence_number=%d", h)
87+
}
88+
89+
// Validate checks if the value of HLSMediaSequenceNumber is valid.
90+
func (h HLSMediaSequenceNumberFlag) Validate() error {
91+
return nil
92+
}
93+
94+
// HLSStartTimeOffsetFlag represents the floating-point number for EXT-X-START time offset.
95+
type HLSStartTimeOffsetFlag float32
96+
97+
// Parse returns the string representation of HLSStartTimeOffset for use in the command line flags.
98+
func (h HLSStartTimeOffsetFlag) Parse() string {
99+
return fmt.Sprintf("--hls_start_time_offset=%v", h)
100+
}
101+
102+
// Validate checks if the value of HLSStartTimeOffset is valid.
103+
func (h HLSStartTimeOffsetFlag) Validate() error {
104+
return nil
105+
}
106+
107+
// HLSCreateSessionKeysFlag represents the flag to enable creation of session keys for Offline HLS playback.
108+
type HLSCreateSessionKeysFlag struct{}
109+
110+
// Parse returns the string representation of HLSCreateSessionKeys for use in the command line flags.
111+
func (h HLSCreateSessionKeysFlag) Parse() string {
112+
return "--create_session_keys"
113+
}
114+
115+
// Validate checks if the value of HLSCreateSessionKeys is valid.
116+
func (h HLSCreateSessionKeysFlag) Validate() error {
117+
return nil // No specific validation logic for this flag
118+
}

pkg/hls_flags_helpers.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package packlit
2+
3+
// WithHLSMasterPlaylistOutputFlag Adds flag '--hls_master_playlist_output <path>'
4+
func WithHLSMasterPlaylistOutputFlag(val string) ShakaFlagFn {
5+
return func(so *ShakaFlags) {
6+
so.Add(HLSMasterPlaylistOutputFlag(val))
7+
}
8+
}
9+
10+
// WithHLSBaseURLFlag Adds flag '--hls_base_url <url>'
11+
func WithHLSBaseURLFlag(val string) ShakaFlagFn {
12+
return func(so *ShakaFlags) {
13+
so.Add(HLSBaseURLFlag(val))
14+
}
15+
}
16+
17+
// WithHLSKeyURIFlag Adds flag '--hls_key_uri <uri>'
18+
func WithHLSKeyURIFlag(val string) ShakaFlagFn {
19+
return func(so *ShakaFlags) {
20+
so.Add(HLSKeyURIFlag(val))
21+
}
22+
}
23+
24+
// WithHLSPlaylistTypeFlag Adds flag '--hls_playlist_type <VOD|EVENT|LIVE>'
25+
func WithHLSPlaylistTypeFlag(val HLSPlaylistTypeFlag) ShakaFlagFn {
26+
return func(so *ShakaFlags) {
27+
so.Add(val)
28+
}
29+
}
30+
31+
// WithHLSMediaSequenceNumberFlag Adds flag '--hls_media_sequence_number <number>'
32+
func WithHLSMediaSequenceNumberFlag(val int) ShakaFlagFn {
33+
return func(so *ShakaFlags) {
34+
so.Add(HLSMediaSequenceNumberFlag(val))
35+
}
36+
}
37+
38+
// WithHLSStartTimeOffsetFlag Adds flag '--hls_start_time_offset <offset>'
39+
func WithHLSStartTimeOffsetFlag(val float32) ShakaFlagFn {
40+
return func(so *ShakaFlags) {
41+
so.Add(HLSStartTimeOffsetFlag(val))
42+
}
43+
}
44+
45+
// WithHLSCreateSessionKeysFlag Adds flag '--create_session_keys'
46+
func WithHLSCreateSessionKeysFlag() ShakaFlagFn {
47+
return func(so *ShakaFlags) {
48+
so.Add(HLSCreateSessionKeysFlag{})
49+
}
50+
}

pkg/http_file_flags.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ package packlit
22

33
import "fmt"
44

5+
var (
6+
_ ShakaParser = (*UserAgentFlag)(nil)
7+
_ ShakaParser = (*CaFileFlag)(nil)
8+
_ ShakaParser = (*ClientCertFileFlag)(nil)
9+
_ ShakaParser = (*ClientCertPrivateKeyFileFlag)(nil)
10+
_ ShakaParser = (*ClientCertPrivateKeyPasswordFlag)(nil)
11+
_ ShakaParser = (*DisablePeerVerificationFlag)(nil)
12+
_ ShakaParser = (*IgnoreHttpOutputFailuresFlag)(nil)
13+
_ ShakaParser = (*IoCacheSizeFlag)(nil)
14+
)
15+
516
// UserAgentFlag represents the flag for setting a custom User-Agent string for HTTP requests.
617
type UserAgentFlag string
718

0 commit comments

Comments
 (0)