-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodec.go
77 lines (62 loc) · 1.59 KB
/
codec.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
package media
import (
"encoding/json"
// Packages
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
)
////////////////////////////////////////////////////////////////////////////////
// TYPES
type codec struct {
ctx *ff.AVCodec
}
var _ Codec = (*codec)(nil)
////////////////////////////////////////////////////////////////////////////////
// LIFECYCLE
func newCodec(ctx *ff.AVCodec) *codec {
return &codec{ctx}
}
////////////////////////////////////////////////////////////////////////////////
// STRINGIFY
type jsonCodec struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
}
func (codec *codec) MarshalJSON() ([]byte, error) {
return json.Marshal(&jsonCodec{
Name: codec.Name(),
Description: codec.Description(),
Type: codec.Type().String(),
})
}
////////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
func (codec *codec) Name() string {
return codec.ctx.Name()
}
// Return the codec description
func (codec *codec) Description() string {
return codec.ctx.LongName()
}
// Return the codec type (AUDIO, VIDEO, SUBTITLE, DATA, INPUT, OUTPUT)
func (codec *codec) Type() MediaType {
t := NONE
switch codec.ctx.Type() {
case ff.AVMEDIA_TYPE_AUDIO:
t = AUDIO
case ff.AVMEDIA_TYPE_VIDEO:
t = VIDEO
case ff.AVMEDIA_TYPE_SUBTITLE:
t = SUBTITLE
default:
t = DATA
}
if ff.AVCodec_is_encoder(codec.ctx) {
t |= OUTPUT
}
if ff.AVCodec_is_decoder(codec.ctx) {
t |= INPUT
}
return t
}
// TODO: Supported sample formats, channel layouts, pixel formats, etc.