2003-03-12 20:21:30 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
2003-04-01 20:58:31 +00:00
|
|
|
|
#include "debug.h"
|
2003-03-12 21:40:47 +00:00
|
|
|
|
#include "sprintf.h"
|
2003-03-12 20:21:30 +00:00
|
|
|
|
#include "lcd.h"
|
|
|
|
|
#include "dir.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "mpeg.h"
|
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "lang.h"
|
|
|
|
|
#include "playlist.h"
|
|
|
|
|
#include "button.h"
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
#include "keyboard.h"
|
2003-04-01 20:58:31 +00:00
|
|
|
|
#include "mp3data.h"
|
|
|
|
|
#include "id3.h"
|
|
|
|
|
#include "screens.h"
|
2003-03-24 13:17:43 +00:00
|
|
|
|
#include "tree.h"
|
2003-05-09 16:01:21 +00:00
|
|
|
|
#include "buffer.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "status.h"
|
2004-01-26 17:05:21 +00:00
|
|
|
|
#include "playlist_viewer.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
|
#include "talk.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
|
#include "onplay.h"
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
|
|
|
|
static char* selected_file = NULL;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
static int selected_file_attr = 0;
|
|
|
|
|
static int onplay_result = ONPLAY_OK;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
/* For playlist options */
|
|
|
|
|
struct playlist_args {
|
|
|
|
|
int position;
|
|
|
|
|
bool queue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool add_to_playlist(int position, bool queue)
|
2003-03-12 20:21:30 +00:00
|
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
|
bool new_playlist = !(mpeg_status() & MPEG_STATUS_PLAY);
|
|
|
|
|
|
|
|
|
|
if (new_playlist)
|
|
|
|
|
playlist_create(NULL, NULL);
|
|
|
|
|
|
2003-12-07 16:57:43 +00:00
|
|
|
|
if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_insert_track(NULL, selected_file, position, queue);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
else if (selected_file_attr & ATTR_DIRECTORY)
|
2003-07-02 15:54:44 +00:00
|
|
|
|
{
|
|
|
|
|
bool recurse = false;
|
|
|
|
|
|
|
|
|
|
if (global_settings.recursive_dir_insert != RECURSE_ASK)
|
|
|
|
|
recurse = (bool)global_settings.recursive_dir_insert;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Ask if user wants to recurse directory */
|
|
|
|
|
bool exit = false;
|
|
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
lcd_puts_scroll(0,0,str(LANG_RECURSE_DIRECTORY_QUESTION));
|
|
|
|
|
lcd_puts_scroll(0,1,selected_file);
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER));
|
|
|
|
|
lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
|
|
while (!exit) {
|
|
|
|
|
int btn = button_get(true);
|
|
|
|
|
switch (btn) {
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
recurse = true;
|
|
|
|
|
exit = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* ignore button releases */
|
|
|
|
|
if (!(btn & BUTTON_REL))
|
|
|
|
|
exit = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_insert_directory(NULL, selected_file, position, queue,
|
|
|
|
|
recurse);
|
2003-07-02 15:54:44 +00:00
|
|
|
|
}
|
2003-12-07 16:57:43 +00:00
|
|
|
|
else if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_insert_playlist(NULL, selected_file, position, queue);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
|
|
if (new_playlist && (playlist_amount() > 0))
|
|
|
|
|
{
|
|
|
|
|
/* nothing is currently playing so begin playing what we just
|
|
|
|
|
inserted */
|
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
|
playlist_shuffle(current_tick, -1);
|
|
|
|
|
playlist_start(0,0);
|
|
|
|
|
status_set_playmode(STATUS_PLAY);
|
|
|
|
|
status_draw(false);
|
|
|
|
|
onplay_result = ONPLAY_START_PLAY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
static bool view_playlist(void)
|
|
|
|
|
{
|
|
|
|
|
bool was_playing = mpeg_status() & MPEG_STATUS_PLAY;
|
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
|
|
result = playlist_viewer_ex(selected_file);
|
|
|
|
|
|
|
|
|
|
if (!was_playing && (mpeg_status() & MPEG_STATUS_PLAY) &&
|
|
|
|
|
onplay_result == ONPLAY_OK)
|
|
|
|
|
/* playlist was started from viewer */
|
|
|
|
|
onplay_result = ONPLAY_START_PLAY;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
/* Sub-menu for playlist options */
|
|
|
|
|
static bool playlist_options(void)
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
struct menu_item items[7];
|
2004-01-26 17:05:21 +00:00
|
|
|
|
struct playlist_args args[7]; /* increase these 2 if you add entries! */
|
|
|
|
|
int m, i=0, pstart=0, result;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U)
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_VIEW);
|
|
|
|
|
items[i].voice_id = LANG_VIEW;
|
|
|
|
|
items[i].function = view_playlist;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
i++;
|
|
|
|
|
pstart++;
|
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
|
|
if (mpeg_status() & MPEG_STATUS_PLAY)
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_INSERT);
|
|
|
|
|
items[i].voice_id = LANG_INSERT;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_INSERT_FIRST);
|
|
|
|
|
items[i].voice_id = LANG_INSERT_FIRST;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT_FIRST;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_INSERT_LAST);
|
|
|
|
|
items[i].voice_id = LANG_INSERT_LAST;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT_LAST;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_QUEUE);
|
|
|
|
|
items[i].voice_id = LANG_QUEUE;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_QUEUE_FIRST);
|
|
|
|
|
items[i].voice_id = LANG_QUEUE_FIRST;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT_FIRST;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_QUEUE_LAST);
|
|
|
|
|
items[i].voice_id = LANG_QUEUE_LAST;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT_LAST;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-12-07 16:57:43 +00:00
|
|
|
|
else if (((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) ||
|
2003-07-01 21:05:43 +00:00
|
|
|
|
(selected_file_attr & ATTR_DIRECTORY))
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_INSERT);
|
|
|
|
|
items[i].voice_id = LANG_INSERT;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
m = menu_init( items, i, NULL, NULL, NULL, NULL );
|
2003-07-01 21:05:43 +00:00
|
|
|
|
result = menu_show(m);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (result >= 0 && result < pstart)
|
2004-03-16 13:44:56 +00:00
|
|
|
|
ret = items[result].function();
|
2004-01-26 17:05:21 +00:00
|
|
|
|
else if (result >= pstart)
|
|
|
|
|
ret = add_to_playlist(args[result].position, args[result].queue);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
menu_exit(m);
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
return ret;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool delete_file(void)
|
|
|
|
|
{
|
|
|
|
|
bool exit = false;
|
|
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
lcd_puts(0,0,str(LANG_REALLY_DELETE));
|
|
|
|
|
lcd_puts_scroll(0,1,selected_file);
|
2003-06-25 08:25:29 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER));
|
|
|
|
|
lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER));
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-24 13:17:43 +00:00
|
|
|
|
lcd_update();
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
|
|
|
|
while (!exit) {
|
|
|
|
|
int btn = button_get(true);
|
|
|
|
|
switch (btn) {
|
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
|
if (!remove(selected_file)) {
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
lcd_clear_display();
|
2003-03-24 13:17:43 +00:00
|
|
|
|
lcd_puts(0,0,str(LANG_DELETED));
|
|
|
|
|
lcd_puts_scroll(0,1,selected_file);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
sleep(HZ);
|
|
|
|
|
exit = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* ignore button releases */
|
|
|
|
|
if (!(btn & BUTTON_REL))
|
|
|
|
|
exit = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool rename_file(void)
|
|
|
|
|
{
|
|
|
|
|
char newname[MAX_PATH];
|
|
|
|
|
char* ptr = strrchr(selected_file, '/') + 1;
|
|
|
|
|
int pathlen = (ptr - selected_file);
|
|
|
|
|
strncpy(newname, selected_file, sizeof newname);
|
|
|
|
|
if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
|
|
|
|
|
if (!strlen(selected_file+pathlen) ||
|
|
|
|
|
(rename(selected_file, newname) < 0)) {
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
lcd_puts(0,0,str(LANG_RENAME));
|
|
|
|
|
lcd_puts(0,1,str(LANG_FAILED));
|
|
|
|
|
lcd_update();
|
|
|
|
|
sleep(HZ*2);
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void xingupdate(int percent)
|
|
|
|
|
{
|
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
|
|
snprintf(buf, 32, "%d%%", percent);
|
2003-04-01 20:58:31 +00:00
|
|
|
|
lcd_puts(0, 1, buf);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 00:27:49 +00:00
|
|
|
|
|
2003-04-13 15:01:44 +00:00
|
|
|
|
static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
|
2003-04-03 00:27:49 +00:00
|
|
|
|
{
|
|
|
|
|
int readlen;
|
|
|
|
|
int rc;
|
|
|
|
|
int orig_fd, fd;
|
|
|
|
|
char tmpname[MAX_PATH];
|
|
|
|
|
|
2004-03-14 21:33:53 +00:00
|
|
|
|
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
|
|
|
|
|
2003-04-03 00:27:49 +00:00
|
|
|
|
snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
|
|
|
|
|
|
|
|
|
|
orig_fd = open(fname, O_RDONLY);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(orig_fd < 0) {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
return 10*orig_fd - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd = creat(tmpname, O_WRONLY);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(fd < 0) {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
close(orig_fd);
|
|
|
|
|
return 10*fd - 2;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 07:20:57 +00:00
|
|
|
|
/* First, copy the initial portion (the ID3 tag) */
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(fpos) {
|
2003-04-03 07:20:57 +00:00
|
|
|
|
readlen = read(orig_fd, mp3buf, fpos);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(readlen < 0) {
|
2003-04-03 07:20:57 +00:00
|
|
|
|
close(fd);
|
|
|
|
|
close(orig_fd);
|
|
|
|
|
return 10*readlen - 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = write(fd, mp3buf, readlen);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
2003-04-03 07:20:57 +00:00
|
|
|
|
close(fd);
|
|
|
|
|
close(orig_fd);
|
|
|
|
|
return 10*rc - 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 15:01:44 +00:00
|
|
|
|
/* Now insert the data into the file */
|
|
|
|
|
rc = write(fd, buf, num_bytes);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
close(orig_fd);
|
|
|
|
|
close(fd);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return 10*rc - 5;
|
2003-04-03 00:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy the file */
|
2003-04-10 00:16:46 +00:00
|
|
|
|
do {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
readlen = read(orig_fd, mp3buf, mp3end - mp3buf);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(readlen < 0) {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
close(fd);
|
|
|
|
|
close(orig_fd);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return 10*readlen - 7;
|
2003-04-03 00:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = write(fd, mp3buf, readlen);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
2003-04-03 00:27:49 +00:00
|
|
|
|
close(fd);
|
|
|
|
|
close(orig_fd);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return 10*rc - 8;
|
2003-04-03 00:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
} while(readlen > 0);
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
close(orig_fd);
|
|
|
|
|
|
|
|
|
|
/* Remove the old file */
|
|
|
|
|
rc = remove(fname);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return 10*rc - 9;
|
2003-04-03 00:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Replace the old file with the new */
|
|
|
|
|
rc = rename(tmpname, fname);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return 10*rc - 9;
|
2003-04-03 00:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-04-10 00:16:46 +00:00
|
|
|
|
|
|
|
|
|
static void fileerror(int rc)
|
|
|
|
|
{
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, "File error: %d", rc);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 15:01:44 +00:00
|
|
|
|
static const unsigned char empty_id3_header[] =
|
|
|
|
|
{
|
|
|
|
|
'I', 'D', '3', 0x04, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x1f, 0x76 /* Size is 4096 minus 10 bytes for the header */
|
|
|
|
|
};
|
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
static bool vbr_fix(void)
|
|
|
|
|
{
|
2003-04-19 01:59:23 +00:00
|
|
|
|
unsigned char xingbuf[1500];
|
2003-04-01 20:58:31 +00:00
|
|
|
|
struct mp3entry entry;
|
|
|
|
|
int fd;
|
|
|
|
|
int rc;
|
|
|
|
|
int flen;
|
|
|
|
|
int num_frames;
|
2003-04-03 07:20:57 +00:00
|
|
|
|
int numbytes;
|
2003-04-19 01:59:23 +00:00
|
|
|
|
int framelen;
|
|
|
|
|
int unused_space;
|
2003-04-01 20:58:31 +00:00
|
|
|
|
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(mpeg_status()) {
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_VBRFIX_STOP_PLAY));
|
2003-07-01 21:05:43 +00:00
|
|
|
|
return onplay_result;
|
2003-04-01 21:22:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-14 21:33:53 +00:00
|
|
|
|
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
lcd_clear_display();
|
2003-04-01 20:58:31 +00:00
|
|
|
|
lcd_puts_scroll(0, 0, selected_file);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
lcd_update();
|
|
|
|
|
|
2003-04-01 20:58:31 +00:00
|
|
|
|
xingupdate(0);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2003-04-01 20:58:31 +00:00
|
|
|
|
rc = mp3info(&entry, selected_file);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(rc < 0) {
|
|
|
|
|
fileerror(rc);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-04-01 20:58:31 +00:00
|
|
|
|
|
|
|
|
|
fd = open(selected_file, O_RDWR);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(fd < 0) {
|
|
|
|
|
fileerror(fd);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-04-01 20:58:31 +00:00
|
|
|
|
|
|
|
|
|
flen = lseek(fd, 0, SEEK_END);
|
|
|
|
|
|
|
|
|
|
xingupdate(0);
|
|
|
|
|
|
|
|
|
|
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
|
|
|
|
flen, xingupdate);
|
|
|
|
|
|
2003-04-10 00:16:46 +00:00
|
|
|
|
if(num_frames) {
|
2003-04-20 22:00:30 +00:00
|
|
|
|
/* Note: We don't need to pass a template header because it will be
|
|
|
|
|
taken from the mpeg stream */
|
2003-04-19 01:59:23 +00:00
|
|
|
|
framelen = create_xing_header(fd, entry.first_frame_offset,
|
|
|
|
|
flen, xingbuf, num_frames,
|
2003-04-20 22:00:30 +00:00
|
|
|
|
0, xingupdate, true);
|
2003-04-01 20:58:31 +00:00
|
|
|
|
|
|
|
|
|
/* Try to fit the Xing header first in the stream. Replace the existing
|
2003-04-19 01:59:23 +00:00
|
|
|
|
VBR header if there is one, else see if there is room between the
|
2003-04-01 20:58:31 +00:00
|
|
|
|
ID3 tag and the first MP3 frame. */
|
2003-04-19 01:59:23 +00:00
|
|
|
|
if(entry.first_frame_offset - entry.id3v2len >=
|
|
|
|
|
(unsigned int)framelen) {
|
|
|
|
|
DEBUGF("Using existing space between ID3 and first frame\n");
|
|
|
|
|
|
|
|
|
|
/* Seek to the beginning of the unused space */
|
|
|
|
|
rc = lseek(fd, entry.id3v2len, SEEK_SET);
|
2003-04-13 15:01:44 +00:00
|
|
|
|
if(rc < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
fileerror(rc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-04-19 01:59:23 +00:00
|
|
|
|
|
|
|
|
|
unused_space =
|
|
|
|
|
entry.first_frame_offset - entry.id3v2len - framelen;
|
2003-04-13 15:01:44 +00:00
|
|
|
|
|
2003-04-19 01:59:23 +00:00
|
|
|
|
/* Fill the unused space with 0's (using the MP3 buffer)
|
|
|
|
|
and write it to the file */
|
|
|
|
|
if(unused_space)
|
|
|
|
|
{
|
|
|
|
|
memset(mp3buf, 0, unused_space);
|
|
|
|
|
rc = write(fd, mp3buf, unused_space);
|
|
|
|
|
if(rc < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
fileerror(rc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Then write the Xing header */
|
|
|
|
|
rc = write(fd, xingbuf, framelen);
|
2003-04-13 15:01:44 +00:00
|
|
|
|
if(rc < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
fileerror(rc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(fd);
|
2003-04-10 00:16:46 +00:00
|
|
|
|
} else {
|
2003-04-19 01:59:23 +00:00
|
|
|
|
/* If not, insert some space. If there is an ID3 tag in the
|
|
|
|
|
file we only insert just enough to squeeze the Xing header
|
|
|
|
|
in. If not, we insert an additional empty ID3 tag of 4K. */
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
/* Nasty trick alert! The insert_data_in_file() function
|
|
|
|
|
uses the MP3 buffer when copying the data. We assume
|
|
|
|
|
that the ID3 tag isn't longer than 1MB so the xing
|
|
|
|
|
buffer won't be overwritten. */
|
|
|
|
|
|
|
|
|
|
if(entry.first_frame_offset) {
|
|
|
|
|
DEBUGF("Inserting %d bytes\n", framelen);
|
|
|
|
|
numbytes = framelen;
|
2003-04-10 00:16:46 +00:00
|
|
|
|
} else {
|
2003-04-19 01:59:23 +00:00
|
|
|
|
DEBUGF("Inserting 4096+%d bytes\n", framelen);
|
|
|
|
|
numbytes = 4096 + framelen;
|
2003-04-03 07:20:57 +00:00
|
|
|
|
|
2003-04-19 01:59:23 +00:00
|
|
|
|
memset(mp3buf + 0x100000, 0, numbytes);
|
2003-04-03 07:20:57 +00:00
|
|
|
|
|
2003-04-19 01:59:23 +00:00
|
|
|
|
/* Insert the ID3 header */
|
|
|
|
|
memcpy(mp3buf + 0x100000, empty_id3_header,
|
|
|
|
|
sizeof(empty_id3_header));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy the Xing header */
|
|
|
|
|
memcpy(mp3buf + 0x100000 + numbytes - framelen, xingbuf, framelen);
|
|
|
|
|
|
|
|
|
|
rc = insert_data_in_file(selected_file,
|
|
|
|
|
entry.first_frame_offset,
|
|
|
|
|
mp3buf + 0x100000, numbytes);
|
|
|
|
|
|
|
|
|
|
if(rc < 0) {
|
|
|
|
|
fileerror(rc);
|
|
|
|
|
return true;
|
2003-04-01 20:58:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xingupdate(100);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Not a VBR file */
|
|
|
|
|
DEBUGF("Not a VBR file\n");
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_VBRFIX_NOT_VBR));
|
2003-04-01 20:58:31 +00:00
|
|
|
|
}
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-04-10 00:16:46 +00:00
|
|
|
|
|
2004-03-11 10:43:53 +00:00
|
|
|
|
bool create_dir(void)
|
|
|
|
|
{
|
|
|
|
|
char dirname[MAX_PATH];
|
|
|
|
|
char *cwd;
|
|
|
|
|
int rc;
|
|
|
|
|
int pathlen;
|
|
|
|
|
|
|
|
|
|
cwd = getcwd(NULL, 0);
|
|
|
|
|
memset(dirname, 0, sizeof dirname);
|
|
|
|
|
|
|
|
|
|
snprintf(dirname, sizeof dirname, "%s/",
|
|
|
|
|
cwd[1] ? cwd : "");
|
|
|
|
|
|
|
|
|
|
pathlen = strlen(dirname);
|
|
|
|
|
rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen);
|
|
|
|
|
if(rc < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
rc = mkdir(dirname, 0);
|
|
|
|
|
if(rc < 0) {
|
|
|
|
|
splash(HZ, true, "%s %s", str(LANG_CREATE_DIR), str(LANG_FAILED));
|
|
|
|
|
} else {
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
int onplay(char* file, int attr)
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
struct menu_item items[5]; /* increase this if you add entries! */
|
2003-03-12 20:21:30 +00:00
|
|
|
|
int m, i=0, result;
|
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_OK;
|
|
|
|
|
|
2004-03-11 10:43:53 +00:00
|
|
|
|
if(file)
|
2003-04-10 21:01:22 +00:00
|
|
|
|
{
|
2004-03-11 10:43:53 +00:00
|
|
|
|
selected_file = file;
|
|
|
|
|
selected_file_attr = attr;
|
|
|
|
|
|
|
|
|
|
if (((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) ||
|
|
|
|
|
(attr & ATTR_DIRECTORY) ||
|
|
|
|
|
((attr & TREE_ATTR_MASK) == TREE_ATTR_M3U))
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_PLAYINDICES_PLAYLIST);
|
|
|
|
|
items[i].voice_id = LANG_PLAYINDICES_PLAYLIST;
|
|
|
|
|
items[i].function = playlist_options;
|
2004-03-11 10:43:53 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_RENAME);
|
|
|
|
|
items[i].voice_id = LANG_RENAME;
|
|
|
|
|
items[i].function = rename_file;
|
2003-04-10 21:01:22 +00:00
|
|
|
|
i++;
|
2004-03-11 10:43:53 +00:00
|
|
|
|
|
|
|
|
|
if (!(attr & ATTR_DIRECTORY))
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_DELETE);
|
|
|
|
|
items[i].voice_id = LANG_DELETE;
|
|
|
|
|
items[i].function = delete_file;
|
2004-03-11 10:43:53 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
|
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_VBRFIX);
|
|
|
|
|
items[i].voice_id = LANG_VBRFIX;
|
|
|
|
|
items[i].function = vbr_fix;
|
2004-03-11 10:43:53 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-04-10 21:01:22 +00:00
|
|
|
|
}
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].desc = str(LANG_CREATE_DIR);
|
|
|
|
|
items[i].voice_id = LANG_CREATE_DIR;
|
|
|
|
|
items[i].function = create_dir;
|
2003-04-10 21:01:22 +00:00
|
|
|
|
i++;
|
2003-04-02 08:20:51 +00:00
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
/* DIY menu handling, since we want to exit after selection */
|
2004-03-16 13:44:56 +00:00
|
|
|
|
m = menu_init( items, i, NULL, NULL, NULL, NULL );
|
2003-03-12 20:21:30 +00:00
|
|
|
|
result = menu_show(m);
|
|
|
|
|
if (result >= 0)
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[result].function();
|
2003-03-12 20:21:30 +00:00
|
|
|
|
menu_exit(m);
|
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
return onplay_result;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|