]> git.sesse.net Git - ffmpeg/commitdiff
Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 1 Dec 2011 23:51:11 +0000 (00:51 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 1 Dec 2011 23:51:11 +0000 (00:51 +0100)
* qatar/master: (25 commits)
  rtpenc: Add support for G726 audio
  rtpdec: Interpret the different G726 names as bits_per_coded_sample
  rtpenc: Change rtp_send_samples to handle sample sizes other than even bytes
  rtpenc: Cast a rescaling parameter to int64_t
  h264: cap max has_b_frames at MAX_DELAYED_PIC_COUNT - 1.
  ARM: fix indentation in ff_dsputil_init_neon()
  ARM: NEON put/avg_pixels8/16 cosmetics
  ARM: add remaining NEON avg_pixels8/16 functions
  ARM: clean up NEON put/avg_pixels macros
  fate: split acodec-pcm into individual tests
  swscale: #include "libavutil/mathematics.h"
  pmpdec: don't use deprecated av_set_pts_info.
  rv34: align temporary block of "dct" coefs
  Add PlayStation Portable PMP format demuxer
  proto: Realign struct initializers
  proto: Use .priv_data_size to allocate the private context
  mmsh: Properly clean up if the second ffurl_alloc failed
  rtmp: Clean up properly if the handshake failed
  md5proto: Remove the get_file_handle function
  applehttpproto: Use the close function if the open function fails
  ...

Conflicts:
libavcodec/vble.c
libavformat/mmsh.c
libavformat/pmpdec.c
libavformat/udp.c
tests/ref/acodec/pcm

Merged-by: Michael Niedermayer <michaelni@gmx.at>
29 files changed:
1  2 
Changelog
libavcodec/arm/dsputil_init_neon.c
libavcodec/arm/dsputil_neon.S
libavcodec/h264.c
libavcodec/rv34.c
libavformat/applehttpproto.c
libavformat/cache.c
libavformat/concat.c
libavformat/gopher.c
libavformat/http.c
libavformat/librtmp.c
libavformat/md5proto.c
libavformat/mmsh.c
libavformat/mmst.c
libavformat/pmpdec.c
libavformat/rtmpproto.c
libavformat/rtpdec_g726.c
libavformat/rtpenc.c
libavformat/rtpproto.c
libavformat/sdp.c
libavformat/tcp.c
libavformat/udp.c
libswscale/utils.c
tests/codec-regression.sh
tests/ref/acodec/pcm_s16be
tests/ref/acodec/pcm_s24be
tests/ref/acodec/pcm_s24daud
tests/ref/acodec/pcm_s32be
tests/ref/acodec/pcm_s8

diff --combined Changelog
index e64dca688b607972cc8bb5319e0afd90b1ed9642,ff37020bdbf361103c98a7a8d2d53a9be0aa2622..3b12e2ae974f09bb85365a853103440bbe86dbe5
+++ b/Changelog
@@@ -1,14 -1,12 +1,14 @@@
  Entries are sorted chronologically from oldest to youngest within each release,
  releases are sorted from youngest to oldest.
  
 +version next:
  
 -version <next>:
 +- openal input device added
 +- boxblur filter added
  - BWF muxer
  - Flash Screen Video 2 decoder
 -- ffplay/ffprobe/ffserver renamed to avplay/avprobe/avserver
 -- ffmpeg deprecated, added avconv, which is almost the same for now, except
 +- lavfi input device added
 +- added avconv, which is almost the same for now, except
  for a few incompatible changes in the options, which will hopefully make them
  easier to use. The changes are:
      * The options placement is now strictly enforced! While in theory the
      * -vframes/-aframes/-dframes options are now aliases to the new -frames option.
      * -vtag/-atag/-stag options are now aliases to the new -tag option.
  - XMV demuxer
 +- LOAS demuxer
 +- ashowinfo filter added
  - Windows Media Image decoder
 +- amovie source added
  - LATM muxer/demuxer
 -- showinfo filter
 -- split filter
 +- Speex encoder via libspeex
 +- JSON output in ffprobe
 +- WTV muxer
 +- Optional C++ Support (needed for libstagefright)
 +- H.264 Decoding on Android via Stagefright
 +- Prores decoder
 +- BIN/XBIN/ADF/IDF text file decoder
 +- aconvert audio filter added
 +- audio support to lavfi input device added
  - libcdio-paranoia input device for audio CD grabbing
 -- select filter
  - Apple ProRes decoder
  - CELT in Ogg demuxing
 +- G.723.1 demuxer and decoder
 +- libmodplug support (--enable-libmodplug)
  - VC-1 interlaced decoding
 -- lut, lutrgb, and lutyuv filters
 -- boxblur filter
 +- libutvideo wrapper (--enable-libutvideo)
 +- aevalsrc audio source added
  - Ut Video decoder
  - Speex encoding via libspeex
  - 4:2:2 H.264 decoding support
  - 4:2:2 and 4:4:4 H.264 encoding with libx264
  - Pulseaudio input device
 +- Prores encoder
 +- Video Decoder Acceleration (VDA) HWAccel module.
  - replacement Indeo 3 decoder
 +- new ffmpeg option: -map_channel
 +- volume audio filter added
 +- earwax audio filter added
 +- libv4l2 support (--enable-libv4l2)
  - TLS/SSL and HTTPS protocol support
  - AVOptions API rewritten and documented
  - most of CODEC_FLAG2_*, some CODEC_FLAG_* and many codec-specific fields in
  - Discworld II BMV decoding support
  - VBLE Decoder
  - OS X Video Decoder Acceleration (VDA) support
 +- compact and csv output in ffprobe
 +- pan audio filter
 +- IFF Amiga Continuous Bitmap (ACBM) decoder
 +- ass filter
  - CRI ADX audio format demuxer
+ - Playstation Portable PMP format demuxer
  
  
 -version 0.7:
 -
 -- E-AC-3 audio encoder
 -- ac3enc: add channel coupling support
 -- floating-point sample format support for (E-)AC-3, DCA, AAC, Vorbis decoders
 -- H.264/MPEG frame-level multithreading
 -- av_metadata_* functions renamed to av_dict_* and moved to libavutil
 -- 4:4:4 H.264 decoding support
 -- 10-bit H.264 optimizations for x86
 -- bump libswscale for recently reported ABI break
 -
 -
 -version 0.7_beta2:
 +version 0.8:
  
 -- VP8 frame-level multithreading
 -- NEON optimizations for VP8
 -- removed a lot of deprecated API cruft
 -- FFT and IMDCT optimizations for AVX (Sandy Bridge) processors
 -- DPX image encoder
 -- SMPTE 302M AES3 audio decoder
 -- ffmpeg no longer quits after the 'q' key is pressed; use 'ctrl+c' instead
 -- 9bit and 10bit per sample support in the H.264 decoder
 -
 -
 -version 0.7_beta1:
  
 +- many many things we forgot because we rather write code than changelogs
  - WebM support in Matroska de/muxer
  - low overhead Ogg muxing
  - MMS-TCP support
  - Demuxer for On2's IVF format
  - Pictor/PC Paint decoder
  - HE-AAC v2 decoder
 +- HE-AAC v2 encoding with libaacplus
  - libfaad2 wrapper removed
  - DTS-ES extension (XCh) decoding support
  - native VP8 decoder
  - RTP depacketization of QDM2
  - ANSI/ASCII art playback system
  - Lego Mindstorms RSO de/muxer
 +- libavcore added (and subsequently removed)
  - SubRip subtitle file muxer and demuxer
  - Chinese AVS encoding via libxavs
  - ffprobe -show_packets option added
  - replace the ocv_smooth filter with a more generic ocv filter
  - Windows Televison (WTV) demuxer
  - FFmpeg metadata format muxer and demuxer
 -- SubRip (srt) subtitle decoder
 +- SubRip (srt) subtitle encoder and decoder
  - floating-point AC-3 encoder added
  - Lagarith decoder
  - ffmpeg -copytb option added
  - sndio support for playback and record
  - Linux framebuffer input device added
  - Chronomaster DFA decoder
 -- Mobotix MxPEG decoder
 +- DPX image encoder
 +- MicroDVD subtitle file muxer and demuxer
 +- Playstation Portable PMP format demuxer
 +- fieldorder video filter added
  - AAC encoding via libvo-aacenc
  - AMR-WB encoding via libvo-amrwbenc
  - xWMA demuxer
 -- fieldorder video filter added
 +- Mobotix MxPEG decoder
 +- VP8 frame-multithreading
 +- NEON optimizations for VP8
 +- Lots of deprecated API cruft removed
 +- fft and imdct optimizations for AVX (Sandy Bridge) processors
 +- showinfo filter added
 +- SMPTE 302M AES3 audio decoder
 +- Apple Core Audio Format muxer
 +- 9bit and 10bit per sample support in the H.264 decoder
 +- 9bit and 10bit FFV1 encoding / decoding
 +- split filter added
 +- select filter added
 +- sdl output device added
 +- libmpcodecs video filter support (3 times as many filters than before)
 +- mpeg2 aspect ratio dection fixed
 +- libxvid aspect pickiness fixed
 +- Frame multithreaded decoding
 +- E-AC-3 audio encoder
 +- ac3enc: add channel coupling support
 +- floating-point sample format support to the ac3, eac3, dca, aac, and vorbis decoders.
 +- H264/MPEG frame-level multi-threading
 +- All av_metadata_* functions renamed to av_dict_* and moved to libavutil
 +- 4:4:4 H.264 decoding support
 +- 10-bit H.264 optimizations for x86
 +- lut, lutrgb, and lutyuv filters added
 +- buffersink libavfilter sink added
 +- Bump libswscale for recently reported ABI break
 +- New J2K encoder (via OpenJPEG)
 +
 +
 +version 0.7:
 +
 +- all the changes for 0.8, but keeping API/ABI compatibility with the 0.6 release
  
  
  version 0.6:
@@@ -491,7 -454,6 +492,7 @@@ version 0.5
  - Gopher client support
  - MXF D-10 muxer
  - generic metadata API
 +- flash ScreenVideo2 encoder
  
  
  version 0.4.9-pre1:
index ddc9d640f8b9ea030a8da6fd924c0af7b89913db,68e5b3ed422149583629f70df158d208a05a7de4..3f4dcdad5c0d2f0d8b885dcff7315d6f8746abde
@@@ -2,20 -2,20 +2,20 @@@
   * ARM NEON optimised DSP functions
   * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -53,7 -53,19 +53,19 @@@ void ff_put_pixels8_y2_no_rnd_neon(uint
  void ff_put_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
  
  void ff_avg_pixels16_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_x2_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_y2_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_xy2_neon(uint8_t *, const uint8_t *, int, int);
  void ff_avg_pixels8_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_x2_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_y2_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_xy2_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
+ void ff_avg_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
  
  void ff_add_pixels_clamped_neon(const DCTELEM *, uint8_t *, int);
  void ff_put_pixels_clamped_neon(const DCTELEM *, uint8_t *, int);
@@@ -189,37 -201,51 +201,51 @@@ void ff_dsputil_init_neon(DSPContext *c
      }
  
      if (!high_bit_depth) {
-     c->clear_block  = ff_clear_block_neon;
-     c->clear_blocks = ff_clear_blocks_neon;
-     c->put_pixels_tab[0][0] = ff_put_pixels16_neon;
-     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_neon;
-     c->put_pixels_tab[0][2] = ff_put_pixels16_y2_neon;
-     c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_neon;
-     c->put_pixels_tab[1][0] = ff_put_pixels8_neon;
-     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_neon;
-     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_neon;
-     c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_neon;
-     c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_neon;
-     c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_neon;
-     c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_neon;
-     c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_neon;
-     c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_neon;
-     c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_neon;
-     c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_neon;
-     c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_neon;
-     c->avg_pixels_tab[0][0] = ff_avg_pixels16_neon;
-     c->avg_pixels_tab[1][0] = ff_avg_pixels8_neon;
+         c->clear_block  = ff_clear_block_neon;
+         c->clear_blocks = ff_clear_blocks_neon;
+         c->put_pixels_tab[0][0] = ff_put_pixels16_neon;
+         c->put_pixels_tab[0][1] = ff_put_pixels16_x2_neon;
+         c->put_pixels_tab[0][2] = ff_put_pixels16_y2_neon;
+         c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_neon;
+         c->put_pixels_tab[1][0] = ff_put_pixels8_neon;
+         c->put_pixels_tab[1][1] = ff_put_pixels8_x2_neon;
+         c->put_pixels_tab[1][2] = ff_put_pixels8_y2_neon;
+         c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_neon;
+         c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_neon;
+         c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_neon;
+         c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_neon;
+         c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_neon;
+         c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_neon;
+         c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_neon;
+         c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_neon;
+         c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_neon;
+         c->avg_pixels_tab[0][0] = ff_avg_pixels16_neon;
+         c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_neon;
+         c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_neon;
+         c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_neon;
+         c->avg_pixels_tab[1][0] = ff_avg_pixels8_neon;
+         c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_neon;
+         c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_neon;
+         c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_neon;
+         c->avg_no_rnd_pixels_tab[0][0] = ff_avg_pixels16_neon;
+         c->avg_no_rnd_pixels_tab[0][1] = ff_avg_pixels16_x2_no_rnd_neon;
+         c->avg_no_rnd_pixels_tab[0][2] = ff_avg_pixels16_y2_no_rnd_neon;
+         c->avg_no_rnd_pixels_tab[0][3] = ff_avg_pixels16_xy2_no_rnd_neon;
+         c->avg_no_rnd_pixels_tab[1][0] = ff_avg_pixels8_neon;
+         c->avg_no_rnd_pixels_tab[1][1] = ff_avg_pixels8_x2_no_rnd_neon;
+         c->avg_no_rnd_pixels_tab[1][2] = ff_avg_pixels8_y2_no_rnd_neon;
+         c->avg_no_rnd_pixels_tab[1][3] = ff_avg_pixels8_xy2_no_rnd_neon;
      }
  
      c->add_pixels_clamped = ff_add_pixels_clamped_neon;
      c->put_pixels_clamped = ff_put_pixels_clamped_neon;
      c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_neon;
  
-     if (CONFIG_H264_DECODER) {
-         if (!high_bit_depth) {
+     if (CONFIG_H264_DECODER && !high_bit_depth) {
          c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_neon;
          c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_neon;
          c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_neon;
          c->avg_h264_qpel_pixels_tab[1][13] = ff_avg_h264_qpel8_mc13_neon;
          c->avg_h264_qpel_pixels_tab[1][14] = ff_avg_h264_qpel8_mc23_neon;
          c->avg_h264_qpel_pixels_tab[1][15] = ff_avg_h264_qpel8_mc33_neon;
-         }
      }
  
      if (CONFIG_VP3_DECODER) {
index b765f23d023bcb7d08ac8e5cbbefe4d8b3948b25,d49aedd6c40ed5ebf62e247a0405c28e006f0960..c660cb0d4c78e9d99c2bc7dd3889af621c8352cf
@@@ -2,20 -2,20 +2,20 @@@
   * ARM NEON optimised DSP functions
   * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -40,75 -40,89 +40,89 @@@ function ff_clear_blocks_neon, export=
          bx              lr
  endfunc
  
        .macro pixels16 avg=0
- .if \avg
-         mov             ip,  r0
- .endif
- 1:      vld1.64         {d0, d1},  [r1], r2
-         vld1.64         {d2, d3},  [r1], r2
-         vld1.64         {d4, d5},  [r1], r2
.macro  pixels16        rnd=1, avg=0
  .if \avg
+         mov             r12, r0
  .endif
+ 1:      vld1.64         {q0},     [r1], r2
+         vld1.64         {q1},     [r1], r2
+         vld1.64         {q2},     [r1], r2
          pld             [r1, r2, lsl #2]
-         vld1.64         {d6, d7},  [r1], r2
+         vld1.64         {q3},     [r1], r2
          pld             [r1]
          pld             [r1, r2]
          pld             [r1, r2, lsl #1]
- .if \avg
-         vld1.64         {d16,d17}, [ip,:128], r2
  .if \avg
+         vld1.64         {q8},     [r12,:128], r2
          vrhadd.u8       q0,  q0,  q8
-         vld1.64         {d18,d19}, [ip,:128], r2
+         vld1.64         {q9},     [r12,:128], r2
          vrhadd.u8       q1,  q1,  q9
-         vld1.64         {d20,d21}, [ip,:128], r2
+         vld1.64         {q10},    [r12,:128], r2
          vrhadd.u8       q2,  q2,  q10
-         vld1.64         {d22,d23}, [ip,:128], r2
+         vld1.64         {q11},    [r12,:128], r2
          vrhadd.u8       q3,  q3,  q11
- .endif
  .endif
          subs            r3,  r3,  #4
-         vst1.64         {d0, d1},  [r0,:128], r2
-         vst1.64         {d2, d3},  [r0,:128], r2
-         vst1.64         {d4, d5},  [r0,:128], r2
-         vst1.64         {d6, d7},  [r0,:128], r2
+         vst1.64         {q0},     [r0,:128], r2
+         vst1.64         {q1},     [r0,:128], r2
+         vst1.64         {q2},     [r0,:128], r2
+         vst1.64         {q3},     [r0,:128], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
-         .macro pixels16_x2 vhadd=vrhadd.u8
- 1:      vld1.64         {d0-d2},   [r1], r2
-         vld1.64         {d4-d6},   [r1], r2
+ .macro  pixels16_x2     rnd=1, avg=0
+ 1:      vld1.64         {d0-d2},  [r1], r2
+         vld1.64         {d4-d6},  [r1], r2
          pld             [r1]
          pld             [r1, r2]
          subs            r3,  r3,  #2
          vext.8          q1,  q0,  q1,  #1
-         \vhadd          q0,  q0,  q1
+         avg             q0,  q0,  q1
          vext.8          q3,  q2,  q3,  #1
-         \vhadd          q2,  q2,  q3
-         vst1.64         {d0, d1},  [r0,:128], r2
-         vst1.64         {d4, d5},  [r0,:128], r2
+         avg             q2,  q2,  q3
+   .if \avg
+         vld1.8          {q1},     [r0,:128], r2
+         vld1.8          {q3},     [r0,:128]
+         vrhadd.u8       q0,  q0,  q1
+         vrhadd.u8       q2,  q2,  q3
+         sub             r0,  r0,  r2
+   .endif
+         vst1.64         {q0},     [r0,:128], r2
+         vst1.64         {q2},     [r0,:128], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
-         .macro pixels16_y2 vhadd=vrhadd.u8
-         vld1.64         {d0, d1},  [r1], r2
-         vld1.64         {d2, d3},  [r1], r2
+ .macro  pixels16_y2     rnd=1, avg=0
+         vld1.64         {q0},     [r1], r2
+         vld1.64         {q1},     [r1], r2
  1:      subs            r3,  r3,  #2
-         \vhadd          q2,  q0,  q1
-         vld1.64         {d0, d1},  [r1], r2
-         \vhadd          q3,  q0,  q1
-         vld1.64         {d2, d3},  [r1], r2
+         avg             q2,  q0,  q1
+         vld1.64         {q0},     [r1], r2
+         avg             q3,  q0,  q1
+         vld1.64         {q1},     [r1], r2
          pld             [r1]
          pld             [r1, r2]
-         vst1.64         {d4, d5},  [r0,:128], r2
-         vst1.64         {d6, d7},  [r0,:128], r2
+   .if \avg
+         vld1.8          {q8},     [r0,:128], r2
+         vld1.8          {q9},     [r0,:128]
+         vrhadd.u8       q2,  q2,  q8
+         vrhadd.u8       q3,  q3,  q9
+         sub             r0,  r0,  r2
+   .endif
+         vst1.64         {q2},     [r0,:128], r2
+         vst1.64         {q3},     [r0,:128], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
        .macro pixels16_xy2 vshrn=vrshrn.u16 no_rnd=0
-         vld1.64         {d0-d2},   [r1], r2
-         vld1.64         {d4-d6},   [r1], r2
.if \no_rnd
.macro  pixels16_xy2    rnd=1, avg=0
+         vld1.64         {d0-d2},  [r1], r2
+         vld1.64         {d4-d6},  [r1], r2
  .ifeq \rnd
          vmov.i16        q13, #1
- .endif
  .endif
          pld             [r1]
          pld             [r1, r2]
          vext.8          q1,  q0,  q1,  #1
          vaddl.u8        q9,  d4,  d6
          vaddl.u8        q11, d5,  d7
  1:      subs            r3,  r3,  #2
-         vld1.64         {d0-d2},   [r1], r2
+         vld1.64         {d0-d2},  [r1], r2
          vadd.u16        q12, q8,  q9
          pld             [r1]
.if \no_rnd
  .ifeq \rnd
          vadd.u16        q12, q12, q13
- .endif
  .endif
          vext.8          q15, q0,  q1,  #1
          vadd.u16        q1 , q10, q11
-         \vshrn          d28, q12, #2
.if \no_rnd
+         shrn            d28, q12, #2
  .ifeq \rnd
          vadd.u16        q1,  q1,  q13
- .endif
-         \vshrn          d29, q1,  #2
+   .endif
+         shrn            d29, q1,  #2
+   .if \avg
+         vld1.8          {q8},     [r0,:128]
+         vrhadd.u8       q14, q14, q8
+   .endif
          vaddl.u8        q8,  d0,  d30
-         vld1.64         {d2-d4},   [r1], r2
+         vld1.64         {d2-d4},  [r1], r2
          vaddl.u8        q10, d1,  d31
-         vst1.64         {d28,d29}, [r0,:128], r2
+         vst1.64         {q14},    [r0,:128], r2
          vadd.u16        q12, q8,  q9
          pld             [r1, r2]
.if \no_rnd
  .ifeq \rnd
          vadd.u16        q12, q12, q13
- .endif
  .endif
          vext.8          q2,  q1,  q2,  #1
          vadd.u16        q0,  q10, q11
-         \vshrn          d30, q12, #2
.if \no_rnd
+         shrn            d30, q12, #2
  .ifeq \rnd
          vadd.u16        q0,  q0,  q13
- .endif
-         \vshrn          d31, q0,  #2
+   .endif
+         shrn            d31, q0,  #2
+   .if \avg
+         vld1.8          {q9},     [r0,:128]
+         vrhadd.u8       q15, q15, q9
+   .endif
          vaddl.u8        q9,  d2,  d4
          vaddl.u8        q11, d3,  d5
-         vst1.64         {d30,d31}, [r0,:128], r2
+         vst1.64         {q15},    [r0,:128], r2
          bgt             1b
          bx              lr
        .endm
+ .endm
  
        .macro pixels8 avg=0
- 1:      vld1.64         {d0}, [r1], r2
-         vld1.64         {d1}, [r1], r2
-         vld1.64         {d2}, [r1], r2
.macro  pixels8         rnd=1, avg=0
+ 1:      vld1.64         {d0},     [r1], r2
+         vld1.64         {d1},     [r1], r2
+         vld1.64         {d2},     [r1], r2
          pld             [r1, r2, lsl #2]
-         vld1.64         {d3}, [r1], r2
+         vld1.64         {d3},     [r1], r2
          pld             [r1]
          pld             [r1, r2]
          pld             [r1, r2, lsl #1]
- .if \avg
-         vld1.64         {d4}, [r0,:64], r2
  .if \avg
+         vld1.64         {d4},     [r0,:64], r2
          vrhadd.u8       d0,  d0,  d4
-         vld1.64         {d5}, [r0,:64], r2
+         vld1.64         {d5},     [r0,:64], r2
          vrhadd.u8       d1,  d1,  d5
-         vld1.64         {d6}, [r0,:64], r2
+         vld1.64         {d6},     [r0,:64], r2
          vrhadd.u8       d2,  d2,  d6
-         vld1.64         {d7}, [r0,:64], r2
+         vld1.64         {d7},     [r0,:64], r2
          vrhadd.u8       d3,  d3,  d7
          sub             r0,  r0,  r2,  lsl #2
- .endif
  .endif
          subs            r3,  r3,  #4
-         vst1.64         {d0}, [r0,:64], r2
-         vst1.64         {d1}, [r0,:64], r2
-         vst1.64         {d2}, [r0,:64], r2
-         vst1.64         {d3}, [r0,:64], r2
+         vst1.64         {d0},     [r0,:64], r2
+         vst1.64         {d1},     [r0,:64], r2
+         vst1.64         {d2},     [r0,:64], r2
+         vst1.64         {d3},     [r0,:64], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
-         .macro pixels8_x2 vhadd=vrhadd.u8
- 1:      vld1.64         {d0, d1},  [r1], r2
+ .macro  pixels8_x2      rnd=1, avg=0
+ 1:      vld1.64         {q0},     [r1], r2
          vext.8          d1,  d0,  d1,  #1
-         vld1.64         {d2, d3},  [r1], r2
+         vld1.64         {q1},     [r1], r2
          vext.8          d3,  d2,  d3,  #1
          pld             [r1]
          pld             [r1, r2]
          subs            r3,  r3,  #2
          vswp            d1,  d2
-         \vhadd          q0,  q0,  q1
-         vst1.64         {d0},      [r0,:64], r2
-         vst1.64         {d1},      [r0,:64], r2
+         avg             q0,  q0,  q1
+   .if \avg
+         vld1.8          {d4},     [r0,:64], r2
+         vld1.8          {d5},     [r0,:64]
+         vrhadd.u8       q0,  q0,  q2
+         sub             r0,  r0,  r2
+   .endif
+         vst1.64         {d0},     [r0,:64], r2
+         vst1.64         {d1},     [r0,:64], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
-         .macro pixels8_y2 vhadd=vrhadd.u8
-         vld1.64         {d0},      [r1], r2
-         vld1.64         {d1},      [r1], r2
+ .macro  pixels8_y2      rnd=1, avg=0
+         vld1.64         {d0},     [r1], r2
+         vld1.64         {d1},     [r1], r2
  1:      subs            r3,  r3,  #2
-         \vhadd          d4,  d0,  d1
-         vld1.64         {d0},      [r1], r2
-         \vhadd          d5,  d0,  d1
-         vld1.64         {d1},      [r1], r2
+         avg             d4,  d0,  d1
+         vld1.64         {d0},     [r1], r2
+         avg             d5,  d0,  d1
+         vld1.64         {d1},     [r1], r2
          pld             [r1]
          pld             [r1, r2]
-         vst1.64         {d4},      [r0,:64], r2
-         vst1.64         {d5},      [r0,:64], r2
+   .if \avg
+         vld1.8          {d2},     [r0,:64], r2
+         vld1.8          {d3},     [r0,:64]
+         vrhadd.u8       q2,  q2,  q1
+         sub             r0,  r0,  r2
+   .endif
+         vst1.64         {d4},     [r0,:64], r2
+         vst1.64         {d5},     [r0,:64], r2
          bne             1b
          bx              lr
        .endm
+ .endm
  
        .macro pixels8_xy2 vshrn=vrshrn.u16 no_rnd=0
-         vld1.64         {d0, d1},  [r1], r2
-         vld1.64         {d2, d3},  [r1], r2
.if \no_rnd
.macro  pixels8_xy2     rnd=1, avg=0
+         vld1.64         {q0},     [r1], r2
+         vld1.64         {q1},     [r1], r2
  .ifeq \rnd
          vmov.i16        q11, #1
- .endif
  .endif
          pld             [r1]
          pld             [r1, r2]
          vext.8          d4,  d0,  d1,  #1
          vaddl.u8        q8,  d0,  d4
          vaddl.u8        q9,  d2,  d6
  1:      subs            r3,  r3,  #2
-         vld1.64         {d0, d1},  [r1], r2
+         vld1.64         {q0},     [r1], r2
          pld             [r1]
          vadd.u16        q10, q8,  q9
          vext.8          d4,  d0,  d1,  #1
.if \no_rnd
  .ifeq \rnd
          vadd.u16        q10, q10, q11
- .endif
  .endif
          vaddl.u8        q8,  d0,  d4
-         \vshrn          d5,  q10, #2
-         vld1.64         {d2, d3},  [r1], r2
+         shrn            d5,  q10, #2
+         vld1.64         {q1},     [r1], r2
          vadd.u16        q10, q8,  q9
          pld             [r1, r2]
- .if \no_rnd
+   .if \avg
+         vld1.8          {d7},     [r0,:64]
+         vrhadd.u8       d5,  d5,  d7
+   .endif
+   .ifeq \rnd
          vadd.u16        q10, q10, q11
- .endif
-         vst1.64         {d5},      [r0,:64], r2
-         \vshrn          d7,  q10, #2
+   .endif
+         vst1.64         {d5},     [r0,:64], r2
+         shrn            d7,  q10, #2
+   .if \avg
+         vld1.8          {d5},     [r0,:64]
+         vrhadd.u8       d7,  d7,  d5
+   .endif
          vext.8          d6,  d2,  d3,  #1
          vaddl.u8        q9,  d2,  d6
-         vst1.64         {d7},      [r0,:64], r2
+         vst1.64         {d7},     [r0,:64], r2
          bgt             1b
          bx              lr
        .endm
+ .endm
  
-         .macro pixfunc pfx name suf rnd_op args:vararg
+ .macro  pixfunc         pfx, name, suf, rnd=1, avg=0
+   .if \rnd
+     .macro avg  rd, rn, rm
+         vrhadd.u8       \rd, \rn, \rm
+     .endm
+     .macro shrn rd, rn, rm
+         vrshrn.u16      \rd, \rn, \rm
+     .endm
+   .else
+     .macro avg  rd, rn, rm
+         vhadd.u8        \rd, \rn, \rm
+     .endm
+     .macro shrn rd, rn, rm
+         vshrn.u16       \rd, \rn, \rm
+     .endm
+   .endif
  function ff_\pfx\name\suf\()_neon, export=1
-         \name \rnd_op \args
+         \name           \rnd, \avg
  endfunc
-         .endm
+         .purgem         avg
+         .purgem         shrn
+ .endm
  
-         .macro pixfunc2 pfx name args:vararg
-         pixfunc \pfx \name
-         pixfunc \pfx \name \args
        .endm
+ .macro  pixfunc2        pfx, name, avg=0
+         pixfunc         \pfx, \name,          rnd=1, avg=\avg
+         pixfunc         \pfx, \name, _no_rnd, rnd=0, avg=\avg
+ .endm
  
  function ff_put_h264_qpel16_mc00_neon, export=1
          mov             r3,  #16
  endfunc
  
-         pixfunc  put_ pixels16
-         pixfunc2 put_ pixels16_x2,  _no_rnd, vhadd.u8
-         pixfunc2 put_ pixels16_y2,  _no_rnd, vhadd.u8
-         pixfunc2 put_ pixels16_xy2, _no_rnd, vshrn.u16, 1
+         pixfunc         put_, pixels16,     avg=0
+         pixfunc2        put_, pixels16_x2,  avg=0
+         pixfunc2        put_, pixels16_y2,  avg=0
+         pixfunc2        put_, pixels16_xy2, avg=0
  
  function ff_avg_h264_qpel16_mc00_neon, export=1
          mov             r3,  #16
  endfunc
  
-         pixfunc  avg_ pixels16,, 1
+         pixfunc         avg_, pixels16,     avg=1
+         pixfunc2        avg_, pixels16_x2,  avg=1
+         pixfunc2        avg_, pixels16_y2,  avg=1
+         pixfunc2        avg_, pixels16_xy2, avg=1
  
  function ff_put_h264_qpel8_mc00_neon, export=1
          mov             r3,  #8
  endfunc
  
-         pixfunc  put_ pixels8
-         pixfunc2 put_ pixels8_x2,   _no_rnd, vhadd.u8
-         pixfunc2 put_ pixels8_y2,   _no_rnd, vhadd.u8
-         pixfunc2 put_ pixels8_xy2,  _no_rnd, vshrn.u16, 1
+         pixfunc         put_, pixels8,     avg=0
+         pixfunc2        put_, pixels8_x2,  avg=0
+         pixfunc2        put_, pixels8_y2,  avg=0
+         pixfunc2        put_, pixels8_xy2, avg=0
  
  function ff_avg_h264_qpel8_mc00_neon, export=1
          mov             r3,  #8
  endfunc
  
-         pixfunc  avg_ pixels8,, 1
+         pixfunc         avg_, pixels8,     avg=1
+         pixfunc2        avg_, pixels8_x2,  avg=1
+         pixfunc2        avg_, pixels8_y2,  avg=1
+         pixfunc2        avg_, pixels8_xy2, avg=1
  
  function ff_put_pixels_clamped_neon, export=1
          vld1.64         {d16-d19}, [r0,:128]!
diff --combined libavcodec/h264.c
index a08573e221627266abcb275612d8fa125052ae89,96062b780672c1655aeca60a6fc15504b5c9ba0b..3bc13aa2d460afd69bf8b7f0ce8323513756830e
@@@ -2,20 -2,20 +2,20 @@@
   * H.26L/H.264/AVC/JVT/14496-10/... decoder
   * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -26,7 -26,6 +26,7 @@@
   */
  
  #include "libavutil/imgutils.h"
 +#include "libavutil/opt.h"
  #include "internal.h"
  #include "dsputil.h"
  #include "avcodec.h"
@@@ -99,9 -98,12 +99,9 @@@ int ff_h264_check_intra4x4_pred_mode(H2
      }
  
      return 0;
 -} //FIXME cleanup like ff_h264_check_intra_pred_mode
 +} //FIXME cleanup like check_intra_pred_mode
  
 -/**
 - * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
 - */
 -int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
 +static int check_intra_pred_mode(H264Context *h, int mode, int is_chroma){
      MpegEncContext * const s = &h->s;
      static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1};
      static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8};
  
      if((h->left_samples_available&0x8080) != 0x8080){
          mode= left[ mode ];
 -        if(h->left_samples_available&0x8080){ //mad cow disease mode, aka MBAFF + constrained_intra_pred
 +        if(is_chroma && (h->left_samples_available&0x8080)){ //mad cow disease mode, aka MBAFF + constrained_intra_pred
              mode= ALZHEIMER_DC_L0T_PRED8x8 + (!(h->left_samples_available&0x8000)) + 2*(mode == DC_128_PRED8x8);
          }
          if(mode<0){
      return mode;
  }
  
 +/**
 + * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
 + */
 +int ff_h264_check_intra16x16_pred_mode(H264Context *h, int mode)
 +{
 +    return check_intra_pred_mode(h, mode, 0);
 +}
 +
 +/**
 + * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
 + */
 +int ff_h264_check_intra_chroma_pred_mode(H264Context *h, int mode)
 +{
 +    return check_intra_pred_mode(h, mode, 1);
 +}
 +
 +
  const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){
      int i, si, di;
      uint8_t *dst;
          i-= RS;
      }
  
 -    if(i>=length-1){ //no escaped 0
 -        *dst_length= length;
 -        *consumed= length+1; //+1 for the header
 -        return src;
 -    }
 -
      bufidx = h->nal_unit_type == NAL_DPC ? 1 : 0; // use second escape buffer for inter data
 -    av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE);
 +    si=h->rbsp_buffer_size[bufidx];
 +    av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE);
      dst= h->rbsp_buffer[bufidx];
 +    if(si != h->rbsp_buffer_size[bufidx])
 +        memset(dst + length, 0, FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE);
  
      if (dst == NULL){
          return NULL;
      }
  
 +    if(i>=length-1){ //no escaped 0
 +        *dst_length= length;
 +        *consumed= length+1; //+1 for the header
 +        if(h->s.avctx->flags2 & CODEC_FLAG2_FAST){
 +            return src;
 +        }else{
 +            memcpy(dst, src, length);
 +            return dst;
 +        }
 +    }
 +
  //printf("decoding esc\n");
      memcpy(dst, src, i);
      si=di=i;
@@@ -730,7 -707,7 +730,7 @@@ prefetch_motion(H264Context *h, int lis
              s->dsp.prefetch(src[1]+off, s->linesize, 4);
              s->dsp.prefetch(src[2]+off, s->linesize, 4);
          }else{
 -            off= ((mx>>1) << pixel_shift) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + (64 << pixel_shift);
 +            off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (s->mb_x&7))*s->uvlinesize;
              s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
          }
      }
@@@ -1052,38 -1029,29 +1052,38 @@@ static av_cold void common_init(H264Con
      s->height = s->avctx->height;
      s->codec_id= s->avctx->codec->id;
  
 -    ff_h264dsp_init(&h->h264dsp, 8, 1);
 -    ff_h264_pred_init(&h->hpc, s->codec_id, 8, 1);
 +    s->avctx->bits_per_raw_sample = 8;
 +    h->cur_chroma_format_idc = 1;
 +
 +    ff_h264dsp_init(&h->h264dsp,
 +                    s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc);
 +    ff_h264_pred_init(&h->hpc, s->codec_id,
 +                      s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc);
  
      h->dequant_coeff_pps= -1;
      s->unrestricted_mv=1;
  
 +    s->dsp.dct_bits = 16;
      dsputil_init(&s->dsp, s->avctx); // needed so that idct permutation is known early
  
      memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
      memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
  }
  
 -int ff_h264_decode_extradata(H264Context *h)
 +int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
  {
      AVCodecContext *avctx = h->s.avctx;
  
 -    if(avctx->extradata[0] == 1){
 +    if(!buf || size <= 0)
 +        return -1;
 +
 +    if(buf[0] == 1){
          int i, cnt, nalsize;
 -        unsigned char *p = avctx->extradata;
 +        const unsigned char *p = buf;
  
          h->is_avc = 1;
  
 -        if(avctx->extradata_size < 7) {
 +        if(size < 7) {
              av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
              return -1;
          }
          p += 6;
          for (i = 0; i < cnt; i++) {
              nalsize = AV_RB16(p) + 2;
 -            if (p - avctx->extradata + nalsize > avctx->extradata_size)
 +            if(nalsize > size - (p-buf))
                  return -1;
              if(decode_nal_units(h, p, nalsize) < 0) {
                  av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i);
          cnt = *(p++); // Number of pps
          for (i = 0; i < cnt; i++) {
              nalsize = AV_RB16(p) + 2;
 -            if (p - avctx->extradata + nalsize > avctx->extradata_size)
 +            if(nalsize > size - (p-buf))
                  return -1;
              if (decode_nal_units(h, p, nalsize) < 0) {
                  av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i);
              p += nalsize;
          }
          // Now store right nal length size, that will be use to parse all other nals
 -        h->nal_length_size = (avctx->extradata[4] & 0x03) + 1;
 +        h->nal_length_size = (buf[4] & 0x03) + 1;
      } else {
          h->is_avc = 0;
 -        if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0)
 +        if(decode_nal_units(h, buf, size) < 0)
              return -1;
      }
      return 0;
@@@ -1166,7 -1134,7 +1166,7 @@@ av_cold int ff_h264_decode_init(AVCodec
      }
  
      if(avctx->extradata_size > 0 && avctx->extradata &&
 -        ff_h264_decode_extradata(h))
 +        ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size))
          return -1;
  
      if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){
@@@ -1291,7 -1259,6 +1291,7 @@@ static int decode_update_thread_context
      copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1);
  
      h->last_slice_type = h1->last_slice_type;
 +    h->sync            = h1->sync;
  
      if(!s->current_picture_ptr) return 0;
  
@@@ -1471,33 -1438,14 +1471,33 @@@ static void decode_postinit(H264Contex
  
      if(   s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT
         && !h->sps.bitstream_restriction_flag){
-         s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT;
+         s->avctx->has_b_frames = MAX_DELAYED_PIC_COUNT - 1;
          s->low_delay= 0;
      }
  
 +    for (i = 0; 1; i++) {
 +        if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
 +            if(i)
 +                h->last_pocs[i-1] = cur->poc;
 +            break;
 +        } else if(i) {
 +            h->last_pocs[i-1]= h->last_pocs[i];
 +        }
 +    }
 +    out_of_order = MAX_DELAYED_PIC_COUNT - i;
 +    if(   cur->f.pict_type == AV_PICTURE_TYPE_B
 +       || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2))
 +        out_of_order = FFMAX(out_of_order, 1);
 +    if(s->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){
 +        av_log(s->avctx, AV_LOG_WARNING, "Increasing reorder buffer to %d\n", out_of_order);
 +        s->avctx->has_b_frames = out_of_order;
 +        s->low_delay = 0;
 +    }
 +
      pics = 0;
      while(h->delayed_pic[pics]) pics++;
  
 -    assert(pics <= MAX_DELAYED_PIC_COUNT);
 +    av_assert0(pics <= MAX_DELAYED_PIC_COUNT);
  
      h->delayed_pic[pics++] = cur;
      if (cur->f.reference == 0)
          h->next_outputed_poc= INT_MIN;
      out_of_order = out->poc < h->next_outputed_poc;
  
 -    if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
 -        { }
 -    else if (out_of_order && pics-1 == s->avctx->has_b_frames &&
 -             s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) {
 -        int cnt = 0, invalid = 0;
 -        for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) {
 -            cnt += out->poc < h->last_pocs[i];
 -            invalid += h->last_pocs[i] == INT_MIN;
 -        }
 -        if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
 -            s->avctx->has_b_frames = FFMAX(s->avctx->has_b_frames, cnt);
 -        } else if (cnt) {
 -            for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
 -                h->last_pocs[i] = INT_MIN;
 -        }
 -        s->low_delay = 0;
 -    } else if (s->low_delay &&
 -               ((h->next_outputed_poc != INT_MIN && out->poc > h->next_outputed_poc + 2) ||
 -                cur->f.pict_type == AV_PICTURE_TYPE_B)) {
 -        s->low_delay = 0;
 -        s->avctx->has_b_frames++;
 -    }
 -
      if(out_of_order || pics > s->avctx->has_b_frames){
          out->f.reference &= ~DELAYED_PIC_REF;
          out->owner2 = s; // for frame threading, the owner must be the second field's thread
          for(i=out_idx; h->delayed_pic[i]; i++)
              h->delayed_pic[i] = h->delayed_pic[i+1];
      }
 -    memmove(h->last_pocs, &h->last_pocs[1], sizeof(*h->last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
 -    h->last_pocs[MAX_DELAYED_PIC_COUNT - 1] = out->poc;
      if(!out_of_order && pics > s->avctx->has_b_frames){
          h->next_output_pic = out;
          if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) {
          av_log(s->avctx, AV_LOG_DEBUG, "no picture\n");
      }
  
 +    if (h->next_output_pic && h->next_output_pic->sync) {
 +        h->sync |= 2;
 +    }
 +
      if (setup_finished)
          ff_thread_finish_setup(s->avctx);
  }
@@@ -1572,7 -1541,7 +1572,7 @@@ static av_always_inline void backup_mb_
                              AV_COPY128(top_border+16, src_cb + 15*uvlinesize);
                              AV_COPY128(top_border+32, src_cr + 15*uvlinesize);
                          }
 -                    } else if(chroma422) {
 +                    } else if(chroma422){
                          if (pixel_shift) {
                              AV_COPY128(top_border+32, src_cb + 15*uvlinesize);
                              AV_COPY128(top_border+48, src_cr + 15*uvlinesize);
@@@ -1947,8 -1916,8 +1947,8 @@@ static av_always_inline void hl_decode_
      }
  
      if (!simple && IS_INTRA_PCM(mb_type)) {
 +        const int bit_depth = h->sps.bit_depth_luma;
          if (pixel_shift) {
 -            const int bit_depth = h->sps.bit_depth_luma;
              int j;
              GetBitContext gb;
              init_get_bits(&gb, (uint8_t*)h->mb, 384*bit_depth);
                  if (!h->sps.chroma_format_idc) {
                      for (i = 0; i < block_h; i++) {
                          uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
 -                        for (j = 0; j < 8; j++) {
 -                            tmp_cb[j] = 1 << (bit_depth - 1);
 -                        }
 -                    }
 -                    for (i = 0; i < block_h; i++) {
                          uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
                          for (j = 0; j < 8; j++) {
 -                            tmp_cr[j] = 1 << (bit_depth - 1);
 +                            tmp_cb[j] = tmp_cr[j] = 1 << (bit_depth - 1);
                          }
                      }
                  } else {
              }
              if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                  if (!h->sps.chroma_format_idc) {
 -                    for (i = 0; i < block_h; i++) {
 -                        memset(dest_cb + i*uvlinesize, 128, 8);
 -                        memset(dest_cr + i*uvlinesize, 128, 8);
 +                    for (i=0; i<8; i++) {
 +                        memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8);
 +                        memset(dest_cr + i*uvlinesize, 1 << (bit_depth - 1), 8);
                      }
                  } else {
 -                    for (i = 0; i < block_h; i++) {
 +                    for (i=0; i<block_h; i++) {
                          memcpy(dest_cb + i*uvlinesize, h->mb + 128 + i*4,  8);
                          memcpy(dest_cr + i*uvlinesize, h->mb + 160 + i*4,  8);
                      }
                      h->h264dsp.h264_idct_add8(dest, block_offset,
                                                h->mb, uvlinesize,
                                                h->non_zero_count_cache);
 -                }else{
 +                }
 +#if CONFIG_SVQ3_DECODER
 +                else{
                      h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*1, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);
                      h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*2, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);
                      for(j=1; j<3; j++){
                          }
                      }
                  }
 +#endif
              }
          }
      }
@@@ -2366,21 -2337,18 +2366,21 @@@ static void implicit_weight_table(H264C
   * instantaneous decoder refresh.
   */
  static void idr(H264Context *h){
 +    int i;
      ff_h264_remove_all_refs(h);
 -    h->prev_frame_num= 0;
 +    h->prev_frame_num= -1;
      h->prev_frame_num_offset= 0;
      h->prev_poc_msb=
      h->prev_poc_lsb= 0;
 +    for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
 +        h->last_pocs[i] = INT_MIN;
  }
  
  /* forget old pics after a seek */
  static void flush_dpb(AVCodecContext *avctx){
      H264Context *h= avctx->priv_data;
      int i;
 -    for(i=0; i<MAX_DELAYED_PIC_COUNT; i++) {
 +    for(i=0; i<=MAX_DELAYED_PIC_COUNT; i++) {
          if(h->delayed_pic[i])
              h->delayed_pic[i]->f.reference = 0;
          h->delayed_pic[i]= NULL;
      h->s.first_field= 0;
      ff_h264_reset_sei(h);
      ff_mpeg_flush(avctx);
 +    h->recovery_frame= -1;
 +    h->sync= 0;
  }
  
  static int init_poc(H264Context *h){
@@@ -2649,7 -2615,7 +2649,7 @@@ static int decode_slice_header(H264Cont
          s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;
      }
  
 -    first_mb_in_slice= get_ue_golomb(&s->gb);
 +    first_mb_in_slice= get_ue_golomb_long(&s->gb);
  
      if(first_mb_in_slice == 0){ //FIXME better field boundary detection
          if(h0->current_slice && FIELD_PICTURE){
  
      s->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p
  
 -    s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);
 -    if(h->sps.frame_mbs_only_flag)
 -        s->height= 16*s->mb_height - (1<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);
 -    else
 -        s->height= 16*s->mb_height - (2<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);
 +    s->width = 16*s->mb_width;
 +    s->height= 16*s->mb_height;
  
      if (s->context_initialized
 -        && (   s->width != s->avctx->width || s->height != s->avctx->height
 +        && (   s->width != s->avctx->coded_width || s->height != s->avctx->coded_height
 +            || s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma
 +            || h->cur_chroma_format_idc != h->sps.chroma_format_idc
              || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {
          if(h != h0) {
 -            av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);
 +            av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0);
              return -1;   // width / height changed during parallelized decoding
          }
          free_tables(h, 0);
          flush_dpb(s->avctx);
          MPV_common_end(s);
 +        h->list_count = 0;
      }
      if (!s->context_initialized) {
          if (h != h0) {
              av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n");
              return -1;
          }
 -
          avcodec_set_dimensions(s->avctx, s->width, s->height);
 +        s->avctx->width  -= (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);
 +        s->avctx->height -= (1<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1) * (2 - h->sps.frame_mbs_only_flag);
          s->avctx->sample_aspect_ratio= h->sps.sar;
          av_assert0(s->avctx->sample_aspect_ratio.den);
  
 +        if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||
 +            h->cur_chroma_format_idc != h->sps.chroma_format_idc) {
 +            if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10 &&
 +                (h->sps.bit_depth_luma != 9 || !CHROMA422)) {
 +                s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
 +                h->cur_chroma_format_idc = h->sps.chroma_format_idc;
 +                h->pixel_shift = h->sps.bit_depth_luma > 8;
 +
 +                ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
 +                ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
 +                s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;
 +                dsputil_init(&s->dsp, s->avctx);
 +            } else {
 +                av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d chroma_idc: %d\n",
 +                       h->sps.bit_depth_luma, h->sps.chroma_format_idc);
 +                return -1;
 +            }
 +        }
 +
          if(h->sps.video_signal_type_present_flag){
 -            s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
 +            s->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
              if(h->sps.colour_description_present_flag){
                  s->avctx->color_primaries = h->sps.color_primaries;
                  s->avctx->color_trc       = h->sps.color_trc;
                  break;
              default:
                  if (CHROMA444){
 +                    s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
                      if (s->avctx->colorspace == AVCOL_SPC_RGB) {
 -                        s->avctx->pix_fmt = PIX_FMT_GBRP;
 -                    } else
 -                        s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
 +                       s->avctx->pix_fmt = PIX_FMT_GBR24P;
 +                       av_log(h->s.avctx, AV_LOG_DEBUG, "Detected GBR colorspace.\n");
 +                    } else if (s->avctx->colorspace == AVCOL_SPC_YCGCO) {
 +                        av_log(h->s.avctx, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n");
 +                    }
                  } else if (CHROMA422) {
                      s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P : PIX_FMT_YUV422P;
                  }else{
                  c->sps = h->sps;
                  c->pps = h->pps;
                  c->pixel_shift = h->pixel_shift;
 +                c->cur_chroma_format_idc = h->cur_chroma_format_idc;
                  init_scan_tables(c);
                  clone_tables(c, h, i);
              }
      if(h->sps.frame_mbs_only_flag){
          s->picture_structure= PICT_FRAME;
      }else{
 +        if(!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B){
 +            av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
 +            return -1;
 +        }
          if(get_bits1(&s->gb)) { //field_pic_flag
              s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
          } else {
  
      if(h0->current_slice == 0){
          // Shorten frame num gaps so we don't have to allocate reference frames just to throw them away
 -        if(h->frame_num != h->prev_frame_num) {
 +        if(h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0) {
              int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;
  
              if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;
              }
          }
  
 -        while(h->frame_num !=  h->prev_frame_num &&
 +        while(h->frame_num !=  h->prev_frame_num && h->prev_frame_num >= 0 &&
                h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){
              Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
              av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num);
                  s0->first_field = FIELD_PICTURE;
  
              } else {
 -                if (h->nal_ref_idc &&
 -                        s0->current_picture_ptr->f.reference &&
 -                        s0->current_picture_ptr->frame_num != h->frame_num) {
 +                if (s0->current_picture_ptr->frame_num != h->frame_num) {
                      /*
 -                     * This and previous field were reference, but had
 +                     * This and previous field had
                       * different frame_nums. Consider this field first in
                       * pair. Throw away previous field except for reference
                       * purposes.
      h->ref_count[1]= h->pps.ref_count[1];
  
      if(h->slice_type_nos != AV_PICTURE_TYPE_I){
 +        unsigned max= (16<<(s->picture_structure != PICT_FRAME))-1;
          if(h->slice_type_nos == AV_PICTURE_TYPE_B){
              h->direct_spatial_mv_pred= get_bits1(&s->gb);
          }
              if(h->slice_type_nos==AV_PICTURE_TYPE_B)
                  h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
  
 -            if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){
 -                av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
 -                h->ref_count[0]= h->ref_count[1]= 1;
 -                return -1;
 -            }
 +        }
 +        if(h->ref_count[0]-1 > max || h->ref_count[1]-1 > max){
 +            av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
 +            h->ref_count[0]= h->ref_count[1]= 1;
 +            return -1;
          }
          if(h->slice_type_nos == AV_PICTURE_TYPE_B)
              h->list_count= 2;
          else
              h->list_count= 1;
      }else
 -        h->list_count= 0;
 +        h->ref_count[1]= h->ref_count[0]= h->list_count= 0;
  
      if(!default_ref_list_done){
          ff_h264_fill_default_ref_list(h);
  
      h0->last_slice_type = slice_type;
      h->slice_num = ++h0->current_slice;
 -    if(h->slice_num >= MAX_SLICES){
 -        av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n");
 +
 +    if(h->slice_num)
 +        h0->slice_row[(h->slice_num-1)&(MAX_SLICES-1)]= s->resync_mb_y;
 +    if (   h0->slice_row[h->slice_num&(MAX_SLICES-1)] + 3 >= s->resync_mb_y
 +        && h0->slice_row[h->slice_num&(MAX_SLICES-1)] <= s->resync_mb_y
 +        && h->slice_num >= MAX_SLICES) {
 +        //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case
 +        av_log(s->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", h->slice_num, MAX_SLICES);
      }
  
      for(j=0; j<2; j++){
@@@ -3690,8 -3623,7 +3690,8 @@@ static int decode_slice(struct AVCodecC
                  if(s->mb_y >= s->mb_height){
                      tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
  
 -                    if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
 +                    if(   get_bits_count(&s->gb) == s->gb.size_in_bits
 +                       || get_bits_count(&s->gb) <  s->gb.size_in_bits && s->avctx->error_recognition < FF_ER_AGGRESSIVE) {
                          ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
  
                          return 0;
@@@ -3741,7 -3673,6 +3741,7 @@@ static int execute_decode_slices(H264Co
              hx = h->thread_context[i];
              hx->s.error_recognition = avctx->error_recognition;
              hx->s.error_count = 0;
 +            hx->x264_build= h->x264_build;
          }
  
          avctx->execute(avctx, (void *)decode_slice,
@@@ -3829,13 -3760,13 +3829,13 @@@ static int decode_nal_units(H264Contex
              s->workaround_bugs |= FF_BUG_TRUNCATED;
  
          if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){
 -        while(ptr[dst_length - 1] == 0 && dst_length > 0)
 +        while(dst_length > 0 && ptr[dst_length - 1] == 0)
              dst_length--;
          }
          bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));
  
          if(s->avctx->debug&FF_DEBUG_STARTCODE){
 -            av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length);
 +            av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length);
          }
  
          if (h->is_avc && (nalsize != consumed) && nalsize){
              if((err = decode_slice_header(hx, h)))
                 break;
  
 +            if (   h->sei_recovery_frame_cnt >= 0
 +                && ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt) {
 +                h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %
 +                                    (1 << h->sps.log2_max_frame_num);
 +            }
 +
              s->current_picture_ptr->f.key_frame |=
 -                    (hx->nal_unit_type == NAL_IDR_SLICE) ||
 -                    (h->sei_recovery_frame_cnt >= 0);
 +                    (hx->nal_unit_type == NAL_IDR_SLICE);
 +
 +            if (h->recovery_frame == h->frame_num) {
 +                h->sync |= 1;
 +                h->recovery_frame = -1;
 +            }
 +
 +            h->sync |= !!s->current_picture_ptr->f.key_frame;
 +            h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL);
 +            s->current_picture_ptr->sync = h->sync;
  
              if (h->current_slice == 1) {
                  if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) {
              break;
          case NAL_SPS:
              init_get_bits(&s->gb, ptr, bit_length);
 -            ff_h264_decode_seq_parameter_set(h);
 +            if(ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? (nalsize != consumed) && nalsize : 1)){
 +                av_log(h->s.avctx, AV_LOG_DEBUG, "SPS decoding failure, trying alternative mode\n");
 +                if(h->is_avc) av_assert0(next_avc - buf_index + consumed == nalsize);
 +                init_get_bits(&s->gb, &buf[buf_index + 1 - consumed], 8*(next_avc - buf_index + consumed));
 +                ff_h264_decode_seq_parameter_set(h);
 +            }
  
              if (s->flags& CODEC_FLAG_LOW_DELAY ||
                  (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))
  
              if(avctx->has_b_frames < 2)
                  avctx->has_b_frames= !s->low_delay;
 -
 -            if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||
 -                h->cur_chroma_format_idc != h->sps.chroma_format_idc) {
 -                if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {
 -                    avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
 -                    h->cur_chroma_format_idc = h->sps.chroma_format_idc;
 -                    h->pixel_shift = h->sps.bit_depth_luma > 8;
 -
 -                    ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
 -                    ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
 -                    s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;
 -                    dsputil_init(&s->dsp, s->avctx);
 -                } else {
 -                    av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", h->sps.bit_depth_luma);
 -                    return -1;
 -                }
 -            }
              break;
          case NAL_PPS:
              init_get_bits(&s->gb, ptr, bit_length);
@@@ -4070,8 -3999,6 +4070,8 @@@ static int decode_frame(AVCodecContext 
  
          return 0;
      }
 +    if(h->is_avc && buf_size >= 9 && AV_RB32(buf)==0x0164001F && buf[5] && buf[8]==0x67)
 +        return ff_h264_decode_extradata(h, buf, buf_size);
  
      buf_index=decode_nal_units(h, buf, buf_size);
      if(buf_index < 0)
  
          field_end(h, 0);
  
 -        if (!h->next_output_pic) {
 -            /* Wait for second field. */
 -            *data_size = 0;
 -
 -        } else {
 -            *data_size = sizeof(AVFrame);
 -            *pict = *(AVFrame*)h->next_output_pic;
 +        *data_size = 0; /* Wait for second field. */
 +        if (h->next_output_pic && h->next_output_pic->sync) {
 +            if(h->sync>1 || h->next_output_pic->f.pict_type != AV_PICTURE_TYPE_B){
 +                *data_size = sizeof(AVFrame);
 +                *pict = *(AVFrame*)h->next_output_pic;
 +            }
          }
      }
  
@@@ -4135,7 -4063,6 +4135,7 @@@ static inline void fill_mb_avail(H264Co
  #undef random
  #define COUNT 8000
  #define SIZE (COUNT*40)
 +extern AVCodec ff_h264_decoder;
  int main(void){
      int i;
      uint8_t temp[SIZE];
      DSPContext dsp;
      AVCodecContext avctx;
  
 +    avcodec_get_context_defaults3(&avctx, &ff_h264_decoder);
 +
      dsputil_init(&dsp, &avctx);
  
      init_put_bits(&pb, temp, SIZE);
@@@ -4250,26 -4175,6 +4250,26 @@@ static const AVProfile profiles[] = 
      { FF_PROFILE_UNKNOWN },
  };
  
 +static const AVOption h264_options[] = {
 +    {"is_avc", "is avc", offsetof(H264Context, is_avc), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, 0},
 +    {"nal_length_size", "nal_length_size", offsetof(H264Context, nal_length_size), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 4, 0},
 +    {NULL}
 +};
 +
 +static const AVClass h264_class = {
 +    "H264 Decoder",
 +    av_default_item_name,
 +    h264_options,
 +    LIBAVUTIL_VERSION_INT,
 +};
 +
 +static const AVClass h264_vdpau_class = {
 +    "H264 VDPAU Decoder",
 +    av_default_item_name,
 +    h264_options,
 +    LIBAVUTIL_VERSION_INT,
 +};
 +
  AVCodec ff_h264_decoder = {
      .name           = "h264",
      .type           = AVMEDIA_TYPE_VIDEO,
      .init_thread_copy      = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
      .update_thread_context = ONLY_IF_THREADS_ENABLED(decode_update_thread_context),
      .profiles = NULL_IF_CONFIG_SMALL(profiles),
 +    .priv_class     = &h264_class,
  };
  
  #if CONFIG_H264_VDPAU_DECODER
@@@ -4302,6 -4206,5 +4302,6 @@@ AVCodec ff_h264_vdpau_decoder = 
      .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
      .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
      .profiles = NULL_IF_CONFIG_SMALL(profiles),
 +    .priv_class     = &h264_vdpau_class,
  };
  #endif
diff --combined libavcodec/rv34.c
index 2e2de85044ffdb21c450f012f1ab9f9548194978,295a633f383d65972680105bdd24d8bcf5adde86..15a5c5430f6fdf0f99b5945a188bd8870ca44add
@@@ -2,20 -2,20 +2,20 @@@
   * RV30/40 decoder common data
   * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -1112,7 -1112,7 +1112,7 @@@ static int rv34_decode_macroblock(RV34D
      GetBitContext *gb = &s->gb;
      int cbp, cbp2;
      int i, blknum, blkoff;
-     DCTELEM block16[64];
+     LOCAL_ALIGNED_16(DCTELEM, block16, [64]);
      int luma_dc_quant;
      int dist;
      int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
  
      luma_dc_quant = r->block_type == RV34_MB_P_MIX16x16 ? r->luma_dc_quant_p[s->qscale] : r->luma_dc_quant_i[s->qscale];
      if(r->is16){
-         memset(block16, 0, sizeof(block16));
+         memset(block16, 0, 64 * sizeof(*block16));
          rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0);
          rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]);
          r->rdsp.rv34_inv_transform_tab[1](block16);
@@@ -1267,10 -1267,6 +1267,10 @@@ static int rv34_decode_slice(RV34DecCon
              av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
              return AVERROR_INVALIDDATA;
          }
 +        if (s->width != r->si.width || s->height != r->si.height) {
 +            av_log(s->avctx, AV_LOG_ERROR, "Size mismatch\n");
 +            return AVERROR_INVALIDDATA;
 +        }
      }
  
      r->si.end = end;
index 8218c0e05f195cb8c500c7db177c106a98b85155,2b157095f030bf72d085e8103feaac59343ea071..8295ccc5f5ea6a0615512aa2d88ddd99270f59cf
@@@ -2,20 -2,20 +2,20 @@@
   * Apple HTTP Live Streaming Protocol Handler
   * Copyright (c) 2010 Martin Storsjo
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -124,7 -124,7 +124,7 @@@ static int parse_playlist(URLContext *h
  
      free_segment_list(s);
      s->finished = 0;
 -    while (!in->eof_reached) {
 +    while (!url_feof(in)) {
          read_chomp_line(in, line, sizeof(line));
          if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
              struct variant_info info = {{0}};
@@@ -174,19 -174,25 +174,25 @@@ fail
      return ret;
  }
  
+ static int applehttp_close(URLContext *h)
+ {
+     AppleHTTPContext *s = h->priv_data;
+     free_segment_list(s);
+     free_variant_list(s);
+     ffurl_close(s->seg_hd);
+     return 0;
+ }
  static int applehttp_open(URLContext *h, const char *uri, int flags)
  {
-     AppleHTTPContext *s;
+     AppleHTTPContext *s = h->priv_data;
      int ret, i;
      const char *nested_url;
  
      if (flags & AVIO_FLAG_WRITE)
          return AVERROR(ENOSYS);
  
-     s = av_mallocz(sizeof(AppleHTTPContext));
-     if (!s)
-         return AVERROR(ENOMEM);
-     h->priv_data = s;
      h->is_streamed = 1;
  
      if (av_strstart(uri, "applehttp+", &nested_url)) {
      return 0;
  
  fail:
-     av_free(s);
+     applehttp_close(h);
      return ret;
  }
  
@@@ -287,21 -293,11 +293,11 @@@ retry
      goto start;
  }
  
- static int applehttp_close(URLContext *h)
- {
-     AppleHTTPContext *s = h->priv_data;
-     free_segment_list(s);
-     free_variant_list(s);
-     ffurl_close(s->seg_hd);
-     av_free(s);
-     return 0;
- }
  URLProtocol ff_applehttp_protocol = {
-     .name      = "applehttp",
-     .url_open  = applehttp_open,
-     .url_read  = applehttp_read,
-     .url_close = applehttp_close,
-     .flags     = URL_PROTOCOL_FLAG_NESTED_SCHEME,
+     .name           = "applehttp",
+     .url_open       = applehttp_open,
+     .url_read       = applehttp_read,
+     .url_close      = applehttp_close,
+     .flags          = URL_PROTOCOL_FLAG_NESTED_SCHEME,
+     .priv_data_size = sizeof(AppleHTTPContext),
  };
diff --combined libavformat/cache.c
index c2bddf5f6d5a826784788a6c9358d68e7e87519a,0000000000000000000000000000000000000000..d94cf5fbaca071262d0bf02a0b181e14b38404e1
mode 100644,000000..100644
--- /dev/null
@@@ -1,144 -1,0 +1,137 @@@
-     Context *c;
-     c = av_mallocz(sizeof(Context));
-     if (!c) {
-         return AVERROR(ENOMEM);
-     }
-     h->priv_data = c;
 +/*
 + * Input cache protocol.
 + * Copyright (c) 2011 Michael Niedermayer
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 + *
 + * Based on file.c by Fabrice Bellard
 + */
 +
 +/**
 + * @TODO
 + *      support non continuous caching
 + *      support keeping files
 + *      support filling with a background thread
 + */
 +
 +#include "libavutil/avassert.h"
 +#include "libavutil/avstring.h"
 +#include "libavutil/file.h"
 +#include "avformat.h"
 +#include <fcntl.h>
 +#if HAVE_SETMODE
 +#include <io.h>
 +#endif
 +#include <unistd.h>
 +#include <sys/stat.h>
 +#include <stdlib.h>
 +#include "os_support.h"
 +#include "url.h"
 +
 +typedef struct Context {
 +    int fd;
 +    int64_t end;
 +    int64_t pos;
 +    URLContext *inner;
 +} Context;
 +
 +static int cache_open(URLContext *h, const char *arg, int flags)
 +{
 +    int access;
 +    const char *buffername;
-     av_freep(&h->priv_data);
++    Context *c= h->priv_data;
 +
 +    av_strstart(arg, "cache:", &arg);
 +
 +    c->fd = av_tempfile("ffcache", &buffername, 0, h);
 +    if (c->fd < 0){
 +        av_log(h, AV_LOG_ERROR, "Failed to create tempfile\n");
 +        return c->fd;
 +    }
 +
 +    unlink(buffername);
 +    av_free(buffername);
 +
 +    return ffurl_open(&c->inner, arg, flags, &h->interrupt_callback, NULL);
 +}
 +
 +static int cache_read(URLContext *h, unsigned char *buf, int size)
 +{
 +    Context *c= h->priv_data;
 +    int r;
 +
 +    if(c->pos<c->end){
 +        r = read(c->fd, buf, FFMIN(size, c->end - c->pos));
 +        if(r>0)
 +            c->pos += r;
 +        return (-1 == r)?AVERROR(errno):r;
 +    }else{
 +        r = ffurl_read(c->inner, buf, size);
 +        if(r > 0){
 +            int r2= write(c->fd, buf, r);
 +            av_assert0(r2==r); // FIXME handle cache failure
 +            c->pos += r;
 +            c->end += r;
 +        }
 +        return r;
 +    }
 +}
 +
 +static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
 +{
 +    Context *c= h->priv_data;
 +
 +    if (whence == AVSEEK_SIZE) {
 +        pos= ffurl_seek(c->inner, pos, whence);
 +        if(pos <= 0){
 +            pos= ffurl_seek(c->inner, -1, SEEK_END);
 +            ffurl_seek(c->inner, c->end, SEEK_SET);
 +            if(pos <= 0)
 +                return c->end;
 +        }
 +        return pos;
 +    }
 +
 +    pos= lseek(c->fd, pos, whence);
 +    if(pos<0){
 +        return pos;
 +    }else if(pos <= c->end){
 +        c->pos= pos;
 +        return pos;
 +    }else{
 +        lseek(c->fd, c->pos, SEEK_SET);
 +        return AVERROR(EPIPE);
 +    }
 +}
 +
 +static int cache_close(URLContext *h)
 +{
 +    Context *c= h->priv_data;
 +    close(c->fd);
 +    ffurl_close(c->inner);
 +
 +    return 0;
 +}
 +
 +URLProtocol ff_cache_protocol = {
 +    .name                = "cache",
 +    .url_open            = cache_open,
 +    .url_read            = cache_read,
 +    .url_seek            = cache_seek,
 +    .url_close           = cache_close,
++    .priv_data_size      = sizeof(Context),
 +};
diff --combined libavformat/concat.c
index 81f37383b9ff5efdeb2f8b72b3960539b8e3dac0,24c50c1e4ea4b7fefa036d935f330b0b933e6adb..f97354c7884514fbf604ceacf456c9d79e1d89e9
@@@ -4,20 -4,20 +4,20 @@@
   * Copyright (c) 2007 Wolfram Gloger
   * Copyright (c) 2010 Michele Orrù
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -50,7 -50,6 +50,6 @@@ static av_cold int concat_close(URLCont
          err |= ffurl_close(nodes[i].uc);
  
      av_freep(&data->nodes);
-     av_freep(&h->priv_data);
  
      return err < 0 ? -1 : 0;
  }
@@@ -62,16 -61,11 +61,11 @@@ static av_cold int concat_open(URLConte
      int64_t size;
      size_t  len, i;
      URLContext *uc;
-     struct concat_data  *data;
+     struct concat_data  *data = h->priv_data;
      struct concat_nodes *nodes;
  
      av_strstart(uri, "concat:", &uri);
  
-     /* creating data */
-     if (!(data = av_mallocz(sizeof(*data))))
-         return AVERROR(ENOMEM);
-     h->priv_data = data;
      for (i = 0, len = 1; uri[i]; i++)
          if (uri[i] == *AV_CAT_SEPARATOR)
              /* integer overflow */
@@@ -81,7 -75,6 +75,6 @@@
              }
  
      if (!(nodes = av_malloc(sizeof(*nodes) * len))) {
-         av_freep(&h->priv_data);
          return AVERROR(ENOMEM);
      } else
          data->nodes = nodes;
@@@ -191,9 -184,10 +184,10 @@@ static int64_t concat_seek(URLContext *
  }
  
  URLProtocol ff_concat_protocol = {
-     .name      = "concat",
-     .url_open  = concat_open,
-     .url_read  = concat_read,
-     .url_seek  = concat_seek,
-     .url_close = concat_close,
+     .name           = "concat",
+     .url_open       = concat_open,
+     .url_read       = concat_read,
+     .url_seek       = concat_seek,
+     .url_close      = concat_close,
+     .priv_data_size = sizeof(struct concat_data),
  };
diff --combined libavformat/gopher.c
index 6a829c8ce5e603c28f0a0bbff930577edf44904c,c0338619b3e728e80443d3a9600d05230ff1835d..e1acf5039c23174f91baa9933a7c80724e628f68
@@@ -5,20 -5,20 +5,20 @@@
   *
   * based on libavformat/http.c, Copyright (c) 2000, 2001 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -72,24 -72,17 +72,17 @@@ static int gopher_close(URLContext *h
          ffurl_close(s->hd);
          s->hd = NULL;
      }
-     av_freep(&h->priv_data);
      return 0;
  }
  
  static int gopher_open(URLContext *h, const char *uri, int flags)
  {
-     GopherContext *s;
+     GopherContext *s = h->priv_data;
      char hostname[1024], auth[1024], path[1024], buf[1024];
      int port, err;
  
      h->is_streamed = 1;
  
-     s = av_malloc(sizeof(GopherContext));
-     if (!s) {
-         return AVERROR(ENOMEM);
-     }
-     h->priv_data = s;
      /* needed in any case to build the host string */
      av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
                   path, sizeof(path), uri);
@@@ -122,9 -115,10 +115,10 @@@ static int gopher_read(URLContext *h, u
  
  
  URLProtocol ff_gopher_protocol = {
-     .name      = "gopher",
-     .url_open  = gopher_open,
-     .url_read  = gopher_read,
-     .url_write = gopher_write,
-     .url_close = gopher_close,
+     .name           = "gopher",
+     .url_open       = gopher_open,
+     .url_read       = gopher_read,
+     .url_write      = gopher_write,
+     .url_close      = gopher_close,
+     .priv_data_size = sizeof(GopherContext),
  };
diff --combined libavformat/http.c
index 2e4e8c235dd2b9b90b397dbe30219230c78dfaf8,a9b4d5a57344520475e547f35950d4efbeac5e24..f7e0b5cc8ca200bbacb8354c320fac2f8dbf3c52
@@@ -1,21 -1,21 +1,21 @@@
  /*
 - * HTTP protocol for avconv client
 + * HTTP protocol for ffmpeg client
   * Copyright (c) 2000, 2001 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -30,7 -30,7 +30,7 @@@
  #include "url.h"
  #include "libavutil/opt.h"
  
 -/* XXX: POST protocol is not completely implemented because avconv uses
 +/* XXX: POST protocol is not completely implemented because ffmpeg uses
     only a subset of it. */
  
  /* used for protocol handling */
@@@ -44,7 -44,6 +44,7 @@@ typedef struct 
      int line_count;
      int http_code;
      int64_t chunksize;      /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
 +    char *user_agent;
      int64_t off, filesize;
      char location[MAX_URL_SIZE];
      HTTPAuthState auth_state;
  #define OFFSET(x) offsetof(HTTPContext, x)
  #define D AV_OPT_FLAG_DECODING_PARAM
  #define E AV_OPT_FLAG_ENCODING_PARAM
 +#define DEC AV_OPT_FLAG_DECODING_PARAM
  static const AVOption options[] = {
  {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, E },
  {"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
 +{"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
  {NULL}
  };
  #define HTTP_CLASS(flavor)\
@@@ -93,7 -90,7 +93,7 @@@ static int http_open_cnx(URLContext *h
  {
      const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
      char hostname[1024], hoststr[1024], proto[10];
-     char auth[1024], proxyauth[1024];
+     char auth[1024], proxyauth[1024] = "";
      char path1[1024];
      char buf[1024], urlbuf[1024];
      int port, use_proxy, err, location_changed = 0, redirects = 0;
@@@ -345,9 -342,8 +345,9 @@@ static int http_connect(URLContext *h, 
  
      /* set default headers if needed */
      if (!has_header(s->headers, "\r\nUser-Agent: "))
 -       len += av_strlcatf(headers + len, sizeof(headers) - len,
 -                          "User-Agent: %s\r\n", LIBAVFORMAT_IDENT);
 +        len += av_strlcatf(headers + len, sizeof(headers) - len,
 +                           "User-Agent: %s\r\n",
 +                           s->user_agent ? s->user_agent : LIBAVFORMAT_IDENT);
      if (!has_header(s->headers, "\r\nAccept: "))
          len += av_strlcpy(headers + len, "Accept: */*\r\n",
                            sizeof(headers) - len);
diff --combined libavformat/librtmp.c
index 01b6c3deb01ae111986da0a6dca6f3674df973f7,c04c833c01b673c0cf304d3f9235b856f9a9b76f..018ea0f4b0c19d8da6ffeaa6b72516d8330161ae
@@@ -2,20 -2,20 +2,20 @@@
   * RTMP network protocol
   * Copyright (c) 2010 Howard Chu
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -52,7 -52,6 +52,6 @@@ static int rtmp_close(URLContext *s
      RTMP *r = s->priv_data;
  
      RTMP_Close(r);
-     av_free(r);
      return 0;
  }
  
   */
  static int rtmp_open(URLContext *s, const char *uri, int flags)
  {
-     RTMP *r;
+     RTMP *r = s->priv_data;
      int rc;
  
-     r = av_mallocz(sizeof(RTMP));
-     if (!r)
-         return AVERROR(ENOMEM);
      switch (av_log_get_level()) {
      default:
      case AV_LOG_FATAL:   rc = RTMP_LOGCRIT;    break;
          goto fail;
      }
  
-     s->priv_data   = r;
      s->is_streamed = 1;
      return 0;
  fail:
-     av_free(r);
      return rc;
  }
  
@@@ -167,7 -160,8 +160,8 @@@ URLProtocol ff_rtmp_protocol = 
      .url_close           = rtmp_close,
      .url_read_pause      = rtmp_read_pause,
      .url_read_seek       = rtmp_read_seek,
-     .url_get_file_handle = rtmp_get_file_handle
+     .url_get_file_handle = rtmp_get_file_handle,
+     .priv_data_size      = sizeof(RTMP),
  };
  
  URLProtocol ff_rtmpt_protocol = {
      .url_close           = rtmp_close,
      .url_read_pause      = rtmp_read_pause,
      .url_read_seek       = rtmp_read_seek,
-     .url_get_file_handle = rtmp_get_file_handle
+     .url_get_file_handle = rtmp_get_file_handle,
+     .priv_data_size      = sizeof(RTMP),
  };
  
  URLProtocol ff_rtmpe_protocol = {
      .url_close           = rtmp_close,
      .url_read_pause      = rtmp_read_pause,
      .url_read_seek       = rtmp_read_seek,
-     .url_get_file_handle = rtmp_get_file_handle
+     .url_get_file_handle = rtmp_get_file_handle,
+     .priv_data_size      = sizeof(RTMP),
  };
  
  URLProtocol ff_rtmpte_protocol = {
      .url_close           = rtmp_close,
      .url_read_pause      = rtmp_read_pause,
      .url_read_seek       = rtmp_read_seek,
-     .url_get_file_handle = rtmp_get_file_handle
+     .url_get_file_handle = rtmp_get_file_handle,
+     .priv_data_size      = sizeof(RTMP),
  };
  
  URLProtocol ff_rtmps_protocol = {
      .url_close           = rtmp_close,
      .url_read_pause      = rtmp_read_pause,
      .url_read_seek       = rtmp_read_seek,
-     .url_get_file_handle = rtmp_get_file_handle
+     .url_get_file_handle = rtmp_get_file_handle,
+     .priv_data_size      = sizeof(RTMP),
  };
diff --combined libavformat/md5proto.c
index 05ee9d366a1a0cf741765b6c7aa1684b83d476e9,796b4ea6826e6f48a62abfa980de3ddc63752e02..f7c8b78fee69ed9fb58bc3068b48a172824456c7
@@@ -1,20 -1,20 +1,20 @@@
  /*
   * Copyright (c) 2010 Mans Rullgard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -79,16 -79,11 +79,11 @@@ static int md5_close(URLContext *h
      return err;
  }
  
- static int md5_get_handle(URLContext *h)
- {
-     return (intptr_t)h->priv_data;
- }
  
  URLProtocol ff_md5_protocol = {
      .name                = "md5",
      .url_open            = md5_open,
      .url_write           = md5_write,
      .url_close           = md5_close,
-     .url_get_file_handle = md5_get_handle,
      .priv_data_size      = PRIV_SIZE,
  };
diff --combined libavformat/mmsh.c
index bc93722f1a02ee215d10d64bd307431ab00a3701,fa1a467223d0cc26f5dc1746a8307bd593c3444c..e92b74fc0a5670db3800deea48ce093aad7bf1fa
@@@ -2,20 -2,20 +2,20 @@@
   * MMS protocol over HTTP
   * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -56,7 -56,6 +56,7 @@@ typedef enum 
  
  typedef struct {
      MMSContext mms;
 +    uint8_t location[1024];
      int request_seq;  ///< request packet sequence
      int chunk_seq;    ///< data packet sequence
  } MMSHContext;
@@@ -69,7 -68,6 +69,6 @@@ static int mmsh_close(URLContext *h
          ffurl_close(mms->mms_hd);
      av_free(mms->streams);
      av_free(mms->asf_header);
-     av_freep(&h->priv_data);
      return 0;
  }
  
@@@ -212,24 -210,21 +211,21 @@@ static int get_http_header_data(MMSHCon
      }
  }
  
 -static int mmsh_open(URLContext *h, const char *uri, int flags)
 +static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int timestamp, int64_t pos)
  {
      int i, port, err;
 -    char httpname[256], path[256], host[128], location[1024];
 +    char httpname[256], path[256], host[128];
      char *stream_selection = NULL;
      char headers[1024];
-     MMSHContext *mmsh;
+     MMSHContext *mmsh = h->priv_data;
      MMSContext *mms;
  
-     mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext));
-     if (!h->priv_data)
-         return AVERROR(ENOMEM);
      mmsh->request_seq = h->is_streamed = 1;
      mms = &mmsh->mms;
 -    av_strlcpy(location, uri, sizeof(location));
 +    av_strlcpy(mmsh->location, uri, sizeof(mmsh->location));
  
      av_url_split(NULL, 0, NULL, 0,
 -        host, sizeof(host), &port, path, sizeof(path), location);
 +        host, sizeof(host), &port, path, sizeof(path), mmsh->location);
      if (port<0)
          port = 80; // default mmsh protocol port
      ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, "%s", path);
               "Pragma: no-cache,rate=1.000000,stream-time=0,"
               "stream-offset=0:0,request-context=%u,max-duration=0\r\n"
               CLIENTGUID
 -             "Connection: Close\r\n\r\n",
 +             "Connection: Close\r\n",
               host, port, mmsh->request_seq++);
      av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
  
      // close the socket and then reopen it for sending the second play request.
      ffurl_close(mms->mms_hd);
      memset(headers, 0, sizeof(headers));
-     if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
-                     &h->interrupt_callback) < 0) {
-         return AVERROR(EIO);
+     if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
+                            &h->interrupt_callback)) < 0) {
+         goto fail;
      }
      stream_selection = av_mallocz(mms->stream_num * 19 + 1);
      if (!stream_selection)
                     CLIENTGUID
                     "Pragma: stream-switch-count=%d\r\n"
                     "Pragma: stream-switch-entry=%s\r\n"
 -                   "Connection: Close\r\n\r\n",
 -                   host, port, mmsh->request_seq++, mms->stream_num, stream_selection);
 +                   "Pragma: no-cache,rate=1.000000,stream-time=%u"
 +                   "Connection: Close\r\n",
 +                   host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp);
      av_freep(&stream_selection);
      if (err < 0) {
          av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n");
@@@ -318,11 -312,6 +314,11 @@@ fail
      return err;
  }
  
 +static int mmsh_open(URLContext *h, const char *uri, int flags)
 +{
 +    return mmsh_open_internal(h, uri, flags, 0, 0);
 +}
 +
  static int handle_chunk_type(MMSHContext *mmsh)
  {
      MMSContext *mms = &mmsh->mms;
@@@ -369,44 -358,10 +365,45 @@@ static int mmsh_read(URLContext *h, uin
      return res;
  }
  
 +static int64_t mmsh_read_seek(URLContext *h, int stream_index,
 +                        int64_t timestamp, int flags)
 +{
 +    MMSHContext *mmsh = h->priv_data;
 +    MMSContext *mms   = &mmsh->mms;
 +    int ret;
 +
 +    ret= mmsh_open_internal(h, mmsh->location, 0, FFMAX(timestamp, 0), 0);
 +
 +    if(ret>=0){
 +        if (mms->mms_hd)
 +            ffurl_close(mms->mms_hd);
 +        av_freep(&mms->streams);
 +        av_freep(&mms->asf_header);
 +        av_free(mmsh);
 +        mmsh = h->priv_data;
 +        mms   = &mmsh->mms;
 +        mms->asf_header_read_size= mms->asf_header_size;
 +    }else
 +        h->priv_data= mmsh;
 +    return ret;
 +}
 +
 +static int64_t mmsh_seek(URLContext *h, int64_t pos, int whence)
 +{
 +    MMSHContext *mmsh = h->priv_data;
 +    MMSContext *mms   = &mmsh->mms;
 +
 +    if(pos == 0 && whence == SEEK_CUR)
 +        return mms->asf_header_read_size + mms->remaining_in_len + mmsh->chunk_seq * mms->asf_packet_len;
 +    return AVERROR(ENOSYS);
 +}
 +
  URLProtocol ff_mmsh_protocol = {
-     .name      = "mmsh",
-     .url_open  = mmsh_open,
-     .url_read  = mmsh_read,
-     .url_seek  = mmsh_seek,
-     .url_close = mmsh_close,
+     .name           = "mmsh",
+     .url_open       = mmsh_open,
+     .url_read       = mmsh_read,
++    .url_seek       = mmsh_seek,
+     .url_close      = mmsh_close,
 +    .url_read_seek  = mmsh_read_seek,
+     .priv_data_size = sizeof(MMSHContext),
  };
diff --combined libavformat/mmst.c
index 0a728eb35f9e86a491c19b7d9a3f9d4a8912955b,753b05ccebfc835493970e7f5047ea09b72abb15..a6fe696f5fc1ec5febe18a82b1b2ad0d4e57b0cb
@@@ -4,20 -4,20 +4,20 @@@
   * Copyright (c) 2007 Björn Axelsson
   * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -152,7 -152,7 +152,7 @@@ static int send_command_packet(MMSTCont
      return 0;
  }
  
 -static void mms_put_utf16(MMSContext *mms, uint8_t *src)
 +static void mms_put_utf16(MMSContext *mms, const uint8_t *src)
  {
      AVIOContext bic;
      int size = mms->write_out_ptr - mms->out_buffer;
@@@ -470,7 -470,6 +470,6 @@@ static int mms_close(URLContext *h
      /* free all separately allocated pointers in mms */
      av_free(mms->streams);
      av_free(mms->asf_header);
-     av_freep(&h->priv_data);
  
      return 0;
  }
@@@ -502,15 -501,12 +501,12 @@@ static void clear_stream_buffers(MMSCon
  
  static int mms_open(URLContext *h, const char *uri, int flags)
  {
-     MMSTContext *mmst;
+     MMSTContext *mmst = h->priv_data;
      MMSContext *mms;
      int port, err;
      char tcpname[256];
  
      h->is_streamed = 1;
-     mmst = h->priv_data = av_mallocz(sizeof(MMSTContext));
-     if (!h->priv_data)
-         return AVERROR(ENOMEM);
      mms = &mmst->mms;
  
      // only for MMS over TCP, so set proto = NULL
@@@ -624,8 -620,9 +620,9 @@@ static int mms_read(URLContext *h, uint
  }
  
  URLProtocol ff_mmst_protocol = {
-     .name      = "mmst",
-     .url_open  = mms_open,
-     .url_read  = mms_read,
-     .url_close = mms_close,
+     .name           = "mmst",
+     .url_open       = mms_open,
+     .url_read       = mms_read,
+     .url_close      = mms_close,
+     .priv_data_size = sizeof(MMSTContext),
  };
diff --combined libavformat/pmpdec.c
index 88b8998ad914e582d1c92b7415692c10b79ac7e4,96c704857066915bf4adb7da59bfb7fa3583e6fa..3d54484314fafcf3c5f6ce5b75f2666747c8d996
@@@ -1,44 -1,46 +1,45 @@@
  /*
 - * PMP demuxer
 + * PMP demuxer.
   * Copyright (c) 2011 Reimar Döffinger
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #include "libavutil/intreadwrite.h"
  #include "avformat.h"
 -#include "internal.h"
  
 -typedef struct PMPContext {
 -    int       cur_stream;
 -    int       num_streams;
 -    int       audio_packets;
 -    int       current_packet;
 +typedef struct {
 +    int cur_stream;
 +    int num_streams;
 +    int audio_packets;
 +    int current_packet;
      uint32_t *packet_sizes;
 -    int       packet_sizes_alloc;
 +    int packet_sizes_alloc;
  } PMPContext;
  
 -static int pmp_probe(AVProbeData *p)
 -{
 -    if (!memcmp(p->buf, "pmpm\1\0\0\0", 8))
 +static int pmp_probe(AVProbeData *p) {
 +    if (AV_RN32(p->buf) == AV_RN32("pmpm") &&
 +        AV_RL32(p->buf + 4) == 1)
          return AVPROBE_SCORE_MAX;
      return 0;
  }
  
- static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) {
+ static int pmp_header(AVFormatContext *s, AVFormatParameters *ap)
+ {
      PMPContext *pmp = s->priv_data;
      AVIOContext *pb = s->pb;
      int tb_num, tb_den;
          av_log(s, AV_LOG_ERROR, "Unsupported video format\n");
          break;
      }
 -    index_cnt          = avio_rl32(pb);
 +    index_cnt = avio_rl32(pb);
      vst->codec->width  = avio_rl32(pb);
      vst->codec->height = avio_rl32(pb);
  
      tb_num = avio_rl32(pb);
      tb_den = avio_rl32(pb);
 -    avpriv_set_pts_info(vst, 32, tb_num, tb_den);
 +    av_set_pts_info(vst, 32, tb_num, tb_den);
      vst->nb_frames = index_cnt;
 -    vst->duration  = index_cnt;
 +    vst->duration = index_cnt;
  
      switch (avio_rl32(pb)) {
      case 0:
          audio_codec_id = CODEC_ID_MP3;
          break;
      case 1:
 -        av_log(s, AV_LOG_WARNING, "AAC is not yet correctly supported\n");
 +        av_log(s, AV_LOG_ERROR, "AAC not yet correctly supported\n");
          audio_codec_id = CODEC_ID_AAC;
          break;
      default:
      }
      pmp->num_streams = avio_rl16(pb) + 1;
      avio_skip(pb, 10);
 -    srate    = avio_rl32(pb);
 +    srate = avio_rl32(pb);
      channels = avio_rl32(pb) + 1;
      for (i = 1; i < pmp->num_streams; i++) {
          AVStream *ast = avformat_new_stream(s, NULL);
          if (!ast)
              return AVERROR(ENOMEM);
-         ast->id = i;
 -        ast->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
 -        ast->codec->codec_id    = audio_codec_id;
 -        ast->codec->channels    = channels;
 +        ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 +        ast->codec->codec_id = audio_codec_id;
 +        ast->codec->channels = channels;
          ast->codec->sample_rate = srate;
 -        avpriv_set_pts_info(ast, 32, 1, srate);
 +        av_set_pts_info(ast, 32, 1, srate);
      }
 -    pos = avio_tell(pb) + 4 * index_cnt;
 +    pos = avio_tell(pb) + 4*index_cnt;
      for (i = 0; i < index_cnt; i++) {
 -        int size  = avio_rl32(pb);
 +        int size = avio_rl32(pb);
          int flags = size & 1 ? AVINDEX_KEYFRAME : 0;
          size >>= 1;
          av_add_index_entry(vst, pos, i, size, 0, flags);
      return 0;
  }
  
- static int pmp_packet(AVFormatContext *s, AVPacket *pkt) {
+ static int pmp_packet(AVFormatContext *s, AVPacket *pkt)
+ {
      PMPContext *pmp = s->priv_data;
      AVIOContext *pb = s->pb;
      int ret = 0;
      int i;
  
 -    if (pb->eof_reached)
 +    if (url_feof(pb))
          return AVERROR_EOF;
      if (pmp->cur_stream == 0) {
          int num_packets;
          av_fast_malloc(&pmp->packet_sizes,
                         &pmp->packet_sizes_alloc,
                         num_packets * sizeof(*pmp->packet_sizes));
+         if (!pmp->packet_sizes_alloc) {
+             av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n");
+             return AVERROR(ENOMEM);
+         }
          for (i = 0; i < num_packets; i++)
              pmp->packet_sizes[i] = avio_rl32(pb);
      }
      ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
 -    if (ret > 0) {
 +    if (ret >= 0) {
          ret = 0;
-         // FIXME: this is a hack that should be remove once
-         // compute_pkt_fields can handle
+         // FIXME: this is a hack that should be removed once
+         // compute_pkt_fields() can handle timestamps properly
          if (pmp->cur_stream == 0)
              pkt->dts = s->streams[0]->cur_dts++;
          pkt->stream_index = pmp->cur_stream;
      }
 -    pmp->current_packet++;
 -    if (pmp->current_packet == 1 || pmp->current_packet > pmp->audio_packets)
 +    if (pmp->current_packet % pmp->audio_packets == 0)
          pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
 -
 +    pmp->current_packet++;
      return ret;
  }
  
- static int pmp_seek(AVFormatContext *s, int stream_index,
-                      int64_t ts, int flags) {
 -static int pmp_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
++static int pmp_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
+ {
      PMPContext *pmp = s->priv_data;
      pmp->cur_stream = 0;
      // fallback to default seek now
diff --combined libavformat/rtmpproto.c
index 8935f56369497e7deb32ada6126d18f1c62287ee,54213b1dd0932aa77e0df3217894a1703da1b208..8f57d1bb5963874b673c6324a530b7c2c0c9ae15
@@@ -2,20 -2,20 +2,20 @@@
   * RTMP network protocol
   * Copyright (c) 2009 Kostya Shishkov
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -784,7 -784,6 +784,6 @@@ static int rtmp_close(URLContext *h
  
      av_freep(&rt->flv_data);
      ffurl_close(rt->stream);
-     av_free(rt);
      return 0;
  }
  
   */
  static int rtmp_open(URLContext *s, const char *uri, int flags)
  {
-     RTMPContext *rt;
+     RTMPContext *rt = s->priv_data;
      char proto[8], hostname[256], path[1024], *fname;
      uint8_t buf[2048];
      int port;
      int ret;
  
-     rt = av_mallocz(sizeof(RTMPContext));
-     if (!rt)
-         return AVERROR(ENOMEM);
-     s->priv_data = rt;
      rt->is_input = !(flags & AVIO_FLAG_WRITE);
  
      av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
  
      rt->state = STATE_START;
      if (rtmp_handshake(s, rt))
-         return -1;
+         goto fail;
  
      rt->chunk_size = 128;
      rt->state = STATE_HANDSHAKED;
@@@ -997,9 -992,10 +992,10 @@@ static int rtmp_write(URLContext *s, co
  }
  
  URLProtocol ff_rtmp_protocol = {
-     .name      = "rtmp",
-     .url_open  = rtmp_open,
-     .url_read  = rtmp_read,
-     .url_write = rtmp_write,
-     .url_close = rtmp_close,
+     .name           = "rtmp",
+     .url_open       = rtmp_open,
+     .url_read       = rtmp_read,
+     .url_write      = rtmp_write,
+     .url_close      = rtmp_close,
+     .priv_data_size = sizeof(RTMPContext),
  };
index 35ca9061fdd0584b70211c382f60ff992196c11e,4a0b6acf59fa5291574c4b1dc12403eca889cb6f..20450d8dfb6d57cac2b1e64c56d8cf7385a4ce96
@@@ -1,20 -1,20 +1,20 @@@
  /*
   * Copyright (c) 2011 Miroslav Slugeň <Thunder.m@seznam.cz>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -27,10 -27,8 +27,8 @@@ static int g726_ ## bitrate ##_init(AVF
      AVStream *stream = s->streams[st_index]; \
      AVCodecContext *codec = stream->codec; \
  \
-     codec->bit_rate = bitrate*1000; \
-     if (codec->sample_rate) \
-         codec->bits_per_coded_sample = \
-             av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5); \
+     codec->bits_per_coded_sample = bitrate/8; \
+     codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \
  \
      return 0; \
  } \
diff --combined libavformat/rtpenc.c
index 73ac76fae7620c90cf9f0a84f34013643d5a4a10,1f036a6baf4d3058ca946d2f30565b582ea2eb35..ac9b32cc0c62903da4164f0696a499a2112c045c
@@@ -2,20 -2,20 +2,20 @@@
   * RTP output format
   * Copyright (c) 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -72,6 -72,7 +72,7 @@@ static int is_supported(enum CodecID id
      case CODEC_ID_THEORA:
      case CODEC_ID_VP8:
      case CODEC_ID_ADPCM_G722:
+     case CODEC_ID_ADPCM_G726:
          return 1;
      default:
          return 0;
@@@ -88,7 -89,7 +89,7 @@@ static int rtp_write_header(AVFormatCon
          return -1;
      st = s1->streams[0];
      if (!is_supported(st->codec->codec_id)) {
 -        av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codec->codec_id);
 +        av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codec->codec_id));
  
          return -1;
      }
              if (st->codec->frame_size == 0) {
                  av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n");
              } else {
-                 s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * st->codec->frame_size, AV_ROUND_DOWN);
+                 s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * (int64_t)st->codec->frame_size, AV_ROUND_DOWN);
              }
          }
          if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
@@@ -248,14 -249,16 +249,16 @@@ void ff_rtp_send_data(AVFormatContext *
  /* send an integer number of samples and compute time stamp and fill
     the rtp send buffer before sending. */
  static void rtp_send_samples(AVFormatContext *s1,
-                              const uint8_t *buf1, int size, int sample_size)
+                              const uint8_t *buf1, int size, int sample_size_bits)
  {
      RTPMuxContext *s = s1->priv_data;
      int len, max_packet_size, n;
+     /* Calculate the number of bytes to get samples aligned on a byte border */
+     int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8);
  
-     max_packet_size = (s->max_payload_size / sample_size) * sample_size;
-     /* not needed, but who nows */
-     if ((size % sample_size) != 0)
+     max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
+     /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
+     if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
          av_abort();
      n = 0;
      while (size > 0) {
          s->buf_ptr += len;
          buf1 += len;
          size -= len;
-         s->timestamp = s->cur_timestamp + n / sample_size;
+         s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
          ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
          n += (s->buf_ptr - s->buf);
      }
@@@ -394,19 -397,24 +397,24 @@@ static int rtp_write_packet(AVFormatCon
      case CODEC_ID_PCM_ALAW:
      case CODEC_ID_PCM_U8:
      case CODEC_ID_PCM_S8:
-         rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels);
+         rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels);
          break;
      case CODEC_ID_PCM_U16BE:
      case CODEC_ID_PCM_U16LE:
      case CODEC_ID_PCM_S16BE:
      case CODEC_ID_PCM_S16LE:
-         rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels);
+         rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels);
          break;
      case CODEC_ID_ADPCM_G722:
          /* The actual sample size is half a byte per sample, but since the
           * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
-          * the correct parameter for send_samples is 1 byte per stream clock. */
-         rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels);
+          * the correct parameter for send_samples_bits is 8 bits per stream
+          * clock. */
+         rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels);
+         break;
+     case CODEC_ID_ADPCM_G726:
+         rtp_send_samples(s1, pkt->data, size,
+                          st->codec->bits_per_coded_sample * st->codec->channels);
          break;
      case CODEC_ID_MP2:
      case CODEC_ID_MP3:
diff --combined libavformat/rtpproto.c
index 41fb7317bbabaa0fe4b3ddaaeda5d51dda35c484,93cad3c8e69893efd9a4735b6184cdc632b0ada5..b6f2a561463488a37a3c3180b832bbe74fdcf9eb
@@@ -2,20 -2,20 +2,20 @@@
   * RTP network protocol
   * Copyright (c) 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -115,7 -115,6 +115,7 @@@ static void build_udp_url(char *buf, in
          url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size);
      if (connect)
          url_add_option(buf, buf_size, "connect=1");
 +    url_add_option(buf, buf_size, "fifo_size=0");
  }
  
  /**
  
  static int rtp_open(URLContext *h, const char *uri, int flags)
  {
-     RTPContext *s;
+     RTPContext *s = h->priv_data;
      int rtp_port, rtcp_port,
          ttl, connect,
          local_rtp_port, local_rtcp_port, max_packet_size;
      char path[1024];
      const char *p;
  
-     s = av_mallocz(sizeof(RTPContext));
-     if (!s)
-         return AVERROR(ENOMEM);
-     h->priv_data = s;
      av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
                   path, sizeof(path), uri);
      /* extract parameters */
          ffurl_close(s->rtp_hd);
      if (s->rtcp_hd)
          ffurl_close(s->rtcp_hd);
-     av_free(s);
      return AVERROR(EIO);
  }
  
@@@ -291,7 -284,6 +285,6 @@@ static int rtp_close(URLContext *h
  
      ffurl_close(s->rtp_hd);
      ffurl_close(s->rtcp_hd);
-     av_free(s);
      return 0;
  }
  
@@@ -337,4 -329,5 +330,5 @@@ URLProtocol ff_rtp_protocol = 
      .url_write           = rtp_write,
      .url_close           = rtp_close,
      .url_get_file_handle = rtp_get_file_handle,
+     .priv_data_size      = sizeof(RTPContext),
  };
diff --combined libavformat/sdp.c
index 13c5ba6629712dde453cdbeb5b91e5847e065549,f0d4253da2056b8240dd54744795ed78b4c2b429..5def15d2a3cdf79f3aa0d79d476a468309f2df3f
@@@ -1,20 -1,20 +1,20 @@@
  /*
   * copyright (c) 2007 Luca Abeni
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -402,7 -402,7 +402,7 @@@ static char *sdp_write_media_attributes
                                       payload_type, config ? config : "");
              break;
          case CODEC_ID_AAC:
 -            if (fmt && fmt->oformat->priv_class &&
 +            if (fmt && fmt->oformat && fmt->oformat->priv_class &&
                  av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) {
                  config = latm_context2config(c);
                  if (!config)
                                           payload_type,
                                           8000, c->channels);
              break;
+         case CODEC_ID_ADPCM_G726: {
+             if (payload_type >= RTP_PT_PRIVATE)
+                 av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n",
+                                          payload_type,
+                                          c->bits_per_coded_sample*8,
+                                          c->sample_rate);
+             break;
+         }
          default:
              /* Nothing special to do here... */
              break;
diff --combined libavformat/tcp.c
index f882fc0deec10d764372883e4e334854985f7d49,0d3aeaf48c5cdc5c14090a5ee0c7fc0490ddbbdf..1aeceb9e02ca6958123a8d0c3a67cb59dc76519a
@@@ -2,20 -2,20 +2,20 @@@
   * TCP protocol
   * Copyright (c) 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  #include "avformat.h"
@@@ -39,13 -39,13 +39,13 @@@ static int tcp_open(URLContext *h, cons
  {
      struct addrinfo hints, *ai, *cur_ai;
      int port, fd = -1;
-     TCPContext *s = NULL;
+     TCPContext *s = h->priv_data;
      int listen_socket = 0;
      const char *p;
      char buf[256];
      int ret;
      socklen_t optlen;
 -    int timeout = 100;
 +    int timeout = 50;
      char hostname[1024],proto[1024],path[1024];
      char portstr[10];
  
              goto fail;
          }
      }
-     s = av_malloc(sizeof(TCPContext));
-     if (!s) {
-         freeaddrinfo(ai);
-         return AVERROR(ENOMEM);
-     }
-     h->priv_data = s;
      h->is_streamed = 1;
      s->fd = fd;
      freeaddrinfo(ai);
@@@ -193,7 -187,6 +187,6 @@@ static int tcp_close(URLContext *h
  {
      TCPContext *s = h->priv_data;
      closesocket(s->fd);
-     av_free(s);
      return 0;
  }
  
@@@ -210,4 -203,5 +203,5 @@@ URLProtocol ff_tcp_protocol = 
      .url_write           = tcp_write,
      .url_close           = tcp_close,
      .url_get_file_handle = tcp_get_file_handle,
+     .priv_data_size      = sizeof(TCPContext),
  };
diff --combined libavformat/udp.c
index ee5b3047699dff1f061741aa991e543dc21dc8f3,529114a860c3f5b1ad5b817b4a927204a47335f7..a0d127c614bc75e9740e7912413d54394cca815f
@@@ -2,20 -2,20 +2,20 @@@
   * UDP prototype streaming system
   * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #include "avformat.h"
  #include "avio_internal.h"
  #include "libavutil/parseutils.h"
 +#include "libavutil/fifo.h"
 +#include "libavutil/intreadwrite.h"
  #include "libavutil/avstring.h"
  #include <unistd.h>
  #include "internal.h"
  #include "network.h"
  #include "os_support.h"
  #include "url.h"
 +
 +#if HAVE_PTHREADS
 +#include <pthread.h>
 +#endif
 +
  #include <sys/time.h>
  
  #ifndef IPV6_ADD_MEMBERSHIP
@@@ -49,9 -42,6 +49,9 @@@
  #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
  #endif
  
 +#define UDP_TX_BUF_SIZE 32768
 +#define UDP_MAX_PKT_SIZE 65536
 +
  typedef struct {
      int udp_fd;
      int ttl;
      struct sockaddr_storage dest_addr;
      int dest_addr_len;
      int is_connected;
 -} UDPContext;
  
 -#define UDP_TX_BUF_SIZE 32768
 -#define UDP_MAX_PKT_SIZE 65536
 +    /* Circular Buffer variables for use in UDP receive code */
 +    int circular_buffer_size;
 +    AVFifoBuffer *fifo;
 +    int circular_buffer_error;
 +#if HAVE_PTHREADS
 +    pthread_t circular_buffer_thread;
 +#endif
 +    uint8_t tmp[UDP_MAX_PKT_SIZE+4];
 +    int remaining_in_dg;
 +} UDPContext;
  
  static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
                                   struct sockaddr *addr)
@@@ -317,71 -300,13 +317,71 @@@ static int udp_get_file_handle(URLConte
      return s->udp_fd;
  }
  
 +static void *circular_buffer_task( void *_URLContext)
 +{
 +    URLContext *h = _URLContext;
 +    UDPContext *s = h->priv_data;
 +    fd_set rfds;
 +    struct timeval tv;
 +
 +    for(;;) {
 +        int left;
 +        int ret;
 +        int len;
 +
 +        if (ff_check_interrupt(&h->interrupt_callback)) {
 +            s->circular_buffer_error = EINTR;
 +            return NULL;
 +        }
 +
 +        FD_ZERO(&rfds);
 +        FD_SET(s->udp_fd, &rfds);
 +        tv.tv_sec = 1;
 +        tv.tv_usec = 0;
 +        ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
 +        if (ret < 0) {
 +            if (ff_neterrno() == AVERROR(EINTR))
 +                continue;
 +            s->circular_buffer_error = EIO;
 +            return NULL;
 +        }
 +
 +        if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds)))
 +            continue;
 +
 +        /* How much do we have left to the end of the buffer */
 +        /* Whats the minimum we can read so that we dont comletely fill the buffer */
 +        left = av_fifo_space(s->fifo);
 +
 +        /* No Space left, error, what do we do now */
 +        if(left < UDP_MAX_PKT_SIZE + 4) {
 +            av_log(h, AV_LOG_ERROR, "circular_buffer: OVERRUN\n");
 +            s->circular_buffer_error = EIO;
 +            return NULL;
 +        }
 +        left = FFMIN(left, s->fifo->end - s->fifo->wptr);
 +        len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0);
 +        if (len < 0) {
 +            if (ff_neterrno() != AVERROR(EAGAIN) && ff_neterrno() != AVERROR(EINTR)) {
 +                s->circular_buffer_error = EIO;
 +                return NULL;
 +            }
 +            continue;
 +        }
 +        AV_WL32(s->tmp, len);
 +        av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
 +    }
 +
 +    return NULL;
 +}
 +
  /* put it in UDP context */
  /* return non zero if error */
  static int udp_open(URLContext *h, const char *uri, int flags)
  {
      char hostname[1024], localaddr[1024] = "";
      int port, udp_fd = -1, tmp, bind_ret = -1;
-     UDPContext *s = NULL;
+     UDPContext *s = h->priv_data;
      int is_output;
      const char *p;
      char buf[256];
  
      is_output = !(flags & AVIO_FLAG_READ);
  
-     s = av_mallocz(sizeof(UDPContext));
-     if (!s)
-         return AVERROR(ENOMEM);
-     h->priv_data = s;
      s->ttl = 16;
      s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
  
 +    s->circular_buffer_size = 7*188*4096;
 +
      p = strchr(uri, '?');
      if (p) {
          if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
          if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
              s->is_connected = strtol(buf, NULL, 10);
          }
 +        if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) {
 +            s->circular_buffer_size = strtol(buf, NULL, 10)*188;
 +        }
          if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
              av_strlcpy(localaddr, buf, sizeof(localaddr));
          }
      }
  
      s->udp_fd = udp_fd;
 +
 +#if HAVE_PTHREADS
 +    if (!is_output && s->circular_buffer_size) {
 +        /* start the task going */
 +        s->fifo = av_fifo_alloc(s->circular_buffer_size);
 +        if (pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h)) {
 +            av_log(h, AV_LOG_ERROR, "pthread_create failed\n");
 +            goto fail;
 +        }
 +    }
 +#endif
 +
      return 0;
   fail:
      if (udp_fd >= 0)
          closesocket(udp_fd);
-     av_free(s);
 +    av_fifo_free(s->fifo);
      return AVERROR(EIO);
  }
  
@@@ -541,39 -442,6 +535,39 @@@ static int udp_read(URLContext *h, uint
  {
      UDPContext *s = h->priv_data;
      int ret;
 +    int avail;
 +    fd_set rfds;
 +    struct timeval tv;
 +
 +    if (s->fifo) {
 +
 +        do {
 +            avail = av_fifo_size(s->fifo);
 +            if (avail) { // >=size) {
 +                uint8_t tmp[4];
 +
 +                av_fifo_generic_read(s->fifo, tmp, 4, NULL);
 +                avail= AV_RL32(tmp);
 +                if(avail > size){
 +                    av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n");
 +                    avail= size;
 +                }
 +
 +                av_fifo_generic_read(s->fifo, buf, avail, NULL);
 +                av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);
 +                return avail;
 +            }
 +            else {
 +                FD_ZERO(&rfds);
 +                FD_SET(s->udp_fd, &rfds);
 +                tv.tv_sec = 1;
 +                tv.tv_usec = 0;
 +                ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
 +                if (ret<0)
 +                    return ret;
 +            }
 +        } while( 1);
 +    }
  
      if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
          ret = ff_network_wait_fd(s->udp_fd, 0);
              return ret;
      }
      ret = recv(s->udp_fd, buf, size, 0);
 +
      return ret < 0 ? ff_neterrno() : ret;
  }
  
@@@ -613,8 -480,6 +607,7 @@@ static int udp_close(URLContext *h
      if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
          udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
      closesocket(s->udp_fd);
-     av_free(s);
 +    av_fifo_free(s->fifo);
      return 0;
  }
  
@@@ -625,4 -490,5 +618,5 @@@ URLProtocol ff_udp_protocol = 
      .url_write           = udp_write,
      .url_close           = udp_close,
      .url_get_file_handle = udp_get_file_handle,
+     .priv_data_size      = sizeof(UDPContext),
  };
diff --combined libswscale/utils.c
index e27144e594ba923907a2a7da87d1001a87781e5f,b644ed9610fa798429e8f185d82d17a47bb1391d..3240b9603070d016b450dac2a1690e793c4af5c0
@@@ -1,25 -1,24 +1,25 @@@
  /*
   * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #define _SVID_SOURCE //needed for MAP_ANONYMOUS
 +#define _DARWIN_C_SOURCE // needed for MAP_ANON
  #include <inttypes.h>
  #include <string.h>
  #include <math.h>
  #include "libavutil/cpu.h"
  #include "libavutil/avutil.h"
  #include "libavutil/bswap.h"
+ #include "libavutil/mathematics.h"
  #include "libavutil/opt.h"
  #include "libavutil/pixdesc.h"
 +#include "libavutil/avassert.h"
  
  unsigned swscale_version(void)
  {
  
  const char *swscale_configuration(void)
  {
 -    return LIBAV_CONFIGURATION;
 +    return FFMPEG_CONFIGURATION;
  }
  
  const char *swscale_license(void)
  {
  #define LICENSE_PREFIX "libswscale license: "
 -    return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
 +    return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  }
  
  #define RET 0xC3 //near return opcode for x86
@@@ -100,10 -99,6 +101,10 @@@ const static FormatEntry format_entries
      [PIX_FMT_RGBA]        = { 1 , 1 },
      [PIX_FMT_ABGR]        = { 1 , 1 },
      [PIX_FMT_BGRA]        = { 1 , 1 },
 +    [PIX_FMT_0RGB]        = { 1 , 1 },
 +    [PIX_FMT_RGB0]        = { 1 , 1 },
 +    [PIX_FMT_0BGR]        = { 1 , 1 },
 +    [PIX_FMT_BGR0]        = { 1 , 1 },
      [PIX_FMT_GRAY16BE]    = { 1 , 1 },
      [PIX_FMT_GRAY16LE]    = { 1 , 1 },
      [PIX_FMT_YUV440P]     = { 1 , 1 },
      [PIX_FMT_YUVA420P]    = { 1 , 1 },
      [PIX_FMT_RGB48BE]     = { 1 , 1 },
      [PIX_FMT_RGB48LE]     = { 1 , 1 },
 +    [PIX_FMT_RGBA64BE]    = { 0 , 0 },
 +    [PIX_FMT_RGBA64LE]    = { 0 , 0 },
      [PIX_FMT_RGB565BE]    = { 1 , 1 },
      [PIX_FMT_RGB565LE]    = { 1 , 1 },
      [PIX_FMT_RGB555BE]    = { 1 , 1 },
      [PIX_FMT_Y400A]       = { 1 , 0 },
      [PIX_FMT_BGR48BE]     = { 1 , 1 },
      [PIX_FMT_BGR48LE]     = { 1 , 1 },
 +    [PIX_FMT_BGRA64BE]    = { 0 , 0 },
 +    [PIX_FMT_BGRA64LE]    = { 0 , 0 },
      [PIX_FMT_YUV420P9BE]  = { 1 , 1 },
      [PIX_FMT_YUV420P9LE]  = { 1 , 1 },
      [PIX_FMT_YUV420P10BE] = { 1 , 1 },
      [PIX_FMT_YUV444P9LE]  = { 1 , 1 },
      [PIX_FMT_YUV444P10BE] = { 1 , 1 },
      [PIX_FMT_YUV444P10LE] = { 1 , 1 },
 +    [PIX_FMT_GBR24P]      = { 1 , 0 },
      [PIX_FMT_GBRP]        = { 1 , 0 },
      [PIX_FMT_GBRP9LE]     = { 1 , 0 },
      [PIX_FMT_GBRP9BE]     = { 1 , 0 },
@@@ -172,12 -162,13 +173,12 @@@ int sws_isSupportedOutput(enum PixelFor
  
  extern const int32_t ff_yuv2rgb_coeffs[8][4];
  
 +#if FF_API_SWS_FORMAT_NAME
  const char *sws_format_name(enum PixelFormat format)
  {
 -    if ((unsigned)format < PIX_FMT_NB && av_pix_fmt_descriptors[format].name)
 -        return av_pix_fmt_descriptors[format].name;
 -    else
 -        return "Unknown format";
 +    return av_get_pix_fmt_name(format);
  }
 +#endif
  
  static double getSplineCoeff(double a, double b, double c, double d, double dist)
  {
@@@ -726,7 -717,7 +727,7 @@@ int sws_getColorspaceDetails(struct Sws
                               int *srcRange, int **table, int *dstRange,
                               int *brightness, int *contrast, int *saturation)
  {
 -    if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
 +    if (!c || isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
  
      *inv_table = c->srcColorspaceTable;
      *table     = c->dstColorspaceTable;
@@@ -746,10 -737,6 +747,10 @@@ static int handle_jpeg(enum PixelForma
      case PIX_FMT_YUVJ422P: *format = PIX_FMT_YUV422P; return 1;
      case PIX_FMT_YUVJ444P: *format = PIX_FMT_YUV444P; return 1;
      case PIX_FMT_YUVJ440P: *format = PIX_FMT_YUV440P; return 1;
 +    case PIX_FMT_0BGR    : *format = PIX_FMT_ABGR   ; return 0;
 +    case PIX_FMT_BGR0    : *format = PIX_FMT_BGRA   ; return 0;
 +    case PIX_FMT_0RGB    : *format = PIX_FMT_ARGB   ; return 0;
 +    case PIX_FMT_RGB0    : *format = PIX_FMT_RGBA   ; return 0;
      default:                                          return 0;
      }
  }
@@@ -766,7 -753,7 +767,7 @@@ SwsContext *sws_alloc_context(void
  
  int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
  {
 -    int i;
 +    int i, j;
      int usesVFilter, usesHFilter;
      int unscaled;
      SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
      int srcH= c->srcH;
      int dstW= c->dstW;
      int dstH= c->dstH;
 -    int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 16, 16), dst_stride_px = dst_stride >> 1;
 +    int dst_stride = FFALIGN(dstW * sizeof(int16_t)+66, 16);
      int flags, cpu_flags;
      enum PixelFormat srcFormat= c->srcFormat;
      enum PixelFormat dstFormat= c->dstFormat;
  
      unscaled = (srcW == dstW && srcH == dstH);
  
 +    handle_jpeg(&srcFormat);
 +    handle_jpeg(&dstFormat);
 +
 +    if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat){
 +        av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
 +        c->srcFormat= srcFormat;
 +        c->dstFormat= dstFormat;
 +    }
 +
      if (!sws_isSupportedInput(srcFormat)) {
 -        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat));
 +        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", av_get_pix_fmt_name(srcFormat));
          return AVERROR(EINVAL);
      }
      if (!sws_isSupportedOutput(dstFormat)) {
 -        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat));
 +        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", av_get_pix_fmt_name(dstFormat));
          return AVERROR(EINVAL);
      }
  
      getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
  
      // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation
 -    if (flags & SWS_FULL_CHR_H_INT &&
 -        dstFormat != PIX_FMT_RGBA &&
 -        dstFormat != PIX_FMT_ARGB &&
 -        dstFormat != PIX_FMT_BGRA &&
 -        dstFormat != PIX_FMT_ABGR &&
 -        dstFormat != PIX_FMT_RGB24 &&
 -        dstFormat != PIX_FMT_BGR24) {
 -        av_log(c, AV_LOG_ERROR,
 -               "full chroma interpolation for destination format '%s' not yet implemented\n",
 -               sws_format_name(dstFormat));
 -        flags &= ~SWS_FULL_CHR_H_INT;
 -        c->flags = flags;
 -    }
      if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1;
  
      // drop some chroma lines if the user wants it
          if (c->swScale) {
              if (flags&SWS_PRINT_INFO)
                  av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",
 -                       sws_format_name(srcFormat), sws_format_name(dstFormat));
 +                       av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
              return 0;
          }
      }
      c->dstBpc = 1 + av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1;
      if (c->dstBpc < 8)
          c->dstBpc = 8;
 +    if (isAnyRGB(srcFormat) || srcFormat == PIX_FMT_PAL8)
 +        c->srcBpc = 16;
      if (c->dstBpc == 16)
          dst_stride <<= 1;
 -    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer,
 -                     (FFALIGN(srcW, 16) * 2 * FFALIGN(c->srcBpc, 8) >> 3) + 16,
 -                     fail);
 +    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW*2+78, 16) * 2, fail);
      if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->srcBpc == 8 && c->dstBpc <= 10) {
          c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;
          if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {
              if (flags&SWS_PRINT_INFO)
                  av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");
          }
 -        if (usesHFilter) c->canMMX2BeUsed=0;
 +        if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat)) c->canMMX2BeUsed=0;
      }
      else
          c->canMMX2BeUsed=0;
              c->chrXInc+= 20;
          }
          //we don't use the x86 asm scaler if MMX is available
 -        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
 +        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX && c->dstBpc <= 10) {
              c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20;
              c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20;
          }
              c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize);
  #endif
  
 +#ifdef MAP_ANONYMOUS
 +            if (c->lumMmx2FilterCode == MAP_FAILED || c->chrMmx2FilterCode == MAP_FAILED)
 +#else
              if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode)
 +#endif
                  return AVERROR(ENOMEM);
              FF_ALLOCZ_OR_GOTO(c, c->hLumFilter   , (dstW        /8+8)*sizeof(int16_t), fail);
              FF_ALLOCZ_OR_GOTO(c, c->hChrFilter   , (c->chrDstW  /4+8)*sizeof(int16_t), fail);
              FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW      /2/8+8)*sizeof(int32_t), fail);
              FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail);
  
 -            initMMX2HScaler(      dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8);
 -            initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4);
 +            initMMX2HScaler(      dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8);
 +            initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4);
  
  #ifdef MAP_ANONYMOUS
              mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);
      c->vLumBufSize= c->vLumFilterSize;
      c->vChrBufSize= c->vChrFilterSize;
      for (i=0; i<dstH; i++) {
 -        int chrI= i*c->chrDstH / dstH;
 +        int chrI= (int64_t)i*c->chrDstH / dstH;
          int nextSlice= FFMAX(c->vLumFilterPos[i   ] + c->vLumFilterSize - 1,
                             ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));
  
          FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+16, fail);
          c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];
      }
 -    // 64 / (c->dstBpc & ~7) is the same as 16 / sizeof(scaling_intermediate)
 -    c->uv_off_px   = dst_stride_px + 64 / (c->dstBpc &~ 7);
 -    c->uv_off_byte = dst_stride + 16;
 +    // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate)
 +    c->uv_off   = (dst_stride>>1) + 64 / (c->dstBpc &~ 7);
 +    c->uv_offx2 = dst_stride + 16;
      for (i=0; i<c->vChrBufSize; i++) {
          FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+32, fail);
          c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];
  
      //try to avoid drawing green stuff between the right end and the stride end
      for (i=0; i<c->vChrBufSize; i++)
 -        memset(c->chrUPixBuf[i], 64, dst_stride*2+1);
 +        if(av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 == 15){
 +            av_assert0(c->dstBpc > 10);
 +            for(j=0; j<dst_stride/2+1; j++)
 +                ((int32_t*)(c->chrUPixBuf[i]))[j] = 1<<18;
 +        } else
 +            for(j=0; j<dst_stride+1; j++)
 +                ((int16_t*)(c->chrUPixBuf[i]))[j] = 1<<14;
  
      assert(c->chrDstH <= dstH);
  
          else                              av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");
  
          av_log(c, AV_LOG_INFO, "from %s to %s%s ",
 -               sws_format_name(srcFormat),
 +               av_get_pix_fmt_name(srcFormat),
  #ifdef DITHER1XBPP
                 dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 ||
                 dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||
  #else
                 "",
  #endif
 -               sws_format_name(dstFormat));
 +               av_get_pix_fmt_name(dstFormat));
  
          if      (HAVE_MMX2     && cpu_flags & AV_CPU_FLAG_MMX2)    av_log(c, AV_LOG_INFO, "using MMX2\n");
          else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW)   av_log(c, AV_LOG_INFO, "using 3DNOW\n");
@@@ -1498,7 -1479,7 +1499,7 @@@ void sws_freeContext(SwsContext *c
  #endif /* HAVE_MMX */
  
      av_freep(&c->yuvTable);
 -    av_free(c->formatConvBuffer);
 +    av_freep(&c->formatConvBuffer);
  
      av_free(c);
  }
index 12f74f055de28b6334afb991b98dd2c89a3d64f9,5133345dc069442f7b59ec6601010e43c5a4452c..7a71e47273dddcd1f3c63a0490ebbaf057469caa
@@@ -65,11 -65,6 +65,11 @@@ if [ -n "$do_mpeg2thread_ilace" ]; the
  # mpeg2 encoding interlaced using intra vlc
  do_video_encoding mpeg2threadivlc.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2"
  do_video_decoding
 +
 +# mpeg2 encoding interlaced
 +file=${outfile}mpeg2reuse.mpg
 +do_avconv $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -same_quant -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
 +do_video_decoding
  fi
  
  if [ -n "$do_msmpeg4v2" ] ; then
@@@ -82,11 -77,6 +82,11 @@@ do_video_encoding msmpeg4.avi "-qscale 
  do_video_decoding
  fi
  
 +if [ -n "$do_msvideo1" ] ; then
 +do_video_encoding msvideo1.avi "-an -vcodec msvideo1"
 +do_video_decoding "" "-pix_fmt yuv420p"
 +fi
 +
  if [ -n "$do_wmv1" ] ; then
  do_video_encoding wmv1.avi "-qscale 10 -an -vcodec wmv1"
  do_video_decoding
@@@ -122,11 -112,6 +122,11 @@@ do_video_encoding huffyuv.avi "-an -vco
  do_video_decoding "" "-strict -2 -pix_fmt yuv420p -sws_flags neighbor+bitexact"
  fi
  
 +if [ -n "$do_amv" ] ; then
 +do_video_encoding amv.avi "-an -vcodec amv"
 +do_video_decoding
 +fi
 +
  if [ -n "$do_rc" ] ; then
  do_video_encoding mpeg4-rc.avi "-b 400k -bf 2 -an -vcodec mpeg4"
  do_video_decoding
@@@ -177,11 -162,6 +177,11 @@@ do_video_encoding mjpeg.avi "-qscale 9 
  do_video_decoding "" "-pix_fmt yuv420p"
  fi
  
 +if [ -n "$do_jpeg2000" ] ; then
 +do_video_encoding jpeg2000.avi "-qscale 7 -an -vcodec j2k -strict experimental -pix_fmt rgb24"
 +do_video_decoding "-vcodec j2k -strict experimental" "-pix_fmt yuv420p"
 +fi
 +
  if [ -n "$do_ljpeg" ] ; then
  do_video_encoding ljpeg.avi "-an -vcodec ljpeg -strict -1"
  do_video_decoding
@@@ -268,11 -248,6 +268,11 @@@ do_video_encoding dnxhd-720p-10bit.dnxh
  do_video_decoding "" "-s cif -pix_fmt yuv420p"
  fi
  
 +if [ -n "$do_prores" ] ; then
 +do_video_encoding prores.mov "-vcodec prores"
 +do_video_decoding "" "-pix_fmt yuv420p"
 +fi
 +
  if [ -n "$do_svq1" ] ; then
  do_video_encoding svq1.mov "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p"
  do_video_decoding "" "-pix_fmt yuv420p"
@@@ -283,12 -258,6 +283,12 @@@ do_video_encoding flashsv.flv "-an -vco
  do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
  fi
  
 +if [ -n "$do_flashsv2" ] ; then
 +do_video_encoding flashsv2.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental"
 +do_video_encoding flashsv2I.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental -g 1"
 +do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
 +fi
 +
  if [ -n "$do_roq" ] ; then
  do_video_encoding roqav.roq "-vframes 5"
  do_video_decoding "" "-pix_fmt yuv420p"
@@@ -299,11 -268,6 +299,11 @@@ do_video_encoding qtrle.mov "-an -vcode
  do_video_decoding "" "-pix_fmt yuv420p"
  fi
  
 +if [ -n "$do_qtrlegray" ] ; then
 +do_video_encoding qtrlegray.mov "-an -vcodec qtrle -pix_fmt gray"
 +do_video_decoding "" "-pix_fmt yuv420p"
 +fi
 +
  if [ -n "$do_rgb" ] ; then
  do_video_encoding rgb.avi "-an -vcodec rawvideo -pix_fmt bgr24"
  do_video_decoding "" "-pix_fmt yuv420p"
@@@ -327,13 -291,8 +327,13 @@@ do_audio_encoding ac3.rm "-vn -acodec a
  #$tiny_psnr $pcm_dst $pcm_ref 2 1024
  fi
  
 +if [ -n "$do_g723_1" ] ; then
 +do_audio_encoding g723_1.tco "-b:a 6.3k -ac 1 -ar 8000 -acodec g723_1"
 +do_audio_decoding
 +fi
 +
  if [ -n "$do_g726" ] ; then
 -do_audio_encoding g726.wav "-b 32k -ac 1 -ar 8000 -acodec g726"
 +do_audio_encoding g726.wav "-b:a 32k -ac 1 -ar 8000 -acodec g726"
  do_audio_decoding
  fi
  
@@@ -395,26 -354,62 +395,62 @@@ do_audio_enc_dec() 
      do_audio_decoding
  }
  
- if [ -n "$do_pcm" ] ; then
+ if [ -n "$do_pcm_alaw" ] ; then
  do_audio_enc_dec wav s16 pcm_alaw
+ fi
+ if [ -n "$do_pcm_mulaw" ] ; then
  do_audio_enc_dec wav s16 pcm_mulaw
+ fi
+ if [ -n "$do_pcm_s8" ] ; then
  do_audio_enc_dec mov u8 pcm_s8
+ fi
+ if [ -n "$do_pcm_u8" ] ; then
  do_audio_enc_dec wav u8 pcm_u8
+ fi
+ if [ -n "$do_pcm_s16be" ] ; then
  do_audio_enc_dec mov s16 pcm_s16be
+ fi
+ if [ -n "$do_pcm_s16le" ] ; then
  do_audio_enc_dec wav s16 pcm_s16le
- do_audio_enc_dec mkv s16 pcm_s16be
- do_audio_enc_dec mkv s16 pcm_s16le
+ fi
+ if [ -n "$do_pcm_s24be" ] ; then
  do_audio_enc_dec mov s32 pcm_s24be
+ fi
+ if [ -n "$do_pcm_s24le" ] ; then
  do_audio_enc_dec wav s32 pcm_s24le
- #do_audio_enc_dec ??? s32 pcm_u24be #no compatible muxer or demuxer
- #do_audio_enc_dec ??? s32 pcm_u24le #no compatible muxer or demuxer
+ fi
+ # no compatible muxer or demuxer
+ # if [ -n "$do_pcm_u24be" ] ; then
+ # do_audio_enc_dec ??? u32 pcm_u24be
+ # fi
+ # if [ -n "$do_pcm_u24le" ] ; then
+ # do_audio_enc_dec ??? u32 pcm_u24le
+ # fi
+ if [ -n "$do_pcm_s32be" ] ; then
  do_audio_enc_dec mov s32 pcm_s32be
+ fi
+ if [ -n "$do_pcm_s32le" ] ; then
  do_audio_enc_dec wav s32 pcm_s32le
- #do_audio_enc_dec ??? s32 pcm_u32be #no compatible muxer or demuxer
- #do_audio_enc_dec ??? s32 pcm_u32le #no compatible muxer or demuxer
+ fi
+ # no compatible muxer or demuxer
+ # if [ -n "$do_pcm_u32be" ] ; then
+ # do_audio_enc_dec ??? u32 pcm_u32be
+ # fi
+ # if [ -n "$do_pcm_u32le" ] ; then
+ # do_audio_enc_dec ??? u32 pcm_u32le
+ # fi
+ if [ -n "$do_pcm_f32be" ] ; then
  do_audio_enc_dec au  flt pcm_f32be
+ fi
+ if [ -n "$do_pcm_f32le" ] ; then
  do_audio_enc_dec wav flt pcm_f32le
+ fi
+ if [ -n "$do_pcm_f64be" ] ; then
  do_audio_enc_dec au  dbl pcm_f64be
+ fi
+ if [ -n "$do_pcm_f64le" ] ; then
  do_audio_enc_dec wav dbl pcm_f64le
+ fi
+ if [ -n "$do_pcm_s24daud" ] ; then
  do_audio_enc_dec 302 s16 pcm_s24daud "-ac 6 -ar 96000"
  fi
index 0000000000000000000000000000000000000000,708375d6571624612f29abc219c277db864335ea..53c4b4370412d50db4962842286bcb387d473bff
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -a4e18d1ca9ef5b8132a84d43625ddc47 *./tests/data/acodec/pcm_s16be.mov
 -1060037 ./tests/data/acodec/pcm_s16be.mov
++9686b93d1439fc2df991a004ab0298f4 *./tests/data/acodec/pcm_s16be.mov
++1058993 ./tests/data/acodec/pcm_s16be.mov
+ 64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s16be.acodec.out.wav
+ stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
index 0000000000000000000000000000000000000000,1e90d7e008ada951bd1308ebb5d44a9b1abb3139..743183e33765848590338b952a2e665baae28a62
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -971d2d2633e41a0326fe2d04a2d0350f *./tests/data/acodec/pcm_s24be.mov
 -1589237 ./tests/data/acodec/pcm_s24be.mov
++22c5c3df0a4765e28c205a4fb95b3cdc *./tests/data/acodec/pcm_s24be.mov
++1588193 ./tests/data/acodec/pcm_s24be.mov
+ 64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s24be.acodec.out.wav
+ stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
index 0000000000000000000000000000000000000000,eab6f8d28e50d613c2eb1a6c6a8b82b557bddc73..62c44219082894e10c30d72c8b972fbda9031aae
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -8168a5c1343553ef027541830f2cb879 *./tests/data/acodec/pcm_s24daud.302
++1b75d5198ae789ab3c48f7024e08f4a9 *./tests/data/acodec/pcm_s24daud.302
+ 10368730 ./tests/data/acodec/pcm_s24daud.302
 -f552afadfdfcd6348a07095da6382de5 *./tests/data/pcm_s24daud.acodec.out.wav
 -stddev: 9416.28 PSNR: 16.85 MAXDIFF:42744 bytes:  6911796/  1058400
++4708f86529c594e29404603c64bb208c *./tests/data/pcm_s24daud.acodec.out.wav
++stddev: 8967.92 PSNR: 17.28 MAXDIFF:42548 bytes:  6911796/  1058400
index 0000000000000000000000000000000000000000,3bbb71df28abe58b68ba68f5c7c22a13ffeef29d..e2fbd3ba5a6822ddd0936f19860f8615f9328a78
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -fc4f4e3e195bbde037ed31021d229f12 *./tests/data/acodec/pcm_s32be.mov
 -2118437 ./tests/data/acodec/pcm_s32be.mov
++b36ac7a1b4fc28248a565a676e555bd1 *./tests/data/acodec/pcm_s32be.mov
++2117393 ./tests/data/acodec/pcm_s32be.mov
+ 64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s32be.acodec.out.wav
+ stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  1058400/  1058400
diff --combined tests/ref/acodec/pcm_s8
index 0000000000000000000000000000000000000000,7a53fdc5c5a46f225c1a7ce825c2694a98e6c5b0..34e5149f782f37c60d8f7c3d26320129332c8f7e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,4 +1,4 @@@
 -760f85fb9f4e8aba326fb44ae84c9507 *./tests/data/acodec/pcm_s8.mov
 -530837 ./tests/data/acodec/pcm_s8.mov
++b78d2a30df75af08ecf86f201281fec2 *./tests/data/acodec/pcm_s8.mov
++529793 ./tests/data/acodec/pcm_s8.mov
+ 651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm_s8.acodec.out.wav
+ stddev:  147.89 PSNR: 52.93 MAXDIFF:  255 bytes:  1058400/  1058400