summaryrefslogtreecommitdiffstats
path: root/apps/mpeg.c
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2009-07-20 05:18:18 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2009-07-20 05:18:18 +0000
commit24b136f62de82d7419751b6aaeae0ad3d8497bea (patch)
treeb9bcfd07ca26f3da2f0ce500fc39e0719b3cbb8a /apps/mpeg.c
parent4c4fb82d9c112ccbcc4c94a7d85fe82d09801844 (diff)
downloadrockbox-24b136f62de82d7419751b6aaeae0ad3d8497bea.tar.gz
rockbox-24b136f62de82d7419751b6aaeae0ad3d8497bea.zip
rework cuesheet support:
swcodec: search for a .cue during buffering (with the possibility of adding embedded cuesheets later) hwcodec: search for a .cue when the id3 info for the current track is requested for the first time (disk should be spining so non issue) major beenfit from this is simplofy cuesheet handling code a bit... if mp3entry.cuesheet != NULL then there is a valid cuesheet.. no need to worry about if its enabled and preloaded. There is the possibility of putting the next/prev subtrack handling inside the playback code (as well as the id3 updating stuff (see FS#9789 for more info), but thats probably not a good idea. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21978 a1c6a512-1295-4272-9138-f99709370657
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 @@
#include "sound.h"
#include "bitswap.h"
#include "appevents.h"
+#include "cuesheet.h"
+#include "settings.h"
#ifndef SIMULATOR
#include "i2c.h"
#include "mas.h"
@@ -116,8 +118,9 @@ static int track_read_idx = 0;
static int track_write_idx = 0;
#endif /* !SIMULATOR */
-/* Cuesheet callback */
-static bool (*cuesheet_callback)(const char *filename) = NULL;
+/* Cuesheet support */
+static struct cuesheet *curr_cuesheet = NULL;
+static bool checked_for_cuesheet = false;
static const char mpeg_thread_name[] = "mpeg";
static unsigned int mpeg_errno;
@@ -265,6 +268,7 @@ static void remove_current_tag(void)
{
/* First move the index, so nobody tries to access the tag */
track_read_idx = (track_read_idx+1) & MAX_TRACK_ENTRIES_MASK;
+ checked_for_cuesheet = false;
debug_tags();
}
else
@@ -470,11 +474,6 @@ unsigned long mpeg_get_last_header(void)
#endif /* !SIMULATOR */
}
-void audio_set_cuesheet_callback(bool (*handler)(const char *filename))
-{
- cuesheet_callback = handler;
-}
-
#ifndef SIMULATOR
/* Send callback events to notify about removing old tracks. */
static void generate_unbuffer_events(void)
@@ -878,9 +877,6 @@ static struct trackdata *add_track_to_tag_list(const char *filename)
if (track->id3.album)
lcd_getstringsize(track->id3.album, NULL, NULL);
#endif
- if (cuesheet_callback)
- if (cuesheet_callback(filename))
- track->id3.cuesheet_type = 1;
/* if this track is the next track then let the UI know it can get it */
send_nid3_event = (track_write_idx == track_read_idx + 1);
@@ -2047,10 +2043,28 @@ static void mpeg_thread(void)
struct mp3entry* audio_current_track()
{
#ifdef SIMULATOR
- return &taginfo;
+ struct mp3entry *id3 = &taginfo;
#else /* !SIMULATOR */
if(num_tracks_in_memory())
- return &get_trackdata(0)->id3;
+ {
+ struct mp3entry *id3 = &get_trackdata(0)->id3;
+#endif
+ if (!checked_for_cuesheet && curr_cuesheet && id3->cuesheet == NULL)
+ {
+ checked_for_cuesheet = true; /* only check once per track */
+ char cuepath[MAX_PATH];
+
+ if (look_for_cuesheet_file(id3->path, cuepath) &&
+ parse_cuesheet(cuepath, curr_cuesheet))
+ {
+ strcpy(curr_cuesheet->audio_filename, id3->path);
+ id3->cuesheet = curr_cuesheet;
+ cue_spoof_id3(curr_cuesheet, id3);
+ }
+ }
+ return id3;
+#ifndef SIMULATOR
+ }
else
return NULL;
#endif /* !SIMULATOR */
@@ -2819,6 +2833,19 @@ static void mpeg_thread(void)
{
id3->elapsed+=1000;
id3->offset+=1000;
+ if (id3->cuesheet)
+ {
+ struct cuesheet *cue = id3->cuesheet;
+ unsigned elapsed = id3->elapsed;
+ if (elapsed < cue->curr_track->offset ||
+ (cue->curr_track_idx < cue->track_count-1 &&
+ elapsed >= (cue->curr_track+1)->offset))
+ {
+ cue_find_current_track(id3->cuesheet, id3->elapsed);
+ cue_spoof_id3(id3->cuesheet, id3);
+ send_event(PLAYBACK_EVENT_CUESHEET_TRACK_CHANGE, id3);
+ }
+ }
}
if (id3->elapsed>=id3->length)
audio_next();
@@ -2831,6 +2858,9 @@ static void mpeg_thread(void)
void audio_init(void)
{
mpeg_errno = 0;
+ /* cuesheet support */
+ if (global_settings.cuesheet)
+ curr_cuesheet = (struct cuesheet*)buffer_alloc(sizeof(struct cuesheet));
#ifndef SIMULATOR
audiobuflen = audiobufend - audiobuf;