Bug 1371000 - add expiration to noncamera device info;r=jib

MozReview-Commit-ID: 406sbEpJfbk

--HG--
extra : rebase_source : 49f4438a4fe6cbf55db5d535bd8b257c343e4d4d
This commit is contained in:
Nico Grunbaum 2017-06-13 17:24:54 -07:00
Родитель 19e8dfd20b
Коммит ebd633ae0a
2 изменённых файлов: 39 добавлений и 9 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "VideoEngine.h"
#include "webrtc/video_engine/browser_capture_impl.h"
#include "webrtc/system_wrappers/include/clock.h"
#ifdef WEBRTC_ANDROID
#include "webrtc/modules/video_capture/video_capture.h"
#endif
@ -21,7 +22,6 @@ mozilla::LazyLogModule gVideoEngineLog("VideoEngine");
#define LOG_ENABLED() MOZ_LOG_TEST(gVideoEngineLog, mozilla::LogLevel::Debug)
int VideoEngine::sId = 0;
#if defined(ANDROID)
int VideoEngine::SetAndroidObjects(JavaVM* javaVM) {
LOG((__PRETTY_FUNCTION__));
@ -59,7 +59,7 @@ VideoEngine::CreateVideoCapture(int32_t& id, const char* deviceUniqueIdUTF8) {
MOZ_ASSERT("CreateVideoCapture NO DESKTOP CAPTURE IMPL ON ANDROID" == nullptr);
#endif
}
mCaps.emplace(id,std::move(entry));
mCaps.emplace(id, std::move(entry));
}
int
@ -74,9 +74,32 @@ VideoEngine::ReleaseVideoCapture(const int32_t id) {
std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo>
VideoEngine::GetOrCreateVideoCaptureDeviceInfo() {
LOG((__PRETTY_FUNCTION__));
int64_t currentTime = 0;
const char * capDevTypeName =
webrtc::CaptureDeviceInfo(mCaptureDevInfo.type).TypeName();
if (mDeviceInfo) {
return mDeviceInfo;
// Camera cache is invalidated by HW change detection elsewhere
if (mCaptureDevInfo.type == webrtc::CaptureDeviceType::Camera) {
LOG(("returning cached CaptureDeviceInfo of type %s", capDevTypeName));
return mDeviceInfo;
}
// Screen sharing cache is invalidated after the expiration time
currentTime = webrtc::Clock::GetRealTimeClock()->TimeInMilliseconds();
if (currentTime <= mExpiryTimeInMs) {
LOG(("returning cached CaptureDeviceInfo of type %s", capDevTypeName));
return mDeviceInfo;
}
}
if (currentTime == 0) {
currentTime = webrtc::Clock::GetRealTimeClock()->TimeInMilliseconds();
}
mExpiryTimeInMs = currentTime + kCacheExpiryPeriodMs;
LOG(("creating a new VideoCaptureDeviceInfo of type %s", capDevTypeName));
switch (mCaptureDevInfo.type) {
case webrtc::CaptureDeviceType::Camera: {
mDeviceInfo.reset(webrtc::VideoCaptureFactory::CreateDeviceInfo());

Просмотреть файл

@ -26,6 +26,10 @@ class VideoEngine
{
private:
virtual ~VideoEngine (){};
// Base cache expiration period
// Note because cameras use HW plug event detection, this
// only applies to screen based modes.
static const int64_t kCacheExpiryPeriodMs = 1000;
public:
VideoEngine (){};
@ -42,11 +46,13 @@ public:
// VideoEngine is responsible for any cleanup in its modules
static void Delete(VideoEngine * engine) { }
/** Returns or creates a new new DeviceInfo.
* It is cached to prevent repeated lengthy polling for "realness"
* of the hardware devices. This could be handled in a more elegant
* way in the future.
* @return on failure the shared_ptr will be null, otherwise it will contain a DeviceInfo.
/** Returns an existing or creates a new new DeviceInfo.
* Camera info is cached to prevent repeated lengthy polling for "realness"
* of the hardware devices. Other types of capture, e.g. screen share info,
* are cached for 1 second. This could be handled in a more elegant way in
* the future.
* @return on failure the shared_ptr will be null, otherwise it will contain
* a DeviceInfo.
* @see bug 1305212 https://bugzilla.mozilla.org/show_bug.cgi?id=1305212
*/
std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo> GetOrCreateVideoCaptureDeviceInfo();
@ -88,7 +94,8 @@ private:
std::shared_ptr<webrtc::VideoCaptureModule::DeviceInfo> mDeviceInfo;
UniquePtr<const webrtc::Config> mConfig;
std::map<int32_t, CaptureEntry> mCaps;
// The validity period for non-camera capture device infos`
int64_t mExpiryTimeInMs = 0;
int32_t GenerateId();
static int32_t sId;
};