Skip to content

Commit

Permalink
parse h264 parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Nov 9, 2023
1 parent 0cf78e9 commit 5f160ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/webrtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "werift",
"version": "0.18.9",
"version": "0.18.11",
"description": "WebRTC Implementation for TypeScript (Node.js)",
"keywords": [
"WebRTC",
Expand Down
14 changes: 10 additions & 4 deletions packages/webrtc/src/sdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,24 @@ export function codecParametersFromString(str: string) {
} else {
parameters[k] = v;
}
} else if (param.includes(":")) {
const [k, v] = param.split(":");
parameters[k] = Number.isNaN(Number(v)) ? v : Number(v);
} else {
parameters[param] = undefined;
}
});
return parameters;
}

export function codecParametersToString(parameters: {
[key: string]: string | number;
}) {
export function codecParametersToString(
parameters: {
[key: string]: string | number;
},
joint: string = "="
) {
const params = Object.entries(parameters).map(([k, v]) => {
if (v) return `${k}=${v}`;
if (v) return `${k}${joint}${v}`;
else return k;
});
if (params.length > 0) {
Expand Down
20 changes: 19 additions & 1 deletion packages/webrtc/tests/sdp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GroupDescription, MediaDescription, SessionDescription } from "../src";
import {
codecParametersFromString,
GroupDescription,
MediaDescription,
SessionDescription,
} from "../src";

describe("sdp", () => {
test("rtx", () => {
Expand All @@ -12,4 +17,17 @@ describe("sdp", () => {
new GroupDescription("FID", ["ssrc", "rtx"]),
]);
});

describe("codecParametersFromString", () => {
test("h264 parameters", () => {
const params = codecParametersFromString(
"packetization-mode:0;profile-level-id:42001f;level-asymmetry-allowed:0"
);
expect(params).toEqual({
"level-asymmetry-allowed": 0,
"packetization-mode": 0,
"profile-level-id": "42001f",
});
});
});
});

0 comments on commit 5f160ec

Please sign in to comment.