在Android端SDK实现了RTMFP协议

做直播这门也有个5年多了,RTMFP协议是梦寐以求的移动客户端实现.在今天,还是成功实现到Android上了.

注意,不是flash,不是AIR哦,而是真正原生c\c++实现.

rtmfp是个激动人心的技术,udp传输\p2p连接\NetGroup,很可能改变直播行业的现状.

欢迎尝鲜:https://github.com/NodeMedia/NodeMediaClient-Android/releases/tag/v2.0.1

SRS-win32 版更新,支持HTTP-FLV

srs-win32编译版 simple rtmp server是Linux环境下运营级流媒体服务器SRS的windows编译版,目的是方便windows平台开发者快速部署流媒体服务器开发测试环境.
同经典的Nginx-Rtmp-Win32项目一样,SRS-win32编译版提供了基本的RTMP\HLS服务.另外,还提供了目前直播app中非常流行的HTTP-FLV格式.
同样,该项目不建议做运营使用,项目是在cygwin环境下编译,默认最大打开文件数256,尽管可以在cygwin环境下修改ulimit数(2016.9.22:最新版2.0.217已默认设置最大打开文件数1024,注意:后来经过验证,即使是改了这地方,程序仍然不能开上百个连接), 但是由于没有Linux环境的epoll,无法高并发.但作为开发测试用已经足够了.
非常建议之前使用Nginx-Rtmp-Win32的开发者使用此项目.

都散了吧,博主精力有限,不会再出新版本了.
如果希望使用Windows平台开发,可以试试博主用Node.js实现的服务端:Node-Media-Server  真正跨平台,高性能谈不上,但上千路没有一点问题.流媒体服务不像HTTP,连接数还没上去,带宽已经跑满了,别太在意并发数.支持RTMP输入,RTMP/HTTP-FLV/WEBSOCKET-FLV输出,支持GOP_CACHE,推流鉴权,播放防盗链.

Eclipse开发Android-NDK项目自动生成javah头文件

博主双修Android,iOS底层库开发也有好几年了,一直盼望Android平台能有Xcode那样强大的IDE,尽管Eclipse的ADT插件也能很好的代码提示,自动补全,但每次新开类生成javah文件也是比较头疼的。

Android Studio从1.3版本开始说是加强NDK的接入,引入了『com.android.tools.build:gradle-experimental』,从功能使用上来看还是挺好的,比如能在java层自动生成对应的jni方法,并能在java和c\c++之间函数跳转,还能自动生成一些简单的env操作,比如转换String类。但是,这个gradle-experimental的写法和默认的gradle差别太大,到博主发这篇帖子是,AS2.1.2仍然还在开发这个插件。AS 2.2 preview版已经可以支持cmake和mk的编译了,而且cmake作为新建项目时勾选c++支持的默认形式了,难道要放弃gradle-experimental 🙁 。目前还不支持代码提示,跳转这些基本操作,后面的版本应该会加强吧。

另外还有一个比较严重的问题,Android Studio好慢,越来越慢了,经常导入一个项目卡半天,最后只能强制退出。项目编译起来,i7-4790都觉得用起来卡。博主到现在仍然使用最经典的Eclipse Indigo,哈哈。

废话完了,现在帖正题,Eclipse其实也是很强大的,我这里利用Ant脚本来实现自动化编译javah头文件。 继续阅读“Eclipse开发Android-NDK项目自动生成javah头文件”

RTMP流媒体服务端应用开发系列 – Nginx-Rtmp鉴权设置

鉴权验证在自建直播流媒体服务端应用中是非常重要的。用以防止非法推流,控制收费播放盗链等场景。
目前各大直播云平台都支持url参数形式的鉴权验证法,例如rtmp://serverhost/app-name/stream-name?key=md5(secret+expires_timestemp)&time=expires_timestemp 这种既有私密key,又有时间戳过期判断的最简单形式,当然还能根据使用场景增加其他判断条件。
Nginx-Rtmp模块作为rtmp直播流媒体服务端,本身没有这种鉴权验证法,但能通过Notify 转为本地的http请求,使用Nginx内置的ngx_http_secure_link_module即能达到同样效果。

首先利用Nginx-Rtmp的on_play通知,将rtmp的播放事件通知到本地的http处理上来 继续阅读“RTMP流媒体服务端应用开发系列 – Nginx-Rtmp鉴权设置”

FFmpeg 3.1 发布

上个月第发布的最新版3.1,特性太多,高亮几个做移动多媒体开发的关注点

  • DXVA2-accelerated HEVC Main10 decoding
  • fieldhint filter
  • loop video filter and aloop audio filter
  • Bob Weaver deinterlacing filter
  • firequalizer filter
  • datascope filter
  • bench and abench filters
  • ciescope filter
  • protocol blacklisting API
  • MediaCodec H264 decoding
  • VC-2 HQ RTP payload format (draft v1) depacketizer and packetizer
  • VP9 RTP payload format (draft v2) packetizer
  • AudioToolbox audio decoders
  • AudioToolbox audio encoders
  • coreimage filter (GPU based image filtering on OSX)
  • libdcadec removed
  • bitstream filter for extracting DTS core
  • ADPCM IMA DAT4 decoder
  • musx demuxer
  • aix demuxer
  • remap filter
  • hash and framehash muxers
  • colorspace filter
  • hdcd filter
  • readvitc filter
  • VAAPI-accelerated format conversion and scaling
  • libnpp/CUDA-accelerated format conversion and scaling
  • Duck TrueMotion 2.0 Real Time decoder
  • Wideband Single-bit Data (WSD) demuxer
  • VAAPI-accelerated H.264/HEVC/MJPEG encoding
  • DTS Express (LBR) decoder
  • Generic OpenMAX IL encoder with support for Raspberry Pi
  • IFF ANIM demuxer & decoder
  • Direct Stream Transfer (DST) decoder
  • loudnorm filter
  • MTAF demuxer and decoder
  • MagicYUV decoder
  • OpenExr improvements (tile data and B44/B44A support)
  • BitJazz SheerVideo decoder
  • CUDA CUVID H264/HEVC decoder
  • 10-bit depth support in native utvideo decoder
  • libutvideo wrapper removed
  • YUY2 Lossless Codec decoder
  • VideoToolbox H.264 encoder

包括了iOS平台上的硬件编解码AAC,硬件编码H.264,Android平台的硬件解码,树莓派的OpenMAX IL硬编码器。官方强烈建议各位升级 :D。

Android使用EGL_image从GPU中读取渲染后的画面,部分手机花屏错位的问题

你已经能使用EGL_image扩展从GPU中读取渲染后的画面了。但你可能会发现,参数一样,有些手机预览时都是正确的,但输出的画面,呈现很有规律的错位花屏,像这样:
预览—-
QQ20160612-0

输出—-
QQ20160612-1

很典型的由于图片stride 和width不同造成的,比较常规的解决方案是

 

[转]Using GL_OES_EGL_image_external on Android

1. The texture target needs to be GLES20.GL_TEXTURE_EXTERNAL_OES instead of GL_TEXTURE_2D, e.g. in the glBindTexture calls and glTexParameteri calls.

2. In the fragment shader define a requirement to use the extension:#extension GL_OES_EGL_image_external : require

3. For the texture sampler used in the fragment shader, use samplerExternalOES instead of sampler2D. Everything below here is all in the C code, no more Java.

4. In the C code, use glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, eglImage) to specify where the data is, instead of using glTexImage2D family of functions.

5. Now, this is android specific, as GraphicBuffer.h is defined in the android native source code. new a GraphicBuffer object, and init with with the width, height, pixel format, etc… this is where we’ll be writing the pixels to. Also, the android’s GraphicBuffer object is the one that will allocate the memory for us i.e. call gralloc.

6. To write pixels to the GraphicBuffer, lock it via graphicBuffer->lock(GRALLOC_USAGE_SW_WRITE_RARELY, (void **) &pixels), lock() will give you the address to write the pixels to in the 2nd parameter. Once you have the address, now, you can freely write the data to the address pixels.

7. After you finish writing, unlock it, graphicBuffer->unlock().

8. Now, you need the eglImage object to pass into glEGLImageTargetTexture2DOES in step 4. To create the eglImage using createEGLImageKHR(). http://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_image_base.txt. 4th parameter to eglCreateImageKHR() takes in a EGLClientBuffer, use this (EGLClientBuffer) graphicBuffer->getNativeBuffer();

9. To clean up, use eglDestroyImageKHR(). I think that’s about it. Everything is public API: glEGLImageTargetTexture2DOES(), eglCreateEGLImageKHR(), eglDestroyImageKHR(). gralloc is used, and the implementation of GraphicsBuffer object in the android native source code does that for us.

https://gist.github.com/rexguo/6696123

RTMP流媒体服务端应用开发系列 – Nginx-Rtmp分离音视频流

开一个RTMP 流媒体服务端开发系列的坑,主要用到Rtmp-Nginx, Linux平台。

需求:推流端发布后,播放端只希望拉取播放纯音频或视频流。

分析:这种需求可能是为了效仿映客直播分离音视频流来播放的方法。从抓包来看,映客使用http-flv的CDN加速直播流,形如
http://pull.a8.com/live/1458696839457751.flv?only-video=1
http://pull.a8.com/live/1458696839457751.flv?only-audio=1
有什么好处? 不确定,估计播放端网络卡时,可以断开视频流但保持码率不大的音频流,体验较好。 还有一种可能是方便做纯音频类应用,播放端只想听到音频,虽然可以不解码视频,但是视频的数据也不想拉下来,节省移动数据流量。

思路:使用Nginx-Rtmp的exec来调用ffmpeg,在服务端分离rtmp流。

实现: 继续阅读“RTMP流媒体服务端应用开发系列 – Nginx-Rtmp分离音视频流”

Android NDK更新到 11

NDK自上次10E后已有10个月更新了11,看了下发行日志,主要这几点值得关注。

  1. 官方推荐从GCC转到Clang了,clang也更新到3.8版。
  2. GCC只保留4.9版了,也不再更新到5.x版。
  3. samples和documentation也不再包含进NDK开发包,都放在了网上。
    NDK Samples :GitHub.
    Doc:Android developer website.
  4. Added Vulkan headers and library to API level N. 这个牛B啊,这不是khronos刚推出的用来替代OpenGL和OpenGL ES的新API么。这都已经可以用啦,后面专门在研究研究。 至少需要Android N的机器。

在DD-WRT路由器上设置VPN服务为3G/4G网络提供google服务

目前Google系列服务使用hosts的方式访问仍然是比较方便的,在DD-WRT路由器上设置DNSMas来通配google.com 来为本局域网内所有设备提供简单的访问方式。

但有时候外出使用3/4G时也想使用,又不想花钱,在自家DD-WRT路由器上开启VPN服务就行!

首先需要满足如下条件:

  1. 一台DD-WRT路由器
  2. 家里的宽带有公网IP,并能从外部链入。

步骤:

  1. 先注册花生壳动态域名解析,网上教程颇多这里就不重复了。
  2. DDWRT-> 设置->动态DNS
    QQ20160316-1
  3. DDWRT->服务->VPN
    QQ20160316-2
    服务器IP就填路由器IP,客服端IP是一个范围,CHAP-Secrets 就是账户区,格式是
    用户名+ 空格 + * + 空格 + 密码 + 空格 + *
  4. DDWRT->NAT/QoS ->端口转发
    QQ20160316-3
    添加一条VPN的1723端口转发。
  5. DDWRT->服务->服务
    QQ20160316-4
    开启DNSMasq,添加规则。至于hosts我就不公布我用的了,网上也挺多。

手机切到3G/4G,添加VPN,地址填花生壳注册下来的动态域名,用户名密码就是CHAP-Secrets里添加的,连接成功,试试看google.com是否就能打开了。

当然,也不只是3,4G网络环境,你在其它WIFI环境下也能用。也不只google服务可以用hosts+https来访问,facebook,twitter也是可以的,浏览器、APP都可以。

关键是一分钱都不用花,博主路由器是TP-LINK WR841N-V7刷的。