1.下载rtmpdum http://rtmpdump.mplayerhq.hu/
- git clone git://git.ffmpeg.org/rtmpdump
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