diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index c2d7d05..b8cc1b6 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -2897,6 +2897,78 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
     return 0;
 }
 
+/**
+ * Make AAC audio config object.
+ * @see 1.6.2.1 "Syntax - AudioSpecificConfig"
+ */
+
+static void put_audio_specific_config(AVCodecContext *avctx,int sr_index,int channels)
+{
+    PutBitContext pb;
+
+    init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8);
+    if(avctx->extradata_size == 2)
+    {
+        put_bits(&pb, 5, 2); //object type: AAC-LC = 2, AAC-HE = SBR = 5
+        put_bits(&pb, 4, sr_index); //sample rate index
+        put_bits(&pb, 4, channels);
+        //GASpecificConfig
+        put_bits(&pb, 1, 0); //frame length - 1024 samples
+        put_bits(&pb, 1, 0); //does not depend on core coder
+        put_bits(&pb, 1, 0); //is not extension
+    }
+    else
+    {
+        uint8_t temp;
+        const uint16_t    ui16SyncExtensionType = 0x2B7;
+        int       ui32Extn_sr_index;
+        
+        for(ui32Extn_sr_index = 0; ui32Extn_sr_index < 16; ui32Extn_sr_index++)
+            if((avctx->sample_rate>>1) == avpriv_mpeg4audio_sample_rates[ui32Extn_sr_index])
+                break;
+
+        if(ui32Extn_sr_index == 16)
+        {
+            av_log(avctx, AV_LOG_ERROR, "Unsupported Extn sample rate %d\n", avctx->sample_rate);
+            return;
+        }
+
+        temp = (2 << 3) | ((ui32Extn_sr_index & 0x0E)>>1);
+        put_bits(&pb, 8, temp);                             //0th byte
+
+        if(avctx->extradata_size == 5)
+            temp = ((ui32Extn_sr_index & 0x01) << 7) | (channels << 3);
+        else
+            temp = ((ui32Extn_sr_index & 0x01) << 7) | (1 << 3);
+        put_bits(&pb, 8, temp);                             //1 st byte
+
+        temp = (ui16SyncExtensionType >> 3) & 0xFF;
+        put_bits(&pb, 8, temp);                             // 2nd byte
+
+        temp = ((ui16SyncExtensionType & 0x7) << 5) | 5 ; /* ext ot id */
+        put_bits(&pb, 8, temp);                             // 3rd byte
+
+        if(avctx->extradata_size == 5)
+        {
+            temp = ((1 & 0x1) << 7) | (sr_index << 3);
+            put_bits(&pb, 8, temp);                        // 4th byte
+        }
+        else
+        {
+            temp = ((1 & 0x1) << 7) | (sr_index << 3) | 5;  // 4th byte
+            put_bits(&pb, 8, temp);
+
+            temp = 0x48;
+            put_bits(&pb, 8, temp);                        // 5th Byte
+
+            temp = 0x80;
+            put_bits(&pb, 8, temp);                         // 6th Byte
+
+        }
+    }
+    flush_put_bits(&pb);
+}
+
 static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
                                 int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt)
 {
@@ -3046,6 +3118,27 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
         ac->oc[1].status = OC_LOCKED;
     }
 
+    if(!avctx->extradata_size)
+    {
+       int sr_index;
+       avctx->extradata_size = 2;
+
+       if(ac->oc[1].m4ac.sbr == 1)
+          avctx->extradata_size = 5;
+       if(ac->oc[1].m4ac.ps == 1)
+          avctx->extradata_size = 7;
+       avctx->extradata = av_mallocz(avctx->extradata_size);
+       for(sr_index = 0; sr_index < 16; sr_index++)
+          if(avctx->sample_rate == avpriv_mpeg4audio_sample_rates[sr_index])
+             break;
+       if(sr_index == 16)
+       {
+          av_log(NULL, AV_LOG_ERROR, "Unsupported sample rate %d\n",avctx->sample_rate);
+          return 0;
+       }
+       put_audio_specific_config(avctx,sr_index,avctx->channels);
+    }
+
     if (multiplier) {
         int side_size;
         const uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
