tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ARDBroadcastSampleHandler.m (4046B)


      1 /*
      2 *  Copyright 2018 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 "ARDBroadcastSampleHandler.h"
     12 
     13 #import <os/log.h>
     14 
     15 #import "ARDExternalSampleCapturer.h"
     16 #import "ARDSettingsModel.h"
     17 
     18 #import "sdk/objc/api/logging/RTCCallbackLogger.h"
     19 #import "sdk/objc/base/RTCLogging.h"
     20 
     21 @implementation ARDBroadcastSampleHandler {
     22  ARDAppClient *_client;
     23  RTC_OBJC_TYPE(RTCCallbackLogger) * _callbackLogger;
     24 }
     25 
     26 @synthesize capturer = _capturer;
     27 
     28 - (instancetype)init {
     29  self = [super init];
     30  if (self) {
     31    _callbackLogger = [[RTC_OBJC_TYPE(RTCCallbackLogger) alloc] init];
     32    os_log_t rtc_os_log = os_log_create("com.google.AppRTCMobile", "RTCLog");
     33    [_callbackLogger start:^(NSString *logMessage) {
     34      os_log(rtc_os_log,
     35             "%{public}s",
     36             [logMessage cStringUsingEncoding:NSUTF8StringEncoding]);
     37    }];
     38  }
     39  return self;
     40 }
     41 
     42 - (void)broadcastStartedWithSetupInfo:
     43    (NSDictionary<NSString *, NSObject *> *)setupInfo {
     44  // User has requested to start the broadcast. Setup info from the UI extension
     45  // can be supplied but optional.
     46  ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init];
     47 
     48  _client = [[ARDAppClient alloc] initWithDelegate:self];
     49  _client.broadcast = YES;
     50 
     51  NSString *roomName = nil;
     52  if (setupInfo[@"roomName"]) {
     53    roomName = (NSString *)setupInfo[@"roomName"];
     54  } else {
     55    u_int32_t randomRoomSuffix = arc4random_uniform(1000);
     56    roomName = [NSString stringWithFormat:@"broadcast_%d", randomRoomSuffix];
     57  }
     58  [_client connectToRoomWithId:roomName settings:settingsModel isLoopback:NO];
     59  RTCLog(@"Broadcast started.");
     60 }
     61 
     62 - (void)broadcastPaused {
     63  // User has requested to pause the broadcast. Samples will stop being
     64  // delivered.
     65 }
     66 
     67 - (void)broadcastResumed {
     68  // User has requested to resume the broadcast. Samples delivery will resume.
     69 }
     70 
     71 - (void)broadcastFinished {
     72  // User has requested to finish the broadcast.
     73  [_client disconnect];
     74 }
     75 
     76 - (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer
     77                   withType:(RPSampleBufferType)sampleBufferType {
     78  switch (sampleBufferType) {
     79    case RPSampleBufferTypeVideo:
     80      [self.capturer didCaptureSampleBuffer:sampleBuffer];
     81      break;
     82    case RPSampleBufferTypeAudioApp:
     83      break;
     84    case RPSampleBufferTypeAudioMic:
     85      break;
     86    default:
     87      break;
     88  }
     89 }
     90 
     91 #pragma mark - ARDAppClientDelegate
     92 
     93 - (void)appClient:(ARDAppClient *)client
     94    didChangeState:(ARDAppClientState)state {
     95  switch (state) {
     96    case kARDAppClientStateConnected:
     97      RTCLog(@"Client connected.");
     98      break;
     99    case kARDAppClientStateConnecting:
    100      RTCLog("Client connecting.");
    101      break;
    102    case kARDAppClientStateDisconnected:
    103      RTCLog(@"Client disconnected.");
    104      break;
    105  }
    106 }
    107 
    108 - (void)appClient:(ARDAppClient *)client
    109    didChangeConnectionState:(RTCIceConnectionState)state {
    110  RTCLog(@"ICE state changed: %ld", (long)state);
    111 }
    112 
    113 - (void)appClient:(ARDAppClient *)client
    114    didCreateLocalCapturer:
    115        (RTC_OBJC_TYPE(RTCCameraVideoCapturer) *)localCapturer {
    116 }
    117 
    118 - (void)appClient:(ARDAppClient *)client
    119    didCreateLocalExternalSampleCapturer:
    120        (ARDExternalSampleCapturer *)externalSampleCapturer {
    121  self.capturer = externalSampleCapturer;
    122 }
    123 
    124 - (void)appClient:(ARDAppClient *)client
    125    didReceiveLocalVideoTrack:(RTC_OBJC_TYPE(RTCVideoTrack) *)localVideoTrack {
    126 }
    127 
    128 - (void)appClient:(ARDAppClient *)client
    129    didReceiveRemoteVideoTrack:
    130        (RTC_OBJC_TYPE(RTCVideoTrack) *)remoteVideoTrack {
    131 }
    132 
    133 - (void)appClient:(ARDAppClient *)client
    134      didGetStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
    135 }
    136 
    137 - (void)appClient:(ARDAppClient *)client didError:(NSError *)error {
    138  RTCLog(@"Error: %@", error);
    139 }
    140 
    141 @end