From 9034b0ed66c8f4a0da13947618503d575fc43957 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 13:33:42 +0200 Subject: [PATCH 1/5] avconv: don't try to free threads that were not initialized. --- avconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index 2ed590d086..9da8d8aeca 100644 --- a/avconv.c +++ b/avconv.c @@ -2827,7 +2827,7 @@ static void free_input_threads(void) InputFile *f = input_files[i]; AVPacket pkt; - if (f->joined) + if (!f->fifo || f->joined) continue; pthread_mutex_lock(&f->fifo_lock); From d1beee0701a41dd5716427060579b10c00c685be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 14 Jun 2012 15:13:14 +0300 Subject: [PATCH 2/5] rtpdec: Don't require frames to start with a Mode A packet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While there is no reason for starting a frame with anything else than a Mode A packet, some senders seem to consistently use Mode B packets for everything. This fixes depacketization of such streams. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h263_rfc2190.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From d2d193c9b6963f3041ee0037c791c44453b845a0 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 14 Jun 2012 20:27:31 +0200 Subject: [PATCH 3/5] doc: document THREAD_TYPE fate variable --- doc/fate.texi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/fate.texi b/doc/fate.texi index 4b0250582b..975f40a6c4 100644 --- a/doc/fate.texi +++ b/doc/fate.texi @@ -78,6 +78,9 @@ meaning only while running the regression tests. @item THREADS Specify how many threads to use while running regression tests, it is quite useful to detect thread-related regressions. +@item THREAD_TYPE +Specify which threading strategy test, either @var{slice} or @var{frame}, +by default @var{slice+frame} @item CPUFLAGS Specify a mask to be applied to autodetected CPU flags. @item TARGET_EXEC From 7dc747f50b0adeaf2bcf6413e291dc4bffa54f9a Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 14 Jun 2012 15:28:40 +0200 Subject: [PATCH 4/5] rtmp: Read and handle incoming packets while writing data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavformat/rtmppkt.c | 16 +++++++++++++--- libavformat/rtmppkt.h | 13 +++++++++++++ libavformat/rtmpproto.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index ed8e6b203d..4ce238d5d0 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 8372484fbd..a83d0feb8f 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 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; } From d246c18ea6dca4dbdc92aec6ae4e3e038999a709 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 14 Jun 2012 10:19:06 +0200 Subject: [PATCH 5/5] Avoid C99 variable declarations within for statements. We generally do not declare variables within for statements and there are compilers that choke on such constructs. --- avplay.c | 6 +++--- libavcodec/pthread.c | 3 ++- libavdevice/dv1394.h | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/avplay.c b/avplay.c index c01e446ab0..e9389ffe65 100644 --- a/avplay.c +++ b/avplay.c @@ -2608,13 +2608,13 @@ static void stream_cycle_channel(VideoState *is, int codec_type) static void toggle_full_screen(void) { - is_full_screen = !is_full_screen; #if defined(__APPLE__) && SDL_VERSION_ATLEAST(1, 2, 14) /* OS X needs to empty the picture_queue */ - for (int i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) { + int i; + for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) cur_stream->pictq[i].reallocate = 1; - } #endif + is_full_screen = !is_full_screen; video_open(cur_stream); } diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 88d8ade57e..c7edb9ec81 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -865,6 +865,7 @@ error: void ff_thread_flush(AVCodecContext *avctx) { + int i; FrameThreadContext *fctx = avctx->thread_opaque; if (!avctx->thread_opaque) return; @@ -880,7 +881,7 @@ void ff_thread_flush(AVCodecContext *avctx) fctx->next_decoding = fctx->next_finished = 0; fctx->delaying = 1; fctx->prev_thread = NULL; - for (int i = 0; i < avctx->thread_count; i++) { + for (i = 0; i < avctx->thread_count; i++) { PerThreadContext *p = &fctx->threads[i]; // Make sure decode flush calls with size=0 won't return old frames p->got_frame = 0; diff --git a/libavdevice/dv1394.h b/libavdevice/dv1394.h index 5ccc68a259..fc4df24032 100644 --- a/libavdevice/dv1394.h +++ b/libavdevice/dv1394.h @@ -175,7 +175,8 @@ if(status.dropped_frames > 0) { reset_dv1394(); } else { - for(int i = 0; i < status.n_clear_frames; i++) { + int i; + for (i = 0; i < status.n_clear_frames; i++) { copy_DV_frame(); } }