diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-06-15 00:09:39 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-06-15 00:14:21 +0200 |
commit | 15f8941108c5372862035ce8e3cbfd2a6cefb241 (patch) | |
tree | 921dc52f4b22ae8f66f251000ecf495154f41e88 /libavformat | |
parent | 01a14ce0424a45caa24d4a9103afe26c39a6fd35 (diff) | |
parent | d246c18ea6dca4dbdc92aec6ae4e3e038999a709 (diff) |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
Avoid C99 variable declarations within for statements.
rtmp: Read and handle incoming packets while writing data
doc: document THREAD_TYPE fate variable
rtpdec: Don't require frames to start with a Mode A packet
avconv: don't try to free threads that were not initialized.
Conflicts:
doc/fate.texi
ffplay.c
libavdevice/dv1394.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/rtmppkt.c | 16 | ||||
-rw-r--r-- | libavformat/rtmppkt.h | 13 | ||||
-rw-r--r-- | libavformat/rtmpproto.c | 30 | ||||
-rw-r--r-- | libavformat/rtpdec_h263_rfc2190.c | 2 |
4 files changed, 57 insertions, 4 deletions
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index f0efa59257..4b5f188074 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -74,15 +74,25 @@ void ff_amf_write_object_end(uint8_t **dst) int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt) { - uint8_t hdr, t, buf[16]; + uint8_t hdr; + + if (ffurl_read(h, &hdr, 1) != 1) + return AVERROR(EIO); + + return ff_rtmp_packet_read_internal(h, p, chunk_size, prev_pkt, hdr); +} + +int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, + RTMPPacket *prev_pkt, uint8_t hdr) +{ + + uint8_t t, buf[16]; int channel_id, timestamp, data_size, offset = 0; uint32_t extra = 0; enum RTMPPacketType type; int size = 0; int ret; - if (ffurl_read(h, &hdr, 1) != 1) - return AVERROR(EIO); size++; channel_id = hdr & 0x3F; diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h index 8acbfc116b..7291397345 100644 --- a/libavformat/rtmppkt.h +++ b/libavformat/rtmppkt.h @@ -115,6 +115,19 @@ void ff_rtmp_packet_destroy(RTMPPacket *pkt); */ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt); +/** + * Read internal RTMP packet sent by the server. + * + * @param h reader context + * @param p packet + * @param chunk_size current chunk size + * @param prev_pkt previously read packet headers for all channels + * (may be needed for restoring incomplete packet header) + * @param c the first byte already read + * @return number of bytes read on success, negative value otherwise + */ +int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, + RTMPPacket *prev_pkt, uint8_t c); /** * Send RTMP packet to the server. diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 5fcec0733e..03f959e009 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; } diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c index a3a4825719..92102f3f51 100644 --- a/libavformat/rtpdec_h263_rfc2190.c +++ b/libavformat/rtpdec_h263_rfc2190.c @@ -132,7 +132,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, if (!data->buf) { /* Check the picture start code, only start buffering a new frame * if this is correct */ - if (!f && len > 4 && AV_RB32(buf) >> 10 == 0x20) { + if (len > 4 && AV_RB32(buf) >> 10 == 0x20) { int ret = avio_open_dyn_buf(&data->buf); if (ret < 0) return ret; |