From 2b2ab15d0022b302e651318ad45aa6a85889a864 Mon Sep 17 00:00:00 2001 From: waker Date: Fri, 25 Jan 2013 22:07:00 +0100 Subject: wma: seeking WIP --- plugins/wma/libasf/asf.c | 12 +++++++----- plugins/wma/libasf/asf.h | 2 +- plugins/wma/wma_plugin.c | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'plugins/wma') diff --git a/plugins/wma/libasf/asf.c b/plugins/wma/libasf/asf.c index 90c8974f..595a27ac 100644 --- a/plugins/wma/libasf/asf.c +++ b/plugins/wma/libasf/asf.c @@ -404,7 +404,7 @@ int asf_get_timestamp(int *duration, DB_FILE *fp) } /*entry point for seeks*/ -int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_offset) +int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_offset, int *skip_ms) { int time, duration, delta, temp, count=0; @@ -437,22 +437,24 @@ int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_o /*check the time stamp of our packet*/ time = asf_get_timestamp(&duration, fp); - DEBUGF("time %d ms with duration %d\n", time, duration); +// DEBUGF("time %d ms with duration %d\n", time, duration); if (time < 0) { /*unknown error, try to recover*/ DEBUGF("UKNOWN SEEK ERROR\n"); deadbeef->fseek (fp, first_frame_offset+initial_packet*wfx->packet_size, SEEK_SET); + *skip_ms = 0; /*seek failed so return time stamp of the initial packet*/ - return asf_get_timestamp(&duration, fp); + return -1;//asf_get_timestamp(&duration, fp); } + DEBUGF("time: %d, duration: %d (ms: %d)\n", time, duration, ms); if ((time+duration>=ms && time<=ms) || count > 10) { - DEBUGF("Found our packet! Now at %d packet\n", packet_num); + DEBUGF("Found our packet! Now at %d packet, time %d, requested %d\n", packet_num, time, ms); deadbeef->fseek (fp, pos, SEEK_SET); + *skip_ms = ms - time; return time; } else { - DEBUGF("Seek again\n", packet_num); /*seek again*/ delta = ms-time; /*estimate new packet number from bitrate and our current position*/ diff --git a/plugins/wma/libasf/asf.h b/plugins/wma/libasf/asf.h index cb96fed2..f49d38d1 100644 --- a/plugins/wma/libasf/asf.h +++ b/plugins/wma/libasf/asf.h @@ -49,6 +49,6 @@ int asf_read_packet(uint8_t** audiobuf, int* audiobufsize, int* packetlength, int asf_get_timestamp(int *duration, DB_FILE *fp); -int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_offset); +int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_offset, int *skip_ms); #endif /* _ASF_H */ diff --git a/plugins/wma/wma_plugin.c b/plugins/wma/wma_plugin.c index 6a141dd1..923b384a 100644 --- a/plugins/wma/wma_plugin.c +++ b/plugins/wma/wma_plugin.c @@ -39,8 +39,8 @@ #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) static DB_decoder_t plugin; DB_functions_t *deadbeef; @@ -321,9 +321,17 @@ wmaplug_seek_sample (DB_fileinfo_t *_info, int sample) { info->skipsamples = sample - frame * info->wmadec.frame_len * n_subframes; info->currentsample = sample; #else - int res = asf_seek ((int64_t)sample * 1000 / info->wfx.rate, &info->wfx, info->fp, info->first_frame_offset); - info->skipsamples = 0; - info->currentsample = (int64_t)res * info->wfx.rate / 1000; + int skip_ms; + int res = asf_seek ((int64_t)sample * 1000 / info->wfx.rate, &info->wfx, info->fp, info->first_frame_offset, &skip_ms); + if (res < 0) { + info->skipsamples = 0; + info->currentsample = 0; + } + else { + printf ("skip_samples: %d\n", (int)((int64_t)skip_ms * info->wfx.rate / 1000)); + info->skipsamples = (int64_t)skip_ms * info->wfx.rate / 1000; + info->currentsample = sample; + } #endif -- cgit v1.2.3