h264: Move start code search functions into separate source files.

This permits re-use with parsers for codecs which use similar start codes.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
vc-1: Add platform-specific start code search routine to VC1DSPContext.

Initialise VC1DSPContext for parser as well as for decoder.
Note, the VC-1 code doesn't actually use the function pointer yet.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
vc-1: Optimise parser (with special attention to ARM)

The previous implementation of the parser made four passes over each input
buffer (reduced to two if the container format already guaranteed the input
buffer corresponded to frames, such as with MKV). But these buffers are
often 200K in size, certainly enough to flush the data out of L1 cache, and
for many CPUs, all the way out to main memory. The passes were:

1) locate frame boundaries (not needed for MKV etc)
2) copy the data into a contiguous block (not needed for MKV etc)
3) locate the start codes within each frame
4) unescape the data between start codes

After this, the unescaped data was parsed to extract certain header fields,
but because the unescape operation was so large, this was usually also
effectively operating on uncached memory. Most of the unescaped data was
simply thrown away and never processed further. Only step 2 - because it
used memcpy - was using prefetch, making things even worse.

This patch reorganises these steps so that, aside from the copying, the
operations are performed in parallel, maximising cache utilisation. No more
than the worst-case number of bytes needed for header parsing is unescaped.
Most of the data is, in practice, only read in order to search for a start
code, for which optimised implementations already existed in the H264 codec
(notably the ARM version uses prefetch, so we end up doing both remaining
passes at maximum speed). For MKV files, we know when we've found the last
start code of interest in a given frame, so we are able to avoid doing even
that one remaining pass for most of the buffer.

In some use-cases (such as the Raspberry Pi) video decode is handled by the
GPU, but the entire elementary stream is still fed through the parser to
pick out certain elements of the header which are necessary to manage the
decode process. As you might expect, in these cases, the performance of the
parser is significant.

To measure parser performance, I used the same VC-1 elementary stream in
either an MPEG-2 transport stream or a MKV file, and fed it through avconv
with -c:v copy -c:a copy -f null. These are the gperftools counts for
those streams, both filtered to only include vc1_parse() and its callees,
and unfiltered (to include the whole binary). Lower numbers are better:

                Before          After
File  Filtered  Mean   StdDev   Mean   StdDev  Confidence  Change
M2TS  No        861.7  8.2      650.5  8.1     100.0%      +32.5%
MKV   No        868.9  7.4      731.7  9.0     100.0%      +18.8%
M2TS  Yes       250.0  11.2     27.2   3.4     100.0%      +817.9%
MKV   Yes       149.0  12.8     1.7    0.8     100.0%      +8526.3%

Yes, that last case shows vc1_parse() running 86 times faster! The M2TS
case does show a larger absolute improvement though, since it was worse
to begin with.

This patch has been tested with the FATE suite (albeit on x86 for speed).

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
mpegts: Define the section length with a constant

The specification says the value is expressed in 10 bits including
the 4-byte CRC.
mpegts: Add HEVC definitions

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
movenc: Add option to disable nero chapters

And add flag to muxer documentation.
Nero chapters break some taggers (mp3tag and iTunes).

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Merge commit 'db7f1c7c5a1d37e7f4da64a79a97bea1c4b6e9f8'

* commit 'db7f1c7c5a1d37e7f4da64a79a97bea1c4b6e9f8':
  h264: Move start code search functions into separate source files.

Conflicts:
	libavcodec/arm/Makefile
	libavcodec/arm/h264dsp_init_arm.c
	libavcodec/h264_parser.c
	libavcodec/h264dsp.c
	libavcodec/startcode.c
	libavcodec/startcode.h

See: 270cede3f3772117454a14b620803d731036942d
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit 'adf8227cf4e7b4fccb2ad88e1e09b6dc00dd00ed'

* commit 'adf8227cf4e7b4fccb2ad88e1e09b6dc00dd00ed':
  vc-1: Add platform-specific start code search routine to VC1DSPContext.

Conflicts:
	configure
	libavcodec/arm/vc1dsp_init_arm.c
	libavcodec/vc1dsp.c
	libavcodec/vc1dsp.h

See: 9d8ecdd8ca6d248e7439e8fdf255e39eda14e0f2
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit '701e8b42e12ad625c64ceae2252acb1de390278c'

* commit '701e8b42e12ad625c64ceae2252acb1de390278c':
  vc-1: Optimise parser (with special attention to ARM)

Conflicts:
	libavcodec/vc1_parser.c

See: a0d7f9ec9a10d935b83a47dbcb2cd85dcc007738
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit '89616408e38ac7257e36976723df0e23d6ee1157'

* commit '89616408e38ac7257e36976723df0e23d6ee1157':
  mpegts: Define the section length with a constant

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit '2601a9447efb778930b01ac58d2cc1d02498db4e'

* commit '2601a9447efb778930b01ac58d2cc1d02498db4e':
  mpegts: Add HEVC definitions

Conflicts:
	libavformat/mpegts.h

See: b2880a3de9e3e160c47c069abcc8cb60015407b6
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Merge commit '0897d2fdc7755849c3ae58d8b543ef734c200d3c'

* commit '0897d2fdc7755849c3ae58d8b543ef734c200d3c':
  movenc: Add option to disable nero chapters

Conflicts:
	doc/muxers.texi

Merged-by: Michael Niedermayer <michaelni@gmx.at>
avfilter/avf_showwaves: New p2p mode for showwaves filter

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>