@@ -56,14 +56,14 @@ var (
5656
5757// Timecode represents timecode.
5858type Timecode struct {
59- preferDF bool
60- sep string
61- lastSep string
62- r * rate
63- HH uint64
64- MM uint64
65- SS uint64
66- FF uint64
59+ forceAsNDF bool
60+ sep string
61+ lastSep string
62+ r * rate
63+ HH uint64
64+ MM uint64
65+ SS uint64
66+ FF uint64
6767}
6868
6969// newNDFRate returns new NDF rate.
@@ -89,18 +89,22 @@ func newDFRate(num, den int32) (*rate, error) {
8989}
9090
9191// newRate returns new rate.
92- func newRate (num , den int32 , preferDF bool ) (* rate , error ) {
93- if preferDF {
94- r , err := newDFRate (num , den )
95- if err != nil {
96- if errors .Is (err , ErrUnsupportedFrameRate ) {
97- return newNDFRate (num , den )
98- }
99- return nil , err
92+ func newRate (num , den int32 , forceAsNDF bool ) (* rate , error ) {
93+ ndf , err := newNDFRate (num , den )
94+ if err != nil {
95+ return nil , err
96+ }
97+ if forceAsNDF {
98+ return ndf , err
99+ }
100+ df , err := newDFRate (num , den )
101+ if err != nil {
102+ if errors .Is (err , ErrUnsupportedFrameRate ) {
103+ return ndf , nil
100104 }
101- return r , nil
105+ return nil , err
102106 }
103- return newNDFRate ( num , den )
107+ return df , nil
104108}
105109
106110// IsSupportedFrameRate returns whether frame rate is supported.
@@ -111,7 +115,7 @@ func IsSupportedFrameRate(num, den int32) bool {
111115
112116// IsRepresentableFramesOptionParam represents IsRepresentableFrames option parameter.
113117type IsRepresentableFramesOptionParam struct {
114- PreferDF bool
118+ ForceAsNDF bool
115119}
116120
117121// IsRepresentableFramesOption represents IsRepresentableFrames option.
@@ -120,7 +124,7 @@ type IsRepresentableFramesOption func(*IsRepresentableFramesOptionParam)
120124// newIsRepresentableFramesOptionParam returns new IsRepresentableFramesOptionParam.
121125func newIsRepresentableFramesOptionParam () IsRepresentableFramesOptionParam {
122126 return IsRepresentableFramesOptionParam {
123- PreferDF : true , // if frame rate is DF or NDF, assume DF
127+ ForceAsNDF : true , // if frame rate is DF or NDF, assume NDF
124128 }
125129}
126130
@@ -136,7 +140,7 @@ func IsRepresentableFrames(frames uint64, num, den int32, opts ...IsRepresentabl
136140 p := newIsRepresentableFramesOptionParam ()
137141 p .applyIsRepresentableFramesOption (opts ... )
138142
139- r , err := newRate (num , den , p .PreferDF )
143+ r , err := newRate (num , den , p .ForceAsNDF )
140144 if err != nil {
141145 return false
142146 }
@@ -145,9 +149,9 @@ func IsRepresentableFrames(frames uint64, num, den int32, opts ...IsRepresentabl
145149
146150// TimecodeOptionParam represents timecode option parameter.
147151type TimecodeOptionParam struct {
148- PreferDF bool
149- Sep string
150- LastSep string
152+ ForceAsNDF bool
153+ Sep string
154+ LastSep string
151155}
152156
153157// TimecodeOption represents timecode option.
@@ -156,9 +160,9 @@ type TimecodeOption func(*TimecodeOptionParam)
156160// newTimecodeOptionParam returns new TimecodeOptionParam.
157161func newTimecodeOptionParam () TimecodeOptionParam {
158162 return TimecodeOptionParam {
159- PreferDF : true , // if frame rate is 29.97 or 59.94 , assume DF . otherwise, assume NDF
160- Sep : ":" ,
161- LastSep : ":" ,
163+ ForceAsNDF : false , // true, if frame rate is DF or NDF , assume NDF . otherwise, assume DF
164+ Sep : ":" ,
165+ LastSep : ":" ,
162166 }
163167}
164168
@@ -174,7 +178,7 @@ func NewTimecode(frames uint64, num, den int32, opts ...TimecodeOption) (*Timeco
174178 p := newTimecodeOptionParam ()
175179 p .applyTimecodeOption (opts ... )
176180
177- r , err := newRate (num , den , p .PreferDF )
181+ r , err := newRate (num , den , p .ForceAsNDF )
178182 if err != nil {
179183 return nil , err
180184 }
@@ -185,10 +189,10 @@ func NewTimecode(frames uint64, num, den int32, opts ...TimecodeOption) (*Timeco
185189 }
186190
187191 tc , err := Reset (& Timecode {
188- preferDF : p .PreferDF ,
189- sep : p .Sep ,
190- lastSep : lastSep ,
191- r : r ,
192+ forceAsNDF : p .ForceAsNDF ,
193+ sep : p .Sep ,
194+ lastSep : lastSep ,
195+ r : r ,
192196 }, frames )
193197 if err != nil {
194198 return nil , err
@@ -198,9 +202,9 @@ func NewTimecode(frames uint64, num, den int32, opts ...TimecodeOption) (*Timeco
198202
199203// TimecodeOptionParam represents timecode option parameter.
200204type ParseTimecodeOptionParam struct {
201- PreferDF bool
202- Sep string
203- LastSep string
205+ ForceAsNDF bool
206+ Sep string
207+ LastSep string
204208}
205209
206210// ParseTimecodeOption represents parse timecode option.
@@ -209,7 +213,7 @@ type ParseTimecodeOption func(*ParseTimecodeOptionParam)
209213// newParseTimecodeOptionParam returns new ParseTimecodeOptionParam.
210214func newParseTimecodeOptionParam () ParseTimecodeOptionParam {
211215 return ParseTimecodeOptionParam {
212- PreferDF : true , // if frame rate is 29.97 or 59.94, assume DF . otherwise, assume NDF
216+ ForceAsNDF : false , // if frame rate is 29.97 or 59.94, assume NDF . otherwise, assume DF
213217 }
214218}
215219
@@ -225,7 +229,7 @@ func ParseTimecode(s string, num, den int32, opts ...ParseTimecodeOption) (*Time
225229 p := newParseTimecodeOptionParam ()
226230 p .applyParseTimecodeOption (opts ... )
227231
228- r , err := newRate (num , den , p .PreferDF )
232+ r , err := newRate (num , den , p .ForceAsNDF )
229233 if err != nil {
230234 return nil , err
231235 }
@@ -252,14 +256,14 @@ func ParseTimecode(s string, num, den int32, opts ...ParseTimecodeOption) (*Time
252256 }
253257
254258 return & Timecode {
255- preferDF : p .PreferDF ,
256- sep : sep ,
257- lastSep : lastSep ,
258- r : r ,
259- HH : uint64 (hh ),
260- MM : uint64 (mm ),
261- SS : uint64 (ss ),
262- FF : uint64 (ff ),
259+ forceAsNDF : p .ForceAsNDF ,
260+ sep : sep ,
261+ lastSep : lastSep ,
262+ r : r ,
263+ HH : uint64 (hh ),
264+ MM : uint64 (mm ),
265+ SS : uint64 (ss ),
266+ FF : uint64 (ff ),
263267 }, nil
264268}
265269
0 commit comments