1
- import { h264depay } from './parser'
1
+ import { H264DepayParser } from './parser'
2
2
import { MessageType } from '../message'
3
+ import { AssertionError } from 'assert'
3
4
4
5
/*
5
6
* The h264Handler is more thoroughly tested in the end2end test.
6
7
*
7
8
*/
8
9
describe ( 'h264 handler' , ( ) => {
9
- let callback : any
10
+ let h264Parser : H264DepayParser
10
11
11
12
beforeEach ( ( ) => {
12
- callback = jest . fn ( )
13
+ h264Parser = new H264DepayParser ( )
13
14
} )
14
15
15
16
it ( 'parses a single NALU packet' , ( ) => {
16
17
const singleNalu = Buffer . from ( 'gOATzCCbbTXpPLiiQZrALBJ/AEphqA==' , 'base64' )
17
- const remaining = h264depay (
18
- Buffer . alloc ( 0 ) ,
19
- { type : MessageType . RTP , data : singleNalu , channel : 0 } ,
20
- callback ,
21
- )
22
- expect ( callback ) . toHaveBeenCalledTimes ( 1 )
23
- expect ( remaining . length ) . toEqual ( 0 )
18
+ const msg = h264Parser . parse ( {
19
+ type : MessageType . RTP ,
20
+ data : singleNalu ,
21
+ channel : 0 ,
22
+ } )
24
23
25
- const msg = callback . mock . calls [ 0 ] [ 0 ]
24
+ expect ( msg ) . not . toBeNull ( )
25
+ expect ( ( h264Parser as any ) . _buffer . length ) . toEqual ( 0 )
26
26
27
+ if ( msg === null ) {
28
+ throw new AssertionError ( )
29
+ }
27
30
expect ( msg . timestamp ) . toEqual ( 547056949 )
28
31
expect ( msg . type ) . toEqual ( MessageType . H264 )
29
32
expect ( msg . data . length ) . toEqual ( 14 )
@@ -41,22 +44,24 @@ describe('h264 handler', () => {
41
44
'base64' ,
42
45
)
43
46
/* eslint-enable */
44
- const remaining = h264depay (
45
- Buffer . alloc ( 0 ) ,
46
- { type : MessageType . RTP , data : fuaPart1 , channel : 0 } ,
47
- callback ,
48
- )
49
- expect ( callback ) . toHaveBeenCalledTimes ( 0 )
50
- expect ( remaining . length ) . toBeGreaterThan ( 0 )
47
+ let msg = h264Parser . parse ( {
48
+ type : MessageType . RTP ,
49
+ data : fuaPart1 ,
50
+ channel : 0 ,
51
+ } )
52
+ expect ( msg ) . toBeNull ( )
53
+ expect ( ( h264Parser as any ) . _buffer . length ) . toBeGreaterThan ( 0 )
51
54
52
- h264depay (
53
- remaining ,
54
- { type : MessageType . RTP , data : fuaPart2 , channel : 0 } ,
55
- callback ,
56
- )
57
- expect ( callback ) . toHaveBeenCalledTimes ( 1 )
58
- const msg = callback . mock . calls [ 0 ] [ 0 ]
55
+ msg = h264Parser . parse ( {
56
+ type : MessageType . RTP ,
57
+ data : fuaPart2 ,
58
+ channel : 0 ,
59
+ } )
60
+ expect ( msg ) . not . toBeNull ( )
59
61
62
+ if ( msg === null ) {
63
+ throw new AssertionError ( )
64
+ }
60
65
expect ( msg . timestamp ) . toEqual ( 153026579 )
61
66
expect ( msg . type ) . toEqual ( MessageType . H264 )
62
67
expect ( msg . data . length ) . toEqual ( 535 )
0 commit comments