<div dir="ltr"><div dir="ltr">Hello,<div>I am doing some AAC audio encoding for an Android app.</div><div><br></div><div>Audio samples from Google's Oboe library are packed so it makes sense to keep the packed sample format when possible. When adding in a sample format check, the documentation and examples state that the available sample formats array should terminate with -1 (AV_SAMPLE_FMT_NONE). I'm not seeing the array terminated correctly in my case. </div><div><br></div><div>I cannot use AV_SAMPLE_FMT_NB because I am dynamically linking to ffmpeg binaries. </div><div><br></div><div>Here's the simple sample format check function:</div><div><br></div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"Droid Sans Mono";font-size:9.8pt"><span style="color:rgb(204,120,50)">int </span><span style="color:rgb(181,182,227)">FrequencyEngine</span>::<span style="color:rgb(255,198,109)">check_sample_fmt</span><span style="color:rgb(152,118,170);font-style:italic">(</span><span style="color:rgb(204,120,50)">const </span><span style="color:rgb(185,188,209)">AVCodec </span>*codec<span style="color:rgb(204,120,50)">, enum </span><span style="color:rgb(181,182,227)">AVSampleFormat </span>sample_fmt<span style="color:rgb(152,118,170);font-style:italic">) {<br></span><span style="color:rgb(152,118,170);font-style:italic">    </span><span style="color:rgb(204,120,50)">const enum </span><span style="color:rgb(181,182,227)">AVSampleFormat </span>*p = codec-><span style="color:rgb(147,115,165)">sample_fmts</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)">    const enum </span><span style="color:rgb(181,182,227)">AVSampleFormat </span>*f = codec-><span style="color:rgb(147,115,165)">sample_fmts</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"><br></span><span style="color:rgb(204,120,50)"><br></span><span style="color:rgb(204,120,50)">    for </span><span style="color:rgb(152,118,170);font-style:italic">(</span><span style="color:rgb(204,120,50)">int </span>i = <span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">; </span>i < <span style="color:rgb(104,151,187)">13</span><span style="color:rgb(204,120,50)">; </span>i++<span style="color:rgb(152,118,170);font-style:italic">) {<br></span><span style="color:rgb(152,118,170);font-style:italic">        </span>__android_log_print<span style="color:rgb(152,118,170);font-style:italic">(ANDROID_LOG_VERBOSE</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">FREQUENCY_ENGINE_TAG</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                            </span><span style="color:rgb(106,135,89)">"Encoder format supported %s, enum value %d"</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                            </span>av_get_sample_fmt_name<span style="color:rgb(152,118,170);font-style:italic">(</span>*f<span style="color:rgb(152,118,170);font-style:italic">)</span><span style="color:rgb(204,120,50)">, </span>*f<span style="color:rgb(152,118,170);font-style:italic">)</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)">        </span>f++<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"><br></span><span style="color:rgb(204,120,50)">    </span><span style="color:rgb(152,118,170);font-style:italic">}<br></span><span style="color:rgb(152,118,170);font-style:italic">    </span><span style="color:rgb(204,120,50)">while </span><span style="color:rgb(152,118,170);font-style:italic">(AV_SAMPLE_FMT_NONE </span>!= *p<span style="color:rgb(152,118,170);font-style:italic">) {<br></span><span style="color:rgb(152,118,170);font-style:italic"><br></span><span style="color:rgb(152,118,170);font-style:italic">        </span>__android_log_print<span style="color:rgb(152,118,170);font-style:italic">(ANDROID_LOG_VERBOSE</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">FREQUENCY_ENGINE_TAG</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                            </span><span style="color:rgb(106,135,89)">"Searching format supported %s"</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                            </span>av_get_sample_fmt_name<span style="color:rgb(152,118,170);font-style:italic">(</span>*p<span style="color:rgb(152,118,170);font-style:italic">))</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)">        if </span><span style="color:rgb(152,118,170);font-style:italic">(</span>*p == sample_fmt<span style="color:rgb(152,118,170);font-style:italic">) {<br></span><span style="color:rgb(152,118,170);font-style:italic">            </span>__android_log_print<span style="color:rgb(152,118,170);font-style:italic">(ANDROID_LOG_VERBOSE</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(144,139,37)">FREQUENCY_ENGINE_TAG</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"Format found! %s"</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                                </span>av_get_sample_fmt_name<span style="color:rgb(152,118,170);font-style:italic">(</span>*p<span style="color:rgb(152,118,170);font-style:italic">))</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)">            return </span><span style="color:rgb(104,151,187)">1</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)">        </span><span style="color:rgb(152,118,170);font-style:italic">}<br></span><span style="color:rgb(152,118,170);font-style:italic"><br></span><span style="color:rgb(152,118,170);font-style:italic">        </span>p++<span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(204,120,50)"><br></span><span style="color:rgb(204,120,50)">    </span><span style="color:rgb(152,118,170);font-style:italic">}<br></span><span style="color:rgb(152,118,170);font-style:italic">    </span><span style="color:rgb(204,120,50)">return </span><span style="color:rgb(104,151,187)">0</span><span style="color:rgb(204,120,50)">;<br></span><span style="color:rgb(152,118,170);font-style:italic">}</span></pre></div><div>In this function I am just incrementing the pointer 13 times as that's the max possible formats. Then I am also using a while loop on the sample format pointer again (as I would in production code). This is where we should be getting the -1 to terminate the array, but the -1 terminator is the second entry in the array, see log printout:</div><div><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div><img src="cid:ii_keyjc5cj0" alt="Screen Shot 2020-09-11 at 12.46.35 PM.png" width="542" height="404"><br></div></div><div><div><br></div><div>According to the while loop, the only available format would be AV_SAMPLE_FMT_FLTP, evidenced by that being the one format before -1, but when I explicitly set the format to AV_SAMPLE_FMT_FLT or any of the formats listed in the log from the first for loop, the encoder accepts this format still and works. Because of this discrepancy, I don't know how to properly check available sample formats for production.</div></div><div><br></div><div>Regards,<br></div><div><br></div></div></div></div></div></div></div></div></div>