Skip to content

Commit 96ddfd5

Browse files
committed
fix: update H.264 parser unit tests
1 parent c2f95fa commit 96ddfd5

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

lib/components/h264depay/parser.test.ts

+30-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import { h264depay } from './parser'
1+
import { H264DepayParser } from './parser'
22
import { MessageType } from '../message'
3+
import { AssertionError } from 'assert'
34

45
/*
56
* The h264Handler is more thoroughly tested in the end2end test.
67
*
78
*/
89
describe('h264 handler', () => {
9-
let callback: any
10+
let h264Parser: H264DepayParser
1011

1112
beforeEach(() => {
12-
callback = jest.fn()
13+
h264Parser = new H264DepayParser()
1314
})
1415

1516
it('parses a single NALU packet', () => {
1617
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+
})
2423

25-
const msg = callback.mock.calls[0][0]
24+
expect(msg).not.toBeNull()
25+
expect((h264Parser as any)._buffer.length).toEqual(0)
2626

27+
if (msg === null) {
28+
throw new AssertionError()
29+
}
2730
expect(msg.timestamp).toEqual(547056949)
2831
expect(msg.type).toEqual(MessageType.H264)
2932
expect(msg.data.length).toEqual(14)
@@ -41,22 +44,24 @@ describe('h264 handler', () => {
4144
'base64',
4245
)
4346
/* 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)
5154

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()
5961

62+
if (msg === null) {
63+
throw new AssertionError()
64+
}
6065
expect(msg.timestamp).toEqual(153026579)
6166
expect(msg.type).toEqual(MessageType.H264)
6267
expect(msg.data.length).toEqual(535)

0 commit comments

Comments
 (0)