swift - FBSimulatorControl : Convert CVPixelBufferRef data to jpeg data for streaming -


i developing cli in swift , using fbsimulatorcontrol in it. want stream data obtained consumedata: delegate method. per data obtained in method data obtained cvpixelbufferref

i logged issue in github repo of fbsimulatorcontrol.

i tried regenerate cvpixelbuffer data , tried obtain ciimage , convert jpeg data. not seem work. can me this? adding below code i've tried

var pixelbuffer:cvpixelbuffer? = nil let result = cvpixelbuffercreate(kcfallocatordefault, 750, 1334, kcvpixelformattype_32bgra, nil, &pixelbuffer)  if result != kcvreturnsuccess {     print("pixel buffer create success")     return } cvpixelbufferlockbaseaddress(pixelbuffer!, .init(rawvalue: 0)) let ydestplane:unsafemutablerawpointer? = cvpixelbuffergetbaseaddressofplane(pixelbuffer!, 0)  if ydestplane == nil {     print("failed create ydestplane")     return }  let nsdata = data nsdata let rawptr = nsdata.bytes  memcpy(ydestplane!, rawptr, 750*1334*4)  cvpixelbufferunlockbaseaddress(pixelbuffer!, .init(rawvalue: 0)) kcvpixelformattype_32bgra, getbasea, 2208, null, null, nil, &pixelbuffer)  if #available(osx 10.12, *) {     let ciimage = ciimage.init(cvpixelbuffer: pixelbuffer!)     let tempcontext = cicontext.init(options: nil)     let videoimage = tempcontext.createcgimage(ciimage, from: cgrect.init(x: 0, y: 0, width: cvpixelbuffergetwidth(pixelbuffer!), height: cvpixelbuffergetheight(pixelbuffer!)))     let imagesize: nssize = nsmakesize(750, 1334)     let nsimagetest = nsimage(cgimage: videoimage!, size: imagesize)     if let bits = nsimagetest.representations.first as? nsbitmapimagerep {         let jpegfinaldata = bits.representation(using: .jpeg, properties: [:])         if self.isstreaming {             var simindex:int?             in 0...(auconnectionsimulatormap.instance.simconnectionmap.count-1) {                 if sim.udid == auconnectionsimulatormap.instance.simconnectionmap[i].sim.sim.udid {                     simindex =                     break                 }             }             var finaldata:data = data()             let finaldict = ["data":["type":"onscreenframe","value":jpegfinaldata!]] dictionary<string,any>             try! finaldata.pack(finaldict)             auconnectionsimulatormap.instance.simconnectionmap[simindex!].ws?.write(data: finaldata)         }      }  } else {     // fallback on earlier versions } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -