本文转自EasyDarwin开源团队成员John的博客:http://blog.csdn.net/jyt0551/article/details/52651194

由于Android 5.0提供了捕获当前屏幕画面的SDK,基于该SDK,EasyPusher实现了实时推送手机屏幕画面的功能。经测试,效果很不错,延迟也比较低,画面也比较流畅。该功能可运用到小型会议PPT演示、手游直播等行业。

具体来说,MediaProjection 类可以将当前屏幕画面采集到一个surface里面,而MediaCodec可以从一个surface里面获取视频数据源。我们让MediaProjection投射到MediaCodec创建的Surface,MediaCodec就可以获取到MediaProjection投射的视频了。如图所示:

MediaProjectionMediaProjectionSurfaceSurfaceMediaCodecMediaCodecEasyPusherEasyPusher投射屏幕提供视频源编码编码数据通过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即可。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
createInputSurface

Surface createInputSurface ()
Requests a Surface to use as the input to an encoder, in place of input buffers. 该接口创建一个作为编码器输入的Surface。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

然后,将后者得到的Surface作为第6个参数传给前者,前者就可以获取到屏幕数据了~

如下图所示,在VLC访问RTSP地址,即可看到屏幕直播。

EasyPusher项目见:https://github.com/EasyDarwin/EasyPusher

获取更多信息

邮件:support@easydarwin.org

WEB:www.EasyDarwin.org

Copyright © EasyDarwin.org 2012-2016

EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用的更多相关文章

  1. 基于EasyDarwin EasyPusher实现Android手机直播推送功能

    EasyPusher直播推送在之前就已经稳定支持了Windows.Linux.ARM上的RTSP直播推送功能,配合EasyDarwin开源流媒体服务器,延时基本在1s以内,这个技术方案经过一年多时间, ...

  2. 获取Android 手机屏幕宽度和高度以及获取Android手机序列号

    1.获取Android 手机屏幕宽度 1 DisplayMetrics dm = new DisplayMetrics(); 2 this.getWindowManager().getDefaultD ...

  3. Unity3D Android手机屏幕分辨率问题

    Android手机屏幕分辨率五花八门,导致开发时不好把握,还好各个引擎对这个屏幕分辨率问题都有较好的处理方式:unity3D 也为我们提供了一个不错的解决方案. 在Unity3D 进行 android ...

  4. 熊猫ios手游直播教程 苹果投屏电脑

    如今手游越来越火热,不管是大人小孩都喜欢在闲暇时刻玩一玩游戏,手机屏幕终归还是有点小的,所以有的小伙伴想要将手机投屏到电脑上,岂不是一件很好的事情,iPhone是有镜像投屏功能的,下面给大家分享熊猫i ...

  5. 基于Node.js的实时推送 juggernaut

    基于Node.js的实时推送 juggernaut Juggernaut 基于 Node.js 构建.为浏览器和服务器端提供一个实时的连接,可在客户端和服务器端进行数据的实时推送,适合多角色游戏.聊天 ...

  6. 使用SignalR ASP.NET Core来简单实现一个后台实时推送数据给Echarts展示图表的功能

    什么是 SignalR ASP.NET Core ASP.NET Core SignalR 是一种开放源代码库,可简化将实时 web 功能添加到应用程序的功能. 实时 web 功能使服务器端代码可以立 ...

  7. 【原创】node+express+socket搭建一个实时推送应用

    技术背景 Web领域的实时推送技术,也被称作Realtime技术.这种技术要达到的目的是让用户不需要刷新浏览器就可以获得实时更新. 应用场景: 监控系统:后台硬件热插拔.LED.温度.电压发生变化 即 ...

  8. SignalR实时推送

    SignalR 的实现机制与 .NET WCF 或 Remoting 是相似的,都是使用远程代理来实现.在具体使用上,有两种不同目的的接口:PersistentConnection 和 Hubs,其中 ...

  9. HTML5 WebSocket 实时推送信息测试demo

    测试一下HTML5的websocket功能,实现了客户端→服务器实时推送信息到客户端,包括推送图片: websocket实现MessageInbound类 onTextMessage()/onBina ...

随机推荐

  1. PE+ 1.0 ( Pump Express Plus 1.0 )

    Dialog iW1788 for PE+ 1.0 Dialog iW1680 for PE PE+1.0 for up to 15W battery, improve charging time, ...

  2. Larevel5.1 打印SQL语句

    Larevel5.1 打印SQL语句 为了方便调试,开发时需要打印sql. 方法一(全局打开): SQL打印默认是关闭的, 需要在/vendor/illuminate/database/Connect ...

  3. LibieOJ 6170 字母树 (Trie)

    题目链接 字母树 (以每个点为根遍历,插入到trie中,统计答案即可)——SamZhang #include <bits/stdc++.h> using namespace std; #d ...

  4. git 撤回上一次commit中某一个不想添加的文件

    1. 假设我们修改了文件a,同时修改了IDE的配置文件b 2.此时我们只想添加文件a到commit中,却不小心将b也添加进去了 3.那么怎么撤回呢? 4.第一种方法 :重新提交commit 5. 第二 ...

  5. Codechef FNCS Chef and Churu

    Disciption Chef has recently learnt Function and Addition. He is too exited to teach this to his fri ...

  6. jquery图片左右来回循环飘动

    $(function () { function left_right() { $("#sc1452").animate({'left':'-=100'},5000).delay( ...

  7. java后4位打成*显示

    /** * [固定电话] 后四位,其他隐藏<例子:****1234> * * @param num * @return */ public static String fixedPhone ...

  8. iOS -- SKScene类

      SKScene类 继承自 SKEffectNode:SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject ...

  9. python中a=a+2与a+=2的区别

    1.a=a+2,表示一个新的对象,新的对象名字还是a,但是指向的内存地址已经变了 >>> a=2 >>> id(a) 140406287260016 >> ...

  10. css 中的浮动

    css中 浮动的作用: 使元素脱离正常的文档流并使其移动到其父元素的“最左边”或“最右边”. css中 浮动的特点: 1)改变元素类型,使元素支持宽高: 2)半脱离文档流: 3)文本环绕: 4)顶对齐 ...