diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c
index e0a8e63a8bb65b3d73d1be6384a3ec8e0447f898..babb85a07b581ed8325bc5d4656356f39e95ba00 100644
--- a/libavcodec/cbrt_tablegen.c
+++ b/libavcodec/cbrt_tablegen.c
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include "libavutil/libm.h"
 #define CONFIG_HARDCODED_TABLES 0
 #include "cbrt_tablegen.h"
 #include "tableprint.h"
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 965ead6c163eac242f9c98f6ca29fb3823e094f5..36df84f741b6a2f100d3ddcfa71ad91b4638d43d 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -391,20 +391,26 @@ static const uint64_t aac_channel_layout[] = {
     0,
 };
 
+static const int aac_sample_rates[] = {
+    96000, 88200, 64000, 48000, 44100, 32000,
+    24000, 22050, 16000, 12000, 11025, 8000, 0
+};
+
 AVCodec ff_libfdk_aac_encoder = {
-    .name            = "libfdk_aac",
-    .type            = AVMEDIA_TYPE_AUDIO,
-    .id              = AV_CODEC_ID_AAC,
-    .priv_data_size  = sizeof(AACContext),
-    .init            = aac_encode_init,
-    .encode2         = aac_encode_frame,
-    .close           = aac_encode_close,
-    .capabilities    = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
-    .sample_fmts     = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
-                                                      AV_SAMPLE_FMT_NONE },
-    .long_name       = NULL_IF_CONFIG_SMALL("Fraunhofer FDK AAC"),
-    .priv_class      = &aac_enc_class,
-    .defaults        = aac_encode_defaults,
-    .profiles        = profiles,
-    .channel_layouts = aac_channel_layout,
+    .name                  = "libfdk_aac",
+    .type                  = AVMEDIA_TYPE_AUDIO,
+    .id                    = AV_CODEC_ID_AAC,
+    .priv_data_size        = sizeof(AACContext),
+    .init                  = aac_encode_init,
+    .encode2               = aac_encode_frame,
+    .close                 = aac_encode_close,
+    .capabilities          = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
+    .sample_fmts           = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
+                                                            AV_SAMPLE_FMT_NONE },
+    .long_name             = NULL_IF_CONFIG_SMALL("Fraunhofer FDK AAC"),
+    .priv_class            = &aac_enc_class,
+    .defaults              = aac_encode_defaults,
+    .profiles              = profiles,
+    .supported_samplerates = aac_sample_rates,
+    .channel_layouts       = aac_channel_layout,
 };
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index e951032722c37b2160932e9d3eff22b3f32c309e..c0a872eba04240a8062899df7ffa3255927317af 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -387,6 +387,10 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
         p->got_frame = 0;
         p->result = codec->decode(avctx, &p->frame, &p->got_frame, &p->avpkt);
 
+        /* many decoders assign whole AVFrames, thus overwriting extended_data;
+         * make sure it's set correctly */
+        p->frame.extended_data = p->frame.data;
+
         if (p->state == STATE_SETTING_UP) ff_thread_finish_setup(avctx);
 
         pthread_mutex_lock(&p->progress_mutex);
diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c
index 4810357d0395d08b94ae897d5a6fd50dee04d7ef..6bea4ec2a87fc580a51354fa2cba79a3a9b213a8 100644
--- a/libavformat/oggparsetheora.c
+++ b/libavformat/oggparsetheora.c
@@ -53,7 +53,8 @@ theora_header (AVFormatContext * s, int idx)
         os->private = thp;
     }
 
-    if (os->buf[os->pstart] == 0x80) {
+    switch (os->buf[os->pstart]) {
+    case 0x80: {
         GetBitContext gb;
         int width, height;
         AVRational timebase;
@@ -109,9 +110,16 @@ theora_header (AVFormatContext * s, int idx)
         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
         st->codec->codec_id = AV_CODEC_ID_THEORA;
         st->need_parsing = AVSTREAM_PARSE_HEADERS;
-
-    } else if (os->buf[os->pstart] == 0x81) {
-        ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8);
+    }
+    break;
+    case 0x81:
+        ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8);
+    case 0x82:
+        if (!thp->version)
+            return -1;
+        break;
+    default:
+        return -1;
     }
 
     st->codec->extradata = av_realloc (st->codec->extradata,