You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
# Design considerations
The header files in this directory form the API to the WebRTC librarythat 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 threadwhere activity needs to happen. Those threads can be passed in by theclient, typically as arguments to factory constructors, or they can becreated by the library if factory constructors that don't take threadsare 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 willbe called when the activity is completed, or a handler function willbe called on an observer object when interesting events happen.
Note: Often, even functions that look like simple functions (such asinformation query functions) will need to jump between threads to performtheir function - which means that things may happen on other threadsbetween calls; writing "increment(x); increment(x)" is not a safeway to increment X by exactly two, since the increment function may havejumped to another thread that already had a queue of things to handle,causing large amounts of other activity to have intervened betweenthe two calls.
(*) The term "thread" is used here to denote any construct that guaranteessequential execution - other names for such constructs are task runnersand sequenced task queues.
# Client threads and callbacks
At the moment, the API does not give any guarantee on which thread* thecallbacks and events are called on. So it's best to write all callbackand event handlers like this (pseudocode):<pre>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}</pre>In the future, the implementation may change to always call the callbacksand event handlers on the client thread.
# Implementation considerations
The C++ classes that are part of the public API are also used to deriveclasses that form part of the implementation.
This should not directly concern users of the API, but may matter if onewants to look at how the WebRTC library is implemented, or for legacy codethat directly accesses internal APIs.
Many APIs are defined in terms of a "proxy object", which will do a blockingdispatch of the function to another thread, and an "implementation object"which will do the actualwork, 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 filesin api/. In many cases, the "xxxProxy" and "xxx" classes are subclassesof "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 inthis note, and need to be understood by inspecting those classes.
|