forked from nstehr/bobcaygeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
34 lines (28 loc) · 853 Bytes
/
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
package player
import (
"strings"
"github.com/carterpeel/bobcaygeon/rtsp"
"github.com/maghul/alac"
)
// CodecHandler handler function for receiving raw bytes and decoding them using some codec
type CodecHandler func(data []byte) ([]byte, error)
var codecMap = map[string]CodecHandler{
"AppleLossless": decodeAlac}
func decodeAlac(data []byte) ([]byte, error) {
decoder, err := alac.New()
if err != nil {
return nil, err
}
return decoder.Decode(data), nil
}
// GetCodec determins the appropriate codec from the rtsp session
func GetCodec(session *rtsp.Session) CodecHandler {
var decoder CodecHandler
rtpmap := session.Description.Attributes["rtpmap"]
if strings.Contains(rtpmap, "AppleLossless") {
decoder = codecMap["AppleLossless"]
} else {
decoder = func(data []byte) ([]byte, error) { return data, nil }
}
return decoder
}