1 
2 /*
3  * Copyright (C) Roman Arutyunyan
4  */
5 
6 
7 #ifndef _NGX_RTMP_AMF_H_INCLUDED_
8 #define _NGX_RTMP_AMF_H_INCLUDED_
9 
10 
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13 
14 
15 /* basic types */
16 #define NGX_RTMP_AMF_NUMBER             0x00
17 #define NGX_RTMP_AMF_BOOLEAN            0x01
18 #define NGX_RTMP_AMF_STRING             0x02
19 #define NGX_RTMP_AMF_OBJECT             0x03
20 #define NGX_RTMP_AMF_NULL               0x05
21 #define NGX_RTMP_AMF_ARRAY_NULL         0x06
22 #define NGX_RTMP_AMF_MIXED_ARRAY        0x08
23 #define NGX_RTMP_AMF_END                0x09
24 #define NGX_RTMP_AMF_ARRAY              0x0a
25 
26 /* extended types */
27 #define NGX_RTMP_AMF_INT8               0x0100
28 #define NGX_RTMP_AMF_INT16              0x0101
29 #define NGX_RTMP_AMF_INT32              0x0102
30 #define NGX_RTMP_AMF_VARIANT_           0x0103
31 
32 /* r/w flags */
33 #define NGX_RTMP_AMF_OPTIONAL           0x1000
34 #define NGX_RTMP_AMF_TYPELESS           0x2000
35 #define NGX_RTMP_AMF_CONTEXT            0x4000
36 
37 #define NGX_RTMP_AMF_VARIANT            (NGX_RTMP_AMF_VARIANT_\
38                                         |NGX_RTMP_AMF_TYPELESS)
39 
40 
41 typedef struct {
42     ngx_int_t                           type;
43     ngx_str_t                           name;
44     void                               *data;
45     size_t                              len;
46 } ngx_rtmp_amf_elt_t;
47 
48 
49 typedef ngx_chain_t * (*ngx_rtmp_amf_alloc_pt)(void *arg);
50 
51 
52 typedef struct {
53     ngx_chain_t                        *link, *first;
54     size_t                              offset;
55     ngx_rtmp_amf_alloc_pt               alloc;
56     void                               *arg;
57     ngx_log_t                          *log;
58 } ngx_rtmp_amf_ctx_t;
59 
60 
61 /* reading AMF */
62 ngx_int_t ngx_rtmp_amf_read(ngx_rtmp_amf_ctx_t *ctx,
63         ngx_rtmp_amf_elt_t *elts, size_t nelts);
64 
65 /* writing AMF */
66 ngx_int_t ngx_rtmp_amf_write(ngx_rtmp_amf_ctx_t *ctx,
67         ngx_rtmp_amf_elt_t *elts, size_t nelts);
68 
69 
70 #endif /* _NGX_RTMP_AMF_H_INCLUDED_ */
71 
72