最近做一款Android与蓝牙BLE设备通讯的项目,记录下开发经验。

蓝牙设备是JDY-19模块,串口透传,非常方便好用。官方教程需要创建Service进行通讯,此处需求为简单数据透传,直接在Activity中收发完成就结束,不开启服务,简单便捷。话不多说,代码伺候。

一、Android扫描BLE设备

0. 开启权限

1. 检查是否有BLE支持

2.检查是否有蓝牙支持

继续阅读

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: Android BLE通讯详解,连接JDY-19

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

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

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

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

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: 在Android端SDK实现了RTMFP协议

博主双修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头文件

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

输出—-
QQ20160612-1

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

 

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

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: [转]Using GL_OES_EGL_image_external on Android

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的机器。

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: Android NDK更新到 11

进行Android NDK开发,最好用的还是Eclipse.新版本由于存在找不到头文件的问题,博主之前一直使用Eclipse Indigo. 使用下面的解决方法后,Juno,Kepler,Luna都正常了。

以下摘录自stackoverflow

原帖地址:http://stackoverflow.com/questions/23122934/eclipse-adt-unresolved-inclusion-jni-h

I ran into a similar problem with a working project with Android NDK-based code after updating to Eclipse Kepler. I observed similar things: the header files would correctly be listed under “includes” in the project, the actual build (via ndk-build) worked fine, but Eclipse’s editor couldn’t locate any headers in standard system directories (all headers with < > brackets).继续阅读

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: [转]解决更新Eclipse后,Android NDK开发找不到头文件的问题

实时的摄像头采集,实时编码,实时发布到流媒体服务器,进行视频直播。视频采用H.264,音频采用AAC,可根据需求发布480×360,320×240,240×180分辨率的视频。可控帧率,码率。320×240分辨率@10fps 中等质量,码率为160kbps左右,非恒定。cpu占用30%左右。
客户端使用Flash播放,跨平台兼容性好。
也可配合使用Android iOS SDK开发手机客户端。

  • 音频编码器:AAC,nellymoser,speex
  • 视频解码器: H.264
  • 协议:RTMP,RTMPT
  • ARMV7-A Neon加速
  • 极速精简内核,so库仅2.0M

前往下载:http://www.nodemedia.cn/zh/client/NodeMediaClient-Android/

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: Android RTMP Live Encoder SDK

RTMP协议的实时视频播放客户端开发库,jni开发,java接口,可配合Adobe Flash Media Live Encoder 3.2或Android iOS直播发布端SDK进行实时视频直播。

  • 音频解码器:AAC,mp3,nellymoser,speex
  • 视频解码器: H.264,flv
  • 协议:RTMP,RTMPT
  • ARMV7-A Neon加速
  • 极速精简内核,so库仅1.4M

前往下载:http://www.nodemedia.cn/zh/client/NodeMediaClient-Android/

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: Android RTMP Live Player SDK

关于Android5.0开放的Native-codec测试一文中有提到4.0通过OpenMAX AL接口实现硬解码。可以先从分析native-media这个sample开始,可以在ndk目录中找到。

  1. 首先调用Java_com_example_nativemedia_NativeMedia_createEngine ?创建引擎和output mix 对象。
  2. Java_com_example_nativemedia_NativeMedia_setSurface 将java层的Surface对象转为NativeWindow对象用于视频显示
  3. Java_com_example_nativemedia_NativeMedia_createStreamingMediaPlayer ?初始化data source、?audio sink、image video sink、media player等对象 ,注册AndroidBufferQueueCallback?StreamChangeCallback两个回调,调用enqueueInitialBuffers预填充部分初始数据。
  4. enqueueInitialBuffers中通过读取ts文件获取足够量的buffer用于初始化
  5. AndroidBufferQueueCallback 的注释:?register the callback from which OpenMAX AL can retrieve the data to play,程序回调这里说明可以读buffer开始播放了

继续阅读

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: Android 4.0以上系统硬件解码RTMP流的一种方式