mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-08-02 06:43:21 +00:00
Remove Encoder.LoadBuf interface method
There is no point in keeping it only for early YUV image pooling.
This commit is contained in:
parent
b903700077
commit
e2226e7492
4 changed files with 10 additions and 20 deletions
|
|
@ -15,8 +15,7 @@ type (
|
|||
InFrame yuv.RawFrame
|
||||
OutFrame []byte
|
||||
Encoder interface {
|
||||
LoadBuf(input []byte)
|
||||
Encode() []byte
|
||||
Encode([]byte) []byte
|
||||
IntraRefresh()
|
||||
Info() string
|
||||
SetFlip(bool)
|
||||
|
|
@ -75,10 +74,8 @@ func (v *Video) Encode(frame InFrame) OutFrame {
|
|||
}
|
||||
|
||||
yCbCr := v.y.Process(yuv.RawFrame(frame), v.rot, v.pf)
|
||||
v.codec.LoadBuf(yCbCr)
|
||||
v.y.Put(&yCbCr)
|
||||
|
||||
if bytes := v.codec.Encode(); len(bytes) > 0 {
|
||||
defer v.y.Put(&yCbCr)
|
||||
if bytes := v.codec.Encode(yCbCr); len(bytes) > 0 {
|
||||
return bytes
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -122,13 +122,11 @@ func NewEncoder(w, h int, th int, opts *Options) (encoder *H264, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (e *H264) LoadBuf(yuv []byte) {
|
||||
func (e *H264) Encode(yuv []byte) []byte {
|
||||
e.in.img.plane[0] = (*C.uchar)(unsafe.Pointer(&yuv[0]))
|
||||
e.in.img.plane[1] = (*C.uchar)(unsafe.Pointer(&yuv[e.y]))
|
||||
e.in.img.plane[2] = (*C.uchar)(unsafe.Pointer(&yuv[e.y+e.uv]))
|
||||
}
|
||||
|
||||
func (e *H264) Encode() []byte {
|
||||
e.in.i_pts += 1
|
||||
|
||||
e.p.Pin(e.in.img.plane[0])
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ func TestH264Encode(t *testing.T) {
|
|||
return
|
||||
}
|
||||
data := make([]byte, 120*120*1.5)
|
||||
h264.LoadBuf(data)
|
||||
h264.Encode()
|
||||
h264.Encode(data)
|
||||
if err := h264.Shutdown(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -25,7 +24,6 @@ func Benchmark(b *testing.B) {
|
|||
}
|
||||
data := make([]byte, int(float64(w)*float64(h)*1.5))
|
||||
for i := 0; i < b.N; i++ {
|
||||
h264.LoadBuf(data)
|
||||
h264.Encode()
|
||||
h264.Encode(data)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,17 +135,13 @@ func NewEncoder(w, h int, opts *Options) (*Vpx, error) {
|
|||
return &vpx, nil
|
||||
}
|
||||
|
||||
func (vpx *Vpx) LoadBuf(yuv []byte) {
|
||||
// Encode encodes yuv image with the VPX8 encoder.
|
||||
// see: https://chromium.googlesource.com/webm/libvpx/+/master/examples/simple_encoder.c
|
||||
func (vpx *Vpx) Encode(yuv []byte) []byte {
|
||||
C.vpx_img_read(&vpx.image, unsafe.Pointer(&yuv[0]))
|
||||
if vpx.flipped {
|
||||
C.vpx_img_flip(&vpx.image)
|
||||
}
|
||||
}
|
||||
|
||||
// Encode encodes yuv image with the VPX8 encoder.
|
||||
// see: https://chromium.googlesource.com/webm/libvpx/+/master/examples/simple_encoder.c
|
||||
func (vpx *Vpx) Encode() []byte {
|
||||
var iter C.vpx_codec_iter_t
|
||||
|
||||
var flags C.int
|
||||
if vpx.kfi > 0 && vpx.frameCount%vpx.kfi == 0 {
|
||||
|
|
@ -156,6 +152,7 @@ func (vpx *Vpx) Encode() []byte {
|
|||
}
|
||||
vpx.frameCount++
|
||||
|
||||
var iter C.vpx_codec_iter_t
|
||||
fb := C.get_frame_buffer(&vpx.codecCtx, &iter)
|
||||
if fb.ptr == nil {
|
||||
return []byte{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue