Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to show video output on a drawable without video effects #1377

Merged

Conversation

levs42
Copy link
Contributor

@levs42 levs42 commented Feb 13, 2024

Description & motivation

This PR brings an option to display camera output on a drawable before applying the video effects. It allows to show the video effects only on the stream. Default value is the same as before. effectsBuffer flags helps to prevent the race condition when the video effects appear on the drawable for some frames; it happens when effects rendering is faster than drawable rendering.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

@levs42 levs42 force-pushed the feature/drawable-without-effects branch from eff0f29 to 1069872 Compare February 13, 2024 01:12
Copy link
Owner

@shogo4405 shogo4405 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With HKView.isCaptureVideoPreviewEnabled = true, it's possible to preview the unprocessed video. Could this feature serve as an alternative?

@levs42
Copy link
Contributor Author

levs42 commented Feb 13, 2024

I tried isCaptureVideoPreviewEnabled but it doesn't lead to the same result. Here is what I'm trying to achieve with the PR:

Screenshots

The preview shows two effects. First is time effect. Second is "view effect" of two yellow bars, a UIView is getting displayed on the screen and is getting rendered as a visual effect. The video preview displays both effects. The preview is in resizeAspectFill mode. This is the current behavior.
IMG_9289

When HKView.drawWithEffects = false and Stream.videoMixerSettings.effectsBuffer = true both effects are not present on the preview:

IMG_9290

@levs42
Copy link
Contributor Author

levs42 commented Feb 13, 2024

I found the cause. Looks like HKView.isCaptureVideoPreviewEnabled = true works only for macos because it always creates an extra buffer. I'm going to keep effectsBuffer flag for other platforms to be able to achieve the same behavior.

@levs42 levs42 force-pushed the feature/drawable-without-effects branch from 1069872 to d78387a Compare February 13, 2024 21:29
@@ -36,6 +36,8 @@ public struct IOVideoMixerSettings: Codable {
public let direction: ImageTransform
/// Specifies the main channel number.
public var channel: UInt8 = 0
/// Specifies if effects are always rendered to a new buffer.
public var effectsBuffer: Bool = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, understood. I accept changes of this magnitude. I'd like the variable name to be changed to "isXXXXEnabled". For example, "isEffectsBufferEnabled" is a bit unclear to me. Do you have any other suggestions for a more appropriate name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use "alwaysUseBufferPoolForVideoEffects" or similar. "always" might be a good choice because even when the flag is false, macos will use the buffer pool. And when the flag is true, pixel buffer pool will always be used. Alternatively, we could add a new enum to the settings:

enum EffectsRenderMode {
   /// This mode tries to save memory on non-macos platforms by rendering to the video output pixel buffer.
   case optimized
   /// This mode is always using a separate pixel buffer to render the video effects.
   case separateBuffer
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with "alwaysUseBufferPoolForVideoEffects".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, please take a look

@levs42 levs42 force-pushed the feature/drawable-without-effects branch from d78387a to 8c9bb7d Compare February 15, 2024 17:48
Copy link
Owner

@shogo4405 shogo4405 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you.

@shogo4405 shogo4405 added this to the 1.7.4 milestone Feb 16, 2024
@shogo4405 shogo4405 merged commit 338b260 into shogo4405:main Feb 16, 2024
1 check passed
@levs42 levs42 deleted the feature/drawable-without-effects branch March 16, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants