用librtmp接收H264+AAC的例子代码网上参考资源比较少,这份代码来自www.cnblogs.com的某个博客,但是已经找不到原链接了。把代码附上,帮助各位网友在开发时少走些弯路。
//
#include "librtmp/rtmp_sys.h"
#include "librtmp/log.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&0xff000000))
#pragma comment(lib, "librtmp.lib")
#pragma pack(1)
typedef struct _FLVHead
{
char type[3];
char version;
char stream_info;
int offset;
}FLVHead;
typedef struct _FLVTag
{
int tag_size;
char type;
char length[3];
char timecamp[3];
char timecampex;
char StreamsID[3];
}FLVTag;
#pragma pack()
char* ByteRead8(int *i8, char *buf)
{
memcpy(i8, buf, 1);
return buf+1;
}
char* ByteRead16(int *i16, char *buf)
{
memcpy(i16, buf, 2);
*i16 = HTON16(*i16);
return buf+2;
}
char* ByteRead32(int *i32, char *buf)
{
memcpy(i32, buf, 4);
*i32 = HTON32(*i32);
return buf+4;
}
void UnPackH264(char *data,int len, char * outData, int & outLen)
{
int h264space = 0x01000000;
char *buf = data+1;
char * pOutBuf = outData;
int avctype = 0;
buf = ByteRead8(&avctype,buf);
buf += 3;
int templength = 0;
char *tempbuff = NULL;
if (avctype == 0)
{
buf += 6;
buf = ByteRead16(&templength,buf);
tempbuff = buf;
// fwrite(&h264space, 1, 4, h264file);
memcpy(pOutBuf, &h264space, 4);
pOutBuf += 4;
// fwrite(tempbuff, 1, templength, h264file);
memcpy(pOutBuf, tempbuff, templength);
pOutBuf += templength;
buf += templength;
buf = ByteRead8(&templength, buf);
buf = ByteRead16(&templength, buf);
tempbuff = buf;
// fwrite(&h264space, 1, 4, h264file);
memcpy(pOutBuf, &