1
0
Fork 0
forked from len0rd/rockbox

Another fix for bug #835158, now handles multiple splits

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4007 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2003-11-03 21:05:46 +00:00
parent 532eb411ac
commit 51d962f99b

View file

@ -1286,6 +1286,7 @@ static void mpeg_thread(void)
int startpos; int startpos;
int rc; int rc;
int offset; int offset;
int countdown;
#endif #endif
is_playing = false; is_playing = false;
@ -1964,67 +1965,81 @@ static void mpeg_thread(void)
case MPEG_NEW_FILE: case MPEG_NEW_FILE:
/* Make sure we have at least one complete frame /* Make sure we have at least one complete frame
in the buffer */ in the buffer. If we haven't recorded a single
frame within 200ms, the MAS is probably not recording
anything, and we bail out. */
countdown = 20;
amount_to_save = get_unsaved_space(); amount_to_save = get_unsaved_space();
while(amount_to_save < 1800) while(countdown-- && amount_to_save < 1800)
{ {
sleep(HZ/10); sleep(HZ/10);
amount_to_save = get_unsaved_space(); amount_to_save = get_unsaved_space();
} }
/* Now find a frame boundary to split at */ if(amount_to_save >= 1800)
startpos = mp3buf_write - 1800;
if(startpos < 0)
startpos += mp3buflen;
{ {
unsigned long tmp[2]; /* Now find a frame boundary to split at */
/* Find out how the mp3 header should look like */ startpos = mp3buf_write - 1800;
mas_readmem(MAS_BANK_D0, 0xfd1, tmp, 2); if(startpos < 0)
saved_header = 0xffe00000 | startpos += mp3buflen;
((tmp[0] & 0x7c00) << 6) |
(tmp[1] & 0xffff); {
DEBUGF("Header: %08x\n", saved_header); unsigned long tmp[2];
} /* Find out how the mp3 header should look like */
mas_readmem(MAS_BANK_D0, 0xfd1, tmp, 2);
rc = mem_find_next_frame(startpos, &offset, 1800, saved_header = 0xffe00000 |
saved_header); ((tmp[0] & 0x7c00) << 6) |
if(rc) /* Header found? */ (tmp[1] & 0xffff);
{ DEBUGF("Header: %08x\n", saved_header);
/* offset will now contain the number of bytes to }
add to startpos to find the frame boundary */
startpos += offset; rc = mem_find_next_frame(startpos, &offset, 1800,
if(startpos >= mp3buflen) saved_header);
startpos -= mp3buflen; if(rc) /* Header found? */
{
/* offset will now contain the number of bytes to
add to startpos to find the frame boundary */
startpos += offset;
if(startpos >= mp3buflen)
startpos -= mp3buflen;
}
else
{
/* No header found. Let's save the whole buffer. */
startpos = mp3buf_write;
}
} }
else else
{ {
/* No header found. Let's save the whole buffer. */ /* Too few bytes recorded, timeout */
startpos = mp3buf_write; startpos = mp3buf_write;
} }
amount_to_save = startpos - mp3buf_read; amount_to_save = startpos - mp3buf_read;
if(amount_to_save < 0) if(amount_to_save < 0)
amount_to_save += mp3buflen; amount_to_save += mp3buflen;
/* First save up to the end of the buffer */ /* First save up to the end of the buffer */
writelen = MIN(amount_to_save, writelen = MIN(amount_to_save,
mp3buflen - mp3buf_read); mp3buflen - mp3buf_read);
rc = write(mpeg_file, mp3buf + mp3buf_read, writelen); if(writelen)
if(rc < 0)
{ {
if(errno == ENOSPC) rc = write(mpeg_file, mp3buf + mp3buf_read, writelen);
if(rc < 0)
{ {
mpeg_errno = MPEGERR_DISK_FULL; if(errno == ENOSPC)
demand_irq_enable(false); {
stop_recording(); mpeg_errno = MPEGERR_DISK_FULL;
queue_post(&mpeg_queue, MPEG_STOP_DONE, 0); demand_irq_enable(false);
break; stop_recording();
} queue_post(&mpeg_queue, MPEG_STOP_DONE, 0);
else break;
{ }
panicf("rec wrt: %d", rc); else
{
panicf("spt wrt: %d", rc);
}
} }
} }