imx6移植librtmp

时间:2023-03-09 01:27:16
imx6移植librtmp
一.openssl交叉编译
1.下载
版本不要太高,刚开始版本高了,有些函数取消了,链接不上
使用1.0.1f即可
2.编译成共享库
./config no-asm shared --prefix=/usr/local/arm/openssl
3.修改Makefile
CROSS_COMPILE=arm-none-linux-gnueabi-
4.make
make install
二.zlib交叉编译
1.下载
2../configure --prefix=/usr/local/arm/zlib
3.修改Makefile
gcc、ar的地方换成交叉编译器的
三.rtmpdump 交叉编译
1.下载
git clone git://git.ffmpeg.org/rtmpdump
2.编译
直接修改makefile,需要修改两个makefile
prefix=/usr/local/arm/librtmp
CROSS_COMPILE=arm-none-linux-gnueabi-
XLDFLAGS=-L/usr/local/arm/openssl/lib -L/usr/local/arm/zlib/lib
XCFLAGS=-I/usr/local/arm/openssl/include -I/usr/local/arm/zlib/include
注意:inlude里不要有文件夹,头文件直接放在include下
3.make
cannot find -lz可能会出现这种错误,产生这种错误是在编译客户程序才出现,此时librtmp库已经生成,直接可以使用.so库
 imx6移植librtmp
测试代码
/*
* main.cpp
*
* Created on: Jan 9, 2017
* Author: tla001
*/
extern "C"{
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> #include "rtmp.h"
#include "log.h"
} int printfAVal(const AVal al)
{
int i = ;
for(i = ;i <al.av_len;i++)
printf("%c",al.av_val[i]);
printf("\n");
} const char RTMPProtocolStringsLower_1[][] = {
"rtmp",
"rtmpt",
"rtmpe",
"rtmpte",
"rtmps",
"rtmpts",
"",
"",
"rtmfp"
}; #define DEF_TIMEOUT 30 /* seconds */ int main(int argc,char * argv[])
{
int Ret = -;
RTMP my_rtmp;
AVal Host, App, Playpath;
unsigned int Port = ;
int Protocol = RTMP_PROTOCOL_UNDEFINED; AVal sockshost = { , };
AVal tcUrl = { , };
AVal swfUrl = { , };
AVal pageUrl = { , };
AVal auth = { , };
AVal swfSHA256Hash = { , };
AVal flashVer = { , };
AVal subscribepath = { , };
AVal usherToken = { , };
uint32_t swfSize = ;
uint32_t dSeek = ; // seek position in resume mode, 0 otherwise
int bLiveStream = FALSE; // is it a live stream? then we can't seek/resume
uint32_t dStopOffset = ;
long int timeout = DEF_TIMEOUT; // timeout connection after 120 seconds int fd = ; char *input_rtmp_url = NULL;
char RTMP_RUL[] = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
if(argv[]==NULL){
input_rtmp_url = RTMP_RUL;
}else{
input_rtmp_url = argv[];
} printf("run %s\n",(char*)argv[]);
printf("input_rtmp_url == %s\n",input_rtmp_url); RTMP_Init(&my_rtmp); //InitSockets(); Ret = RTMP_ParseURL(input_rtmp_url, &Protocol, &Host, &Port,
&Playpath, &App);
if(Ret == TRUE){
printfAVal(Host);
printfAVal(App);
printfAVal(Playpath);
printf("%d\n",Port);
}else{
printf("url(%s) con`t parsed!\n",input_rtmp_url);\
goto EXIT;
} if (Port == )
{
if (Protocol & RTMP_FEATURE_SSL)
Port = ;
else if (Protocol & RTMP_FEATURE_HTTP)
Port = ;
else
Port = ;
} if (tcUrl.av_len == )
{
tcUrl.av_len = strlen(RTMPProtocolStringsLower_1[Protocol]) +
Host.av_len + App.av_len + sizeof("://:65535/");
tcUrl.av_val = (char *) malloc(tcUrl.av_len);
if (!tcUrl.av_val)
return -;
tcUrl.av_len = snprintf(tcUrl.av_val, tcUrl.av_len, "%s://%.*s:%d/%.*s",
RTMPProtocolStringsLower_1[Protocol], Host.av_len,
Host.av_val,Port, App.av_len, App.av_val);
} RTMP_SetupStream(&my_rtmp,
Protocol,
&Host,
Port,
&sockshost,
&Playpath,
&tcUrl,
&swfUrl,
&pageUrl,
&App,
&auth,
&swfSHA256Hash,
swfSize,
&flashVer,
&subscribepath,
&usherToken,
dSeek,
dStopOffset,bLiveStream, timeout); RTMP_Connect(&my_rtmp,NULL); RTMP_ConnectStream(&my_rtmp,dSeek); fd = open("test.flv",O_CREAT|O_RDWR); if(fd){
char buf[*] = {};
while(){
memset(buf,,*);
Ret = RTMP_Read(&my_rtmp,buf,*);
printf("read size %d\n",Ret);
if(Ret <= )
break;
else{
write(fd,buf,Ret);
}
}
}
EXIT:
if(fd)
close(fd);
RTMP_Close(&my_rtmp);
return ;
}