find_fps attempts to infer framerate from AVCodec's timebase. When this
results in a frame rate that isn't explicitly marked as supported in
av_timecode_check_frame_rate, find_fps returns the AVStream's
avg_frame_rate, which, per avformat.h, _may_ be set (or not).

mov_get_mpeg2_xdcam_codec_tag, mov_get_h264_codec_tag and
find_compressor attempt to call av_q2d on the return value of find_fps,
which in the above case, may result in division by zero and therefore,
an undefined frame rate when NaN is converted to int.

This patch aims to reduce the number of input/output surfaces
NVENC allocates per session. Previous default sets allocated surfaces to 32
(unless there is user specified param or lookahead involved). Having large
number of surfaces consumes extra video memory (esp for higher resolution
encoding). The patch changes the surfaces calculation for default, B-frames,
lookahead scenario respectively.

The other change involves surface selection. Previously, if a session
allocates x surfaces, only x-1 surfaces are used (due to combination
of output delay and lock toggle logic). To prevent unused surfaces,
changing surface rotation to using predefined fifo.

2017-04-24 20:45:04 @ubitux BBB: btw, do you think you can get the bsf thing this week or we should skip it to give you more time and go on with the merges?
2017-04-24 20:45:20 @BBB I’m not sure I’ll finish it that soon
2017-04-24 20:45:26 @BBB I’d skip it and leave it for later
2017-04-24 20:45:35 @BBB I’ll do it, I promise, but I Can’t guarantee it’ll be done by $date

Previously, the pts value was initialised to AV_NOPTS_VALUE and so
it was not necessary to always set it. Now, with the new-new decode
API, this is no longer true. I'm not sure why I avoided setting the
pts when the decoder value was also AV_NOPTS_VALUE - it clearly
wouldn't have changed anything previously, but here we are.

Failing to do this, means the frame pts will be some random uninitalised
value.

webm_dash_manifest_demuxer: Fix UB in cue timestamp string code and make it actually work

Output was apparently not tested for correctness. Passing overlapping
memory to snprintf causes undefined behavior, and usually resulted in
only the very last timestamp being written to metadata, and not a list
at all.

The new new decode API requires the decoder to ask for the next input
packet, and it cannot just return EAGAIN if that packet cannot be
processed yet. This means we must finally confront how we get this
decoder to block when the input buffer is full and no output frames
are ready yet.

In the end, that isn't too hard to achieve - the main trick seems to
be that you have to aggressively poll the hardware - it doesn't seem
to make any forward progress if you sleep.

Purpose: libavutil/thread.h: Fixed g++ build error when ASSERT_LEVEL
is greater than 1. This is only relevant when thread.h is included by
C++ files. In this case, the relevant code is only defined if
HAVE_PTHREADS is defined as 1. Use configure --assert-level=2 to do
so.

Note: Issue discovered as a result of Coverity build failure. Cause
of build failure pinpointed by Hendrik Leppkes.

Comments:

-- libavutil/thread.h: Altered ASSERT_PTHREAD_NORET definition such
that it uses av_make_error_string instead of av_err2str().
av_err2str() uses a "parenthesized type followed by an initializer
list", which is apparently not valid C++. This issue started
occurring because thread.h is now included by the DeckLink C++
files. The alteration does the equivalent of what av_err2str()
does, but instead declares the character buffer as a local
variable.