golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
967 B
69 lines
967 B
//go:build rpicamera |
|
// +build rpicamera |
|
|
|
package rpicamera |
|
|
|
import ( |
|
"encoding/binary" |
|
"syscall" |
|
) |
|
|
|
func syscallReadAll(fd int, buf []byte) error { |
|
size := len(buf) |
|
read := 0 |
|
|
|
for { |
|
n, err := syscall.Read(fd, buf[read:size]) |
|
if err != nil { |
|
return err |
|
} |
|
|
|
read += n |
|
if read >= size { |
|
break |
|
} |
|
} |
|
|
|
return nil |
|
} |
|
|
|
type pipe struct { |
|
readFD int |
|
writeFD int |
|
} |
|
|
|
func newPipe() (*pipe, error) { |
|
fds := make([]int, 2) |
|
err := syscall.Pipe(fds) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
return &pipe{ |
|
readFD: fds[0], |
|
writeFD: fds[1], |
|
}, nil |
|
} |
|
|
|
func (p *pipe) close() { |
|
syscall.Close(p.readFD) |
|
syscall.Close(p.writeFD) |
|
} |
|
|
|
func (p *pipe) read() ([]byte, error) { |
|
sizebuf := make([]byte, 4) |
|
err := syscallReadAll(p.readFD, sizebuf) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
size := int(binary.LittleEndian.Uint32(sizebuf)) |
|
buf := make([]byte, size) |
|
|
|
err = syscallReadAll(p.readFD, buf) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
return buf, nil |
|
}
|
|
|