Make SendCodec() lock-free.
Fetching the current codec for sake of gathering stats, is frequently blocked since it's done by acquiring the same lock as is held while encoding frames. This can mean tens of milliseconds. To improve this, I'm taking advantage of the fact that the codec information is set on the same thread as is used to query the information. This means that locking isn't needed for querying this information. I'm adding checks to make sure debug builds will crash if this isn't followed. An alternative to this approach could be to add one more lock that is specifically used for the codec information variable. This would also decouple querying codec information from the encoder itself, but still requires a lock. This patch depends on making ThreadChecker part of rtc_base_approved: https://webrtc-codereview.appspot.com/40539004/ BUG=2822 R=mflodman@webrtc.org, pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/37779004 Cr-Commit-Position: refs/heads/master@{#8435} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8435 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -11,6 +11,16 @@
|
||||
#ifndef WEBRTC_MODULES_INTERFACE_VIDEO_CODING_H_
|
||||
#define WEBRTC_MODULES_INTERFACE_VIDEO_CODING_H_
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
// This is a workaround on Windows due to the fact that some Windows
|
||||
// headers define CreateEvent as a macro to either CreateEventW or CreateEventA.
|
||||
// This can cause problems since we use that name as well and could
|
||||
// declare them as one thing here whereas in another place a windows header
|
||||
// may have been included and then implementing CreateEvent() causes compilation
|
||||
// errors. So for consistency, we include the main windows header here.
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "webrtc/common_video/interface/i420_video_frame.h"
|
||||
#include "webrtc/modules/interface/module.h"
|
||||
#include "webrtc/modules/interface/module_common_types.h"
|
||||
@ -112,6 +122,8 @@ public:
|
||||
// encoding-related settings by calling this function.
|
||||
// For instance, a send codec has to be registered again.
|
||||
//
|
||||
// NOTE: Must be called on the thread that constructed the VCM instance.
|
||||
//
|
||||
// Return value : VCM_OK, on success.
|
||||
// < 0, on error.
|
||||
virtual int32_t InitializeSender() = 0;
|
||||
@ -119,6 +131,8 @@ public:
|
||||
// Registers a codec to be used for encoding. Calling this
|
||||
// API multiple times overwrites any previously registered codecs.
|
||||
//
|
||||
// NOTE: Must be called on the thread that constructed the VCM instance.
|
||||
//
|
||||
// Input:
|
||||
// - sendCodec : Settings for the codec to be registered.
|
||||
// - numberOfCores : The number of cores the codec is allowed
|
||||
@ -132,6 +146,17 @@ public:
|
||||
uint32_t numberOfCores,
|
||||
uint32_t maxPayloadSize) = 0;
|
||||
|
||||
// Get the current send codec in use.
|
||||
//
|
||||
// If a codec has not been set yet, the |id| property of the return value
|
||||
// will be 0 and |name| empty.
|
||||
//
|
||||
// NOTE: This method intentionally does not hold locks and minimizes data
|
||||
// copying. It must be called on the thread where the VCM was constructed.
|
||||
virtual const VideoCodec& GetSendCodec() const = 0;
|
||||
|
||||
// DEPRECATED: Use GetSendCodec() instead.
|
||||
//
|
||||
// API to get the current send codec in use.
|
||||
//
|
||||
// Input:
|
||||
@ -139,12 +164,20 @@ public:
|
||||
//
|
||||
// Return value : VCM_OK, on success.
|
||||
// < 0, on error.
|
||||
//
|
||||
// NOTE: The returned codec information is not guaranteed to be current when
|
||||
// the call returns. This method acquires a lock that is aligned with
|
||||
// video encoding, so it should be assumed to be allowed to block for
|
||||
// several milliseconds.
|
||||
virtual int32_t SendCodec(VideoCodec* currentSendCodec) const = 0;
|
||||
|
||||
// DEPRECATED: Use GetSendCodec() instead.
|
||||
//
|
||||
// API to get the current send codec type
|
||||
//
|
||||
// Return value : Codec type, on success.
|
||||
// kVideoCodecUnknown, on error or if no send codec is set
|
||||
// NOTE: Same notes apply as for SendCodec() above.
|
||||
virtual VideoCodecType SendCodec() const = 0;
|
||||
|
||||
// Register an external encoder object. This can not be used together with
|
||||
|
Reference in New Issue
Block a user