2005-06-05 23:05:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 09:40:22 +00:00
|
|
|
* Copyright (C) 2005-2007 Miika Pekkarinen
|
|
|
|
* Copyright (C) 2007-2008 Nicolas Pennequin
|
2011-04-27 03:08:23 +00:00
|
|
|
* Copyright (C) 2011 Michael Sevakis
|
2005-06-05 23:05:10 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2005-06-05 23:05:10 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-02-23 14:31:13 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
2005-06-05 23:05:10 +00:00
|
|
|
#include "kernel.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "panic.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "sound.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#include "codecs.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "codec_thread.h"
|
2007-11-18 17:12:19 +00:00
|
|
|
#include "voice_thread.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "metadata.h"
|
|
|
|
#include "cuesheet.h"
|
|
|
|
#include "buffering.h"
|
|
|
|
#include "talk.h"
|
2005-06-05 23:05:10 +00:00
|
|
|
#include "playlist.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "abrepeat.h"
|
2005-07-13 12:48:22 +00:00
|
|
|
#include "pcmbuf.h"
|
2013-05-31 06:41:02 +00:00
|
|
|
#include "audio_thread.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
#include "playback.h"
|
2020-07-08 20:01:38 +00:00
|
|
|
#include "storage.h"
|
2011-06-29 06:37:04 +00:00
|
|
|
#include "misc.h"
|
2011-08-30 19:48:08 +00:00
|
|
|
#include "settings.h"
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-03-26 16:37:18 +00:00
|
|
|
#include "tagcache.h"
|
2006-10-25 10:17:57 +00:00
|
|
|
#endif
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2005-06-05 23:05:10 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2009-10-16 19:14:41 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
2007-11-11 12:29:37 +00:00
|
|
|
#include "albumart.h"
|
2009-10-16 19:14:41 +00:00
|
|
|
#endif
|
2005-06-05 23:05:10 +00:00
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2017-11-24 12:55:56 +00:00
|
|
|
#ifdef HAVE_PLAY_FREQ
|
|
|
|
#include "pcm_mixer.h"
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* TODO: The audio thread really is doing multitasking of acting like a
|
|
|
|
consumer and producer of tracks. It may be advantageous to better
|
|
|
|
logically separate the two functions. I won't go that far just yet. */
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Internal support for voice playback */
|
2006-09-17 08:34:42 +00:00
|
|
|
#define PLAYBACK_VOICE
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#if CONFIG_PLATFORM & PLATFORM_NATIVE
|
|
|
|
/* Application builds don't support direct code loading */
|
|
|
|
#define HAVE_CODEC_BUFFERING
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Amount of guess-space to allow for codecs that must hunt and peck
|
|
|
|
* for their correct seek target, 32k seems a good size */
|
2006-04-11 03:55:58 +00:00
|
|
|
#define AUDIO_REBUFFER_GUESS_SIZE (1024*32)
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2007-10-24 22:06:36 +00:00
|
|
|
/* Define LOGF_ENABLE to enable logf output in this file */
|
2017-12-08 18:01:25 +00:00
|
|
|
#if 0
|
|
|
|
#define LOGF_ENABLE
|
|
|
|
#endif
|
2007-10-24 22:06:36 +00:00
|
|
|
#include "logf.h"
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Macros to enable logf for queues
|
2006-11-06 18:07:30 +00:00
|
|
|
logging on SYS_TIMEOUT can be disabled */
|
2007-05-09 03:48:52 +00:00
|
|
|
#ifdef SIMULATOR
|
2006-11-06 18:07:30 +00:00
|
|
|
/* Define this for logf output of all queuing except SYS_TIMEOUT */
|
|
|
|
#define PLAYBACK_LOGQUEUES
|
|
|
|
/* Define this to logf SYS_TIMEOUT messages */
|
2007-10-24 22:06:36 +00:00
|
|
|
/*#define PLAYBACK_LOGQUEUES_SYS_TIMEOUT*/
|
2006-08-31 10:01:07 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-17 08:34:42 +00:00
|
|
|
#ifdef PLAYBACK_LOGQUEUES
|
2007-05-08 23:13:46 +00:00
|
|
|
#define LOGFQUEUE logf
|
2006-08-31 10:01:07 +00:00
|
|
|
#else
|
2007-05-08 23:13:46 +00:00
|
|
|
#define LOGFQUEUE(...)
|
2006-08-31 10:01:07 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
#ifdef PLAYBACK_LOGQUEUES_SYS_TIMEOUT
|
2007-05-08 23:13:46 +00:00
|
|
|
#define LOGFQUEUE_SYS_TIMEOUT logf
|
2006-11-06 18:07:30 +00:00
|
|
|
#else
|
2007-05-08 23:13:46 +00:00
|
|
|
#define LOGFQUEUE_SYS_TIMEOUT(...)
|
2006-11-06 18:07:30 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Variables are commented with the threads that use them:
|
|
|
|
* A=audio, C=codec, O=other. A suffix of "-" indicates that the variable is
|
|
|
|
* read but not updated on that thread. Audio is the only user unless otherwise
|
|
|
|
* specified.
|
|
|
|
*/
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** Miscellaneous **/
|
2013-05-31 06:41:02 +00:00
|
|
|
extern unsigned int audio_thread_id; /* from audio_thread.c */
|
|
|
|
extern struct event_queue audio_queue; /* from audio_thread.c */
|
|
|
|
extern bool audio_is_initialized; /* from audio_thread.c */
|
|
|
|
extern struct codec_api ci; /* from codecs.c */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/** Possible arrangements of the main buffer **/
|
|
|
|
static enum audio_buffer_state
|
|
|
|
{
|
|
|
|
AUDIOBUF_STATE_TRASHED = -1, /* trashed; must be reset */
|
|
|
|
AUDIOBUF_STATE_INITIALIZED = 0, /* voice+audio OR audio-only */
|
|
|
|
} buffer_state = AUDIOBUF_STATE_TRASHED; /* (A,O) */
|
|
|
|
|
|
|
|
/** Main state control **/
|
|
|
|
static bool ff_rw_mode SHAREDBSS_ATTR = false; /* Pre-ff-rewind mode (A,O-) */
|
|
|
|
|
2015-01-11 17:02:43 +00:00
|
|
|
static enum play_status
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
PLAY_STOPPED = 0,
|
|
|
|
PLAY_PLAYING = AUDIO_STATUS_PLAY,
|
|
|
|
PLAY_PAUSED = AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE,
|
|
|
|
} play_status = PLAY_STOPPED;
|
|
|
|
|
|
|
|
/* Sizeable things that only need exist during playback and not when stopped */
|
|
|
|
static struct audio_scratch_memory
|
|
|
|
{
|
|
|
|
struct mp3entry codec_id3; /* (A,C) */
|
|
|
|
struct mp3entry unbuffered_id3;
|
|
|
|
struct cuesheet *curr_cue; /* Will follow this structure */
|
|
|
|
} * audio_scratch_memory = NULL;
|
|
|
|
|
|
|
|
/* These are used to store the current, next and optionally the peek-ahead
|
2011-05-09 21:52:06 +00:00
|
|
|
* mp3entry's - this guarantees that the pointer returned by audio_current/
|
2011-04-27 03:08:23 +00:00
|
|
|
* next_track will be valid for the full duration of the currently playing
|
|
|
|
* track */
|
|
|
|
enum audio_id3_types
|
|
|
|
{
|
|
|
|
/* These are allocated statically */
|
|
|
|
PLAYING_ID3 = 0,
|
|
|
|
NEXTTRACK_ID3,
|
|
|
|
#ifdef AUDIO_FAST_SKIP_PREVIEW
|
|
|
|
/* The real playing metadata must has to be protected since it contains
|
|
|
|
critical info for other features */
|
|
|
|
PLAYING_PEEK_ID3,
|
2011-02-23 14:31:13 +00:00
|
|
|
#endif
|
2011-04-27 03:08:23 +00:00
|
|
|
ID3_TYPE_NUM_STATIC,
|
|
|
|
/* These go in the scratch memory */
|
|
|
|
UNBUFFERED_ID3 = ID3_TYPE_NUM_STATIC,
|
|
|
|
CODEC_ID3,
|
|
|
|
};
|
|
|
|
static struct mp3entry static_id3_entries[ID3_TYPE_NUM_STATIC]; /* (A,O) */
|
2007-01-26 18:35:49 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
struct audio_resume_info
|
|
|
|
{
|
|
|
|
unsigned long elapsed;
|
|
|
|
unsigned long offset;
|
|
|
|
};
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Peeking functions can yield and mess us up */
|
2011-05-09 21:52:06 +00:00
|
|
|
static struct mutex id3_mutex SHAREDBSS_ATTR; /* (A,O)*/
|
2007-01-26 18:35:49 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** For album art support **/
|
2010-05-12 10:38:00 +00:00
|
|
|
#define MAX_MULTIPLE_AA SKINNABLE_SCREENS_COUNT
|
2009-10-31 19:17:36 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
2011-02-09 20:13:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
static struct albumart_slot
|
|
|
|
{
|
|
|
|
struct dim dim; /* Holds width, height of the albumart */
|
|
|
|
int used; /* Counter; increments if something uses it */
|
|
|
|
} albumart_slots[MAX_MULTIPLE_AA]; /* (A,O) */
|
2009-10-31 19:17:36 +00:00
|
|
|
|
2017-12-04 17:59:15 +00:00
|
|
|
#define FOREACH_ALBUMART(i) for (int i = 0; i < MAX_MULTIPLE_AA; i++)
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif /* HAVE_ALBUMART */
|
2009-10-31 19:17:36 +00:00
|
|
|
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** Information used for tracking buffer fills **/
|
2009-10-31 19:17:36 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Buffer and thread state tracking */
|
|
|
|
static enum filling_state
|
|
|
|
{
|
2011-09-01 12:15:43 +00:00
|
|
|
STATE_IDLE = 0, /* audio is stopped: nothing to do */
|
2011-04-27 03:08:23 +00:00
|
|
|
STATE_FILLING, /* adding tracks to the buffer */
|
|
|
|
STATE_FULL, /* can't add any more tracks */
|
|
|
|
STATE_END_OF_PLAYLIST, /* all remaining tracks have been added */
|
|
|
|
STATE_FINISHED, /* all remaining tracks are fully buffered */
|
|
|
|
STATE_ENDING, /* audio playback is ending */
|
|
|
|
STATE_ENDED, /* audio playback is done */
|
2011-09-01 12:15:43 +00:00
|
|
|
} filling = STATE_IDLE;
|
2007-10-02 07:47:43 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Track info - holds information about each track in the buffer */
|
2017-12-08 18:01:25 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
#define TRACK_INFO_AA MAX_MULTIPLE_AA
|
|
|
|
#else
|
|
|
|
#define TRACK_INFO_AA 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
|
|
|
#define TRACK_INFO_CODEC 1
|
|
|
|
#else
|
|
|
|
#define TRACK_INFO_CODEC 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TRACK_INFO_HANDLES (3 + TRACK_INFO_AA + TRACK_INFO_CODEC)
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
struct track_info
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
int self_hid; /* handle for the info on buffer */
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* In per-track allocated order: */
|
2017-12-08 18:01:25 +00:00
|
|
|
union {
|
|
|
|
int handle[TRACK_INFO_HANDLES]; /* array mirror for efficient wipe/close */
|
|
|
|
struct {
|
|
|
|
int id3_hid; /* Metadata handle ID */
|
|
|
|
int cuesheet_hid; /* Parsed cuesheet handle ID */
|
2011-04-27 03:08:23 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
2017-12-08 18:01:25 +00:00
|
|
|
int aa_hid[MAX_MULTIPLE_AA]; /* Album art handle IDs */
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
2017-12-08 18:01:25 +00:00
|
|
|
int codec_hid; /* Buffered codec handle ID */
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
2017-12-08 18:01:25 +00:00
|
|
|
int audio_hid; /* Main audio data handle ID */
|
|
|
|
}; };
|
2011-04-27 03:08:23 +00:00
|
|
|
};
|
2007-10-02 07:47:43 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* On-buffer info format; includes links */
|
|
|
|
struct track_buf_info
|
|
|
|
{
|
|
|
|
int link[2]; /* prev/next handles */
|
|
|
|
struct track_info info;
|
|
|
|
};
|
2009-10-16 19:14:41 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
#define FOR_EACH_TRACK_INFO_HANDLE(i) \
|
|
|
|
for (int i = 0; i < TRACK_INFO_HANDLES; i++)
|
2009-10-31 19:17:36 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
static struct
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
/* TODO: perhaps cache -1/+1 delta handles if speed ever matters much
|
|
|
|
because those lookups are common; also could cache a few recent
|
|
|
|
acccesses */
|
|
|
|
int first_hid; /* handle of first track in list */
|
|
|
|
int current_hid; /* handle of track delta 0 */
|
|
|
|
int last_hid; /* handle of last track in list */
|
|
|
|
int in_progress_hid; /* track in process of loading */
|
|
|
|
unsigned int count; /* number of tracks in list */
|
2011-04-27 03:08:23 +00:00
|
|
|
} track_list; /* (A, O-) */
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2006-10-12 15:54:36 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Playlist steps from playlist position to next track to be buffered */
|
|
|
|
static int playlist_peek_offset = 0;
|
2007-01-26 18:35:49 +00:00
|
|
|
|
2009-01-10 21:10:56 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Buffer margin A.K.A. anti-skip buffer (in seconds) */
|
|
|
|
static size_t buffer_margin = 5;
|
2009-01-10 21:10:56 +00:00
|
|
|
#endif
|
2005-06-06 00:35:21 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Values returned for track loading */
|
|
|
|
enum track_load_status
|
|
|
|
{
|
|
|
|
LOAD_TRACK_ERR_START_CODEC = -6,
|
|
|
|
LOAD_TRACK_ERR_FINISH_FAILED = -5,
|
|
|
|
LOAD_TRACK_ERR_FINISH_FULL = -4,
|
|
|
|
LOAD_TRACK_ERR_BUSY = -3,
|
|
|
|
LOAD_TRACK_ERR_NO_MORE = -2,
|
|
|
|
LOAD_TRACK_ERR_FAILED = -1,
|
|
|
|
LOAD_TRACK_OK = 0,
|
|
|
|
LOAD_TRACK_READY = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Track change controls **/
|
|
|
|
|
|
|
|
/* What sort of skip is pending globally? */
|
2015-01-11 17:02:43 +00:00
|
|
|
static enum track_skip_type
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Relative to what user is intended to see: */
|
|
|
|
/* Codec: +0, Track List: +0, Playlist: +0 */
|
|
|
|
TRACK_SKIP_NONE = 0, /* no track skip */
|
|
|
|
/* Codec: +1, Track List: +1, Playlist: +0 */
|
|
|
|
TRACK_SKIP_AUTO, /* codec-initiated skip */
|
|
|
|
/* Codec: +1, Track List: +1, Playlist: +1 */
|
|
|
|
TRACK_SKIP_AUTO_NEW_PLAYLIST, /* codec-initiated skip is new playlist */
|
|
|
|
/* Codec: xx, Track List: +0, Playlist: +0 */
|
|
|
|
TRACK_SKIP_AUTO_END_PLAYLIST, /* codec-initiated end of playlist */
|
|
|
|
/* Manual skip: Never pends */
|
|
|
|
TRACK_SKIP_MANUAL, /* manual track skip */
|
|
|
|
/* Manual skip: Never pends */
|
|
|
|
TRACK_SKIP_DIR_CHANGE, /* manual directory skip */
|
|
|
|
} skip_pending = TRACK_SKIP_NONE;
|
|
|
|
|
|
|
|
/* Note about TRACK_SKIP_AUTO_NEW_PLAYLIST:
|
|
|
|
Fixing playlist code to be able to peek into the first song of
|
|
|
|
the next playlist would fix any issues and this wouldn't need
|
|
|
|
to be a special case since pre-advancing the playlist would be
|
|
|
|
unneeded - it could be much more like TRACK_SKIP_AUTO and all
|
|
|
|
actions that require reversal during an in-progress transition
|
|
|
|
would work as expected */
|
|
|
|
|
|
|
|
/* Used to indicate status for the events. Must be separate to satisfy all
|
2013-07-12 16:06:38 +00:00
|
|
|
clients so the correct metadata is read when sending the change events. */
|
|
|
|
static unsigned int track_event_flags = TEF_NONE; /* (A, O-) */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Pending manual track skip offset */
|
|
|
|
static int skip_offset = 0; /* (A, O) */
|
|
|
|
|
|
|
|
/* Track change notification */
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
unsigned int in; /* Number of pcmbuf posts (audio isr) */
|
|
|
|
unsigned int out; /* Number of times audio has read the difference */
|
|
|
|
} track_change = { 0, 0 };
|
|
|
|
|
|
|
|
/** Codec status **/
|
2011-05-09 21:52:06 +00:00
|
|
|
/* Did the codec notify us it finished while we were paused or while still
|
2011-04-27 03:08:23 +00:00
|
|
|
in an automatic transition?
|
|
|
|
|
|
|
|
If paused, it is necessary to defer a codec-initiated skip until resuming
|
|
|
|
or else the track will move forward while not playing audio!
|
|
|
|
|
|
|
|
If in-progress, skips should not build-up ahead of where the WPS is when
|
|
|
|
really short tracks finish decoding.
|
|
|
|
|
|
|
|
If it is forgotten, it will be missed altogether and playback will just sit
|
|
|
|
there looking stupid and comatose until the user does something */
|
|
|
|
static bool codec_skip_pending = false;
|
|
|
|
static int codec_skip_status;
|
|
|
|
static bool codec_seeking = false; /* Codec seeking ack expected? */
|
2011-08-28 07:45:35 +00:00
|
|
|
static unsigned int position_key = 0;
|
2009-10-31 19:17:36 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Forward declarations */
|
|
|
|
enum audio_start_playback_flags
|
|
|
|
{
|
|
|
|
AUDIO_START_RESTART = 0x1, /* "Restart" playback (flush _all_ tracks) */
|
|
|
|
AUDIO_START_NEWBUF = 0x2, /* Mark the audiobuffer as invalid */
|
|
|
|
};
|
2006-04-09 15:30:28 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
static void audio_start_playback(const struct audio_resume_info *resume_info,
|
|
|
|
unsigned int flags);
|
2008-10-26 20:15:10 +00:00
|
|
|
static void audio_stop_playback(void);
|
2014-03-14 22:15:16 +00:00
|
|
|
static void buffer_event_buffer_low_callback(unsigned short id, void *data, void *user_data);
|
|
|
|
static void buffer_event_rebuffer_callback(unsigned short id, void *data);
|
|
|
|
static void buffer_event_finished_callback(unsigned short id, void *data);
|
2011-08-28 07:45:35 +00:00
|
|
|
void audio_pcmbuf_sync_position(void);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2005-08-20 11:13:19 +00:00
|
|
|
|
2009-10-31 19:17:36 +00:00
|
|
|
/**************************************/
|
2008-02-28 22:37:46 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** --- MP3Entry --- **/
|
2009-11-16 20:09:46 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Does the mp3entry have enough info for us to use it? */
|
|
|
|
static struct mp3entry * valid_mp3entry(const struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
return id3 && (id3->length != 0 || id3->filesize != 0) &&
|
|
|
|
id3->codectype != AFMT_UNKNOWN ? (struct mp3entry *)id3 : NULL;
|
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return a pointer to an mp3entry on the buffer, as it is */
|
|
|
|
static struct mp3entry * bufgetid3(int handle_id)
|
2007-10-25 21:27:45 +00:00
|
|
|
{
|
|
|
|
if (handle_id < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
struct mp3entry *id3;
|
|
|
|
ssize_t ret = bufgetdata(handle_id, 0, (void *)&id3);
|
|
|
|
|
2011-02-10 22:03:39 +00:00
|
|
|
if (ret != sizeof(struct mp3entry))
|
2007-10-25 21:27:45 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return id3;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Read an mp3entry from the buffer, adjusted */
|
2011-02-10 22:03:39 +00:00
|
|
|
static bool bufreadid3(int handle_id, struct mp3entry *id3out)
|
|
|
|
{
|
|
|
|
struct mp3entry *id3 = bufgetid3(handle_id);
|
|
|
|
|
|
|
|
if (id3)
|
|
|
|
{
|
|
|
|
copy_mp3entry(id3out, id3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Lock the id3 mutex */
|
|
|
|
static void id3_mutex_lock(void)
|
2007-10-25 21:27:45 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
mutex_lock(&id3_mutex);
|
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Unlock the id3 mutex */
|
|
|
|
static void id3_mutex_unlock(void)
|
|
|
|
{
|
|
|
|
mutex_unlock(&id3_mutex);
|
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return one of the collection of mp3entry pointers - collect them all here */
|
|
|
|
static inline struct mp3entry * id3_get(enum audio_id3_types id3_num)
|
|
|
|
{
|
|
|
|
switch (id3_num)
|
2009-10-16 19:14:41 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
case UNBUFFERED_ID3:
|
|
|
|
return &audio_scratch_memory->unbuffered_id3;
|
|
|
|
case CODEC_ID3:
|
|
|
|
return &audio_scratch_memory->codec_id3;
|
|
|
|
default:
|
|
|
|
return &static_id3_entries[id3_num];
|
2007-11-11 12:29:37 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2007-11-11 12:29:37 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Copy an mp3entry into one of the mp3 entries */
|
|
|
|
static void id3_write(enum audio_id3_types id3_num,
|
|
|
|
const struct mp3entry *id3_src)
|
|
|
|
{
|
|
|
|
struct mp3entry *dest_id3 = id3_get(id3_num);
|
2009-07-20 05:18:18 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (id3_src)
|
|
|
|
copy_mp3entry(dest_id3, id3_src);
|
|
|
|
else
|
|
|
|
wipe_mp3entry(dest_id3);
|
|
|
|
}
|
2007-11-04 19:01:02 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Call id3_write "safely" because peek aheads can yield, even if the fast
|
|
|
|
preview isn't enabled */
|
|
|
|
static void id3_write_locked(enum audio_id3_types id3_num,
|
|
|
|
const struct mp3entry *id3_src)
|
|
|
|
{
|
|
|
|
id3_mutex_lock();
|
|
|
|
id3_write(id3_num, id3_src);
|
|
|
|
id3_mutex_unlock();
|
2007-10-25 21:27:45 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 16:18:17 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** --- Track info --- **/
|
|
|
|
|
2017-12-09 22:34:33 +00:00
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
2017-12-08 18:01:25 +00:00
|
|
|
static void track_info_close_handle(int *hidp)
|
2007-04-12 05:58:09 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
bufclose(*hidp);
|
|
|
|
*hidp = ERR_HANDLE_NOT_FOUND;
|
2007-11-18 17:12:19 +00:00
|
|
|
}
|
2017-12-09 22:34:33 +00:00
|
|
|
#endif /* HAVE_CODEC_BUFFERING */
|
2007-11-18 17:12:19 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Invalidate all members to initial values - does not close handles or sync */
|
|
|
|
static void track_info_wipe(struct track_info *infop)
|
2007-11-18 17:12:19 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
/* don't touch ->self_hid */
|
2007-04-12 05:58:09 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
FOR_EACH_TRACK_INFO_HANDLE(i)
|
|
|
|
infop->handle[i] = ERR_HANDLE_NOT_FOUND;
|
|
|
|
}
|
2006-11-28 15:00:56 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** --- Track list --- **/
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Clear tracks in the list, optionally preserving the current track -
|
|
|
|
returns 'false' if the operation was changed */
|
|
|
|
enum track_clear_action
|
|
|
|
{
|
|
|
|
TRACK_LIST_CLEAR_ALL = 0, /* Clear all tracks */
|
|
|
|
TRACK_LIST_KEEP_CURRENT, /* Keep current only; clear before + after */
|
|
|
|
TRACK_LIST_KEEP_NEW /* Keep current and those that follow */
|
|
|
|
};
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Initialize the track list */
|
2013-06-30 02:19:59 +00:00
|
|
|
static void INIT_ATTR track_list_init(void)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.first_hid = 0;
|
|
|
|
track_list.current_hid = 0;
|
|
|
|
track_list.last_hid = 0;
|
|
|
|
track_list.in_progress_hid = 0;
|
|
|
|
track_list.count = 0;
|
2006-11-06 18:07:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return number of items allocated in the list */
|
2017-12-08 18:01:25 +00:00
|
|
|
static inline unsigned int track_list_count(void)
|
2008-12-13 01:32:39 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
return track_list.count;
|
2008-12-13 01:32:39 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return true if the list is empty */
|
|
|
|
static inline bool track_list_empty(void)
|
2006-11-06 18:07:30 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
return track_list.count == 0;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Returns a pointer to the track info data on the buffer */
|
|
|
|
static struct track_buf_info * track_buf_info_get(int hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
void *p;
|
|
|
|
ssize_t size = bufgetdata(hid, sizeof (struct track_buf_info), &p);
|
|
|
|
return size == (ssize_t)sizeof (struct track_buf_info) ? p : NULL;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Synchronize the buffer object with the cached track info */
|
|
|
|
static bool track_info_sync(const struct track_info *infop)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_buf_info *tbip = track_buf_info_get(infop->self_hid);
|
|
|
|
if (!tbip)
|
|
|
|
return false;
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
tbip->info = *infop;
|
|
|
|
return true;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-04-22 14:40:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Return track info a given offset from the info referenced by hid and
|
|
|
|
* place a copy into *infop, if provided */
|
|
|
|
static struct track_buf_info *
|
|
|
|
track_list_get_info_from(int hid, int offset, struct track_info *infop)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
int sgn = SGN(offset);
|
|
|
|
struct track_buf_info *tbip;
|
2006-04-22 14:40:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (!(tbip = track_buf_info_get(hid)))
|
|
|
|
break;
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!offset)
|
|
|
|
break;
|
2007-11-11 12:29:37 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if ((hid = tbip->link[(unsigned)(sgn + 1) / 2]) <= 0)
|
|
|
|
{
|
|
|
|
tbip = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-29 13:55:34 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
offset -= sgn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (infop)
|
|
|
|
{
|
|
|
|
if (tbip)
|
|
|
|
{
|
|
|
|
*infop = tbip->info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
track_info_wipe(infop);
|
|
|
|
infop->self_hid = ERR_HANDLE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tbip;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-02-07 20:38:55 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Commit the track info to the buffer updated with the provided source info */
|
|
|
|
static bool track_list_commit_buf_info(struct track_buf_info *tbip,
|
|
|
|
const struct track_info *src_infop)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Leaves the list unmodified if anything fails */
|
|
|
|
if (tbip->link[1] != ERR_HANDLE_NOT_FOUND)
|
|
|
|
return false;
|
2009-04-21 03:33:39 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
int hid = tbip->info.self_hid;
|
|
|
|
int last_hid = track_list.last_hid;
|
|
|
|
struct track_buf_info *last_tbip = NULL;
|
2009-04-21 03:33:39 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (last_hid > 0 && !(last_tbip = track_buf_info_get(last_hid)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tbip->info = *src_infop;
|
|
|
|
|
|
|
|
/* Insert last */
|
|
|
|
tbip->link[0] = last_hid;
|
|
|
|
tbip->link[1] = 0; /* "In list" */
|
|
|
|
|
|
|
|
if (last_tbip)
|
|
|
|
{
|
|
|
|
last_tbip->link[1] = hid;
|
|
|
|
}
|
|
|
|
else
|
2007-11-11 15:50:52 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.first_hid = hid;
|
|
|
|
track_list.current_hid = hid;
|
2007-11-11 15:50:52 +00:00
|
|
|
}
|
2017-12-08 18:01:25 +00:00
|
|
|
|
|
|
|
track_list.last_hid = hid;
|
|
|
|
track_list.count++;
|
|
|
|
return true;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2006-04-22 14:40:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Free the track buffer entry and possibly remove it from the list if it
|
|
|
|
was succesfully added at some point */
|
|
|
|
static void track_list_free_buf_info(struct track_buf_info *tbip)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
int hid = tbip->info.self_hid;
|
|
|
|
int next_hid = tbip->link[1];
|
2005-07-16 12:25:28 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (next_hid != ERR_HANDLE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
int prev_hid = tbip->link[0];
|
|
|
|
struct track_buf_info *prev_tbip = NULL;
|
|
|
|
struct track_buf_info *next_tbip = NULL;
|
|
|
|
|
|
|
|
if ((prev_hid > 0 && !(prev_tbip = track_buf_info_get(prev_hid))) ||
|
|
|
|
(next_hid > 0 && !(next_tbip = track_buf_info_get(next_hid))))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-16 02:46:30 +00:00
|
|
|
/* If this one is the current track; new current track is next one,
|
|
|
|
if any, else, the previous */
|
|
|
|
if (hid == track_list.current_hid)
|
|
|
|
track_list.current_hid = next_hid > 0 ? next_hid : prev_hid;
|
|
|
|
|
|
|
|
/* Fixup list links */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (prev_tbip)
|
|
|
|
prev_tbip->link[1] = next_hid;
|
|
|
|
else
|
|
|
|
track_list.first_hid = next_hid;
|
|
|
|
|
|
|
|
if (next_tbip)
|
|
|
|
next_tbip->link[0] = prev_hid;
|
|
|
|
else
|
|
|
|
track_list.last_hid = prev_hid;
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No movement allowed during bufclose calls */
|
|
|
|
buf_pin_handle(hid, true);
|
|
|
|
|
|
|
|
FOR_EACH_TRACK_INFO_HANDLE(i)
|
|
|
|
bufclose(tbip->info.handle[i]);
|
|
|
|
|
|
|
|
/* Finally, the handle itself */
|
|
|
|
bufclose(hid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return current track plus an offset */
|
|
|
|
static bool track_list_current(int offset, struct track_info *infop)
|
|
|
|
{
|
|
|
|
return !!track_list_get_info_from(track_list.current_hid, offset, infop);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return current based upon what's intended that the user sees - not
|
|
|
|
necessarily where decoding is taking place */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool track_list_user_current(int offset, struct track_info *infop)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
if (skip_pending == TRACK_SKIP_AUTO ||
|
|
|
|
skip_pending == TRACK_SKIP_AUTO_NEW_PLAYLIST)
|
2007-11-11 15:50:52 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
offset--;
|
2007-11-11 15:50:52 +00:00
|
|
|
}
|
2007-11-08 16:52:29 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
return !!track_list_get_info_from(track_list.current_hid, offset, infop);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2005-08-20 11:13:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Advance current track by an offset, return false if result is out of
|
|
|
|
bounds */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool track_list_advance_current(int offset, struct track_info *infop)
|
2010-01-13 06:02:38 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_buf_info *new_bufinfop =
|
|
|
|
track_list_get_info_from(track_list.current_hid, offset, infop);
|
2010-01-13 06:02:38 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!new_bufinfop)
|
|
|
|
return false;
|
2011-02-10 22:03:39 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.current_hid = new_bufinfop->info.self_hid;
|
|
|
|
return true;
|
2010-01-13 06:02:38 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Return the info of the last allocation plus an offset, NULL if result is
|
|
|
|
out of bounds */
|
|
|
|
static bool track_list_last(int offset, struct track_info *infop)
|
2009-10-16 19:14:41 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
return !!track_list_get_info_from(track_list.last_hid, offset, infop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new struct track_info on the buffer; does not add to list */
|
|
|
|
static bool track_list_alloc_info(struct track_info *infop)
|
|
|
|
{
|
|
|
|
int hid = bufalloc(NULL, sizeof (struct track_buf_info), TYPE_RAW_ATOMIC);
|
|
|
|
|
|
|
|
track_info_wipe(infop);
|
|
|
|
|
|
|
|
struct track_buf_info *tbip = track_buf_info_get(hid);
|
|
|
|
if (!tbip)
|
|
|
|
{
|
|
|
|
infop->self_hid = ERR_HANDLE_NOT_FOUND;
|
|
|
|
bufclose(hid);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
infop->self_hid = hid;
|
|
|
|
|
|
|
|
tbip->link[0] = 0;
|
|
|
|
tbip->link[1] = ERR_HANDLE_NOT_FOUND; /* "Not in list" */
|
|
|
|
tbip->info.self_hid = hid;
|
|
|
|
track_info_wipe(&tbip->info);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Actually commit the track info to the track list */
|
|
|
|
static bool track_list_commit_info(const struct track_info *infop)
|
|
|
|
{
|
|
|
|
struct track_buf_info *tbip = track_buf_info_get(infop->self_hid);
|
|
|
|
if (!tbip)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return track_list_commit_buf_info(tbip, infop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the track entry and possibly remove it from the list if it was
|
|
|
|
succesfully added at some point */
|
|
|
|
static void track_list_free_info(struct track_info *infop)
|
|
|
|
{
|
|
|
|
struct track_buf_info *tbip = track_buf_info_get(infop->self_hid);
|
|
|
|
if (!tbip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
track_list_free_buf_info(tbip);
|
|
|
|
}
|
2009-10-16 19:14:41 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Close all open handles in the range except the for the current track
|
|
|
|
if preserving that */
|
|
|
|
static void track_list_clear(unsigned int action)
|
2009-10-16 19:14:41 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:action=%u", __func__, action);
|
2011-02-09 20:13:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Don't care now since rebuffering is imminent */
|
|
|
|
buf_set_watermark(0);
|
|
|
|
|
|
|
|
if (action != TRACK_LIST_CLEAR_ALL)
|
2009-10-16 19:14:41 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
if (!track_list_current(0, &info) || info.id3_hid < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
action = TRACK_LIST_CLEAR_ALL; /* Nothing worthwhile keeping */
|
|
|
|
}
|
2011-02-09 20:13:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
int hid = track_list.first_hid;
|
|
|
|
int current_hid = track_list.current_hid;
|
|
|
|
int last_hid = action == TRACK_LIST_KEEP_NEW ? current_hid : 0;
|
2009-10-16 19:14:41 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
while (hid != last_hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_buf_info *tbip = track_buf_info_get(hid);
|
|
|
|
if (!tbip)
|
|
|
|
break;
|
2006-10-25 08:54:25 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
int next_hid = tbip->link[1];
|
2005-06-26 19:41:29 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (action != TRACK_LIST_KEEP_CURRENT || hid != current_hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* If this is the in-progress load, abort it */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (hid == track_list.in_progress_hid)
|
|
|
|
track_list.in_progress_hid = 0;
|
2006-01-21 22:42:44 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_free_buf_info(tbip);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-09-26 07:19:43 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
hid = next_hid;
|
2006-09-17 08:34:42 +00:00
|
|
|
}
|
2008-02-26 17:15:33 +00:00
|
|
|
}
|
2006-09-26 07:19:43 +00:00
|
|
|
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** --- Audio buffer -- **/
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* What size is needed for the scratch buffer? */
|
|
|
|
static size_t scratch_mem_size(void)
|
2006-04-22 14:40:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
size_t size = sizeof (struct audio_scratch_memory);
|
2005-07-12 16:45:38 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (global_settings.cuesheet)
|
|
|
|
size += sizeof (struct cuesheet);
|
2006-04-06 16:21:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return size;
|
2006-04-09 02:15:35 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Initialize the memory area where data is stored that is only used when
|
|
|
|
playing audio and anything depending upon it */
|
|
|
|
static void scratch_mem_init(void *mem)
|
2006-04-09 02:15:35 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_scratch_memory = (struct audio_scratch_memory *)mem;
|
|
|
|
id3_write_locked(UNBUFFERED_ID3, NULL);
|
|
|
|
id3_write(CODEC_ID3, NULL);
|
|
|
|
ci.id3 = id3_get(CODEC_ID3);
|
|
|
|
audio_scratch_memory->curr_cue = NULL;
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (global_settings.cuesheet)
|
|
|
|
{
|
|
|
|
audio_scratch_memory->curr_cue =
|
|
|
|
SKIPBYTES((struct cuesheet *)audio_scratch_memory,
|
|
|
|
sizeof (struct audio_scratch_memory));
|
|
|
|
}
|
2006-04-09 02:15:35 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
static int audiobuf_handle;
|
2011-11-17 17:55:02 +00:00
|
|
|
#define AUDIO_BUFFER_RESERVE (256*1024)
|
2011-08-30 14:01:33 +00:00
|
|
|
static size_t filebuflen;
|
|
|
|
|
2011-11-17 17:55:02 +00:00
|
|
|
|
|
|
|
size_t audio_buffer_size(void)
|
|
|
|
{
|
|
|
|
if (audiobuf_handle > 0)
|
|
|
|
return filebuflen - AUDIO_BUFFER_RESERVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
size_t audio_buffer_available(void)
|
|
|
|
{
|
2011-11-17 17:55:02 +00:00
|
|
|
size_t size = 0;
|
|
|
|
size_t core_size = core_available();
|
|
|
|
if (audiobuf_handle > 0) /* if allocated return what we can give */
|
|
|
|
size = filebuflen - AUDIO_BUFFER_RESERVE - 128;
|
|
|
|
return MAX(core_size, size);
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* Set up the audio buffer for playback
|
|
|
|
* filebuflen must be pre-initialized with the maximum size */
|
2012-05-02 21:22:28 +00:00
|
|
|
static void audio_reset_buffer_noalloc(
|
2013-05-30 09:24:16 +00:00
|
|
|
void *filebuf)
|
2006-07-29 17:25:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/*
|
|
|
|
* Layout audio buffer as follows:
|
2013-05-30 09:24:16 +00:00
|
|
|
* [|SCRATCH|BUFFERING|PCM]
|
2011-04-27 03:08:23 +00:00
|
|
|
*/
|
|
|
|
logf("%s()", __func__);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* If the setup of anything allocated before the file buffer is
|
|
|
|
changed, do check the adjustments after the buffer_alloc call
|
|
|
|
as it will likely be affected and need sliding over */
|
2011-08-30 14:01:33 +00:00
|
|
|
size_t allocsize;
|
2013-05-30 09:24:16 +00:00
|
|
|
/* Subtract whatever the pcm buffer says it used plus the guard
|
|
|
|
buffer */
|
|
|
|
allocsize = pcmbuf_init(filebuf + filebuflen);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
/* Make sure filebuflen is a pointer sized multiple after
|
|
|
|
adjustment */
|
2011-08-14 15:13:00 +00:00
|
|
|
allocsize = ALIGN_UP(allocsize, sizeof (intptr_t));
|
|
|
|
if (allocsize > filebuflen)
|
|
|
|
goto bufpanic;
|
|
|
|
|
|
|
|
filebuflen -= allocsize;
|
2006-03-24 13:43:15 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
/* Scratch memory */
|
|
|
|
allocsize = scratch_mem_size();
|
|
|
|
if (allocsize > filebuflen)
|
|
|
|
goto bufpanic;
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
scratch_mem_init(filebuf);
|
|
|
|
filebuf += allocsize;
|
|
|
|
filebuflen -= allocsize;
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
buffering_reset(filebuf, filebuflen);
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
buffer_state = AUDIOBUF_STATE_INITIALIZED;
|
2007-03-19 22:04:17 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#if defined(ROCKBOX_HAS_LOGF) && defined(LOGF_ENABLE)
|
|
|
|
/* Make sure everything adds up - yes, some info is a bit redundant but
|
2011-05-09 21:52:06 +00:00
|
|
|
aids viewing and the summation of certain variables should add up to
|
2011-04-27 03:08:23 +00:00
|
|
|
the location of others. */
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("fbuf: %08X", (unsigned)filebuf);
|
|
|
|
logf("fbufe: %08X", (unsigned)(filebuf + filebuflen));
|
|
|
|
logf("sbuf: %08X", (unsigned)audio_scratch_memory);
|
|
|
|
logf("sbufe: %08X", (unsigned)(audio_scratch_memory + allocsize));
|
2005-06-05 23:05:10 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return;
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
bufpanic:
|
|
|
|
panicf("%s(): EOM (%zu > %zu)", __func__, allocsize, filebuflen);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2007-08-06 13:08:36 +00:00
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/* Buffer must not move. */
|
|
|
|
static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
|
|
|
|
{
|
2011-11-05 10:01:22 +00:00
|
|
|
struct queue_event ev;
|
|
|
|
static const long filter_list[][2] =
|
|
|
|
{
|
|
|
|
/* codec messages */
|
|
|
|
{ Q_AUDIO_PLAY, Q_AUDIO_PLAY },
|
|
|
|
};
|
2013-07-14 11:59:39 +00:00
|
|
|
|
|
|
|
static struct audio_resume_info resume;
|
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
bool give_up = false;
|
2013-07-14 11:59:39 +00:00
|
|
|
|
2011-11-03 21:51:46 +00:00
|
|
|
/* filebuflen is, at this point, the buffering.c buffer size,
|
|
|
|
* i.e. the audiobuf except voice, scratch mem, pcm, ... */
|
|
|
|
ssize_t extradata_size = old_size - filebuflen;
|
|
|
|
/* check what buflib requests */
|
|
|
|
size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK);
|
|
|
|
ssize_t size = (ssize_t)old_size - wanted_size;
|
2013-05-30 09:24:16 +00:00
|
|
|
|
2011-11-17 17:55:02 +00:00
|
|
|
if ((size - extradata_size) < AUDIO_BUFFER_RESERVE)
|
2013-05-30 09:24:16 +00:00
|
|
|
{
|
|
|
|
/* check if buflib needs the memory really hard. if yes we give
|
|
|
|
* up playback for now, otherwise refuse to shrink to keep at least
|
|
|
|
* 256K for the buffering */
|
|
|
|
if ((hints & BUFLIB_SHRINK_POS_MASK) == BUFLIB_SHRINK_POS_MASK)
|
|
|
|
give_up = true;
|
|
|
|
else
|
|
|
|
return BUFLIB_CB_CANNOT_SHRINK;
|
|
|
|
}
|
2011-11-03 21:51:46 +00:00
|
|
|
|
2011-11-05 10:01:22 +00:00
|
|
|
|
2011-09-19 20:52:00 +00:00
|
|
|
/* TODO: Do it without stopping playback, if possible */
|
2013-07-14 11:59:39 +00:00
|
|
|
struct mp3entry *id3 = audio_current_track();
|
|
|
|
unsigned long elapsed = id3->elapsed;
|
|
|
|
unsigned long offset = id3->offset;
|
2012-03-23 09:48:50 +00:00
|
|
|
/* resume if playing */
|
|
|
|
bool playing = (audio_status() == AUDIO_STATUS_PLAY);
|
2011-11-05 10:01:22 +00:00
|
|
|
/* There's one problem with stoping and resuming: If it happens in a too
|
|
|
|
* frequent fashion, the codecs lose the resume postion and playback
|
|
|
|
* begins from the beginning.
|
|
|
|
* To work around use queue_post() to effectively delay the resume in case
|
|
|
|
* we're called another time. However this has another problem: id3->offset
|
|
|
|
* gets zero since playback is stopped. Therefore, try to peek at the
|
|
|
|
* queue_post from the last call to get the correct offset. This also
|
2011-11-06 12:07:33 +00:00
|
|
|
* lets us conviniently remove the queue event so Q_AUDIO_PLAY is only
|
2011-11-05 10:01:22 +00:00
|
|
|
* processed once. */
|
2013-07-14 11:59:39 +00:00
|
|
|
bool play_queued = queue_peek_ex(&audio_queue, &ev, QPEEK_REMOVE_EVENTS,
|
|
|
|
filter_list);
|
2011-11-05 10:01:22 +00:00
|
|
|
|
2014-06-20 08:54:18 +00:00
|
|
|
if (playing && (elapsed > 0 || offset > 0))
|
2013-07-14 11:59:39 +00:00
|
|
|
{
|
2014-06-20 08:54:18 +00:00
|
|
|
if (play_queued)
|
|
|
|
resume = *(struct audio_resume_info *)ev.data;
|
2013-07-14 11:59:39 +00:00
|
|
|
|
|
|
|
/* current id3->elapsed/offset are king */
|
|
|
|
if (elapsed > 0)
|
|
|
|
resume.elapsed = elapsed;
|
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
resume.offset = offset;
|
|
|
|
}
|
2011-11-05 10:01:22 +00:00
|
|
|
|
2011-09-19 20:52:00 +00:00
|
|
|
/* don't call audio_hard_stop() as it frees this handle */
|
|
|
|
if (thread_self() == audio_thread_id)
|
|
|
|
{ /* inline case Q_AUDIO_STOP (audio_hard_stop() response
|
|
|
|
* if we're in the audio thread */
|
|
|
|
audio_stop_playback();
|
|
|
|
queue_clear(&audio_queue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
audio_queue_send(Q_AUDIO_STOP, 1);
|
|
|
|
#ifdef PLAYBACK_VOICE
|
|
|
|
voice_stop();
|
|
|
|
#endif
|
2013-05-30 09:24:16 +00:00
|
|
|
|
|
|
|
/* we should be free to change the buffer now */
|
|
|
|
if (give_up)
|
|
|
|
{
|
|
|
|
buffer_state = AUDIOBUF_STATE_TRASHED;
|
|
|
|
audiobuf_handle = core_free(audiobuf_handle);
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
/* set final buffer size before calling audio_reset_buffer_noalloc()
|
2011-11-03 21:51:46 +00:00
|
|
|
* (now it's the total size, the call will subtract voice etc) */
|
2011-09-19 20:52:00 +00:00
|
|
|
filebuflen = size;
|
2011-08-30 14:01:45 +00:00
|
|
|
switch (hints & BUFLIB_SHRINK_POS_MASK)
|
|
|
|
{
|
|
|
|
case BUFLIB_SHRINK_POS_BACK:
|
|
|
|
core_shrink(handle, start, size);
|
2013-05-30 09:24:16 +00:00
|
|
|
audio_reset_buffer_noalloc(start);
|
2011-08-30 14:01:45 +00:00
|
|
|
break;
|
|
|
|
case BUFLIB_SHRINK_POS_FRONT:
|
|
|
|
core_shrink(handle, start + wanted_size, size);
|
2013-05-30 09:24:16 +00:00
|
|
|
audio_reset_buffer_noalloc(start + wanted_size);
|
2011-08-30 14:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-11-05 10:01:22 +00:00
|
|
|
if (playing || play_queued)
|
2011-09-19 20:52:00 +00:00
|
|
|
{
|
2011-11-05 10:01:22 +00:00
|
|
|
/* post, to make subsequent calls not break the resume position */
|
2013-07-14 11:59:39 +00:00
|
|
|
audio_queue_post(Q_AUDIO_PLAY, (intptr_t)&resume);
|
2011-08-30 14:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buflib_callbacks ops = {
|
|
|
|
.move_callback = NULL,
|
|
|
|
.shrink_callback = shrink_callback,
|
|
|
|
};
|
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
static void audio_reset_buffer(void)
|
2011-08-30 14:01:45 +00:00
|
|
|
{
|
|
|
|
if (audiobuf_handle > 0)
|
|
|
|
{
|
|
|
|
core_free(audiobuf_handle);
|
|
|
|
audiobuf_handle = 0;
|
|
|
|
}
|
|
|
|
audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops);
|
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
if (audiobuf_handle > 0)
|
|
|
|
audio_reset_buffer_noalloc(core_get_data(audiobuf_handle));
|
|
|
|
else
|
|
|
|
/* someone is abusing core_alloc_maximum(). Fix this evil guy instead of
|
|
|
|
* trying to handle OOM without hope */
|
|
|
|
panicf("%s(): OOM!\n", __func__);
|
2011-08-30 14:01:45 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Set the buffer margin to begin rebuffering when 'seconds' from empty */
|
|
|
|
static void audio_update_filebuf_watermark(int seconds)
|
2006-04-11 03:55:58 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
size_t bytes = 0;
|
2006-04-13 14:17:12 +00:00
|
|
|
|
2009-04-19 19:38:56 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
2020-07-08 18:50:30 +00:00
|
|
|
int spinup = storage_spinup_time();
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (seconds == 0)
|
|
|
|
{
|
|
|
|
/* By current setting */
|
|
|
|
seconds = buffer_margin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* New setting */
|
|
|
|
buffer_margin = seconds;
|
|
|
|
|
|
|
|
if (buf_get_watermark() == 0)
|
|
|
|
{
|
|
|
|
/* Write a watermark only if the audio thread already did so for
|
|
|
|
itself or it will fail to set the event and the watermark - if
|
|
|
|
it hasn't yet, it will use the new setting when it does */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 21:10:56 +00:00
|
|
|
if (spinup)
|
2011-04-27 03:08:23 +00:00
|
|
|
seconds += (spinup / HZ) + 1;
|
2009-01-10 21:10:56 +00:00
|
|
|
else
|
2011-04-27 03:08:23 +00:00
|
|
|
seconds += 5;
|
2009-04-19 19:38:56 +00:00
|
|
|
|
|
|
|
seconds += buffer_margin;
|
|
|
|
#else
|
|
|
|
/* flash storage */
|
2011-04-27 03:08:23 +00:00
|
|
|
seconds = 1;
|
2009-01-10 21:10:56 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Watermark is a function of the bitrate of the last track in the buffer */
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
2011-05-09 21:52:06 +00:00
|
|
|
struct mp3entry *id3 = NULL;
|
2008-04-03 17:51:53 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (track_list_last(0, &info))
|
|
|
|
id3 = valid_mp3entry(bufgetid3(info.id3_hid));
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (id3)
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2011-08-12 05:27:13 +00:00
|
|
|
if (!rbcodec_format_is_atomic(id3->codectype))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
bytes = id3->bitrate * (1000/8) * seconds;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Bitrate has no meaning to buffering margin for atomic audio -
|
2011-05-09 21:52:06 +00:00
|
|
|
rebuffer when it's the only track left unless it's the only
|
2011-04-27 03:08:23 +00:00
|
|
|
track that fits, in which case we should avoid constant buffer
|
|
|
|
low events */
|
|
|
|
if (track_list_count() > 1)
|
2017-12-17 21:12:10 +00:00
|
|
|
bytes = buf_filesize(info.audio_hid) + 1;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2008-04-14 16:17:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Then set the minimum - this should not occur anyway */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("fwmark: No id3 for last track (f=%d:c=%d:l=%d)",
|
|
|
|
track_list.first_hid, track_list.current_hid, track_list.last_hid);
|
2008-04-14 16:17:47 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Actually setting zero disables the notification and we use that
|
|
|
|
to detect that it has been reset */
|
|
|
|
buf_set_watermark(MAX(bytes, 1));
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("fwmark: %zu", bytes);
|
2008-04-03 17:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** -- Track change notification -- **/
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Check the pcmbuf track changes and return write the message into the event
|
|
|
|
if there are any */
|
|
|
|
static inline bool audio_pcmbuf_track_change_scan(void)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (track_change.out != track_change.in)
|
|
|
|
{
|
|
|
|
track_change.out++;
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return false;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2007-10-29 13:55:34 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Clear outstanding track change posts */
|
|
|
|
static inline void audio_pcmbuf_track_change_clear(void)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
track_change.out = track_change.in;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Post a track change notification - called by audio ISR */
|
|
|
|
static inline void audio_pcmbuf_track_change_post(void)
|
2008-03-08 23:50:55 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
track_change.in++;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 02:49:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** --- Helper functions --- **/
|
|
|
|
|
|
|
|
/* Removes messages that might end up in the queue before or while processing
|
|
|
|
a manual track change. Responding to them would be harmful since they
|
|
|
|
belong to a previous track's playback period. Anything that would generate
|
|
|
|
the stale messages must first be put into a state where it will not do so.
|
|
|
|
*/
|
|
|
|
static void audio_clear_track_notifications(void)
|
|
|
|
{
|
|
|
|
static const long filter_list[][2] =
|
|
|
|
{
|
|
|
|
/* codec messages */
|
|
|
|
{ Q_AUDIO_CODEC_SEEK_COMPLETE, Q_AUDIO_CODEC_COMPLETE },
|
|
|
|
/* track change messages */
|
|
|
|
{ Q_AUDIO_TRACK_CHANGED, Q_AUDIO_TRACK_CHANGED },
|
|
|
|
};
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
const int filter_count = ARRAYLEN(filter_list) - 1;
|
2011-01-02 02:49:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Remove any pcmbuf notifications */
|
|
|
|
pcmbuf_monitor_track_change(false);
|
|
|
|
audio_pcmbuf_track_change_clear();
|
2011-01-02 02:49:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Scrub the audio queue of the old mold */
|
|
|
|
while (queue_peek_ex(&audio_queue, NULL,
|
|
|
|
filter_count | QPEEK_REMOVE_EVENTS,
|
|
|
|
filter_list))
|
2011-01-02 02:49:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
yield(); /* Not strictly needed, per se, ad infinitum, ra, ra */
|
2011-01-02 02:49:13 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2011-01-02 02:49:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Takes actions based upon track load status codes */
|
|
|
|
static void audio_handle_track_load_status(int trackstat)
|
|
|
|
{
|
|
|
|
switch (trackstat)
|
|
|
|
{
|
|
|
|
case LOAD_TRACK_ERR_NO_MORE:
|
|
|
|
if (track_list_count() > 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_TRACK_ERR_START_CODEC:
|
|
|
|
audio_queue_post(Q_AUDIO_CODEC_COMPLETE, CODEC_ERROR);
|
|
|
|
break;
|
2007-11-19 17:30:46 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
/* Send track events that use a struct track_event for data */
|
|
|
|
static void send_track_event(unsigned int id, unsigned int flags,
|
|
|
|
struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
if (id3 == id3_get(PLAYING_ID3))
|
|
|
|
flags |= TEF_CURRENT;
|
|
|
|
|
|
|
|
send_event(id, &(struct track_event){ .flags = flags, .id3 = id3 });
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Announce the end of playing the current track */
|
|
|
|
static void audio_playlist_track_finish(void)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
struct mp3entry *ply_id3 = id3_get(PLAYING_ID3);
|
|
|
|
struct mp3entry *id3 = valid_mp3entry(ply_id3);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_update_resume_info(filling == STATE_ENDED ? NULL : id3);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (id3)
|
|
|
|
{
|
2013-07-12 16:06:38 +00:00
|
|
|
send_track_event(PLAYBACK_EVENT_TRACK_FINISH,
|
|
|
|
track_event_flags, id3);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Announce the beginning of the new track */
|
|
|
|
static void audio_playlist_track_change(void)
|
|
|
|
{
|
|
|
|
struct mp3entry *id3 = valid_mp3entry(id3_get(PLAYING_ID3));
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (id3)
|
2013-07-12 16:06:38 +00:00
|
|
|
{
|
|
|
|
send_track_event(PLAYBACK_EVENT_TRACK_CHANGE,
|
|
|
|
track_event_flags, id3);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
position_key = pcmbuf_get_position_key();
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_update_resume_info(id3);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Change the data for the next track and send the event */
|
|
|
|
static void audio_update_and_announce_next_track(const struct mp3entry *id3_next)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_write_locked(NEXTTRACK_ID3, id3_next);
|
2013-07-12 16:06:38 +00:00
|
|
|
send_track_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE,
|
|
|
|
0, id3_get(NEXTTRACK_ID3));
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bring the user current mp3entry up to date and set a new offset for the
|
|
|
|
buffered metadata */
|
2017-12-08 18:01:25 +00:00
|
|
|
static void playing_id3_sync(struct track_info *user_infop,
|
2013-07-14 11:59:39 +00:00
|
|
|
unsigned long elapsed, unsigned long offset)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
id3_mutex_lock();
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct mp3entry *id3 = bufgetid3(user_infop->id3_hid);
|
2011-08-28 07:45:35 +00:00
|
|
|
struct mp3entry *playing_id3 = id3_get(PLAYING_ID3);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
pcm_play_lock();
|
|
|
|
|
|
|
|
unsigned long e = playing_id3->elapsed;
|
|
|
|
unsigned long o = playing_id3->offset;
|
|
|
|
|
|
|
|
id3_write(PLAYING_ID3, id3);
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
if (elapsed == (unsigned long)-1)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
playing_id3->elapsed = e;
|
2013-07-14 11:59:39 +00:00
|
|
|
elapsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == (unsigned long)-1)
|
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
playing_id3->offset = o;
|
2011-04-27 03:08:23 +00:00
|
|
|
offset = 0;
|
|
|
|
}
|
2011-08-28 07:45:35 +00:00
|
|
|
|
|
|
|
pcm_play_unlock();
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (id3)
|
2013-07-14 11:59:39 +00:00
|
|
|
{
|
|
|
|
id3->elapsed = elapsed;
|
2011-04-27 03:08:23 +00:00
|
|
|
id3->offset = offset;
|
2013-07-14 11:59:39 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
id3_mutex_unlock();
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Wipe-out track metadata - current is optional */
|
|
|
|
static void wipe_track_metadata(bool current)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_mutex_lock();
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (current)
|
|
|
|
id3_write(PLAYING_ID3, NULL);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_write(NEXTTRACK_ID3, NULL);
|
|
|
|
id3_write(UNBUFFERED_ID3, NULL);
|
2008-04-16 16:41:35 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_mutex_unlock();
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Called when buffering is completed on the last track handle */
|
|
|
|
static void filling_is_finished(void)
|
|
|
|
{
|
|
|
|
logf("last track finished buffering");
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* There's no more to load or watch for */
|
|
|
|
buf_set_watermark(0);
|
|
|
|
filling = STATE_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the codec decoding or waiting for its data to be ready - returns
|
|
|
|
'false' if the codec ended up stopped */
|
|
|
|
static bool halt_decoding_track(bool stop)
|
|
|
|
{
|
|
|
|
/* If it was waiting for us to clear the buffer to make a rebuffer
|
|
|
|
happen, it should cease otherwise codec_stop could deadlock waiting
|
|
|
|
for the codec to go to its main loop - codec's request will now
|
|
|
|
force-fail */
|
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
buf_signal_handle(ci.audio_hid, true);
|
|
|
|
|
|
|
|
if (stop)
|
|
|
|
codec_stop();
|
2006-09-01 07:59:31 +00:00
|
|
|
else
|
2011-04-27 03:08:23 +00:00
|
|
|
retval = codec_pause();
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_clear_track_notifications();
|
2008-04-16 16:41:35 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* We now know it's idle and not waiting for buffered data */
|
|
|
|
buf_signal_handle(ci.audio_hid, false);
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
codec_skip_pending = false;
|
|
|
|
codec_seeking = false;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
/* Wait for any in-progress fade to complete */
|
|
|
|
static void audio_wait_fade_complete(void)
|
|
|
|
{
|
|
|
|
/* Just loop until it's done */
|
|
|
|
while (pcmbuf_fading())
|
|
|
|
sleep(0);
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* End the ff/rw mode */
|
|
|
|
static void audio_ff_rewind_end(void)
|
|
|
|
{
|
|
|
|
/* A seamless seek (not calling audio_pre_ff_rewind) skips this
|
|
|
|
section */
|
|
|
|
if (ff_rw_mode)
|
|
|
|
{
|
|
|
|
ff_rw_mode = false;
|
|
|
|
|
|
|
|
if (codec_seeking)
|
|
|
|
{
|
|
|
|
/* Clear the buffer */
|
|
|
|
pcmbuf_play_stop();
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_pcmbuf_sync_position();
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (play_status != PLAY_PAUSED)
|
|
|
|
{
|
|
|
|
/* Seeking-while-playing, resume PCM playback */
|
|
|
|
pcmbuf_pause(false);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Complete the codec seek */
|
|
|
|
static void audio_complete_codec_seek(void)
|
|
|
|
{
|
|
|
|
/* If a seek completed while paused, 'paused' is true.
|
|
|
|
* If seeking from seek mode, 'ff_rw_mode' is true. */
|
|
|
|
if (codec_seeking)
|
|
|
|
{
|
|
|
|
audio_ff_rewind_end();
|
|
|
|
codec_seeking = false; /* set _after_ the call! */
|
|
|
|
}
|
|
|
|
/* else it's waiting and we must repond */
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Get the current cuesheet pointer */
|
|
|
|
static inline struct cuesheet * get_current_cuesheet(void)
|
|
|
|
{
|
|
|
|
return audio_scratch_memory->curr_cue;
|
|
|
|
}
|
2011-02-09 20:27:23 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Read the cuesheet from the buffer */
|
|
|
|
static void buf_read_cuesheet(int handle_id)
|
|
|
|
{
|
|
|
|
struct cuesheet *cue = get_current_cuesheet();
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!cue || handle_id < 0)
|
|
|
|
return;
|
2007-11-03 21:48:08 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
bufread(handle_id, sizeof (struct cuesheet), cue);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Backend to peek/current/next track metadata interface functions -
|
|
|
|
fill in the mp3entry with as much information as we may obtain about
|
|
|
|
the track at the specified offset from the user current track -
|
|
|
|
returns false if no information exists with us */
|
|
|
|
static bool audio_get_track_metadata(int offset, struct mp3entry *id3)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (play_status == PLAY_STOPPED)
|
2008-06-30 16:20:46 +00:00
|
|
|
return false;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (id3->path[0] != '\0')
|
|
|
|
return true; /* Already filled */
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!track_list_user_current(offset, &info))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
struct mp3entry *ub_id3 = id3_get(UNBUFFERED_ID3);
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (offset > 0 && track_list_user_current(offset - 1, NULL))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Try the unbuffered id3 since we're moving forward */
|
|
|
|
if (ub_id3->path[0] != '\0')
|
|
|
|
{
|
|
|
|
copy_mp3entry(id3, ub_id3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:01:25 +00:00
|
|
|
else if (bufreadid3(info.id3_hid, id3))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-22 00:14:56 +00:00
|
|
|
id3->cuesheet = NULL;
|
2011-04-27 03:08:23 +00:00
|
|
|
return true;
|
2008-06-30 16:20:46 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* We didn't find the ID3 metadata, so we fill it with the little info we
|
|
|
|
have and return that */
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
char path[MAX_PATH+1];
|
|
|
|
if (playlist_peek(offset, path, sizeof (path)))
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
|
|
|
|
/* Try to get it from the database */
|
|
|
|
if (!tagcache_fill_tags(id3, path))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* By now, filename is the only source of info */
|
|
|
|
fill_metadata_from_path(id3, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
wipe_mp3entry(id3);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
/* Get resume rewind adjusted progress from the ID3 */
|
|
|
|
static void resume_rewind_adjust_progress(const struct mp3entry *id3,
|
|
|
|
unsigned long *elapsed,
|
|
|
|
unsigned long *offset)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
unsigned int rewind = MAX(global_settings.resume_rewind, 0);
|
|
|
|
unsigned long d_e = rewind*1000;
|
|
|
|
*elapsed = id3->elapsed - MIN(id3->elapsed, d_e);
|
|
|
|
unsigned long d_o = rewind * id3->bitrate * (1000/8);
|
|
|
|
*offset = id3->offset - MIN(id3->offset, d_o);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the codec into ram and initialize it - keep it if it's ready */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool audio_init_codec(struct track_info *track_infop,
|
2011-04-27 03:08:23 +00:00
|
|
|
struct mp3entry *track_id3)
|
|
|
|
{
|
|
|
|
int codt_loaded = get_audio_base_codec_type(codec_loaded());
|
|
|
|
int hid = ERR_HANDLE_NOT_FOUND;
|
2008-02-23 17:46:33 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (codt_loaded != AFMT_UNKNOWN)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
int codt = get_audio_base_codec_type(track_id3->codectype);
|
|
|
|
|
|
|
|
if (codt == codt_loaded)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Codec is the same base type */
|
|
|
|
logf("Reusing prev. codec: %d", track_id3->codectype);
|
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
|
|
|
/* Close any buffered codec (we could have skipped directly to a
|
|
|
|
format transistion that is the same format as the current track
|
|
|
|
and the buffered one is no longer needed) */
|
2017-12-08 18:01:25 +00:00
|
|
|
track_info_close_handle(&track_infop->codec_hid);
|
|
|
|
track_info_sync(track_infop);
|
|
|
|
#endif /* HAVE_CODEC_BUFFERING */
|
2011-04-27 03:08:23 +00:00
|
|
|
return true;
|
2007-10-25 21:27:45 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
else
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* New codec - first make sure the old one's gone */
|
|
|
|
logf("Removing prev. codec: %d", codt_loaded);
|
|
|
|
codec_unload();
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("New codec: %d/%d", track_id3->codectype, codec_loaded());
|
|
|
|
|
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
|
|
|
/* Codec thread will close the handle even if it fails and will load from
|
|
|
|
storage if hid is not valid or the buffer load fails */
|
2017-12-08 18:01:25 +00:00
|
|
|
hid = track_infop->codec_hid;
|
|
|
|
track_infop->codec_hid = ERR_HANDLE_NOT_FOUND;
|
|
|
|
track_info_sync(track_infop);
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return codec_load(hid, track_id3->codectype);
|
2017-12-08 18:01:25 +00:00
|
|
|
(void)track_infop; /* When codec buffering isn't supported */
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 05:36:25 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
/* Check settings for whether the file should be autoresumed */
|
|
|
|
enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE };
|
|
|
|
static bool autoresumable(struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
char *endp, *path;
|
|
|
|
size_t len;
|
|
|
|
bool is_resumable;
|
|
|
|
|
|
|
|
if (id3->autoresumable) /* result cached? */
|
|
|
|
return id3->autoresumable == AUTORESUMABLE_TRUE;
|
|
|
|
|
|
|
|
is_resumable = false;
|
|
|
|
|
|
|
|
if (id3->path)
|
|
|
|
{
|
|
|
|
for (path = global_settings.autoresume_paths;
|
|
|
|
*path; /* search terms left? */
|
|
|
|
path++)
|
|
|
|
{
|
|
|
|
if (*path == ':') /* Skip empty search patterns */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* FIXME: As soon as strcspn or strchrnul are made available in
|
|
|
|
the core, the following can be made more efficient. */
|
|
|
|
endp = strchr(path, ':');
|
|
|
|
if (endp)
|
|
|
|
len = endp - path;
|
|
|
|
else
|
|
|
|
len = strlen(path);
|
|
|
|
|
|
|
|
/* Note: At this point, len is always > 0 */
|
|
|
|
|
|
|
|
if (strncasecmp(id3->path, path, len) == 0)
|
|
|
|
{
|
|
|
|
/* Full directory-name matches only. Trailing '/' in
|
|
|
|
search path OK. */
|
|
|
|
if (id3->path[len] == '/' || id3->path[len - 1] == '/')
|
|
|
|
{
|
|
|
|
is_resumable = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path += len - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cache result */
|
|
|
|
id3->autoresumable =
|
|
|
|
is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE;
|
|
|
|
|
|
|
|
logf("autoresumable: %s is%s resumable",
|
|
|
|
id3->path, is_resumable ? "" : " not");
|
|
|
|
|
|
|
|
return is_resumable;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_TAGCACHE */
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Start the codec for the current track scheduled to be decoded */
|
|
|
|
static bool audio_start_codec(bool auto_skip)
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
track_list_current(0, &info);
|
|
|
|
|
|
|
|
struct mp3entry *cur_id3 = valid_mp3entry(bufgetid3(info.id3_hid));
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (!cur_id3)
|
|
|
|
return false;
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_pin_handle(info.id3_hid, true);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!audio_init_codec(&info, cur_id3))
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_pin_handle(info.id3_hid, false);
|
2011-04-27 03:08:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
bool autoresume_enable = global_settings.autoresume_enable;
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
if (autoresume_enable && !(cur_id3->elapsed || cur_id3->offset))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Resume all manually selected tracks */
|
|
|
|
bool resume = !auto_skip;
|
2008-10-26 20:15:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Send the "buffer" event to obtain the resume position for the codec */
|
2013-07-12 16:06:38 +00:00
|
|
|
send_track_event(PLAYBACK_EVENT_TRACK_BUFFER, 0, cur_id3);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (!resume)
|
2008-10-26 20:15:10 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Automatic skip - do further tests to see if we should just
|
|
|
|
ignore any autoresume position */
|
|
|
|
int autoresume_automatic = global_settings.autoresume_automatic;
|
|
|
|
|
|
|
|
switch (autoresume_automatic)
|
|
|
|
{
|
|
|
|
case AUTORESUME_NEXTTRACK_ALWAYS:
|
|
|
|
/* Just resume unconditionally */
|
|
|
|
resume = true;
|
|
|
|
break;
|
|
|
|
case AUTORESUME_NEXTTRACK_NEVER:
|
|
|
|
/* Force-rewind it */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Not "never resume" - pass resume filter? */
|
|
|
|
resume = autoresumable(cur_id3);
|
|
|
|
}
|
2008-10-26 20:15:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!resume)
|
2013-07-14 11:59:39 +00:00
|
|
|
{
|
|
|
|
cur_id3->elapsed = 0;
|
2011-04-27 03:08:23 +00:00
|
|
|
cur_id3->offset = 0;
|
2013-07-14 11:59:39 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
logf("%s: Set resume for %s to %lu %lX", __func__,
|
|
|
|
cur_id3->title, cur_id3->elapsed, cur_id3->offset);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif /* HAVE_TAGCACHE */
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Rewind the required amount - if an autoresume was done, this also rewinds
|
|
|
|
that by the setting's amount
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
It would be best to have bookkeeping about whether or not the track
|
|
|
|
sounded or not since skipping to it or else skipping to it while paused
|
|
|
|
and back again will cause accumulation of silent rewinds - that's not
|
|
|
|
our job to track directly nor could it be in any reasonable way
|
|
|
|
*/
|
2013-07-14 11:59:39 +00:00
|
|
|
resume_rewind_adjust_progress(cur_id3, &cur_id3->elapsed,
|
|
|
|
&cur_id3->offset);
|
2008-01-08 23:48:51 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Update the codec API with the metadata and track info */
|
|
|
|
id3_write(CODEC_ID3, cur_id3);
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
ci.audio_hid = info.audio_hid;
|
2017-12-17 21:12:10 +00:00
|
|
|
ci.filesize = buf_filesize(info.audio_hid);
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_set_base_handle(info.audio_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* All required data is now available for the codec */
|
|
|
|
codec_go();
|
|
|
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2013-07-14 11:59:39 +00:00
|
|
|
if (!autoresume_enable || cur_id3->elapsed || cur_id3->offset)
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Send the "buffer" event now */
|
2013-07-12 16:06:38 +00:00
|
|
|
send_track_event(PLAYBACK_EVENT_TRACK_BUFFER, 0, cur_id3);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_pin_handle(info.id3_hid, false);
|
2011-04-27 03:08:23 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
(void)auto_skip; /* ifndef HAVE_TAGCACHE */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** --- Audio thread --- **/
|
|
|
|
|
|
|
|
/* Load and parse a cuesheet for the file - returns false if the buffer
|
|
|
|
is full */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool audio_load_cuesheet(struct track_info *infop,
|
2011-04-27 03:08:23 +00:00
|
|
|
struct mp3entry *track_id3)
|
|
|
|
{
|
|
|
|
struct cuesheet *cue = get_current_cuesheet();
|
|
|
|
track_id3->cuesheet = NULL;
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (cue && infop->cuesheet_hid == ERR_HANDLE_NOT_FOUND)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* If error other than a full buffer, then mark it "unsupported" to
|
|
|
|
avoid reloading attempt */
|
|
|
|
int hid = ERR_UNSUPPORTED_TYPE;
|
2011-12-16 10:09:41 +00:00
|
|
|
struct cuesheet_file cue_file;
|
2008-04-07 13:43:09 +00:00
|
|
|
|
2011-12-16 10:09:41 +00:00
|
|
|
if (look_for_cuesheet_file(track_id3, &cue_file))
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
hid = bufalloc(NULL, sizeof (struct cuesheet), TYPE_CUESHEET);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (hid >= 0)
|
|
|
|
{
|
|
|
|
void *cuesheet = NULL;
|
|
|
|
bufgetdata(hid, sizeof (struct cuesheet), &cuesheet);
|
|
|
|
|
2011-12-16 10:09:41 +00:00
|
|
|
if (parse_cuesheet(&cue_file, (struct cuesheet *)cuesheet))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Indicate cuesheet is present (while track remains
|
|
|
|
buffered) */
|
|
|
|
track_id3->cuesheet = cue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufclose(hid);
|
|
|
|
hid = ERR_UNSUPPORTED_TYPE;
|
|
|
|
}
|
2009-04-06 00:39:43 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (hid == ERR_BUFFER_FULL)
|
|
|
|
{
|
|
|
|
logf("buffer is full for now (%s)", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (hid < 0)
|
|
|
|
logf("Cuesheet loading failed");
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
infop->cuesheet_hid = hid;
|
2008-04-14 16:17:47 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 16:17:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-16 18:06:50 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Load any album art for the file - returns false if the buffer is full */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool audio_load_albumart(struct track_info *infop,
|
2011-04-27 03:08:23 +00:00
|
|
|
struct mp3entry *track_id3)
|
2011-02-16 18:06:50 +00:00
|
|
|
{
|
|
|
|
FOREACH_ALBUMART(i)
|
|
|
|
{
|
|
|
|
struct bufopen_bitmap_data user_data;
|
2017-12-08 18:01:25 +00:00
|
|
|
int *aa_hid = &infop->aa_hid[i];
|
2011-04-27 03:08:23 +00:00
|
|
|
int hid = ERR_UNSUPPORTED_TYPE;
|
2011-02-16 18:06:50 +00:00
|
|
|
|
|
|
|
/* albumart_slots may change during a yield of bufopen,
|
|
|
|
* but that's no problem */
|
2011-04-27 03:08:23 +00:00
|
|
|
if (*aa_hid >= 0 || *aa_hid == ERR_UNSUPPORTED_TYPE ||
|
|
|
|
!albumart_slots[i].used)
|
2011-02-16 18:06:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&user_data, 0, sizeof(user_data));
|
2011-04-27 03:08:23 +00:00
|
|
|
user_data.dim = &albumart_slots[i].dim;
|
|
|
|
|
|
|
|
/* We can only decode jpeg for embedded AA */
|
2011-12-22 18:48:43 +00:00
|
|
|
if (track_id3->has_embedded_albumart && track_id3->albumart.type == AA_TYPE_JPG)
|
2011-02-16 18:06:50 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
user_data.embedded_albumart = &track_id3->albumart;
|
2011-02-16 18:06:50 +00:00
|
|
|
hid = bufopen(track_id3->path, 0, TYPE_BITMAP, &user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hid < 0 && hid != ERR_BUFFER_FULL)
|
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* No embedded AA or it couldn't be loaded - try other sources */
|
2011-02-16 18:06:50 +00:00
|
|
|
char path[MAX_PATH];
|
|
|
|
|
|
|
|
if (find_albumart(track_id3, path, sizeof(path),
|
2011-04-27 03:08:23 +00:00
|
|
|
&albumart_slots[i].dim))
|
2011-02-16 18:06:50 +00:00
|
|
|
{
|
|
|
|
user_data.embedded_albumart = NULL;
|
|
|
|
hid = bufopen(path, 0, TYPE_BITMAP, &user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hid == ERR_BUFFER_FULL)
|
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("buffer is full for now (%s)", __func__);
|
|
|
|
return false;
|
2011-02-16 18:06:50 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
else
|
2011-02-16 18:06:50 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* If error other than a full buffer, then mark it "unsupported"
|
|
|
|
to avoid reloading attempt */
|
|
|
|
if (hid < 0)
|
|
|
|
{
|
|
|
|
logf("Album art loading failed");
|
|
|
|
hid = ERR_UNSUPPORTED_TYPE;
|
|
|
|
}
|
2017-12-08 18:01:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
logf("Loaded album art:%dx%d", user_data.dim->width,
|
|
|
|
user_data.dim->height);
|
|
|
|
}
|
2011-02-16 18:06:50 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
*aa_hid = hid;
|
|
|
|
}
|
2011-02-16 18:06:50 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
return true;
|
2011-02-16 18:06:50 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif /* HAVE_ALBUMART */
|
2011-02-16 18:06:50 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
|
|
|
/* Load a codec for the file onto the buffer - assumes we're working from the
|
|
|
|
currently loading track - not called for the current track */
|
2017-12-08 18:01:25 +00:00
|
|
|
static bool audio_buffer_codec(struct track_info *track_infop,
|
2011-04-27 03:08:23 +00:00
|
|
|
struct mp3entry *track_id3)
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* This will not be the current track -> it cannot be the first and the
|
|
|
|
current track cannot be ahead of buffering -> there is a previous
|
|
|
|
track entry which is either current or ahead of the current */
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info prev_info;
|
|
|
|
track_list_last(-1, &prev_info);
|
|
|
|
|
|
|
|
struct mp3entry *prev_id3 = bufgetid3(prev_info.id3_hid);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* If the previous codec is the same as this one, there is no need to
|
|
|
|
put another copy of it on the file buffer (in other words, only
|
|
|
|
buffer codecs at format transitions) */
|
|
|
|
if (prev_id3)
|
|
|
|
{
|
|
|
|
int codt = get_audio_base_codec_type(track_id3->codectype);
|
|
|
|
int prev_codt = get_audio_base_codec_type(prev_id3->codectype);
|
2008-06-30 16:20:46 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (codt == prev_codt)
|
|
|
|
{
|
|
|
|
logf("Reusing prev. codec: %d", prev_id3->codectype);
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-14 16:17:47 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
/* else just load it (harmless) */
|
|
|
|
|
|
|
|
/* Load the codec onto the buffer if possible */
|
|
|
|
const char *codec_fn = get_codec_filename(track_id3->codectype);
|
|
|
|
if (!codec_fn)
|
|
|
|
return false;
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
char codec_path[MAX_PATH+1]; /* Full path to codec */
|
|
|
|
codec_get_full_path(codec_path, codec_fn);
|
2007-11-11 20:09:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_infop->codec_hid = bufopen(codec_path, 0, TYPE_CODEC, NULL);
|
2007-11-11 20:09:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (track_infop->codec_hid > 0)
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("Buffered codec: %d", track_infop->codec_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CODEC_BUFFERING */
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Load metadata for the next track (with bufopen). The rest of the track
|
|
|
|
loading will be handled by audio_finish_load_track once the metadata has
|
|
|
|
been actually loaded by the buffering thread.
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
Each track is arranged in the buffer as follows:
|
|
|
|
<id3|[cuesheet|][album art|][codec|]audio>
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
The next will not be loaded until the previous succeeds if the buffer was
|
|
|
|
full at the time. To put any metadata after audio would make those handles
|
|
|
|
unmovable.
|
|
|
|
*/
|
|
|
|
static int audio_load_track(void)
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
|
|
|
|
if (track_list.in_progress_hid > 0)
|
2009-07-20 05:18:18 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* There must be an info pointer if the in-progress id3 is even there */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (track_list_last(0, &info) && info.self_hid == track_list.in_progress_hid)
|
2009-07-20 05:18:18 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (filling == STATE_FILLING)
|
2009-07-20 15:50:26 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Haven't finished the metadata but the notification is
|
|
|
|
anticipated to come soon */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:in progress:id=%d", __func__, info.self_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
return LOAD_TRACK_OK;
|
|
|
|
}
|
|
|
|
else if (filling == STATE_FULL)
|
|
|
|
{
|
|
|
|
/* Buffer was full trying to complete the load after the
|
|
|
|
metadata finished, so attempt to continue - older handles
|
|
|
|
should have been cleared already */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:finished:id=%d", __func__, info.self_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
filling = STATE_FILLING;
|
2017-12-08 18:01:25 +00:00
|
|
|
buffer_event_finished_callback(BUFFER_EVENT_FINISHED, &info.id3_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
return LOAD_TRACK_OK;
|
2009-07-20 15:50:26 +00:00
|
|
|
}
|
2009-07-20 05:18:18 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Some old, stray buffering message */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:busy:id=%d", __func__, info.self_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
return LOAD_TRACK_ERR_BUSY;
|
2009-07-20 05:18:18 +00:00
|
|
|
}
|
2011-02-09 20:13:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
filling = STATE_FILLING;
|
2007-11-11 20:09:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!track_list_alloc_info(&info))
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* List is full so stop buffering tracks - however, attempt to obtain
|
|
|
|
metadata as the unbuffered id3 */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("buffer full:alloc");
|
2011-04-27 03:08:23 +00:00
|
|
|
filling = STATE_FULL;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_peek_offset++;
|
2010-04-24 14:10:28 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("Buffering track:f=%d:c=%d:l=%d:pk=%d",
|
|
|
|
track_list.first_hid, track_list.current_hid, track_list.last_hid,
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_peek_offset);
|
|
|
|
|
|
|
|
/* Get track name from current playlist read position */
|
2017-12-17 21:12:10 +00:00
|
|
|
char path_buf[MAX_PATH + 1];
|
|
|
|
const char *path = playlist_peek(playlist_peek_offset,
|
|
|
|
path_buf,
|
|
|
|
sizeof (path_buf));
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-17 21:12:10 +00:00
|
|
|
if (!path)
|
2010-04-24 14:10:28 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* No track - exhausted the playlist entries */
|
|
|
|
logf("End-of-playlist");
|
|
|
|
id3_write_locked(UNBUFFERED_ID3, NULL);
|
|
|
|
|
|
|
|
if (filling != STATE_FULL)
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_free_info(&info); /* Free this entry */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
playlist_peek_offset--; /* Maintain at last index */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* We can end up here after the real last track signals its completion
|
|
|
|
and miss the transition to STATE_FINISHED esp. if dropping the last
|
|
|
|
songs of a playlist late in their load (2nd stage) */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (track_list_last(0, &info) && buf_handle_remaining(info.audio_hid) == 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
filling_is_finished();
|
|
|
|
else
|
|
|
|
filling = STATE_END_OF_PLAYLIST;
|
|
|
|
|
|
|
|
return LOAD_TRACK_ERR_NO_MORE;
|
2010-04-24 14:10:28 +00:00
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Successfully opened the file - get track metadata */
|
|
|
|
if (filling == STATE_FULL ||
|
2017-12-17 21:12:10 +00:00
|
|
|
(info.id3_hid = bufopen(path, 0, TYPE_ID3, NULL)) < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Buffer or track list is full */
|
|
|
|
struct mp3entry *ub_id3;
|
|
|
|
|
|
|
|
playlist_peek_offset--;
|
2007-11-03 06:21:32 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Load the metadata for the first unbuffered track */
|
|
|
|
ub_id3 = id3_get(UNBUFFERED_ID3);
|
2017-12-17 21:12:10 +00:00
|
|
|
|
|
|
|
int fd = open(path, O_RDONLY);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
id3_mutex_lock();
|
|
|
|
get_metadata(ub_id3, fd, path);
|
|
|
|
id3_mutex_unlock();
|
|
|
|
close(fd);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (filling != STATE_FULL)
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_free_info(&info);
|
2011-04-27 03:08:23 +00:00
|
|
|
filling = STATE_FULL;
|
2007-11-03 06:21:32 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("%s: buffer is full for now (%u tracks)", __func__,
|
|
|
|
track_list_count());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!track_list_commit_info(&info))
|
|
|
|
{
|
|
|
|
track_list_free_info(&info);
|
|
|
|
track_list.in_progress_hid = 0;
|
|
|
|
return LOAD_TRACK_ERR_FAILED;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Successful load initiation */
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.in_progress_hid = info.self_hid;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return LOAD_TRACK_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second part of the track loading: We now have the metadata available, so we
|
|
|
|
can load the codec, the album art and finally the audio data.
|
|
|
|
This is called on the audio thread after the buffering thread calls the
|
|
|
|
buffering_handle_finished_callback callback. */
|
2017-12-08 18:01:25 +00:00
|
|
|
static int audio_finish_load_track(struct track_info *infop)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
int trackstat = LOAD_TRACK_OK;
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (infop->self_hid != track_list.in_progress_hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* We must not be here if not! */
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:wrong track:hids=%d!=%d", __func__, infop->self_hid,
|
|
|
|
track_list.in_progress_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
return LOAD_TRACK_ERR_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The current track for decoding (there is always one if the list is
|
|
|
|
populated) */
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info cur_info;
|
|
|
|
track_list_current(0, &cur_info);
|
|
|
|
|
|
|
|
struct mp3entry *track_id3 = valid_mp3entry(bufgetid3(infop->id3_hid));
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (!track_id3)
|
|
|
|
{
|
|
|
|
/* This is an error condition. Track cannot be played without valid
|
|
|
|
metadata; skip the track. */
|
2011-08-26 15:46:18 +00:00
|
|
|
logf("No metadata");
|
2011-04-27 03:08:23 +00:00
|
|
|
trackstat = LOAD_TRACK_ERR_FINISH_FAILED;
|
|
|
|
goto audio_finish_load_track_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to load a cuesheet for the track */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!audio_load_cuesheet(infop, track_id3))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* No space for cuesheet on buffer, not an error */
|
|
|
|
filling = STATE_FULL;
|
|
|
|
goto audio_finish_load_track_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
/* Try to load album art for the track */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!audio_load_albumart(infop, track_id3))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* No space for album art on buffer, not an error */
|
|
|
|
filling = STATE_FULL;
|
|
|
|
goto audio_finish_load_track_exit;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 08:35:31 +00:00
|
|
|
/* All handles available to external routines are ready - audio and codec
|
|
|
|
information is private */
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info user_cur;
|
|
|
|
track_list_user_current(0, &user_cur);
|
|
|
|
if (infop->self_hid == user_cur.self_hid)
|
2011-05-25 08:35:31 +00:00
|
|
|
{
|
|
|
|
/* Send only when the track handles could not all be opened ahead of
|
|
|
|
time for the user's current track - otherwise everything is ready
|
|
|
|
by the time PLAYBACK_EVENT_TRACK_CHANGE is sent */
|
2013-07-12 16:06:38 +00:00
|
|
|
send_track_event(PLAYBACK_EVENT_CUR_TRACK_READY, 0,
|
|
|
|
id3_get(PLAYING_ID3));
|
2011-05-25 08:35:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#ifdef HAVE_CODEC_BUFFERING
|
|
|
|
/* Try to buffer a codec for the track */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (infop->self_hid != cur_info.self_hid
|
|
|
|
&& !audio_buffer_codec(infop, track_id3))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
if (infop->codec_hid == ERR_BUFFER_FULL)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* No space for codec on buffer, not an error */
|
|
|
|
filling = STATE_FULL;
|
2017-12-08 18:01:25 +00:00
|
|
|
logf("%s:STATE_FULL", __func__);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is an error condition, either no codec was found, or
|
|
|
|
reading the codec file failed part way through, either way,
|
|
|
|
skip the track */
|
|
|
|
logf("No codec for: %s", track_id3->path);
|
|
|
|
trackstat = LOAD_TRACK_ERR_FINISH_FAILED;
|
2007-11-03 06:21:32 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
goto audio_finish_load_track_exit;
|
2005-06-05 23:05:10 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif /* HAVE_CODEC_BUFFERING */
|
|
|
|
|
|
|
|
/** Finally, load the audio **/
|
2017-12-17 21:12:10 +00:00
|
|
|
off_t file_offset = 0;
|
2013-07-14 11:59:39 +00:00
|
|
|
|
|
|
|
if (track_id3->elapsed > track_id3->length)
|
|
|
|
track_id3->elapsed = 0;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-17 21:12:10 +00:00
|
|
|
if ((off_t)track_id3->offset >= buf_filesize(infop->audio_hid))
|
2011-04-27 03:08:23 +00:00
|
|
|
track_id3->offset = 0;
|
|
|
|
|
|
|
|
logf("%s: set offset for %s to %lu\n", __func__,
|
2017-12-17 21:12:10 +00:00
|
|
|
track_id3->title, track_id3->offset);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Adjust for resume rewind so we know what to buffer - starting the codec
|
|
|
|
calls it again, so we don't save it (and they shouldn't accumulate) */
|
2013-07-14 11:59:39 +00:00
|
|
|
unsigned long elapsed, offset;
|
|
|
|
resume_rewind_adjust_progress(track_id3, &elapsed, &offset);
|
|
|
|
|
2017-12-17 21:12:10 +00:00
|
|
|
logf("%s: Set resume for %s to %lu %lu", __func__,
|
iBasso DX50/DX90: Major code cleanup and reorganization.
Reorganization
- Separated iBasso devices from PLATFORM_ANDROID. These are now standlone
hosted targets. Most device specific code is in the
firmware/target/hosted/ibasso directory.
- No dependency on Android SDK, only the Android NDK is needed.
32 bit Android NDK and Android API Level 16.
- Separate implementation for each device where feasible.
Code cleanup
- Rewrite of existing code, from simple reformat to complete reimplementation.
- New backlight interface, seperating backlight from touchscreen.
- Rewrite of device button handler, removing unneeded code and fixing memory
leaks.
- New Debug messages interface logging to Android adb logcat (DEBUGF, panicf,
logf).
- Rewrite of lcd device handler, removing unneeded code and fixing memory leaks.
- Rewrite of audiohw device handler/pcm interface, removing unneeded code and
fixing memory leaks, enabling 44.1/48kHz pthreaded playback.
- Rewrite of power and powermng, proper shutdown, using batterylog results
(see http://gerrit.rockbox.org/r/#/c/1047/).
- Rewrite of configure (Android NDK) and device specific config.
- Rewrite of the Android NDK specific Makefile.
Misc
- All plugins/games/demos activated.
- Update tinyalsa to latest from https://github.com/tinyalsa/tinyalsa.
Includes
- http://gerrit.rockbox.org/r/#/c/993/
- http://gerrit.rockbox.org/r/#/c/1010/
- http://gerrit.rockbox.org/r/#/c/1035/
Does not include http://gerrit.rockbox.org/r/#/c/1007/ due to new backlight
interface and new option for hold switch, touchscreen, physical button
interaction.
Rockbox needs the iBasso DX50/DX90 loader for startup, see
http://gerrit.rockbox.org/r/#/c/1099/
The loader expects Rockbox to be installed in /mnt/sdcard/.rockbox/. If
/mnt/sdcard/ is accessed as USB mass storage device, Rockbox will exit
gracefully and the loader will restart Rockbox on USB disconnect.
Tested on iBasso DX50.
Compiled (not tested) for iBasso DX90.
Compiled (not tested) for PLATFORM_ANDROID.
Change-Id: I5f5e22e68f5b4cf29c28e2b40b2c265f2beb7ab7
2015-02-02 20:44:29 +00:00
|
|
|
track_id3->title, elapsed, offset);
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-08-12 05:27:13 +00:00
|
|
|
enum data_type audiotype = rbcodec_format_is_atomic(track_id3->codectype) ?
|
|
|
|
TYPE_ATOMIC_AUDIO : TYPE_PACKET_AUDIO;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (audiotype == TYPE_ATOMIC_AUDIO)
|
|
|
|
logf("Loading atomic %d", track_id3->codectype);
|
|
|
|
|
|
|
|
if (format_buffers_with_offset(track_id3->codectype))
|
|
|
|
{
|
|
|
|
/* This format can begin buffering from any point */
|
|
|
|
file_offset = offset;
|
|
|
|
}
|
2010-04-24 14:10:28 +00:00
|
|
|
|
2009-11-02 15:50:56 +00:00
|
|
|
logf("load track: %s", track_id3->path);
|
2006-08-15 18:01:42 +00:00
|
|
|
|
2007-11-05 16:02:12 +00:00
|
|
|
if (file_offset > AUDIO_REBUFFER_GUESS_SIZE)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* We can buffer later in the file, adjust the hunt-and-peck margin */
|
2007-11-05 16:02:12 +00:00
|
|
|
file_offset -= AUDIO_REBUFFER_GUESS_SIZE;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2007-11-05 16:02:12 +00:00
|
|
|
else
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* No offset given or it is very minimal - begin at the first frame
|
|
|
|
according to the metadata */
|
|
|
|
file_offset = track_id3->first_frame_offset;
|
|
|
|
}
|
2007-11-05 01:56:12 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int hid = bufopen(track_id3->path, file_offset, audiotype, NULL);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (hid >= 0)
|
2009-02-23 21:09:30 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
infop->audio_hid = hid;
|
|
|
|
if (infop->self_hid == cur_info.self_hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* This is the current track to decode - should be started now */
|
|
|
|
trackstat = LOAD_TRACK_READY;
|
|
|
|
}
|
2009-02-23 21:09:30 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
else
|
2009-02-23 21:09:30 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Buffer could be full but not properly so if this is the only
|
|
|
|
track! */
|
|
|
|
if (hid == ERR_BUFFER_FULL && audio_track_count() > 1)
|
|
|
|
{
|
|
|
|
filling = STATE_FULL;
|
|
|
|
logf("Buffer is full for now (%s)", __func__);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Nothing to play if no audio handle - skip this */
|
|
|
|
logf("Could not add audio data handle");
|
|
|
|
trackstat = LOAD_TRACK_ERR_FINISH_FAILED;
|
|
|
|
}
|
2009-02-23 21:09:30 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_finish_load_track_exit:
|
2017-12-08 18:01:25 +00:00
|
|
|
if (trackstat >= LOAD_TRACK_OK && !track_info_sync(infop))
|
|
|
|
{
|
|
|
|
logf("Track info sync failed");
|
|
|
|
trackstat = LOAD_TRACK_ERR_FINISH_FAILED;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (trackstat < LOAD_TRACK_OK)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_skip_entry(NULL, playlist_peek_offset);
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_free_info(infop);
|
2006-03-23 16:18:17 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (playlist_peek(playlist_peek_offset, NULL, 0))
|
|
|
|
playlist_next(0);
|
2008-03-28 20:18:53 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_peek_offset--;
|
|
|
|
}
|
2011-01-02 02:49:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (filling != STATE_FULL)
|
|
|
|
{
|
|
|
|
/* Load next track - error or not */
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list.in_progress_hid = 0;
|
2011-04-27 03:08:23 +00:00
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_FILL_BUFFER");
|
|
|
|
audio_queue_post(Q_AUDIO_FILL_BUFFER, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Full */
|
|
|
|
trackstat = LOAD_TRACK_ERR_FINISH_FULL;
|
|
|
|
}
|
2008-04-14 16:17:47 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return trackstat;
|
2005-08-20 11:13:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Start a new track load */
|
|
|
|
static int audio_fill_file_buffer(void)
|
2005-08-20 11:13:19 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return LOAD_TRACK_ERR_FAILED;
|
2008-03-28 20:18:53 +00:00
|
|
|
|
2011-09-19 20:52:00 +00:00
|
|
|
trigger_cpu_boost();
|
|
|
|
|
|
|
|
/* Must reset the buffer before use if trashed or voice only - voice
|
|
|
|
file size shouldn't have changed so we can go straight from
|
|
|
|
AUDIOBUF_STATE_VOICED_ONLY to AUDIOBUF_STATE_INITIALIZED */
|
2013-05-23 17:58:51 +00:00
|
|
|
if (buffer_state != AUDIOBUF_STATE_INITIALIZED ||
|
|
|
|
!pcmbuf_is_same_size())
|
|
|
|
{
|
2013-05-30 09:24:16 +00:00
|
|
|
audio_reset_buffer();
|
2013-05-23 17:58:51 +00:00
|
|
|
}
|
2011-09-19 20:52:00 +00:00
|
|
|
|
2007-10-25 21:27:45 +00:00
|
|
|
logf("Starting buffer fill");
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int trackstat = audio_load_track();
|
|
|
|
|
|
|
|
if (trackstat >= LOAD_TRACK_OK)
|
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info, user_cur;
|
|
|
|
track_list_current(0, &info);
|
|
|
|
track_list_user_current(0, &user_cur);
|
|
|
|
|
|
|
|
if (info.self_hid == user_cur.self_hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_next(0);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (filling == STATE_FULL && !track_list_user_current(1, NULL))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* There are no user tracks on the buffer after this therefore
|
|
|
|
this is the next track */
|
|
|
|
audio_update_and_announce_next_track(id3_get(UNBUFFERED_ID3));
|
|
|
|
}
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return trackstat;
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2005-08-20 11:13:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Discard unwanted tracks and start refill from after the specified playlist
|
|
|
|
offset */
|
|
|
|
static int audio_reset_and_rebuffer(
|
|
|
|
enum track_clear_action action, int peek_offset)
|
2005-08-20 11:13:19 +00:00
|
|
|
{
|
2013-11-10 11:34:31 +00:00
|
|
|
logf("Forcing rebuffer: 0x%X, %d", action, peek_offset);
|
2006-12-16 20:19:58 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_write_locked(UNBUFFERED_ID3, NULL);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Remove unwanted tracks - caller must have ensured codec isn't using
|
|
|
|
any */
|
|
|
|
track_list_clear(action);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Refill at specified position (-1 starts at index offset 0) */
|
|
|
|
playlist_peek_offset = peek_offset;
|
2008-06-30 16:20:46 +00:00
|
|
|
|
2006-09-01 07:59:31 +00:00
|
|
|
/* Fill the buffer */
|
2011-04-27 03:08:23 +00:00
|
|
|
return audio_fill_file_buffer();
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Handle buffering events
|
|
|
|
(Q_AUDIO_BUFFERING) */
|
|
|
|
static void audio_on_buffering(int event)
|
2005-06-05 23:05:10 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
enum track_clear_action action;
|
|
|
|
int peek_offset;
|
|
|
|
|
|
|
|
if (track_list_empty())
|
|
|
|
return;
|
2011-05-09 21:52:06 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
switch (event)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
case BUFFER_EVENT_BUFFER_LOW:
|
|
|
|
if (filling != STATE_FULL && filling != STATE_END_OF_PLAYLIST)
|
|
|
|
return; /* Should be nothing left to fill */
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Clear old tracks and continue buffering where it left off */
|
|
|
|
action = TRACK_LIST_KEEP_NEW;
|
|
|
|
peek_offset = playlist_peek_offset;
|
|
|
|
break;
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
case BUFFER_EVENT_REBUFFER:
|
|
|
|
/* Remove all but the currently decoding track and redo buffering
|
|
|
|
after that */
|
|
|
|
action = TRACK_LIST_KEEP_CURRENT;
|
|
|
|
peek_offset = (skip_pending == TRACK_SKIP_AUTO) ? 1 : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
switch (skip_pending)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
case TRACK_SKIP_NONE:
|
|
|
|
case TRACK_SKIP_AUTO:
|
|
|
|
case TRACK_SKIP_AUTO_NEW_PLAYLIST:
|
|
|
|
audio_reset_and_rebuffer(action, peek_offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRACK_SKIP_AUTO_END_PLAYLIST:
|
|
|
|
/* Already finished */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Invalid */
|
|
|
|
logf("Buffering call, inv. state: %d", (int)skip_pending);
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Handle starting the next track load
|
|
|
|
(Q_AUDIO_FILL_BUFFER) */
|
|
|
|
static void audio_on_fill_buffer(void)
|
|
|
|
{
|
|
|
|
audio_handle_track_load_status(audio_fill_file_buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle posted load track finish event
|
|
|
|
(Q_AUDIO_FINISH_LOAD_TRACK) */
|
|
|
|
static void audio_on_finish_load_track(int id3_hid)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info, user_cur;
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!buf_is_handle(id3_hid) || !track_list_last(0, &info))
|
2011-04-27 03:08:23 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_user_current(1, &user_cur);
|
|
|
|
if (info.self_hid == user_cur.self_hid)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Just loaded the metadata right after the current position */
|
2017-12-08 18:01:25 +00:00
|
|
|
audio_update_and_announce_next_track(bufgetid3(info.id3_hid));
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (audio_finish_load_track(&info) != LOAD_TRACK_READY)
|
2011-04-27 03:08:23 +00:00
|
|
|
return; /* Not current track */
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
track_list_user_current(0, &user_cur);
|
|
|
|
bool is_user_current = info.self_hid == user_cur.self_hid;
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (is_user_current)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Copy cuesheet */
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_read_cuesheet(info.cuesheet_hid);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2005-11-17 19:31:29 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
if (audio_start_codec(track_event_flags & TEF_AUTO_SKIP))
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (is_user_current)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Be sure all tagtree info is synchronized; it will be needed for the
|
|
|
|
track finish event - the sync will happen when finalizing a track
|
|
|
|
change otherwise */
|
|
|
|
bool was_valid = valid_mp3entry(id3_get(PLAYING_ID3));
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
playing_id3_sync(&info, -1, -1);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (!was_valid)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Playing id3 hadn't been updated yet because no valid track
|
|
|
|
was yet available - treat like the first track */
|
|
|
|
audio_playlist_track_change();
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2008-04-02 17:04:59 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
else
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_handle_track_load_status(LOAD_TRACK_ERR_START_CODEC);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when handles other than metadata handles have finished buffering
|
|
|
|
(Q_AUDIO_HANDLE_FINISHED) */
|
|
|
|
static void audio_on_handle_finished(int hid)
|
|
|
|
{
|
|
|
|
/* Right now, only audio handles should end up calling this */
|
|
|
|
if (filling == STATE_END_OF_PLAYLIST)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Really we don't know which order the handles will actually complete
|
|
|
|
to zero bytes remaining since another thread is doing it - be sure
|
|
|
|
it's the right one */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (track_list_last(0, &info) && info.audio_hid == hid)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* This was the last track in the playlist and we now have all the
|
|
|
|
data we need */
|
|
|
|
filling_is_finished();
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-01-19 18:21:12 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Called to make an outstanding track skip the current track and to send the
|
|
|
|
transition events */
|
2011-08-28 07:45:35 +00:00
|
|
|
static void audio_finalise_track_change(void)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
switch (skip_pending)
|
|
|
|
{
|
|
|
|
case TRACK_SKIP_NONE: /* Manual skip */
|
|
|
|
break;
|
2007-11-11 21:27:18 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
case TRACK_SKIP_AUTO:
|
|
|
|
case TRACK_SKIP_AUTO_NEW_PLAYLIST:
|
2007-10-25 21:27:45 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
int playlist_delta = skip_pending == TRACK_SKIP_AUTO ? 1 : 0;
|
|
|
|
audio_playlist_track_finish();
|
|
|
|
|
|
|
|
if (!playlist_peek(playlist_delta, NULL, 0))
|
2007-11-07 00:59:42 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Track ended up rejected - push things ahead like the codec blew
|
|
|
|
it (because it was never started and now we're here where it
|
|
|
|
should have been decoding the next track by now) - next, a
|
|
|
|
directory change or end of playback will most likely happen */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
|
|
|
audio_handle_track_load_status(LOAD_TRACK_ERR_START_CODEC);
|
|
|
|
return;
|
2007-11-07 00:59:42 +00:00
|
|
|
}
|
2006-10-12 15:54:36 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!playlist_delta)
|
|
|
|
break;
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
playlist_peek_offset -= playlist_delta;
|
|
|
|
if (playlist_next(playlist_delta) >= 0)
|
|
|
|
break;
|
|
|
|
/* What!? Disappear? Hopeless bleak despair */
|
|
|
|
}
|
|
|
|
/* Fallthrough */
|
|
|
|
case TRACK_SKIP_AUTO_END_PLAYLIST:
|
|
|
|
default: /* Invalid */
|
|
|
|
filling = STATE_ENDED;
|
|
|
|
audio_stop_playback();
|
|
|
|
return;
|
2007-10-25 21:27:45 +00:00
|
|
|
}
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
bool have_info = track_list_current(0, &info);
|
2011-04-27 03:08:23 +00:00
|
|
|
struct mp3entry *track_id3 = NULL;
|
|
|
|
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
/* Update the current cuesheet if any and enabled */
|
2017-12-08 18:01:25 +00:00
|
|
|
if (have_info)
|
2006-09-01 07:59:31 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_read_cuesheet(info.cuesheet_hid);
|
|
|
|
track_id3 = bufgetid3(info.id3_hid);
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_write(PLAYING_ID3, track_id3);
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* The skip is technically over */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Sync the next track information */
|
2017-12-08 18:01:25 +00:00
|
|
|
have_info = track_list_current(1, &info);
|
2007-11-03 02:53:57 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
id3_write(NEXTTRACK_ID3, have_info ? bufgetid3(info.id3_hid) :
|
|
|
|
id3_get(UNBUFFERED_ID3));
|
2007-11-03 02:53:57 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
id3_mutex_unlock();
|
2006-05-02 16:18:21 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_playlist_track_change();
|
|
|
|
}
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Actually begin a transition and take care of the codec change - may complete
|
2011-08-28 07:45:35 +00:00
|
|
|
it now or ask pcmbuf for notification depending on the type */
|
|
|
|
static void audio_begin_track_change(enum pcm_track_change_type type,
|
|
|
|
int trackstat)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Even if the new track is bad, the old track must be finished off */
|
2011-08-28 07:45:35 +00:00
|
|
|
pcmbuf_start_track_change(type);
|
|
|
|
|
|
|
|
bool auto_skip = type != TRACK_CHANGE_MANUAL;
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
if (!auto_skip)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Manual track change happens now */
|
|
|
|
audio_finalise_track_change();
|
|
|
|
pcmbuf_sync_position_update();
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return; /* Stopped us */
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (trackstat >= LOAD_TRACK_OK)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
if (track_list_current(0, &info))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
if (info.audio_hid < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Everything needed for the codec is ready - start it */
|
|
|
|
if (audio_start_codec(auto_skip))
|
|
|
|
{
|
|
|
|
if (!auto_skip)
|
|
|
|
playing_id3_sync(&info, -1, -1);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trackstat = LOAD_TRACK_ERR_START_CODEC;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_handle_track_load_status(trackstat);
|
2006-10-19 09:42:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Transition to end-of-playlist state and begin wait for PCM to finish */
|
|
|
|
static void audio_monitor_end_of_playlist(void)
|
2009-10-31 19:17:36 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
skip_pending = TRACK_SKIP_AUTO_END_PLAYLIST;
|
|
|
|
filling = STATE_ENDING;
|
2011-08-28 07:45:35 +00:00
|
|
|
pcmbuf_start_track_change(TRACK_CHANGE_END_OF_DATA);
|
2009-10-31 19:17:36 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Codec has completed decoding the track
|
|
|
|
(usually Q_AUDIO_CODEC_COMPLETE) */
|
|
|
|
static void audio_on_codec_complete(int status)
|
2005-06-05 23:05:10 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("%s(%d)", __func__, status);
|
2007-05-09 03:44:44 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return;
|
2007-05-09 03:44:44 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* If it didn't notify us first, don't expect "seek complete" message
|
|
|
|
since the codec can't post it now - do things like it would have
|
|
|
|
done */
|
|
|
|
audio_complete_codec_seek();
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (play_status == PLAY_PAUSED || skip_pending != TRACK_SKIP_NONE)
|
|
|
|
{
|
|
|
|
/* Old-hay on the ip-skay - codec has completed decoding
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
Paused: We're not sounding it, so just remember that it happened
|
|
|
|
and the resume will begin the transition
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
Skipping: There was already a skip in progress, remember it and
|
|
|
|
allow no further progress until the PCM from the previous
|
|
|
|
song has finished
|
2017-04-06 23:32:35 +00:00
|
|
|
|
|
|
|
This function will be reentered upon completing the existing
|
|
|
|
transition in order to do the one that was just tried (below)
|
2011-04-27 03:08:23 +00:00
|
|
|
*/
|
|
|
|
codec_skip_pending = true;
|
|
|
|
codec_skip_status = status;
|
2017-04-06 23:32:35 +00:00
|
|
|
|
|
|
|
/* PCM buffer must know; audio could still be filling and hasn't
|
|
|
|
yet reached the play watermark */
|
|
|
|
pcmbuf_start_track_change(TRACK_CHANGE_AUTO_PILEUP);
|
2011-04-27 03:08:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
codec_skip_pending = false;
|
2006-01-21 22:58:08 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int trackstat = LOAD_TRACK_OK;
|
2007-05-09 03:44:44 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_AUTO_SKIP;
|
2011-04-27 03:08:23 +00:00
|
|
|
skip_pending = TRACK_SKIP_AUTO;
|
2007-03-25 17:12:27 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Does this track have an entry allocated? */
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
bool have_track = track_list_advance_current(1, &info);
|
2010-11-23 00:13:14 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!have_track || info.audio_hid < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
bool end_of_playlist = false;
|
2008-02-28 17:40:31 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (have_track)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Track load is not complete - it might have stopped on a
|
|
|
|
full buffer without reaching the audio handle or we just
|
|
|
|
arrived at it early
|
|
|
|
|
|
|
|
If this type is atomic and we couldn't get the audio,
|
|
|
|
perhaps it would need to wrap to make the allocation and
|
|
|
|
handles are in the way - to maximize the liklihood it can
|
|
|
|
be allocated, clear all handles to reset the buffer and
|
|
|
|
its indexes to 0 - for packet audio, this should not be an
|
|
|
|
issue and a pointless full reload of all the track's
|
|
|
|
metadata may be avoided */
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct mp3entry *track_id3 = bufgetid3(info.id3_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-12 05:27:13 +00:00
|
|
|
if (track_id3 && !rbcodec_format_is_atomic(track_id3->codectype))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Continue filling after this track */
|
|
|
|
audio_reset_and_rebuffer(TRACK_LIST_KEEP_CURRENT, 1);
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_begin_track_change(TRACK_CHANGE_AUTO, trackstat);
|
2011-04-27 03:08:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* else rebuffer at this track; status applies to the track we
|
|
|
|
want */
|
|
|
|
}
|
|
|
|
else if (!playlist_peek(1, NULL, 0))
|
|
|
|
{
|
|
|
|
/* Play sequence is complete - directory change or other playlist
|
|
|
|
resequencing - the playlist must now be advanced in order to
|
|
|
|
continue since a peek ahead to the next track is not possible */
|
|
|
|
skip_pending = TRACK_SKIP_AUTO_NEW_PLAYLIST;
|
|
|
|
end_of_playlist = playlist_next(1) < 0;
|
|
|
|
}
|
2008-04-03 17:51:53 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!end_of_playlist)
|
|
|
|
{
|
|
|
|
trackstat = audio_reset_and_rebuffer(TRACK_LIST_CLEAR_ALL,
|
|
|
|
skip_pending == TRACK_SKIP_AUTO ? 0 : -1);
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (trackstat == LOAD_TRACK_ERR_NO_MORE)
|
|
|
|
{
|
2011-05-09 21:52:06 +00:00
|
|
|
/* Failed to find anything after all - do playlist switchover
|
2011-04-27 03:08:23 +00:00
|
|
|
instead */
|
|
|
|
skip_pending = TRACK_SKIP_AUTO_NEW_PLAYLIST;
|
|
|
|
end_of_playlist = playlist_next(1) < 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (end_of_playlist)
|
|
|
|
{
|
|
|
|
audio_monitor_end_of_playlist();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-03-28 20:18:53 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_begin_track_change(TRACK_CHANGE_AUTO, trackstat);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Called when codec completes seek operation
|
|
|
|
(usually Q_AUDIO_CODEC_SEEK_COMPLETE) */
|
|
|
|
static void audio_on_codec_seek_complete(void)
|
|
|
|
{
|
|
|
|
logf("%s()", __func__);
|
|
|
|
audio_complete_codec_seek();
|
|
|
|
codec_go();
|
2005-06-05 23:05:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Called when PCM track change has completed
|
|
|
|
(Q_AUDIO_TRACK_CHANGED) */
|
|
|
|
static void audio_on_track_changed(void)
|
2005-06-05 23:05:10 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Finish whatever is pending so that the WPS is in sync */
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_finalise_track_change();
|
2007-11-04 19:01:02 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (codec_skip_pending)
|
|
|
|
{
|
|
|
|
/* Codec got ahead completing a short track - complete the
|
|
|
|
codec's skip and begin the next */
|
|
|
|
codec_skip_pending = false;
|
|
|
|
audio_on_codec_complete(codec_skip_status);
|
|
|
|
}
|
|
|
|
}
|
2006-03-30 05:56:19 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Begin playback from an idle state, transition to a new playlist or
|
|
|
|
invalidate the buffer and resume (if playing).
|
|
|
|
(usually Q_AUDIO_PLAY, Q_AUDIO_REMAKE_AUDIO_BUFFER) */
|
2013-07-14 11:59:39 +00:00
|
|
|
static void audio_start_playback(const struct audio_resume_info *resume_info,
|
|
|
|
unsigned int flags)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
struct audio_resume_info resume =
|
|
|
|
*(resume_info ?: &(struct audio_resume_info){ 0, 0 } );
|
2011-04-27 03:08:23 +00:00
|
|
|
enum play_status old_status = play_status;
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (flags & AUDIO_START_NEWBUF)
|
|
|
|
{
|
|
|
|
/* Mark the buffer dirty - if not playing, it will be reset next
|
|
|
|
time */
|
|
|
|
if (buffer_state == AUDIOBUF_STATE_INITIALIZED)
|
2013-05-30 09:24:16 +00:00
|
|
|
buffer_state = AUDIOBUF_STATE_TRASHED;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2007-05-08 22:56:12 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (old_status != PLAY_STOPPED)
|
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
logf("%s(%lu, %lu): skipping", __func__, resume.elapsed,
|
|
|
|
resume.offset);
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
halt_decoding_track(true);
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_NONE;
|
2011-04-27 03:08:23 +00:00
|
|
|
ff_rw_mode = false;
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (flags & AUDIO_START_RESTART)
|
|
|
|
{
|
|
|
|
/* Clear out some stuff to resume the current track where it
|
|
|
|
left off */
|
|
|
|
pcmbuf_play_stop();
|
2013-07-14 11:59:39 +00:00
|
|
|
resume.elapsed = id3_get(PLAYING_ID3)->elapsed;
|
|
|
|
resume.offset = id3_get(PLAYING_ID3)->offset;
|
2011-04-27 03:08:23 +00:00
|
|
|
track_list_clear(TRACK_LIST_CLEAR_ALL);
|
2017-11-24 12:55:56 +00:00
|
|
|
pcmbuf_update_frequency();
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is more-or-less treated as manual track transition */
|
|
|
|
/* Save resume information for current track */
|
|
|
|
audio_playlist_track_finish();
|
|
|
|
track_list_clear(TRACK_LIST_CLEAR_ALL);
|
|
|
|
|
|
|
|
/* Indicate manual track change */
|
2011-08-28 07:45:35 +00:00
|
|
|
pcmbuf_start_track_change(TRACK_CHANGE_MANUAL);
|
2011-04-27 03:08:23 +00:00
|
|
|
wipe_track_metadata(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set after track finish event in case skip was in progress */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags & AUDIO_START_RESTART)
|
|
|
|
return; /* Must already be playing */
|
|
|
|
|
|
|
|
/* Cold playback start from a stopped state */
|
2013-07-14 11:59:39 +00:00
|
|
|
logf("%s(%lu, %lu): starting", __func__, resume.elapsed,
|
|
|
|
resume.offset);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Set audio parameters */
|
|
|
|
#if INPUT_SRC_CAPS != 0
|
|
|
|
audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
|
|
|
audio_set_output_source(AUDIO_SRC_PLAYBACK);
|
|
|
|
#endif
|
|
|
|
#ifndef PLATFORM_HAS_VOLUME_CHANGE
|
|
|
|
sound_set_volume(global_settings.volume);
|
2013-05-23 17:58:51 +00:00
|
|
|
#endif
|
|
|
|
pcmbuf_update_frequency();
|
|
|
|
|
2011-06-29 06:37:04 +00:00
|
|
|
/* Be sure channel is audible */
|
|
|
|
pcmbuf_fade(false, true);
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Update our state */
|
|
|
|
play_status = PLAY_PLAYING;
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Codec's position should be available as soon as it knows it */
|
|
|
|
position_key = pcmbuf_get_position_key();
|
|
|
|
pcmbuf_sync_position_update();
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Start fill from beginning of playlist */
|
|
|
|
playlist_peek_offset = -1;
|
|
|
|
buf_set_base_handle(-1);
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2007-05-08 22:56:12 +00:00
|
|
|
/* Officially playing */
|
|
|
|
queue_reply(&audio_queue, 1);
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Add these now - finish event for the first id3 will most likely be sent
|
|
|
|
immediately */
|
2014-03-14 22:15:16 +00:00
|
|
|
add_event(BUFFER_EVENT_REBUFFER, buffer_event_rebuffer_callback);
|
|
|
|
add_event(BUFFER_EVENT_FINISHED, buffer_event_finished_callback);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (old_status == PLAY_STOPPED)
|
|
|
|
{
|
|
|
|
/* Send coldstart event */
|
|
|
|
send_event(PLAYBACK_EVENT_START_PLAYBACK, NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-19 20:52:00 +00:00
|
|
|
/* Fill the buffer */
|
2011-04-27 03:08:23 +00:00
|
|
|
int trackstat = audio_fill_file_buffer();
|
|
|
|
|
|
|
|
if (trackstat >= LOAD_TRACK_OK)
|
|
|
|
{
|
|
|
|
/* This is the currently playing track - get metadata, stat */
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
track_list_current(0, &info);
|
|
|
|
playing_id3_sync(&info, resume.elapsed, resume.offset);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (valid_mp3entry(id3_get(PLAYING_ID3)))
|
|
|
|
{
|
|
|
|
/* Only if actually changing tracks... */
|
|
|
|
if (!(flags & AUDIO_START_RESTART))
|
|
|
|
audio_playlist_track_change();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Found nothing playable */
|
|
|
|
audio_handle_track_load_status(trackstat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop playback and enter an idle state
|
|
|
|
(usually Q_AUDIO_STOP) */
|
|
|
|
static void audio_stop_playback(void)
|
|
|
|
{
|
|
|
|
logf("%s()", __func__);
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return;
|
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
bool do_fade = global_settings.fade_on_stop && filling != STATE_ENDED;
|
|
|
|
|
|
|
|
pcmbuf_fade(do_fade, false);
|
|
|
|
|
|
|
|
/* Wait for fade-out */
|
|
|
|
audio_wait_fade_complete();
|
2011-06-29 06:37:04 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Stop the codec and unload it */
|
|
|
|
halt_decoding_track(true);
|
|
|
|
pcmbuf_play_stop();
|
|
|
|
codec_unload();
|
|
|
|
|
|
|
|
/* Save resume information - "filling" might have been set to
|
|
|
|
"STATE_ENDED" by caller in order to facilitate end of playlist */
|
|
|
|
audio_playlist_track_finish();
|
|
|
|
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_NONE;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Close all tracks and mark them NULL */
|
|
|
|
remove_event(BUFFER_EVENT_REBUFFER, buffer_event_rebuffer_callback);
|
|
|
|
remove_event(BUFFER_EVENT_FINISHED, buffer_event_finished_callback);
|
2014-03-14 22:15:16 +00:00
|
|
|
remove_event_ex(BUFFER_EVENT_BUFFER_LOW, buffer_event_buffer_low_callback, NULL);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
track_list_clear(TRACK_LIST_CLEAR_ALL);
|
|
|
|
|
|
|
|
/* Update our state */
|
|
|
|
ff_rw_mode = false;
|
|
|
|
play_status = PLAY_STOPPED;
|
|
|
|
|
|
|
|
wipe_track_metadata(true);
|
|
|
|
|
|
|
|
/* Go idle */
|
|
|
|
filling = STATE_IDLE;
|
|
|
|
cancel_cpu_boost();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pause the playback of the current track
|
|
|
|
(Q_AUDIO_PAUSE) */
|
|
|
|
static void audio_on_pause(bool pause)
|
|
|
|
{
|
|
|
|
logf("%s(%s)", __func__, pause ? "true" : "false");
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED || pause == (play_status == PLAY_PAUSED))
|
|
|
|
return;
|
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
play_status = pause ? PLAY_PAUSED : PLAY_PLAYING;
|
2011-06-29 06:37:04 +00:00
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
if (!pause && codec_skip_pending)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-23 01:37:59 +00:00
|
|
|
/* Actually do the skip that is due - resets the status flag */
|
|
|
|
audio_on_codec_complete(codec_skip_status);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
bool do_fade = global_settings.fade_on_stop;
|
2011-06-29 06:37:04 +00:00
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
pcmbuf_fade(do_fade, !pause);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
if (!ff_rw_mode && !(do_fade && pause))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-23 01:37:59 +00:00
|
|
|
/* Not in ff/rw mode - can actually change the audio state now */
|
|
|
|
pcmbuf_pause(pause);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip a certain number of tracks forwards or backwards
|
|
|
|
(Q_AUDIO_SKIP) */
|
|
|
|
static void audio_on_skip(void)
|
|
|
|
{
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
/* Eat the delta to keep it synced, even if not playing */
|
|
|
|
int toskip = skip_offset;
|
|
|
|
skip_offset = 0;
|
|
|
|
|
|
|
|
logf("%s(): %d", __func__, toskip);
|
|
|
|
|
|
|
|
id3_mutex_unlock();
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Force codec to abort this track */
|
|
|
|
halt_decoding_track(true);
|
|
|
|
|
|
|
|
/* Kill the ff/rw halt */
|
|
|
|
ff_rw_mode = false;
|
|
|
|
|
|
|
|
/* Manual skip */
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_NONE;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* If there was an auto skip in progress, there will be residual
|
|
|
|
advancement of the playlist and/or track list so compensation will be
|
|
|
|
required in order to end up in the right spot */
|
|
|
|
int track_list_delta = toskip;
|
|
|
|
int playlist_delta = toskip;
|
|
|
|
|
|
|
|
if (skip_pending != TRACK_SKIP_NONE)
|
|
|
|
{
|
|
|
|
if (skip_pending != TRACK_SKIP_AUTO_END_PLAYLIST)
|
|
|
|
track_list_delta--;
|
|
|
|
|
|
|
|
if (skip_pending == TRACK_SKIP_AUTO_NEW_PLAYLIST)
|
|
|
|
playlist_delta--;
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_playlist_track_finish();
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
|
|
|
|
|
|
|
/* Update the playlist current track now */
|
2012-03-19 09:56:38 +00:00
|
|
|
int pl_retval;
|
|
|
|
while ((pl_retval = playlist_next(playlist_delta)) < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2012-03-19 09:56:38 +00:00
|
|
|
if (pl_retval < -1)
|
|
|
|
{
|
|
|
|
/* Some variety of fatal error while updating playlist */
|
|
|
|
filling = STATE_ENDED;
|
|
|
|
audio_stop_playback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Manual skip out of range (because the playlist wasn't updated
|
|
|
|
yet by us and so the check in audio_skip returned 'ok') - bring
|
|
|
|
back into range */
|
|
|
|
int d = toskip < 0 ? 1 : -1;
|
|
|
|
|
|
|
|
while (!playlist_check(playlist_delta))
|
|
|
|
{
|
|
|
|
if (playlist_delta == d)
|
|
|
|
{
|
|
|
|
/* Had to move the opposite direction to correct, which is
|
|
|
|
wrong - this is the end */
|
|
|
|
filling = STATE_ENDED;
|
|
|
|
audio_stop_playback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist_delta += d;
|
|
|
|
track_list_delta += d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust things by how much the playlist was manually moved */
|
|
|
|
playlist_peek_offset -= playlist_delta;
|
|
|
|
|
|
|
|
int trackstat = LOAD_TRACK_OK;
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info info;
|
|
|
|
if (!track_list_advance_current(track_list_delta, &info)
|
|
|
|
|| info.audio_hid < 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* We don't know the next track thus we know we don't have it */
|
|
|
|
trackstat = audio_reset_and_rebuffer(TRACK_LIST_CLEAR_ALL, -1);
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_begin_track_change(TRACK_CHANGE_MANUAL, trackstat);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip to the next/previous directory
|
|
|
|
(Q_AUDIO_DIR_SKIP) */
|
|
|
|
static void audio_on_dir_skip(int direction)
|
|
|
|
{
|
|
|
|
logf("%s(%d)", __func__, direction);
|
|
|
|
|
|
|
|
id3_mutex_lock();
|
|
|
|
skip_offset = 0;
|
|
|
|
id3_mutex_unlock();
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Force codec to abort this track */
|
|
|
|
halt_decoding_track(true);
|
|
|
|
|
|
|
|
/* Kill the ff/rw halt */
|
|
|
|
ff_rw_mode = false;
|
|
|
|
|
|
|
|
/* Manual skip */
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_NONE;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
audio_playlist_track_finish();
|
|
|
|
|
|
|
|
/* Unless automatic and gapless, skips do not pend */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
|
|
|
|
|
|
|
/* Regardless of the return value we need to rebuffer. If it fails the old
|
|
|
|
playlist will resume, else the next dir will start playing. */
|
|
|
|
playlist_next_dir(direction);
|
|
|
|
|
|
|
|
wipe_track_metadata(false);
|
|
|
|
|
|
|
|
int trackstat = audio_reset_and_rebuffer(TRACK_LIST_CLEAR_ALL, -1);
|
|
|
|
|
|
|
|
if (trackstat == LOAD_TRACK_ERR_NO_MORE)
|
|
|
|
{
|
|
|
|
/* The day the music died - finish-off whatever is playing and call it
|
|
|
|
quits */
|
|
|
|
audio_monitor_end_of_playlist();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
audio_begin_track_change(TRACK_CHANGE_MANUAL, trackstat);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter seek mode in order to start a seek
|
|
|
|
(Q_AUDIO_PRE_FF_REWIND) */
|
|
|
|
static void audio_on_pre_ff_rewind(void)
|
|
|
|
{
|
|
|
|
logf("%s()", __func__);
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED || ff_rw_mode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ff_rw_mode = true;
|
|
|
|
|
2011-08-23 01:37:59 +00:00
|
|
|
audio_wait_fade_complete();
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (play_status == PLAY_PAUSED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pcmbuf_pause(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seek the playback of the current track to the specified time
|
|
|
|
(Q_AUDIO_FF_REWIND) */
|
|
|
|
static void audio_on_ff_rewind(long time)
|
|
|
|
{
|
|
|
|
logf("%s(%ld)", __func__, time);
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
enum track_skip_type pending = skip_pending;
|
2008-04-03 17:51:53 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
switch (pending)
|
|
|
|
{
|
|
|
|
case TRACK_SKIP_NONE: /* The usual case */
|
|
|
|
case TRACK_SKIP_AUTO: /* Have to back it out (fun!) */
|
|
|
|
case TRACK_SKIP_AUTO_END_PLAYLIST: /* Still have the last codec used */
|
|
|
|
{
|
|
|
|
struct mp3entry *id3 = id3_get(PLAYING_ID3);
|
|
|
|
struct mp3entry *ci_id3 = id3_get(CODEC_ID3);
|
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
track_event_flags = TEF_NONE;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2013-07-12 16:06:38 +00:00
|
|
|
/* Send event before clobbering the time if rewinding. */
|
2011-04-27 03:08:23 +00:00
|
|
|
if (time == 0)
|
2013-07-12 16:06:38 +00:00
|
|
|
{
|
|
|
|
send_track_event(PLAYBACK_EVENT_TRACK_FINISH,
|
|
|
|
track_event_flags | TEF_REWIND, id3);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
id3->elapsed = time;
|
|
|
|
queue_reply(&audio_queue, 1);
|
|
|
|
|
|
|
|
bool haltres = halt_decoding_track(pending == TRACK_SKIP_AUTO);
|
|
|
|
|
|
|
|
/* Need this set in case ff/rw mode + error but _after_ the codec
|
|
|
|
halt that will reset it */
|
|
|
|
codec_seeking = true;
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* If in transition, key will have changed - sync to it */
|
|
|
|
position_key = pcmbuf_get_position_key();
|
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (pending == TRACK_SKIP_AUTO && !track_list_advance_current(-1, NULL))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Not in list - must rebuffer at the current playlist index */
|
|
|
|
if (audio_reset_and_rebuffer(TRACK_LIST_CLEAR_ALL, -1)
|
|
|
|
< LOAD_TRACK_OK)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
/* Codec is stopped */
|
|
|
|
break;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set after audio_fill_file_buffer to disable playing id3 clobber if
|
|
|
|
rebuffer is needed */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
2017-12-08 18:01:25 +00:00
|
|
|
|
|
|
|
struct track_info cur_info;
|
|
|
|
track_list_current(0, &cur_info);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Track must complete the loading _now_ since a codec and audio
|
|
|
|
handle are needed in order to do the seek */
|
2017-12-08 18:01:25 +00:00
|
|
|
bool finish_load = cur_info.audio_hid < 0;
|
Ensure ci is properly updated if seeking before track load completes
If in the middle of a manual skip, playback would try to seek, and
therefore start, the codec before the audio handle was available.
This wasn't really a problem since the codec would just bail out
and be retried later. But, it is a problem for a change I was working
on with seeking where the codec could get caught in a full-speed
loop trying to seek itself (stoppable, not lockup).
The main side effect of this change that you may notice, if using an
HDD with dircache turned on and the disk is not spinning, is that you
can keep holding down prev/next if dir skipping and the WPS will
start FF/RW mode. By the time the new track shows up, you will have
seeked into it some amount.
Well, the PBE is getting the info ASAP anyway and as far as it's
concerned, the next track is under way. On that end of things, it's
correct. Perhaps WPS should lock out its own seek mode at certain
times.
Change-Id: Ifc7409a886df399cec189d1bae2adba3872e857a
2017-12-07 16:20:09 +00:00
|
|
|
|
|
|
|
if (finish_load &&
|
2017-12-08 18:01:25 +00:00
|
|
|
audio_finish_load_track(&cur_info) != LOAD_TRACK_READY)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Call above should push any load sequence - no need for
|
|
|
|
halt_decoding_track here if no skip was pending here because
|
|
|
|
there would not be a codec started if no audio handle was yet
|
|
|
|
opened */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Ensure ci is properly updated if seeking before track load completes
If in the middle of a manual skip, playback would try to seek, and
therefore start, the codec before the audio handle was available.
This wasn't really a problem since the codec would just bail out
and be retried later. But, it is a problem for a change I was working
on with seeking where the codec could get caught in a full-speed
loop trying to seek itself (stoppable, not lockup).
The main side effect of this change that you may notice, if using an
HDD with dircache turned on and the disk is not spinning, is that you
can keep holding down prev/next if dir skipping and the WPS will
start FF/RW mode. By the time the new track shows up, you will have
seeked into it some amount.
Well, the PBE is getting the info ASAP anyway and as far as it's
concerned, the next track is under way. On that end of things, it's
correct. Perhaps WPS should lock out its own seek mode at certain
times.
Change-Id: Ifc7409a886df399cec189d1bae2adba3872e857a
2017-12-07 16:20:09 +00:00
|
|
|
if (pending == TRACK_SKIP_AUTO || finish_load)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!bufreadid3(cur_info.id3_hid, ci_id3) ||
|
|
|
|
!audio_init_codec(&cur_info, ci_id3))
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* We should have still been able to get it - skip it and move
|
2011-05-09 21:52:06 +00:00
|
|
|
onto the next one - like it or not this track is broken */
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the codec API to the correct metadata and track info */
|
2017-12-08 18:01:25 +00:00
|
|
|
ci.audio_hid = cur_info.audio_hid;
|
2017-12-17 21:12:10 +00:00
|
|
|
ci.filesize = buf_filesize(cur_info.audio_hid);
|
2017-12-08 18:01:25 +00:00
|
|
|
buf_set_base_handle(cur_info.audio_hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!haltres)
|
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
/* If codec must be (re)started, reset the resume info so that
|
|
|
|
it doesn't execute resume procedures */
|
|
|
|
ci_id3->elapsed = 0;
|
2011-04-27 03:08:23 +00:00
|
|
|
ci_id3->offset = 0;
|
|
|
|
}
|
2007-06-24 19:20:27 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
codec_seek(time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TRACK_SKIP_AUTO_NEW_PLAYLIST:
|
|
|
|
{
|
|
|
|
/* We cannot do this because the playlist must be reversed by one
|
|
|
|
and it doesn't always return the same song when going backwards
|
|
|
|
across boundaries as forwards (either because of randomization
|
|
|
|
or inconsistency in deciding what the previous track should be),
|
|
|
|
therefore the whole operation would often end up as nonsense -
|
|
|
|
lock out seeking for a couple seconds */
|
|
|
|
|
|
|
|
/* Sure as heck cancel seek mode too! */
|
|
|
|
audio_ff_rewind_end();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Won't see this */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
{
|
|
|
|
/* Playback ended because of an error completing a track load */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always fake it as a codec start error which will handle mode
|
|
|
|
cancellations and skip to the next track */
|
|
|
|
audio_handle_track_load_status(LOAD_TRACK_ERR_START_CODEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalidates all but currently playing track
|
|
|
|
(Q_AUDIO_FLUSH) */
|
|
|
|
static void audio_on_audio_flush(void)
|
|
|
|
{
|
|
|
|
logf("%s", __func__);
|
|
|
|
|
|
|
|
if (track_list_empty())
|
|
|
|
return; /* Nothing to flush out */
|
|
|
|
|
|
|
|
switch (skip_pending)
|
|
|
|
{
|
|
|
|
case TRACK_SKIP_NONE:
|
|
|
|
case TRACK_SKIP_AUTO_END_PLAYLIST:
|
|
|
|
/* Remove all but the currently playing track from the list and
|
|
|
|
refill after that */
|
|
|
|
track_list_clear(TRACK_LIST_KEEP_CURRENT);
|
|
|
|
playlist_peek_offset = 0;
|
|
|
|
id3_write_locked(UNBUFFERED_ID3, NULL);
|
|
|
|
audio_update_and_announce_next_track(NULL);
|
|
|
|
|
2011-05-09 21:52:06 +00:00
|
|
|
/* Ignore return since it's about the next track, not this one */
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_fill_file_buffer();
|
|
|
|
|
|
|
|
if (skip_pending == TRACK_SKIP_NONE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* There's now a track after this one now - convert to auto skip -
|
|
|
|
no skip should pend right now because multiple flush messages can
|
|
|
|
be fired which would cause a restart in the below cases */
|
|
|
|
skip_pending = TRACK_SKIP_NONE;
|
|
|
|
audio_clear_track_notifications();
|
|
|
|
audio_queue_post(Q_AUDIO_CODEC_COMPLETE, CODEC_OK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRACK_SKIP_AUTO:
|
|
|
|
case TRACK_SKIP_AUTO_NEW_PLAYLIST:
|
|
|
|
/* Precisely removing what it already decoded for the next track is
|
|
|
|
not possible so a restart is required in order to continue the
|
|
|
|
currently playing track without the now invalid future track
|
|
|
|
playing */
|
2013-07-14 11:59:39 +00:00
|
|
|
audio_start_playback(NULL, AUDIO_START_RESTART);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Nothing else is a state */
|
|
|
|
break;
|
|
|
|
}
|
2005-06-06 00:35:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
/* Called by audio thread when playback is started */
|
|
|
|
void audio_playback_handler(struct queue_event *ev)
|
2005-06-08 10:33:01 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
while (1)
|
2007-08-02 13:19:35 +00:00
|
|
|
{
|
2013-05-31 06:41:02 +00:00
|
|
|
switch (ev->id)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/** Codec and track change messages **/
|
|
|
|
case Q_AUDIO_CODEC_COMPLETE:
|
|
|
|
/* Codec is done processing track and has gone idle */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_CODEC_COMPLETE: %ld",
|
|
|
|
(long)ev->data);
|
|
|
|
audio_on_codec_complete(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_CODEC_SEEK_COMPLETE:
|
|
|
|
/* Codec is done seeking */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_SEEK_COMPLETE");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_codec_seek_complete();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_TRACK_CHANGED:
|
|
|
|
/* PCM track change done */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_TRACK_CHANGED");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_track_changed();
|
|
|
|
break;
|
2007-08-02 13:19:35 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** Control messages **/
|
|
|
|
case Q_AUDIO_PLAY:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_PLAY");
|
2013-07-14 11:59:39 +00:00
|
|
|
audio_start_playback((struct audio_resume_info *)ev->data, 0);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-31 10:24:06 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2013-05-31 06:41:02 +00:00
|
|
|
/* So we can go straight from playback to recording */
|
|
|
|
case Q_AUDIO_INIT_RECORDING:
|
|
|
|
#endif
|
|
|
|
case SYS_USB_CONNECTED:
|
2011-04-27 03:08:23 +00:00
|
|
|
case Q_AUDIO_STOP:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_STOP");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_stop_playback();
|
2013-05-31 06:41:02 +00:00
|
|
|
if (ev->data != 0)
|
2011-04-27 03:08:23 +00:00
|
|
|
queue_clear(&audio_queue);
|
2013-05-31 06:41:02 +00:00
|
|
|
return; /* no more playback */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
case Q_AUDIO_PAUSE:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_PAUSE");
|
|
|
|
audio_on_pause(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_SKIP:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_SKIP");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_skip();
|
|
|
|
break;
|
2005-06-08 10:33:01 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
case Q_AUDIO_DIR_SKIP:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_DIR_SKIP");
|
|
|
|
audio_on_dir_skip(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_PRE_FF_REWIND:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_PRE_FF_REWIND");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_pre_ff_rewind();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_FF_REWIND:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_FF_REWIND");
|
|
|
|
audio_on_ff_rewind(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_FLUSH:
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_FLUSH: %d", (int)ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_audio_flush();
|
|
|
|
break;
|
2005-06-08 10:33:01 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** Buffering messages **/
|
|
|
|
case Q_AUDIO_BUFFERING:
|
|
|
|
/* some buffering event */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_BUFFERING: %d", (int)ev->data);
|
|
|
|
audio_on_buffering(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_FILL_BUFFER:
|
|
|
|
/* continue buffering next track */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_FILL_BUFFER");
|
2011-04-27 03:08:23 +00:00
|
|
|
audio_on_fill_buffer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_FINISH_LOAD_TRACK:
|
|
|
|
/* metadata is buffered */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_FINISH_LOAD_TRACK");
|
|
|
|
audio_on_finish_load_track(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Q_AUDIO_HANDLE_FINISHED:
|
|
|
|
/* some other type is buffered */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_HANDLE_FINISHED");
|
|
|
|
audio_on_handle_finished(ev->data);
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/** Miscellaneous messages **/
|
|
|
|
case Q_AUDIO_REMAKE_AUDIO_BUFFER:
|
|
|
|
/* buffer needs to be reinitialized */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_REMAKE_AUDIO_BUFFER");
|
2013-07-14 11:59:39 +00:00
|
|
|
audio_start_playback(NULL, AUDIO_START_RESTART | AUDIO_START_NEWBUF);
|
2013-05-31 08:13:39 +00:00
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return; /* just need to change buffer state */
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_DISK_STORAGE
|
|
|
|
case Q_AUDIO_UPDATE_WATERMARK:
|
|
|
|
/* buffering watermark needs updating */
|
2013-05-31 06:41:02 +00:00
|
|
|
LOGFQUEUE("playback < Q_AUDIO_UPDATE_WATERMARK: %d",
|
|
|
|
(int)ev->data);
|
|
|
|
audio_update_filebuf_watermark(ev->data);
|
2013-05-31 08:13:39 +00:00
|
|
|
if (play_status == PLAY_STOPPED)
|
|
|
|
return; /* just need to update setting */
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
#endif /* HAVE_DISK_STORAGE */
|
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
case SYS_TIMEOUT:
|
|
|
|
LOGFQUEUE_SYS_TIMEOUT("playback < SYS_TIMEOUT");
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
default:
|
|
|
|
/* LOGFQUEUE("audio < default : %08lX", ev->id); */
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
2013-05-31 06:41:02 +00:00
|
|
|
} /* end switch */
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
switch (filling)
|
|
|
|
{
|
|
|
|
/* Active states */
|
|
|
|
case STATE_FULL:
|
|
|
|
case STATE_END_OF_PLAYLIST:
|
|
|
|
if (buf_get_watermark() == 0)
|
|
|
|
{
|
|
|
|
/* End of buffering for now, let's calculate the watermark,
|
|
|
|
register for a low buffer event and unboost */
|
|
|
|
audio_update_filebuf_watermark(0);
|
2014-03-14 22:15:16 +00:00
|
|
|
add_event_ex(BUFFER_EVENT_BUFFER_LOW, true,
|
|
|
|
buffer_event_buffer_low_callback, NULL);
|
2013-05-31 06:41:02 +00:00
|
|
|
}
|
|
|
|
/* Fall-through */
|
|
|
|
case STATE_FINISHED:
|
|
|
|
/* All data was buffered */
|
|
|
|
cancel_cpu_boost();
|
|
|
|
/* Fall-through */
|
|
|
|
case STATE_FILLING:
|
|
|
|
case STATE_ENDING:
|
|
|
|
if (audio_pcmbuf_track_change_scan())
|
|
|
|
{
|
|
|
|
/* Transfer notification to audio queue event */
|
|
|
|
ev->id = Q_AUDIO_TRACK_CHANGED;
|
|
|
|
ev->data = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If doing auto skip, poll pcmbuf track notifications a bit
|
|
|
|
faster to promply detect the transition */
|
|
|
|
queue_wait_w_tmo(&audio_queue, ev,
|
|
|
|
skip_pending == TRACK_SKIP_NONE ? HZ/2 : HZ/10);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
/* Idle states */
|
2011-04-27 03:08:23 +00:00
|
|
|
default:
|
2013-05-31 06:41:02 +00:00
|
|
|
queue_wait(&audio_queue, ev);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
} /* end while */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* --- Buffering callbacks --- */
|
|
|
|
|
|
|
|
/* Called when fullness is below the watermark level */
|
2014-03-14 22:15:16 +00:00
|
|
|
static void buffer_event_buffer_low_callback(unsigned short id, void *ev_data, void *user_data)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
logf("low buffer callback");
|
|
|
|
LOGFQUEUE("buffering > audio Q_AUDIO_BUFFERING: buffer low");
|
|
|
|
audio_queue_post(Q_AUDIO_BUFFERING, BUFFER_EVENT_BUFFER_LOW);
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
|
|
|
(void)ev_data;
|
|
|
|
(void)user_data;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when handles must be discarded in order to buffer new data */
|
2014-03-14 22:15:16 +00:00
|
|
|
static void buffer_event_rebuffer_callback(unsigned short id, void *ev_data)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
logf("rebuffer callback");
|
|
|
|
LOGFQUEUE("buffering > audio Q_AUDIO_BUFFERING: rebuffer");
|
|
|
|
audio_queue_post(Q_AUDIO_BUFFERING, BUFFER_EVENT_REBUFFER);
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
|
|
|
(void)ev_data;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A handle has completed buffering and all required data is available */
|
2014-03-14 22:15:16 +00:00
|
|
|
static void buffer_event_finished_callback(unsigned short id, void *ev_data)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2014-03-14 22:15:16 +00:00
|
|
|
(void)id;
|
|
|
|
int hid = *(const int *)ev_data;
|
2017-12-17 21:12:10 +00:00
|
|
|
int htype = buf_handle_data_type(hid);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2017-12-17 21:12:10 +00:00
|
|
|
logf("handle %d finished buffering (type:%d)", hid, htype);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
/* Limit queue traffic */
|
|
|
|
switch (htype)
|
|
|
|
{
|
|
|
|
case TYPE_ID3:
|
|
|
|
/* The metadata handle for the last loaded track has been buffered.
|
|
|
|
We can ask the audio thread to load the rest of the track's data. */
|
|
|
|
LOGFQUEUE("buffering > audio Q_AUDIO_FINISH_LOAD_TRACK: %d", hid);
|
|
|
|
audio_queue_post(Q_AUDIO_FINISH_LOAD_TRACK, hid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_PACKET_AUDIO:
|
|
|
|
/* Strip any useless trailing tags that are left. */
|
|
|
|
strip_tags(hid);
|
|
|
|
/* Fall-through */
|
|
|
|
case TYPE_ATOMIC_AUDIO:
|
|
|
|
LOGFQUEUE("buffering > audio Q_AUDIO_HANDLE_FINISHED: %d", hid);
|
|
|
|
audio_queue_post(Q_AUDIO_HANDLE_FINISHED, hid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Don't care to know about these */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** -- Codec callbacks -- **/
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Update elapsed time for next PCM insert */
|
|
|
|
void audio_codec_update_elapsed(unsigned long elapsed)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
#ifdef AB_REPEAT_ENABLE
|
2011-08-28 07:45:35 +00:00
|
|
|
ab_position_report(elapsed);
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Save in codec's id3 where it is used at next pcm insert */
|
|
|
|
id3_get(CODEC_ID3)->elapsed = elapsed;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Update offset for next PCM insert */
|
|
|
|
void audio_codec_update_offset(size_t offset)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Save in codec's id3 where it is used at next pcm insert */
|
|
|
|
id3_get(CODEC_ID3)->offset = offset;
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Codec has finished running */
|
|
|
|
void audio_codec_complete(int status)
|
|
|
|
{
|
|
|
|
#ifdef AB_REPEAT_ENABLE
|
|
|
|
if (status >= CODEC_OK)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Normal automatic skip */
|
|
|
|
ab_end_of_track_report();
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2011-08-28 07:45:35 +00:00
|
|
|
#endif
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
LOGFQUEUE("codec > audio Q_AUDIO_CODEC_COMPLETE: %d", status);
|
|
|
|
audio_queue_post(Q_AUDIO_CODEC_COMPLETE, status);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Codec has finished seeking */
|
|
|
|
void audio_codec_seek_complete(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("codec > audio Q_AUDIO_CODEC_SEEK_COMPLETE");
|
|
|
|
audio_queue_post(Q_AUDIO_CODEC_SEEK_COMPLETE, 0);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** --- Pcmbuf callbacks --- **/
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Update the elapsed and offset from the information cached during the
|
|
|
|
PCM buffer insert */
|
|
|
|
void audio_pcmbuf_position_callback(unsigned long elapsed, off_t offset,
|
|
|
|
unsigned int key)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
2011-08-28 07:45:35 +00:00
|
|
|
if (key == position_key)
|
|
|
|
{
|
|
|
|
struct mp3entry *id3 = id3_get(PLAYING_ID3);
|
|
|
|
id3->elapsed = elapsed;
|
|
|
|
id3->offset = offset;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Synchronize position info to the codec's */
|
|
|
|
void audio_pcmbuf_sync_position(void)
|
|
|
|
{
|
|
|
|
audio_pcmbuf_position_callback(ci.id3->elapsed, ci.id3->offset,
|
|
|
|
pcmbuf_get_position_key());
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Post message from pcmbuf that the end of the previous track has just
|
|
|
|
* been played */
|
|
|
|
void audio_pcmbuf_track_change(bool pcmbuf)
|
|
|
|
{
|
|
|
|
if (pcmbuf)
|
|
|
|
{
|
|
|
|
/* Notify of the change in special-purpose semaphore object */
|
|
|
|
LOGFQUEUE("pcmbuf > pcmbuf Q_AUDIO_TRACK_CHANGED");
|
|
|
|
audio_pcmbuf_track_change_post();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Safe to post directly to the queue */
|
|
|
|
LOGFQUEUE("pcmbuf > audio Q_AUDIO_TRACK_CHANGED");
|
|
|
|
audio_queue_post(Q_AUDIO_TRACK_CHANGED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* May pcmbuf start PCM playback when the buffer is full enough? */
|
|
|
|
bool audio_pcmbuf_may_play(void)
|
|
|
|
{
|
2011-06-29 06:37:04 +00:00
|
|
|
return play_status == PLAY_PLAYING && !ff_rw_mode;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** -- External interfaces -- **/
|
|
|
|
|
|
|
|
/* Get a copy of the id3 data for the for current track + offset + skip delta */
|
|
|
|
bool audio_peek_track(struct mp3entry *id3, int offset)
|
|
|
|
{
|
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
if (play_status != PLAY_STOPPED)
|
|
|
|
{
|
|
|
|
id3->path[0] = '\0'; /* Null path means it should be filled now */
|
|
|
|
retval = audio_get_track_metadata(offset + skip_offset, id3) &&
|
|
|
|
id3->path[0] != '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
id3_mutex_unlock();
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the mp3entry for the currently playing track */
|
|
|
|
struct mp3entry * audio_current_track(void)
|
|
|
|
{
|
|
|
|
struct mp3entry *id3;
|
|
|
|
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
#ifdef AUDIO_FAST_SKIP_PREVIEW
|
|
|
|
if (skip_offset != 0)
|
|
|
|
{
|
|
|
|
/* This is a peekahead */
|
|
|
|
id3 = id3_get(PLAYING_PEEK_ID3);
|
|
|
|
audio_peek_track(id3, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Normal case */
|
|
|
|
id3 = id3_get(PLAYING_ID3);
|
|
|
|
audio_get_track_metadata(0, id3);
|
|
|
|
}
|
|
|
|
|
|
|
|
id3_mutex_unlock();
|
|
|
|
|
|
|
|
return id3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Obtains the mp3entry for the next track from the current */
|
|
|
|
struct mp3entry * audio_next_track(void)
|
|
|
|
{
|
|
|
|
struct mp3entry *id3 = id3_get(NEXTTRACK_ID3);
|
|
|
|
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
#ifdef AUDIO_FAST_SKIP_PREVIEW
|
|
|
|
if (skip_offset != 0)
|
|
|
|
{
|
|
|
|
/* This is a peekahead */
|
|
|
|
if (!audio_peek_track(id3, 1))
|
|
|
|
id3 = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Normal case */
|
|
|
|
if (!audio_get_track_metadata(1, id3))
|
|
|
|
id3 = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
id3_mutex_unlock();
|
|
|
|
|
|
|
|
return id3;
|
|
|
|
}
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
/* Start playback at the specified elapsed time or offset */
|
|
|
|
void audio_play(unsigned long elapsed, unsigned long offset)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
logf("audio_play");
|
|
|
|
|
|
|
|
#ifdef PLAYBACK_VOICE
|
|
|
|
/* Truncate any existing voice output so we don't have spelling
|
|
|
|
* etc. over the first part of the played track */
|
|
|
|
talk_force_shutup();
|
|
|
|
#endif
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_PLAY: %lu %lX", elapsed, offset);
|
|
|
|
audio_queue_send(Q_AUDIO_PLAY,
|
|
|
|
(intptr_t)&(struct audio_resume_info){ elapsed, offset });
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop playback if playing */
|
|
|
|
void audio_stop(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_STOP");
|
|
|
|
audio_queue_send(Q_AUDIO_STOP, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pause playback if playing */
|
|
|
|
void audio_pause(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_PAUSE");
|
|
|
|
audio_queue_send(Q_AUDIO_PAUSE, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This sends a stop message and the audio thread will dump all its
|
|
|
|
subsequent messages */
|
|
|
|
void audio_hard_stop(void)
|
|
|
|
{
|
|
|
|
/* Stop playback */
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_STOP: 1");
|
|
|
|
audio_queue_send(Q_AUDIO_STOP, 1);
|
|
|
|
#ifdef PLAYBACK_VOICE
|
|
|
|
voice_stop();
|
|
|
|
#endif
|
2011-08-30 14:01:33 +00:00
|
|
|
if (audiobuf_handle > 0)
|
|
|
|
audiobuf_handle = core_free(audiobuf_handle);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Resume playback if paused */
|
|
|
|
void audio_resume(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_PAUSE resume");
|
|
|
|
audio_queue_send(Q_AUDIO_PAUSE, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip the specified number of tracks forward or backward from the current */
|
|
|
|
void audio_skip(int offset)
|
|
|
|
{
|
|
|
|
id3_mutex_lock();
|
|
|
|
|
|
|
|
/* If offset has to be backed-out to stay in range, no skip is done */
|
|
|
|
int accum = skip_offset + offset;
|
|
|
|
|
|
|
|
while (offset != 0 && !playlist_check(accum))
|
|
|
|
{
|
|
|
|
offset += offset < 0 ? 1 : -1;
|
|
|
|
accum = skip_offset + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != 0)
|
|
|
|
{
|
|
|
|
/* Accumulate net manual skip count since the audio thread last
|
|
|
|
processed one */
|
|
|
|
skip_offset = accum;
|
|
|
|
|
2011-07-08 22:31:15 +00:00
|
|
|
system_sound_play(SOUND_TRACK_SKIP);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_SKIP %d", offset);
|
|
|
|
|
|
|
|
#ifdef AUDIO_FAST_SKIP_PREVIEW
|
|
|
|
/* Do this before posting so that the audio thread can correct us
|
|
|
|
when things settle down - additionally, if audio gets a message
|
|
|
|
and the delta is zero, the Q_AUDIO_SKIP handler (audio_on_skip)
|
|
|
|
handler a skip event with the correct info but doesn't skip */
|
|
|
|
send_event(PLAYBACK_EVENT_TRACK_SKIP, NULL);
|
|
|
|
#endif /* AUDIO_FAST_SKIP_PREVIEW */
|
|
|
|
|
|
|
|
/* Playback only needs the final state even if more than one is
|
|
|
|
processed because it wasn't removed in time */
|
|
|
|
queue_remove_from_head(&audio_queue, Q_AUDIO_SKIP);
|
|
|
|
audio_queue_post(Q_AUDIO_SKIP, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No more tracks */
|
2011-07-08 22:31:15 +00:00
|
|
|
system_sound_play(SOUND_TRACK_NO_MORE);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id3_mutex_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip one track forward from the current */
|
|
|
|
void audio_next(void)
|
|
|
|
{
|
|
|
|
audio_skip(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip one track backward from the current */
|
|
|
|
void audio_prev(void)
|
|
|
|
{
|
|
|
|
audio_skip(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move one directory forward */
|
|
|
|
void audio_next_dir(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_DIR_SKIP 1");
|
|
|
|
audio_queue_post(Q_AUDIO_DIR_SKIP, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move one directory backward */
|
|
|
|
void audio_prev_dir(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_DIR_SKIP -1");
|
|
|
|
audio_queue_post(Q_AUDIO_DIR_SKIP, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pause playback in order to start a seek that flushes the old audio */
|
|
|
|
void audio_pre_ff_rewind(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_PRE_FF_REWIND");
|
|
|
|
audio_queue_post(Q_AUDIO_PRE_FF_REWIND, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seek to the new time in the current track */
|
|
|
|
void audio_ff_rewind(long time)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_FF_REWIND");
|
|
|
|
audio_queue_post(Q_AUDIO_FF_REWIND, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear all but the currently playing track then rebuffer */
|
|
|
|
void audio_flush_and_reload_tracks(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_FLUSH");
|
|
|
|
audio_queue_post(Q_AUDIO_FLUSH, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** --- Miscellaneous public interfaces --- **/
|
|
|
|
|
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
/* Return which album art handle is current for the user in the given slot */
|
|
|
|
int playback_current_aa_hid(int slot)
|
|
|
|
{
|
|
|
|
if ((unsigned)slot < MAX_MULTIPLE_AA)
|
2007-08-02 13:19:35 +00:00
|
|
|
{
|
2017-12-08 18:01:25 +00:00
|
|
|
struct track_info user_cur;
|
|
|
|
bool have_info = track_list_user_current(skip_offset, &user_cur);
|
2005-06-07 06:34:54 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (!have_info && abs(skip_offset) <= 1)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
/* Give the actual position a go */
|
2017-12-08 18:01:25 +00:00
|
|
|
have_info = track_list_user_current(0, &user_cur);
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-04-11 20:41:04 +00:00
|
|
|
|
2017-12-08 18:01:25 +00:00
|
|
|
if (have_info)
|
|
|
|
return user_cur.aa_hid[slot];
|
2006-09-01 07:59:31 +00:00
|
|
|
}
|
2007-10-25 21:27:45 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return ERR_HANDLE_NOT_FOUND;
|
2005-07-21 11:44:00 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Find an album art slot that doesn't match the dimensions of another that
|
|
|
|
is already claimed - increment the use count if it is */
|
|
|
|
int playback_claim_aa_slot(struct dim *dim)
|
2007-11-11 15:50:52 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* First try to find a slot already having the size to reuse it since we
|
|
|
|
don't want albumart of the same size buffered multiple times */
|
|
|
|
FOREACH_ALBUMART(i)
|
2007-11-11 15:50:52 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
struct albumart_slot *slot = &albumart_slots[i];
|
2007-11-11 21:27:18 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (slot->dim.width == dim->width &&
|
|
|
|
slot->dim.height == dim->height)
|
2008-04-14 16:17:47 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
slot->used++;
|
|
|
|
return i;
|
2008-04-14 16:17:47 +00:00
|
|
|
}
|
2008-01-08 14:29:11 +00:00
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Size is new, find a free slot */
|
|
|
|
FOREACH_ALBUMART(i)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!albumart_slots[i].used)
|
|
|
|
{
|
|
|
|
albumart_slots[i].used++;
|
|
|
|
albumart_slots[i].dim = *dim;
|
|
|
|
return i;
|
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Sorry, no free slot */
|
|
|
|
return -1;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Invalidate the albumart_slot - decrement the use count if > 0 */
|
|
|
|
void playback_release_aa_slot(int slot)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if ((unsigned)slot < MAX_MULTIPLE_AA)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
struct albumart_slot *aa_slot = &albumart_slots[slot];
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (aa_slot->used > 0)
|
|
|
|
aa_slot->used--;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-24 12:55:56 +00:00
|
|
|
|
|
|
|
void playback_update_aa_dims(void)
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER");
|
|
|
|
audio_queue_send(Q_AUDIO_REMAKE_AUDIO_BUFFER, 0);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
#endif /* HAVE_ALBUMART */
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
/* Return file byte offset */
|
2011-04-27 03:08:23 +00:00
|
|
|
int audio_get_file_pos(void)
|
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
return id3_get(PLAYING_ID3)->offset;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return total file buffer length after accounting for the talk buf */
|
|
|
|
size_t audio_get_filebuflen(void)
|
|
|
|
{
|
|
|
|
return buf_length();
|
|
|
|
}
|
2011-02-08 20:31:27 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* How many tracks exist on the buffer - full or partial */
|
2018-10-18 13:57:20 +00:00
|
|
|
unsigned int audio_track_count(void)
|
2011-04-27 03:08:23 +00:00
|
|
|
__attribute__((alias("track_list_count")));
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return total ringbuffer space occupied - ridx to widx */
|
|
|
|
long audio_filebufused(void)
|
|
|
|
{
|
|
|
|
return buf_used();
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** -- Settings -- **/
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Enable or disable cuesheet support and allocate/don't allocate the
|
|
|
|
extra associated resources */
|
2013-03-24 13:58:40 +00:00
|
|
|
void audio_set_cuesheet(bool enable)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
if (play_status == PLAY_STOPPED || !enable != !get_current_cuesheet())
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER");
|
|
|
|
audio_queue_send(Q_AUDIO_REMAKE_AUDIO_BUFFER, 0);
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
Auto-Ranging Time Formatting For Menus (hh:mm:ss:mss)
Unifies time formatting in settings_list.c allows time format to
display as HH:MM:SS.MSS or any consecutive combination thereof
(hh:mm:ss, mm:ss, mm:ss.mss, ss.mss, hh, mm, ss ,mss)
works in INT and TABLE settings with the addition of flag 'F_TIME_SETTING'
Time is auto-ranged dependent on value
Adds talk_time_intervals to allow time values to be spoken similar to
display format: x Hours, x Minutes, x Seconds, x Milliseconds
Table lookups merged or removed from recording, clip meter and lcd timeout
-String_Choice replaced with TABLE_SETTING or INT_SETTING for these
functions as well, cleaned-up cfg_vals that get saved to cfgfile
RTL Languages ARE supported
Negative values ARE supported
Backlight on/off are now Always and Never to share formatter with LCD
Timeout
Added flag to allow ranged units to be locked to a minimum index
Added flag to allow leading zero to be supressed from the largest unit
merged talk_time_unit() and talk_time_intervals()
optimized time_split()
optimized format_time_auto()
Backlight time-out list same as original
Change-Id: I59027c62d3f2956bd16fdcc1a48b2ac32c084abd
2018-12-18 04:27:55 +00:00
|
|
|
/* Set the audio antiskip buffer margin in SECONDS */
|
|
|
|
void audio_set_buffer_margin(int seconds)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
Auto-Ranging Time Formatting For Menus (hh:mm:ss:mss)
Unifies time formatting in settings_list.c allows time format to
display as HH:MM:SS.MSS or any consecutive combination thereof
(hh:mm:ss, mm:ss, mm:ss.mss, ss.mss, hh, mm, ss ,mss)
works in INT and TABLE settings with the addition of flag 'F_TIME_SETTING'
Time is auto-ranged dependent on value
Adds talk_time_intervals to allow time values to be spoken similar to
display format: x Hours, x Minutes, x Seconds, x Milliseconds
Table lookups merged or removed from recording, clip meter and lcd timeout
-String_Choice replaced with TABLE_SETTING or INT_SETTING for these
functions as well, cleaned-up cfg_vals that get saved to cfgfile
RTL Languages ARE supported
Negative values ARE supported
Backlight on/off are now Always and Never to share formatter with LCD
Timeout
Added flag to allow ranged units to be locked to a minimum index
Added flag to allow leading zero to be supressed from the largest unit
merged talk_time_unit() and talk_time_intervals()
optimized time_split()
optimized format_time_auto()
Backlight time-out list same as original
Change-Id: I59027c62d3f2956bd16fdcc1a48b2ac32c084abd
2018-12-18 04:27:55 +00:00
|
|
|
logf("buffer margin: %u", (unsigned) seconds);
|
|
|
|
LOGFQUEUE("audio > audio Q_AUDIO_UPDATE_WATERMARK: %u",(unsigned) seconds);
|
|
|
|
audio_queue_post(Q_AUDIO_UPDATE_WATERMARK, (unsigned) seconds); /*SECONDS*/
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_DISK_STORAGE */
|
2007-11-03 17:55:29 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#ifdef HAVE_CROSSFADE
|
|
|
|
/* Take necessary steps to enable or disable the crossfade setting */
|
|
|
|
void audio_set_crossfade(int enable)
|
|
|
|
{
|
|
|
|
/* Tell it the next setting to use */
|
|
|
|
pcmbuf_request_crossfade_enable(enable);
|
2007-11-03 17:55:29 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Return if size hasn't changed or this is too early to determine
|
|
|
|
which in the second case there's no way we could be playing
|
|
|
|
anything at all */
|
|
|
|
if (!pcmbuf_is_same_size())
|
|
|
|
{
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER");
|
|
|
|
audio_queue_send(Q_AUDIO_REMAKE_AUDIO_BUFFER, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CROSSFADE */
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2017-11-24 12:55:56 +00:00
|
|
|
#ifdef HAVE_PLAY_FREQ
|
|
|
|
void audio_set_playback_frequency(int setting)
|
|
|
|
{
|
|
|
|
static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48 };
|
|
|
|
|
|
|
|
if ((unsigned)setting >= ARRAYLEN(play_sampr))
|
|
|
|
setting = 0;
|
|
|
|
|
|
|
|
unsigned long playback_sampr = mixer_get_frequency();
|
|
|
|
unsigned long sampr = play_sampr[setting];
|
|
|
|
|
|
|
|
if (sampr != playback_sampr)
|
|
|
|
{
|
|
|
|
mixer_set_frequency(sampr);
|
|
|
|
LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER");
|
|
|
|
audio_queue_send(Q_AUDIO_REMAKE_AUDIO_BUFFER, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PLAY_FREQ */
|
|
|
|
|
2013-05-31 06:41:02 +00:00
|
|
|
unsigned int playback_status(void)
|
|
|
|
{
|
|
|
|
return play_status;
|
|
|
|
}
|
2006-09-01 07:59:31 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** -- Startup -- **/
|
2013-06-30 02:19:59 +00:00
|
|
|
void INIT_ATTR playback_init(void)
|
2007-03-09 12:30:14 +00:00
|
|
|
{
|
2013-05-31 06:41:02 +00:00
|
|
|
logf("playback: initializing");
|
2008-03-25 02:34:12 +00:00
|
|
|
|
2012-05-02 21:22:28 +00:00
|
|
|
/* Initialize the track buffering system */
|
2013-05-31 06:41:02 +00:00
|
|
|
mutex_init(&id3_mutex);
|
2012-05-02 21:22:28 +00:00
|
|
|
track_list_init();
|
|
|
|
buffering_init();
|
2013-05-23 17:58:51 +00:00
|
|
|
pcmbuf_update_frequency();
|
2009-11-10 03:46:08 +00:00
|
|
|
#ifdef HAVE_CROSSFADE
|
2007-03-19 22:04:17 +00:00
|
|
|
/* Set crossfade setting for next buffer init which should be about... */
|
2009-11-05 21:59:36 +00:00
|
|
|
pcmbuf_request_crossfade_enable(global_settings.crossfade);
|
2009-11-10 03:46:08 +00:00
|
|
|
#endif
|
2008-10-07 19:37:33 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
2007-03-09 12:30:14 +00:00
|
|
|
audio_set_buffer_margin(global_settings.buffer_margin);
|
2007-08-01 08:50:44 +00:00
|
|
|
#endif
|
2009-10-31 19:17:36 +00:00
|
|
|
}
|