mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-16 00:31:09 +02:00
improved amf writing
This commit is contained in:
parent
fd54d6cc0f
commit
dbbd320864
|
@ -414,9 +414,9 @@ ngx_int_t ngx_rtmp_send_user_unknown(ngx_rtmp_session_t *s,
|
|||
uint32_t timestamp);
|
||||
|
||||
/* AMF sender/receiver */
|
||||
ngx_chain_t * ngx_rtmp_create_amf_message(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_header_t *h, ngx_chain_t **last, ngx_rtmp_amf_elt_t *elts,
|
||||
size_t nelts);
|
||||
ngx_int_t ngx_rtmp_append_amf(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t **first, ngx_chain_t **last,
|
||||
ngx_rtmp_amf_elt_t *elts, size_t nelts);
|
||||
ngx_int_t ngx_rtmp_send_amf(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_rtmp_amf_elt_t *elts, size_t nelts);
|
||||
ngx_int_t ngx_rtmp_receive_amf(ngx_rtmp_session_t *s, ngx_chain_t *in,
|
||||
|
|
|
@ -207,59 +207,66 @@ ngx_rtmp_alloc_amf_buf(void *arg)
|
|||
|
||||
|
||||
/* AMF sender */
|
||||
ngx_chain_t *
|
||||
ngx_rtmp_create_amf_message(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t **last, ngx_rtmp_amf_elt_t *elts, size_t nelts)
|
||||
|
||||
/* NOTE: this function does not free shared bufs on error */
|
||||
ngx_int_t
|
||||
ngx_rtmp_append_amf(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t **first, ngx_chain_t **last,
|
||||
ngx_rtmp_amf_elt_t *elts, size_t nelts)
|
||||
{
|
||||
ngx_rtmp_amf_ctx_t act;
|
||||
ngx_rtmp_core_srv_conf_t *cscf;
|
||||
ngx_int_t rc;
|
||||
|
||||
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.arg = cscf;
|
||||
if (last) {
|
||||
act.link = *last;
|
||||
}
|
||||
act.alloc = ngx_rtmp_alloc_amf_buf;
|
||||
act.log = s->connection->log;
|
||||
|
||||
if (ngx_rtmp_amf_write(&act, elts, nelts) != NGX_OK) {
|
||||
if (act.first) {
|
||||
ngx_rtmp_free_shared_bufs(cscf, act.first);
|
||||
}
|
||||
return NULL;
|
||||
if (first) {
|
||||
act.first = *first;
|
||||
}
|
||||
|
||||
if (act.first) {
|
||||
ngx_rtmp_prepare_message(s, h, NULL, act.first);
|
||||
if (last) {
|
||||
act.link = *last;
|
||||
}
|
||||
|
||||
rc = ngx_rtmp_amf_write(&act, elts, nelts);
|
||||
|
||||
if (first) {
|
||||
*first = act.first;
|
||||
}
|
||||
|
||||
if (last) {
|
||||
*last = act.link;
|
||||
}
|
||||
|
||||
return act.first;
|
||||
return rc;
|
||||
}
|
||||
|
||||
ngx_int_t ngx_rtmp_send_amf(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_rtmp_amf_elt_t *elts, size_t nelts)
|
||||
{
|
||||
ngx_chain_t *cl;
|
||||
ngx_chain_t *first;
|
||||
ngx_int_t rc;
|
||||
ngx_rtmp_core_srv_conf_t *cscf;
|
||||
|
||||
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
|
||||
|
||||
cl = ngx_rtmp_create_amf_message(s, h, NULL, elts, nelts);
|
||||
|
||||
if (cl == NULL) {
|
||||
return NGX_ERROR;
|
||||
first = NULL;
|
||||
rc = ngx_rtmp_append_amf(s, h, &first, NULL, elts, nelts);
|
||||
if (rc != NGX_OK || first == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = ngx_rtmp_send_message(s, cl, 0);
|
||||
ngx_rtmp_prepare_message(s, h, NULL, first);
|
||||
|
||||
ngx_rtmp_free_shared_bufs(cscf, cl);
|
||||
rc = ngx_rtmp_send_message(s, first, 0);
|
||||
|
||||
done:
|
||||
ngx_rtmp_free_shared_bufs(cscf, first);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue