diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/mpeg.c | 97 |
1 files changed, 56 insertions, 41 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index e42623cbd9..24b3a68008 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -1286,6 +1286,7 @@ static void mpeg_thread(void) | |||
1286 | int startpos; | 1286 | int startpos; |
1287 | int rc; | 1287 | int rc; |
1288 | int offset; | 1288 | int offset; |
1289 | int countdown; | ||
1289 | #endif | 1290 | #endif |
1290 | 1291 | ||
1291 | is_playing = false; | 1292 | is_playing = false; |
@@ -1964,67 +1965,81 @@ static void mpeg_thread(void) | |||
1964 | 1965 | ||
1965 | case MPEG_NEW_FILE: | 1966 | case MPEG_NEW_FILE: |
1966 | /* Make sure we have at least one complete frame | 1967 | /* Make sure we have at least one complete frame |
1967 | in the buffer */ | 1968 | in the buffer. If we haven't recorded a single |
1969 | frame within 200ms, the MAS is probably not recording | ||
1970 | anything, and we bail out. */ | ||
1971 | countdown = 20; | ||
1968 | amount_to_save = get_unsaved_space(); | 1972 | amount_to_save = get_unsaved_space(); |
1969 | while(amount_to_save < 1800) | 1973 | while(countdown-- && amount_to_save < 1800) |
1970 | { | 1974 | { |
1971 | sleep(HZ/10); | 1975 | sleep(HZ/10); |
1972 | amount_to_save = get_unsaved_space(); | 1976 | amount_to_save = get_unsaved_space(); |
1973 | } | 1977 | } |
1974 | 1978 | ||
1975 | /* Now find a frame boundary to split at */ | 1979 | if(amount_to_save >= 1800) |
1976 | startpos = mp3buf_write - 1800; | ||
1977 | if(startpos < 0) | ||
1978 | startpos += mp3buflen; | ||
1979 | |||
1980 | { | 1980 | { |
1981 | unsigned long tmp[2]; | 1981 | /* Now find a frame boundary to split at */ |
1982 | /* Find out how the mp3 header should look like */ | 1982 | startpos = mp3buf_write - 1800; |
1983 | mas_readmem(MAS_BANK_D0, 0xfd1, tmp, 2); | 1983 | if(startpos < 0) |
1984 | saved_header = 0xffe00000 | | 1984 | startpos += mp3buflen; |
1985 | ((tmp[0] & 0x7c00) << 6) | | 1985 | |
1986 | (tmp[1] & 0xffff); | 1986 | { |
1987 | DEBUGF("Header: %08x\n", saved_header); | 1987 | unsigned long tmp[2]; |
1988 | } | 1988 | /* Find out how the mp3 header should look like */ |
1989 | 1989 | mas_readmem(MAS_BANK_D0, 0xfd1, tmp, 2); | |
1990 | rc = mem_find_next_frame(startpos, &offset, 1800, | 1990 | saved_header = 0xffe00000 | |
1991 | saved_header); | 1991 | ((tmp[0] & 0x7c00) << 6) | |
1992 | if(rc) /* Header found? */ | 1992 | (tmp[1] & 0xffff); |
1993 | { | 1993 | DEBUGF("Header: %08x\n", saved_header); |
1994 | /* offset will now contain the number of bytes to | 1994 | } |
1995 | add to startpos to find the frame boundary */ | 1995 | |
1996 | startpos += offset; | 1996 | rc = mem_find_next_frame(startpos, &offset, 1800, |
1997 | if(startpos >= mp3buflen) | 1997 | saved_header); |
1998 | startpos -= mp3buflen; | 1998 | if(rc) /* Header found? */ |
1999 | { | ||
2000 | /* offset will now contain the number of bytes to | ||
2001 | add to startpos to find the frame boundary */ | ||
2002 | startpos += offset; | ||
2003 | if(startpos >= mp3buflen) | ||
2004 | startpos -= mp3buflen; | ||
2005 | } | ||
2006 | else | ||
2007 | { | ||
2008 | /* No header found. Let's save the whole buffer. */ | ||
2009 | startpos = mp3buf_write; | ||
2010 | } | ||
1999 | } | 2011 | } |
2000 | else | 2012 | else |
2001 | { | 2013 | { |
2002 | /* No header found. Let's save the whole buffer. */ | 2014 | /* Too few bytes recorded, timeout */ |
2003 | startpos = mp3buf_write; | 2015 | startpos = mp3buf_write; |
2004 | } | 2016 | } |
2005 | 2017 | ||
2006 | amount_to_save = startpos - mp3buf_read; | 2018 | amount_to_save = startpos - mp3buf_read; |
2007 | if(amount_to_save < 0) | 2019 | if(amount_to_save < 0) |
2008 | amount_to_save += mp3buflen; | 2020 | amount_to_save += mp3buflen; |
2009 | 2021 | ||
2010 | /* First save up to the end of the buffer */ | 2022 | /* First save up to the end of the buffer */ |
2011 | writelen = MIN(amount_to_save, | 2023 | writelen = MIN(amount_to_save, |
2012 | mp3buflen - mp3buf_read); | 2024 | mp3buflen - mp3buf_read); |
2013 | 2025 | ||
2014 | rc = write(mpeg_file, mp3buf + mp3buf_read, writelen); | 2026 | if(writelen) |
2015 | if(rc < 0) | ||
2016 | { | 2027 | { |
2017 | if(errno == ENOSPC) | 2028 | rc = write(mpeg_file, mp3buf + mp3buf_read, writelen); |
2018 | { | 2029 | if(rc < 0) |
2019 | mpeg_errno = MPEGERR_DISK_FULL; | ||
2020 | demand_irq_enable(false); | ||
2021 | stop_recording(); | ||
2022 | queue_post(&mpeg_queue, MPEG_STOP_DONE, 0); | ||
2023 | break; | ||
2024 | } | ||
2025 | else | ||
2026 | { | 2030 | { |
2027 | panicf("rec wrt: %d", rc); | 2031 | if(errno == ENOSPC) |
2032 | { | ||
2033 | mpeg_errno = MPEGERR_DISK_FULL; | ||
2034 | demand_irq_enable(false); | ||
2035 | stop_recording(); | ||
2036 | queue_post(&mpeg_queue, MPEG_STOP_DONE, 0); | ||
2037 | break; | ||
2038 | } | ||
2039 | else | ||
2040 | { | ||
2041 | panicf("spt wrt: %d", rc); | ||
2042 | } | ||
2028 | } | 2043 | } |
2029 | } | 2044 | } |
2030 | 2045 | ||