Skip to content

Commit

Permalink
rearrange extensions for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxfrazer committed Nov 28, 2023
1 parent 1ed35f5 commit 208cabc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
22 changes: 14 additions & 8 deletions stream-raw-audio-and-video/ModifyAudioFrameDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@ protocol HasModifyAudio {
var audioModification: AudioModification { get }
}

public class ModifyAudioFrameDelegate: NSObject, AgoraAudioFrameDelegate {
public class ModifyAudioFrameDelegate: NSObject {

var modifyController: any HasModifyAudio

init(modifyController: any HasModifyAudio) {
self.modifyController = modifyController
}
}

// MARK: - Audio Buffer Modifiers

extension ModifyAudioFrameDelegate: AgoraAudioFrameDelegate {
public func onRecordAudioFrame(_ frame: AgoraAudioFrame, channelId: String) -> Bool {
// Change the audio frame immediately after recording it
switch modifyController.audioModification {
case .louder: applyAudioVolumeModification(frame, gain: 4)
case .reverb: applyReverbAudioModification(frame)
case .none: break
}
return true
}

init(modifyController: any HasModifyAudio) {
self.modifyController = modifyController
public func onPlaybackAudioFrame(_ frame: AgoraAudioFrame, channelId: String) -> Bool {
// Change the audio frame just before playback
true
}
}

// MARK: - Audio Buffer Modifiers

public extension ModifyAudioFrameDelegate {
fileprivate extension ModifyAudioFrameDelegate {
private func applyAudioVolumeModification(_ frame: AgoraAudioFrame, gain: Float) {
// Implement high audio modification here.
// You can manipulate the audio data in the `frame` parameter to apply high modification.
Expand Down
56 changes: 31 additions & 25 deletions stream-raw-audio-and-video/ModifyVideoFrameDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ protocol HasModifyVideo {
var videoModification: VideoModification { get }
}

public class ModifyVideoFrameDelegate: NSObject, AgoraVideoFrameDelegate {
public class ModifyVideoFrameDelegate: NSObject {

var modifyController: any HasModifyVideo

public func onCapture(_ videoFrame: AgoraOutputVideoFrame, sourceType: AgoraVideoSourceType) -> Bool {
init(modifyController: any HasModifyVideo) { self.modifyController = modifyController }
}

extension ModifyVideoFrameDelegate: AgoraVideoFrameDelegate {
public func onCapture(
_ videoFrame: AgoraOutputVideoFrame, sourceType: AgoraVideoSourceType
) -> Bool {
// Change the video frame immediately after recording it
guard let pixelBuffer = videoFrame.pixelBuffer else { return true }
var outputBuffer: CVPixelBuffer?
switch modifyController.videoModification {
Expand All @@ -24,6 +31,28 @@ public class ModifyVideoFrameDelegate: NSObject, AgoraVideoFrameDelegate {
return true
}

// Indicate the video frame mode of the observer
public func getVideoFrameProcessMode() -> AgoraVideoFrameProcessMode {
// The process mode of the video frame: readOnly, readWrite
// Default is `.readOnly` function is required to change the output.
.readWrite
}

// Sets the video frame type preference
public func getVideoFormatPreference() -> AgoraVideoFormat {
// cvPixelBGRA is the default, you can omit this.
return .cvPixelBGRA
}

// Sets the frame position for the video observer
public func getObservedFramePosition() -> AgoraVideoFramePosition {
// postCapture is default, you can omit this.
return .postCapture
}
}

extension ModifyVideoFrameDelegate {

/// Copies pixel data from the source CVPixelBuffer to the destination CVPixelBuffer.
///
/// - Parameters:
Expand Down Expand Up @@ -57,29 +86,6 @@ public class ModifyVideoFrameDelegate: NSObject, AgoraVideoFrameDelegate {
CVPixelBufferUnlockBaseAddress(destinationPixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
CVPixelBufferUnlockBaseAddress(sourcePixelBuffer, .readOnly)
}

// Indicate the video frame mode of the observer
public func getVideoFrameProcessMode() -> AgoraVideoFrameProcessMode {
// The process mode of the video frame: readOnly, readWrite
// Default is `.readOnly` function is required to change the output.
return .readWrite
}

// Sets the video frame type preference
public func getVideoFormatPreference() -> AgoraVideoFormat {
// cvPixelBGRA is the default, you can omit this.
return .cvPixelBGRA
}

// Sets the frame position for the video observer
public func getObservedFramePosition() -> AgoraVideoFramePosition {
// postCapture is default, you can omit this.
return .postCapture
}

init(modifyController: any HasModifyVideo) {
self.modifyController = modifyController
}
}

// MARK: - Pixel Buffer Modifiers
Expand Down

0 comments on commit 208cabc

Please sign in to comment.