Skip to content

Commit 77d4ac0

Browse files
committed
Add command line flags and helper functions for MPD and Packager configurations
1 parent 0179c83 commit 77d4ac0

File tree

4 files changed

+420
-0
lines changed

4 files changed

+420
-0
lines changed

pkg/mpd_flags.go

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package packlit
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
var (
9+
_ ShakaParser = (*OutputMediaInfoFlag)(nil)
10+
_ ShakaParser = (*MpdOutputFlag)(nil)
11+
_ ShakaParser = (*BaseUrlsFlag)(nil)
12+
_ ShakaParser = (*MinBufferTimeFlag)(nil)
13+
_ ShakaParser = (*MinimumUpdatePeriodFlag)(nil)
14+
_ ShakaParser = (*SuggestedPresentationDelayFlag)(nil)
15+
_ ShakaParser = (*UtCTimingsFlag)(nil)
16+
_ ShakaParser = (*GenerateDashIfIopCompliantMpdFlag)(nil)
17+
_ ShakaParser = (*AllowApproximateSegmentTimelineFlag)(nil)
18+
_ ShakaParser = (*AllowCodecSwitchingFlag)(nil)
19+
_ ShakaParser = (*IncludeMsprProForPlayReadyFlag)(nil)
20+
_ ShakaParser = (*DashForceSegmentListFlag)(nil)
21+
_ ShakaParser = (*LowLatencyDashModeFlag)(nil)
22+
)
23+
24+
// OutputMediaInfoFlag represents the flag to output media information.
25+
type OutputMediaInfoFlag struct{}
26+
27+
// Parse returns the string representation of OutputMediaInfo for use in the command line flags.
28+
func (o OutputMediaInfoFlag) Parse() string {
29+
return "--output_media_info"
30+
}
31+
32+
// Validate checks if the OutputMediaInfoFlag value is valid.
33+
func (o OutputMediaInfoFlag) Validate() error {
34+
// No specific validation logic for this boolean flag.
35+
return nil
36+
}
37+
38+
// BaseUrlsFlag represents the comma-separated BaseURLs for the MPD.
39+
type BaseUrlsFlag []string
40+
41+
// Parse returns the string representation of BaseUrls for use in the command line flags.
42+
func (b BaseUrlsFlag) Parse() string {
43+
return fmt.Sprintf("--base_urls=%s", strings.Join(b, ","))
44+
}
45+
46+
// Validate checks if the BaseUrls value is valid.
47+
func (b BaseUrlsFlag) Validate() error {
48+
return nil
49+
}
50+
51+
// MinBufferTimeFlag represents the minimum buffer time for MPD.
52+
type MinBufferTimeFlag float32
53+
54+
// Parse returns the string representation of MinBufferTime for use in the command line flags.
55+
func (m MinBufferTimeFlag) Parse() string {
56+
return fmt.Sprintf("--min_buffer_time=%v", m)
57+
}
58+
59+
// Validate checks if the MinBufferTime value is valid.
60+
func (m MinBufferTimeFlag) Validate() error {
61+
return nil
62+
}
63+
64+
// MinimumUpdatePeriodFlag represents the minimum update period for the MPD.
65+
type MinimumUpdatePeriodFlag float32
66+
67+
// Parse returns the string representation of MinimumUpdatePeriod for use in the command line flags.
68+
func (m MinimumUpdatePeriodFlag) Parse() string {
69+
return fmt.Sprintf("--minimum_update_period=%v", m)
70+
}
71+
72+
// Validate checks if the MinimumUpdatePeriod value is valid.
73+
func (m MinimumUpdatePeriodFlag) Validate() error {
74+
return nil
75+
}
76+
77+
// SuggestedPresentationDelayFlag represents the suggested presentation delay for the MPD.
78+
type SuggestedPresentationDelayFlag float32
79+
80+
// Parse returns the string representation of SuggestedPresentationDelay for use in the command line flags.
81+
func (s SuggestedPresentationDelayFlag) Parse() string {
82+
return fmt.Sprintf("--suggested_presentation_delay=%v", s)
83+
}
84+
85+
// Validate checks if the SuggestedPresentationDelay value is valid.
86+
func (s SuggestedPresentationDelayFlag) Validate() error {
87+
// Placeholder validation logic. It could be any required check.
88+
return nil
89+
}
90+
91+
// UtCTimingsFlag represents the UTC Timing for the MPD.
92+
type UtCTimingsFlag []string
93+
94+
// Parse returns the string representation of UtCTimings for use in the command line flags.
95+
func (u UtCTimingsFlag) Parse() string {
96+
return fmt.Sprintf("--utc_timings=%s", strings.Join(u, ","))
97+
}
98+
99+
// Validate checks if the UtCTimings value is valid.
100+
func (u UtCTimingsFlag) Validate() error {
101+
// You can add specific validation for the UTC Timing here.
102+
return nil
103+
}
104+
105+
// GenerateDashIfIopCompliantMpdFlag represents the flag to generate DASH-IF IOP compliant MPD.
106+
type GenerateDashIfIopCompliantMpdFlag struct{}
107+
108+
// Parse returns the string representation of GenerateDashIfIopCompliantMpd for use in the command line flags.
109+
func (g GenerateDashIfIopCompliantMpdFlag) Parse() string {
110+
return "--generate_dash_if_iop_compliant_mpd"
111+
}
112+
113+
// Validate checks if the GenerateDashIfIopCompliantMpdFlag value is valid.
114+
func (g GenerateDashIfIopCompliantMpdFlag) Validate() error {
115+
// No specific validation logic for this boolean flag.
116+
return nil
117+
}
118+
119+
// AllowApproximateSegmentTimelineFlag represents the flag to allow approximate segment timeline for live profiles.
120+
type AllowApproximateSegmentTimelineFlag struct{}
121+
122+
// Parse returns the string representation of AllowApproximateSegmentTimeline for use in the command line flags.
123+
func (a AllowApproximateSegmentTimelineFlag) Parse() string {
124+
return "--allow_approximate_segment_timeline"
125+
}
126+
127+
// Validate checks if the AllowApproximateSegmentTimelineFlag value is valid.
128+
func (a AllowApproximateSegmentTimelineFlag) Validate() error {
129+
// No specific validation logic for this boolean flag.
130+
return nil
131+
}
132+
133+
// AllowCodecSwitchingFlag represents the flag to allow adaptive switching between different codecs.
134+
type AllowCodecSwitchingFlag struct{}
135+
136+
// Parse returns the string representation of AllowCodecSwitching for use in the command line flags.
137+
func (a AllowCodecSwitchingFlag) Parse() string {
138+
return "--allow_codec_switching"
139+
}
140+
141+
// Validate checks if the AllowCodecSwitchingFlag value is valid.
142+
func (a AllowCodecSwitchingFlag) Validate() error {
143+
// No specific validation logic for this boolean flag.
144+
return nil
145+
}
146+
147+
// IncludeMsprProForPlayReadyFlag represents the flag to include mspr:pro for PlayReady content protection.
148+
type IncludeMsprProForPlayReadyFlag struct{}
149+
150+
// Parse returns the string representation of IncludeMsprProForPlayReady for use in the command line flags.
151+
func (i IncludeMsprProForPlayReadyFlag) Parse() string {
152+
return "--include_mspr_pro_for_playready"
153+
}
154+
155+
// Validate checks if the IncludeMsprProForPlayReadyFlag value is valid.
156+
func (i IncludeMsprProForPlayReadyFlag) Validate() error {
157+
// No specific validation logic for this boolean flag.
158+
return nil
159+
}
160+
161+
// DashForceSegmentListFlag represents the flag to force SegmentList in DASH MPD.
162+
type DashForceSegmentListFlag struct{}
163+
164+
// Parse returns the string representation of DashForceSegmentList for use in the command line flags.
165+
func (d DashForceSegmentListFlag) Parse() string {
166+
return "--dash_force_segment_list"
167+
}
168+
169+
// Validate checks if the DashForceSegmentListFlag value is valid.
170+
func (d DashForceSegmentListFlag) Validate() error {
171+
// No specific validation logic for this boolean flag.
172+
return nil
173+
}
174+
175+
// LowLatencyDashModeFlag represents the flag to enable low latency DASH mode.
176+
type LowLatencyDashModeFlag bool
177+
178+
// Parse returns the string representation of LowLatencyDashMode for use in the command line flags.
179+
func (l LowLatencyDashModeFlag) Parse() string {
180+
return fmt.Sprintf("--low_latency_dash_mode=%v", l)
181+
}
182+
183+
// Validate checks if the LowLatencyDashModeFlag value is valid.
184+
func (l LowLatencyDashModeFlag) Validate() error {
185+
// No specific validation logic for this boolean flag.
186+
return nil
187+
}

pkg/mpd_flags_helpers.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package packlit
2+
3+
// WithOutputMediaInfoFlag Adds flag '--output_media_info'
4+
func WithOutputMediaInfoFlag() ShakaFlagFn {
5+
return func(so *ShakaFlags) {
6+
so.Add(OutputMediaInfoFlag{})
7+
}
8+
}
9+
10+
// WithBaseUrlsFlag Adds flag '--base_urls <url1,url2,...>'
11+
func WithBaseUrlsFlag(values []string) ShakaFlagFn {
12+
return func(so *ShakaFlags) {
13+
so.Add(BaseUrlsFlag(values))
14+
}
15+
}
16+
17+
// WithMinBufferTimeFlag Adds flag '--min_buffer_time <duration>'
18+
func WithMinBufferTimeFlag(val float32) ShakaFlagFn {
19+
return func(so *ShakaFlags) {
20+
so.Add(MinBufferTimeFlag(val))
21+
}
22+
}
23+
24+
// WithMinimumUpdatePeriodFlag Adds flag '--minimum_update_period <duration>'
25+
func WithMinimumUpdatePeriodFlag(val float32) ShakaFlagFn {
26+
return func(so *ShakaFlags) {
27+
so.Add(MinimumUpdatePeriodFlag(val))
28+
}
29+
}
30+
31+
// WithSuggestedPresentationDelayFlag Adds flag '--suggested_presentation_delay <duration>'
32+
func WithSuggestedPresentationDelayFlag(val float32) ShakaFlagFn {
33+
return func(so *ShakaFlags) {
34+
so.Add(SuggestedPresentationDelayFlag(val))
35+
}
36+
}
37+
38+
// WithUtCTimingsFlag Adds flag '--utc_timings <timing>'
39+
func WithUtCTimingsFlag(val []string) ShakaFlagFn {
40+
return func(so *ShakaFlags) {
41+
so.Add(UtCTimingsFlag(val))
42+
}
43+
}
44+
45+
// WithGenerateDashIfIopCompliantMpdFlag Adds flag '--generate_dash_if_iop_compliant_mpd'
46+
func WithGenerateDashIfIopCompliantMpdFlag() ShakaFlagFn {
47+
return func(so *ShakaFlags) {
48+
so.Add(GenerateDashIfIopCompliantMpdFlag{})
49+
}
50+
}
51+
52+
// WithAllowApproximateSegmentTimelineFlag Adds flag '--allow_approximate_segment_timeline'
53+
func WithAllowApproximateSegmentTimelineFlag() ShakaFlagFn {
54+
return func(so *ShakaFlags) {
55+
so.Add(AllowApproximateSegmentTimelineFlag{})
56+
}
57+
}
58+
59+
// WithAllowCodecSwitchingFlag Adds flag '--allow_codec_switching'
60+
func WithAllowCodecSwitchingFlag() ShakaFlagFn {
61+
return func(so *ShakaFlags) {
62+
so.Add(AllowCodecSwitchingFlag{})
63+
}
64+
}
65+
66+
// WithIncludeMsprProForPlayReadyFlag Adds flag '--include_mspr_pro_for_playready'
67+
func WithIncludeMsprProForPlayReadyFlag() ShakaFlagFn {
68+
return func(so *ShakaFlags) {
69+
so.Add(IncludeMsprProForPlayReadyFlag{})
70+
}
71+
}
72+
73+
// WithDashForceSegmentListFlag Adds flag '--dash_force_segment_list'
74+
func WithDashForceSegmentListFlag() ShakaFlagFn {
75+
return func(so *ShakaFlags) {
76+
so.Add(DashForceSegmentListFlag{})
77+
}
78+
}
79+
80+
// WithLowLatencyDashModeFlag Adds flag '--low_latency_dash_mode=boolean'
81+
func WithLowLatencyDashModeFlag(val bool) ShakaFlagFn {
82+
return func(so *ShakaFlags) {
83+
so.Add(LowLatencyDashModeFlag(val))
84+
}
85+
}

pkg/packager_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 "fmt"
4+
5+
var (
6+
_ ShakaParser = (*LicensesFlag)(nil)
7+
_ ShakaParser = (*QuietFlag)(nil)
8+
_ ShakaParser = (*UseFakeClockForMuxerFlag)(nil)
9+
_ ShakaParser = (*TestPackagerVersionFlag)(nil)
10+
_ ShakaParser = (*SingleThreadedFlag)(nil)
11+
_ ShakaParser = (*VModuleFlag)(nil)
12+
_ ShakaParser = (*VersionFlag)(nil)
13+
)
14+
15+
// LicensesFlag represents the flag for dumping licenses information.
16+
type LicensesFlag struct{}
17+
18+
func (g LicensesFlag) Parse() string {
19+
return "--licenses"
20+
}
21+
22+
func (g LicensesFlag) Validate() error {
23+
return nil
24+
}
25+
26+
// QuietFlag represents the flag for suppressing LOG(INFO) output.
27+
type QuietFlag struct{}
28+
29+
func (g QuietFlag) Parse() string {
30+
return "--quiet"
31+
}
32+
33+
func (g QuietFlag) Validate() error {
34+
return nil
35+
}
36+
37+
// UseFakeClockForMuxerFlag represents the flag for using a fake clock for muxing.
38+
type UseFakeClockForMuxerFlag struct{}
39+
40+
func (g UseFakeClockForMuxerFlag) Parse() string {
41+
return "--use_fake_clock_for_muxer"
42+
}
43+
44+
func (g UseFakeClockForMuxerFlag) Validate() error {
45+
return nil
46+
}
47+
48+
// TestPackagerVersionFlag represents the flag for specifying the packager version for testing.
49+
type TestPackagerVersionFlag struct{}
50+
51+
func (g TestPackagerVersionFlag) Parse() string {
52+
return "--test_packager_version"
53+
}
54+
55+
func (g TestPackagerVersionFlag) Validate() error {
56+
return nil
57+
}
58+
59+
// SingleThreadedFlag represents the flag for enabling single-threaded content generation.
60+
type SingleThreadedFlag struct{}
61+
62+
func (g SingleThreadedFlag) Parse() string {
63+
return "--single_threaded"
64+
}
65+
66+
func (g SingleThreadedFlag) Validate() error {
67+
return nil
68+
}
69+
70+
// VModuleFlag adds verbose logging through --v or --vmodule command line flags.
71+
// Equivalent to --vmodule=http_file=1
72+
type VModuleFlag string
73+
74+
func (v VModuleFlag) Parse() string {
75+
return fmt.Sprintf("--vmodule=%s", v)
76+
}
77+
78+
func (v VModuleFlag) Validate() error {
79+
return nil
80+
}
81+
82+
// VersionFlag adds --version for checking packager version
83+
type VersionFlag struct{}
84+
85+
func (v VersionFlag) Parse() string {
86+
return "--version"
87+
}
88+
89+
func (v VersionFlag) Validate() error {
90+
return nil
91+
}

0 commit comments

Comments
 (0)