pthread: Fix deadlock during thread initialization

Sometimes, if pthread_create() failed, then pthread_cond_wait() could
accidentally be called in the worker threads after the uninit function
had already called pthread_cond_broadcast(), leading to a deadlock.

Don't call pthread_cond_wait() if c->done is set.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
pthread: Avoid spurious wakeups

pthread_wait_cond can wake up unexpectedly (Wikipedia: Spurious_wakeup).

The FF_THREAD_SLICE thread mechanism could spontaneously execute
jobs or allow the caller of avctx->execute to return before all
jobs were complete.

Test both cases to ensure the wakeup is real.

Signed-off-by: Ben Jackson <ben@ben.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
avformat/wavdec: Dont trust the fact chunk for PCM

Fixes Ticket3033

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 83fc6c822b06688e572333299927d93eb3c6c426)

Conflicts:
	libavformat/wavdec.c
avformat/matroskadec: only set r_frame_rate if the value is within reasonable limits

Fixes Ticket2451

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 6853e40106cac769f0641183ea0bdd530ae9a0a1)
avcodec/h264_refs: modify key frame detection heuristic to detect more cases

Fixes Ticket2968

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 5ac6b6028f17b64723884c9fa72cfcbd369a1ba2)

Conflicts:
	libavcodec/h264_refs.c
avformat/mov: force parsing of headers if stts is absent

Fixes Ticket2991

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit e41ea866fc26f38d770bbc1ad67703e7f4400ae1)
avcodec/h264: do not trust last_pic_droppable when marking pictures as done

This simplifies the code and fixes a deadlock

Fixes Ticket2927
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 29ffeef5e73b8f41ff3a3f2242d356759c66f91f)

Conflicts:
	libavcodec/h264.c
avformat/mp3dec: perform seek resync in the correct direction

Fixes seeking to the last frame in CBR files
Fixes Ticket2773

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit ba8716df7fb541fb690d1a898cda0e12f9011faf)
avcodec/h264: reduce noisiness of "mmco: unref short failure"

Do not consider it an error if we have no frames and should discard one.
This condition can easily happen when decoding is started from an I frame

Fixes Ticket2811

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 08a89761964bdd0a023eff6d37a1131fb7e1d7a0)

Conflicts:
	libavcodec/h264_refs.c
h264: make flush_change() set mmco_reset

This ensures that frames do not get mixed on context reinits

Fixes Ticket2836

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 3c9dd93faa9f3c250428dd0548c075583aa07cc3)
avformat/utils: do not override pts in h264 when they are provided from the demuxer

Fixes Ticket2143

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 1e5271a9fd6ddcceb083f2185a4bbd8d44c9a813)
x86: ac3dsp: Remove 3dnow version of ff_ac3_extract_exponents

The function requires increasing the fuzz factor for the ac3/eac3 encode
tests and even so makes fate fail. It only provides a slight encoding
speedup for legacy CPUs that do not support SSE2. Thus its benefit is not
worth the trouble it creates and fixing it would be a waste of time.
build: avoid stdin stall with GNU AS probing.

a758c5e added probing for various tools, such as AS. Unfortunately, GNU
AS is reading stdin with -v, and thus configure is stalled with
configure arguments such as --as=as.

Fixes Ticket #1898.
(cherry picked from commit dbb41f93c16cbc65a899a75723c95da51c851cd5)
avformat/utils: dont count attached pics toward the probesize

Such pics behave more like headers which we also dont count.
Fixes Ticket3146

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit a8dec360c5db15e8da4b44ff3c0f02a6c57e8ac0)
mpeg4videodec: split initializing static tables into a separate function

Signed-off-by: Anton Khirnov <anton@khirnov.net>
mpeg4video_parser: init mpeg4 static tables.

They are used when decoding the frame header.
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC:libav-stable@libav.org

Signed-off-by: Anton Khirnov <anton@khirnov.net>
h264/mpegvideo: do not provide pixel formats for hwaccels that are not compiled in
avcodec/cabac: force get_cabac to be not inlined

works around bug in gccs inline asm register assignment
Fixes Ticket3177

gcc from 4.4 to 4.6 is affected at least, no non affected gccs known
clang seems not affected

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 0538b29ae8002c44f27bae8a1a6fc6e646998be5)
alsdec: check block length

Fix writing over the end

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Addresses: CVE-2013-0845
(cherry picked from commit 2a0fb7286d67c47e44aa76c237ede117b22af616)

Signed-off-by: Reinhard Tartler <siretart@tauware.de>
arm: Don't clobber callee saved registers in scalarproduct

q4-q7/d8-d15 are supposed to not be clobbered by the callee.

CC: libav-stable@libav.org
Signed-off-by: Martin Storsjö <martin@martin.st>
(cherry picked from commit d307e408d4a9ada22df443cc38be77cc5e492694)

Signed-off-by: Martin Storsjö <martin@martin.st>