dkrivoruchko / ScreenStream

ScreenStream Android App
https://screenstream.io
MIT License
1.56k stars 320 forks source link

How can I view the stream on SurfaceView or CanvasView? #143

Closed jayesh83 closed 3 years ago

jayesh83 commented 3 years ago

I'm using features of ScreenStream i.e. capturing screen and streaming. The current implementation is amazing but I want something specific. I'm building an app to app streaming and not from app to WebView or Browser to be involved. And for that, I'm sure that I'll have to use SurfaceView or CanvasView or something of this sort. But I'm not sure exactly how. Can anyone suggest how can I achieve this? @dkrivoruchko @WaldiSt @tiborepcek

dkrivoruchko commented 3 years ago

The stream is in MJPEG format but for app to app you may just use Android Broadcast mechanism (Not LocalBroadcastManager) and just stream jpeg images. But I'm unsure if broadcast speed will be enough.

dkrivoruchko commented 3 years ago

Another option is to use localhost, connect to it from new app and parse mjpeg stream (or update Screen Stream to publish JPEGs via some simple json api call)

jayesh83 commented 3 years ago

Okay thank you so much for the approaches. I'll surely implement both of them and write here about the same. I'll keep this open untill all finalized. Thank You 🔆

jayesh83 commented 3 years ago

There's slite confusion I guess. Actually, I'm not concerned about transferring MJPEG or images or connections between client and server. It is about how to view incoming data on SurfaceView or CanvasView natively in android. I'm not getting how the browser is receiving MJPEGs, parsing it, and showing them on the screen. Currently, I'm using a webview inside ScreenStream and there I'm showing the receiver side screen and not in the browser. But now I want a native viewer where I can achieve the same goal.

Steps I want to implement.

  1. Server starts the connection [done]
  2. Client types/scans the address in the app itself and connection established [done]
  3. Server sending MJPEG/stream/images [done]
  4. Client should receive MJPEG/stream, render it and show on the SurfaceView or any compatible consumer view [want to achive]

How to receive stream inside the app itself on the receiver side, render it and show it on some view?

Also, I'm intermediate so step by step guide will help me clearly understand your approach. Thank you👍

dkrivoruchko commented 3 years ago

The easiest way is in this new app to make a network call to http://127.0.0.1:8080/stream.mjpeg (Assuming that ScreanStream server running on local host) and parse jmpeg stream for jpeg bytes (Google this). Then show jpeg in SurfaceView.

jayesh83 commented 3 years ago

Sure! Yes. That sounds like a good start. Thanks, I'll start implementing that. And also is there any problem if I keep the server on the current implementation of ScreenStream and not change it to a local host?

dkrivoruchko commented 3 years ago

ScreenStream already can work on localhost, just use current app version.

jayesh83 commented 3 years ago

Yes alright!

jayesh83 commented 3 years ago

There's a package called Grafika. can you tell me what's that used for exactly? it has something to do with capturing the screen but not getting it exactly.

dkrivoruchko commented 3 years ago

Read this: https://github.com/dkrivoruchko/ScreenStream/pull/128