From: Laurentiu Mihalcea Date: Fri, 26 Aug 2022 08:52:38 +0000 (+0300) Subject: utils: cplay: Reset file cursor after MP3 header parse X-Git-Tag: v1.2.8~7 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=f9fe0e3e0cc21b9550d30850fb06f68aeabc9337;p=tinycompress.git utils: cplay: Reset file cursor after MP3 header parse 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 Signed-off-by: Laurentiu Mihalcea --- diff --git a/src/utils/cplay.c b/src/utils/cplay.c index ebb9328..4604c36 100644 --- a/src/utils/cplay.c +++ b/src/utils/cplay.c @@ -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,