-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtypes_linux.go
37 lines (29 loc) · 863 Bytes
/
types_linux.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
//go:build linux
package rtsp
/*
#cgo LDFLAGS: -lavformat -lavutil -lavcodec -lswresample -lswscale -lm
#include "ffmpeg.h"
*/
import "C"
import (
"bytes"
"unsafe"
)
// CErr2Str convert C error code to Go string
func CErr2Str(code C.int) string {
buf := make([]byte, 1024)
C.av_strerror(code, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
return string(buf[:bytes.Index(buf, []byte{0})])
}
func swrAllocSetOpts(layout uint64, sampleRate C.int, sampleFmt int32) *C.SwrContext {
swrContext := C.swr_alloc_set_opts(nil, // we're allocating a new context
C.long(layout), // out_ch_layout
C.AV_SAMPLE_FMT_S16, // out_sample_fmt
sampleRate, // out_sample_rate
C.long(layout), // in_ch_layout
sampleFmt, // in_sample_fmt
sampleRate, // in_sample_rate
0, // log_offset
nil) // log_ctx
return swrContext
}