diff options
author | Samuel Pitoiset <samuel.pitoiset@gmail.com> | 2012-06-14 15:28:40 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-06-14 22:22:58 +0300 |
commit | 7dc747f50b0adeaf2bcf6413e291dc4bffa54f9a (patch) | |
tree | ccdcab4a4c61542a0f84e7a504ee42435a60d375 /libavformat/rtmpproto.c | |
parent | d2d193c9b6963f3041ee0037c791c44453b845a0 (diff) | |
download | ffmpeg-7dc747f50b0adeaf2bcf6413e291dc4bffa54f9a.tar.gz |
rtmp: Read and handle incoming packets while writing data
This makes sure all incoming packets are read and handled (and reacted
to) while sending an FLV stream over RTMP to a server. If there were
enough incoming data to fill the TCP buffers, this could potentially
make things block at unexpected places. For the upcoming RTMPT support,
we need to consume all incoming data before we can send the next
request.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r-- | libavformat/rtmpproto.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index e64e2a322b..b3ae5a21e6 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1287,6 +1287,7 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) int pktsize, pkttype; uint32_t ts; const uint8_t *buf_temp = buf; + uint8_t c; int ret; do { @@ -1356,6 +1357,35 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) rt->flv_header_bytes = 0; } } while (buf_temp - buf < size); + + /* set stream into nonblocking mode */ + rt->stream->flags |= AVIO_FLAG_NONBLOCK; + + /* try to read one byte from the stream */ + ret = ffurl_read(rt->stream, &c, 1); + + /* switch the stream back into blocking mode */ + rt->stream->flags &= ~AVIO_FLAG_NONBLOCK; + + if (ret == AVERROR(EAGAIN)) { + /* no incoming data to handle */ + return size; + } else if (ret < 0) { + return ret; + } else if (ret == 1) { + RTMPPacket rpkt = { 0 }; + + if ((ret = ff_rtmp_packet_read_internal(rt->stream, &rpkt, + rt->chunk_size, + rt->prev_pkt[0], c)) <= 0) + return ret; + + if ((ret = rtmp_parse_result(s, rt, &rpkt)) < 0) + return ret; + + ff_rtmp_packet_destroy(&rpkt); + } + return size; } |