2010-05-17 15:03:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-05-17 21:42:07 +00:00
|
|
|
* $Id$
|
2010-05-17 15:03:59 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2011-02-18 23:29:11 +00:00
|
|
|
#include "system.h"
|
2010-05-17 15:03:59 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "radio.h"
|
|
|
|
#include "buffering.h"
|
2011-03-16 10:20:32 +00:00
|
|
|
#include "playback.h" /* bufopen_user_data */
|
2010-05-17 15:03:59 +00:00
|
|
|
#include "file.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "string-extra.h"
|
2010-08-01 16:15:27 +00:00
|
|
|
#include "filefuncs.h"
|
2010-05-17 15:03:59 +00:00
|
|
|
|
|
|
|
#define MAX_RADIOART_IMAGES 10
|
|
|
|
struct radioart {
|
|
|
|
int handle;
|
|
|
|
long last_tick;
|
|
|
|
struct dim dim;
|
|
|
|
char name[MAX_FMPRESET_LEN+1];
|
|
|
|
};
|
|
|
|
|
2012-05-21 06:18:46 +00:00
|
|
|
static char* buf;
|
2010-05-17 15:03:59 +00:00
|
|
|
static struct radioart radioart[MAX_RADIOART_IMAGES];
|
2012-05-21 06:18:46 +00:00
|
|
|
|
2013-05-21 05:33:00 +00:00
|
|
|
static int find_oldest_image_index(void)
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-05-21 05:33:00 +00:00
|
|
|
long oldest_tick = current_tick;
|
|
|
|
int oldest_idx = -1;
|
|
|
|
for(i = 0; ARRAYLEN(radioart); i++)
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
2013-05-21 05:33:00 +00:00
|
|
|
struct radioart *ra = &radioart[i];
|
|
|
|
/* last_tick is only valid if it's actually loaded, i.e. valid handle */
|
|
|
|
if (ra->handle >= 0 && TIME_BEFORE(ra->last_tick, oldest_tick))
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
2013-05-21 05:33:00 +00:00
|
|
|
oldest_tick = ra->last_tick;
|
2010-05-17 15:03:59 +00:00
|
|
|
oldest_idx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return oldest_idx;
|
|
|
|
}
|
2013-05-21 05:33:00 +00:00
|
|
|
|
2010-05-17 15:03:59 +00:00
|
|
|
static int load_radioart_image(struct radioart *ra, const char* preset_name,
|
|
|
|
struct dim *dim)
|
|
|
|
{
|
|
|
|
char path[MAX_PATH];
|
2011-03-16 10:20:32 +00:00
|
|
|
struct bufopen_bitmap_data user_data;
|
2010-05-17 15:03:59 +00:00
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
|
|
|
cpu_idle_mode(false);
|
|
|
|
#endif
|
|
|
|
snprintf(path, sizeof(path), FMPRESET_PATH "/%s.bmp",preset_name);
|
|
|
|
if (!file_exists(path))
|
|
|
|
snprintf(path, sizeof(path), FMPRESET_PATH "/%s.jpg",preset_name);
|
|
|
|
if (!file_exists(path))
|
|
|
|
{
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2011-05-08 20:35:29 +00:00
|
|
|
cpu_idle_mode(true);
|
2010-05-17 15:03:59 +00:00
|
|
|
#endif
|
|
|
|
return -1;
|
2011-05-08 20:35:29 +00:00
|
|
|
}
|
2010-05-17 15:03:59 +00:00
|
|
|
strlcpy(ra->name, preset_name, MAX_FMPRESET_LEN+1);
|
|
|
|
ra->dim.height = dim->height;
|
|
|
|
ra->dim.width = dim->width;
|
|
|
|
ra->last_tick = current_tick;
|
2011-03-16 10:20:32 +00:00
|
|
|
user_data.embedded_albumart = NULL;
|
|
|
|
user_data.dim = &ra->dim;
|
|
|
|
ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
|
2010-05-17 15:03:59 +00:00
|
|
|
if (ra->handle == ERR_BUFFER_FULL)
|
|
|
|
{
|
2013-05-21 05:33:00 +00:00
|
|
|
int i = find_oldest_image_index();
|
|
|
|
if (i != -1)
|
|
|
|
{
|
|
|
|
bufclose(radioart[i].handle);
|
|
|
|
ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
|
|
|
|
}
|
2010-05-17 15:03:59 +00:00
|
|
|
}
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
|
|
|
cpu_idle_mode(true);
|
|
|
|
#endif
|
|
|
|
return ra->handle;
|
|
|
|
}
|
|
|
|
int radio_get_art_hid(struct dim *requested_dim)
|
|
|
|
{
|
|
|
|
int preset = radio_current_preset();
|
2011-10-15 19:35:02 +00:00
|
|
|
int free_idx = -1;
|
2010-05-17 15:03:59 +00:00
|
|
|
const char* preset_name;
|
2012-05-21 06:18:46 +00:00
|
|
|
|
|
|
|
if (!buf || radio_scan_mode() || preset < 0)
|
2010-05-17 15:03:59 +00:00
|
|
|
return -1;
|
2012-05-21 06:18:46 +00:00
|
|
|
|
2010-05-17 15:03:59 +00:00
|
|
|
preset_name = radio_get_preset_name(preset);
|
2011-10-15 19:35:02 +00:00
|
|
|
for (int i=0; i<MAX_RADIOART_IMAGES; i++)
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
|
|
|
if (radioart[i].handle < 0)
|
|
|
|
{
|
|
|
|
free_idx = i;
|
|
|
|
}
|
|
|
|
else if (!strcmp(radioart[i].name, preset_name) &&
|
|
|
|
radioart[i].dim.width == requested_dim->width &&
|
|
|
|
radioart[i].dim.height == requested_dim->height)
|
|
|
|
{
|
|
|
|
radioart[i].last_tick = current_tick;
|
|
|
|
return radioart[i].handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (free_idx >= 0)
|
|
|
|
{
|
|
|
|
return load_radioart_image(&radioart[free_idx],
|
|
|
|
preset_name, requested_dim);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-21 05:33:00 +00:00
|
|
|
int i = find_oldest_image_index();
|
|
|
|
if (i != -1)
|
|
|
|
{
|
|
|
|
bufclose(radioart[i].handle);
|
|
|
|
return load_radioart_image(&radioart[i],
|
|
|
|
preset_name, requested_dim);
|
|
|
|
}
|
2010-05-17 15:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2012-05-21 06:18:46 +00:00
|
|
|
|
|
|
|
static void buffer_reset_handler(void *data)
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
2012-05-21 06:18:46 +00:00
|
|
|
buf = NULL;
|
|
|
|
for(int i=0;i<MAX_RADIOART_IMAGES;i++)
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
|
|
|
if (radioart[i].handle >= 0)
|
|
|
|
bufclose(radioart[i].handle);
|
|
|
|
radioart[i].handle = -1;
|
|
|
|
radioart[i].name[0] = '\0';
|
|
|
|
}
|
2012-05-21 06:18:46 +00:00
|
|
|
|
2010-05-17 15:03:59 +00:00
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void radioart_init(bool entering_screen)
|
|
|
|
{
|
|
|
|
if (entering_screen)
|
|
|
|
{
|
2011-08-23 18:43:17 +00:00
|
|
|
/* grab control over buffering */
|
|
|
|
size_t bufsize;
|
|
|
|
buf = audio_get_buffer(false, &bufsize);
|
|
|
|
buffering_reset(buf, bufsize);
|
2012-05-21 06:18:46 +00:00
|
|
|
/* one-shot */
|
|
|
|
add_event(BUFFER_EVENT_BUFFER_RESET, true, buffer_reset_handler);
|
2010-05-17 15:03:59 +00:00
|
|
|
}
|
2012-05-21 06:18:46 +00:00
|
|
|
else /* init at startup */
|
2010-05-17 15:03:59 +00:00
|
|
|
{
|
2012-05-21 06:18:46 +00:00
|
|
|
for(int i=0;i<MAX_RADIOART_IMAGES;i++)
|
|
|
|
{
|
|
|
|
radioart[i].handle = -1;
|
|
|
|
radioart[i].name[0] = '\0';
|
|
|
|
}
|
2010-05-17 15:03:59 +00:00
|
|
|
}
|
|
|
|
}
|