summaryrefslogtreecommitdiff
path: root/apps/mpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mpeg.c')
-rw-r--r--apps/mpeg.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/apps/mpeg.c b/apps/mpeg.c
index 0e1217b5c8..5db0272752 100644
--- a/apps/mpeg.c
+++ b/apps/mpeg.c
@@ -40,6 +40,8 @@
40#include "sound.h" 40#include "sound.h"
41#include "bitswap.h" 41#include "bitswap.h"
42#include "appevents.h" 42#include "appevents.h"
43#include "cuesheet.h"
44#include "settings.h"
43#ifndef SIMULATOR 45#ifndef SIMULATOR
44#include "i2c.h" 46#include "i2c.h"
45#include "mas.h" 47#include "mas.h"
@@ -116,8 +118,9 @@ static int track_read_idx = 0;
116static int track_write_idx = 0; 118static int track_write_idx = 0;
117#endif /* !SIMULATOR */ 119#endif /* !SIMULATOR */
118 120
119/* Cuesheet callback */ 121/* Cuesheet support */
120static bool (*cuesheet_callback)(const char *filename) = NULL; 122static struct cuesheet *curr_cuesheet = NULL;
123static bool checked_for_cuesheet = false;
121 124
122static const char mpeg_thread_name[] = "mpeg"; 125static const char mpeg_thread_name[] = "mpeg";
123static unsigned int mpeg_errno; 126static unsigned int mpeg_errno;
@@ -265,6 +268,7 @@ static void remove_current_tag(void)
265 { 268 {
266 /* First move the index, so nobody tries to access the tag */ 269 /* First move the index, so nobody tries to access the tag */
267 track_read_idx = (track_read_idx+1) & MAX_TRACK_ENTRIES_MASK; 270 track_read_idx = (track_read_idx+1) & MAX_TRACK_ENTRIES_MASK;
271 checked_for_cuesheet = false;
268 debug_tags(); 272 debug_tags();
269 } 273 }
270 else 274 else
@@ -470,11 +474,6 @@ unsigned long mpeg_get_last_header(void)
470#endif /* !SIMULATOR */ 474#endif /* !SIMULATOR */
471} 475}
472 476
473void audio_set_cuesheet_callback(bool (*handler)(const char *filename))
474{
475 cuesheet_callback = handler;
476}
477
478#ifndef SIMULATOR 477#ifndef SIMULATOR
479/* Send callback events to notify about removing old tracks. */ 478/* Send callback events to notify about removing old tracks. */
480static void generate_unbuffer_events(void) 479static void generate_unbuffer_events(void)
@@ -878,9 +877,6 @@ static struct trackdata *add_track_to_tag_list(const char *filename)
878 if (track->id3.album) 877 if (track->id3.album)
879 lcd_getstringsize(track->id3.album, NULL, NULL); 878 lcd_getstringsize(track->id3.album, NULL, NULL);
880#endif 879#endif
881 if (cuesheet_callback)
882 if (cuesheet_callback(filename))
883 track->id3.cuesheet_type = 1;
884 880
885 /* if this track is the next track then let the UI know it can get it */ 881 /* if this track is the next track then let the UI know it can get it */
886 send_nid3_event = (track_write_idx == track_read_idx + 1); 882 send_nid3_event = (track_write_idx == track_read_idx + 1);
@@ -2047,10 +2043,28 @@ static void mpeg_thread(void)
2047struct mp3entry* audio_current_track() 2043struct mp3entry* audio_current_track()
2048{ 2044{
2049#ifdef SIMULATOR 2045#ifdef SIMULATOR
2050 return &taginfo; 2046 struct mp3entry *id3 = &taginfo;
2051#else /* !SIMULATOR */ 2047#else /* !SIMULATOR */
2052 if(num_tracks_in_memory()) 2048 if(num_tracks_in_memory())
2053 return &get_trackdata(0)->id3; 2049 {
2050 struct mp3entry *id3 = &get_trackdata(0)->id3;
2051#endif
2052 if (!checked_for_cuesheet && curr_cuesheet && id3->cuesheet == NULL)
2053 {
2054 checked_for_cuesheet = true; /* only check once per track */
2055 char cuepath[MAX_PATH];
2056
2057 if (look_for_cuesheet_file(id3->path, cuepath) &&
2058 parse_cuesheet(cuepath, curr_cuesheet))
2059 {
2060 strcpy(curr_cuesheet->audio_filename, id3->path);
2061 id3->cuesheet = curr_cuesheet;
2062 cue_spoof_id3(curr_cuesheet, id3);
2063 }
2064 }
2065 return id3;
2066#ifndef SIMULATOR
2067 }
2054 else 2068 else
2055 return NULL; 2069 return NULL;
2056#endif /* !SIMULATOR */ 2070#endif /* !SIMULATOR */
@@ -2819,6 +2833,19 @@ static void mpeg_thread(void)
2819 { 2833 {
2820 id3->elapsed+=1000; 2834 id3->elapsed+=1000;
2821 id3->offset+=1000; 2835 id3->offset+=1000;
2836 if (id3->cuesheet)
2837 {
2838 struct cuesheet *cue = id3->cuesheet;
2839 unsigned elapsed = id3->elapsed;
2840 if (elapsed < cue->curr_track->offset ||
2841 (cue->curr_track_idx < cue->track_count-1 &&
2842 elapsed >= (cue->curr_track+1)->offset))
2843 {
2844 cue_find_current_track(id3->cuesheet, id3->elapsed);
2845 cue_spoof_id3(id3->cuesheet, id3);
2846 send_event(PLAYBACK_EVENT_CUESHEET_TRACK_CHANGE, id3);
2847 }
2848 }
2822 } 2849 }
2823 if (id3->elapsed>=id3->length) 2850 if (id3->elapsed>=id3->length)
2824 audio_next(); 2851 audio_next();
@@ -2831,6 +2858,9 @@ static void mpeg_thread(void)
2831void audio_init(void) 2858void audio_init(void)
2832{ 2859{
2833 mpeg_errno = 0; 2860 mpeg_errno = 0;
2861 /* cuesheet support */
2862 if (global_settings.cuesheet)
2863 curr_cuesheet = (struct cuesheet*)buffer_alloc(sizeof(struct cuesheet));
2834 2864
2835#ifndef SIMULATOR 2865#ifndef SIMULATOR
2836 audiobuflen = audiobufend - audiobuf; 2866 audiobuflen = audiobufend - audiobuf;