dji-sdk / Mobile-SDK-Android-V5

MSDK V5 Sample
Other
263 stars 140 forks source link

Clarification request regarding switching to multiple cameras. #215

Closed egm108 closed 7 months ago

egm108 commented 9 months ago

Could you please clarify? According to the docs I need MediaDataCenter.getInstance().getVideoStreamManager().addStreamSourcesListener(new StreamSourceListener() bla bla and listen to available StreamSources.

The problem for me that StreamSource don´t have information about it´s type (CameraVideoStreamSourceType) which would be convinient to show user for choose.

On the other side, KeyCameraVideoStreamSourceRange just gives me info about types, no sources per se (or channels). What is the proper way to switching to another camera?

Thank you in advance!

PeimanAtaeiJPDroni commented 9 months ago

Hi

just to share my experience with this issue.

to get the number of avalable stream resources, you need to call this :

MediaDataCenter.getInstance().videoStreamManager.availableStreamSources

which gives you the list of avalable stream resources. now if you have more than one stream source, it means you have more than one cameraso you can switch between them.

to do that it is a simple solution you can use :

  1. first, get the avalable stream sources and stream channels
  2. then create your video decoder and start it with for example primary video channel (which is connected to one of the stream sources)
  3. to change the camera use a method like this :

` private fun changeCameraSource() {

    if (streamSources!!.size >= 2) {

        if (selectedVideoChannel?.videoChannelType == VideoChannelType.PRIMARY_STREAM_CHANNEL){
            selectedVideoChannel = secondaryVideoChannel
        }else if(selectedVideoChannel?.videoChannelType == VideoChannelType.SECONDARY_STREAM_CHANNEL){
            selectedVideoChannel = primaryVideoChannel
        }

        primaryVideoDecoder!!.videoChannelType = selectedVideoChannel!!.videoChannelType
        primarySurfaceView.postInvalidate()
        setCameraName()

    }
}

`

it works for me but if any one has a better solution please let us know

egm108 commented 9 months ago

Hi

just to share my experience with this issue.

to get the number of avalable stream resources, you need to call this :

MediaDataCenter.getInstance().videoStreamManager.availableStreamSources

which gives you the list of avalable stream resources. now if you have more than one stream source, it means you have more than one cameraso you can switch between them.

to do that it is a simple solution you can use :

  1. first, get the avalable stream sources and stream channels
  2. then create your video decoder and start it with for example primary video channel (which is connected to one of the stream sources)
  3. to change the camera use a method like this :

` private fun changeCameraSource() {

    if (streamSources!!.size >= 2) {

        if (selectedVideoChannel?.videoChannelType == VideoChannelType.PRIMARY_STREAM_CHANNEL){
            selectedVideoChannel = secondaryVideoChannel
        }else if(selectedVideoChannel?.videoChannelType == VideoChannelType.SECONDARY_STREAM_CHANNEL){
            selectedVideoChannel = primaryVideoChannel
        }

        primaryVideoDecoder!!.videoChannelType = selectedVideoChannel!!.videoChannelType
        primarySurfaceView.postInvalidate()
        setCameraName()

    }
}

`

it works for me but if any one has a better solution please let us know

Thank you! I do the same. But StreamSource (from listener) doesn't have information about type. The question is how to match type and StreamSource.

One of possible ways could be by KeyCameraVideoStreamSource, but how much this is valid.

Also from listener I don't see how I can get some information to show to user for choose video stream (like thermal, zoom, etc

Thank you!!!

dji-dev commented 9 months ago

Agent comment from yating.liao in Zendesk ticket #96807:

The StreamSource obtained through StreamSourcesListener contains the location where the camera is installed. You can use the camera location included in the StreamSource to determine the StreamSource bound to the VideoChannel.

As for CameraVideoStreamSourceType, it represents the video source type of the camera. For example, H20T has multiple camera video sources, including zoom, wide, and infrared lenses. You can use KeyCameraVideoStreamSourceRange to obtain the video source type category of a camera installed at a specific location.

Based on the information mentioned above, StreamSource and CameraVideoStreamSourceType can be associated based on the installation location. PhysicalDevicePosition.PORTSIDE represents the position on the left side under the aircraft, and PhysicalDevicePosition.DEFAULT corresponds to the default camera, both of which correspond to ComponentIndexType.LEFT_OR_MAIN. The same relationship applies to other positions.

°°°