DJI Bridge App Tutorial No Video Stream in Swift - Phantom 4 Pro -
i going trough dji bridge app tutorial. using swift bridge header imports videopreviewer. app compiles fine. can connect product. can register. bridging app working fine. stuck video stream. have got ideas?
method
"func videofeed(_ videofeed: djivideofeed, didupdatevideodata videodata: data)
is called correctly. when reading bytes data object. receiving values. sending these values videpreviewer as
func videofeed(_ videofeed: djivideofeed, didupdatevideodata videodata: data) {
var result = videodata.withunsafebytes { (pointer: unsafepointer<uint8>) -> uint8 in return pointer.pointee } print (result) print("stream info:\(videopreviewer.instance().currentstreaminfo.framerate)") videopreviewer.instance().push(&result, length: int32(videodata.count)) print(videopreviewer.instance().isdefaultpreviewer) }"
however correct? djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 15, encodertype: 1). print (result) returns values -----but framesize 0.0, 0.0 problem?----- result view set videopreviewer black. below code whole swift file whole djicameraviewcontroller.swift, compiles , run.
import uikit import djisdk
class djicameraviewcontroller: uiviewcontroller, djisdkmanagerdelegate,djicameradelegate,djibaseproductdelegate, djivideofeedlistener {
var camera: djicamera! @iboutlet weak var fpvpreviewview: uiview! @iboutlet weak var recordbtn: uibutton! @iboutlet weak var changeworkmodesegmentcontrol: uisegmentedcontrol! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } override func viewdidappear(_ animated: bool) { super.viewdidappear(animated) self.registerapp() videopreviewer.instance().setview(self.fpvpreviewview) } override func viewwilldisappear(_ animated: bool){ super.viewwilldisappear(animated) videopreviewer.instance().setview(nil) djisdkmanager.videofeeder()?.primaryvideofeed.remove(self) } func registerapp(){ djisdkmanager.registerapp(with: self) } func appregisteredwitherror(_ error:error?) { var message: string = "application registered." if (error != nil) { message = "register app failed!" } else { message = "application registered." djisdkmanager.enablebridgemode(withbridgeappip: "192.168.2.2") djisdkmanager.startconnectiontoproduct() videopreviewer.instance().start() } dispatchqueue.main.async { let alert = uialertcontroller(title: "alert", message: message, preferredstyle: uialertcontrollerstyle.alert) alert.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil)) self.present(alert, animated: true, completion: nil) } } /* after product recognized. fetchcamera method called method productconnected */ func fetchcamera() -> djicamera? { if ((djisdkmanager.product()) == nil){ return nil } if (djisdkmanager.product()!.iskind(of: djiaircraft.self)){ print("have uav") return ((djisdkmanager.product() as? djiaircraft)?.camera)! } return nil } /* djibaseproductdelegate method called when product recognized */ func productconnected(_ product: djibaseproduct?) { print("product recognized") if ((product) != nil) { product?.delegate = self camera = self.fetchcamera() if (camera != nil) { camera.delegate = self djisdkmanager.videofeeder()?.primaryvideofeed.add(self, with: nil) } } } func videofeed(_ videofeed: djivideofeed, didupdatevideodata videodata: data) { var result = videodata.withunsafebytes { (pointer: unsafepointer<uint8>) -> uint8 in return pointer.pointee } print (result) print("stream info:\(videopreviewer.instance().currentstreaminfo.framerate)") videopreviewer.instance().push(&result, length: int32(videodata.count)) print(videopreviewer.instance().isdefaultpreviewer) }
}
from xcode console following code prints outputs below
`print("stream info:\(videopreview.currentstreaminfo.framerate)") videopreviewer.instance().push(&result, length: int32(videodata.count)) print(videopreview.currentstreaminfo) print(videopreview.isdefaultpreviewer)`
output printed print code above:
start:
stream info:0 djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 0, encodertype: 0) true 136
2nd:
stream info:0 [h264 @ 0x102024210] sps_id 32 out of range vui timing infomation not present, set default:29.97fps [h264 @ 0x102024210] sps_id 32 out of range vui timing infomation not present, set default:29.97fps [h264 @ 0x102024210] missing picture in access unit size 958351 djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 0, encodertype: 0) true 65
3rd:
stream info:15 djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 15, encodertype: 1) true 119
and pops up:
stream info:15 [h264 @ 0x102024210] sei type 103 size 1712 truncated @ 288 [h264 @ 0x102024210] sps_id 32 out of range vui timing infomation not present, set default:29.97fps [h264 @ 0x102024210] missing picture in access unit size 111113 djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 15, encodertype: [h264 @ 0x102024810] sei type 103 size 1712 truncated @ 279
and other times pops-up:
stream info:15 djivideostreambasicinfo(framesize: (0.0, 0.0), framerate: 15, encodertype: 1) [h264 @ 0x102024810] sps_id 32 out of range true [h264 @ 0x102024810] sps_id 32 out of range [h264 @ 0x102024810] sps_id 32 out of range [h264 @ 0x102024810] sps_id 32 out of range [h264 @ 0x102024810] sps_id 32 out of range 0[h264 @ 0x102024810] sps_id 32 out of range
you should try set videopreview.instance() let somewhere convenient , use it.
also, make sure provide valid queue when adding listener video feed.
try these , let me know if helped.
Comments
Post a Comment