]> git.alsa-project.org Git - tinycompress.git/commitdiff
utils: cplay: Reset file cursor after MP3 header parse
authorLaurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
Fri, 26 Aug 2022 08:52:38 +0000 (11:52 +0300)
committerVinod Koul <3178504+vinodkoul@users.noreply.github.com>
Mon, 19 Sep 2022 08:56:18 +0000 (14:26 +0530)
We need to reset the file cursor to the beginning of the file.

Initially, the program would simply get stuck polling the
compress fd. This was probably because of the fact that the
codec would hang because of the fact that it was expecting
to receive the MP3 data along with its associated MP3 header.

This was not the case for the first (header, data) pair because,
after parsing the first header, the file cursor would point
at the beginning of the data region.

By resetting the file cursor to the beginning of the file,
the codec will receive all the (header, data) pairs it
actually expects.

Suggested-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
src/utils/cplay.c

index ebb9328afb2bebd4962bc56e5c9eb4e20de7e8a2..4604c36956703e689d740afe1fc1a43df4c5979d 100644 (file)
@@ -526,6 +526,26 @@ void get_codec_mp3(FILE *file, struct compr_config *config,
        codec->level = 0;
        codec->ch_mode = 0;
        codec->format = 0;
+
+       /* reset file cursor to start
+        *
+        * this is done because if we leave it as is
+        * the program will hang in a poll call waiting
+        * for ring buffer to empty out.
+        *
+        * this never actually happens because of the fact
+        * that the codec probably expects to receive the
+        * MP3 header along with its associated MP3 data
+        * so, if we leave the file cursor positioned at
+        * the first MP3 data then the codec will most
+        * likely hang because it's expecting to also get
+        * the MP3 header
+        */
+       if (fseek(file, 0, SEEK_SET) < 0) {
+               fprintf(stderr, "Failed to set cursor to start.\n");
+               fclose(file);
+               exit(EXIT_FAILURE);
+       }
 }
 
 void get_codec_iec(FILE *file, struct compr_config *config,