changeset 931:b6c95e2a14f4 trunk

[svn] - Implement seek support for files without a seektable
author ertzing
date Mon, 09 Apr 2007 11:12:20 -0700
parents 2f742d127b3e
children a5752784d87b
files ChangeLog src/flacng/plugin.c src/flacng/seekable_stream_callbacks.c
diffstat 3 files changed, 55 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 09 10:55:23 2007 -0700
+++ b/ChangeLog	Mon Apr 09 11:12:20 2007 -0700
@@ -1,3 +1,27 @@
+2007-04-09 17:55:23 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [1988]
+  - initial import of flacng from audacious-flacng-0.012
+  
+  trunk/configure.ac                           |   24 
+  trunk/mk/rules.mk.in                         |    5 
+  trunk/src/flacng/AUTHORS                     |   28 +
+  trunk/src/flacng/Makefile                    |   16 
+  trunk/src/flacng/README                      |  109 ++++
+  trunk/src/flacng/debug.h                     |   35 +
+  trunk/src/flacng/flac_compat112.h            |   35 +
+  trunk/src/flacng/flac_compat113.h            |    7 
+  trunk/src/flacng/flac_compat114.h            |    7 
+  trunk/src/flacng/flacng.h                    |   94 +++
+  trunk/src/flacng/plugin.c                    |  706 +++++++++++++++++++++++++++
+  trunk/src/flacng/plugin.h                    |   14 
+  trunk/src/flacng/seekable_stream_callbacks.c |  338 ++++++++++++
+  trunk/src/flacng/seekable_stream_callbacks.h |   35 +
+  trunk/src/flacng/tools.c                     |  478 ++++++++++++++++++
+  trunk/src/flacng/tools.h                     |   34 +
+  trunk/src/flacng/version.h                   |    6 
+  17 files changed, 1969 insertions(+), 2 deletions(-)
+
+
 2007-04-09 15:51:31 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [1986]
   - use C-style vectors (part 2)
--- a/src/flacng/plugin.c	Mon Apr 09 10:55:23 2007 -0700
+++ b/src/flacng/plugin.c	Mon Apr 09 11:12:20 2007 -0700
@@ -473,19 +473,15 @@
         if (-1 != seek_to) {
             _DEBUG("Seek requested to %d seconds", seek_to);
 
-            if (FALSE == main_info->stream.has_seektable) {
-                _ERROR("Stream does not have a seektable, can not seek!");
+            seek_sample = seek_to * main_info->stream.samplerate;
+            _DEBUG("Seek requested to sample %d", seek_sample);
+            if (FALSE == FLAC__stream_decoder_seek_absolute(main_decoder, seek_sample)) {
+                _ERROR("Could not seek to sample %d!", seek_sample);
             } else {
-                seek_sample = seek_to * main_info->stream.samplerate;
-                _DEBUG("Seek requested to sample %d", seek_sample);
-                if (FALSE == FLAC__stream_decoder_seek_absolute(main_decoder, seek_sample)) {
-                    _ERROR("Could not seek to sample %d!", seek_sample);
-                } else {
-                    /*
-                     * Flush the buffers
-                     */
-                    flac_ip.output->flush(seek_to * 1000);
-                }
+                /*
+                 * Flush the buffers
+                 */
+                flac_ip.output->flush(seek_to * 1000);
             }
             seek_to = -1;
         }
--- a/src/flacng/seekable_stream_callbacks.c	Mon Apr 09 10:55:23 2007 -0700
+++ b/src/flacng/seekable_stream_callbacks.c	Mon Apr 09 11:12:20 2007 -0700
@@ -115,7 +115,7 @@
     _DEBUG("Using callback_info %s", info->name);
 
     if (-1 == (position = vfs_ftell(info->input_stream))) {
-        fprintf(stderr, "Could not tell current position!");
+        _ERROR("Could not tell current position!");
         return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
     }
 
@@ -149,13 +149,34 @@
 
     callback_info* info;
     size_t size;
+    glong position;
 
     _ENTER;
 
     info = (callback_info*) client_data;
     _DEBUG("Using callback_info %s", info->name);
 
-    *stream_length = 0;
+    if (-1 == (position = vfs_ftell(info->input_stream))) {
+        _ERROR("Could not tell current position!");
+        _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
+    }
+
+    if (-1 == vfs_fseek(info->input_stream, 0, SEEK_END)) {
+        _ERROR("Could not seek to end of stream.");
+        _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
+    }
+
+    if (-1 == (*stream_length = vfs_ftell(info->input_stream))) {
+        _ERROR("Could not tell position at end of stream!");
+        _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
+    }
+
+    if (-1 == vfs_fseek(info->input_stream, position, SEEK_SET)) {
+        _ERROR("Could not reset stream position. We're probably in trouble now.");
+        _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
+    }
+
+    _DEBUG("Stream length is %d bytes", *stream_length);
 
     _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
 }