<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: 宋体, sans-serif; "><div><span class="Apple-style-span" style="font-size: medium; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">hi</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">I need some help with decoding AAC stream of audio. I get audio data via socket. It is neccessary to create AVCodecContext separately, not from AVFormatContext->streams[...]->codec;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">First i create AVCodec, AVCOdecContext and encode PCM data to AAC packet:</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "> avcodec_init<span style="color: rgb(0, 0, 0); ">();</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span>avcodec_register_all<span style="color: rgb(0, 0, 0); ">();</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">AVCodec<span style="color: rgb(0, 0, 0); "> *</span></span><span style="color: rgb(62, 130, 135); ">encode</span><span style="color: rgb(0, 0, 0); "> = </span>avcodec_find_encoder<span style="color: rgb(0, 0, 0); ">(</span>CODEC_ID_AAC<span style="color: rgb(0, 0, 0); ">);</span></p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> <span style="color: rgb(200, 36, 157); ">if</span> (!<span style="color: rgb(62, 130, 135); ">encode</span>) </p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> {</p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(226, 20, 31); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(128, 70, 46); ">DBLog</span><span style="color: rgb(0, 0, 0); ">(</span>"codec not found codec\n"<span style="color: rgb(0, 0, 0); ">);</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 132, 35); "><span style="color: rgb(0, 0, 0); "> </span>//exit(1);</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> }</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">AVCodecContext</span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> *</span></span><span style="color: rgb(62, 130, 135); ">encodeContext</span><span style="color: rgb(0, 0, 0); ">= </span>avcodec_alloc_context<span style="color: rgb(0, 0, 0); ">();</span></p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 132, 35); "><span style="color: rgb(0, 0, 0); "> </span>/* put sample parameters*/</p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>encodeContext<span style="color: rgb(0, 0, 0); ">-></span>sample_fmt<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(35, 90, 93); ">AV_SAMPLE_FMT_S16</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>encodeContext<span style="color: rgb(0, 0, 0); ">-></span>bit_rate<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">128000</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>encodeContext<span style="color: rgb(0, 0, 0); ">-></span>sample_rate<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">44100.00</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>encodeContext<span style="color: rgb(0, 0, 0); ">-></span>channels<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">2</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(200, 36, 157); ">if</span><span style="color: rgb(0, 0, 0); "> (</span><span style="color: rgb(35, 90, 93); ">avcodec_open</span><span style="color: rgb(0, 0, 0); ">(</span>encodeContext<span style="color: rgb(0, 0, 0); ">, </span>encode<span style="color: rgb(0, 0, 0); ">) < </span><span style="color: rgb(0, 55, 209); ">0</span><span style="color: rgb(0, 0, 0); ">) {</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(226, 20, 31); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(128, 70, 46); ">DBLog</span><span style="color: rgb(0, 0, 0); ">(</span>"could not open codec\n"<span style="color: rgb(0, 0, 0); ">);</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 132, 35); "><span style="color: rgb(0, 0, 0); "> </span>//exit(1);</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> }</p><div style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); "><br></div><div><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(200, 36, 157); "> char</span> buffer[<span style="color: rgb(0, 55, 209); ">2048</span>];</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> <span style="color: rgb(200, 36, 157); ">int</span> size = <span style="color: rgb(0, 55, 209); ">0</span>;</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> size = <span style="color: rgb(35, 90, 93); ">avcodec_encode_audio</span>(<span style="color: rgb(62, 130, 135); ">encodeContext</span>, (<span style="color: rgb(116, 64, 164); ">uint8_t</span>*)buffer, <span style="color: rgb(0, 55, 209); ">2048</span>, (<span style="color: rgb(200, 36, 157); ">short</span>*)pcm_buffer);</p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></p><p style="font-weight: normal; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3"> This step works well, I can encode audio data successfully, then I send the data in buffer and it's size to remote device via socket, at the other side, I try to decode audio data to PCM:</font></p><p style="font-weight: normal; font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "> avcodec_init<span style="color: rgb(0, 0, 0); ">();</span></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span>avcodec_register_all<span style="color: rgb(0, 0, 0); ">();</span></p><p style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "><font class="Apple-style-span" size="3"> </font> </span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">AVCodec<span style="color: rgb(0, 0, 0); "> *</span></span><span style="color: rgb(62, 130, 135); ">decode</span><span style="color: rgb(0, 0, 0); "> = </span>avcodec_find_decoder<span style="color: rgb(0, 0, 0); ">(</span>CODEC_ID_AAC<span style="color: rgb(0, 0, 0); ">);</span></p><div style="font-weight: normal; "><span class="Apple-style-span" style="color: rgb(62, 130, 135); "> AVCodecContext<span style="color: rgb(0, 0, 0); "> *</span></span><span class="Apple-style-span" style="color: rgb(35, 90, 93); "><span style="color: rgb(62, 130, 135); ">decodeContext</span><span style="color: rgb(0, 0, 0); "> = </span>avcodec_alloc_context<span style="color: rgb(0, 0, 0); ">();</span></span><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>decodeContext<span style="color: rgb(0, 0, 0); ">-></span>sample_fmt<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(35, 90, 93); ">AV_SAMPLE_FMT_S16</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>decodeContext<span style="color: rgb(0, 0, 0); ">-></span>bit_rate<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">128000</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>decodeContext<span style="color: rgb(0, 0, 0); ">-></span>sample_rate<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">44100.00</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span>decodeContext<span style="color: rgb(0, 0, 0); ">-></span>channels<span style="color: rgb(0, 0, 0); "> = </span><span style="color: rgb(0, 55, 209); ">2</span><span style="color: rgb(0, 0, 0); ">;</span></p><p style="font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span>av_init_packet<span style="color: rgb(0, 0, 0); ">(&</span><span style="color: rgb(62, 130, 135); ">avpkt</span><span style="color: rgb(0, 0, 0); ">);</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); font-size: 14px; "><span style="color: rgb(0, 0, 0); "></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "> ……</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "> AudioData<span style="color: rgb(0, 0, 0); ">* data = [</span>receivedAudioDataArray<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(61, 34, 125); ">objectAtIndex</span><span style="color: rgb(0, 0, 0); ">:i</span>ndex<span style="color: rgb(0, 0, 0); ">];//received AAC data is in receivedAudioDataArray</span></p><p></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(35, 90, 93); "><span style="color: rgb(0, 0, 0); "> </span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">avpkt</span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); ">.</span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">data</span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> = (</span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(116, 64, 164); ">uint8_t</span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); ">*)[data.</span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); ">audioData</span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(61, 34, 125); ">bytes</span></span><span class="Apple-style-span" style="color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); ">];//</span></span></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> <span style="color: rgb(62, 130, 135); ">avpkt</span>.<span style="color: rgb(62, 130, 135); ">size</span> = data.<span style="color: rgb(62, 130, 135); ">bytes</span>;</p><p style="font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "> </p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 130, 135); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(200, 36, 157); ">if</span><span style="color: rgb(0, 0, 0); "> (</span><span style="color: rgb(35, 90, 93); ">avcodec_open</span><span style="color: rgb(0, 0, 0); ">(</span>decodeContext<span style="color: rgb(0, 0, 0); ">, </span>decode<span style="color: rgb(0, 0, 0); ">) < </span><span style="color: rgb(0, 55, 209); ">0</span><span style="color: rgb(0, 0, 0); ">) {</span></p><p style="font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(226, 20, 31); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(128, 70, 46); ">DBLog</span><span style="color: rgb(0, 0, 0); ">(</span>"could not open decodec\n"<span style="color: rgb(0, 0, 0); ">);</span></p><p style="font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> <span style="color: rgb(128, 70, 46); ">assert</span>(<span style="color: rgb(0, 55, 209); ">0</span>);</p><p style="font-size: 14px; color: rgb(0, 0, 0); margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "> }</p><div style="font-size: 14px; color: rgb(0, 0, 0); "><br></div></div><div style="color: rgb(0, 0, 0); "><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(200, 36, 157); "> int</span> len = <span style="color: rgb(35, 90, 93); ">avcodec_decode_audio3</span>(<span style="color: rgb(62, 130, 135); ">decodeContext</span>, (<span style="color: rgb(200, 36, 157); ">short</span> *)pcm_buffer, &out_size, &<span style="color: rgb(62, 130, 135); ">avpkt</span>);</p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></p><p style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-style-span" style="font-size: 14px; "> </span><font class="Apple-style-span" size="3">When decode received data to PCM, I always get –1, and get console log:</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><b>channel element -1073948900.-1073948920 is not allocated</b></p><p style="font-weight: normal; font-size: 14px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><b><br></b></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3">I have been confused for one week, I want to know if my way is correct or not? Is something wrong with decodeContext's parameter? How can I decode audio data correctly? It is very appreciate to have your help, thank you.</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3"><br></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3">----</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3">Best Regards</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><font class="Apple-style-span" size="3">Kong </font></p></div></div></span></div></body></html>