haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
tkchin | 89717aa | 2016-03-31 17:14:04 -0700 | [diff] [blame] | 11 | #import "RTCDispatcher+Private.h" |
| 12 | |
tkchin | 0ce3bf9 | 2016-03-12 16:52:04 -0800 | [diff] [blame] | 13 | static dispatch_queue_t kAudioSessionQueue = nil; |
haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 14 | static dispatch_queue_t kCaptureSessionQueue = nil; |
| 15 | |
tkchin | 0ce3bf9 | 2016-03-12 16:52:04 -0800 | [diff] [blame] | 16 | @implementation RTCDispatcher |
haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 17 | |
| 18 | + (void)initialize { |
| 19 | static dispatch_once_t onceToken; |
| 20 | dispatch_once(&onceToken, ^{ |
tkchin | 0ce3bf9 | 2016-03-12 16:52:04 -0800 | [diff] [blame] | 21 | kAudioSessionQueue = dispatch_queue_create( |
| 22 | "org.webrtc.RTCDispatcherAudioSession", |
| 23 | DISPATCH_QUEUE_SERIAL); |
haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 24 | 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; |
tkchin | 0ce3bf9 | 2016-03-12 16:52:04 -0800 | [diff] [blame] | 44 | case RTCDispatcherTypeAudioSession: |
| 45 | return kAudioSessionQueue; |
haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | @end |
| 50 | |