|
36 | 36 | ObjCDesktopMediaList::ObjCDesktopMediaList(DesktopType type, |
37 | 37 | RTC_OBJC_TYPE(RTCDesktopMediaList)* objcMediaList) |
38 | 38 | :thread_(rtc::Thread::Create()),objcMediaList_(objcMediaList),type_(type) { |
| 39 | + RTC_DCHECK(thread_); |
| 40 | + thread_->Start(); |
39 | 41 | options_ = webrtc::DesktopCaptureOptions::CreateDefault(); |
40 | 42 | options_.set_detect_updated_region(true); |
41 | 43 | options_.set_allow_iosurface(true); |
42 | | - if (type == kScreen) { |
43 | | - capturer_ = webrtc::DesktopCapturer::CreateScreenCapturer(options_); |
44 | | - } else { |
45 | | - capturer_ = webrtc::DesktopCapturer::CreateWindowCapturer(options_); |
46 | | - } |
| 44 | + |
47 | 45 | callback_ = std::make_unique<CallbackProxy>(); |
48 | | - thread_->Start(); |
49 | | - capturer_->Start(callback_.get()); |
| 46 | + |
| 47 | + thread_->BlockingCall([this, type] { |
| 48 | + if (type == kScreen) { |
| 49 | + capturer_ = webrtc::DesktopCapturer::CreateScreenCapturer(options_); |
| 50 | + } else { |
| 51 | + capturer_ = webrtc::DesktopCapturer::CreateWindowCapturer(options_); |
| 52 | + } |
| 53 | + capturer_->Start(callback_.get()); |
| 54 | + }); |
| 55 | + |
50 | 56 | } |
51 | 57 |
|
52 | 58 | ObjCDesktopMediaList::~ObjCDesktopMediaList() { |
53 | | - thread_->Stop(); |
| 59 | + thread_->BlockingCall([this] { |
| 60 | + capturer_.reset(); |
| 61 | + }); |
54 | 62 | } |
55 | 63 |
|
56 | 64 | int32_t ObjCDesktopMediaList::UpdateSourceList(bool force_reload, bool get_thumbnail) { |
|
63 | 71 | } |
64 | 72 |
|
65 | 73 | webrtc::DesktopCapturer::SourceList new_sources; |
66 | | - capturer_->GetSourceList(&new_sources); |
| 74 | + |
| 75 | + thread_->BlockingCall([this,&new_sources] { |
| 76 | + capturer_->GetSourceList(&new_sources); |
| 77 | + }); |
67 | 78 |
|
68 | 79 | typedef std::set<DesktopCapturer::SourceId> SourceSet; |
69 | 80 | SourceSet new_source_set; |
|
91 | 102 | if (old_source_set.find(new_sources[i].id) == old_source_set.end()) { |
92 | 103 | MediaSource* source = new MediaSource(this, new_sources[i],type_); |
93 | 104 | sources_.insert(sources_.begin() + i, std::shared_ptr<MediaSource>(source)); |
94 | | - GetThumbnail(source, false); |
95 | 105 | [objcMediaList_ mediaSourceAdded:source]; |
| 106 | + GetThumbnail(source, true); |
96 | 107 | } |
97 | 108 | } |
98 | 109 | } |
|
135 | 146 | } |
136 | 147 |
|
137 | 148 | bool ObjCDesktopMediaList::GetThumbnail(MediaSource *source, bool notify) { |
138 | | - callback_->SetCallback([&](webrtc::DesktopCapturer::Result result, |
| 149 | + thread_->PostTask([this, source, notify] { |
| 150 | + if(capturer_->SelectSource(source->id())){ |
| 151 | + callback_->SetCallback([&](webrtc::DesktopCapturer::Result result, |
139 | 152 | std::unique_ptr<webrtc::DesktopFrame> frame) { |
140 | | - auto old_thumbnail = source->thumbnail(); |
141 | | - source->SaveCaptureResult(result, std::move(frame)); |
142 | | - if(old_thumbnail.size() != source->thumbnail().size() && notify) { |
143 | | - [objcMediaList_ mediaSourceThumbnailChanged:source]; |
144 | | - } |
| 153 | + auto old_thumbnail = source->thumbnail(); |
| 154 | + source->SaveCaptureResult(result, std::move(frame)); |
| 155 | + if(old_thumbnail.size() != source->thumbnail().size() && notify) { |
| 156 | + [objcMediaList_ mediaSourceThumbnailChanged:source]; |
| 157 | + } |
| 158 | + }); |
| 159 | + capturer_->CaptureFrame(); |
| 160 | + } |
145 | 161 | }); |
146 | | - if(capturer_->SelectSource(source->id())){ |
147 | | - capturer_->CaptureFrame(); |
148 | | - return true; |
149 | | - } |
150 | | - return false; |
| 162 | + |
| 163 | + return true; |
151 | 164 | } |
152 | 165 |
|
153 | 166 | int ObjCDesktopMediaList::GetSourceCount() const { |
|
0 commit comments