forked from w3c/webrtc-encoded-transform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
959 lines (846 loc) · 45.2 KB
/
index.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
<pre class='metadata'>
Title: WebRTC Encoded Transform
Shortname: webrtc-encoded-transform
Level: None
Status: ED
Group: webrtc
TR: https://www.w3.org/TR/webrtc-encoded-transform/
Repository: w3c/webrtc-encoded-transform
URL: https://w3c.github.io/webrtc-encoded-transform/
Editor: Harald Alvestrand, w3cid 24610 , Google https://google.com, hta@google.com
Editor: Guido Urdaneta, w3cid 84810, Google https://google.com, guidou@google.com
Editor: Youenn Fablet, w3cid 96458, Apple https://www.apple.com, youenn@apple.com
Abstract: This API defines an API surface for manipulating the bits on
Abstract: {{MediaStreamTrack}}s being sent via an {{RTCPeerConnection}}.
Markup Shorthands: css no, markdown yes
</pre>
<pre class=link-defaults>
spec:webidl; type:dfn; text:resolve
</pre>
<pre class=biblio>
{
"SFRAME": {
"href":
"https://www.ietf.org/archive/id/draft-ietf-sframe-enc-04.html",
"title": "Secure Frame (SFrame)"
},
"VP9": {
"href":
"https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp9-bitstream-specification-v0.6-20160331-draft.pdf",
"title": "VP9 Bitstream & Decoding Process Specification",
"publisher": "The WebM Project"
},
"ITU-T-REC-H.264": {
"href": "https://www.itu.int/rec/T-REC-H.264",
"title": "H.264 : Advanced video coding for generic audiovisual services",
"publisher": "ITU"
},
"ITU-G.711": {
"href": "https://www.itu.int/rec/T-REC-G.711/",
"title": "G.711 : Pulse code modulation (PCM) of voice frequencies",
"publisher": "ITU"
},
"ITU-G.722": {
"href": "https://www.itu.int/rec/T-REC-G.722/",
"title": "G.722 : 7 kHz audio-coding within 64 kbit/s",
"publisher": "ITU"
}
}
</pre>
<pre class=link-defaults>
spec:streams; type:interface; text:ReadableStream
</pre>
# Introduction # {#introduction}
The [[WEBRTC-NV-USE-CASES]] document describes the use-case of
* Untrusted JavaScript Cloud Conferencing
which requires that the conferencing server does not have access
to the cleartext media (requirement N27).
This specification provides access to encoded media,
which is the output of the encoder part of a codec and the input to the
decoder part of a codec which allows the user agent to apply encryption
locally.
The interface is inspired by [[WEBCODECS]] to
provide access to such functionality while retaining the setup flow of
RTCPeerConnection
# Specification # {#specification}
The Streams definition doesn't use WebIDL much, but the WebRTC spec does.
This specification shows the IDL extensions for WebRTC.
It uses an additional API on {{RTCRtpSender}} and {{RTCRtpReceiver}} to
insert the processing into the pipeline.
<pre class="idl">
typedef (SFrameTransform or RTCRtpScriptTransform) RTCRtpTransform;
// New methods for RTCRtpSender and RTCRtpReceiver
partial interface RTCRtpSender {
attribute RTCRtpTransform? transform;
};
partial interface RTCRtpReceiver {
attribute RTCRtpTransform? transform;
};
</pre>
## Extension operation ## {#operation}
At the time when a codec is initialized as part of the encoder, and the
corresponding flag is set in the {{RTCPeerConnection}}'s {{RTCConfiguration}}
argument, ensure that the codec is disabled and produces no output.
### Stream creation ### {#stream-creation}
At construction of each {{RTCRtpSender}} or {{RTCRtpReceiver}}, run the following steps:
1. Initialize [=this=].`[[transform]]` to null.
1. Initialize [=this=].`[[readable]]` to a new {{ReadableStream}}.
1. <a dfn for="ReadableStream">Set up</a> [=this=].`[[readable]]`. [=this=].`[[readable]]` is provided frames using the [$readEncodedData$] algorithm given |this| as parameter.
1. Initialize [=this=].`[[writable]]` to a new {{WritableStream}}.
1. <a dfn for="WritableStream">Set up</a> [=this=].`[[writable]]` with its [=WritableStream/set up/writeAlgorithm=] set to [$writeEncodedData$] given |this| as parameter and its [=WritableStream/set up/highWaterMark=] set to <code>Infinity</code>.
<p class="note">highWaterMark is set to Infinity to explicitly disable backpressure.</p>
1. Initialize [=this=].`[[pipeToController]]` to null.
1. Initialize [=this=].`[[lastReceivedFrameCounter]]` to <code>0</code>.
1. Initialize [=this=].`[[lastEnqueuedFrameCounter]]` to <code>0</code>.
1. [=Queue a task=] to run the following steps:
1. If [=this=].`[[pipeToController]]` is not null, abort these steps.
2. Set [=this=].`[[pipeToController]]` to a new {{AbortController}}.
<!-- FIXME: Use pipeTo algorithm when available. -->
3. Call <a href="https://streams.spec.whatwg.org/#readable-stream-pipe-to">pipeTo</a> with [=this=].`[[readable]]`, [=this=].`[[writable]]`, preventClose equal to true, preventAbort equal to true, preventCancel equal to true and [=this=].`[[pipeToController]]`'s [=AbortController/signal=].
<p class=note>
Streams backpressure can optimize throughput while limiting processing and memory consumption by pausing data production as early as possible in a data pipeline.
This proves useful in contexts where reliability is essential and latency is less of a concern.
On the other hand, WebRTC media pipelines favour low latency over reliability, for instance by allowing to drop frames at various places and by using recovery mechanisms.
Buffering within a transform would add latency without allowing web applications to adapt much.
The User Agent is responsible for doing these adaptations, especially since it controls both ends of the transform.
For those reasons, streams backpressure is disabled in WebRTC encoded transforms.
</p>
### Stream processing ### {#stream-processing}
The <dfn abstract-op>readEncodedData</dfn> algorithm is given a |rtcObject| as parameter. It is defined by running the following steps:
1. Wait for a frame to be produced by |rtcObject|'s encoder if it is a {{RTCRtpSender}} or |rtcObject|'s packetizer if it is a {{RTCRtpReceiver}}.
1. Increment |rtcObject|.`[[lastEnqueuedFrameCounter]]` by <code>1</code>.
1. Let |frame| be the newly produced frame.
1. Set |frame|.`[[owner]]` to |rtcObject|.
1. Set |frame|.`[[counter]]` to |rtcObject|.`[[lastEnqueuedFrameCounter]]`.
1. [=ReadableStream/Enqueue=] |frame| in |rtcObject|.`[[readable]]`.
The <dfn abstract-op>writeEncodedData</dfn> algorithm is given a |rtcObject| as parameter and a |frame| as input. It is defined by running the following steps:
1. If |frame|.`[[owner]]` is not equal to |rtcObject|, abort these steps and return [=a promise resolved with=] undefined. A processor cannot create frames, or move frames between streams.
1. If |frame|.`[[counter]]` is equal or smaller than |rtcObject|.`[[lastReceivedFrameCounter]]`, abort these steps and return [=a promise resolved with=] undefined. A processor cannot reorder frames, although it may delay them or drop them.
1. Set |rtcObject|.`[[lastReceivedFrameCounter]]` to |frame|`[[counter]]`.
1. Let |data| be |frame|.`[[data]]`.
1. Let |serializedFrame| be [$StructuredSerializeWithTransfer$](|frame|, « |data| »).
1. Let |frameCopy| be [$StructuredDeserialize$](|serializedFrame|, |frame|'s [=relevant realm=]).
1. Enqueue |frameCopy| for processing as if it came directly from the encoded data source, by running one of the following steps:
* If |rtcObject| is a {{RTCRtpSender}}, enqueue |frameCopy| to |rtcObject|'s packetizer, to be processed [=in parallel=].
* If |rtcObject| is a {{RTCRtpReceiver}}, enqueue |frameCopy| it to |rtcObject|'s decoder, to be processed [=in parallel=].
1. Return [=a promise resolved with=] undefined.
On sender side, as part of [$readEncodedData$], frames produced by |rtcObject|'s encoder MUST be enqueued in |rtcObject|.`[[readable]]` in the encoder's output order.
As [$writeEncodedData$] ensures that the transform cannot reorder frames, the encoder's output order is also the order followed by packetizers to generate RTP packets and assign RTP packet sequence numbers.
The packetizer may expect the transformed data to still conform to the original format, e.g. a series of NAL units separated by Annex B start codes.
On receiver side, as part of [$readEncodedData$], frames produced by |rtcObject|'s packetizer MUST be enqueued in |rtcObject|.`[[readable]]` in the same encoder's output order.
To ensure the order is respected, the depacketizer will typically use RTP packet sequence numbers to reorder RTP packets as needed before enqueuing frames in |rtcObject|.`[[readable]]`.
As [$writeEncodedData$] ensures that the transform cannot reorder frames, this will be the order expected by |rtcObject|'s decoder.
## Extension attribute ## {#attribute}
A RTCRtpTransform has two private slots called `[[readable]]` and `[[writable]]`.
Each RTCRtpTransform has an <dfn abstract-op for=RTCRtpTransform>association steps</dfn> set, which is empty by default.
The <dfn attribute for="RTCRtpSender,RTCRtpReceiver">transform</dfn> getter steps are:
1. Return [=this=].`[[transform]]`.
The `transform` setter steps are:
2. Let |transform| be the argument to the setter.
3. Let |checkedTransform| set to |transform| if it is not null or to an [=identity transform stream=] otherwise.
3. Let |reader| be the result of [=ReadableStream/getting a reader=] for |checkedTransform|.`[[readable]]`.
4. Let |writer| be the result of [=WritableStream/getting a writer=] for |checkedTransform|.`[[writable]]`.
5. Initialize |newPipeToController| to a new {{AbortController}}.
6. If [=this=].`[[pipeToController]]` is not null, run the following steps:
1. [=AbortSignal/Add=] the [$chain transform algorithm$] to [=this=].`[[pipeToController]]`'s [=AbortController/signal=].
2. [=AbortController/signal abort=] on [=this=].`[[pipeToController]]`.
7. Else, run the [$chain transform algorithm$] steps.
8. Set [=this=].`[[pipeToController]]` to |newPipeToController|.
9. Set [=this=].`[[transform]]` to |transform|.
10. Run the steps in the set of [$association steps$] of |transform| with [=this=].
The <dfn abstract-op>chain transform algorithm</dfn> steps are defined as:
1. If |newPipeToController|'s [=AbortController/signal=] is [=AbortSignal/aborted=], abort these steps.
2. [=ReadableStreamDefaultReader/Release=] |reader|.
3. [=WritableStreamDefaultWriter/Release=] |writer|.
4. Assert that |newPipeToController| is the same object as |rtcObject|.`[[pipeToController]]`.
<!-- FIXME: Use pipeTo algorithm when available. -->
5. Call <a href="https://streams.spec.whatwg.org/#readable-stream-pipe-to">pipeTo</a> with |rtcObject|.`[[readable]]`, |checkedTransform|.`[[writable]]`, preventClose equal to false, preventAbort equal to false, preventCancel equal to true and |newPipeToController|'s [=AbortController/signal=].
6. Call <a href="https://streams.spec.whatwg.org/#readable-stream-pipe-to">pipeTo</a> with |checkedTransform|.`[[readable]]`, |rtcObject|.`[[writable]]`, preventClose equal to true, preventAbort equal to true, preventCancel equal to false and |newPipeToController|'s [=AbortController/signal=].
This algorithm is defined so that transforms can be updated dynamically.
There is no guarantee on which frame will happen the switch from the previous transform to the new transform.
If a web application sets the transform synchronously at creation of the {{RTCRtpSender}} (for instance when calling addTrack), the transform will receive the first frame generated by the {{RTCRtpSender}}'s encoder.
Similarly, if a web application sets the transform synchronously at creation of the {{RTCRtpReceiver}} (for instance when calling addTrack, or at track event handler), the transform will receive the first full frame generated by the {{RTCRtpReceiver}}'s packetizer.
# SFrameTransform # {#sframe}
<p>
The API presented in this section allows applications to process SFrame data as defined in [[SFrame]].
</p>
<xmp class="idl">
enum SFrameTransformRole {
"encrypt",
"decrypt"
};
dictionary SFrameTransformOptions {
SFrameTransformRole role = "encrypt";
};
typedef [EnforceRange] unsigned long long SmallCryptoKeyID;
typedef (SmallCryptoKeyID or bigint) CryptoKeyID;
[Exposed=(Window,DedicatedWorker)]
interface SFrameTransform : EventTarget {
constructor(optional SFrameTransformOptions options = {});
Promise<undefined> setEncryptionKey(CryptoKey key, optional CryptoKeyID keyID);
attribute EventHandler onerror;
};
SFrameTransform includes GenericTransformStream;
enum SFrameTransformErrorEventType {
"authentication",
"keyID",
"syntax"
};
[Exposed=(Window,DedicatedWorker)]
interface SFrameTransformErrorEvent : Event {
constructor(DOMString type, SFrameTransformErrorEventInit eventInitDict);
readonly attribute SFrameTransformErrorEventType errorType;
readonly attribute CryptoKeyID? keyID;
readonly attribute any frame;
};
dictionary SFrameTransformErrorEventInit : EventInit {
required SFrameTransformErrorEventType errorType;
required any frame;
CryptoKeyID? keyID;
};
</xmp>
The <dfn constructor for="SFrameTransform" lt="SFrameTransform(options)"><code>new SFrameTransform(<var>options</var>)</code></dfn> constructor steps are:
1. Let |transformAlgorithm| be an algorithm which takes a |frame| as input and runs the <a href="#sframe-transform-algorithm">SFrame transform algorithm</a> with |this| and |frame|.
2. Set |this|.`[[transform]]` to a new {{TransformStream}}.
3. <a dfn for="ReadableStream">Set up</a> [=this=].`[[transform]]` with [=TransformStream/set up/transformAlgorithm=] set to |transformAlgorithm|.
4. Let |options| be the method's first argument.
5. Set |this|.`[[role]]` to |options|["{{SFrameTransformOptions/role}}"].
6. Set |this|.`[[readable]]` to |this|.`[[transform]]`.`[[readable]]`.
7. Set |this|.`[[writable]]` to |this|.`[[transform]]`.`[[writable]]`.
## Algorithm ## {#sframe-transform-algorithm}
The SFrame transform algorithm, given |sframe| as a SFrameTransform object and |frame|, runs these steps:
1. Let |role| be |sframe|.`[[role]]`.
1. If |frame|.`[[owner]]` is a {{RTCRtpSender}}, set |role| to 'encrypt'.
1. If |frame|.`[[owner]]` is a {{RTCRtpReceiver}}, set |role| to 'decrypt'.
1. Let |data| be undefined.
1. If |frame| is a {{BufferSource}}, set |data| to |frame|.
1. If |frame| is a {{RTCEncodedAudioFrame}}, set |data| to |frame|.{{RTCEncodedAudioFrame/data}}
1. If |frame| is a {{RTCEncodedVideoFrame}}, set |data| to |frame|.{{RTCEncodedVideoFrame/data}}
1. If |data| is undefined, abort these steps.
1. Let |buffer| be the result of running the SFrame algorithm with |data| and |role| as parameters. This algorithm is defined by the <a href="https://datatracker.ietf.org/doc/draft-omara-sframe/">SFrame specification</a> and returns an {{ArrayBuffer}}.
1. If the SFrame algorithm exits abruptly with an error, [=queue a task=] to run the following sub steps:
1. If the processing fails on decryption side due to |data| not following the SFrame format, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/errorType}} attribute set to {{SFrameTransformErrorEventType/syntax}}
and its {{SFrameTransformErrorEvent/frame}} attribute set to |frame|.
1. If the processing fails on decryption side due to the key identifier parsed in |data| being unknown, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/errorType}} attribute set to {{SFrameTransformErrorEventType/keyID}},
its {{SFrameTransformErrorEvent/frame}} attribute set to |frame| and its {{SFrameTransformErrorEvent/keyID}} attribute set to the keyID value parsed in the SFrame header.
1. If the processing fails on decryption side due to validation of the authentication tag, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/errorType}} attribute set to {{SFrameTransformErrorEventType/authentication}}
and its {{SFrameTransformErrorEvent/frame}} attribute set to |frame|.
1. Abort these steps.
1. If |frame| is a {{BufferSource}}, set |frame| to |buffer|.
1. If |frame| is a {{RTCEncodedAudioFrame}}, set |frame|.{{RTCEncodedAudioFrame/data}} to |buffer|.
1. If |frame| is a {{RTCEncodedVideoFrame}}, set |frame|.{{RTCEncodedVideoFrame/data}} to |buffer|.
1. [=ReadableStream/Enqueue=] |frame| in |sframe|.`[[transform]]`.
## Methods ## {#sframe-transform-methods}
The <dfn method for="SFrameTransform">setEncryptionKey(|key|, |keyID|)</dfn> method steps are:
1. Let |promise| be [=a new promise=].
2. If |keyID| is a {{bigint}} which cannot be represented as a integer between 0 and 2<sup>64</sup>-1 inclusive, [=reject=] |promise| with a {{RangeError}} exception.
3. Otherwise, [=in parallel=], run the following steps:
1. Set |key| with its optional |keyID| as key material to use for the SFrame transform algorithm, as defined by the <a href="https://datatracker.ietf.org/doc/draft-omara-sframe/">SFrame specification</a>.
2. If setting the key material fails, [=reject=] |promise| with an {{InvalidModificationError}} exception and abort these steps.
3. [=Resolve=] |promise| with undefined.
4. Return |promise|.
# RTCRtpScriptTransform # {#scriptTransform}
## <dfn enum>RTCEncodedVideoFrameType</dfn> dictionary ## {#RTCEncodedVideoFrameType}
<pre class="idl">
// New enum for video frame types. Will eventually re-use the equivalent defined
// by WebCodecs.
enum RTCEncodedVideoFrameType {
"empty",
"key",
"delta",
};
</pre>
<table dfn-for="RTCEncodedVideoFrameType" class="simple">
<caption>Enumeration description</caption>
<thead>
<tr>
<th>Enum value</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn enum-value>empty</dfn>
</td>
<td>
<p>
This frame contains no data.
</p>
</td>
</tr>
<tr>
<td>
<dfn enum-value>key</dfn>
</td>
<td>
<p>
This frame can be decoded without reference to any other frames.
</p>
</td>
</tr>
<tr>
<td>
<dfn enum-value>delta</dfn>
</td>
<td>
<p>
This frame references another frame and can not be decoded without that frame.
</p>
</td>
</tr>
</tbody>
</table>
## <dfn dictionary>RTCEncodedVideoFrameMetadata</dfn> dictionary ## {#RTCEncodedVideoFrameMetadata}
<pre class="idl">
dictionary RTCEncodedVideoFrameMetadata {
unsigned long long frameId;
sequence<unsigned long long> dependencies;
unsigned short width;
unsigned short height;
unsigned long spatialIndex;
unsigned long temporalIndex;
unsigned long synchronizationSource;
octet payloadType;
sequence<unsigned long> contributingSources;
long long timestamp; // microseconds
unsigned long rtpTimestamp;
DOMString mimeType;
};
</pre>
### Members ### {#RTCEncodedVideoFrameMetadata-members}
<dl dfn-for="RTCEncodedVideoFrameMetadata" class="dictionary-members">
<dt>
<dfn dict-member>frameId</dfn> <span class="idlMemberType">unsigned long long</span>
</dt>
<dd>
<p>
An identifier for the encoded frame, monotonically increasing in decode order. Its lower
16 bits match the frame_number of the AV1 Dependency Descriptor Header Extension defined in Appendix A of [[?AV1-RTP-SPEC]], if present.
Only present for received frames if the Dependency Descriptor Header Extension is present.
</p>
</dd>
<dt>
<dfn dict-member>dependencies</dfn> <span class="idlMemberType">sequence<unsigned long long></span>
</dt>
<dd>
<p>
List of frameIds of frames this frame references.
Only present for received frames if the AV1 Dependency Descriptor Header Extension defined in Appendix A of [[?AV1-RTP-SPEC]] is present.
</p>
</dd>
<dt>
<dfn dict-member>synchronizationSource</dfn> <span class="idlMemberType">unsigned long</span>
</dt>
<dd>
<p>
The synchronization source (ssrc) identifier is an unsigned integer value per [[RFC3550]]
used to identify the stream of RTP packets that the encoded frame object is describing.
</p>
</dd>
<dt>
<dfn dict-member>payloadType</dfn> <span class="idlMemberType">octet</span>
</dt>
<dd>
<p>
The payload type is an unsigned integer value in the range from 0 to 127 per [[RFC3550]]
that is used to describe the format of the RTP payload.
</p>
</dd>
<dt>
<dfn dict-member>contributingSources</dfn> <span class=
"idlMemberType">sequence<unsigned long></span>
</dt>
<dd>
<p>
The list of contribution sources (csrc list) as defined in [[RFC3550]].
</p>
</dd>
<dt>
<dfn dict-member>timestamp</dfn> <span class=
"idlMemberType">long long</span>
</dt>
<dd>
<p>
The media presentation timestamp (PTS) in microseconds of raw frame, matching the
{{VideoFrame/timestamp}} for raw frames which correspond to this frame.
</p>
</dd>
<dt>
<dfn dict-member>rtpTimestamp</dfn> <span class=
"idlMemberType">unsigned long</span>
</dt>
<dd>
<p>
The RTP timestamp identifier is an unsigned integer value per [[RFC3550]]
that reflects the sampling instant of the first octet in the RTP data packet.
</p>
</dd>
<dt>
<dfn dict-member>mimeType</dfn> <span class="idlMemberType">DOMString</span>
</dt>
<dd>
<p>
The codec MIME media type/subtype defined in the IANA media types registry
[[!IANA-MEDIA-TYPES]], e.g. video/VP8.
</p>
</dd>
</dl>
## <dfn interface>RTCEncodedVideoFrame</dfn> interface ## {#RTCEncodedVideoFrame-interface}
<pre class="idl">
// New interfaces to define encoded video and audio frames. Will eventually
// re-use or extend the equivalent defined in WebCodecs.
[Exposed=(Window,DedicatedWorker), Serializable]
interface RTCEncodedVideoFrame {
readonly attribute RTCEncodedVideoFrameType type;
attribute ArrayBuffer data;
RTCEncodedVideoFrameMetadata getMetadata();
};
</pre>
### Members ### {#RTCEncodedVideoFrame-members}
<dl dfn-for="RTCEncodedVideoFrame" class="dictionary-members">
<dt>
<dfn attribute>type</dfn> <span class="idlMemberType">RTCEncodedVideoFrameType</span>
</dt>
<dd>
<p>
The type attribute allows the application to determine when a key frame is being
sent or received.
</p>
</dd>
<dt>
<dfn attribute>data</dfn> <span class="idlMemberType">ArrayBuffer</span>
</dt>
<dd>
<p>
The encoded frame data. The format of the data depends on the video codec that is
used to encode/decode the frame which can be determined by looking at the
{{RTCEncodedVideoFrameMetadata/mimeType}}.
For <a href="https://w3c.github.io/webrtc-svc/">SVC</a>, each spatial layer
is transformed separately.
<p class="note">
Since packetizers may drop certain elements, e.g. AV1 temporal delimiter OBUs,
the input to an receive-side transform may be different from the output of
a send-side transform.
</p>
The following table gives a number of examples:
</p>
<table class="simple">
<thead>
<tr>
<th>mimeType</th><th>Data format</th>
</tr>
</thead>
<tbody>
<tr>
<td>
video/VP8
</td>
<td>
The data starts with the "uncompressed data chunk" defined in
<a href="https://datatracker.ietf.org/doc/html/rfc6386#section-9.1">
section 9.1</a> of [[RFC6386]] and is followed by the rest of the
frame data. The <a href="https://www.rfc-editor.org/rfc/rfc7741#section-4.1">
VP8 payload descriptor</a> is not accessible.
</td>
</tr>
<tr>
<td>
video/VP9
</td>
<td>
The data is a frame as described in Section 6 of [[VP9]].
The <a href="https://datatracker.ietf.org/doc/html/draft-ietf-payload-vp9#section-4.2">
VP9 payload descriptor</a> is not accessible.
</td>
</tr>
<tr>
<td>
video/H264
</td>
<td>
The data is a series of NAL units in Annex B format,
as defined in [[ITU-T-REC-H.264]] Annex B.
</td>
</tr>
<tr>
<td>
video/AV1
</td>
<td>
The data is a series of OBUs compliant to the
<a href="https://aomediacodec.github.io/av1-spec/#low-overhead-bitstream-format">
low-overhead bitstream format</a> as described in Section 5 of [[AV1]].
The <a href="https://aomediacodec.github.io/av1-rtp-spec/#41-rtp-header-usage">
AV1 aggregation header</a> is not accessible.
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
### Methods ### {#RTCEncodedVideoFrame-methods}
<dl dfn-for="RTCEncodedVideoFrame" class="dictionary-members">
<dt>
<dfn for="RTCEncodedVideoFrame" method>getMetadata()</dfn>
</dt>
<dd>
<p>
Returns the metadata associated with the frame.
</p>
</dd>
</dl>
### Serialization ### {#RTCEncodedVideoFrame-serialization}
{{RTCEncodedVideoFrame}} objects are serializable objects [[HTML]].
Their [=serialization steps=], given |value|, |serialized|, and |forStorage|, are:
1. If |forStorage| is true, then throw a {{DataCloneError}}.
1. Set |serialized|.`[[type]]` to the value of |value|.{{RTCEncodedVideoFrame/type}}
1. Set |serialized|.`[[metadata]]` to an internal representation of |value|'s metadata.
1. Set |serialized|.`[[data]]` to |value|.`[[data]]`
Their [=deserialization steps=], given |serialized|, |value| and |realm|, are:
1. Set |value|.{{RTCEncodedVideoFrame/type}} to |serialized|.`[[type]]`
1. Set |value|'s metadata to the platform object representation of |serialized|.`[[metadata]]`
1. Set |value|.`[[data]]` to |serialized|.`[[data]]`.
<p class="note">
The internal form of a serialized RTCEncodedVideoFrame is not observable;
it is defined chiefly so that it can be used with frame cloning in the
[$writeEncodedData$] algorithm and in the {{WindowOrWorkerGlobalScope/structuredClone()}} operation.
An implementation is therefore free to choose whatever method works best.
</p>
## <dfn dictionary>RTCEncodedAudioFrameMetadata</dfn> dictionary ## {#RTCEncodedAudioFrameMetadata}
<pre class="idl">
dictionary RTCEncodedAudioFrameMetadata {
unsigned long synchronizationSource;
octet payloadType;
sequence<unsigned long> contributingSources;
short sequenceNumber;
unsigned long rtpTimestamp;
DOMString mimeType;
};
</pre>
### Members ### {#RTCEncodedAudioFrameMetadata-members}
<dl dfn-for="RTCEncodedAudioFrameMetadata" class="dictionary-members">
<dt>
<dfn dict-member>synchronizationSource</dfn> <span class="idlMemberType">unsigned long</span>
</dt>
<dd>
<p>
The synchronization source (ssrc) identifier is an unsigned integer value per [[RFC3550]]
used to identify the stream of RTP packets that the encoded frame object is describing.
</p>
</dd>
<dt>
<dfn dict-member>payloadType</dfn> <span class="idlMemberType">octet</span>
</dt>
<dd>
<p>
The payload type is an unsigned integer value in the range from 0 to 127 per [[RFC3550]]
that is used to describe the format of the RTP payload.
</p>
</dd>
<dt>
<dfn dict-member>contributingSources</dfn> <span class=
"idlMemberType">sequence<unsigned long></span>
</dt>
<dd>
<p>
The list of contribution sources (csrc list) as defined in [[RFC3550]].
</p>
</dd>
<dt>
<dfn dict-member>sequenceNumber</dfn> <span class=
"idlMemberType">short</span>
</dt>
<dd>
<p>
The RTP sequence number as defined in [[RFC3550]]. Only exists for incoming audio frames.
</p>
<p class="note">
Comparing two sequence numbers requires serial number arithmetic described in [[RFC1982]].
</p>
</dd>
<dt>
<dfn dict-member>rtpTimestamp</dfn> <span class="idlMemberType">unsigned long</span>
</dt>
<dd>
<p>
The RTP timestamp identifier is an unsigned integer value per [[RFC3550]]
that reflects the sampling instant of the first octet in the RTP data packet.
</p>
</dd>
<dt>
<dfn dict-member>mimeType</dfn> <span class="idlMemberType">DOMString</span>
</dt>
<dd>
<p>
The codec MIME media type/subtype defined in the IANA media types registry
[[!IANA-MEDIA-TYPES]], e.g. audio/opus.
</p>
</dd>
</dl>
## <dfn interface>RTCEncodedAudioFrame</dfn> interface ## {#RTCEncodedAudioFrame-interface}
<pre class="idl">
[Exposed=(Window,DedicatedWorker), Serializable]
interface RTCEncodedAudioFrame {
attribute ArrayBuffer data;
RTCEncodedAudioFrameMetadata getMetadata();
};
</pre>
### Members ### {#RTCEncodedAudioFrame-members}
<dl dfn-for="RTCEncodedAudioFrame" class="dictionary-members">
<dt>
<dfn attribute>data</dfn> <span class="idlMemberType">ArrayBuffer</span>
</dt>
<dd>
<p>
The encoded frame data. The format of the data depends on the audio codec that is
used to encode/decode the frame which can be determined by looking at the
{{RTCEncodedAudioFrameMetadata/mimeType}}.
The following table gives a number of examples:
</p>
<table class="simple">
<thead>
<tr>
<th>mimeType</th><th>Data format</th>
</tr>
</thead>
<tbody>
<tr>
<td>
audio/opus
</td>
<td>
The data is Opus packets, as described in
<a href="https://datatracker.ietf.org/doc/html/rfc6716#section-3">
section 3</a> of [[RFC6716]].
</td>
</tr>
<tr>
<td>
audio/PCMU
</td>
<td>
The data is a sequence of bytes of arbitrary length, where each byte is a u-law
encoded PCM sample as defined by Table 2a and 2b in [[ITU-G.711]].
</td>
</tr>
<tr>
<td>
audio/PCMA
</td>
<td>
The data is a sequence of bytes of arbitrary length, where each byte is
an A-law encoded PCM sample as defined by Tables 1a and 1b in [[ITU-G.711]].
</td>
</tr>
<tr>
<td>
audio/G722
</td>
<td>
The data is G.722 audio as described in [[ITU-G.722]].
</td>
</tr>
<tr>
<td>
audio/RED
</td>
<td>
The data is Redundant Audio Data as described in
<a href="https://www.rfc-editor.org/rfc/rfc2198#section-3">
section 3</a> of [[RFC2198]].
</td>
</tr>
<tr>
<td>
audio/CN
</td>
<td>
The data is Comfort Noise as described in
<a href="https://www.rfc-editor.org/rfc/rfc3389#section-3">
section 3</a> of [[RFC3389]].
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
### Methods ### {#RTCEncodedAudioFrame-methods}
<dl dfn-for="RTCEncodedAudioFrame" class="dictionary-members">
<dt>
<dfn for="RTCEncodedAudioFrame" method>getMetadata()</dfn>
</dt>
<dd>
<p>
Returns the metadata associated with the frame.
</p>
</dd>
</dl>
### Serialization ### {#RTCEncodedAudioFrame-serialization}
{{RTCEncodedAudioFrame}} objects are serializable objects [[HTML]].
Their [=serialization steps=], given |value|, |serialized|, and |forStorage|, are:
1. If |forStorage| is true, then throw a {{DataCloneError}}.
1. Set |serialized|.`[[metadata]]` to an internal representation of |value|'s metadata.
1. Set |serialized|.`[[data]]` to |value|.`[[data]]`
Their [=deserialization steps=], given |serialized|, |value| and |realm|, are:
1. Set |value|'s metadata to the platform object representation of |serialized|.`[[metadata]]`
1. Set |value|.`[[data]]` to |serialized|.`[[data]]`.
## Interfaces ## {#RTCRtpScriptTransformer-interfaces}
<pre class="idl">
[Exposed=DedicatedWorker]
interface RTCTransformEvent : Event {
readonly attribute RTCRtpScriptTransformer transformer;
};
partial interface DedicatedWorkerGlobalScope {
attribute EventHandler onrtctransform;
};
[Exposed=DedicatedWorker]
interface RTCRtpScriptTransformer : EventTarget {
// Attributes and methods related to the transformer source
readonly attribute ReadableStream readable;
Promise<unsigned long long> generateKeyFrame(optional DOMString rid);
Promise<undefined> sendKeyFrameRequest();
// Attributes and methods related to the transformer sink
readonly attribute WritableStream writable;
attribute EventHandler onkeyframerequest;
// Attributes for configuring the Javascript code
readonly attribute any options;
};
[Exposed=Window]
interface RTCRtpScriptTransform {
constructor(Worker worker, optional any options, optional sequence<object> transfer);
};
[Exposed=DedicatedWorker]
interface KeyFrameRequestEvent : Event {
constructor(DOMString type, optional DOMString rid);
readonly attribute DOMString? rid;
};
</pre>
## Operations ## {#RTCRtpScriptTransform-operations}
The <dfn constructor for="RTCRtpScriptTransform" lt="RTCRtpScriptTransform(worker, options)"><code>new RTCRtpScriptTransform(|worker|, |options|, |transfer|)</code></dfn> constructor steps are:
1. Set |t1| to an [=identity transform stream=].
2. Set |t2| to an [=identity transform stream=].
3. Set |this|.`[[writable]]` to |t1|.`[[writable]]`.
4. Set |this|.`[[readable]]` to |t2|.`[[readable]]`.
5. Let |serializedOptions| be the result of [$StructuredSerializeWithTransfer$](|options|, |transfer|).
6. Let |serializedReadable| be the result of [$StructuredSerializeWithTransfer$](|t1|.`[[readable]]`, « |t1|.`[[readable]]` »).
7. Let |serializedWritable| be the result of [$StructuredSerializeWithTransfer$](|t2|.`[[writable]]`, « |t2|.`[[writable]]` »).
8. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
1. Let |transformerOptions| be the result of [$StructuredDeserialize$](|serializedOptions|, the current Realm).
2. Let |readable| be the result of [$StructuredDeserialize$](|serializedReadable|, the current Realm).
3. Let |writable| be the result of [$StructuredDeserialize$](|serializedWritable|, the current Realm).
4. Let |transformer| be a new {{RTCRtpScriptTransformer}}.
5. Set |transformer|.`[[options]]` to |transformerOptions|.
6. Set |transformer|.`[[readable]]` to |readable|.
7. Set |transformer|.`[[writable]]` to |writable|.
8. [=Fire an event=] named <dfn event for="DedicatedWorkerGlobalScope">rtctransform</dfn> using {{RTCTransformEvent}} with {{RTCTransformEvent/transformer}} set to |transformer| on |worker|’s global scope.
// FIXME: Describe error handling (worker closing flag true at RTCRtpScriptTransform creation time. And worker being terminated while transform is processing data).
Each RTCRtpScriptTransform has the following set of [$association steps$], given |rtcObject|:
1. Let |transform| be the {{RTCRtpScriptTransform}} object that owns the [$association steps$].
1. Let |encoder| be |rtcObject|'s encoder if |rtcObject| is a {{RTCRtpSender}} or undefined otherwise.
1. Let |depacketizer| be |rtcObject|'s depacketizer if |rtcObject| is a {{RTCRtpReceiver}} or undefined otherwise.
1. [=Queue a task=] on the DOM manipulation [=task source=] |worker|'s global scope to run the following steps:
1. Let |transformer| be the {{RTCRtpScriptTransformer}} object associated to |transform|.
1. Set |transformer|.`[[encoder]]` to |encoder|.
1. Set |transformer|.`[[depacketizer]]` to |depacketizer|.
The <dfn method for="RTCRtpScriptTransform">generateKeyFrame(|rid|)</dfn> method steps are:
1. Let |promise| be a new promise.
1. Run the [$generate key frame algorithm$] with |promise|, |this|.`[[encoder]]` and |rid|.
1. Return |promise|.
The <dfn method for="RTCRtpScriptTransform">sendKeyFrameRequest()</dfn> method steps are:
1. Let |promise| be a new promise.
1. Run the [$send request key frame algorithm$] with |promise| and |this|.`[[depacketizer]]`.
1. Return |promise|.
## Attributes ## {#RTCRtpScriptTransformer-attributes}
A {{RTCRtpScriptTransformer}} has the following private slots called `[[depacketizer]]`, `[[encoder]]`, `[[options]]`, `[[readable]]` and `[[writable]]`.
In addition, a {{RTCRtpScriptTransformer}} is always associated with its parent {{RTCRtpScriptTransform}} transform.
This allows algorithms to go from an {{RTCRtpScriptTransformer}} object to its {{RTCRtpScriptTransform}} parent and vice versa.
The <dfn attribute for="RTCRtpScriptTransformer">options</dfn> getter steps are:
1. Return [=this=].`[[options]]`.
The <dfn attribute for="RTCRtpScriptTransform">readable</dfn> getter steps are:
1. Return [=this=].`[[readable]]`.
The <dfn attribute for="RTCRtpScriptTransform">writable</dfn> getter steps are:
1. Return [=this=].`[[writable]]`.
The <dfn attribute for="RTCRtpScriptTransform">onbandwidthestimate</dfn> EventHandler has type bandwidthestimate.
The <dfn attribute for="RTCRtpScriptTransform">onkeyframerequest</dfn> EventHandler has type keyframerequest.
## Events ## {#RTCRtpScriptTransformer-events}
The following event fires on an {{RTCRtpScriptTransformer}}:
* keyframerequest of type {{KeyFrameRequestEvent}} - fired when the sink determines that a key frame has been requested.
The steps that generate an event of type {{KeyFrameRequestEvent}} are as follows:
Given a {{RTCRtpScriptTransformer}} |transform|:
When |transform|'s `[[encoder]]` receives a keyframe request, for instance from an incoming RTCP Picture Loss Indication (PLI)
or Full Intra Refresh (FIR), queue a task to perform the following steps:
1. Set |rid| to the RID of the appropriate layer, or undefined if the request is not for a specific layer.
1. [=Fire an event=] named `keyframerequest` at |transform| using {{KeyFrameRequestEvent}} with its {{Event/cancelable}} attribute initialized to "true", and with {{KeyFrameRequestEvent/rid}} set to |rid|.
1. If the event's [=Event/canceled flag=] is true, abort these steps.
1. Run the [$generate key frame algorithm$] with a new promise, |transform|.`[[encoder]]` and |rid|.
## KeyFrame Algorithms ## {#KeyFrame-algorithms}
The <dfn abstract-op>generate key frame algorithm</dfn>, given |promise|, |encoder| and |rid|, is defined by running these steps:
1. If |encoder| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
1. If |encoder| is not processing video frames, reject |promise| with {{InvalidStateError}}, abort these steps.
1. If |rid| is defined, but does not conform to the grammar requirements specified
in Section 10 of [[!RFC8851]], then reject |promise| with {{TypeError}} and abort
these steps.
1. [=In parallel=], run the following steps:
1. Gather a list of video encoders, named |videoEncoders| from |encoder|, ordered according negotiated RIDs if any.
1. If |rid| is defined, remove from |videoEncoders| any video encoder that does not match |rid|.
1. If |rid| is undefined, remove from |videoEncoders| all video encoders except the first one.
1. If |videoEncoders| is empty, reject |promise| with {{NotFoundError}} and abort these steps.
|videoEncoders| is expected to be empty if the corresponding {{RTCRtpSender}} is not active, or the corresponding {{RTCRtpSender}} track is ended.
1. Let |videoEncoder| be the first encoder in |videoEncoders|.
1. If |rid| is undefined, set |rid| to the RID value corresponding to |videoEncoder|.
1. Create a pending key frame task called |task| with |task|.`[[rid]]` set to rid and |task|.`[[promise]]`| set to |promise|.
1. If |encoder|.`[[pendingKeyFrameTasks]]` is undefined, initialize |encoder|.`[[pendingKeyFrameTasks]]` to an empty set.
1. Let |shouldTriggerKeyFrame| be <code>false</code> if |encoder|.`[[pendingKeyFrameTasks]]` contains a task whose `[[rid]]`
value is equal to |rid|, and <code>true</code> otherwise.
1. Add |task| to |encoder|.`[[pendingKeyFrameTasks]]`.
1. If |shouldTriggerKeyFrame| is <code>true</code>, instruct |videoEncoder| to generate a key frame for the next provided video frame.
For any {{RTCRtpScriptTransformer}} named |transformer|, the following steps are run just before any |frame| is enqueued in |transformer|.`[[readable]]`:
1. Let |encoder| be |transformer|.`[[encoder]]`.
1. If |encoder| or |encoder|.`[[pendingKeyFrameTasks]]` is undefined, abort these steps.
1. If |frame| is not a video {{RTCEncodedVideoFrameType/"key"}} frame, abort these steps.
1. For each |task| in |encoder|.`[[pendingKeyFrameTasks]]`, run the following steps:
1. If |frame| was generated by a video encoder identified by |task|.`[[rid]]`, run the following steps:
1. Remove |task| from |encoder|.`[[pendingKeyFrameTasks]]`.
1. Resolve |task|.`[[promise]]` with |frame|'s timestamp.
By resolving the promises just before enqueuing the corresponding key frame in a {{RTCRtpScriptTransformer}}'s readable,
the resolution callbacks of the promises are always executed just before the corresponding key frame is exposed.
If the promise is associated to several rid values, it will be resolved when the first key frame corresponding to one the rid value is enqueued.
The <dfn abstract-op>send request key frame algorithm</dfn>, given |promise| and |depacketizer|, is defined by running these steps:
1. If |depacketizer| is undefined, reject |promise| with {{InvalidStateError}}, abort these steps.
1. If |depacketizer| is not processing video packets, reject |promise| with {{InvalidStateError}}, abort these steps.
1. [=In parallel=], run the following steps:
1. If sending a Full Intra Request (FIR) by |depacketizer|'s receiver is not deemed appropriate, [=resolve=] |promise| with undefined and abort these steps.
Section 4.3.1 of [[RFC5104]] provides guidelines of how and when it is appropriate to sending a Full Intra Request.
1. Generate a Full Intra Request (FIR) packet as defined in section 4.3.1 of [[RFC5104]] and send it through |depacketizer|'s receiver.
1. [=Resolve=] |promise| with undefined.
# RTCRtpSender extension # {#rtcrtpsender-extension}
An additional API on {{RTCRtpSender}} is added to complement the generation of key frame added to {{RTCRtpScriptTransformer}}.
<pre class="idl">
partial interface RTCRtpSender {
Promise<undefined> generateKeyFrame(optional sequence <DOMString> rids);
};
</pre>
## Extension operation ## {#sender-operation}
The <dfn method for="RTCRtpSender">generateKeyFrame(|rids|)</dfn> method steps are:
1. Let |promise| be a new promise.
1. [=In parallel=], run the [$generate key frame algorithm$] with |promise|, |this|'s encoder and |rids|.
1. Return |promise|.
# Privacy and security considerations # {#privacy}
This API gives Javascript access to the content of media streams. This
is also available from other sources, such as Canvas and WebAudio.
However, streams that are isolated (as specified in
[[WEBRTC-IDENTITY]]) or tainted with another origin, cannot be
accessed using this API, since that would break the isolation rule.
The API will allow access to some aspects of timing information that are
otherwise unavailable, which allows some fingerprinting surface.
The API will give access to encoded media, which means that the JS application
will have full control over what's delivered to internal components like
the packetizer or the decoder. This may require additional care with
auditing how data is handled inside these components.
For instance, packetizers may expect to see data only from trusted encoders,
and may not be audited for reception of data from untrusted sources.
# Examples # {#examples}
See the [explainer document](https://github.com/w3c/webrtc-encoded-transform/blob/master/explainer.md#code-examples).