Development Mobile App 'Video push'

Hi

I use xamarin to develop mobile apps with MIPSDK2018R1 Mobile.

There is java sample code for video push, but there is no sample code for .net and xamarin.

Does xamarin not implement video push?

If you can implement xamarin or .net video push, please share the sample source.

Hi Kimyeong,

Video Push is available for .NET/Xamarin also.

Unfortunately there is no sample for it.

I’ll try to draft you the most important parts.

First a start method:

private bool StartVideoPush()

{

  var response = \_connection.Video.RequestUploadStream(\_timeout);

  \_pushVideo = \_connection.VideoFactory.CreatePushVideo(response);

  if (null != \_pushVideo)

  {

    \_pushVideo.QueueProcessingType = PushVideo.QueueProcessing.Sync;

    // or PushVideo.QueueProcessing.Async;

    \_fpsMeter = \_pushVideo.FpsMeter;

  }

  return null != \_pushVideo;

}

I’m assuming you do have _connection (of type VideoOS.Mobile.SDK.Portable.Server.Base.Connection.Connection) object and the it has been already logged in successfully.

You can look other .NET samples to see how to initialize it.

Second - a stop method:

private void StopVideoPush()

{

  if (null != \_pushVideo)

  {

    \_pushVideo.Dispose();

    \_pushVideo = null;

  }

}

Third - sending the data trough the video push channel:

private void OnJpegData(byte\[\] jpegData)

{

  try

  {

    var videoPushFrame = new PushVideoFrame();

    videoPushFrame.FrameData = jpegData;

    \_pushVideo?.EnqueueFrame(videoPushFrame);

    // \_fpsMeter.Fps - you can observer the achieved fps of the channel

  }

  catch (Exception exception)

  {

  }

}

// jpegData is byte buffer containing one JPEG encoded image.

I’m assuming that _pushVideo saves the channel created in the Start method.

Please bear in mind that actual data sending is happen on separate thread.

Basically you only have to add frames to the internal queue.

Queue max size could be controlled and by default is 3 frames.

If channel is not capable to send data with the speed of data creation, unneeded frames are dropped.

Therefore is a good idea to check the value of the _fpsMeter.Fps.

I look forward to seeing your draft. Please help me.

Hi Kimyeong,

I probably didn’t explain it well.

What have to be done is already written in the previous post.

(Long enough with code samples).

Please click on “Show More” link if you do not see the full answer.

(The forum by default shows just few form the first lines, which I have to admit is not very handy sometimes).

Thank you Petar Vutov!

Your code works very well.

I hope you will always have good luck

Glad to hear it worked fine :slight_smile:

Thanks Kimyeong !

Hi Mr. @ki myeong han​,

where did you find the sample java code for Video Push? May I ask for the location where we can download it? Thanks!

Hi @Dulce Polinar​,

Here is a sample code on Java for Video Push in application that uses MIP SDK Mobile. The steps that should be followed are:

1. Connect to Milestone Mobile Server.

2. Login to the server.

3. Request a video push channel.

4. Push all the frames that you want with an incremented frame number.

5. Call stopVideoStream command from the MIP SDK Mobile to close the opened channel.

And the code is:

private static String videoChannelID = “”;

private void requestNewPushChannel(){

xpMobileSDK.requestVideoStream(null, null, null, null, CommunicationCommand.PARAM_SIGNAL_UPLOAD, CommunicationCommand.PARAM_METHOD_PULL, null, new SuccessCallback() {

   @Override

   public void onSuccess(CommunicationCommand response) {

       _videoChannelID_ \= response.getOutputParam().get("VideoId");

       //After the received video push channel ID, you could start sending frames to the Mobile server.

   }

}, new ErrorCallback() {

   @Override

   public void onErrorOccurred(CommunicationCommand cmd) {

       //Error occurred when requestVideoStream was called.

   }

});

}

/**

* Pushes frames to the Mobile server. Before sending your frames to the Mobile server, you should request a new video channel id. Then you can send all the frames by calling pushFrame method. When you want to stop sending frames, you should stop calling pushFrame method and call stopVideoStream command from the Mobile SDK.

* @param frameAsByteArray - the frame that will be pushed to the Mobile Server. It should be in JPEG format.

* @param frameNumber - number of the frame. Every next should be incremented with 1

*/

private void pushFrame(final byte[] frameAsByteArray,int frameNumber) {

if (videoChannelID != null && !videoChannelID.equals(“”)) {

   String videoAlias = new StringBuilder("/").append(_communicationAlias_).append("/Video/").append(_videoChannelID_).append('/').toString();

   try {

       HTTPConnection conn = new HTTPConnection(address, port, videoAlias);

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();

       byte\[\] hBuffer = new byte\[36\];

       bOut.write(hBuffer);

       bOut.write(frameAsByteArray);

       VideoCommand vcmd = new VideoCommand(_videoChannelID_);

       byte\[\] frameBuffer = bOut.toByteArray();

       vcmd.refactorMainHeader(frameBuffer, frameNumber, System._currentTimeMillis_());

       conn.sendByteArrayRequest(frameBuffer);

   } catch (IOException e) {

       //Handle the IOException ...

   }

}

}