summaryrefslogtreecommitdiff
path: root/plugins/wma/libasf
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2013-01-25 21:36:05 +0100
committerGravatar waker <wakeroid@gmail.com>2013-01-25 21:36:05 +0100
commit1bceb2657b2e2e426c3fc1c96e668e8612fec490 (patch)
tree781534b414ffd6ec231a9737bea36f00193af07b /plugins/wma/libasf
parent66a3c3505fabf206db8aea7cfffbd064ba21fdb1 (diff)
wma: fixed seeking of VBR files; seeking is NOT sample-accurate
Diffstat (limited to 'plugins/wma/libasf')
-rw-r--r--plugins/wma/libasf/asf.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/plugins/wma/libasf/asf.c b/plugins/wma/libasf/asf.c
index ee07953a..90c8974f 100644
--- a/plugins/wma/libasf/asf.c
+++ b/plugins/wma/libasf/asf.c
@@ -29,8 +29,8 @@
#include "asf.h"
#include "../../deadbeef.h"
extern DB_functions_t *deadbeef;
-#define trace(...) { fprintf (stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf (stderr, __VA_ARGS__); }
+#define trace(fmt,...)
#define DEBUGF trace
/* Read an unaligned 32-bit little endian long from buffer. */
@@ -409,23 +409,26 @@ int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_o
int time, duration, delta, temp, count=0;
/*estimate packet number from bitrate*/
- int initial_packet = 0;//deadbeef->ftell (fp)/wfx->packet_size;
- printf ("initial_packet=%d\n", initial_packet);
+ int64_t datasize = deadbeef->fgetlength (fp) - first_frame_offset;
+
+ int initial_packet = (deadbeef->ftell (fp) - first_frame_offset) / wfx->packet_size;
int packet_num = (((int64_t)ms)*(wfx->bitrate>>3))/wfx->packet_size/1000;
- printf ("packet_num=%d (%d * %d / %d / 1000)\n", packet_num, ms, wfx->bitrate, wfx->packet_size);
- int last_packet = deadbeef->fgetlength (fp) / wfx->packet_size;
- printf ("last_packet=%d\n", last_packet);
+ int last_packet = datasize / wfx->packet_size;
if (packet_num > last_packet) {
packet_num = last_packet;
}
/*calculate byte address of the start of that packet*/
- int packet_offset = packet_num*wfx->packet_size;
- printf ("packet_offset=%d (%d*%d)\n", packet_offset, packet_num, wfx->packet_size);
+ int64_t packet_offset = packet_num*wfx->packet_size;
+ trace ("initial_packet: %d\n", initial_packet);
+ trace ("packet_num: %d\n", packet_num);
+ trace ("last_packet: %d\n", last_packet);
+ trace ("packet_offset: %lld\n", packet_offset);
/*seek to estimated packet*/
deadbeef->fseek (fp, first_frame_offset+packet_offset, SEEK_SET);
+ int64_t pos = deadbeef->ftell (fp);
temp = ms;
while (1)
{
@@ -446,8 +449,10 @@ int asf_seek(int ms, asf_waveformatex_t* wfx, DB_FILE *fp, int64_t first_frame_o
if ((time+duration>=ms && time<=ms) || count > 10) {
DEBUGF("Found our packet! Now at %d packet\n", packet_num);
+ deadbeef->fseek (fp, pos, SEEK_SET);
return time;
} else {
+ DEBUGF("Seek again\n", packet_num);
/*seek again*/
delta = ms-time;
/*estimate new packet number from bitrate and our current position*/