millicast / millicast-sdk

SDK for building a realtime broadcaster using the Millicast platform.
Other
37 stars 28 forks source link

Adding zoom functionality to sample IOS app #232

Closed willvictor closed 4 months ago

willvictor commented 1 year ago

Hi,

I'm trying to modify the sample ios publish app to add the ability to pinch for digital zoom with an IOS camera.

It seems like to do this, I'll need to:

  1. add a pinch listener to the uiView of the publisher.
  2. access the underlying video device and change the zoom level according to the pinch.

Something like this:

// maybe inside MCSwiftVideoRenderer init
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
uiView.addGestureRecognizer(pinchGesture)

func pinch(_ pinch: UIPinchGestureRecognizer) {
        guard let device = videoDeviceInput.device else { return }

        // Return zoom value between the minimum and maximum zoom values
        func minMaxZoom(_ factor: CGFloat) -> CGFloat {
            return min(min(max(factor, minimumZoom), maximumZoom), device.activeFormat.videoMaxZoomFactor)
        }

        func update(scale factor: CGFloat) {
            do {
                try device.lockForConfiguration()
                defer { device.unlockForConfiguration() }
                device.videoZoomFactor = factor
            } catch {
                print("\(error.localizedDescription)")
            }
        }

        let newScaleFactor = minMaxZoom(pinch.scale * lastZoomFactor)

        switch pinch.state {
        case .began: fallthrough
        case .changed: update(scale: newScaleFactor)
        case .ended:
            lastZoomFactor = minMaxZoom(newScaleFactor)
            update(scale: lastZoomFactor)
        default: break
        }
    }

(I jumped off of this stack overflow post)

The problem here is that i need a videoDeviceInput. I was thinking maybe i could access the device from the self.mcMan.videoSource but this seems to be an MCVideoSource, not a video device.

Could you point me in the right direction here? I'm completely new to IOS, and just trying to get started with this example.

Thanks!

Santiago-Souto commented 9 months ago

Hi @willvictor ! Sorry for the late response.

Could you explain a bit more which publish sample app are you referring to? In this repository, we do not have any. The publisher demo package we have is browser based.

Thanks!

dubeyShivank commented 4 months ago

Closing owing to lack of activity.