-
Notifications
You must be signed in to change notification settings - Fork 2
/
type.go
83 lines (72 loc) · 1.78 KB
/
type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package media
import (
"encoding/json"
)
///////////////////////////////////////////////////////////////////////////////
// TYPES
// Type of codec, device, format or stream
type Type int
///////////////////////////////////////////////////////////////////////////////
// GLOBALS
const (
NONE Type = 0 // Type is not defined
VIDEO Type = (1 << iota) // Type is video
AUDIO // Type is audio
SUBTITLE // Type is subtitle
DATA // Type is data
UNKNOWN // Type is unknown
INPUT // Type is input format
OUTPUT // Type is output format
DEVICE // Type is input or output device
maxtype
mintype = VIDEO
ANY = NONE // Type is any (used for filtering)
)
///////////////////////////////////////////////////////////////////////////////
// STINGIFY
// Return the type as a string
func (t Type) MarshalJSON() ([]byte, error) {
return json.Marshal(t.String())
}
// Return the type as a string
func (t Type) String() string {
if t == NONE {
return t.FlagString()
}
str := ""
for f := mintype; f < maxtype; f <<= 1 {
if t&f == f {
str += "|" + f.FlagString()
}
}
return str[1:]
}
// Return a flag as a string
func (t Type) FlagString() string {
switch t {
case NONE:
return "NONE"
case VIDEO:
return "VIDEO"
case AUDIO:
return "AUDIO"
case SUBTITLE:
return "SUBTITLE"
case DATA:
return "DATA"
case INPUT:
return "INPUT"
case OUTPUT:
return "OUTPUT"
case DEVICE:
return "DEVICE"
default:
return "UNKNOWN"
}
}
///////////////////////////////////////////////////////////////////////////////
// METHODS
// Returns true if the type matches a set of flags
func (t Type) Is(u Type) bool {
return t&u == u
}