首页 > 解决方案 > VideoFeed 无法在使用最新 Windows SDK 的 MavicAir 2 上运行

问题描述

它与 Windows SDK 0.2.0 配合良好,我能够控制无人机并获得 FPV。我意识到发布了一个新版本的 SDK,我尝试了一下。我发现最新的SDK只支持移动命令,即使使用DJI提供的示例代码,我也无法从无人机获取任何视频数据。谁能告诉我如何使用这个 sdk 获取视频反馈?

这是 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;
            }

        }
    }

}

标签: c#dji-sdk

解决方案


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


推荐阅读