forked from len0rd/rockbox
Patch #1235763 by Ryan Jackson - Resume/bookmark support for Vorbis
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7098 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b1ecc8319d
commit
c4b7c671f9
2 changed files with 100 additions and 74 deletions
|
@ -25,6 +25,8 @@
|
||||||
#include "dsp.h"
|
#include "dsp.h"
|
||||||
#include "lib/codeclib.h"
|
#include "lib/codeclib.h"
|
||||||
|
|
||||||
|
#define TEST_RESUME
|
||||||
|
|
||||||
static struct codec_api* rb;
|
static struct codec_api* rb;
|
||||||
|
|
||||||
/* Some standard functions and variables needed by Tremor */
|
/* Some standard functions and variables needed by Tremor */
|
||||||
|
@ -88,6 +90,38 @@ long tell_handler(void *datasource)
|
||||||
return rb->curpos;
|
return rb->curpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This sets the DSP parameters based on the current logical bitstream
|
||||||
|
* (sampling rate, number of channels, etc). It also tries to guess
|
||||||
|
* reasonable buffer parameters based on the current quality setting.
|
||||||
|
*/
|
||||||
|
bool vorbis_set_codec_parameters(OggVorbis_File *vf)
|
||||||
|
{
|
||||||
|
vorbis_info* vi;
|
||||||
|
|
||||||
|
vi=ov_info(vf,-1);
|
||||||
|
|
||||||
|
if (vi==NULL) {
|
||||||
|
//rb->splash(HZ*2, true, "Vorbis Error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rb->id3->frequency != NATIVE_FREQUENCY) {
|
||||||
|
rb->configure(CODEC_DSP_ENABLE, (bool *)true);
|
||||||
|
} else {
|
||||||
|
rb->configure(CODEC_DSP_ENABLE, (bool *)false);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb->configure(DSP_SET_FREQUENCY, (int *)rb->id3->frequency);
|
||||||
|
|
||||||
|
if (vi->channels == 2) {
|
||||||
|
rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED);
|
||||||
|
} else if (vi->channels == 1) {
|
||||||
|
rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_IRAM
|
#ifdef USE_IRAM
|
||||||
extern char iramcopy[];
|
extern char iramcopy[];
|
||||||
extern char iramstart[];
|
extern char iramstart[];
|
||||||
|
@ -103,17 +137,16 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
{
|
{
|
||||||
ov_callbacks callbacks;
|
ov_callbacks callbacks;
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
vorbis_info* vi;
|
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
long n;
|
long n;
|
||||||
int current_section;
|
int current_section;
|
||||||
|
int previous_section = -1;
|
||||||
int eof;
|
int eof;
|
||||||
ogg_int64_t vf_offsets[2];
|
ogg_int64_t vf_offsets[2];
|
||||||
ogg_int64_t vf_dataoffsets;
|
ogg_int64_t vf_dataoffsets;
|
||||||
ogg_uint32_t vf_serialnos;
|
ogg_uint32_t vf_serialnos;
|
||||||
ogg_int64_t vf_pcmlengths[2];
|
ogg_int64_t vf_pcmlengths[2];
|
||||||
int current_stereo_mode = -1;
|
|
||||||
|
|
||||||
TEST_CODEC_API(api);
|
TEST_CODEC_API(api);
|
||||||
|
|
||||||
|
@ -125,12 +158,20 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
|
|
||||||
rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*64));
|
|
||||||
|
|
||||||
rb->configure(DSP_DITHER, (bool *)false);
|
rb->configure(DSP_DITHER, (bool *)false);
|
||||||
rb->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
|
rb->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
|
||||||
|
|
||||||
|
/* Note: These are sane defaults for these values. Perhaps
|
||||||
|
* they should be set differently based on quality setting
|
||||||
|
*/
|
||||||
|
rb->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
|
||||||
|
|
||||||
|
/* The chunk size below is magic. If set any lower, resume
|
||||||
|
* doesn't work properly (ov_raw_seek() does the wrong thing).
|
||||||
|
*/
|
||||||
|
rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
|
||||||
|
|
||||||
|
|
||||||
/* We need to flush reserver memory every track load. */
|
/* We need to flush reserver memory every track load. */
|
||||||
next_track:
|
next_track:
|
||||||
if (codec_init(rb)) {
|
if (codec_init(rb)) {
|
||||||
|
@ -140,13 +181,6 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
while (!*rb->taginfo_ready && !rb->stop_codec)
|
while (!*rb->taginfo_ready && !rb->stop_codec)
|
||||||
rb->yield();
|
rb->yield();
|
||||||
|
|
||||||
if (rb->id3->frequency != NATIVE_FREQUENCY) {
|
|
||||||
rb->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
|
|
||||||
rb->configure(CODEC_DSP_ENABLE, (bool *)true);
|
|
||||||
} else {
|
|
||||||
rb->configure(CODEC_DSP_ENABLE, (bool *)false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a decoder instance */
|
/* Create a decoder instance */
|
||||||
callbacks.read_func=read_handler;
|
callbacks.read_func=read_handler;
|
||||||
callbacks.seek_func=initial_seek_handler;
|
callbacks.seek_func=initial_seek_handler;
|
||||||
|
@ -158,7 +192,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
/* If the non-seekable open was successful, we need to supply the missing
|
/* If the non-seekable open was successful, we need to supply the missing
|
||||||
* data to make it seekable. This is a hack, but it's reasonable since we
|
* data to make it seekable. This is a hack, but it's reasonable since we
|
||||||
* don't want to read the whole file into the buffer before we start
|
* don't want to run the whole file through the buffer before we start
|
||||||
* playing. Using Tremor's seekable open routine would cause us to do
|
* playing. Using Tremor's seekable open routine would cause us to do
|
||||||
* this, so we pretend not to be seekable at first. Then we fill in the
|
* this, so we pretend not to be seekable at first. Then we fill in the
|
||||||
* missing fields of vf with 1) information in rb->id3, and 2) info
|
* missing fields of vf with 1) information in rb->id3, and 2) info
|
||||||
|
@ -169,8 +203,6 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
* get here.
|
* get here.
|
||||||
*/
|
*/
|
||||||
if ( !error ) {
|
if ( !error ) {
|
||||||
//rb->logf("no error");
|
|
||||||
/* FIXME Should these be dynamically allocated? */
|
|
||||||
vf.offsets = vf_offsets;
|
vf.offsets = vf_offsets;
|
||||||
vf.dataoffsets = &vf_dataoffsets;
|
vf.dataoffsets = &vf_dataoffsets;
|
||||||
vf.serialnos = &vf_serialnos;
|
vf.serialnos = &vf_serialnos;
|
||||||
|
@ -184,39 +216,19 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
vf.serialnos[0] = vf.current_serialno;
|
vf.serialnos[0] = vf.current_serialno;
|
||||||
vf.callbacks.seek_func=seek_handler;
|
vf.callbacks.seek_func=seek_handler;
|
||||||
vf.seekable = 1;
|
vf.seekable = 1;
|
||||||
vf.offset = 58; /* length of Ogg header */
|
|
||||||
vf.end = rb->id3->filesize;
|
vf.end = rb->id3->filesize;
|
||||||
vf.ready_state = OPENED;
|
vf.ready_state = OPENED;
|
||||||
vf.links = 1;
|
vf.links = 1;
|
||||||
|
|
||||||
/*if(ov_raw_seek(&vf,0)){
|
|
||||||
rb->logf("seek err");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//rb->logf("ov_open: %d", error);
|
//rb->logf("ov_open: %d", error);
|
||||||
}
|
|
||||||
|
|
||||||
vi=ov_info(&vf,-1);
|
|
||||||
|
|
||||||
if (vi==NULL) {
|
|
||||||
//rb->splash(HZ*2, true, "Vorbis Error");
|
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->configure(DSP_SET_FREQUENCY, (int *)rb->id3->frequency);
|
if ( rb->id3->offset ) {
|
||||||
|
rb->advance_buffer(rb->id3->offset);
|
||||||
if (vi->channels == 2) {
|
ov_raw_seek(&vf,rb->id3->offset);
|
||||||
if (current_stereo_mode != STEREO_INTERLEAVED) {
|
rb->id3->offset = ov_raw_tell(&vf);
|
||||||
rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED);
|
rb->set_elapsed(ov_time_tell(&vf));
|
||||||
current_stereo_mode = STEREO_INTERLEAVED;
|
|
||||||
}
|
|
||||||
} else if (vi->channels == 1) {
|
|
||||||
if (current_stereo_mode != STEREO_MONO) {
|
|
||||||
rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
|
|
||||||
current_stereo_mode = STEREO_MONO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eof=0;
|
eof=0;
|
||||||
|
@ -236,6 +248,15 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
/* Read host-endian signed 16 bit PCM samples */
|
/* Read host-endian signed 16 bit PCM samples */
|
||||||
n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),¤t_section);
|
n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),¤t_section);
|
||||||
|
|
||||||
|
/* Change DSP and buffer settings for this bitstream */
|
||||||
|
if ( current_section != previous_section ) {
|
||||||
|
if (!vorbis_set_codec_parameters(&vf)) {
|
||||||
|
return CODEC_ERROR;
|
||||||
|
} else {
|
||||||
|
previous_section = current_section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (n==0) {
|
if (n==0) {
|
||||||
eof=1;
|
eof=1;
|
||||||
} else if (n < 0) {
|
} else if (n < 0) {
|
||||||
|
@ -251,6 +272,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !rb->seek_time ) {
|
if ( !rb->seek_time ) {
|
||||||
|
rb->id3->offset = ov_raw_tell(&vf);
|
||||||
rb->set_elapsed(ov_time_tell(&vf));
|
rb->set_elapsed(ov_time_tell(&vf));
|
||||||
rb->yield();
|
rb->yield();
|
||||||
}
|
}
|
||||||
|
@ -269,3 +291,4 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
return CODEC_OK;
|
return CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -962,6 +962,9 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
|
||||||
ci.curpos = offset;
|
ci.curpos = offset;
|
||||||
tracks[track_widx].start_pos = offset;
|
tracks[track_widx].start_pos = offset;
|
||||||
break;
|
break;
|
||||||
|
case AFMT_OGG_VORBIS:
|
||||||
|
tracks[track_widx].id3.offset = offset;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue