dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
998 stars 580 forks source link

Use two DjiCodecManager at the same time. #386

Closed hvilinka closed 5 years ago

hvilinka commented 5 years ago

Hi.

My drone matrice 210. DJI Android SDK 4.7.1 Device CrystalSky CS785, Android 5.1.1

I shuld display video stream from two camers at the same time, like a DJI Pilot. My solutions: I create two diferance DjiCodecManager, and use it in diferent VideoFeeder callbaks.

DJICodecManager primaryDJICodecManager  = new DJICodecManager(Activity,
        pramirySurfaceTexture,
        pramirySurfaceTextureTextureWidth,
        pramirySurfaceTextureTextureHeight);

DJICodecManager secondaryDJICodecManager  = new DJICodecManager(Activity,
        secondarySurfaceTexture,
        secondarySurfaceTextureTextureWidth,
        secondarySurfaceTextureTextureHeight);

pramirySurfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
    @Override
    public void onFrameAvailable(SurfaceTexture surfaceTexture) {
        surfaceTexture.updateTexImage();
    }
});

secondarySurfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
    @Override
    public void onFrameAvailable(SurfaceTexture surfaceTexture) {
        surfaceTexture.updateTexImage();
    }
});

VideoFeeder.VideoFeed videoFeed = VideoFeeder.getInstance().getPrimaryVideoFeed();
VideoFeeder.VideoFeed secondaryVideoFeed = VideoFeeder.getInstance().getSecondaryVideoFeed();

secondaryVideoFeed.setCallback(new VideoFeeder.VideoDataCallback() {
    @Override
    public void onReceive(byte[] videoBuffer, int size) {
        if (DjiManagers.mSecondaryCodecManager != null) {
            DjiManagers.mSecondaryCodecManager.sendDataToDecoder(videoBuffer, size);
        }
    }
});

videoFeed.setCallback(new VideoFeeder.VideoDataCallback() {
    @Override
    public void onReceive(byte[] videoBuffer, int size) {
        if (DjiManagers.mCodecManager != null) {
            DjiManagers.mCodecManager.sendDataToDecoder(videoBuffer, size);
        }
    }
});

But the pramirySurfaceTexture callback does not work. And on the second texture, an image from different cameras (color and grayscale (I use a thermal imaging camera)) appears alternately, but most often the texture is green.

Is it possible to create and use two DJICodecManager? And if not, how can I show the video stream simultaneously?

dji-sdk[bot] commented 5 years ago

Hi, there are two options for you to ask for help:

  1. Post your issues on StackOverflow: https://stackoverflow.com/questions/tagged/dji-sdk, the community can help you.

  2. Report your issues to dev@dji.com, as it's our official channel for developers to request DJI Developer Support now.

For DJI Developer Support, we have the following three tiers:

Michael-DJI commented 5 years ago

pls check out this file : https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/src/main/java/com/dji/sdk/sample/demo/camera/VideoFeederView.java it's a demo of how to display two live stream at the same time.