Android rtmp推流gni

本文介绍了如何在Android上实现RTMP推流,通过C++编译rtmpdump源码,利用JNI调用C++代码,将FLV文件内容推送到RTMP服务器。详细步骤包括下载rtmpdump源码,配置CMakeLists.txt,定义JNI接口,并实现RTMP连接、发送数据及文件读取等关键函数。
摘要由CSDN通过智能技术生成

1.下载rtmpdum   http://rtmpdump.mplayerhq.hu/

2.CMakelists.txt

cmake_minimum_required(VERSION 3.10.2)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_CRYPTO") #CMAKE_C_FLAGS:用C的方式去编译,  -D传入参数。
include_directories( ${CMAKE_SOURCE_DIR}/include )

add_library( # Sets the name of the library.
        rtmp
        SHARED
        amf.c
        hashswf.c
        log.c
        parseurl.c
        rtmp.c
        native-lib.cpp)

find_library(
        log-lib
        log)

target_link_libraries(
        rtmp
        ${log-lib})

3.native_rtmp.cpp

#include <jni.h>
#include "android_log.h"
#include <exception>

//定义日志宏变量
#define logw(content)   __android_log_write(ANDROID_LOG_WARN,"eric",content)
#define loge(content)   __android_log_write(ANDROID_LOG_ERROR,"eric",content)
#define logd(content)   __android_log_write(ANDROID_LOG_DEBUG,"eric",content)

extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include "rtmp_sys.h"
#include "log.h"
#include <unistd.h>
#include "rtmp.h"
#include <pthread.h>

#define HTON16(x)  ((x>>8&0xff)|(x<<8&0xff00))
#define HTON24(x)  ((x>>16&0xff)|(x<<16&0xff0000)|(x&0xff00))
#define HTON32(x)  ((x>>24&0xff)|(x>>8&0xff00)|\
    (x<<8&0xff0000)|(x<<24&0xff000000))
#define HTONTIME(x) ((x>>16&0xff)|(x<<16&0xff0000)|(x&0xff00)|(x&0xff0000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值