blob: 4df19bc297015aa2be9cdcba0e69b5307f0e8b4f [file] [log] [blame]
hayscedd8fef2015-12-08 19:08:391/*
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-04-01 00:14:0411#import "RTCDispatcher+Private.h"
12
tkchin0ce3bf92016-03-13 00:52:0413static dispatch_queue_t kAudioSessionQueue = nil;
hayscedd8fef2015-12-08 19:08:3914static dispatch_queue_t kCaptureSessionQueue = nil;
Taylor Brandstetterea7fbfb2020-08-19 23:41:5415static dispatch_queue_t kNetworkMonitorQueue = nil;
hayscedd8fef2015-12-08 19:08:3916
Mirko Bonadeia81e9c82020-05-04 14:14:3217@implementation RTC_OBJC_TYPE (RTCDispatcher)
hayscedd8fef2015-12-08 19:08:3918
19+ (void)initialize {
20 static dispatch_once_t onceToken;
21 dispatch_once(&onceToken, ^{
tkchin0ce3bf92016-03-13 00:52:0422 kAudioSessionQueue = dispatch_queue_create(
23 "org.webrtc.RTCDispatcherAudioSession",
24 DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 19:08:3925 kCaptureSessionQueue = dispatch_queue_create(
26 "org.webrtc.RTCDispatcherCaptureSession",
27 DISPATCH_QUEUE_SERIAL);
Taylor Brandstetterea7fbfb2020-08-19 23:41:5428 kNetworkMonitorQueue =
29 dispatch_queue_create("org.webrtc.RTCDispatcherNetworkMonitor", DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 19:08:3930 });
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 10:50:1739+ (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 19:08:3950#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-13 00:52:0458 case RTCDispatcherTypeAudioSession:
59 return kAudioSessionQueue;
Taylor Brandstetterea7fbfb2020-08-19 23:41:5460 case RTCDispatcherTypeNetworkMonitor:
61 return kNetworkMonitorQueue;
hayscedd8fef2015-12-08 19:08:3962 }
63}
64
65@end