diff --git a/configure b/configure
index 2b0a0ff980b3e3e3d43354a3d5e7cd13e5b523a0..c8b8c2b371ed62150892e734767e67b978bcd918 100755
--- a/configure
+++ b/configure
@@ -1627,9 +1627,10 @@ mdct_select="fft"
 rdft_select="fft"
 mpegaudio_select="mpegaudiodsp"
 mpegaudiodsp_select="dct"
+mpegvideo_select="videodsp"
 mpegvideoenc_select="mpegvideo"
 
-# decoders / encoders / hardware accelerators
+# decoders / encoders
 aac_decoder_select="mdct sinewin"
 aac_encoder_select="mdct sinewin"
 aac_latm_decoder_select="aac_decoder aac_latm_parser"
@@ -1675,18 +1676,9 @@ h261_decoder_select="error_resilience mpegvideo"
 h261_encoder_select="aandcttables mpegvideoenc"
 h263_decoder_select="error_resilience h263_parser mpegvideo"
 h263_encoder_select="aandcttables error_resilience mpegvideoenc"
-h263_vaapi_hwaccel_select="vaapi h263_decoder"
 h263i_decoder_select="h263_decoder"
 h263p_encoder_select="h263_encoder"
-h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
 h264_decoder_select="error_resilience golomb h264chroma h264dsp h264pred h264qpel mpegvideo"
-h264_dxva2_hwaccel_deps="dxva2api_h"
-h264_dxva2_hwaccel_select="dxva2 h264_decoder"
-h264_vaapi_hwaccel_select="vaapi h264_decoder"
-h264_vda_decoder_select="vda h264_parser h264_decoder"
-h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
-h264_vda_hwaccel_select="vda h264_decoder"
-h264_vdpau_decoder_select="vdpau h264_decoder"
 huffyuv_encoder_select="huffman"
 iac_decoder_select="fft mdct sinewin"
 imc_decoder_select="fft mdct sinewin"
@@ -1709,27 +1701,14 @@ mp3on4_decoder_select="mpegaudio"
 mp3on4float_decoder_select="mpegaudio"
 mpc7_decoder_select="mpegaudiodsp"
 mpc8_decoder_select="mpegaudiodsp"
-mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
 mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
 mpeg_xvmc_decoder_select="mpegvideo_decoder"
-mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
-mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
 mpeg1video_decoder_select="error_resilience mpegvideo"
 mpeg1video_encoder_select="aandcttables error_resilience mpegvideoenc"
-mpeg2_crystalhd_decoder_select="crystalhd"
-mpeg2_dxva2_hwaccel_deps="dxva2api_h"
-mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
-mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
-mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
 mpeg2video_decoder_select="error_resilience mpegvideo"
 mpeg2video_encoder_select="aandcttables error_resilience mpegvideoenc"
-mpeg4_crystalhd_decoder_select="crystalhd"
 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
 mpeg4_encoder_select="h263_encoder"
-mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
-mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
-mpegvideo_select="videodsp"
-msmpeg4_crystalhd_decoder_select="crystalhd"
 msmpeg4v1_decoder_select="h263_decoder"
 msmpeg4v1_encoder_select="h263_encoder"
 msmpeg4v2_decoder_select="h263_decoder"
@@ -1770,12 +1749,7 @@ truehd_decoder_select="mlp_parser"
 tscc_decoder_select="zlib"
 twinvq_decoder_select="mdct lsp sinewin"
 utvideo_encoder_select="huffman"
-vc1_crystalhd_decoder_select="crystalhd"
 vc1_decoder_select="h263_decoder h264chroma h264qpel"
-vc1_dxva2_hwaccel_deps="dxva2api_h"
-vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
-vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
-vc1_vdpau_decoder_select="vdpau vc1_decoder"
 vc1image_decoder_select="vc1_decoder"
 vorbis_decoder_select="mdct"
 vorbis_encoder_select="mdct"
@@ -1796,10 +1770,6 @@ wmv1_encoder_select="h263_encoder"
 wmv2_decoder_select="h263_decoder"
 wmv2_encoder_select="h263_encoder"
 wmv3_decoder_select="vc1_decoder"
-wmv3_crystalhd_decoder_select="crystalhd"
-wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
-wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
-wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
 wmv3image_decoder_select="wmv3_decoder"
 zerocodec_decoder_select="zlib"
 zlib_decoder_select="zlib"
@@ -1807,11 +1777,43 @@ zlib_encoder_select="zlib"
 zmbv_decoder_select="zlib"
 zmbv_encoder_select="zlib"
 
+# hardware accelerators
 crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 vaapi_deps="va_va_h"
 vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
 vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
 
+h263_vaapi_hwaccel_select="vaapi h263_decoder"
+h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
+h264_dxva2_hwaccel_deps="dxva2api_h"
+h264_dxva2_hwaccel_select="dxva2 h264_decoder"
+h264_vaapi_hwaccel_select="vaapi h264_decoder"
+h264_vda_decoder_select="vda h264_parser h264_decoder"
+h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
+h264_vda_hwaccel_select="vda h264_decoder"
+h264_vdpau_decoder_select="vdpau h264_decoder"
+mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
+mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
+mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
+mpeg2_crystalhd_decoder_select="crystalhd"
+mpeg2_dxva2_hwaccel_deps="dxva2api_h"
+mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
+mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
+mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
+mpeg4_crystalhd_decoder_select="crystalhd"
+mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
+mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
+msmpeg4_crystalhd_decoder_select="crystalhd"
+vc1_crystalhd_decoder_select="crystalhd"
+vc1_dxva2_hwaccel_deps="dxva2api_h"
+vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
+vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
+vc1_vdpau_decoder_select="vdpau vc1_decoder"
+wmv3_crystalhd_decoder_select="crystalhd"
+wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
+wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
+wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
+
 # parsers
 h264_parser_select="error_resilience golomb h264dsp h264pred mpegvideo"
 mpeg4video_parser_select="error_resilience mpegvideo"
diff --git a/libavcodec/anm.c b/libavcodec/anm.c
index c27ab1de1c7df677792ba06b6ed44e344e06c23e..d405213c827c9105ecfe5be431e1e50c1f4eb264 100644
--- a/libavcodec/anm.c
+++ b/libavcodec/anm.c
@@ -159,7 +159,7 @@ static int decode_frame(AVCodecContext *avctx,
                     break; // stop
                 if (type == 2) {
                     av_log_ask_for_sample(avctx, "unknown opcode");
-                    return AVERROR_INVALIDDATA;
+                    return AVERROR_PATCHWELCOME;
                 }
                 continue;
             }
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index 9c6d2901736efbb5d6841362795f47eb6090ec50..b323da4741156558611c3cccacaf4f28936b07bd 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -334,7 +334,7 @@ static int cinepak_decode (CinepakContext *s)
     if (s->sega_film_skip_bytes == -1) {
         if (!encoded_buf_size) {
             av_log_ask_for_sample(s->avctx, "encoded_buf_size is 0");
-            return AVERROR_INVALIDDATA;
+            return AVERROR_PATCHWELCOME;
         }
         if (encoded_buf_size != s->size && (s->size % encoded_buf_size) != 0) {
             /* If the encoded frame size differs from the frame size as indicated
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 63df2c71c4d2c96e9423ff670ceabdf63ad55d2e..81d6d012a22e4fe8a0bae08ba33f5c7c78f74183 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2942,7 +2942,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
                         av_log_ask_for_sample(s->avctx, NULL);
                         s->picture_structure = last_pic_structure;
                         s->droppable         = last_pic_droppable;
-                        return AVERROR_INVALIDDATA;
+                        return AVERROR_PATCHWELCOME;
                     }
 
                     /* Take ownership of this buffer. Note that if another thread owned
diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c
index b7d7bf0cd44457199ccbc23019d25a6f6ad9f094..7c8f7e9f360b4da4ff8f8b5ce25bd6577c38ae75 100644
--- a/libavcodec/pictordec.c
+++ b/libavcodec/pictordec.c
@@ -131,7 +131,7 @@ static int decode_frame(AVCodecContext *avctx,
     bpp            = bits_per_plane * s->nb_planes;
     if (bits_per_plane > 8 || bpp < 1 || bpp > 32) {
         av_log_ask_for_sample(avctx, "unsupported bit depth\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     if (bytestream2_peek_byte(&s->g) == 0xFF || bpp == 1 || bpp == 4 || bpp == 8) {
diff --git a/libavcodec/ptx.c b/libavcodec/ptx.c
index 91231a8baad0cc66f9332bfb99d9504de8e2deb7..720dad1b9436b0a52400816fbf7c601d95372fbf 100644
--- a/libavcodec/ptx.c
+++ b/libavcodec/ptx.c
@@ -57,7 +57,7 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     if (bytes_per_pixel != 2) {
         av_log_ask_for_sample(avctx, "Image format is not RGB15.\n");
-        return -1;
+        return AVERROR_PATCHWELCOME;
     }
 
     avctx->pix_fmt = AV_PIX_FMT_BGR555LE;
diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c
index 6378d6388d217437b97b88e46aa03ae1cffa6032..e2c1d2804acd829f6946868a13339a05f19544a1 100644
--- a/libavcodec/truemotion1.c
+++ b/libavcodec/truemotion1.c
@@ -356,7 +356,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
     if (s->flags & FLAG_SPRITE) {
         av_log_ask_for_sample(s->avctx, "SPRITE frame found.\n");
         /* FIXME header.width, height, xoffset and yoffset aren't initialized */
-        return -1;
+        return AVERROR_PATCHWELCOME;
     } else {
         s->w = header.xsize;
         s->h = header.ysize;
diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index e8a88cfb744ee1d93d4d4b7fd6c3352153b35e44..edaaea686afb11d05092d249d0ca5c98d44e0a3d 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -65,7 +65,7 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
 
     if (avctx->channels != 1) {
         av_log_ask_for_sample(avctx, "Unsupported channel count: %d\n", avctx->channels);
-        return AVERROR(EINVAL);
+        return AVERROR_PATCHWELCOME;
     }
 
     avctx->channel_layout = AV_CH_LAYOUT_MONO;
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index 066b572fc2208aa8e49c395786e92b936f09c944..4f372619ee8cfd1ebd2a90c71de1ee727942f013 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -203,7 +203,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     } else {
         av_log_ask_for_sample(avctx, "Unsupported extradata size\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     /* generic init */
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 3c1ca48f9f1c374dc8d4d26d0b746fc490591a37..41e07aa5f8b7f843166bd53310eb9c8d7e4adb67 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -299,7 +299,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     } else {
         av_log_ask_for_sample(avctx, "Unknown extradata size\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     /** generic init */
@@ -690,7 +690,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
         if (get_bits1(&s->gb)) {
             av_log_ask_for_sample(s->avctx,
                                   "unsupported channel transform bit\n");
-            return AVERROR_INVALIDDATA;
+            return AVERROR_PATCHWELCOME;
         }
 
         for (s->num_chgroups = 0; remaining_channels &&
@@ -1160,7 +1160,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
     /** no idea for what the following bit is used */
     if (get_bits1(&s->gb)) {
         av_log_ask_for_sample(s->avctx, "reserved bit set\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
 
diff --git a/libavformat/anm.c b/libavformat/anm.c
index 69a5ddab0f0fa109a2c3596ca8e772f461ea1eb0..f93c57e08a433ec9d88f46e690f32d82173d5049 100644
--- a/libavformat/anm.c
+++ b/libavformat/anm.c
@@ -86,7 +86,7 @@ static int read_header(AVFormatContext *s)
     avio_skip(pb, 4); /* magic number */
     if (avio_rl16(pb) != MAX_PAGES) {
         av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     anm->nb_pages   = avio_rl16(pb);
@@ -163,7 +163,7 @@ static int read_header(AVFormatContext *s)
 
 invalid:
     av_log_ask_for_sample(s, NULL);
-    return AVERROR_INVALIDDATA;
+    return AVERROR_PATCHWELCOME;
 }
 
 static int read_packet(AVFormatContext *s,
diff --git a/libavformat/au.c b/libavformat/au.c
index 55a32388ab737a34cfbfb648bf8af5201fd6c830..3648e89df36c20000a5a1fad50e8b748d114b35c 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -93,7 +93,7 @@ static int au_read_header(AVFormatContext *s)
 
     if (!(bps = av_get_bits_per_sample(codec))) {
         av_log_ask_for_sample(s, "could not determine bits per sample\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     if (channels == 0 || channels > 64) {
diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c
index b41fdb73e5392ea3fa0a2c2a3542842773e23765..aa41fa45c50f9e5c2972c0656ac12e6dd7ecce59 100644
--- a/libavformat/filmstripdec.c
+++ b/libavformat/filmstripdec.c
@@ -56,7 +56,7 @@ static int read_header(AVFormatContext *s)
     st->nb_frames = avio_rb32(pb);
     if (avio_rb16(pb) != 0) {
         av_log_ask_for_sample(s, "unsupported packing method\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     avio_skip(pb, 2);
diff --git a/libavformat/mtv.c b/libavformat/mtv.c
index 622a9b8f5ee6069bdf5b4adbd89fbb4d5e819615..5f39ec53685893a30a374275716ddd11f26c1d61 100644
--- a/libavformat/mtv.c
+++ b/libavformat/mtv.c
@@ -115,7 +115,7 @@ static int mtv_read_header(AVFormatContext *s)
 
     if (audio_subsegments == 0) {
         av_log_ask_for_sample(s, "MTV files without audio are not supported\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     mtv->full_segment_size =
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index acc2a6df6ca6dec9e6d4b4ea1f3de74b31d9092d..794a7754dbfedf0eeedd7f8d83308f2e24d7e1cb 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -220,8 +220,8 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
     if (av_size_mult(ogg->nstreams + 1, sizeof(*ogg->streams), &size) < 0 ||
         !(os = av_realloc(ogg->streams, size)))
         return AVERROR(ENOMEM);
-    ogg->streams      = os;
-    os                = ogg->streams + idx;
+    ogg->streams = os;
+    os           = ogg->streams + idx;
     memset(os, 0, sizeof(*os));
     os->serial        = serial;
     os->bufsize       = DECODER_BUFFER_SIZE;
@@ -374,6 +374,8 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 
     if (os->bufsize - os->bufpos < size) {
         uint8_t *nb = av_malloc((os->bufsize *= 2) + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (!nb)
+            return AVERROR(ENOMEM);
         memcpy(nb, os->buf, os->bufpos);
         av_free(os->buf);
         os->buf = nb;
diff --git a/libavformat/rsodec.c b/libavformat/rsodec.c
index d8ed695fdff3a75691de29ba94bc9dc7829bdaeb..aae80a82215ddf4520513dd7cc5353f4ae22dac5 100644
--- a/libavformat/rsodec.c
+++ b/libavformat/rsodec.c
@@ -50,7 +50,7 @@ static int rso_read_header(AVFormatContext *s)
     bps = av_get_bits_per_sample(codec);
     if (!bps) {
         av_log_ask_for_sample(s, "could not determine bits per sample\n");
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     /* now we are ready: build format streams */
diff --git a/libavformat/smjpegdec.c b/libavformat/smjpegdec.c
index ceb29c9b5f16ba2ebc4bcba57f96cac67652d254..f32f635d5fe61f5e55c81f8f922b5560f68353d6 100644
--- a/libavformat/smjpegdec.c
+++ b/libavformat/smjpegdec.c
@@ -78,7 +78,7 @@ static int smjpeg_read_header(AVFormatContext *s)
         case SMJPEG_SND:
             if (ast) {
                 av_log_ask_for_sample(s, "multiple audio streams not supported\n");
-                return AVERROR_INVALIDDATA;
+                return AVERROR_PATCHWELCOME;
             }
             hlength = avio_rb32(pb);
             if (hlength < 8)
diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index cd9a7d4052c58923648649d3598cb1a82dd45332..aaf0568763c95915126575d1abaf2dcd059b70ba 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -414,7 +414,7 @@ static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
          * distribute the TrueHD frames in the MAT frame */
         av_log(s, AV_LOG_ERROR, "TrueHD frame too big, %d bytes\n", pkt->size);
         av_log_ask_for_sample(s, NULL);
-        return AVERROR_INVALIDDATA;
+        return AVERROR_PATCHWELCOME;
     }
 
     memcpy(&ctx->hd_buf[ctx->hd_buf_count * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + mat_code_length],