blob: 94176ac6d810d4890addced9ad379d515f6418b4 [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
36#pragma mark - Private
37
38+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType {
39 switch (dispatchType) {
40 case RTCDispatcherTypeMain:
41 return dispatch_get_main_queue();
42 case RTCDispatcherTypeCaptureSession:
43 return kCaptureSessionQueue;
tkchin0ce3bf92016-03-12 16:52:04 -080044 case RTCDispatcherTypeAudioSession:
45 return kAudioSessionQueue;
hayscedd8fef2015-12-08 11:08:39 -080046 }
47}
48
49@end
50