EasyPusher Android实时推送当前屏幕画面
2016-09-24 16:02
344 查看
由于Android 5.0提供了捕获当前屏幕画面的SDK,基于该SDK,EasyPusher实现了实时推送手机屏幕画面的功能。经测试,效果很不错,延迟也比较低,画面也比较流畅。该功能可运用到小型会议PPT演示、手游直播等行业。
具体来说,MediaProjection 类可以将当前屏幕画面采集到一个surface里面,而MediaCodec可以从一个surface里面获取视频数据源。我们让MediaProjection投射到MediaCodec创建的Surface,MediaCodec就可以获取到MediaProjection投射的视频了。如图所示:
Created with Raphaël 2.1.0MediaProjectionMediaProjectionSurfaceSurfaceMediaCodecMediaCodecEasyPusherEasyPusher投射屏幕提供视频源编码编码数据通过Pusher推送
在这里就不再详细描述代码的实现,主要介绍下两个接口:
然后,将后者得到的Surface作为第6个参数传给前者,前者就可以获取到屏幕数据了~
如下图所示,在VLC访问RTSP地址,即可看到屏幕直播。
EasyPusher项目见:https://github.com/EasyDarwin/EasyPusher
具体来说,MediaProjection 类可以将当前屏幕画面采集到一个surface里面,而MediaCodec可以从一个surface里面获取视频数据源。我们让MediaProjection投射到MediaCodec创建的Surface,MediaCodec就可以获取到MediaProjection投射的视频了。如图所示:
Created with Raphaël 2.1.0MediaProjectionMediaProjectionSurfaceSurfaceMediaCodecMediaCodecEasyPusherEasyPusher投射屏幕提供视频源编码编码数据通过Pusher推送
在这里就不再详细描述代码的实现,主要介绍下两个接口:
VirtualDisplay createVirtualDisplay (String name, int width, int height, int dpi, int flags, Surface surface, VirtualDisplay.Callback callback, Handler handler) Creates a VirtualDisplay to capture the contents of the screen. Parameters name String: The name of the virtual display, must be non-empty. 要创建的投射器的名称,非空 width int: The width of the virtual display in pixels. Must be greater than 0. 投射后视频的宽度,这里的宽度就是实际上后面MediaCodec初始化的宽度. height int: The height of the virtual display in pixels. Must be greater than 0. 投射后视频的高度,这里的宽度就是实际上后面MediaCodec初始化的高度. dpi int: The density of the virtual display in dpi. Must be greater than 0. 投射器的像素密度,未理解啥意思,我们直接用DisplayMetrics的densityDpi即可. flags int: A combination of virtual display flags. See DisplayManager for the full list of flags. 我们传 DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR|DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC|DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION 即可。 surface Surface: The surface to which the content of the virtual display should be rendered, or null if there is none initially. 投射器要投射到的Surface callback VirtualDisplay.Callback: Callback to call when the virtual display's state changes, or null if none. 投射器更改后的状态回调,我们这里不需要,传null即可。 handler Handler: The Handler on which the callback should be invoked, or null if the callback should be invoked on the calling thread's main Looper. 回调函数将在该Handler所在的线程调用,我们也不需要,传null即可。
createInputSurface Surface createInputSurface () Requests a Surface to use as the input to an encoder, in place of input buffers. 该接口创建一个作为编码器输入的Surface。
然后,将后者得到的Surface作为第6个参数传给前者,前者就可以获取到屏幕数据了~
如下图所示,在VLC访问RTSP地址,即可看到屏幕直播。
EasyPusher项目见:https://github.com/EasyDarwin/EasyPusher
相关文章推荐
- EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用
- EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用
- EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用
- EasyRTC EasyPusher 推送 视频画面旋转90度问题
- Android开发:在代码里面滚动当前屏幕
- Android中截取当前屏幕图片
- Android中用java截取当前屏幕的功能
- Android开发经验一判断当前屏幕是全屏还是非全屏
- Android ListView只加载当前屏幕内的图片(解决list滑动时加载卡顿)
- Android 旋转屏幕捕获当前屏幕的状态
- [Android] 获得系统当前屏幕的分辨率
- android 获得当前view在屏幕的坐标
- Android ListView只加载当前屏幕内的图片(解决list滑动时加载卡顿)
- 设定Android当前屏幕锁屏和解锁屏
- 关于android推送服务-点击通知栏回不到当前应用程序的问题研究
- android下截取当前屏幕程序中遇到的错误总结
- Android中截取当前屏幕的功能
- [Android] 008_得到当前手机屏幕的宽度和高度
- Android中截取当前屏幕的功能
- Android屏幕尺寸、标题栏高度、状态栏高度、当前View尺寸