/*
* 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 librtmp 库和编译环境
共131个文件
h:107个
c:5个
lib:4个
5星 · 超过95%的资源 需积分: 50 118 下载量 198 浏览量
2014-10-19
23:35:29
上传
评论 1
收藏 2.13MB RAR 举报
温馨提示
RTMPDump librtmp 库及编译环境 支持VC6.0、VS2005、VS2010 已包含所有需要的第3方库
资源推荐
资源详情
资源评论
收起资源包目录
rtmpdump librtmp 库和编译环境 (131个子文件)
librtmp.3 7KB
rtmp.c 109KB
amf.c 24KB
hashswf.c 15KB
parseurl.c 6KB
log.c 4KB
COPYING 26KB
libeay32.dll 1.12MB
libssl32.dll 228KB
zlib1.dll 59KB
librtmp.dsp 4KB
librtmp.dsw 539B
librtmp.vcxproj.filters 2KB
safestack.h 134KB
obj_mac.h 113KB
ssl.h 82KB
zlib.h 78KB
asn1.h 47KB
x509.h 47KB
engine.h 37KB
evp.h 35KB
objects.h 33KB
bn.h 32KB
handshake.h 31KB
bio.h 30KB
x509v3.h 29KB
bn_mul.h 28KB
asn1t.h 27KB
pem.h 27KB
store.h 26KB
ocsp.h 24KB
ssl3.h 22KB
crypto.h 22KB
ec.h 21KB
x509_vfy.h 20KB
symhacks.h 20KB
tls1.h 19KB
asn1_mac.h 19KB
ssl.h 18KB
des_old.h 18KB
rsa.h 18KB
ui.h 16KB
pkcs7.h 16KB
dso.h 16KB
bignum.h 15KB
zconf.h 13KB
pkcs12.h 12KB
x509.h 12KB
err.h 12KB
rsa.h 11KB
des.h 10KB
ssl2.h 10KB
ecdsa.h 10KB
dsa.h 10KB
e_os2.h 9KB
dhgroups.h 9KB
rtmp.h 9KB
conf.h 9KB
dh.h 8KB
dh.h 8KB
krb5_asn.h 7KB
stdint.h 7KB
lhash.h 7KB
sha.h 7KB
opensslconf.h 6KB
ossl_typ.h 6KB
config.h 6KB
pq_compat.h 6KB
dtls1.h 6KB
kssl.h 6KB
amf.h 6KB
aes.h 5KB
rand.h 5KB
blowfish.h 5KB
des.h 5KB
net.h 5KB
openssl.h 5KB
md4.h 5KB
md5.h 5KB
sha4.h 5KB
ecdh.h 5KB
buffer.h 4KB
camellia.h 4KB
sha2.h 4KB
stack.h 4KB
dhm.h 4KB
hmac.h 4KB
idea.h 4KB
cast.h 4KB
txt_db.h 4KB
rc2.h 4KB
ripemd.h 4KB
aes.h 4KB
tmdiff.h 4KB
conf_api.h 4KB
md2.h 4KB
sha1.h 4KB
md5.h 4KB
md4.h 4KB
md2.h 4KB
共 131 条
- 1
- 2
资源评论
- supaly2015-11-17不错,可以使用,对学习有帮助
- 胡峰HF2015-12-29学习,我直接使用nginx里面的rtmp的插件了
- moranhuishou1234562014-10-30不错,可以使用,对学习有帮助
- fuym20122015-07-19很不错,可以编译通过,要是能有第三方库代码就更好了
- 眯莎2015-10-19代码貌似不是最新的,但是资源还不错,我把代码合并了一下,使用这个项目编译成功了
flooodsky
- 粉丝: 11
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功