@@ -5,6 +5,7 @@ package jitterbuffer
5
5
6
6
import (
7
7
"bytes"
8
+ "errors"
8
9
"testing"
9
10
"time"
10
11
@@ -17,8 +18,6 @@ import (
17
18
)
18
19
19
20
func TestBufferStart (t * testing.T ) {
20
- buf := bytes.Buffer {}
21
-
22
21
factory , err := NewInterceptor (
23
22
Log (logging .NewDefaultLoggerFactory ().NewLogger ("test" )),
24
23
)
@@ -27,8 +26,6 @@ func TestBufferStart(t *testing.T) {
27
26
i , err := factory .NewInterceptor ("" )
28
27
assert .NoError (t , err )
29
28
30
- assert .Zero (t , buf .Len ())
31
-
32
29
stream := test .NewMockStream (& interceptor.StreamInfo {
33
30
SSRC : 123456 ,
34
31
ClockRate : 90000 ,
@@ -55,7 +52,6 @@ func TestBufferStart(t *testing.T) {
55
52
}
56
53
err = i .Close ()
57
54
assert .NoError (t , err )
58
- assert .Zero (t , buf .Len ())
59
55
}
60
56
61
57
func TestReceiverBuffersAndPlaysout (t * testing.T ) {
@@ -96,3 +92,51 @@ func TestReceiverBuffersAndPlaysout(t *testing.T) {
96
92
err = i .Close ()
97
93
assert .NoError (t , err )
98
94
}
95
+
96
+ type MockRTPReader struct {
97
+ readFunc func ([]byte , interceptor.Attributes ) (int , interceptor.Attributes , error )
98
+ }
99
+
100
+ func (m * MockRTPReader ) Read (data []byte , attrs interceptor.Attributes ) (int , interceptor.Attributes , error ) {
101
+ if m .readFunc != nil {
102
+ return m .readFunc (data , attrs )
103
+ }
104
+ return 0 , nil , errors .New ("mock function not implemented" )
105
+ }
106
+
107
+ func NewMockRTPReader (readFunc func ([]byte , interceptor.Attributes ) (int , interceptor.Attributes , error )) * MockRTPReader {
108
+ return & MockRTPReader {
109
+ readFunc : readFunc ,
110
+ }
111
+ }
112
+
113
+ func TestReceiverInterceptorHonorsBufferLength (t * testing.T ) {
114
+ buf := []byte {0x80 , 0x88 , 0xe6 , 0xfd , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 ,
115
+ 0xde , 0xad , 0xbe , 0xef , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 }
116
+ readBuf := make ([]byte , 2048 )
117
+ copy (readBuf [0 :], buf )
118
+ copy (readBuf [17 :], buf )
119
+ factory , err := NewInterceptor (
120
+ Log (logging .NewDefaultLoggerFactory ().NewLogger ("test" )),
121
+ )
122
+ assert .NoError (t , err )
123
+
124
+ i , err := factory .NewInterceptor ("" )
125
+
126
+ rtpReadFn := NewMockRTPReader (func (data []byte , attrs interceptor.Attributes ) (int , interceptor.Attributes , error ) {
127
+ copy (data , readBuf )
128
+ return 7 , attrs , nil
129
+ })
130
+ reader := i .BindRemoteStream (& interceptor.StreamInfo {
131
+ SSRC : 123456 ,
132
+ ClockRate : 90000 ,
133
+ }, rtpReadFn )
134
+
135
+ bufLen , _ , err := reader .Read (readBuf , interceptor.Attributes {})
136
+ assert .Contains (t , err .Error (), "7 < 12" )
137
+ assert .Equal (t , 0 , bufLen )
138
+
139
+ err = i .Close ()
140
+ assert .NoError (t , err )
141
+
142
+ }
0 commit comments