14
14
#include < memory>
15
15
16
16
#include " modules/video_capture/video_capture_factory.h"
17
- #include " rtc_base/checks.h"
18
- #include " rtc_base/logging.h"
17
+ #include " webrtc/rtc_base/bind.h"
18
+ #include " webrtc/rtc_base/checks.h"
19
+ #include " webrtc/rtc_base/logging.h"
19
20
20
21
// This file is borrowed from webrtc project.
21
22
namespace owt {
22
23
namespace base {
23
24
24
- VcmCapturer::VcmCapturer () : vcm_(nullptr ) {}
25
+ VcmCapturer::VcmCapturer ()
26
+ : vcm_(nullptr ),
27
+ vcm_thread_ (rtc::Thread::CreateWithSocketServer()) {
28
+ vcm_thread_->Start ();
29
+ }
25
30
26
31
bool VcmCapturer::Init (size_t width,
27
32
size_t height,
@@ -39,7 +44,10 @@ bool VcmCapturer::Init(size_t width,
39
44
return false ;
40
45
}
41
46
42
- vcm_ = webrtc::VideoCaptureFactory::Create (unique_name);
47
+ vcm_ = vcm_thread_->Invoke <rtc::scoped_refptr<webrtc::VideoCaptureModule>>(
48
+ RTC_FROM_HERE,
49
+ Bind (&VcmCapturer::CreateDeviceOnVCMThread, this ,
50
+ unique_name));
43
51
if (!vcm_) {
44
52
return false ;
45
53
}
@@ -52,15 +60,33 @@ bool VcmCapturer::Init(size_t width,
52
60
capability_.maxFPS = static_cast <int32_t >(target_fps);
53
61
capability_.videoType = webrtc::VideoType::kI420 ;
54
62
55
- if (vcm_->StartCapture (capability_) != 0 ) {
63
+ if (vcm_thread_->Invoke <int32_t >(
64
+ RTC_FROM_HERE,
65
+ Bind (&VcmCapturer::StartCaptureOnVCMThread, this , capability_)) != 0 ) {
56
66
Destroy ();
57
67
return false ;
58
68
}
59
69
60
- RTC_CHECK (vcm_->CaptureStarted ());
61
-
62
70
return true ;
63
71
}
72
+ rtc::scoped_refptr<webrtc::VideoCaptureModule>
73
+ VcmCapturer::CreateDeviceOnVCMThread (
74
+ const char * unique_device_utf8) {
75
+ return webrtc::VideoCaptureFactory::Create (unique_device_utf8);
76
+ }
77
+
78
+ int32_t VcmCapturer::StartCaptureOnVCMThread (
79
+ webrtc::VideoCaptureCapability capability) {
80
+ return vcm_->StartCapture (capability);
81
+ }
82
+
83
+ int32_t VcmCapturer::StopCaptureOnVCMThread () {
84
+ return vcm_->StopCapture ();
85
+ }
86
+
87
+ void VcmCapturer::ReleaseOnVCMThread () {
88
+ vcm_ = nullptr ;
89
+ }
64
90
65
91
VcmCapturer* VcmCapturer::Create (size_t width,
66
92
size_t height,
@@ -80,14 +106,17 @@ void VcmCapturer::Destroy() {
80
106
if (!vcm_)
81
107
return ;
82
108
83
- vcm_->StopCapture ();
109
+ vcm_thread_->Invoke <int32_t >(RTC_FROM_HERE,
110
+ Bind (&VcmCapturer::StopCaptureOnVCMThread, this ));
84
111
vcm_->DeRegisterCaptureDataCallback ();
85
112
// Release reference to VCM.
86
- vcm_ = nullptr ;
113
+ vcm_thread_->Invoke <void >(RTC_FROM_HERE,
114
+ Bind (&VcmCapturer::ReleaseOnVCMThread, this ));
87
115
}
88
116
89
117
VcmCapturer::~VcmCapturer () {
90
118
Destroy ();
119
+ vcm_thread_->Stop ();
91
120
}
92
121
93
122
void VcmCapturer::OnFrame (const webrtc::VideoFrame& frame) {
0 commit comments