AgoraIO / Advanced-Video

MIT License
261 stars 336 forks source link

Android - Screen Share - simple implementation #180

Closed JakubHolovsky closed 4 years ago

JakubHolovsky commented 4 years ago

Hello, I am trying to implement simple Screen Share feature on Android using Agora.io. However the example here seems to be overly complex. I wonder, is there any easier way how to achieve this? For example using OnImageAvailableListener or OnFrameAvailableListener (is it even possible?)

I found the EglRenderer. Could I use that for example like this:

var eglRenderer = new EglRenderer("screenshare");
            eglRenderer.AddFrameListener(new AgoraFrameListener(), 1);

Then in the listener push the bitmap data using the PushExternalVideoFrame method?

apiphoomchu commented 4 years ago

What platform did you use IOS?

JakubHolovsky commented 4 years ago

What platform did you use IOS?

we were trying to use Android

shivchand commented 4 years ago

Have u find any solution for it ? I am also looking for it ?

If you have achieve screen sharing by present functionality given by agora then let me know. How to do it . I am facing issue in it

JakubHolovsky commented 4 years ago

@shivchand we are kind of waiting with the Android implementation until Agora provides more robust and easy to implement examples. I reckon that some of the stuff like EglCore etc. should be part of the standard Nuget package or at least it should be packaged in a way so it's easy to implement. Right now the implementation is quite confusing unless you understand the low level Android graphics API.

brianxcli commented 4 years ago

There are surely some other alternative implementations.

The ReadMe explicitly notes the demo is not the only way to do it, and we recommend developers to have their own implementations.

For those who want the entire control, we provide this demo using graphics APIs since they are likely to find difficult to create and maintain OpenGL contexts. In some situations, knowing the texture id of the receiving Surface is convenient, for example, when introducing image processing libraries.

Once you understand this way, other implementations will not be problems.

Of course, it is OK to receive the screen-share content via ImageReader, or set the input surface of a MediaCodec. Anything suits you most.

JakubHolovsky commented 4 years ago

@brianxcli could you confirm that the screen sharing is actually possible by using just ImageReader while having the app in background and getting images of the screen no matter which app is opened? What would be more useful to see a real working example - rather than guessing if it's gonna work or not.

brianxcli commented 4 years ago

As long as you provide a valid Surface, the media projection will work, why can't I be sure about that? I am not guessing but know how it works.

JakubHolovsky commented 4 years ago

Hello @brianxcli thanks for that, sorry for the post sounding too offensive. As long as i have the valid surface is there any easier way how to obtain the data for the AgoraVideoFrame? meaning the buffers etc.? That's the bit that is the most confusing for me.

brianxcli commented 4 years ago

Take ImageReader as an example. Assume you've provided ImageReader.getSurface() to projection. Every time a frame is ready a callback methods is invoked. An Image instance is returned using ImageReader.acquireLatestImage(), and it contains necessary data for a AgoraVideoFrame