blob: dc2a990dfc38a033cf695cacc07ffa27ab7ddc11 [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
11#import "RTCDispatcher.h"
12
tkchin89717aa2016-03-31 17:14:04 -070013#import "RTCDispatcher+Private.h"
14
tkchin0ce3bf92016-03-12 16:52:04 -080015static dispatch_queue_t kAudioSessionQueue = nil;
hayscedd8fef2015-12-08 11:08:39 -080016static dispatch_queue_t kCaptureSessionQueue = nil;
17
tkchin0ce3bf92016-03-12 16:52:04 -080018@implementation RTCDispatcher
hayscedd8fef2015-12-08 11:08:39 -080019
20+ (void)initialize {
21 static dispatch_once_t onceToken;
22 dispatch_once(&onceToken, ^{
tkchin0ce3bf92016-03-12 16:52:04 -080023 kAudioSessionQueue = dispatch_queue_create(
24 "org.webrtc.RTCDispatcherAudioSession",
25 DISPATCH_QUEUE_SERIAL);
hayscedd8fef2015-12-08 11:08:39 -080026 kCaptureSessionQueue = dispatch_queue_create(
27 "org.webrtc.RTCDispatcherCaptureSession",
28 DISPATCH_QUEUE_SERIAL);
29 });
30}
31
32+ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType
33 block:(dispatch_block_t)block {
34 dispatch_queue_t queue = [self dispatchQueueForType:dispatchType];
35 dispatch_async(queue, block);
36}
37
38#pragma mark - Private
39
40+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType {
41 switch (dispatchType) {
42 case RTCDispatcherTypeMain:
43 return dispatch_get_main_queue();
44 case RTCDispatcherTypeCaptureSession:
45 return kCaptureSessionQueue;
tkchin0ce3bf92016-03-12 16:52:04 -080046 case RTCDispatcherTypeAudioSession:
47 return kAudioSessionQueue;
hayscedd8fef2015-12-08 11:08:39 -080048 }
49}
50
51@end
52