@@ -255,25 +255,41 @@ public struct HLSChannels: Equatable, FailableStringLiteralConvertible {
255
255
/// This parameter is an array of Special Usage Identifiers.
256
256
public let specialUsageIdentifiers : [ SpecialUsageIdentifier ]
257
257
258
- public enum SpecialUsageIdentifier : String {
258
+ public enum SpecialUsageIdentifier : RawRepresentable , Equatable {
259
259
/// The audio is binaural (either recorded or synthesized). It SHOULD NOT be dynamically spatialized. It is best
260
260
/// suited for delivery to headphones.
261
- case binaural = " BINAURAL "
261
+ case binaural
262
262
/// The audio is pre-processed content that SHOULD NOT be dynamically spatialized. It is suitable to deliver to
263
263
/// either headphones or speakers.
264
- case immersive = " IMMERSIVE "
264
+ case immersive
265
265
/// The audio is a downmix derivative of some other audio. If desired, the downmix may be used as a subtitute
266
266
/// for alternative Renditions in the same group with compatible attributes and a greater channel count. It MAY
267
267
/// be dynamically spatialized.
268
- case downmix = " DOWNMIX "
268
+ case downmix
269
+ /// The audio identifier is not recognized by this library; however, we provide the raw identifier string that
270
+ /// existed in the manifest.
271
+ case unrecognized( String )
272
+
273
+ public var rawValue : String {
274
+ switch self {
275
+ case . binaural: return " BINAURAL "
276
+ case . immersive: return " IMMERSIVE "
277
+ case . downmix: return " DOWNMIX "
278
+ case . unrecognized( let string) : return string
279
+ }
280
+ }
281
+
282
+ public init ? ( rawValue: String ) {
283
+ self . init ( str: Substring ( rawValue) )
284
+ }
269
285
270
286
/// Allows `init` without having to allocate a new `String` object.
271
- init ? ( str: Substring ) {
287
+ init ( str: Substring ) {
272
288
switch str {
273
289
case " BINAURAL " : self = . binaural
274
290
case " IMMERSIVE " : self = . immersive
275
291
case " DOWNMIX " : self = . downmix
276
- default : return nil
292
+ default : self = . unrecognized ( String ( str ) )
277
293
}
278
294
}
279
295
}
@@ -287,15 +303,7 @@ public struct HLSChannels: Equatable, FailableStringLiteralConvertible {
287
303
switch index {
288
304
case 0 : count = Self . parseChannelCount ( str: str)
289
305
case 1 : spatialAudioCodingIdentifiers = Self . parseSpatialAudioCodingIdentifiers ( str: str)
290
- case 2 :
291
- guard let ids = Self . parseSpecialUsageIdentifiers ( str: str) else {
292
- // In the case that we don't recognize one of the special usage identifiers, leading to nil being
293
- // parsed out, I believe it is better to fail the entire parsing, as otherwise we could mislead the
294
- // user of the library into thinking that there are less special usage identifiers than there
295
- // actually are in the CHANNELS attribtue.
296
- return nil
297
- }
298
- specialUsageIdentifiers = ids
306
+ case 2 : specialUsageIdentifiers = Self . parseSpecialUsageIdentifiers ( str: str)
299
307
default : break // In the future there may be more parameters defined.
300
308
}
301
309
}
@@ -331,16 +339,8 @@ public struct HLSChannels: Equatable, FailableStringLiteralConvertible {
331
339
return identifiers
332
340
}
333
341
334
- private static func parseSpecialUsageIdentifiers( str: Substring ) -> [ SpecialUsageIdentifier ] ? {
335
- let split = str. split ( separator: " , " )
336
- var identifiers = [ SpecialUsageIdentifier] ( )
337
- for id in split {
338
- guard let specialUsageId = SpecialUsageIdentifier ( str: id) else {
339
- return nil
340
- }
341
- identifiers. append ( specialUsageId)
342
- }
343
- return identifiers
342
+ private static func parseSpecialUsageIdentifiers( str: Substring ) -> [ SpecialUsageIdentifier ] {
343
+ str. split ( separator: " , " ) . map { SpecialUsageIdentifier ( str: $0) }
344
344
}
345
345
}
346
346
@@ -435,36 +435,42 @@ public struct HLSVideoLayout: Equatable, FailableStringLiteralConvertible {
435
435
/// is predominantly monoscopic then the Multivariant Playlist SHOULD specify `REQ-VIDEO-LAYOUT="CH-MONO,CH-STEREO"`.
436
436
public let predominantLayout : VideoLayoutIdentifier
437
437
438
- public enum VideoLayoutIdentifier : String {
438
+ public enum VideoLayoutIdentifier : RawRepresentable , Equatable {
439
439
/// Monoscopic.
440
440
///
441
441
/// Indicates that a single image is present.
442
- case chMono = " CH-MONO "
442
+ case chMono
443
443
/// Stereoscopic.
444
444
///
445
445
/// Indicates that both left and right eye images are present.
446
- case chStereo = " CH-STEREO "
446
+ case chStereo
447
+ /// The video layout identifier is not recognized by this library; however, we provide the raw identifier string
448
+ /// that existed in the manifest.
449
+ case unrecognized( String )
450
+
451
+ public var rawValue : String {
452
+ switch self {
453
+ case . chMono: return " CH-MONO "
454
+ case . chStereo: return " CH-STEREO "
455
+ case . unrecognized( let string) : return string
456
+ }
457
+ }
458
+
459
+ public init ? ( rawValue: String ) {
460
+ self . init ( str: Substring ( rawValue) )
461
+ }
447
462
448
- init ? ( str: Substring ) {
463
+ init ( str: Substring ) {
449
464
switch str {
450
465
case " CH-MONO " : self = . chMono
451
466
case " CH-STEREO " : self = . chStereo
452
- default : return nil
467
+ default : self = . unrecognized ( String ( str ) )
453
468
}
454
469
}
455
470
}
456
471
457
472
public init ? ( string: String ) {
458
- var layouts = [ VideoLayoutIdentifier] ( )
459
- for str in string. split ( separator: " , " ) {
460
- if let layout = VideoLayoutIdentifier ( str: str) {
461
- layouts. append ( layout)
462
- } else {
463
- // Favor failing to parse the whole array if we find an unrecognized layout, so that we don't risk mis-
464
- // reporting the existing layouts.
465
- return nil
466
- }
467
- }
473
+ let layouts = string. split ( separator: " , " ) . map { VideoLayoutIdentifier ( str: $0) }
468
474
guard let firstLayout = layouts. first else {
469
475
return nil
470
476
}
0 commit comments