comparison src/flacng/seekable_stream_callbacks.c @ 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 1f78881a5f3c
comparison
equal deleted inserted replaced
930:2f742d127b3e 931:b6c95e2a14f4
113 113
114 info = (callback_info*) client_data; 114 info = (callback_info*) client_data;
115 _DEBUG("Using callback_info %s", info->name); 115 _DEBUG("Using callback_info %s", info->name);
116 116
117 if (-1 == (position = vfs_ftell(info->input_stream))) { 117 if (-1 == (position = vfs_ftell(info->input_stream))) {
118 fprintf(stderr, "Could not tell current position!"); 118 _ERROR("Could not tell current position!");
119 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; 119 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
120 } 120 }
121 121
122 _DEBUG("Current position: %d", position); 122 _DEBUG("Current position: %d", position);
123 123
147 147
148 FLAC__StreamDecoderLengthStatus length_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) { 148 FLAC__StreamDecoderLengthStatus length_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) {
149 149
150 callback_info* info; 150 callback_info* info;
151 size_t size; 151 size_t size;
152 152 glong position;
153 _ENTER; 153
154 154 _ENTER;
155 info = (callback_info*) client_data; 155
156 _DEBUG("Using callback_info %s", info->name); 156 info = (callback_info*) client_data;
157 157 _DEBUG("Using callback_info %s", info->name);
158 *stream_length = 0; 158
159 if (-1 == (position = vfs_ftell(info->input_stream))) {
160 _ERROR("Could not tell current position!");
161 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
162 }
163
164 if (-1 == vfs_fseek(info->input_stream, 0, SEEK_END)) {
165 _ERROR("Could not seek to end of stream.");
166 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
167 }
168
169 if (-1 == (*stream_length = vfs_ftell(info->input_stream))) {
170 _ERROR("Could not tell position at end of stream!");
171 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
172 }
173
174 if (-1 == vfs_fseek(info->input_stream, position, SEEK_SET)) {
175 _ERROR("Could not reset stream position. We're probably in trouble now.");
176 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
177 }
178
179 _DEBUG("Stream length is %d bytes", *stream_length);
159 180
160 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_OK; 181 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
161 } 182 }
162 183
163 /* --- */ 184 /* --- */