Skip to content

Commit

Permalink
test: 💍 add test case for annex-b nalu split
Browse files Browse the repository at this point in the history
  • Loading branch information
gemxx committed Dec 23, 2024
1 parent d031e1e commit dc22b0b
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 31 deletions.
43 changes: 23 additions & 20 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ module.exports = {

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
"packages/xgplayer-flv/src/**/*.js",
"packages/xgplayer-hls/src/**/*.js",
"packages/xgplayer-transmuxer/src/**/*.js",
"!**/node_modules/**"
'packages/xgplayer-flv/src/**/*.js',
'packages/xgplayer-hls/src/**/*.js',
'packages/xgplayer-transmuxer/src/**/*.js',
'!**/node_modules/**'
],

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [
"/node_modules/",
"index.umd.js"
'/node_modules/',
'index.umd.js'
],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
"text",
"lcov",
"clover"
'text',
'lcov',
'clover'
],

// An object that configures minimum threshold enforcement for coverage results
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports = {

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [
"node_modules"
'node_modules'
],

// An array of file extensions your modules use
Expand All @@ -90,8 +90,8 @@ module.exports = {
'xgplayer-streaming-shared': '<rootDir>/packages/xgplayer-streaming-shared/src/',
'xgplayer-transmuxer': '<rootDir>/packages/xgplayer-transmuxer/src/',
'xgplayer': '<rootDir>/packages/xgplayer/src/',
"\\.(jpg|jpeg|png|gif|webp|svg)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.js"
'\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/fileMock.js',
'\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.js'
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down Expand Up @@ -155,9 +155,9 @@ module.exports = {

// The glob patterns Jest uses to detect test files
testMatch: [
"**/packages/xgplayer-flv/__tests__/**/*.(spec|test).js",
"**/packages/xgplayer-hls/__tests__/**/*.(spec|test).js",
"**/packages/xgplayer-transmuxer/__tests__/**/*.(spec|test).js",
'**/packages/xgplayer-flv/__tests__/**/*.(spec|test).js',
'**/packages/xgplayer-hls/__tests__/**/*.(spec|test).js',
'**/packages/xgplayer-transmuxer/__tests__/**/*.(spec|test).js'
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
Expand All @@ -182,16 +182,19 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
"\\.[jt]sx?$": ["babel-jest", {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]]
}],
'\\.[jt]sx?$': ['babel-jest', {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
}]
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: [
"node_modules/(?!crypto-es/.*)",
'node_modules/(?!crypto-es/.*)'
// "\\.pnp\\.[^\\/]+$"
],
]

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@babel/eslint-parser": "^7.14.3",
"@babel/parser": "^7.15.3",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.26.0",
"@rollup/plugin-babel": "^5.3.1",
"@types/events": "^3.0.0",
"@types/jest": "^28.1.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/xgplayer-flv/src/flv/services/buffer-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,13 @@ export class BufferService {
if (remuxResult.audioSegment) p.push(mse.append(audioType, remuxResult.audioSegment))

this.flv._transferCost.start(TRANSFER_EVENT.APPEND)
return Promise.all(p).then(afterAppend).then(() => {

const ret = Promise.all(p)
ret.then(afterAppend).then(() => {
this.flv._transferCost.end(TRANSFER_EVENT.APPEND)
afterAppend()
})
return ret
} else if (this._softVideo) {
this._softVideo.appendBuffer(videoTrack, audioTrack)
afterAppend()
Expand Down
5 changes: 4 additions & 1 deletion packages/xgplayer-hls/src/hls/buffer-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ export class BufferService {
const {data: audioData, ...audioRest} = audio
p.push(mse.append(MSE.AUDIO, audioData, audioRest))
}
return Promise.all(p).then(afterAppend)

const ret = Promise.all(p)
ret.then(afterAppend)
return ret
}
}

Expand Down
20 changes: 12 additions & 8 deletions packages/xgplayer-transmuxer/__tests__/codec/nalu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ import { NALu } from '../../src/codec'
describe('NALu', () => {

test('parseAnnexB', () => {
const uint1 = [9, 240]
const uint2 = [103, 100, 0, 31, 172, 217, 64, 212, 61, 176, 17, 0, 0, 3, 0, 1, 0, 0, 3, 0, 120, 15, 24, 49, 150]
const uint3 = [104, 235, 226, 75, 34, 192]
const uint0 = [9, 240]
const uint1 = [103, 100, 0, 31, 172, 217, 64, 212, 61, 176, 17, 0, 0, 3, 0, 1, 0, 0, 3, 0, 120, 15, 24, 49, 150]
const uint2 = [104, 235, 226, 75, 34, 192]
const uint3 = [226, 249, 198, 12, 0, 0, 0, 70, 83, 84, 83, 29, 1, 168, 170, 147, 1, 0, 0, 18] // 00 00 00 + not 1
const data = new Uint8Array([
0, 0, 0, 1,
...uint0,
0, 0, 0, 1,
...uint1,
0, 0, 0, 1,
...uint2,
0, 0, 0, 1,
0, 0, 1,
...uint3,
0, 0, 1
])

const result = NALu.parseAnnexB(data)

expect(result.length).toBe(3)
expect(result[0]).toEqual(new Uint8Array(uint1))
expect(result[1]).toEqual(new Uint8Array(uint2))
expect(result[2]).toEqual(new Uint8Array(uint3))
expect(result.length).toBe(4)
expect(result[0]).toEqual(new Uint8Array(uint0))
expect(result[1]).toEqual(new Uint8Array(uint1))
expect(result[2]).toEqual(new Uint8Array(uint2))
expect(result[3]).toEqual(new Uint8Array(uint3))
})

test('parseAvcC', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/xgplayer-transmuxer/src/codec/nalu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { readBig32 } from '../utils'

export class NALu {
/**
* @param {Uint8Array} data
* @returns {Uint8Array[]}
*/
static parseAnnexB (data) {
const len = data.length
let start = 2
Expand Down
Loading

0 comments on commit dc22b0b

Please sign in to comment.