Inherits from NSObject
Conforms to AVCaptureVideoDataOutputSampleBufferDelegate
Declared in SCMediaManager.h

Overview

The SCMediaManager class is the shared instance for managing video capture sessions.

The SCMediaManager class can be controlled by the application in order to hook into a video capture session during a video call and to receive the captured frames for further processing like face recognition. The C2Call SDK video call subsystem uses this class to request a capture session and register a AVCaptureVideoDataOutputSampleBufferDelegate. Up to two AVCaptureVideoDataOutputSampleBufferDelegate can be registered for a video capture session. It’s important that any additional video frame processing should be fast enough to allow a smoth video call with 10 - 20 frames per second. Video frames consume a lot of memory. Please don’t forget to run a profiler session on any additional video processing in order to detect potential memory leaks.

Properties

cameraPosition

@property (nonatomic, readonly) AVCaptureDevicePosition cameraPosition

disableHoldTheLineAnnouncement

Donot use hold the line announcement when the call is interrupted

@property (nonatomic) BOOL disableHoldTheLineAnnouncement

Declared In

SCMediaManager.h

holdTheLineSoundFilePath

Soundfile path for hold the line announcement when the call is interrupted

@property (nonatomic, strong, nullable) NSString *holdTheLineSoundFilePath

Declared In

SCMediaManager.h

useExternalVideoCapture

Disable internal video capture session management This option allows to setup and run the video capture session externally, in order to use tools like GPUImage for video image processing. The developer is then responsible to call

@property (nonatomic) BOOL useExternalVideoCapture

Discussion

[[SCMediaManager instance] captureOutput:didOutputSampleBuffer:fromConnection:]

with the processed video data for submission.

Declared In

SCMediaManager.h

useGPUImageVideoCapture

Enable/Disable GPUImage Video Capture C2Call API supports GPUImage Filtering for Video Capture. With this feature enabled, GPUImageFilters can be applied to the video feed before sending it to the remote party. Other features like screen sharing, video recording will be disabled when using this feature. This property must be set before the call starts.

@property (nonatomic) BOOL useGPUImageVideoCapture

Discussion

The GPUImage library must be linked to the App, otherwise setting this property has no effect

Declared In

SCMediaManager.h

videoCaptureDevice

Returns the current active video capture device (front or rear camera)

@property (nonatomic, readonly, nullable) AVCaptureDevice *videoCaptureDevice

Declared In

SCMediaManager.h

videoCaptureSession

Returns the current active video capture session

@property (nonatomic, readonly, nullable) AVCaptureSession *videoCaptureSession

Declared In

SCMediaManager.h

Class Methods

instance

Returns a share instance of SCMediaManager.

+ (nonnull SCMediaManager *)instance

Return Value

The media manager.

Declared In

SCMediaManager.h

setDefaultCaptureSessionPreset:

Set the Default CaptureSession Preset

+ (void)setDefaultCaptureSessionPreset:(id)preset

Parameters

preset
  • AVCaptureSessionPreset

Discussion

SCMediaManager uses AVCaptureSessionPresetMedium when creating the AVCaptureSession by default. Use setDefaultCaptureSessionPreset: before accessing the instace first time to change the default capture session preset.

Declared In

SCMediaManager.h

Instance Methods

addVideoDataOutputDelegate:

Add a VideoDataOutput Delegate to the current capture session.

- (BOOL)addVideoDataOutputDelegate:(id)delegate

Parameters

delegate
  • The AVCaptureVideoDataOutputSampleBufferDelegate

Return Value

YES if delegate has been added, NO if max delegates have been reached.

Discussion

If the capture session is already running, the delegate will be simply added and called for every available video frame; If the session is not running it can be started with startVideoCapture. Every delegate should stop only its own capture session, using stopVideoCaptureForDelegate. This also removes the delegate.

Stop all video output with stopVideoCapture. All delegates will be removed.

Declared In

SCMediaManager.h

capturePreviewImageWithCompletionHandler:

Capture the current preview image

- (void)capturePreviewImageWithCompletionHandler:(id)handler

Parameters

handler
  • The completion handler

Discussion

Capture a still image recorded by the camera during a video call.

Declared In

SCMediaManager.h

disableAudioOutput:

Disable Audio output while a capture session is running

- (void)disableAudioOutput:(id)disable

Parameters

disable
  • Set YES to pause the Audio output, NO to re-enable

Discussion

This is a global setting which will keep it’s setting between 2 calls

Declared In

SCMediaManager.h

disableMediaOutput:

Disable Audio / Video output while a capture session is running

- (void)disableMediaOutput:(id)disable

Parameters

disable
  • Set YES to disable the Audio Video output, NO to re-enable

Discussion

This is a global setting which will keep it’s setting between 2 calls

Declared In

SCMediaManager.h

disableVideoOutput:

Disable Video output while a capture session is running

- (void)disableVideoOutput:(id)disable

Parameters

disable
  • Set YES to pause the Video output, NO to re-enable

Discussion

This is a global setting which will keep it’s setting between 2 calls

Declared In

SCMediaManager.h

encodeAndTransferYUV:u:v:width:height:rotate:

Experimental, for internal use only

- (void)encodeAndTransferYUV:(id)yPtr u:(id)uPtr v:(id)vPtr width:(id)width height:(id)height rotate:(id)rotate

Parameters

yPtr
  • ptr to Y data
uPtr
  • ptr to U data
vPtr
  • ptr to V data
width
  • image width
height
  • image height
rotate
  • [0 .. 3] : rotate image 0, 90, 180 and 270 degrees

Discussion

Directly transfer YUV encoded data

Declared In

SCMediaManager.h

getDecodedVideoFrame

Returns the next decoded video frame in YUV420 format

- (nullable NSDictionary *)getDecodedVideoFrame

Return Value

dictionary with frame data or nil

Discussion

The method will wait for the next frame and returns it in YUV420 format including size and rotation metadata

Dictionary Keys: frame : NSData - The Frame data width : NSNumber - Image width height : NSNumber - Image height rotation : NSNumber - Rotation Value (0 - 3)

IMPORTANT: Process the frame data before retrieving the next frame. The data buffer takes always only one frame and will be overwritten with the next frame

Declared In

SCMediaManager.h

hasFrontCamera

Is front camera available.

- (BOOL)hasFrontCamera

Return Value

YES / NO

Declared In

SCMediaManager.h

hasRearCamera

Is rear camera available.

- (BOOL)hasRearCamera

Return Value

YES / NO

Declared In

SCMediaManager.h

previewLayer

Returns the previewLayer.

- (nullable AVCaptureVideoPreviewLayer *)previewLayer

Return Value

The camera preview layler.

Declared In

SCMediaManager.h

recordingAudioSession

Initialize the recording audio session

- (void)recordingAudioSession

Declared In

SCMediaManager.h

regularAudioSession

Initialize the default audio session

- (void)regularAudioSession

Declared In

SCMediaManager.h

setBackgroundAudioVolumeForVoice:andSound:

Set the audio volumes when mixing background audio

- (void)setBackgroundAudioVolumeForVoice:(id)voice andSound:(id)sound

Parameters

voice
  • Voice volume factor (Recommended Range: 1.0 - 1.5)
sound
  • Sound volume factor (Recommended Range: 0.2 - 1.0)

Discussion

When mixing background audio, the audio streams for voice and the sound files are being reduced or increased before beeing mixed. You can set the factor or reducing or increasing for each stream separately It’s recomended to increase the voice and reduce the background sounds, so that the voice is not being overtaken by the background sound. The actual recommended factors are voice: 1.2 - 1.3 sound: 0.3 - 0.5

However this depends on the actual sound files for background audio and should be checked experimentally for your own case. The default value is 1.0 / 1.0.

Declared In

SCMediaManager.h

setFrameRate:

For internal use only

- (void)setFrameRate:(id)frameRate

Parameters

frameRate
  • The FrameRate

Declared In

SCMediaManager.h

setGPUImageFilter:

Set a GPUImageFilter for video processing

- (BOOL)setGPUImageFilter:(id)filter

Parameters

filter
  • The GPUImage Filter to be applied to all video frames

Return Value

YES - If GPU Image is available / NO if GPUImage library is not added to the project

Discussion

nil will remove a previously set filter. Setting a filter will automatically set useGPUImageVideoCapture = YES;

Filter can be changed during a call if useGPUImageVideoCapture was YES before the call started.

Declared In

SCMediaManager.h

setOrientation:

The orientation of the video.

- (void)setOrientation:(id)orientation

Parameters

enable
  • The orientation

Declared In

SCMediaManager.h

setVideoCaptureSessionPreset:

Set current video caputre session preset

- (void)setVideoCaptureSessionPreset:(id)sessionPreset

Parameters

sessionPreset
  • Video Capture Session Preset

Declared In

SCMediaManager.h

setVideoStabilizationWhenAvailable:

A Boolean value that indicates whether the system should enable video stabilization when it is available.

- (void)setVideoStabilizationWhenAvailable:(id)enable

Parameters

enable
  • Set to YES for enabling

Declared In

SCMediaManager.h

setupCaptureSession

Setup Capture Sesession

- (void)setupCaptureSession

Discussion

Initialize the VideoCapture Session

Declared In

SCMediaManager.h

startAudioRecording:

Start Recording of the current VoIP Audio Stream

- (void)startAudioRecording:(id)mediaType

Parameters

mediaType
  • Either AVFileTypeAppleM4A or AVFileTypeWAVE is supported

Declared In

SCMediaManager.h

startBackgroundAudio:loopAudio:

Start Background Audio during a call

- (void)startBackgroundAudio:(id)soundfilePath loopAudio:(id)loop

Parameters

soundfilePath
  • Path to the sound file
loop
  • Repeat endless

Discussion

This feature will mix the recorded voice from microphone with the sound from an audio file before transferring it to the remote party in an audio or video call

Declared In

SCMediaManager.h

startMediaRecording

Start Recording of the current MediaStream

- (void)startMediaRecording

Declared In

SCMediaManager.h

startScreenCaptureForView:usingAudio:

Start ScreenCapture Recording of the provided UIView

- (void)startScreenCaptureForView:(id)captureView usingAudio:(id)useAudio

Parameters

captureView
  • The view to be captured and recorded
useAudio
  • Capture Audio from the microphone

Discussion

The provide view will be recorded as screen capture session into an MP4 video file. The view will be recorded with 10 frames / second.

Declared In

SCMediaManager.h

startScreenSharingForView:

Start a screenSharing session during an active video call

- (void)startScreenSharingForView:(id)shareView

Parameters

shareView

The view to be shared

Declared In

SCMediaManager.h

startVideoCapture

Start Video Capture

- (void)startVideoCapture

Discussion

Does nothing if the session is already running.

Declared In

SCMediaManager.h

stopAudioRecordingWithCompletionHandler:

Stop recording of the current VoIP Audio Stream

- (void)stopAudioRecordingWithCompletionHandler:(id)handler

Parameters

handler
  • The completion handler will be called with the mediaKey as parameter after completion

Declared In

SCMediaManager.h

stopBackgroundAudio

Stop Background Audio

- (void)stopBackgroundAudio

Declared In

SCMediaManager.h

stopMediaRecordingWithCompletionHandler:

Stop recording of the current media stream

- (void)stopMediaRecordingWithCompletionHandler:(id)handler

Parameters

handler
  • The completion handler will be called with the mediaKey as parameter after completion

Declared In

SCMediaManager.h

stopScreenCaptureWithCompletionHandler:

Stop recording of the current screen capture session

- (void)stopScreenCaptureWithCompletionHandler:(id)handler

Parameters

handler
  • The completion handler will be called with the mediaKey as parameter after completion

Declared In

SCMediaManager.h

stopScreenSharing

Stop active screenSharing session

- (void)stopScreenSharing

Declared In

SCMediaManager.h

stopVideoCapture

Remove all delegates and stop the capture session.

- (void)stopVideoCapture

Declared In

SCMediaManager.h

stopVideoCaptureForDelegate:

Stop video capture for a specific delegate.

- (void)stopVideoCaptureForDelegate:(id)delegate

Parameters

delegate
  • The delegate to remove.

Discussion

The delegate will be removed. If it’s the last delegate, the capture session will be stopped.

Declared In

SCMediaManager.h

switchCamera:

Switch between cameras

- (AVCaptureDevicePosition)switchCamera:(id)camera

Parameters

The

selected camera device

Return Value

Returns the new device or the old device if the camera couldn’t be changed.

Discussion

AVCaptureDevicePositionUnspecified stops the capture output temporary.

Declared In

SCMediaManager.h