简体   繁体   English

VideoFeed 不适用于使用最新 Windows SDK 的 MavicAir 2

[英]VideoFeed not working on MavicAir 2 with the latest windows SDK

It was working well with windows SDK 0.2.0, I was able the control the UAV and got the FPV.它在 windows SDK 0.2.0 上运行良好,我能够控制无人机并获得 FPV。 I realized a new version SDK is released and I tried it.我意识到发布了新版本的 SDK 并尝试了它。 I found that the latest SDK only support moving command, I couldn't get any video data from the UAV, even with the sample code provided by DJI.我发现最新的SDK只支持移动命令,我无法从无人机中获取任何视频数据,即使使用DJI提供的示例代码。 Can anyone tell me what to do for getting video feed back with this sdk?谁能告诉我如何使用此 sdk 获取视频反馈?

Here is the git sample code:这是 git 示例代码:

public sealed partial class FPVPage : Page
{
    private DJIVideoParser.Parser videoParser;

    public FPVPage()
    {
        this.InitializeComponent();
    }

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);
        InitializeVideoFeedModule();
        await DJI.WindowsSDK.DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).SetCameraWorkModeAsync(new CameraWorkModeMsg { value = CameraWorkMode.SHOOT_PHOTO });
    }

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        UninitializeVideoFeedModule();
    }


    private async void InitializeVideoFeedModule()
    {
        //Must in UI thread
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
        {
            //Raw data and decoded data listener
            if (videoParser == null)
            {
                videoParser = new DJIVideoParser.Parser();
                videoParser.Initialize(delegate (byte[] data)
                {
                    //Note: This function must be called because we need DJI Windows SDK to help us to parse frame data.
                    return DJISDKManager.Instance.VideoFeeder.ParseAssitantDecodingInfo(0, data);
                });
                //Set the swapChainPanel to display and set the decoded data callback.
                videoParser.SetSurfaceAndVideoCallback(0, 0, swapChainPanel, ReceiveDecodedData);
                DJISDKManager.Instance.VideoFeeder.GetPrimaryVideoFeed(0).VideoDataUpdated += OnVideoPush;
            }
            //get the camera type and observe the CameraTypeChanged event.
            DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).CameraTypeChanged += OnCameraTypeChanged;
            var type = await DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).GetCameraTypeAsync();
            OnCameraTypeChanged(this, type.value);
        });
    }


    private void UninitializeVideoFeedModule()
    {
        if (DJISDKManager.Instance.SDKRegistrationResultCode == SDKError.NO_ERROR)
        {
            videoParser.SetSurfaceAndVideoCallback(0, 0, null, null);
            DJISDKManager.Instance.VideoFeeder.GetPrimaryVideoFeed(0).VideoDataUpdated -= OnVideoPush;
        }
    }

    //raw data
    void OnVideoPush(VideoFeed sender, byte[] bytes)
    {
        videoParser.PushVideoData(0, 0, bytes, bytes.Length);
    }

    //Decode data. Do nothing here. This function would return a bytes array with image data in RGBA format.
    async void ReceiveDecodedData(byte[] data, int width, int height)
    {
    }

    //We need to set the camera type of the aircraft to the DJIVideoParser. After setting camera type, DJIVideoParser would correct the distortion of the video automatically.
    private void OnCameraTypeChanged(object sender, CameraTypeMsg? value)
    {
        if (value != null)
        {
            switch (value.Value.value)
            {
                case CameraType.MAVIC_2_ZOOM:
                    this.videoParser.SetCameraSensor(AircraftCameraType.Mavic2Zoom);
                    break;
                case CameraType.MAVIC_2_PRO:
                    this.videoParser.SetCameraSensor(AircraftCameraType.Mavic2Pro);
                    break;
                default:
                    this.videoParser.SetCameraSensor(AircraftCameraType.Others);
                    break;
            }

        }
    }

}

大疆技术团队快速上传新版本sdk(0.3.1),问题解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM