mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00

This reverts commit0f2ce5cc1c
. Reason for revert: Downstream infrastructure should be ready now Original change's description: > Revert "Migrate WebRTC documentation to new renderer" > > This reverts commit3eceaf4669
. > > Reason for revert: > > Original change's description: > > Migrate WebRTC documentation to new renderer > > > > Bug: b/258408932 > > Change-Id: Ib96f39fe0c3912f9746bcc09d079097a145d6115 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/290987 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39205} > > Bug: b/258408932 > Change-Id: I16cb4088bee3fc15c2bb88bd692c592b3a7db9fe > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291560 > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Owners-Override: Artem Titov <titovartem@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39209} Bug: b/258408932 Change-Id: Ia172e4a6ad1cc7953b48eed08776e9d1e44eb074 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291660 Owners-Override: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39231}
74 lines
3.1 KiB
Markdown
74 lines
3.1 KiB
Markdown
<!-- go/cmark -->
|
|
<!--* freshness: {owner: 'hta' reviewed: '2021-04-12'} *-->
|
|
|
|
# API Threading Design considerations
|
|
|
|
The header files in this directory form the API to the WebRTC library
|
|
that is intended for client applications' use.
|
|
|
|
This API is designed to be used on top of a multithreaded runtime.
|
|
|
|
The public API functions are designed to be called from a single thread*
|
|
(the "client thread"), and can do internal dispatching to the thread
|
|
where activity needs to happen. Those threads can be passed in by the
|
|
client, typically as arguments to factory constructors, or they can be
|
|
created by the library if factory constructors that don't take threads
|
|
are used.
|
|
|
|
Many of the functions are designed to be used in an asynchronous manner,
|
|
where a function is called to initiate an activity, and a callback will
|
|
be called when the activity is completed, or a handler function will
|
|
be called on an observer object when interesting events happen.
|
|
|
|
Note: Often, even functions that look like simple functions (such as
|
|
information query functions) will need to jump between threads to perform
|
|
their function - which means that things may happen on other threads
|
|
between calls; writing "increment(x); increment(x)" is not a safe
|
|
way to increment X by exactly two, since the increment function may have
|
|
jumped to another thread that already had a queue of things to handle,
|
|
causing large amounts of other activity to have intervened between
|
|
the two calls.
|
|
|
|
(*) The term "thread" is used here to denote any construct that guarantees
|
|
sequential execution - other names for such constructs are task runners
|
|
and sequenced task queues.
|
|
|
|
## Client threads and callbacks
|
|
|
|
At the moment, the API does not give any guarantee on which thread* the
|
|
callbacks and events are called on. So it's best to write all callback
|
|
and event handlers like this (pseudocode):
|
|
```
|
|
void ObserverClass::Handler(event) {
|
|
if (!called_on_client_thread()) {
|
|
dispatch_to_client_thread(bind(handler(event)));
|
|
return;
|
|
}
|
|
// Process event, we're now on the right thread
|
|
}
|
|
```
|
|
In the future, the implementation may change to always call the callbacks
|
|
and event handlers on the client thread.
|
|
|
|
## Implementation considerations
|
|
|
|
The C++ classes that are part of the public API are also used to derive
|
|
classes that form part of the implementation.
|
|
|
|
This should not directly concern users of the API, but may matter if one
|
|
wants to look at how the WebRTC library is implemented, or for legacy code
|
|
that directly accesses internal APIs.
|
|
|
|
Many APIs are defined in terms of a "proxy object", which will do a blocking
|
|
dispatch of the function to another thread, and an "implementation object"
|
|
which will do the actual
|
|
work, but can only be created, invoked and destroyed on its "home thread".
|
|
|
|
Usually, the classes are named "xxxInterface" (in api/), "xxxProxy" and
|
|
"xxx" (not in api/). WebRTC users should only need to depend on the files
|
|
in api/. In many cases, the "xxxProxy" and "xxx" classes are subclasses
|
|
of "xxxInterface", but this property is an implementation feature only,
|
|
and should not be relied upon.
|
|
|
|
The threading properties of these internal APIs are NOT documented in
|
|
this note, and need to be understood by inspecting those classes.
|