The context pointed by rtmp_hd/rtmp_hd_out is used for reading/writing
requests. These two streams will be used by RTMPT for HTTP tunneling.
---
libavformat/rtmpproto.c | 55 ++++++++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index e049c8a..02ff81a 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -63,7 +63,8 @@ typedef enum {
/** protocol handler context */
typedef struct RTMPContext {
const AVClass *class;
- URLContext* stream; ///< TCP stream used in
interactions with RTMP server
+ URLContext* rtmp_hd; ///< RTMP TCP connection handle
+ URLContext* rtmp_hd_out; ///< additional output handle
for HTTP tunneling
RTMPPacket prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when
reading and sending packets
int chunk_size; ///< size of the chunks RTMP
packets are divided into
int is_input; ///< input/output flag
@@ -165,7 +166,7 @@ static void gen_connect(URLContext *s, RTMPContext *rt)
pkt.data_size = p - pkt.data;
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -188,7 +189,7 @@ static void gen_release_stream(URLContext *s, RTMPContext
*rt)
ff_amf_write_null(&p);
ff_amf_write_string(&p, rt->playpath);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -211,7 +212,7 @@ static void gen_fcpublish_stream(URLContext *s, RTMPContext
*rt)
ff_amf_write_null(&p);
ff_amf_write_string(&p, rt->playpath);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -234,7 +235,7 @@ static void gen_fcunpublish_stream(URLContext *s,
RTMPContext *rt)
ff_amf_write_null(&p);
ff_amf_write_string(&p, rt->playpath);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -256,7 +257,7 @@ static void gen_create_stream(URLContext *s, RTMPContext
*rt)
ff_amf_write_null(&p);
rt->create_stream_invoke = rt->nb_invokes;
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -279,7 +280,7 @@ static void gen_delete_stream(URLContext *s, RTMPContext
*rt)
ff_amf_write_null(&p);
ff_amf_write_number(&p, rt->main_channel_id);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -304,7 +305,7 @@ static void gen_play(URLContext *s, RTMPContext *rt)
ff_amf_write_string(&p, rt->playpath);
ff_amf_write_number(&p, rt->live);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
// set client buffer time disguised in ping packet
@@ -315,7 +316,7 @@ static void gen_play(URLContext *s, RTMPContext *rt)
bytestream_put_be32(&p, 1);
bytestream_put_be32(&p, 256); //TODO: what is a good value here?
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -339,7 +340,7 @@ static void gen_publish(URLContext *s, RTMPContext *rt)
ff_amf_write_string(&p, rt->playpath);
ff_amf_write_string(&p, "live");
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -355,7 +356,7 @@ static void gen_pong(URLContext *s, RTMPContext *rt,
RTMPPacket *ppkt)
p = pkt.data;
bytestream_put_be16(&p, 7);
bytestream_put_be32(&p, AV_RB32(ppkt->data+2));
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -370,7 +371,7 @@ static void gen_server_bw(URLContext *s, RTMPContext *rt)
ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_SERVER_BW, 0, 4);
p = pkt.data;
bytestream_put_be32(&p, 2500000);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -389,7 +390,7 @@ static void gen_check_bw(URLContext *s, RTMPContext *rt)
ff_amf_write_number(&p, ++rt->nb_invokes);
ff_amf_write_null(&p);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -404,7 +405,7 @@ static void gen_bytes_read(URLContext *s, RTMPContext *rt,
uint32_t ts)
ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_BYTES_READ, ts,
4);
p = pkt.data;
bytestream_put_be32(&p, rt->bytes_read);
- ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &pkt, rt->chunk_size,
rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&pkt);
}
@@ -537,13 +538,13 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
tosend[i] = av_lfg_get(&rnd) >> 24;
client_pos = rtmp_handshake_imprint_with_digest(tosend + 1);
- ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
- i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE
+ 1);
+ ffurl_write(rt->rtmp_hd_out, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
+ i = ffurl_read_complete(rt->rtmp_hd, serverdata,
RTMP_HANDSHAKE_PACKET_SIZE + 1);
if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
return -1;
}
- i = ffurl_read_complete(rt->stream, clientdata,
RTMP_HANDSHAKE_PACKET_SIZE);
+ i = ffurl_read_complete(rt->rtmp_hd, clientdata,
RTMP_HANDSHAKE_PACKET_SIZE);
if (i != RTMP_HANDSHAKE_PACKET_SIZE) {
av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
return -1;
@@ -583,9 +584,9 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32);
// write reply back to the server
- ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE);
+ ffurl_write(rt->rtmp_hd_out, tosend, RTMP_HANDSHAKE_PACKET_SIZE);
} else {
- ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE);
+ ffurl_write(rt->rtmp_hd_out, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE);
}
return 0;
@@ -614,7 +615,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext
*rt, RTMPPacket *pkt)
return -1;
}
if (!rt->is_input)
- ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size,
rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, pkt, rt->chunk_size,
rt->prev_pkt[1]);
rt->chunk_size = AV_RB32(pkt->data);
if (rt->chunk_size <= 0) {
av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n",
rt->chunk_size);
@@ -745,7 +746,7 @@ static int get_packet(URLContext *s, int for_header)
for (;;) {
RTMPPacket rpkt = { 0 };
- if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,
+ if ((ret = ff_rtmp_packet_read(rt->rtmp_hd, &rpkt,
rt->chunk_size, rt->prev_pkt[0])) <= 0)
{
if (ret == 0) {
return AVERROR(EAGAIN);
@@ -839,7 +840,10 @@ static int rtmp_close(URLContext *h)
gen_delete_stream(h, rt);
av_freep(&rt->flv_data);
- ffurl_close(rt->stream);
+
+ if (rt->rtmp_hd_out != rt->rtmp_hd)
+ ffurl_close(rt->rtmp_hd_out);
+ ffurl_close(rt->rtmp_hd);
return 0;
}
@@ -869,11 +873,12 @@ static int rtmp_open(URLContext *s, const char *uri, int
flags)
rt->port = RTMP_DEFAULT_PORT;
ff_url_join(buf, sizeof(buf), "tcp", NULL, rt->host, rt->port, NULL);
- if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
+ if (ffurl_open(&rt->rtmp_hd, buf, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL) < 0) {
av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail;
}
+ rt->rtmp_hd_out = rt->rtmp_hd;
rt->state = STATE_START;
if (rtmp_handshake(s, rt))
@@ -981,7 +986,7 @@ static int rtmp_open(URLContext *s, const char *uri, int
flags)
rt->skip_bytes = 13;
}
- s->max_packet_size = rt->stream->max_packet_size;
+ s->max_packet_size = rt->rtmp_hd->max_packet_size;
s->is_streamed = 1;
return 0;
@@ -1080,7 +1085,7 @@ static int rtmp_write(URLContext *s, const uint8_t *buf,
int size)
if (rt->flv_off == rt->flv_size) {
rt->skip_bytes = 4;
- ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size,
rt->prev_pkt[1]);
+ ff_rtmp_packet_write(rt->rtmp_hd_out, &rt->out_pkt,
rt->chunk_size, rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&rt->out_pkt);
rt->flv_size = 0;
rt->flv_off = 0;
--
1.7.10.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel