blob: 530e51a3c94bc812425e5c00696245781f5d819d [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;
15
tkchin0ce3bf92016-03-12 16:52:04 -080016@implementation RTCDispatcher
hayscedd8fef2015-12-08 11:08:39 -080017
18+ (void)initialize {
19 static dispatch_once_t onceToken;
20 dispatch_once(&onceToken, ^{
tkchin0ce3bf92016-03-12 16:52:04 -080021 kAudioSessionQueue = dispatch_queue_create(
22 "org.webrtc.RTCDispatcherAudioSession",
23 DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 11:08:39 -080024 kCaptureSessionQueue = dispatch_queue_create(
25 "org.webrtc.RTCDispatcherCaptureSession",
26 DISPATCH_QUEUE_SERIAL);
27 });
28}
29
30+ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType
31 block:(dispatch_block_t)block {
32 dispatch_queue_t queue = [self dispatchQueueForType:dispatchType];
33 dispatch_async(queue, block);
34}
35
sakalcee51412017-05-03 03:50:17 -070036+ (BOOL)isOnQueueForType:(RTCDispatcherQueueType)dispatchType {
37 dispatch_queue_t targetQueue = [self dispatchQueueForType:dispatchType];
38 const char* targetLabel = dispatch_queue_get_label(targetQueue);
39 const char* currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
40
41 NSAssert(strlen(targetLabel) > 0, @"Label is required for the target queue.");
42 NSAssert(strlen(currentLabel) > 0, @"Label is required for the current queue.");
43
44 return strcmp(targetLabel, currentLabel) == 0;
45}
46
hayscedd8fef2015-12-08 11:08:39 -080047#pragma mark - Private
48
49+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType {
50 switch (dispatchType) {
51 case RTCDispatcherTypeMain:
52 return dispatch_get_main_queue();
53 case RTCDispatcherTypeCaptureSession:
54 return kCaptureSessionQueue;
tkchin0ce3bf92016-03-12 16:52:04 -080055 case RTCDispatcherTypeAudioSession:
56 return kAudioSessionQueue;
hayscedd8fef2015-12-08 11:08:39 -080057 }
58}
59
60@end
61