@@ -7,9 +7,34 @@ import (
77 "github.com/pion/mediadevices/pkg/codec"
88 "github.com/pion/mediadevices/pkg/codec/internal/codectest"
99 "github.com/pion/mediadevices/pkg/frame"
10+ "github.com/pion/mediadevices/pkg/io/video"
1011 "github.com/pion/mediadevices/pkg/prop"
1112)
1213
14+ func getTestVideoEncoder () (codec.ReadCloser , error ) {
15+ p , err := NewParams ()
16+ if err != nil {
17+ return nil , err
18+ }
19+ p .BitRate = 200000
20+ enc , err := p .BuildVideoEncoder (video .ReaderFunc (func () (image.Image , func (), error ) {
21+ return image .NewYCbCr (
22+ image .Rect (0 , 0 , 256 , 144 ),
23+ image .YCbCrSubsampleRatio420 ,
24+ ), nil , nil
25+ }), prop.Media {
26+ Video : prop.Video {
27+ Width : 256 ,
28+ Height : 144 ,
29+ FrameFormat : frame .FormatI420 ,
30+ },
31+ })
32+ if err != nil {
33+ return nil , err
34+ }
35+ return enc , nil
36+ }
37+
1338func TestEncoder (t * testing.T ) {
1439 t .Run ("SimpleRead" , func (t * testing.T ) {
1540 p , err := NewParams ()
@@ -69,19 +94,53 @@ func TestEncoder(t *testing.T) {
6994}
7095
7196func TestShouldImplementKeyFrameControl (t * testing.T ) {
72- t .SkipNow () // TODO: Implement key frame control
73-
7497 e := & encoder {}
7598 if _ , ok := e .Controller ().(codec.KeyFrameController ); ! ok {
7699 t .Error ()
77100 }
78101}
79102
80- func TestShouldImplementBitRateControl (t * testing.T ) {
81- t .SkipNow () // TODO: Implement bit rate control
103+ func TestNoErrorOnForceKeyFrame (t * testing.T ) {
104+ enc , err := getTestVideoEncoder ()
105+ if err != nil {
106+ t .Error (err )
107+ }
108+ kfc , ok := enc .Controller ().(codec.KeyFrameController )
109+ if ! ok {
110+ t .Error ()
111+ }
112+ if err := kfc .ForceKeyFrame (); err != nil {
113+ t .Error (err )
114+ }
115+ _ , rel , err := enc .Read () // try to read the encoded frame
116+ rel ()
117+ if err != nil {
118+ t .Fatal (err )
119+ }
120+ }
82121
122+ func TestShouldImplementBitRateControl (t * testing.T ) {
83123 e := & encoder {}
84124 if _ , ok := e .Controller ().(codec.BitRateController ); ! ok {
85125 t .Error ()
86126 }
87127}
128+
129+ func TestNoErrorOnSetBitRate (t * testing.T ) {
130+ enc , err := getTestVideoEncoder ()
131+ if err != nil {
132+ t .Error (err )
133+ }
134+ brc , ok := enc .Controller ().(codec.BitRateController )
135+ if ! ok {
136+ t .Error ()
137+ }
138+ if err := brc .SetBitRate (1000 ); err != nil { // 1000 bit/second is ridiculously low, but this is a testcase.
139+ t .Error (err )
140+ }
141+ _ , rel , err := enc .Read () // try to read the encoded frame
142+ rel ()
143+ if err != nil {
144+ t .Fatal (err )
145+ }
146+ }
0 commit comments