Split EventWrapper in twain.
I'm splitting the timer functions in EventWrapper into a separate interface. - Users of the timer functions have different needs than users of a generic event - Providing a default implementation for EventWrapper that simply uses rtc::Event. This means that clients of WebRTC that don't use the relatively few classes, typically rendering classes, that depend on the event timer functionality, also don't pull in dependencies on multimedia timers. R=mflodman@webrtc.org, mflodman BUG= Review URL: https://webrtc-codereview.appspot.com/48599004 Cr-Commit-Position: refs/heads/master@{#8833} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8833 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
82e8ae4ee8
commit
9509fbfc30
@ -247,14 +247,14 @@ int16_t APITest::SetUp() {
|
|||||||
|
|
||||||
//--- EVENT TIMERS
|
//--- EVENT TIMERS
|
||||||
// A
|
// A
|
||||||
_pullEventA = EventWrapper::Create();
|
_pullEventA = EventTimerWrapper::Create();
|
||||||
_pushEventA = EventWrapper::Create();
|
_pushEventA = EventTimerWrapper::Create();
|
||||||
_processEventA = EventWrapper::Create();
|
_processEventA = EventTimerWrapper::Create();
|
||||||
_apiEventA = EventWrapper::Create();
|
_apiEventA = EventWrapper::Create();
|
||||||
// B
|
// B
|
||||||
_pullEventB = EventWrapper::Create();
|
_pullEventB = EventTimerWrapper::Create();
|
||||||
_pushEventB = EventWrapper::Create();
|
_pushEventB = EventTimerWrapper::Create();
|
||||||
_processEventB = EventWrapper::Create();
|
_processEventB = EventTimerWrapper::Create();
|
||||||
_apiEventB = EventWrapper::Create();
|
_apiEventB = EventWrapper::Create();
|
||||||
|
|
||||||
//--- I/O params
|
//--- I/O params
|
||||||
@ -682,7 +682,7 @@ void APITest::TestDelay(char side) {
|
|||||||
AudioCodingModule* myACM;
|
AudioCodingModule* myACM;
|
||||||
Channel* myChannel;
|
Channel* myChannel;
|
||||||
int32_t* myMinDelay;
|
int32_t* myMinDelay;
|
||||||
EventWrapper* myEvent = EventWrapper::Create();
|
EventTimerWrapper* myEvent = EventTimerWrapper::Create();
|
||||||
|
|
||||||
uint32_t inTimestamp = 0;
|
uint32_t inTimestamp = 0;
|
||||||
uint32_t outTimestamp = 0;
|
uint32_t outTimestamp = 0;
|
||||||
|
@ -109,14 +109,14 @@ class APITest : public ACMTest {
|
|||||||
bool _writeToFile;
|
bool _writeToFile;
|
||||||
//--- Events
|
//--- Events
|
||||||
// A
|
// A
|
||||||
EventWrapper* _pullEventA; // pulling data from ACM
|
EventTimerWrapper* _pullEventA; // pulling data from ACM
|
||||||
EventWrapper* _pushEventA; // pushing data to ACM
|
EventTimerWrapper* _pushEventA; // pushing data to ACM
|
||||||
EventWrapper* _processEventA; // process
|
EventTimerWrapper* _processEventA; // process
|
||||||
EventWrapper* _apiEventA; // API calls
|
EventWrapper* _apiEventA; // API calls
|
||||||
// B
|
// B
|
||||||
EventWrapper* _pullEventB; // pulling data from ACM
|
EventTimerWrapper* _pullEventB; // pulling data from ACM
|
||||||
EventWrapper* _pushEventB; // pushing data to ACM
|
EventTimerWrapper* _pushEventB; // pushing data to ACM
|
||||||
EventWrapper* _processEventB; // process
|
EventTimerWrapper* _processEventB; // process
|
||||||
EventWrapper* _apiEventB; // API calls
|
EventWrapper* _apiEventB; // API calls
|
||||||
|
|
||||||
// keep track of the codec in either side.
|
// keep track of the codec in either side.
|
||||||
|
@ -292,7 +292,7 @@ void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
|
|||||||
|
|
||||||
char currentTime[500];
|
char currentTime[500];
|
||||||
CodecInst sendCodec;
|
CodecInst sendCodec;
|
||||||
EventWrapper* myEvent = EventWrapper::Create();
|
EventTimerWrapper* myEvent = EventTimerWrapper::Create();
|
||||||
EXPECT_TRUE(myEvent->StartTimer(true, 10));
|
EXPECT_TRUE(myEvent->StartTimer(true, 10));
|
||||||
while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
|
while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
|
||||||
Run10ms();
|
Run10ms();
|
||||||
|
@ -47,7 +47,7 @@ namespace webrtc {
|
|||||||
AudioDeviceWindowsWave::AudioDeviceWindowsWave(const int32_t id) :
|
AudioDeviceWindowsWave::AudioDeviceWindowsWave(const int32_t id) :
|
||||||
_ptrAudioBuffer(NULL),
|
_ptrAudioBuffer(NULL),
|
||||||
_critSect(*CriticalSectionWrapper::CreateCriticalSection()),
|
_critSect(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
_timeEvent(*EventWrapper::Create()),
|
_timeEvent(*EventTimerWrapper::Create()),
|
||||||
_recStartEvent(*EventWrapper::Create()),
|
_recStartEvent(*EventWrapper::Create()),
|
||||||
_playStartEvent(*EventWrapper::Create()),
|
_playStartEvent(*EventWrapper::Create()),
|
||||||
_hGetCaptureVolumeThread(NULL),
|
_hGetCaptureVolumeThread(NULL),
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#pragma comment( lib, "winmm.lib" )
|
#pragma comment( lib, "winmm.lib" )
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
class EventTimerWrapper;
|
||||||
class EventWrapper;
|
class EventWrapper;
|
||||||
|
|
||||||
const uint32_t TIMER_PERIOD_MS = 2;
|
const uint32_t TIMER_PERIOD_MS = 2;
|
||||||
@ -211,7 +212,7 @@ private:
|
|||||||
AudioDeviceBuffer* _ptrAudioBuffer;
|
AudioDeviceBuffer* _ptrAudioBuffer;
|
||||||
|
|
||||||
CriticalSectionWrapper& _critSect;
|
CriticalSectionWrapper& _critSect;
|
||||||
EventWrapper& _timeEvent;
|
EventTimerWrapper& _timeEvent;
|
||||||
EventWrapper& _recStartEvent;
|
EventWrapper& _recStartEvent;
|
||||||
EventWrapper& _playStartEvent;
|
EventWrapper& _playStartEvent;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ IncomingVideoStream::IncomingVideoStream(const int32_t module_id,
|
|||||||
thread_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
thread_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
buffer_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
buffer_critsect_(*CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
incoming_render_thread_(),
|
incoming_render_thread_(),
|
||||||
deliver_buffer_event_(*EventWrapper::Create()),
|
deliver_buffer_event_(*EventTimerWrapper::Create()),
|
||||||
running_(false),
|
running_(false),
|
||||||
external_callback_(NULL),
|
external_callback_(NULL),
|
||||||
render_callback_(NULL),
|
render_callback_(NULL),
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
class ThreadWrapper;
|
class ThreadWrapper;
|
||||||
class VideoRenderCallback;
|
class VideoRenderCallback;
|
||||||
class VideoRenderFrames;
|
class VideoRenderFrames;
|
||||||
@ -73,7 +73,7 @@ class IncomingVideoStream : public VideoRenderCallback {
|
|||||||
CriticalSectionWrapper& thread_critsect_;
|
CriticalSectionWrapper& thread_critsect_;
|
||||||
CriticalSectionWrapper& buffer_critsect_;
|
CriticalSectionWrapper& buffer_critsect_;
|
||||||
rtc::scoped_ptr<ThreadWrapper> incoming_render_thread_;
|
rtc::scoped_ptr<ThreadWrapper> incoming_render_thread_;
|
||||||
EventWrapper& deliver_buffer_event_;
|
EventTimerWrapper& deliver_buffer_event_;
|
||||||
bool running_;
|
bool running_;
|
||||||
|
|
||||||
VideoRenderCallback* external_callback_;
|
VideoRenderCallback* external_callback_;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
|
|
||||||
class VideoRenderIosGles20 {
|
class VideoRenderIosGles20 {
|
||||||
public:
|
public:
|
||||||
@ -63,7 +63,7 @@ class VideoRenderIosGles20 {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
rtc::scoped_ptr<CriticalSectionWrapper> gles_crit_sec_;
|
rtc::scoped_ptr<CriticalSectionWrapper> gles_crit_sec_;
|
||||||
EventWrapper* screen_update_event_;
|
EventTimerWrapper* screen_update_event_;
|
||||||
rtc::scoped_ptr<ThreadWrapper> screen_update_thread_;
|
rtc::scoped_ptr<ThreadWrapper> screen_update_thread_;
|
||||||
|
|
||||||
VideoRenderIosView* view_;
|
VideoRenderIosView* view_;
|
||||||
|
@ -34,7 +34,7 @@ VideoRenderIosGles20::VideoRenderIosGles20(VideoRenderIosView* view,
|
|||||||
is_rendering_(true) {
|
is_rendering_(true) {
|
||||||
screen_update_thread_ = ThreadWrapper::CreateThread(
|
screen_update_thread_ = ThreadWrapper::CreateThread(
|
||||||
ScreenUpdateThreadProc, this, "ScreenUpdateGles20");
|
ScreenUpdateThreadProc, this, "ScreenUpdateGles20");
|
||||||
screen_update_event_ = EventWrapper::Create();
|
screen_update_event_ = EventTimerWrapper::Create();
|
||||||
GetWindowRect(window_rect_);
|
GetWindowRect(window_rect_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,16 +31,13 @@
|
|||||||
class Trace;
|
class Trace;
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
class ThreadWrapper;
|
class ThreadWrapper;
|
||||||
class VideoRenderNSOpenGL;
|
class VideoRenderNSOpenGL;
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
|
|
||||||
class VideoChannelNSOpenGL : public VideoRenderCallback
|
class VideoChannelNSOpenGL : public VideoRenderCallback {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VideoChannelNSOpenGL(NSOpenGLContext *nsglContext, int iId, VideoRenderNSOpenGL* owner);
|
VideoChannelNSOpenGL(NSOpenGLContext *nsglContext, int iId, VideoRenderNSOpenGL* owner);
|
||||||
virtual ~VideoChannelNSOpenGL();
|
virtual ~VideoChannelNSOpenGL();
|
||||||
|
|
||||||
@ -170,7 +167,7 @@ private: // variables
|
|||||||
int _id;
|
int _id;
|
||||||
CriticalSectionWrapper& _nsglContextCritSec;
|
CriticalSectionWrapper& _nsglContextCritSec;
|
||||||
rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
|
rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
|
||||||
EventWrapper* _screenUpdateEvent;
|
EventTimerWrapper* _screenUpdateEvent;
|
||||||
NSOpenGLContext* _nsglContext;
|
NSOpenGLContext* _nsglContext;
|
||||||
NSOpenGLContext* _nsglFullScreenContext;
|
NSOpenGLContext* _nsglFullScreenContext;
|
||||||
CocoaFullScreenWindow* _fullScreenWindow;
|
CocoaFullScreenWindow* _fullScreenWindow;
|
||||||
|
@ -367,7 +367,7 @@ _windowRef( (CocoaRenderView*)windowRef),
|
|||||||
_fullScreen( fullScreen),
|
_fullScreen( fullScreen),
|
||||||
_id( iId),
|
_id( iId),
|
||||||
_nsglContextCritSec( *CriticalSectionWrapper::CreateCriticalSection()),
|
_nsglContextCritSec( *CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
_screenUpdateEvent( 0),
|
_screenUpdateEvent(EventTimerWrapper::Create()),
|
||||||
_nsglContext( 0),
|
_nsglContext( 0),
|
||||||
_nsglFullScreenContext( 0),
|
_nsglFullScreenContext( 0),
|
||||||
_fullScreenWindow( nil),
|
_fullScreenWindow( nil),
|
||||||
@ -382,7 +382,6 @@ _windowRefSuperViewFrame(NSMakeRect(0,0,0,0))
|
|||||||
{
|
{
|
||||||
_screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc,
|
_screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc,
|
||||||
this, "ScreenUpdateNSOpenGL");
|
this, "ScreenUpdateNSOpenGL");
|
||||||
_screenUpdateEvent = EventWrapper::Create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoRenderNSOpenGL::ChangeWindow(CocoaRenderView* newWindowRef)
|
int VideoRenderNSOpenGL::ChangeWindow(CocoaRenderView* newWindowRef)
|
||||||
|
@ -297,7 +297,7 @@ VideoRenderDirect3D9::VideoRenderDirect3D9(Trace* trace,
|
|||||||
{
|
{
|
||||||
_screenUpdateThread = ThreadWrapper::CreateThread(
|
_screenUpdateThread = ThreadWrapper::CreateThread(
|
||||||
ScreenUpdateThreadProc, this, "ScreenUpdateThread");
|
ScreenUpdateThreadProc, this, "ScreenUpdateThread");
|
||||||
_screenUpdateEvent = EventWrapper::Create();
|
_screenUpdateEvent = EventTimerWrapper::Create();
|
||||||
SetRect(&_originalHwndRect, 0, 0, 0, 0);
|
SetRect(&_originalHwndRect, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
class Trace;
|
class Trace;
|
||||||
|
|
||||||
class D3D9Channel: public VideoRenderCallback
|
class D3D9Channel: public VideoRenderCallback
|
||||||
@ -205,7 +205,7 @@ private:
|
|||||||
CriticalSectionWrapper& _refD3DCritsect;
|
CriticalSectionWrapper& _refD3DCritsect;
|
||||||
Trace* _trace;
|
Trace* _trace;
|
||||||
rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
|
rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
|
||||||
EventWrapper* _screenUpdateEvent;
|
EventTimerWrapper* _screenUpdateEvent;
|
||||||
|
|
||||||
HWND _hWnd;
|
HWND _hWnd;
|
||||||
bool _fullScreen;
|
bool _fullScreen;
|
||||||
|
@ -65,11 +65,11 @@ static_library("system_wrappers") {
|
|||||||
"source/critical_section_win.h",
|
"source/critical_section_win.h",
|
||||||
"source/data_log_c.cc",
|
"source/data_log_c.cc",
|
||||||
"source/event.cc",
|
"source/event.cc",
|
||||||
"source/event_posix.cc",
|
"source/event_timer_posix.cc",
|
||||||
"source/event_posix.h",
|
"source/event_timer_posix.h",
|
||||||
|
"source/event_timer_win.cc",
|
||||||
|
"source/event_timer_win.h",
|
||||||
"source/event_tracer.cc",
|
"source/event_tracer.cc",
|
||||||
"source/event_win.cc",
|
|
||||||
"source/event_win.h",
|
|
||||||
"source/file_impl.cc",
|
"source/file_impl.cc",
|
||||||
"source/file_impl.h",
|
"source/file_impl.h",
|
||||||
"source/logging.cc",
|
"source/logging.cc",
|
||||||
|
@ -18,13 +18,15 @@ enum EventTypeWrapper {
|
|||||||
kEventTimeout = 3
|
kEventTimeout = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
#define WEBRTC_EVENT_10_SEC 10000
|
|
||||||
#define WEBRTC_EVENT_INFINITE 0xffffffff
|
#define WEBRTC_EVENT_INFINITE 0xffffffff
|
||||||
|
|
||||||
|
class EventTimerWrapper;
|
||||||
|
|
||||||
class EventWrapper {
|
class EventWrapper {
|
||||||
public:
|
public:
|
||||||
// Factory method. Constructor disabled.
|
// Factory method. Constructor disabled.
|
||||||
static EventWrapper* Create();
|
static EventWrapper* Create();
|
||||||
|
|
||||||
virtual ~EventWrapper() {}
|
virtual ~EventWrapper() {}
|
||||||
|
|
||||||
// Releases threads who are calling Wait() and has started waiting. Please
|
// Releases threads who are calling Wait() and has started waiting. Please
|
||||||
@ -43,6 +45,11 @@ class EventWrapper {
|
|||||||
// be released. It is possible that multiple (random) threads are released
|
// be released. It is possible that multiple (random) threads are released
|
||||||
// Depending on timing.
|
// Depending on timing.
|
||||||
virtual EventTypeWrapper Wait(unsigned long max_time) = 0;
|
virtual EventTypeWrapper Wait(unsigned long max_time) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventTimerWrapper : public EventWrapper {
|
||||||
|
public:
|
||||||
|
static EventTimerWrapper* Create();
|
||||||
|
|
||||||
// Starts a timer that will call a non-sticky version of Set() either once
|
// Starts a timer that will call a non-sticky version of Set() either once
|
||||||
// or periodically. If the timer is periodic it ensures that there is no
|
// or periodically. If the timer is periodic it ensures that there is no
|
||||||
@ -52,6 +59,7 @@ class EventWrapper {
|
|||||||
virtual bool StopTimer() = 0;
|
virtual bool StopTimer() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_
|
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_
|
||||||
|
@ -12,22 +12,43 @@
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "webrtc/system_wrappers/source/event_win.h"
|
#include "webrtc/system_wrappers/source/event_timer_win.h"
|
||||||
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "webrtc/system_wrappers/source/event_posix.h"
|
#include "webrtc/system_wrappers/source/event_timer_posix.h"
|
||||||
#else
|
#else
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "webrtc/system_wrappers/source/event_posix.h"
|
#include "webrtc/system_wrappers/source/event_timer_posix.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "webrtc/base/event.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
class EventWrapperImpl : public EventWrapper {
|
||||||
|
public:
|
||||||
|
EventWrapperImpl() : event_(false, false) {}
|
||||||
|
~EventWrapperImpl() override {}
|
||||||
|
|
||||||
|
bool Set() override {
|
||||||
|
event_.Set();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTypeWrapper Wait(unsigned long max_time) override {
|
||||||
|
int to_wait = max_time == WEBRTC_EVENT_INFINITE ?
|
||||||
|
rtc::Event::kForever : static_cast<int>(max_time);
|
||||||
|
return event_.Wait(to_wait) ? kEventSignaled : kEventTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
rtc::Event event_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// static
|
||||||
EventWrapper* EventWrapper::Create() {
|
EventWrapper* EventWrapper::Create() {
|
||||||
#if defined(_WIN32)
|
return new EventWrapperImpl();
|
||||||
return new EventWindows();
|
|
||||||
#else
|
|
||||||
return EventPosix::Create();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/system_wrappers/source/event_posix.h"
|
#include "webrtc/system_wrappers/source/event_timer_posix.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -22,17 +22,17 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
// static
|
||||||
|
EventTimerWrapper* EventTimerWrapper::Create() {
|
||||||
|
return new EventTimerPosix();
|
||||||
|
}
|
||||||
|
|
||||||
const long int E6 = 1000000;
|
const long int E6 = 1000000;
|
||||||
const long int E9 = 1000 * E6;
|
const long int E9 = 1000 * E6;
|
||||||
|
|
||||||
EventWrapper* EventPosix::Create() {
|
EventTimerPosix::EventTimerPosix()
|
||||||
return new EventPosix();
|
|
||||||
}
|
|
||||||
|
|
||||||
EventPosix::EventPosix()
|
|
||||||
: event_set_(false),
|
: event_set_(false),
|
||||||
timer_thread_(nullptr),
|
timer_thread_(nullptr),
|
||||||
timer_event_(0),
|
|
||||||
created_at_(),
|
created_at_(),
|
||||||
periodic_(false),
|
periodic_(false),
|
||||||
time_(0),
|
time_(0),
|
||||||
@ -52,14 +52,14 @@ EventPosix::EventPosix()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
EventPosix::~EventPosix() {
|
EventTimerPosix::~EventTimerPosix() {
|
||||||
StopTimer();
|
StopTimer();
|
||||||
pthread_cond_destroy(&cond_);
|
pthread_cond_destroy(&cond_);
|
||||||
pthread_mutex_destroy(&mutex_);
|
pthread_mutex_destroy(&mutex_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(pbos): Make this void.
|
// TODO(pbos): Make this void.
|
||||||
bool EventPosix::Set() {
|
bool EventTimerPosix::Set() {
|
||||||
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
||||||
event_set_ = true;
|
event_set_ = true;
|
||||||
pthread_cond_signal(&cond_);
|
pthread_cond_signal(&cond_);
|
||||||
@ -67,7 +67,7 @@ bool EventPosix::Set() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTypeWrapper EventPosix::Wait(unsigned long timeout) {
|
EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout) {
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ EventTypeWrapper EventPosix::Wait(unsigned long timeout) {
|
|||||||
return ret_val == 0 ? kEventSignaled : kEventTimeout;
|
return ret_val == 0 ? kEventSignaled : kEventTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTypeWrapper EventPosix::Wait(timespec* end_at) {
|
EventTypeWrapper EventTimerPosix::Wait(timespec* end_at) {
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
CHECK_EQ(0, pthread_mutex_lock(&mutex_));
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ EventTypeWrapper EventPosix::Wait(timespec* end_at) {
|
|||||||
return ret_val == 0 ? kEventSignaled : kEventTimeout;
|
return ret_val == 0 ? kEventSignaled : kEventTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventPosix::StartTimer(bool periodic, unsigned long time) {
|
bool EventTimerPosix::StartTimer(bool periodic, unsigned long time) {
|
||||||
pthread_mutex_lock(&mutex_);
|
pthread_mutex_lock(&mutex_);
|
||||||
if (timer_thread_) {
|
if (timer_thread_) {
|
||||||
if (periodic_) {
|
if (periodic_) {
|
||||||
@ -152,7 +152,7 @@ bool EventPosix::StartTimer(bool periodic, unsigned long time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the timer thread
|
// Start the timer thread
|
||||||
timer_event_ = static_cast<EventPosix*>(EventWrapper::Create());
|
timer_event_.reset(new EventTimerPosix());
|
||||||
const char* thread_name = "WebRtc_event_timer_thread";
|
const char* thread_name = "WebRtc_event_timer_thread";
|
||||||
timer_thread_ = ThreadWrapper::CreateThread(Run, this, thread_name);
|
timer_thread_ = ThreadWrapper::CreateThread(Run, this, thread_name);
|
||||||
periodic_ = periodic;
|
periodic_ = periodic;
|
||||||
@ -164,11 +164,11 @@ bool EventPosix::StartTimer(bool periodic, unsigned long time) {
|
|||||||
return started;
|
return started;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventPosix::Run(void* obj) {
|
bool EventTimerPosix::Run(void* obj) {
|
||||||
return static_cast<EventPosix*>(obj)->Process();
|
return static_cast<EventTimerPosix*>(obj)->Process();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventPosix::Process() {
|
bool EventTimerPosix::Process() {
|
||||||
pthread_mutex_lock(&mutex_);
|
pthread_mutex_lock(&mutex_);
|
||||||
if (created_at_.tv_sec == 0) {
|
if (created_at_.tv_sec == 0) {
|
||||||
#ifndef WEBRTC_MAC
|
#ifndef WEBRTC_MAC
|
||||||
@ -210,7 +210,7 @@ bool EventPosix::Process() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventPosix::StopTimer() {
|
bool EventTimerPosix::StopTimer() {
|
||||||
if (timer_event_) {
|
if (timer_event_) {
|
||||||
timer_event_->Set();
|
timer_event_->Set();
|
||||||
}
|
}
|
||||||
@ -220,10 +220,7 @@ bool EventPosix::StopTimer() {
|
|||||||
}
|
}
|
||||||
timer_thread_.reset();
|
timer_thread_.reset();
|
||||||
}
|
}
|
||||||
if (timer_event_) {
|
timer_event_.reset();
|
||||||
delete timer_event_;
|
|
||||||
timer_event_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set time to zero to force new reference time for the timer.
|
// Set time to zero to force new reference time for the timer.
|
||||||
memset(&created_at_, 0, sizeof(created_at_));
|
memset(&created_at_, 0, sizeof(created_at_));
|
@ -25,11 +25,10 @@ enum State {
|
|||||||
kDown = 2
|
kDown = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventPosix : public EventWrapper {
|
class EventTimerPosix : public EventTimerWrapper {
|
||||||
public:
|
public:
|
||||||
static EventWrapper* Create();
|
EventTimerPosix();
|
||||||
|
~EventTimerPosix() override;
|
||||||
~EventPosix() override;
|
|
||||||
|
|
||||||
EventTypeWrapper Wait(unsigned long max_time) override;
|
EventTypeWrapper Wait(unsigned long max_time) override;
|
||||||
bool Set() override;
|
bool Set() override;
|
||||||
@ -38,8 +37,6 @@ class EventPosix : public EventWrapper {
|
|||||||
bool StopTimer() override;
|
bool StopTimer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventPosix();
|
|
||||||
|
|
||||||
static bool Run(void* obj);
|
static bool Run(void* obj);
|
||||||
bool Process();
|
bool Process();
|
||||||
EventTypeWrapper Wait(timespec* end_at);
|
EventTypeWrapper Wait(timespec* end_at);
|
||||||
@ -50,7 +47,7 @@ class EventPosix : public EventWrapper {
|
|||||||
bool event_set_;
|
bool event_set_;
|
||||||
|
|
||||||
rtc::scoped_ptr<ThreadWrapper> timer_thread_;
|
rtc::scoped_ptr<ThreadWrapper> timer_thread_;
|
||||||
EventPosix* timer_event_;
|
rtc::scoped_ptr<EventTimerPosix> timer_event_;
|
||||||
timespec created_at_;
|
timespec created_at_;
|
||||||
|
|
||||||
bool periodic_;
|
bool periodic_;
|
@ -8,13 +8,18 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/system_wrappers/source/event_win.h"
|
#include "webrtc/system_wrappers/source/event_timer_win.h"
|
||||||
|
|
||||||
#include "Mmsystem.h"
|
#include "Mmsystem.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
EventWindows::EventWindows()
|
// static
|
||||||
|
EventTimerWrapper* EventTimerWrapper::Create() {
|
||||||
|
return new EventTimerWin();
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTimerWin::EventTimerWin()
|
||||||
: event_(::CreateEvent(NULL, // security attributes
|
: event_(::CreateEvent(NULL, // security attributes
|
||||||
FALSE, // manual reset
|
FALSE, // manual reset
|
||||||
FALSE, // initial state
|
FALSE, // initial state
|
||||||
@ -22,17 +27,17 @@ EventWindows::EventWindows()
|
|||||||
timerID_(NULL) {
|
timerID_(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
EventWindows::~EventWindows() {
|
EventTimerWin::~EventTimerWin() {
|
||||||
StopTimer();
|
StopTimer();
|
||||||
CloseHandle(event_);
|
CloseHandle(event_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventWindows::Set() {
|
bool EventTimerWin::Set() {
|
||||||
// Note: setting an event that is already set has no effect.
|
// Note: setting an event that is already set has no effect.
|
||||||
return SetEvent(event_) == 1;
|
return SetEvent(event_) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTypeWrapper EventWindows::Wait(unsigned long max_time) {
|
EventTypeWrapper EventTimerWin::Wait(unsigned long max_time) {
|
||||||
unsigned long res = WaitForSingleObject(event_, max_time);
|
unsigned long res = WaitForSingleObject(event_, max_time);
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
@ -44,7 +49,7 @@ EventTypeWrapper EventWindows::Wait(unsigned long max_time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventWindows::StartTimer(bool periodic, unsigned long time) {
|
bool EventTimerWin::StartTimer(bool periodic, unsigned long time) {
|
||||||
if (timerID_ != NULL) {
|
if (timerID_ != NULL) {
|
||||||
timeKillEvent(timerID_);
|
timeKillEvent(timerID_);
|
||||||
timerID_ = NULL;
|
timerID_ = NULL;
|
||||||
@ -61,7 +66,7 @@ bool EventWindows::StartTimer(bool periodic, unsigned long time) {
|
|||||||
return timerID_ != NULL;
|
return timerID_ != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventWindows::StopTimer() {
|
bool EventTimerWin::StopTimer() {
|
||||||
if (timerID_ != NULL) {
|
if (timerID_ != NULL) {
|
||||||
timeKillEvent(timerID_);
|
timeKillEvent(timerID_);
|
||||||
timerID_ = NULL;
|
timerID_ = NULL;
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class EventWindows : public EventWrapper {
|
class EventTimerWin : public EventTimerWrapper {
|
||||||
public:
|
public:
|
||||||
EventWindows();
|
EventTimerWin();
|
||||||
virtual ~EventWindows();
|
virtual ~EventTimerWin();
|
||||||
|
|
||||||
virtual EventTypeWrapper Wait(unsigned long max_time);
|
virtual EventTypeWrapper Wait(unsigned long max_time);
|
||||||
virtual bool Set();
|
virtual bool Set();
|
@ -75,11 +75,11 @@
|
|||||||
'source/data_log_c.cc',
|
'source/data_log_c.cc',
|
||||||
'source/data_log_no_op.cc',
|
'source/data_log_no_op.cc',
|
||||||
'source/event.cc',
|
'source/event.cc',
|
||||||
'source/event_posix.cc',
|
'source/event_timer_posix.cc',
|
||||||
'source/event_posix.h',
|
'source/event_timer_posix.h',
|
||||||
|
'source/event_timer_win.cc',
|
||||||
|
'source/event_timer_win.h',
|
||||||
'source/event_tracer.cc',
|
'source/event_tracer.cc',
|
||||||
'source/event_win.cc',
|
|
||||||
'source/event_win.h',
|
|
||||||
'source/file_impl.cc',
|
'source/file_impl.cc',
|
||||||
'source/file_impl.h',
|
'source/file_impl.h',
|
||||||
'source/logcat_trace_context.cc',
|
'source/logcat_trace_context.cc',
|
||||||
|
@ -30,7 +30,7 @@ FakeAudioDevice::FakeAudioDevice(Clock* clock, const std::string& filename)
|
|||||||
playout_buffer_(),
|
playout_buffer_(),
|
||||||
last_playout_ms_(-1),
|
last_playout_ms_(-1),
|
||||||
clock_(clock),
|
clock_(clock),
|
||||||
tick_(EventWrapper::Create()),
|
tick_(EventTimerWrapper::Create()),
|
||||||
lock_(CriticalSectionWrapper::CreateCriticalSection()),
|
lock_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
file_utility_(new ModuleFileUtility(0)),
|
file_utility_(new ModuleFileUtility(0)),
|
||||||
input_stream_(FileWrapper::Create()) {
|
input_stream_(FileWrapper::Create()) {
|
||||||
|
@ -20,7 +20,7 @@ namespace webrtc {
|
|||||||
|
|
||||||
class Clock;
|
class Clock;
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
class FileWrapper;
|
class FileWrapper;
|
||||||
class ModuleFileUtility;
|
class ModuleFileUtility;
|
||||||
class ThreadWrapper;
|
class ThreadWrapper;
|
||||||
@ -57,7 +57,7 @@ class FakeAudioDevice : public FakeAudioDeviceModule {
|
|||||||
int64_t last_playout_ms_;
|
int64_t last_playout_ms_;
|
||||||
|
|
||||||
Clock* clock_;
|
Clock* clock_;
|
||||||
rtc::scoped_ptr<EventWrapper> tick_;
|
rtc::scoped_ptr<EventTimerWrapper> tick_;
|
||||||
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
|
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
|
||||||
rtc::scoped_ptr<ThreadWrapper> thread_;
|
rtc::scoped_ptr<ThreadWrapper> thread_;
|
||||||
rtc::scoped_ptr<ModuleFileUtility> file_utility_;
|
rtc::scoped_ptr<ModuleFileUtility> file_utility_;
|
||||||
|
@ -65,7 +65,7 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(Clock* clock,
|
|||||||
: VideoCapturer(input),
|
: VideoCapturer(input),
|
||||||
clock_(clock),
|
clock_(clock),
|
||||||
sending_(false),
|
sending_(false),
|
||||||
tick_(EventWrapper::Create()),
|
tick_(EventTimerWrapper::Create()),
|
||||||
lock_(CriticalSectionWrapper::CreateCriticalSection()),
|
lock_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
frame_generator_(frame_generator),
|
frame_generator_(frame_generator),
|
||||||
target_fps_(target_fps),
|
target_fps_(target_fps),
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventTimerWrapper;
|
||||||
class ThreadWrapper;
|
class ThreadWrapper;
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
@ -60,7 +60,7 @@ class FrameGeneratorCapturer : public VideoCapturer {
|
|||||||
Clock* const clock_;
|
Clock* const clock_;
|
||||||
bool sending_;
|
bool sending_;
|
||||||
|
|
||||||
rtc::scoped_ptr<EventWrapper> tick_;
|
rtc::scoped_ptr<EventTimerWrapper> tick_;
|
||||||
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
|
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
|
||||||
rtc::scoped_ptr<ThreadWrapper> thread_;
|
rtc::scoped_ptr<ThreadWrapper> thread_;
|
||||||
rtc::scoped_ptr<FrameGenerator> frame_generator_;
|
rtc::scoped_ptr<FrameGenerator> frame_generator_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user