~ubuntu-branches/ubuntu/raring/flac/raring

« back to all changes in this revision

Viewing changes to src/metaflac/operations_shorthand_seektable.c

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* metaflac - Command-line FLAC metadata editor
2
 
 * Copyright (C) 2001,2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
16
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
17
 */
18
18
 
 
19
#if HAVE_CONFIG_H
 
20
#  include <config.h>
 
21
#endif
 
22
 
19
23
#include "utils.h"
20
24
#include "FLAC/assert.h"
21
 
#include "FLAC/file_decoder.h"
 
25
#include "FLAC/stream_decoder.h"
22
26
#include "FLAC/metadata.h"
23
27
#include "share/grabbag.h"
24
28
 
99
103
        FLAC__StreamDecoderErrorStatus error_status;
100
104
} ClientData;
101
105
 
102
 
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
 
106
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
103
107
{
104
108
        ClientData *cd = (ClientData*)client_data;
105
109
 
106
110
        (void)buffer;
107
111
        FLAC__ASSERT(0 != cd);
108
112
 
109
 
        if(!cd->error_occurred && cd->seektable_template->num_points > 0) {
 
113
        if(!cd->error_occurred) {
110
114
                const unsigned blocksize = frame->header.blocksize;
111
115
                const FLAC__uint64 frame_first_sample = cd->samples_written;
112
116
                const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
134
138
                        }
135
139
                }
136
140
                cd->samples_written += blocksize;
137
 
                if(!FLAC__file_decoder_get_decode_position(decoder, &cd->last_offset))
 
141
                if(!FLAC__stream_decoder_get_decode_position(decoder, &cd->last_offset))
138
142
                        return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
139
143
                return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
140
144
        }
142
146
                return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
143
147
}
144
148
 
145
 
static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
146
 
{
147
 
        (void)decoder, (void)metadata, (void)client_data;
148
 
        FLAC__ASSERT(0); /* we asked to skip all metadata */
149
 
}
150
 
 
151
 
static void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
 
149
static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
152
150
{
153
151
        ClientData *cd = (ClientData*)client_data;
154
152
 
163
161
 
164
162
FLAC__bool populate_seekpoint_values(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write)
165
163
{
166
 
        FLAC__FileDecoder *decoder;
 
164
        FLAC__StreamDecoder *decoder;
167
165
        ClientData client_data;
168
166
        FLAC__bool ok = true;
169
167
 
176
174
        client_data.first_seekpoint_to_check = 0;
177
175
        client_data.error_occurred = false;
178
176
 
179
 
        decoder = FLAC__file_decoder_new();
 
177
        decoder = FLAC__stream_decoder_new();
180
178
 
181
179
        if(0 == decoder) {
182
180
                fprintf(stderr, "%s: ERROR (--add-seekpoint) creating the decoder instance\n", filename);
183
181
                return false;
184
182
        }
185
183
 
186
 
        FLAC__file_decoder_set_md5_checking(decoder, false);
187
 
        FLAC__file_decoder_set_filename(decoder, filename);
188
 
        FLAC__file_decoder_set_metadata_ignore_all(decoder);
189
 
        FLAC__file_decoder_set_write_callback(decoder, write_callback_);
190
 
        FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback_);
191
 
        FLAC__file_decoder_set_error_callback(decoder, error_callback_);
192
 
        FLAC__file_decoder_set_client_data(decoder, &client_data);
193
 
 
194
 
        if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) {
195
 
                fprintf(stderr, "%s: ERROR (--add-seekpoint) initializing the decoder instance (%s)\n", filename, FLAC__file_decoder_get_resolved_state_string(decoder));
196
 
                ok = false;
197
 
        }
198
 
 
199
 
        if(ok && !FLAC__file_decoder_process_until_end_of_metadata(decoder)) {
200
 
                fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__file_decoder_get_resolved_state_string(decoder));
201
 
                ok = false;
202
 
        }
203
 
 
204
 
        if(ok && !FLAC__file_decoder_get_decode_position(decoder, &client_data.audio_offset)) {
 
184
        FLAC__stream_decoder_set_md5_checking(decoder, false);
 
185
        FLAC__stream_decoder_set_metadata_ignore_all(decoder);
 
186
 
 
187
        if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, /*metadata_callback=*/0, error_callback_, &client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
 
188
                fprintf(stderr, "%s: ERROR (--add-seekpoint) initializing the decoder instance (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
 
189
                ok = false;
 
190
        }
 
191
 
 
192
        if(ok && !FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
 
193
                fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
 
194
                ok = false;
 
195
        }
 
196
 
 
197
        if(ok && !FLAC__stream_decoder_get_decode_position(decoder, &client_data.audio_offset)) {
205
198
                fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file\n", filename);
206
199
                ok = false;
207
200
        }
208
201
        client_data.last_offset = client_data.audio_offset;
209
202
 
210
 
        if(ok && !FLAC__file_decoder_process_until_end_of_file(decoder)) {
211
 
                fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__file_decoder_get_resolved_state_string(decoder));
 
203
        if(ok && !FLAC__stream_decoder_process_until_end_of_stream(decoder)) {
 
204
                fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
212
205
                ok = false;
213
206
        }
214
207
 
218
211
        }
219
212
 
220
213
        *needs_write = true;
221
 
        FLAC__file_decoder_delete(decoder);
 
214
        FLAC__stream_decoder_delete(decoder);
222
215
        return ok;
223
216
}