summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-12-17 16:12:10 -0500
committerMichael Sevakis <jethead71@rockbox.org>2017-12-17 16:33:50 -0500
commitdfff938dff089667038041fcb66262c87c3186c2 (patch)
treef592218ad9b33d8b0bb0e5c07bcb155f6243aaf4 /apps/playback.c
parentd14e3f45a859045e81065bfd6740605be45c2349 (diff)
downloadrockbox-dfff938dff089667038041fcb66262c87c3186c2.tar.gz
rockbox-dfff938dff089667038041fcb66262c87c3186c2.zip
Get rid of useless playlist probing and fix up some data types.
Playback checked the files' presence before attempting to buffer the track. Just get rid of that and save an extra open/close call. It will find out if the path is bad when the metadata fails. Fix some size_t/off_t conflation. No need to update plugin version because no plugin actually uses bufopen(). Change-Id: I3db112449dc0b2eeb91c546f308880ac82494fc7
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c73
1 files changed, 24 insertions, 49 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 8b607f30f0..e8aaf3bacc 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -227,11 +227,6 @@ struct track_info
227#endif 227#endif
228 int audio_hid; /* Main audio data handle ID */ 228 int audio_hid; /* Main audio data handle ID */
229 }; }; 229 }; };
230 off_t filesize; /* File total length on disk
231 TODO: This should be stored
232 in the handle or the
233 id3 and would use less
234 ram */
235}; 230};
236 231
237/* On-buffer info format; includes links */ 232/* On-buffer info format; includes links */
@@ -459,8 +454,6 @@ static void track_info_wipe(struct track_info *infop)
459 454
460 FOR_EACH_TRACK_INFO_HANDLE(i) 455 FOR_EACH_TRACK_INFO_HANDLE(i)
461 infop->handle[i] = ERR_HANDLE_NOT_FOUND; 456 infop->handle[i] = ERR_HANDLE_NOT_FOUND;
462
463 infop->filesize = 0;
464} 457}
465 458
466/** --- Track list --- **/ 459/** --- Track list --- **/
@@ -1065,7 +1058,7 @@ static void audio_update_filebuf_watermark(int seconds)
1065 track that fits, in which case we should avoid constant buffer 1058 track that fits, in which case we should avoid constant buffer
1066 low events */ 1059 low events */
1067 if (track_list_count() > 1) 1060 if (track_list_count() > 1)
1068 bytes = info.filesize + 1; 1061 bytes = buf_filesize(info.audio_hid) + 1;
1069 } 1062 }
1070 } 1063 }
1071 else 1064 else
@@ -1613,7 +1606,7 @@ static bool audio_start_codec(bool auto_skip)
1613 id3_write(CODEC_ID3, cur_id3); 1606 id3_write(CODEC_ID3, cur_id3);
1614 1607
1615 ci.audio_hid = info.audio_hid; 1608 ci.audio_hid = info.audio_hid;
1616 ci.filesize = info.filesize; 1609 ci.filesize = buf_filesize(info.audio_hid);
1617 buf_set_base_handle(info.audio_hid); 1610 buf_set_base_handle(info.audio_hid);
1618 1611
1619 /* All required data is now available for the codec */ 1612 /* All required data is now available for the codec */
@@ -1870,33 +1863,12 @@ static int audio_load_track(void)
1870 playlist_peek_offset); 1863 playlist_peek_offset);
1871 1864
1872 /* Get track name from current playlist read position */ 1865 /* Get track name from current playlist read position */
1873 int fd = -1; 1866 char path_buf[MAX_PATH + 1];
1874 char name_buf[MAX_PATH + 1]; 1867 const char *path = playlist_peek(playlist_peek_offset,
1875 const char *trackname; 1868 path_buf,
1876 1869 sizeof (path_buf));
1877 while (1)
1878 {
1879 trackname = playlist_peek(playlist_peek_offset, name_buf,
1880 sizeof (name_buf));
1881
1882 if (!trackname)
1883 break;
1884
1885 /* Test for broken playlists by probing for the files */
1886 fd = open(trackname, O_RDONLY);
1887 if (fd >= 0)
1888 break;
1889
1890 logf("Open failed");
1891 /* Skip invalid entry from playlist */
1892 playlist_skip_entry(NULL, playlist_peek_offset);
1893
1894 /* Sync the playlist if it isn't finished */
1895 if (playlist_peek(playlist_peek_offset, NULL, 0))
1896 playlist_next(0);
1897 }
1898 1870
1899 if (!trackname) 1871 if (!path)
1900 { 1872 {
1901 /* No track - exhausted the playlist entries */ 1873 /* No track - exhausted the playlist entries */
1902 logf("End-of-playlist"); 1874 logf("End-of-playlist");
@@ -1920,7 +1892,7 @@ static int audio_load_track(void)
1920 1892
1921 /* Successfully opened the file - get track metadata */ 1893 /* Successfully opened the file - get track metadata */
1922 if (filling == STATE_FULL || 1894 if (filling == STATE_FULL ||
1923 (info.id3_hid = bufopen(trackname, 0, TYPE_ID3, NULL)) < 0) 1895 (info.id3_hid = bufopen(path, 0, TYPE_ID3, NULL)) < 0)
1924 { 1896 {
1925 /* Buffer or track list is full */ 1897 /* Buffer or track list is full */
1926 struct mp3entry *ub_id3; 1898 struct mp3entry *ub_id3;
@@ -1929,9 +1901,15 @@ static int audio_load_track(void)
1929 1901
1930 /* Load the metadata for the first unbuffered track */ 1902 /* Load the metadata for the first unbuffered track */
1931 ub_id3 = id3_get(UNBUFFERED_ID3); 1903 ub_id3 = id3_get(UNBUFFERED_ID3);
1932 id3_mutex_lock(); 1904
1933 get_metadata(ub_id3, fd, trackname); 1905 int fd = open(path, O_RDONLY);
1934 id3_mutex_unlock(); 1906 if (fd >= 0)
1907 {
1908 id3_mutex_lock();
1909 get_metadata(ub_id3, fd, path);
1910 id3_mutex_unlock();
1911 close(fd);
1912 }
1935 1913
1936 if (filling != STATE_FULL) 1914 if (filling != STATE_FULL)
1937 { 1915 {
@@ -1944,8 +1922,6 @@ static int audio_load_track(void)
1944 } 1922 }
1945 else 1923 else
1946 { 1924 {
1947 info.filesize = filesize(fd);
1948
1949 if (!track_list_commit_info(&info)) 1925 if (!track_list_commit_info(&info))
1950 { 1926 {
1951 track_list_free_info(&info); 1927 track_list_free_info(&info);
@@ -1957,7 +1933,6 @@ static int audio_load_track(void)
1957 track_list.in_progress_hid = info.self_hid; 1933 track_list.in_progress_hid = info.self_hid;
1958 } 1934 }
1959 1935
1960 close(fd);
1961 return LOAD_TRACK_OK; 1936 return LOAD_TRACK_OK;
1962} 1937}
1963 1938
@@ -2050,23 +2025,23 @@ static int audio_finish_load_track(struct track_info *infop)
2050#endif /* HAVE_CODEC_BUFFERING */ 2025#endif /* HAVE_CODEC_BUFFERING */
2051 2026
2052 /** Finally, load the audio **/ 2027 /** Finally, load the audio **/
2053 size_t file_offset = 0; 2028 off_t file_offset = 0;
2054 2029
2055 if (track_id3->elapsed > track_id3->length) 2030 if (track_id3->elapsed > track_id3->length)
2056 track_id3->elapsed = 0; 2031 track_id3->elapsed = 0;
2057 2032
2058 if ((off_t)track_id3->offset >= infop->filesize) 2033 if ((off_t)track_id3->offset >= buf_filesize(infop->audio_hid))
2059 track_id3->offset = 0; 2034 track_id3->offset = 0;
2060 2035
2061 logf("%s: set offset for %s to %lu\n", __func__, 2036 logf("%s: set offset for %s to %lu\n", __func__,
2062 track_id3->title, (unsigned long)track_id3->offset); 2037 track_id3->title, track_id3->offset);
2063 2038
2064 /* Adjust for resume rewind so we know what to buffer - starting the codec 2039 /* Adjust for resume rewind so we know what to buffer - starting the codec
2065 calls it again, so we don't save it (and they shouldn't accumulate) */ 2040 calls it again, so we don't save it (and they shouldn't accumulate) */
2066 unsigned long elapsed, offset; 2041 unsigned long elapsed, offset;
2067 resume_rewind_adjust_progress(track_id3, &elapsed, &offset); 2042 resume_rewind_adjust_progress(track_id3, &elapsed, &offset);
2068 2043
2069 logf("%s: Set resume for %s to %lu %lX", __func__, 2044 logf("%s: Set resume for %s to %lu %lu", __func__,
2070 track_id3->title, elapsed, offset); 2045 track_id3->title, elapsed, offset);
2071 2046
2072 enum data_type audiotype = rbcodec_format_is_atomic(track_id3->codectype) ? 2047 enum data_type audiotype = rbcodec_format_is_atomic(track_id3->codectype) ?
@@ -3049,7 +3024,7 @@ static void audio_on_ff_rewind(long time)
3049 3024
3050 /* Set the codec API to the correct metadata and track info */ 3025 /* Set the codec API to the correct metadata and track info */
3051 ci.audio_hid = cur_info.audio_hid; 3026 ci.audio_hid = cur_info.audio_hid;
3052 ci.filesize = cur_info.filesize; 3027 ci.filesize = buf_filesize(cur_info.audio_hid);
3053 buf_set_base_handle(cur_info.audio_hid); 3028 buf_set_base_handle(cur_info.audio_hid);
3054 } 3029 }
3055 3030
@@ -3343,9 +3318,9 @@ static void buffer_event_finished_callback(unsigned short id, void *ev_data)
3343{ 3318{
3344 (void)id; 3319 (void)id;
3345 int hid = *(const int *)ev_data; 3320 int hid = *(const int *)ev_data;
3346 const enum data_type htype = buf_handle_data_type(hid); 3321 int htype = buf_handle_data_type(hid);
3347 3322
3348 logf("handle %d finished buffering (type:%u)", hid, (unsigned)htype); 3323 logf("handle %d finished buffering (type:%d)", hid, htype);
3349 3324
3350 /* Limit queue traffic */ 3325 /* Limit queue traffic */
3351 switch (htype) 3326 switch (htype)