summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c70
1 files changed, 43 insertions, 27 deletions
diff --git a/apps/playback.c b/apps/playback.c
index aa4471ab33..9a7c9e2bf6 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -921,8 +921,23 @@ static void audio_rebuffer(void)
921 logf("Forcing rebuffer"); 921 logf("Forcing rebuffer");
922 922
923 /* Notify the codec that this will take a while */ 923 /* Notify the codec that this will take a while */
924 if (!filling) 924 /* Currently this can cause some problems (logf in reverse order):
925 queue_post(&codec_callback_queue, Q_CODEC_REQUEST_PENDING, 0); 925 * Codec load error:-1
926 * Codec load disk
927 * Codec: Unsupported
928 * Codec finished
929 * New codec:0/3
930 * Clearing tracks:7/7, 1
931 * Forcing rebuffer
932 * Check new track buffer
933 * Request new track
934 * Clearing tracks:5/5, 0
935 * Starting buffer fill
936 * Clearing tracks:5/5, 1
937 * Re-buffering song w/seek
938 */
939 //if (!filling)
940 // queue_post(&codec_callback_queue, Q_CODEC_REQUEST_PENDING, 0);
926 941
927 /* Stop in progress fill, and clear open file descriptor */ 942 /* Stop in progress fill, and clear open file descriptor */
928 if (current_fd >= 0) 943 if (current_fd >= 0)
@@ -935,6 +950,7 @@ static void audio_rebuffer(void)
935 /* Reset buffer and track pointers */ 950 /* Reset buffer and track pointers */
936 buf_ridx = buf_widx = 0; 951 buf_ridx = buf_widx = 0;
937 track_widx = track_ridx; 952 track_widx = track_ridx;
953 cur_ti = &tracks[track_ridx];
938 audio_clear_track_entries(true, true); 954 audio_clear_track_entries(true, true);
939 filebufused = 0; 955 filebufused = 0;
940 956
@@ -1111,16 +1127,12 @@ static void rebuffer_and_seek(size_t newpos)
1111 ci.curpos = newpos; 1127 ci.curpos = newpos;
1112 1128
1113 /* Clear codec buffer. */ 1129 /* Clear codec buffer. */
1114 filebufused = 0;
1115 buf_widx = cur_ti->buf_idx + newpos;
1116 while (buf_widx >= filebuflen)
1117 buf_widx -= filebuflen;
1118 buf_ridx = buf_widx;
1119
1120 /* Write to the now current track */
1121 track_widx = track_ridx; 1130 track_widx = track_ridx;
1131 filebufused = 0;
1132 buf_widx = buf_ridx = 0;
1122 1133
1123 last_peek_offset = 0; 1134 last_peek_offset = 0;
1135 filling = false;
1124 initialize_buffer_fill(true); 1136 initialize_buffer_fill(true);
1125 1137
1126 if (newpos > AUDIO_REBUFFER_GUESS_SIZE) 1138 if (newpos > AUDIO_REBUFFER_GUESS_SIZE)
@@ -1496,25 +1508,23 @@ static void codec_discard_codec_callback(void)
1496 if (buf_ridx >= filebuflen) 1508 if (buf_ridx >= filebuflen)
1497 buf_ridx -= filebuflen; 1509 buf_ridx -= filebuflen;
1498 } 1510 }
1499 1511
1500 /* Check if a buffer desync has happened, and log it */ 1512#if 0
1513 /* Check if a buffer desync has happened, log it and stop playback. */
1501 if (buf_ridx != cur_ti->buf_idx) 1514 if (buf_ridx != cur_ti->buf_idx)
1502 { 1515 {
1503 int offset = cur_ti->buf_idx - buf_ridx; 1516 int offset = cur_ti->buf_idx - buf_ridx;
1504 size_t new_used = filebufused - offset; 1517 size_t new_used = filebufused - offset;
1518
1505 logf("Buf off :%d=%d-%d", offset, cur_ti->buf_idx, buf_ridx); 1519 logf("Buf off :%d=%d-%d", offset, cur_ti->buf_idx, buf_ridx);
1506 buf_ridx += offset; 1520 logf("Used off:%d",filebufused - new_used);
1507 /* Reset the buffer used amount based on the read and write pointers */ 1521
1508 filebufused = track_widx; 1522 /* This is a fatal internal error and it's not safe to
1509 if (track_widx < track_ridx) 1523 * continue playback. */
1510 filebufused += filebuflen; 1524 ci.stop_codec = true;
1511 filebufused -= track_ridx; 1525 queue_post(&audio_queue, Q_AUDIO_STOP, 0);
1512 /* If that was not the same amount as the track was off, log it */
1513 if (new_used != filebufused)
1514 {
1515 logf("Used off:%d",filebufused - new_used);
1516 }
1517 } 1526 }
1527#endif
1518} 1528}
1519 1529
1520static const char *get_codec_path(int codectype) 1530static const char *get_codec_path(int codectype)
@@ -1602,7 +1612,8 @@ static bool loadcodec(bool start_play)
1602 /* If the previous codec is the same as this one, there is no need 1612 /* If the previous codec is the same as this one, there is no need
1603 * to put another copy of it on the file buffer */ 1613 * to put another copy of it on the file buffer */
1604 if (get_codec_base_type(tracks[track_widx].id3.codectype) == 1614 if (get_codec_base_type(tracks[track_widx].id3.codectype) ==
1605 get_codec_base_type(tracks[prev_track].id3.codectype)) 1615 get_codec_base_type(tracks[prev_track].id3.codectype)
1616 && audio_codec_loaded)
1606 { 1617 {
1607 logf("Reusing prev. codec"); 1618 logf("Reusing prev. codec");
1608 return true; 1619 return true;
@@ -1729,7 +1740,8 @@ static bool audio_load_track(int offset, bool start_play, bool rebuffer)
1729 { 1740 {
1730 /* Handle broken playlists. */ 1741 /* Handle broken playlists. */
1731 current_fd = open(trackname, O_RDONLY); 1742 current_fd = open(trackname, O_RDONLY);
1732 if (current_fd < 0) { 1743 if (current_fd < 0)
1744 {
1733 logf("Open failed"); 1745 logf("Open failed");
1734 /* Skip invalid entry from playlist. */ 1746 /* Skip invalid entry from playlist. */
1735 playlist_skip_entry(NULL, last_peek_offset); 1747 playlist_skip_entry(NULL, last_peek_offset);
@@ -1869,13 +1881,14 @@ static bool audio_load_track(int offset, bool start_play, bool rebuffer)
1869 } 1881 }
1870 1882
1871 logf("alt:%s", trackname); 1883 logf("alt:%s", trackname);
1872 tracks[track_widx].buf_idx = buf_widx; 1884 // tracks[track_widx].buf_idx = buf_widx;
1873 1885
1874 audio_read_file(rebuffer); 1886 audio_read_file(rebuffer);
1875 1887
1876 return true; 1888 return true;
1877} 1889}
1878 1890
1891/* Note that this function might yield(). */
1879static void audio_clear_track_entries( 1892static void audio_clear_track_entries(
1880 bool clear_buffered, bool clear_unbuffered) 1893 bool clear_buffered, bool clear_unbuffered)
1881{ 1894{
@@ -1883,6 +1896,7 @@ static void audio_clear_track_entries(
1883 int last_idx = -1; 1896 int last_idx = -1;
1884 1897
1885 logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered); 1898 logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered);
1899
1886 /* Loop over all tracks from write-to-read */ 1900 /* Loop over all tracks from write-to-read */
1887 while (1) 1901 while (1)
1888 { 1902 {
@@ -2060,9 +2074,11 @@ static void initialize_buffer_fill(bool clear_tracks)
2060 /* TODO: This doesn't look right, and might explain some problems with 2074 /* TODO: This doesn't look right, and might explain some problems with
2061 * seeking in large files (to offsets larger than filebuflen). 2075 * seeking in large files (to offsets larger than filebuflen).
2062 * And what about buffer wraps? 2076 * And what about buffer wraps?
2077 *
2078 * This really doesn't look right, so don't use it.
2063 */ 2079 */
2064 if (buf_ridx > cur_ti->buf_idx) 2080 // if (buf_ridx > cur_ti->buf_idx)
2065 cur_ti->start_pos = buf_ridx - cur_ti->buf_idx; 2081 // cur_ti->start_pos = buf_ridx - cur_ti->buf_idx;
2066 2082
2067 if (clear_tracks) 2083 if (clear_tracks)
2068 audio_clear_track_entries(true, false); 2084 audio_clear_track_entries(true, false);