0

i build camera app from this guide : https://developer.dji.com/mobile-sdk/documentation/ios-tutorials/index.html and write averything in swift . Can someone help to convert this to swift ?

-(void)videoFeed:(DJIVideoFeed *)videoFeed didUpdateVideoData:(NSData *)videoData {
    [[DJIVideoPreviewer instance] push:(uint8_t *)videoData.bytes length:(int)videoData.length];
}

when i convert this to swift like this :

func videoFeed(_ videoFeed: DJIVideoFeed, didUpdateVideoData videoData: Data) {
        DJIVideoPreviewer.instance().push(UInt8(videoData?.bytes ?? 0), length: (videoData?.count ?? 0))
    }

i got errors:

Cannot convert value of type 'UInt8' to expected argument type 'UnsafeMutablePointer?' Cannot convert value of type 'UnsafeRawPointer' to expected argument type 'Int?'

Please help.

Yakir Sayada
  • 171
  • 1
  • 11
  • `videoData?`, why the "?" here? It doesn't seem unwrapped. So `(videoData?.count ?? 0)` should be `videoData.count`, `(videoData?.bytes ?? 0)` should be `videoData.bytes`, For the rest: https://stackoverflow.com/questions/31821709/nsdata-to-uint8-in-swift ? – Larme Sep 04 '20 at 11:22

1 Answers1

1

You can use official code samples GitHub

Right here

    func videoFeed(_ videoFeed: DJIVideoFeed, didUpdateVideoData videoData: Data) {
        guard videoFeed == feed else {
            NSLog("ERROR: Wrong video feed update is received!");
            return
        }
        videoData.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
            let p = UnsafeMutablePointer<UInt8>.init(mutating: ptr)
            previewer?.push(p, length: Int32(videoData.count))
            
        }
    }

try to search a bit better before deleting posts next time

Kstin
  • 659
  • 1
  • 4
  • 18