基于http live streaming视频直播在android上的实现

最近将视频客户端移植到了ANDROID平台。 分享一下开发心得。


类似HTTP LIVE STREAMING的流式下载方式, 但APPLE的TS格式冗余数据太多, 我用的是私有格式,更加节省带宽资源。H264+AMRNB编码。每个分片文件20秒。整体架构如下图:


作为HTTP下载模块对稳定性要求比较高,用NDK的话debug会很麻烦,JAVA层下载效率也还行,所以采用JAVA层的HttpURLConnection类, 服务器端在Response header里包含了下一个文件的filename,下一次的连接时将把filename作为URL的一个参数发送。这样就能做到流式的下载。 建立一个bytearrayoutputstream实例来缓存数据。 并通过JNI传递给文件解析层。


因为JAVA与JNI层数据交互很耗时,所以选择下载好一个完整文件再feed给Parser。


AUDIO必须要流畅,所以单开一个thread, Video来得及的话可以用一个timer(减少一点功耗),开一个thread也行。


H264和AMR-NB都移植自OPENCORE, 手机用baseline够了。如果要支持AAC可用helix的AAC解码器或者OPENCORE AAC Decoder.


JNI解码好再回传给JAVA层显示所造成的延时是无法忍受的,所以选择在NDK层直接render画面和声音。 可参考android ffmpeg开源工程里的做法,或者有网友已经总结提取了方法:http://www.cnblogs.com/mcodec/。 付出的代价就是可移植性, 因为现成的libjnivideo.so和libjniaudio.so都是android 2.2版本的, 其他版本会提示can not load libjnivideo.so, 需要在ANDROID工程里重新编译。 ffmpeg和android media framework的代码都可下载:https://github.com/havlenapetr


发现在NDK使用usleep时CPU占用骤增, 所以在做音视频同步的时候,最好不要用usleep.


在V880上测试,在EDGE网络较稳定的情况下, 176*144, 10帧,视频码率48k,音频码率7.95k, 可以流畅播放。 以下是真机效果。(直播我暂时用feature phone的码流 码率只有32K,画面比较模糊)












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fixed-point HE-AAC decoder Developed by RealNetworks, 2005===============================Overview--------This module contains a high-performance HE-AAC decoder for 32-bit fixed-point processors. The following is a summary of what is and is not supported:Supported: - MPEG2, MPEG4 low complexity decoding (intensity stereo, M-S, TNS, PNS) - spectral band replication (SBR), high-quality mode - mono, stereo, and multichannel modes - ADTS, ADIF, and raw data block file formatsNot currently supported: - main or SSR profile, LTP - coupling channel elements (CCE) - 960/1920-sample frame size - low-power mode SBR - downsampled (single-rate) SBR - parametric stereoHighlights - highly optimized for ARM processors (details in docs/ subdirectory) - reference x86 implementation - C and assembly code only (C++ not required for codec library) - reentrant, statically linkable - low memory (details in docs/ subdirectory) - option to use Intel Integrated Performance Primitives (details below)Supported platforms and toolchainsThis codec should run on any 32-bit fixed-point processor which can perform a full 32x32-bit multiply (providing a 64-bit result). The following processors and toolchains are supported: - x86, Microsoft Visual C++ - x86, GNU toolchain (gcc) - ARM, ARM Developer Suite (ADS) - ARM, Microsoft Embedded Visual C++ - ARM, GNU toolchain (gcc)ARM refers to any processor supporting ARM architecture v.4 or above. Thumb is not required.Generally ADS produces the fastest code. EVC 3 does not support inline assembly code for ARM targets, so calls to MULSHIFT32 (smull on ARM) are left as function calls. This incurs a significant performance penalty. For the fastest code on targets which do not normally use ADS consider compiling with ADS, using the -S option to output assembly code, and feeding this assembly code to the assem
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值