]> git.sesse.net Git - vlc/blob - modules/access/rtmp/rtmp_amf_flv.h
Annotation libvlc_media_get_user_data tracks parameter as an [OUT] parameter
[vlc] / modules / access / rtmp / rtmp_amf_flv.h
1 /*****************************************************************************
2  * rtmp_amf_flv.h: RTMP, AMF and FLV over RTMP implementation.
3  *****************************************************************************
4  * Copyright (C) URJC - LADyR - Luis Lopez Fernandez
5  *
6  * Author: Miguel Angel Cabrera Moya
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Local prototypes (continued from access.c)
25  *****************************************************************************/
26 typedef struct rtmp_packet_t rtmp_packet_t;
27 typedef struct rtmp_body_t rtmp_body_t;
28 typedef struct rtmp_control_thread_t rtmp_control_thread_t;
29 typedef void (*rtmp_handler_t)( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet );
30
31 struct rtmp_packet_t
32 {
33     int length_header;
34     int stream_index;
35     uint32_t timestamp;
36     uint32_t timestamp_relative;
37     int32_t length_encoded;
38     int32_t length_body;
39     uint8_t content_type;
40     uint32_t src_dst;
41     rtmp_body_t *body;
42 };
43
44 struct rtmp_body_t
45 {
46     int32_t length_body; /* without interchunk headers */
47     int32_t length_buffer;
48     uint8_t *body;
49 };
50
51 struct rtmp_control_thread_t
52 {
53     VLC_COMMON_MEMBERS
54
55     int fd;
56     bool b_error;
57
58     vlc_url_t url;
59     char *psz_application;
60     char *psz_media;
61
62     char *psz_swf_url;
63     char *psz_page_url;
64
65     block_fifo_t *p_fifo_input;
66     block_fifo_t *p_empty_blocks;
67
68     vlc_mutex_t lock;
69     vlc_cond_t  wait;
70     vlc_thread_t thread;
71
72     int result_connect;
73     int result_publish;
74     int result_play;
75     int result_stop;
76
77     double stream_client_id;
78     double stream_server_id;
79
80     char *psz_publish;
81
82     /* Rebuild FLV variables (access) */
83     int has_audio;
84     int has_video;
85     int metadata_received;
86     uint8_t metadata_stereo;
87     uint8_t metadata_samplesize;
88     uint32_t metadata_samplerate;
89     uint8_t metadata_audiocodecid;
90     uint8_t metadata_videocodecid;
91     uint8_t metadata_frametype;
92     int first_media_packet;
93     uint32_t flv_tag_previous_tag_size;
94
95     /* Vars for rebuilding FLV (access_output) */
96     rtmp_body_t *flv_body;
97     uint8_t flv_content_type;
98     uint32_t flv_length_body;
99     uint32_t flv_timestamp;
100
101     /* vars for channel state */
102     uint32_t chunk_size_recv;
103     uint32_t chunk_size_send;
104     rtmp_packet_t rtmp_headers_recv[64]; /* RTMP_HEADER_STREAM_MAX */
105     rtmp_packet_t rtmp_headers_send[64];
106
107     rtmp_handler_t rtmp_handler[21]; /* index by RTMP_CONTENT_TYPE */
108
109     /* Pointer to base module object (later needs to casted) */
110     void *p_base_object;
111 };
112
113 struct access_sys_t
114 {
115     int active;
116
117     /* vars for reading from fifo */
118     block_t *flv_packet;
119     int read_packet;
120
121     /* thread for filtering and handling control messages */
122     rtmp_control_thread_t *p_thread;
123 };
124
125 /*****************************************************************************
126  * RTMP header:
127  ******************************************************************************/
128 int rtmp_handshake_active( vlc_object_t *p_this, int fd );
129 int rtmp_handshake_passive( vlc_object_t *p_this, int fd );
130 int rtmp_connect_active( rtmp_control_thread_t *p_thread );
131 int rtmp_connect_passive( rtmp_control_thread_t *p_thread );
132 //int rtmp_seek( access_t *p_access, int64_t i_pos ); TODO
133 //
134 rtmp_packet_t *rtmp_build_bytes_read( rtmp_control_thread_t *p_thread, uint32_t reply );
135 rtmp_packet_t *rtmp_build_publish_start( rtmp_control_thread_t *p_thread );
136 rtmp_packet_t *rtmp_build_flv_over_rtmp( rtmp_control_thread_t *p_thread, block_t *p_buffer );
137
138 rtmp_packet_t *rtmp_read_net_packet( rtmp_control_thread_t *p_thread );
139 uint8_t *rtmp_encode_packet( rtmp_control_thread_t *p_thread, rtmp_packet_t *rtmp_packet );
140 void rtmp_init_handler( rtmp_handler_t *rtmp_handler );
141 /*****************************************************************************
142  * FLV header:
143  ******************************************************************************/
144 block_t *flv_get_metadata( access_t *p_access );
145 block_t *flv_insert_header( access_t *p_access, block_t *first_packet );
146
147 /*****************************************************************************
148  * RTMP body header:
149  ******************************************************************************/
150 rtmp_body_t *rtmp_body_new( int length_buffer );
151 void rtmp_body_reset( rtmp_body_t * );