haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
tkchin | 89717aa | 2016-04-01 00:14:04 | [diff] [blame] | 11 | #import "RTCDispatcher+Private.h" |
| 12 | |
tkchin | 0ce3bf9 | 2016-03-13 00:52:04 | [diff] [blame] | 13 | static dispatch_queue_t kAudioSessionQueue = nil; |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 14 | static dispatch_queue_t kCaptureSessionQueue = nil; |
Taylor Brandstetter | ea7fbfb | 2020-08-19 23:41:54 | [diff] [blame] | 15 | static dispatch_queue_t kNetworkMonitorQueue = nil; |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 16 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 14:14:32 | [diff] [blame] | 17 | @implementation RTC_OBJC_TYPE (RTCDispatcher) |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 18 | |
| 19 | + (void)initialize { |
| 20 | static dispatch_once_t onceToken; |
| 21 | dispatch_once(&onceToken, ^{ |
tkchin | 0ce3bf9 | 2016-03-13 00:52:04 | [diff] [blame] | 22 | kAudioSessionQueue = dispatch_queue_create( |
| 23 | "org.webrtc.RTCDispatcherAudioSession", |
| 24 | DISPATCH_QUEUE_SERIAL); |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 25 | kCaptureSessionQueue = dispatch_queue_create( |
| 26 | "org.webrtc.RTCDispatcherCaptureSession", |
| 27 | DISPATCH_QUEUE_SERIAL); |
Taylor Brandstetter | ea7fbfb | 2020-08-19 23:41:54 | [diff] [blame] | 28 | kNetworkMonitorQueue = |
| 29 | dispatch_queue_create("org.webrtc.RTCDispatcherNetworkMonitor", DISPATCH_QUEUE_SERIAL); |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 30 | }); |
| 31 | } |
| 32 | |
| 33 | + (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType |
| 34 | block:(dispatch_block_t)block { |
| 35 | dispatch_queue_t queue = [self dispatchQueueForType:dispatchType]; |
| 36 | dispatch_async(queue, block); |
| 37 | } |
| 38 | |
sakal | cee5141 | 2017-05-03 10:50:17 | [diff] [blame] | 39 | + (BOOL)isOnQueueForType:(RTCDispatcherQueueType)dispatchType { |
| 40 | dispatch_queue_t targetQueue = [self dispatchQueueForType:dispatchType]; |
| 41 | const char* targetLabel = dispatch_queue_get_label(targetQueue); |
| 42 | const char* currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); |
| 43 | |
| 44 | NSAssert(strlen(targetLabel) > 0, @"Label is required for the target queue."); |
| 45 | NSAssert(strlen(currentLabel) > 0, @"Label is required for the current queue."); |
| 46 | |
| 47 | return strcmp(targetLabel, currentLabel) == 0; |
| 48 | } |
| 49 | |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 50 | #pragma mark - Private |
| 51 | |
| 52 | + (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType { |
| 53 | switch (dispatchType) { |
| 54 | case RTCDispatcherTypeMain: |
| 55 | return dispatch_get_main_queue(); |
| 56 | case RTCDispatcherTypeCaptureSession: |
| 57 | return kCaptureSessionQueue; |
tkchin | 0ce3bf9 | 2016-03-13 00:52:04 | [diff] [blame] | 58 | case RTCDispatcherTypeAudioSession: |
| 59 | return kAudioSessionQueue; |
Taylor Brandstetter | ea7fbfb | 2020-08-19 23:41:54 | [diff] [blame] | 60 | case RTCDispatcherTypeNetworkMonitor: |
| 61 | return kNetworkMonitorQueue; |
haysc | edd8fef | 2015-12-08 19:08:39 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | @end |