diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-05-25 20:48:50 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-05-25 21:06:14 +0200 |
commit | c0b47d1914a19abacdf1edf081cbf07485952920 (patch) | |
tree | 94b26fadd3ecf4352ff87bd807ea6124bc2f4c02 /libavformat/rtmpproto.c | |
parent | e02e58fb1c108dd96ef5b61454a2ba8d2af895ea (diff) | |
parent | ed7bdd8647a3d0f534c2af0d244fc8744ff262a0 (diff) | |
download | ffmpeg-c0b47d1914a19abacdf1edf081cbf07485952920.tar.gz |
Merge remote-tracking branch 'qatar/master'n0.12-dev
* qatar/master:
movenc: Don't write the 'wave' atom or its child 'enda' for lpcm audio.
imc: some cosmetics
rtmp: Pass the proper return code in rtmp_handshake
rtmp: Check return codes of net IO operations
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r-- | libavformat/rtmpproto.c | 98 |
1 files changed, 64 insertions, 34 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index fdba429ab2..0f643e6c8a 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -167,10 +167,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -194,10 +195,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -221,10 +223,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -248,10 +251,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -276,10 +280,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } @@ -305,10 +310,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -336,9 +342,13 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); + if (ret < 0) + return ret; + // set client buffer time disguised in ping packet if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, 1, 10)) < 0) @@ -349,10 +359,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -379,7 +390,8 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); return ret; @@ -401,10 +413,11 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -422,10 +435,11 @@ static int gen_server_bw(URLContext *s, RTMPContext *rt) p = pkt.data; bytestream_put_be32(&p, 2500000); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -446,7 +460,8 @@ static int 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]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); return ret; @@ -467,10 +482,11 @@ static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts) p = pkt.data; bytestream_put_be32(&p, rt->bytes_read); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } //TODO: Move HMAC code somewhere. Eventually. @@ -617,16 +633,22 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) if (client_pos < 0) return client_pos; - ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); - i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); - if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { + if ((ret = ffurl_write(rt->stream, tosend, + RTMP_HANDSHAKE_PACKET_SIZE + 1)) < 0) { + av_log(s, AV_LOG_ERROR, "Cannot write RTMP handshake request\n"); + return ret; + } + + if ((ret = ffurl_read_complete(rt->stream, serverdata, + RTMP_HANDSHAKE_PACKET_SIZE + 1)) < 0) { av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); - return AVERROR(EIO); + return ret; } - i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); - if (i != RTMP_HANDSHAKE_PACKET_SIZE) { + + if ((ret = ffurl_read_complete(rt->stream, clientdata, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) { av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); - return AVERROR(EIO); + return ret; } av_log(s, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", @@ -678,9 +700,13 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) return ret; // write reply back to the server - ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); + if ((ret = ffurl_write(rt->stream, tosend, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) + return ret; } else { - ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); + if ((ret = ffurl_write(rt->stream, serverdata + 1, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) + return ret; } return 0; @@ -710,7 +736,9 @@ 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]); + if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, + rt->prev_pkt[1])) < 0) + return ret; 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); @@ -1201,7 +1229,9 @@ 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]); + if ((ret = ff_rtmp_packet_write(rt->stream, &rt->out_pkt, + rt->chunk_size, rt->prev_pkt[1])) < 0) + return ret; ff_rtmp_packet_destroy(&rt->out_pkt); rt->flv_size = 0; rt->flv_off = 0; |