blob: 4df19bc297015aa2be9cdcba0e69b5307f0e8b4f [file] [log] [blame]
hayscedd8fef2015-12-08 11:08:39 -08001/*
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
tkchin89717aa2016-03-31 17:14:04 -070011#import "RTCDispatcher+Private.h"
12
tkchin0ce3bf92016-03-12 16:52:04 -080013static dispatch_queue_t kAudioSessionQueue = nil;
hayscedd8fef2015-12-08 11:08:39 -080014static dispatch_queue_t kCaptureSessionQueue = nil;
Taylor Brandstetterea7fbfb2020-08-19 16:41:54 -070015static dispatch_queue_t kNetworkMonitorQueue = nil;
hayscedd8fef2015-12-08 11:08:39 -080016
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020017@implementation RTC_OBJC_TYPE (RTCDispatcher)
hayscedd8fef2015-12-08 11:08:39 -080018
19+ (void)initialize {
20 static dispatch_once_t onceToken;
21 dispatch_once(&onceToken, ^{
tkchin0ce3bf92016-03-12 16:52:04 -080022 kAudioSessionQueue = dispatch_queue_create(
23 "org.webrtc.RTCDispatcherAudioSession",
24 DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 11:08:39 -080025 kCaptureSessionQueue = dispatch_queue_create(
26 "org.webrtc.RTCDispatcherCaptureSession",
27 DISPATCH_QUEUE_SERIAL);
Taylor Brandstetterea7fbfb2020-08-19 16:41:54 -070028 kNetworkMonitorQueue =
29 dispatch_queue_create("org.webrtc.RTCDispatcherNetworkMonitor", DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 11:08:39 -080030 });
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
sakalcee51412017-05-03 03:50:17 -070039+ (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
hayscedd8fef2015-12-08 11:08:39 -080050#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;
tkchin0ce3bf92016-03-12 16:52:04 -080058 case RTCDispatcherTypeAudioSession:
59 return kAudioSessionQueue;
Taylor Brandstetterea7fbfb2020-08-19 16:41:54 -070060 case RTCDispatcherTypeNetworkMonitor:
61 return kNetworkMonitorQueue;
hayscedd8fef2015-12-08 11:08:39 -080062 }
63}
64
65@end