title: How to build the Exoplayer ffmpeg extension with the GSM codec?
body: <p>I wanted to use Exoplayer to play an audio file but when I tried I got this exception:</p>
  
  <pre><code>2019-12-13 10:08:14.827 28972-29388/com.XXX.XXX E/ExoPlayerImplInternal: Source error.
      com.google.android.exoplayer2.ParserException: Expected block alignment: 0; got: 65
          at com.google.android.exoplayer2.extractor.wav.WavHeaderReader.peek(WavHeaderReader.java:81)
          at com.google.android.exoplayer2.extractor.wav.WavExtractor.sniff(WavExtractor.java:50)
          at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractorHolder.selectExtractor(ProgressiveMediaPeriod.java:1061)
          at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:952)
          at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:394)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
          at java.lang.Thread.run(Thread.java:764)
  </code></pre>
  
  <p>The audio files I have to play are wav files (GSM_MS, 13kb/s)</p>
  
  <p>I tried to build the the Exoplayer Ffmpeg extension following the tutorial:
  <a href="https://github.com/google/ExoPlayer/tree/release-v2/extensions/ffmpeg" rel="nofollow noreferrer">https://github.com/google/ExoPlayer/tree/release-v2/extensions/ffmpeg</a></p>
  
  <p>I cloned the Exoplayer repository and I downloaded the Android NDK version r20b.</p>
  
  <p>I modified the build script build_ffmpeg.sh to enable the libgsm:</p>
  
  <pre><code>COMMON_OPTIONS=“
  …
     —enable-libgsm
  "
  
  </code></pre>
  
  <p>I defined the required environment variables:</p>
  
  <ul>
  <li>FFMPEG_EXT_PATH=“/extensions/ffmpeg/src/main/jni” </li>
  <li>NDK_PATH="/Users/USER/Documents/Android/android-ndk-r20b/"</li>
  <li>HOST_PLATFORM(“darwin-x86_64”)</li>
  <li>ENABLED_DECODERS(all the decoders available <a href="https://exoplayer.dev/supported-formats.html#ffmpeg-extension" rel="nofollow noreferrer">https://exoplayer.dev/supported-formats.html#ffmpeg-extension</a>)</li>
  </ul>
  
  <p>Then I built the library using the provided command line:</p>
  
  <pre><code>cd "${FFMPEG_EXT_PATH}" &amp;&amp; \
  ./build_ffmpeg.sh \
   "${FFMPEG_EXT_PATH}" "${NDK_PATH}" "${HOST_PLATFORM}" "${ENABLED_DECODERS[@]}"
  </code></pre>
  
  <p>But something goes wrong during the build process:</p>
  
  <pre><code>remote: Enumerating objects: 38, done.
  remote: Counting objects: 100% (38/38), done.
  remote: Compressing objects: 100% (26/26), done.
  remote: Total 26 (delta 20), reused 0 (delta 0)
  Unpacking objects: 100% (26/26), done.
  From git://source.ffmpeg.org/ffmpeg
    377a095dc3..bd83191271  master     -&gt; origin/master
  Already up to date.
  Already on 'release/4.2'
  Your branch is up to date with 'origin/release/4.2'.
  ERROR: libgsm not found
  
  If you think configure made a mistake, make sure you are using the latest
  version from Git.  If the latest version fails, report the problem to the
  ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
  Include the log file "ffbuild/config.log" produced by configure as this will help
  solve the problem.
  GEN libavutil/libavutil.version
  GEN libswresample/libswresample.version
  GEN libavresample/libavresample.version
  GEN libavcodec/libavcodec.version
  CC  libavcodec/aac_ac3_parser.o
  CC  libavcodec/aacdec.o
  CC  libavcodec/aacps_float.o
  CC  libavcodec/aacpsdsp_float.o
  CC  libavcodec/aacsbr.o
  CC  libavcodec/aactab.o
  CC  libavcodec/ac3.o
  CC  libavcodec/ac3_parser.o
  CC  libavcodec/ac3dec_data.o
  CC  libavcodec/ac3dec_float.o
  </code></pre>
  
  <p>Here is a part of the content of the config.log file located in the ffmpeg checked out library (/extensions/ffmpeg/src/main/jni/ffmpeg/ffbuild/config.log:</p>
  
  <pre><code>…
  /Users/USER/Documents/Android/android-ndk-r20b/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android16-clang -march=i686 -Wl,--as-needed -Wl,-z,noexecstack -pie -fPIE -pie -o /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.o
  /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.o:test.c:function foo: error: undefined reference to 'cexp'
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  check_lib libgsm gsm.h gsm_create -lgsm
  check_func_headers gsm.h gsm_create -lgsm
  test_ld cc -lgsm
  test_cc
  BEGIN /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.c
      1   #include &lt;gsm.h&gt;
      2   #include &lt;stdint.h&gt;
      3   long check_gsm_create(void) { return (long) gsm_create; }
      4   int main(void) { int ret = 0;
      5    ret |= ((intptr_t)check_gsm_create) &amp; 0xFFFF;
      6   return ret; }
  END /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.c
  /Users/USER/Documents/Android/android-ndk-r20b/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android16-clang -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Dstrtod=avpriv_strtod -DPIC -march=i686 -std=c11 -fPIE -fomit-frame-pointer -fPIC -pthread -c -o /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.o /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.c
  /var/folders/9l/trkjpc091_79vk3krfpykbsh0000gn/T//ffconf.hv2yROG1/test.c:1:10: fatal error: 'gsm.h' file not found
  …
  </code></pre>
  
  <p>The gsm.h file is located there: /extensions/ffmpeg/src/main/jni/ffmpeg/libavcodec</p>
  
  <p>I assume this path has been configured to be used by the build script.</p>
  
  <p>Any help is much appreciated.</p>