Debian Codegraph @

Xh264/README.md

raw
1 # h264-profile-level-id
2
3 JavaScript utility to process [H264](https://tools.ietf.org/html/rfc6184) `profile-level-id` values based on Google's [libwebrtc](https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/media/base/h264_profile_level_id.h) C++ code.
4
5 ```bash
6 $ npm install h264-profile-level-id
7 ```
8
9 This library provides TypeScript definitions.
10
11
12 ## API
13
14 ```js
15 import {
16 // H264 Profile identifiers.
17 ProfileConstrainedBaseline,
18 ProfileBaseline,
19 ProfileMain,
20 ProfileConstrainedHigh,
21 ProfileHigh,
22 // H264 Level identifiers.
23 Level1_b,
24 Level1,
25 Level1_1,
26 Level1_2,
27 Level1_3,
28 Level2,
29 Level2_1,
30 Level2_2,
31 Level3,
32 Level3_1,
33 Level3_2,
34 Level4,
35 Level4_1,
36 Level4_2,
37 Level5,
38 Level5_1,
39 Level5_2,
40 // Class.
41 ProfileLevelId,
42 // Functions.
43 parseProfileLevelId,
44 profileLevelIdToString,
45 parseSdpProfileLevelId,
46 isSameProfile,
47 generateProfileLevelIdForAnswer
48 } from 'h264-profile-level-id';
49 ```
50
51 ### ProfileLevelId
52
53 Class containing both H264 Profile and Level.
54
55 ```js
56 const profile_level_id = new ProfileLevelId(ProfileMain, Level3_1);
57
58 console.log('profile:%d, level:%d', profile_level_id.profile, profile_level_id.level);
59 // => profile:3, level:31
60 ```
61
62 Both `profile` and `level` members are public.
63
64
65 ### parseProfileLevelId(str)
66
67 Parse profile level id that is represented as a string of 3 hex bytes. Nothing will be returned if the string is not a recognized H264 profile level id.
68
69 * `@param` {String} **str** - profile-level-id value as a string of 3 hex bytes.
70 * `@returns` {ProfileLevelId} A instance of the `ProfileLevelId` class.
71
72
73 ### profileLevelIdToString(profile_level_id)
74
75 Returns canonical string representation as three hex bytes of the profile level id, or returns nothing for invalid profile level ids.
76
77 * `@param` {ProfileLevelId} **profile_level_id** - A instance of the `ProfileLevelId` class.
78 * `@returns` {String}
79
80
81 ### parseSdpProfileLevelId(params={})
82
83 Parse profile level id that is represented as a string of 3 hex bytes contained in an SDP key-value map. A default profile level id will be returned if the profile-level-id key is missing. Nothing will be returned if the key is present but the string is invalid.
84
85 * `@param` {Object} **[params={}]** - Codec parameters object.
86 * `@returns` {ProfileLevelId} A instance of the `ProfileLevelId` class.
87
88
89 ### isSameProfile(params1={}, params2={})
90
91 Returns true if the parameters have the same H264 profile, i.e. the same H264 profile (Baseline, High, etc).
92
93 * `@param` {Object} **[params1={}]** - Codec parameters object.
94 * `@param` {Object} **[params2={}]** - Codec parameters object.
95 * `@returns` {Boolean}
96
97
98 ### generateProfileLevelIdForAnswer(local_supported_params={}, remote_offered_params={})
99
100 Generate a profile level id that is represented as a string of 3 hex bytes suitable for an answer in an SDP negotiation based on local supported parameters and remote offered parameters. The parameters that are used when negotiating are the level part of `profile-level-id` and `level-asymmetry-allowed`.
101
102 **NOTE:** This function is just intended to manage H264 profile levels ids with same Profile (otherwise it will throw). Use `isSameProfile()` API before this one.
103
104 * `@param` {Object} **[local_supported_params={}]**
105 * `@param` {Object} **[remote_offered_params={}]**
106 * `@returns` {String} Canonical string representation as three hex bytes of the profile level id, or null if no one of the params have `profile-level-id.`
107 * `@throws` {TypeError} If Profile mismatch or invalid params.
108
109
110 ## Usage examples
111
112 See the [unit tests](test/test.js).
113
114
115 ## Author
116
117 * Iñaki Baz Castillo [[website](https://inakibaz.me)|[github](https://github.com/ibc/)]
118
119
120 ## License
121
122 [ISC](./LICENSE)