/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
* Copyright (C) 2008-2009 Andrej Stepanchuk
* Copyright (C) 2009-2010 Howard Chu
*
* This file is part of librtmp.
*
* librtmp is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1,
* or (at your option) any later version.
*
* librtmp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "rtmp_sys.h"
#include "log.h"
#ifdef CRYPTO
#ifdef USE_POLARSSL
#include <polarssl/havege.h>
#elif defined(USE_GNUTLS)
#include <gnutls/gnutls.h>
#else /* USE_OPENSSL */
#include <openssl/ssl.h>
#include <openssl/rc4.h>
#endif
TLS_CTX RTMP_TLS_ctx;
#endif
#define RTMP_SIG_SIZE 1536
#define RTMP_LARGE_HEADER_SIZE 12
static const int packetSize[] = { 12, 8, 4, 1 };
int RTMP_ctrlC;
const char RTMPProtocolStrings[][7] = {
"RTMP",
"RTMPT",
"RTMPE",
"RTMPTE",
"RTMPS",
"RTMPTS",
"",
"",
"RTMFP"
};
const char RTMPProtocolStringsLower[][7] = {
"rtmp",
"rtmpt",
"rtmpe",
"rtmpte",
"rtmps",
"rtmpts",
"",
"",
"rtmfp"
};
static const char *RTMPT_cmds[] = {
"open",
"send",
"idle",
"close"
};
typedef enum {
RTMPT_OPEN=0, RTMPT_SEND, RTMPT_IDLE, RTMPT_CLOSE
} RTMPTCmd;
static int DumpMetaData(AMFObject *obj);
static int HandShake(RTMP *r, int FP9HandShake);
static int SocksNegotiate(RTMP *r);
static int SendConnectPacket(RTMP *r, RTMPPacket *cp);
static int SendCheckBW(RTMP *r);
static int SendCheckBWResult(RTMP *r, double txn);
static int SendDeleteStream(RTMP *r, double dStreamId);
static int SendFCSubscribe(RTMP *r, AVal *subscribepath);
static int SendPlay(RTMP *r);
static int SendBytesReceived(RTMP *r);
#if 0 /* unused */
static int SendBGHasStream(RTMP *r, double dId, AVal *playpath);
#endif
static int HandleInvoke(RTMP *r, const char *body, unsigned int nBodySize);
static int HandleMetadata(RTMP *r, char *body, unsigned int len);
static void HandleChangeChunkSize(RTMP *r, const RTMPPacket *packet);
static void HandleAudio(RTMP *r, const RTMPPacket *packet);
static void HandleVideo(RTMP *r, const RTMPPacket *packet);
static void HandleCtrl(RTMP *r, const RTMPPacket *packet);
static void HandleServerBW(RTMP *r, const RTMPPacket *packet);
static void HandleClientBW(RTMP *r, const RTMPPacket *packet);
static int ReadN(RTMP *r, char *buffer, int n);
static int WriteN(RTMP *r, const char *buffer, int n);
static void DecodeTEA(AVal *key, AVal *text);
static int HTTP_Post(RTMP *r, RTMPTCmd cmd, const char *buf, int len);
static int HTTP_read(RTMP *r, int fill);
#ifndef _WIN32
static int clk_tck;
#endif
#ifdef CRYPTO
#include "handshake.h"
#endif
uint32_t
RTMP_GetTime()
{
#ifdef _DEBUG
return 0;
#elif defined(_WIN32)
return timeGetTime();
#else
struct tms t;
if (!clk_tck) clk_tck = sysconf(_SC_CLK_TCK);
return times(&t) * 1000 / clk_tck;
#endif
}
void
RTMP_UserInterrupt()
{
RTMP_ctrlC = TRUE;
}
void
RTMPPacket_Reset(RTMPPacket *p)
{
p->m_headerType = 0;
p->m_packetType = 0;
p->m_nChannel = 0;
p->m_nTimeStamp = 0;
p->m_nInfoField2 = 0;
p->m_hasAbsTimestamp = FALSE;
p->m_nBodySize = 0;
p->m_nBytesRead = 0;
}
int
RTMPPacket_Alloc(RTMPPacket *p, int nSize)
{
char *ptr = calloc(1, nSize + RTMP_MAX_HEADER_SIZE);
if (!ptr)
return FALSE;
p->m_body = ptr + RTMP_MAX_HEADER_SIZE;
p->m_nBytesRead = 0;
return TRUE;
}
void
RTMPPacket_Free(RTMPPacket *p)
{
if (p->m_body)
{
free(p->m_body - RTMP_MAX_HEADER_SIZE);
p->m_body = NULL;
}
}
void
RTMPPacket_Dump(RTMPPacket *p)
{
RTMP_Log(RTMP_LOGDEBUG,
"RTMP PACKET: packet type: 0x%02x. channel: 0x%02x. info 1: %d info 2: %d. Body size: %lu. body: 0x%02x",
p->m_packetType, p->m_nChannel, p->m_nTimeStamp, p->m_nInfoField2,
p->m_nBodySize, p->m_body ? (unsigned char)p->m_body[0] : 0);
}
int
RTMP_LibVersion()
{
return RTMP_LIB_VERSION;
}
void
RTMP_TLS_Init()
{
#ifdef CRYPTO
#ifdef USE_POLARSSL
/* Do this regardless of NO_SSL, we use havege for rtmpe too */
RTMP_TLS_ctx = calloc(1,sizeof(struct tls_ctx));
havege_init(&RTMP_TLS_ctx->hs);
#elif defined(USE_GNUTLS) && !defined(NO_SSL)
/* Technically we need to initialize libgcrypt ourselves if
* we're not going to call gnutls_global_init(). Ignoring this
* for now.
*/
gnutls_global_init();
RTMP_TLS_ctx = malloc(sizeof(struct tls_ctx));
gnutls_certificate_allocate_credentials(&RTMP_TLS_ctx->cred);
gnutls_priority_init(&RTMP_TLS_ctx->prios, "NORMAL", NULL);
gnutls_certificate_set_x509_trust_file(RTMP_TLS_ctx->cred,
"ca.pem", GNUTLS_X509_FMT_PEM);
#elif !defined(NO_SSL) /* USE_OPENSSL */
/* libcrypto doesn't need anything special */
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_digests();
RTMP_TLS_ctx = SSL_CTX_new(SSLv23_method());
SSL_CTX_set_options(RTMP_TLS_ctx, SSL_OP_ALL);
SSL_CTX_set_default_verify_paths(RTMP_TLS_ctx);
#endif
#endif
}
RTMP *
RTMP_Alloc()
{
return calloc(1, sizeof(RTMP));
}
void
RTMP_Free(RTMP *r)
{
free(r);
}
void
RTMP_Init(RTMP *r)
{
#ifdef CRYPTO
if (!RTMP_TLS_ctx)
RTMP_TLS_Init();
#endif
memset(r, 0, sizeof(RTMP));
r->m_sb.sb_socket = -1;
r->m_inChunkSize = RTMP_DEFAULT_CHUNKSIZE;
r->m_outChunkSize = RTMP_DEFAULT_CHUNKSIZE;
r->m_nBufferMS = 30000;
r->m_nClientBW = 2500000;
r->m_nClientBW2 = 2;
r->m_nServerBW = 2500000;
r->m_fAudioCodecs = 3191.0;
r->m_fVideoCodecs = 252.0;
r->Link.timeout = 30;
r->Link.swfAge = 30;
}
void
RTMP_EnableWrite(RTMP *r)
{
r->Link.protocol |= RTMP_FEATURE_WRITE;
}
double
RTMP_GetDuration(RTMP *r)
{
return r->m_fDuration;
}
int
RTMP_IsConnected(RTMP *r)
{
return r->m_sb.sb_socket != -1;
}
int
RTMP_Socket(RTMP *r)
{
return r->m_sb.sb_socket;
}
int
RTMP_IsTimedout(RTMP *r)
{
return r->m_sb.sb_timedout;
}
void
RTMP_SetBufferMS(RTMP *r, int size)
{
r->m_nBufferMS = size;
}
void
RTMP_UpdateBufferMS(RTMP *r)
{
RTMP_SendCtrl(r, 3, r->m_stream_id, r->m_nBufferMS);
}
#undef OSS
#ifdef _WIN32
#define OSS "WIN"
#elif defined(__sun__)
#define OSS "SOL"
#elif defined(__APPLE__)
#define OSS "MAC"
#elif defined(__linux__)
#define OSS "LNX"
#else
#define OSS "GNU"
#endif
#define DEF_VERSTR OSS " 10,0,32,18"
static const char DEFAULT_FLASH_VER[] = DEF_VERSTR;
const AVal RTMP_DefaultFlashVer =
{ (char *)DEFAULT_FLASH_VER, sizeof(DEFAULT_FLASH_VER) - 1 };
void
RTMP_SetupStream(RTMP *r,
int protocol,
AVal *host,
unsigned int port,
AVal *sockshost,
AVal *playpath,
AVal *tcUrl,
AVal *swfUrl,
AVal *pageUrl,
AVal *app,
AVal *auth,
AVal *swfSHA256Hash,
uint32_t swfSize,
AVal *flashVer,
AVal *subscribepath,
int dStart,
int dStop, int bLiveStream, long int timeout)
{
RTMP_Log(RTMP_LOGDEBUG, "Protocol : %s", RTMPProtocolStrings[protocol&7]);
RTMP_Log(RTMP_LOGDEBUG, "Hostname : %.*s", host->av_len, host->av_val);
RTMP_Log(RTMP_LOGDEBUG, "Port : %d", port);
RTMP_Log(RTMP_LOGDEBUG, "Playpath : %s", playpath->av_val);
if (tcUrl && tcUrl->av_val)
RTMP_Log(RTMP_LOGDEBUG, "tcUrl : %s", tcUrl->av_val);
if (swfUrl && swfUrl->av_val)
RTMP_Log(RTMP_LOGDEBUG, "swfUrl : %s", swfUrl->av_val);
if (pageUrl && pageUrl->av_val)
RTMP_Log(RTMP_LOGDEBUG, "pageUrl : %s", pageUrl->av_val);
if (app && app->av_val)
RTMP_Log(RTMP_LOGDEBUG, "app : %.*s", app->av_len,
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
将RTMPdump的服务器端程序与flex客户端连接成功,实现了rtmpsrv与flex之间的通讯。 运行步骤详见: http://blog.csdn.net/yangzhaohui168/archive/2010/07/23/5756734.aspx 这是服务器和客户端的源程序。
资源推荐
资源详情
资源评论
收起资源包目录
rtmpdump.rar (60个子文件)
rtmpdump
rtmpdump.vcxproj.user 143B
getopt
getopt.h 2KB
getopt.c 6KB
thread.h 1KB
include
zlib.h 66KB
zconf.h 10KB
polarssl
des.h 5KB
certs.h 1KB
rsa.h 11KB
base64.h 3KB
md5.h 4KB
net.h 5KB
bignum.h 15KB
camellia.h 4KB
config.h 6KB
padlock.h 3KB
dhm.h 4KB
timing.h 2KB
havege.h 1KB
sha2.h 4KB
md4.h 4KB
md2.h 4KB
sha4.h 5KB
sha1.h 4KB
aes.h 4KB
ssl.h 18KB
xtea.h 2KB
openssl.h 5KB
x509.h 12KB
debug.h 3KB
bn_mul.h 28KB
arc4.h 2KB
rtmpsrv.c 27KB
rtmpdump.vcxproj.filters 3KB
librtmp
COPYING 26KB
log.h 2KB
librtmp.pc.in 262B
amf.c 24KB
rtmp.h 9KB
http.h 2KB
dhgroups.h 9KB
parseurl.c 6KB
log.c 4KB
rtmp.c 109KB
librtmp.3.html 8KB
dh.h 8KB
rtmp_sys.h 4KB
hashswf.c 15KB
librtmp.3 7KB
handshake.h 31KB
bytes.h 2KB
Makefile 2KB
amf.h 5KB
rtmpdump.vcxproj 5KB
lib
zdll.lib 10KB
zlib1.dll 59KB
polarssl.lib 736KB
thread.c 2KB
rtmpdump.sln 891B
rtmpdump.mxml 2KB
共 60 条
- 1
Andy_Yang
- 粉丝: 43
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页