rtmp_amf_flv.h 4.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*****************************************************************************
 * rtmp_amf_flv.h: RTMP, AMF and FLV over RTMP implementation.
 *****************************************************************************
 * Copyright (C) URJC - LADyR - Luis Lopez Fernandez
 *
 * Author: Miguel Angel Cabrera Moya
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Local prototypes (continued from access.c)
 *****************************************************************************/
typedef struct rtmp_packet_t rtmp_packet_t;
typedef struct rtmp_body_t rtmp_body_t;
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

struct rtmp_packet_t
{
    int length_header;
    int stream_index;
    uint32_t timestamp;
    uint32_t timestamp_relative;
    int32_t length_encoded;
    int32_t length_body;
    uint8_t content_type;
    uint32_t src_dst;
    rtmp_body_t *body;
};

struct rtmp_body_t
{
    int32_t length_body; /* without interchunk headers */
    int32_t length_buffer;
    uint8_t *body;
};

struct rtmp_control_thread_t
{
    VLC_COMMON_MEMBERS

    int fd;
56
    bool b_error;
57

58 59 60 61
    vlc_url_t url;
    char *psz_application;
    char *psz_media;

62 63 64
    char *psz_swf_url;
    char *psz_page_url;

65
    block_fifo_t *p_fifo_input;
66 67 68 69
    block_fifo_t *p_empty_blocks;

    vlc_mutex_t lock;
    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 78
    double stream_client_id;
    double stream_server_id;
79 80 81

    char *psz_publish;

82
    /* Rebuild FLV variables (access) */
83 84 85 86 87
    int has_audio;
    int has_video;
    int metadata_received;
    uint8_t metadata_stereo;
    uint8_t metadata_samplesize;
88
    uint32_t metadata_samplerate;
89 90 91 92 93 94
    uint8_t metadata_audiocodecid;
    uint8_t metadata_videocodecid;
    uint8_t metadata_frametype;
    int first_media_packet;
    uint32_t flv_tag_previous_tag_size;

95 96 97 98 99 100
    /* Vars for rebuilding FLV (access_output) */
    rtmp_body_t *flv_body;
    uint8_t flv_content_type;
    uint32_t flv_length_body;
    uint32_t flv_timestamp;

101
    /* vars for channel state */
102 103
    uint32_t chunk_size_recv;
    uint32_t chunk_size_send;
104 105 106 107
    rtmp_packet_t rtmp_headers_recv[64]; /* RTMP_HEADER_STREAM_MAX */
    rtmp_packet_t rtmp_headers_send[64];

    rtmp_handler_t rtmp_handler[21]; /* index by RTMP_CONTENT_TYPE */
108 109 110

    /* Pointer to base module object (later needs to casted) */
    void *p_base_object;
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
};

struct access_sys_t
{
    int active;

    /* vars for reading from fifo */
    block_t *flv_packet;
    int read_packet;

    /* thread for filtering and handling control messages */
    rtmp_control_thread_t *p_thread;
};

/*****************************************************************************
 * RTMP header:
 ******************************************************************************/
128 129 130 131
int rtmp_handshake_active( vlc_object_t *p_this, int fd );
int rtmp_handshake_passive( vlc_object_t *p_this, int fd );
int rtmp_connect_active( rtmp_control_thread_t *p_thread );
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 135 136
//
rtmp_packet_t *rtmp_build_bytes_read( rtmp_control_thread_t *p_thread, uint32_t reply );
rtmp_packet_t *rtmp_build_publish_start( rtmp_control_thread_t *p_thread );
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 141 142 143 144 145
void rtmp_init_handler( rtmp_handler_t *rtmp_handler );
/*****************************************************************************
 * FLV header:
 ******************************************************************************/
block_t *flv_get_metadata( access_t *p_access );
block_t *flv_insert_header( access_t *p_access, block_t *first_packet );
146 147 148 149 150 151

/*****************************************************************************
 * RTMP body header:
 ******************************************************************************/
rtmp_body_t *rtmp_body_new( int length_buffer );
void rtmp_body_reset( rtmp_body_t * );