mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 10:35:44 +00:00
The main benefit of libyuv, apart from shortening the video pipeline, is quite noticeable latency and CPU usage decrease due to various assembler/SIMD optimizations of the library. However, there is a drawback for macOS systems: libyuv cannot be downloaded as a compiled library and can only be built from the source, which means we should include a cropped source code of the library (~10K LoC) into the app or rise the complexity of macOS dev and run toolchains. The main target system -- Linux, and Windows will use compiled lib from the package managers and macOS will use the lib included as a shortened source-code. Building the app with the no_libyuv tag will force it to use libyuv from the provided source files.
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package recorder
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync"
|
|
"sync/atomic"
|
|
)
|
|
|
|
type rawStream struct {
|
|
dir string
|
|
id uint32
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
const videoFile = "f%07d__%dx%d__%d.raw"
|
|
|
|
func newRawStream(dir string) (*rawStream, error) {
|
|
return &rawStream{dir: dir}, nil
|
|
}
|
|
|
|
func (p *rawStream) Close() error {
|
|
atomic.StoreUint32(&p.id, 0)
|
|
p.wg.Wait()
|
|
return nil
|
|
}
|
|
|
|
func (p *rawStream) Write(data Video) {
|
|
i := atomic.AddUint32(&p.id, 1)
|
|
fileName := fmt.Sprintf(videoFile, i, data.Frame.W, data.Frame.H, data.Frame.Stride)
|
|
p.wg.Add(1)
|
|
go p.saveFrame(fileName, data.Frame)
|
|
}
|
|
|
|
func (p *rawStream) saveFrame(fileName string, frame Frame) {
|
|
file, err := os.Create(filepath.Join(p.dir, fileName))
|
|
if err != nil {
|
|
log.Printf("c err: %v", err)
|
|
}
|
|
if _, err = file.Write(frame.Data); err != nil {
|
|
log.Printf("f err: %v", err)
|
|
}
|
|
|
|
if err = file.Close(); err != nil {
|
|
log.Printf("fc err: %v", err)
|
|
}
|
|
p.wg.Done()
|
|
}
|
|
|
|
func ExtractFileInfo(name string) (w, h, st string) {
|
|
s1 := strings.Split(name, "__")
|
|
if len(s1) > 1 {
|
|
s12 := strings.Split(s1[1], "x")
|
|
if len(s12) > 1 {
|
|
w, h = s12[0], s12[1]
|
|
}
|
|
s21 := strings.TrimSuffix(s1[2], filepath.Ext(s1[2]))
|
|
if s21 != "" {
|
|
st = s21
|
|
}
|
|
}
|
|
return
|
|
}
|