diff options
author | waker <wakeroid@gmail.com> | 2012-08-02 20:20:10 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-08-02 20:20:10 +0200 |
commit | e373d25a2f7198906cb16b529c216dc5d0556ae1 (patch) | |
tree | fb6cac55d345f66f44f3efc90a1d3e88193f9baa /plugins/alac | |
parent | 002d8c063496bbaa4d781c2812b1f28d28902c23 (diff) |
alac: implemented seeking
Diffstat (limited to 'plugins/alac')
-rw-r--r-- | plugins/alac/alac_plugin.c | 52 | ||||
-rw-r--r-- | plugins/alac/stream.c | 21 | ||||
-rw-r--r-- | plugins/alac/stream.h | 8 |
3 files changed, 45 insertions, 36 deletions
diff --git a/plugins/alac/alac_plugin.c b/plugins/alac/alac_plugin.c index fd0d33bb..aec38d8a 100644 --- a/plugins/alac/alac_plugin.c +++ b/plugins/alac/alac_plugin.c @@ -68,6 +68,7 @@ typedef struct { int startsample; int endsample; int current_frame; + int64_t dataoffs; } alacplug_info_t; // allocate codec control structure @@ -155,13 +156,14 @@ alacplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) { return -1; } - info->stream = stream_create_file (info->file, 1); + info->stream = stream_create_file (info->file, 1, info->junk); if (!qtmovie_read(info->stream, &info->demux_res)) { if (!info->demux_res.format_read || info->demux_res.format != MAKEFOURCC('a','l','a','c')) { return -1; } } + info->dataoffs = deadbeef->ftell (info->file); info->alac = create_alac(info->demux_res.sample_size, info->demux_res.num_channels); alac_set_info(info->alac, info->demux_res.codecdata); @@ -293,37 +295,39 @@ alacplug_read (DB_fileinfo_t *_info, char *bytes, int size) { static int alacplug_seek_sample (DB_fileinfo_t *_info, int sample) { - return 0; -#if 0 alacplug_info_t *info = (alacplug_info_t *)_info; - sample += info->startsample; - if (info->mp4file) { - int scale = _info->fmt.samplerate / mp4ff_time_scale (info->mp4file, info->mp4track) * info->mp4framesize; - info->mp4sample = sample / scale; - info->skipsamples = sample - info->mp4sample * scale; - } - else { - int skip = deadbeef->junk_get_leading_size (info->file); - if (skip >= 0) { - deadbeef->fseek (info->file, skip, SEEK_SET); - } - else { - deadbeef->fseek (info->file, 0, SEEK_SET); - } + int totalsamples = 0; + int64_t seekpos = 0; + int i; + for (i = 0; i < info->demux_res.num_sample_byte_sizes; i++) + { + unsigned int thissample_duration = 0; + unsigned int thissample_bytesize = 0; - int res = seek_raw_aac (info, sample); - if (res < 0) { - return -1; + get_sample_info(&info->demux_res, i, &thissample_duration, + &thissample_bytesize); + + if (totalsamples + thissample_duration > sample) { + info->skipsamples = sample - totalsamples; + break; } - info->skipsamples = res; + totalsamples += thissample_duration; + seekpos += info->demux_res.sample_byte_size[i]; } - info->remaining = 0; + + if (i == info->demux_res.num_sample_byte_sizes) { + return -1; + } + + + deadbeef->fseek(info->file, info->dataoffs + seekpos, SEEK_SET); + + info->current_frame = i; info->out_remaining = 0; info->currentsample = sample; _info->readpos = (float)(info->currentsample - info->startsample) / _info->fmt.samplerate; return 0; -#endif } static int @@ -459,7 +463,7 @@ alacplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { float duration = -1; - stream = stream_create_file (fp, 1); + stream = stream_create_file (fp, 1, info.junk); if (!stream) { trace ("alac: stream_create_file failed\n"); goto error; diff --git a/plugins/alac/stream.c b/plugins/alac/stream.c index 4976a539..0c99a32b 100644 --- a/plugins/alac/stream.c +++ b/plugins/alac/stream.c @@ -58,6 +58,7 @@ struct stream_tTAG { DB_FILE *f; int bigendian; int eof; + int64_t junk_offset; }; void stream_read(stream_t *stream, size_t size, void *buf) @@ -133,9 +134,9 @@ uint8_t stream_read_uint8(stream_t *stream) } -void stream_skip(stream_t *stream, size_t skip) +void stream_skip(stream_t *stream, int64_t skip) { - if (deadbeef->fseek(stream->f, (long)skip, SEEK_CUR) == 0) return; + if (deadbeef->fseek(stream->f, skip, SEEK_CUR) == 0) return; if (errno == ESPIPE) { char *buffer = malloc(skip); @@ -149,18 +150,21 @@ int stream_eof(stream_t *stream) return stream->eof; } -long stream_tell(stream_t *stream) +int64_t stream_tell(stream_t *stream) { - return deadbeef->ftell(stream->f); /* returns -1 on error */ + int64_t res = deadbeef->ftell(stream->f); /* returns -1 on error */ + if (res < 0) { + return res; + } + return res - stream->junk_offset; } -int stream_setpos(stream_t *stream, long pos) +int64_t stream_setpos(stream_t *stream, int64_t pos) { - return deadbeef->fseek(stream->f, pos, SEEK_SET); + return deadbeef->fseek(stream->f, pos + stream->junk_offset, SEEK_SET); } -stream_t *stream_create_file(DB_FILE *file, - int bigendian) +stream_t *stream_create_file(DB_FILE *file, int bigendian, int64_t junk_offset) { stream_t *new_stream; @@ -168,6 +172,7 @@ stream_t *stream_create_file(DB_FILE *file, new_stream->f = file; new_stream->bigendian = bigendian; new_stream->eof = 0; + new_stream->junk_offset = 0;//junk_offset; return new_stream; } diff --git a/plugins/alac/stream.h b/plugins/alac/stream.h index ae5881e4..2e32e4a7 100644 --- a/plugins/alac/stream.h +++ b/plugins/alac/stream.h @@ -24,15 +24,15 @@ uint16_t stream_read_uint16(stream_t *stream); int8_t stream_read_int8(stream_t *stream); uint8_t stream_read_uint8(stream_t *stream); -void stream_skip(stream_t *stream, size_t skip); +void stream_skip(stream_t *stream, int64_t skip); int stream_eof(stream_t *stream); -long stream_tell(stream_t *stream); -int stream_setpos(stream_t *stream, long pos); +int64_t stream_tell(stream_t *stream); +int64_t stream_setpos(stream_t *stream, int64_t pos); stream_t *stream_create_file(DB_FILE *file, - int bigendian); + int bigendian, int64_t junk_offset); void stream_destroy(stream_t *stream); #endif /* STREAM_H */ |