fixed bugs in packet input

This commit is contained in:
Roman Arutyunyan 2012-03-15 15:49:05 +04:00
parent 78ea1b1266
commit 17a3d368d8
4 changed files with 20 additions and 5 deletions

View file

@ -66,6 +66,7 @@ ngx_rtmp_amf0_get(ngx_rtmp_amf0_ctx_t *ctx, void *p, size_t n)
ngx_chain_t *l; ngx_chain_t *l;
#ifdef NGX_DEBUG #ifdef NGX_DEBUG
void *op = p; void *op = p;
size_t on = n;
#endif #endif
if (!n) if (!n)
@ -80,9 +81,11 @@ ngx_rtmp_amf0_get(ngx_rtmp_amf0_ctx_t *ctx, void *p, size_t n)
p = ngx_cpymem(p, b->pos, n); p = ngx_cpymem(p, b->pos, n);
} }
b->pos += n; b->pos += n;
ctx->link = l;
#ifdef NGX_DEBUG #ifdef NGX_DEBUG
ngx_rtmp_amf0_debug("read", ctx->log, (u_char*)op, n); ngx_rtmp_amf0_debug("read", ctx->log, (u_char*)op, on);
#endif #endif
return NGX_OK; return NGX_OK;
@ -90,8 +93,9 @@ ngx_rtmp_amf0_get(ngx_rtmp_amf0_ctx_t *ctx, void *p, size_t n)
size = b->last - b->pos; size = b->last - b->pos;
if (p) if (p) {
p = ngx_cpymem(p, b->pos, size); p = ngx_cpymem(p, b->pos, size);
}
n -= size; n -= size;
} }

View file

@ -237,6 +237,9 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module); ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
h->timestamp -= s->peer_epoch;
h->timestamp += s->epoch;
if (ctx == NULL if (ctx == NULL
|| !(ctx->flags & NGX_RTMP_BROADCAST_PUBLISHER)) || !(ctx->flags & NGX_RTMP_BROADCAST_PUBLISHER))
{ {
@ -319,11 +322,13 @@ ngx_rtmp_broadcast_connect(ngx_rtmp_session_t *s, double in_trans,
static double trans; static double trans;
static u_char app[1024]; static u_char app[1024];
static u_char url[1024]; static u_char url[1024];
static u_char acodecs[1024];
static ngx_str_t app_str; static ngx_str_t app_str;
static ngx_rtmp_amf0_elt_t in_cmd[] = { static ngx_rtmp_amf0_elt_t in_cmd[] = {
{ NGX_RTMP_AMF0_STRING, "app", app, sizeof(app) }, { NGX_RTMP_AMF0_STRING, "app", app, sizeof(app) },
{ NGX_RTMP_AMF0_STRING, "tcUrl" , url, sizeof(url) }, { NGX_RTMP_AMF0_STRING, "tcUrl" , url, sizeof(url) },
{ NGX_RTMP_AMF0_STRING, "audiocodecs" , acodecs, sizeof(acodecs) },
}; };
static ngx_rtmp_amf0_elt_t out_inf[] = { static ngx_rtmp_amf0_elt_t out_inf[] = {

View file

@ -360,6 +360,7 @@ ngx_rtmp_handshake_send(ngx_event_t *wev)
ngx_rtmp_core_srv_conf_t *cscf; ngx_rtmp_core_srv_conf_t *cscf;
ngx_buf_t *b; ngx_buf_t *b;
size_t offs; size_t offs;
static u_char zeroes[4];
c = wev->data; c = wev->data;
s = c->data; s = c->data;
@ -394,6 +395,9 @@ restart:
/* use the timestamp from echo packet */ /* use the timestamp from echo packet */
n = c->send(c, b->pos + 4, 4 - (b->pos - b->start)); n = c->send(c, b->pos + 4, 4 - (b->pos - b->start));
} else if (b->pos - b->start < 8) {
n = c->send(c, zeroes, 8 - (b->pos - b->start));
} else { } else {
offs = (b->pos - b->start - 4) % sizeof(handshake_text); offs = (b->pos - b->start - 4) % sizeof(handshake_text);
n = c->send(c, (u_char*)handshake_text + offs, n = c->send(c, (u_char*)handshake_text + offs,
@ -659,8 +663,8 @@ ngx_rtmp_recv(ngx_event_t *rev)
if (fsize > s->in_chunk_size) { if (fsize > s->in_chunk_size) {
/* collect fragmented chunks */ /* collect fragmented chunks */
st->len += s->in_chunk_size; st->len += s->in_chunk_size;
b->last = b->pos + s->in_chunk_size;
old_pos = b->pos + s->in_chunk_size; old_pos = b->last;
old_size = size - s->in_chunk_size; old_size = size - s->in_chunk_size;
} else { } else {
@ -747,6 +751,7 @@ ngx_rtmp_send(ngx_event_t *wev)
l = s->out; l = s->out;
if (l->buf->pos < l->buf->last) { if (l->buf->pos < l->buf->last) {
l->buf->pos = l->buf->last;
break; break;
} }

View file

@ -1 +1,2 @@
ffmpeg -loglevel verbose -re -i /mnt/home/rarutyunyan/Videos/the_changeup-solaris.giga.su.avi -an -f flv rtmp://localhost/helo ffmpeg -loglevel verbose -re -i /mnt/home/rarutyunyan/Videos/anything_else-solaris.giga.su.avi -f flv rtmp://localhost/helo
#ffmpeg -loglevel verbose -re -i /mnt/home/rarutyunyan/Videos/the_changeup-solaris.giga.su.avi -an -f flv rtmp://localhost/helo