~ubuntu-branches/debian/sid/vorbis-tools/sid

« back to all changes in this revision

Viewing changes to vorbiscomment/vcedit.c

  • Committer: Bazaar Package Importer
  • Author(s): Jesus Climent
  • Date: 2005-04-10 09:22:24 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050410092224-xtukpa3qghghhjje
Tags: 1.0.1-1.3
* Authorized NMU.
* Modified alsa to mention alsa09 (although the device might be nowadays
  alsa, back, since alsa1.0 has been already released). (Closes: #258286)
* Modified the manpage/help message for vorbiscomment to make it a bit more
  userfiendly: Closes: #252531.
* Added oggdec to the long description field, so that it triggers apt-cache
  searches: Closes: #274894.
* Typos in manpages: Closes: #302150.
* Escaped dashes in manpage: Closes: #264365.
* Quiet option is actually with -Q, not -q (Closes: #211289) Reported
  upstream but patched for Debian.
* Change input.wav with inputfile, since we accept flac-formated files:
  Closes: #262509.
* Translation bits:
  * Updated translation hu.po: Closes: #272037.
  * French translation correction: Encodage -> Codage (Closes: #248431).
  * debian/rules: remove .gmo's to avoid clash with uploaded tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This program is licensed under the GNU Library General Public License, version 2,
2
2
 * a copy of which is included with this program (LICENCE.LGPL).
3
3
 *
4
 
 * (c) 2000-2001 Michael Smith <msmith@labyrinth.net.au>
 
4
 * (c) 2000-2001 Michael Smith <msmith@xiph.org>
5
5
 *
6
6
 *
7
7
 * Comment editing backend, suitable for use by nice frontend interfaces.
8
8
 *
9
 
 * last modified: $Id: vcedit.c,v 1.16 2001/12/19 02:53:00 volsung Exp $
 
9
 * last modified: $Id: vcedit.c,v 1.23 2003/09/03 07:58:05 calc Exp $
10
10
 */
11
11
 
12
12
#include <stdio.h>
13
13
#include <stdlib.h>
14
14
#include <string.h>
 
15
#include <errno.h>
15
16
#include <ogg/ogg.h>
16
17
#include <vorbis/codec.h>
17
18
 
18
19
#include "vcedit.h"
 
20
#include "i18n.h"
 
21
 
19
22
 
20
23
#define CHUNKSIZE 4096
21
24
 
39
42
 
40
43
static void vcedit_clear_internals(vcedit_state *state)
41
44
{
 
45
    char *tmp;
42
46
        if(state->vc)
43
47
        {
44
48
                vorbis_comment_clear(state->vc);
45
49
                free(state->vc);
46
 
                state->vc=NULL;
47
50
        }
48
51
        if(state->os)
49
52
        {
50
53
                ogg_stream_clear(state->os);
51
54
                free(state->os);
52
 
                state->os=NULL;
53
55
        }
54
56
        if(state->oy)
55
57
        {
56
58
                ogg_sync_clear(state->oy);
57
59
                free(state->oy);
58
 
                state->oy=NULL;
59
60
        }
60
61
        if(state->vendor)
61
 
        {
62
62
                free(state->vendor);
63
 
                state->vendor=NULL;
64
 
        }
 
63
    if(state->mainbuf)
 
64
        free(state->mainbuf);
 
65
    if(state->bookbuf)
 
66
        free(state->bookbuf);
 
67
    if(state->vi) {
 
68
        vorbis_info_clear(state->vi);
 
69
        free(state->vi);
 
70
    }
 
71
 
 
72
    tmp = state->lasterror;
 
73
    memset(state, 0, sizeof(*state));
 
74
    state->lasterror = tmp;
65
75
}
66
76
 
67
77
void vcedit_clear(vcedit_state *state)
122
132
        op->e_o_s=0;
123
133
        op->granulepos=0;
124
134
 
 
135
        oggpack_writeclear(&opb);
125
136
        return 0;
126
137
}
127
138
 
128
139
static int _blocksize(vcedit_state *s, ogg_packet *p)
129
140
{
130
 
        int this = vorbis_packet_blocksize(&s->vi, p);
 
141
        int this = vorbis_packet_blocksize(s->vi, p);
131
142
        int ret = (this + s->prevW)/4;
132
143
 
133
144
        if(!s->prevW)
188
199
 
189
200
        char *buffer;
190
201
        int bytes,i;
 
202
    int chunks = 0;
191
203
        ogg_packet *header;
192
204
        ogg_packet      header_main;
193
205
        ogg_packet  header_comments;
201
213
        state->oy = malloc(sizeof(ogg_sync_state));
202
214
        ogg_sync_init(state->oy);
203
215
 
204
 
        buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
205
 
        bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
206
 
 
207
 
        ogg_sync_wrote(state->oy, bytes);
208
 
 
209
 
        if(ogg_sync_pageout(state->oy, &og) != 1)
210
 
        {
211
 
                if(bytes<CHUNKSIZE)
212
 
                        state->lasterror = "Input truncated or empty.";
213
 
                else
214
 
                        state->lasterror = "Input is not an Ogg bitstream.";
215
 
                goto err;
216
 
        }
 
216
    while(1)
 
217
    {
 
218
        buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
 
219
            bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
 
220
 
 
221
        ogg_sync_wrote(state->oy, bytes);
 
222
 
 
223
        if(ogg_sync_pageout(state->oy, &og) == 1)
 
224
            break;
 
225
 
 
226
        if(chunks++ >= 10) /* Bail if we don't find data in the first 40 kB */
 
227
        {
 
228
                    if(bytes<CHUNKSIZE)
 
229
                            state->lasterror = _("Input truncated or empty.");
 
230
                else
 
231
                        state->lasterror = _("Input is not an Ogg bitstream.");
 
232
                    goto err;
 
233
        }
 
234
    }
217
235
 
218
236
        state->serial = ogg_page_serialno(&og);
219
237
 
220
238
        state->os = malloc(sizeof(ogg_stream_state));
221
239
        ogg_stream_init(state->os, state->serial);
222
240
 
223
 
        vorbis_info_init(&state->vi);
 
241
    state->vi = malloc(sizeof(vorbis_info));
 
242
        vorbis_info_init(state->vi);
224
243
 
225
244
        state->vc = malloc(sizeof(vorbis_comment));
226
245
        vorbis_comment_init(state->vc);
227
246
 
228
247
        if(ogg_stream_pagein(state->os, &og) < 0)
229
248
        {
230
 
                state->lasterror = "Error reading first page of Ogg bitstream.";
 
249
                state->lasterror = _("Error reading first page of Ogg bitstream.");
231
250
                goto err;
232
251
        }
233
252
 
234
253
        if(ogg_stream_packetout(state->os, &header_main) != 1)
235
254
        {
236
 
                state->lasterror = "Error reading initial header packet.";
 
255
                state->lasterror = _("Error reading initial header packet.");
237
256
                goto err;
238
257
        }
239
258
 
240
 
        if(vorbis_synthesis_headerin(&state->vi, state->vc, &header_main) < 0)
 
259
        if(vorbis_synthesis_headerin(state->vi, state->vc, &header_main) < 0)
241
260
        {
242
 
                state->lasterror = "Ogg bitstream does not contain vorbis data.";
 
261
                state->lasterror = _("Ogg bitstream does not contain vorbis data.");
243
262
                goto err;
244
263
        }
245
264
 
262
281
                                        if(result == 0) break;
263
282
                                        if(result == -1)
264
283
                                        {
265
 
                                                state->lasterror = "Corrupt secondary header.";
 
284
                                                state->lasterror = _("Corrupt secondary header.");
266
285
                                                goto err;
267
286
                                        }
268
 
                                        vorbis_synthesis_headerin(&state->vi, state->vc, header);
 
287
                                        vorbis_synthesis_headerin(state->vi, state->vc, header);
269
288
                                        if(i==1)
270
289
                                        {
271
290
                                                state->booklen = header->bytes;
283
302
                bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
284
303
                if(bytes == 0 && i < 2)
285
304
                {
286
 
                        state->lasterror = "EOF before end of vorbis headers.";
 
305
                        state->lasterror = _("EOF before end of vorbis headers.");
287
306
                        goto err;
288
307
                }
289
308
                ogg_sync_wrote(state->oy, bytes);
415
434
                        goto cleanup;
416
435
        }
417
436
 
418
 
        /* FIXME: freeing this here probably leaks memory */
419
 
        /* Done with this, now */
420
 
        vorbis_info_clear(&state->vi);
421
 
 
422
437
        if (state->extrapage)
423
438
        {
424
439
                if(state->write(ogin.header,1,ogin.header_len,
437
452
                while(1)
438
453
                {
439
454
                        result = ogg_sync_pageout(state->oy, &ogout);
440
 
                        if(result==0) break;
 
455
                        if(result==0)
 
456
                break;
441
457
                        if(result<0)
442
 
                                state->lasterror = "Corrupt or missing data, continuing...";
 
458
                                state->lasterror = _("Corrupt or missing data, continuing...");
443
459
                        else
444
460
                        {
445
461
                                /* Don't bother going through the rest, we can just 
446
462
                                 * write the page out now */
447
463
                                if(state->write(ogout.header,1,ogout.header_len, 
448
 
                                                out) != (size_t) ogout.header_len)
 
464
                                                out) != (size_t) ogout.header_len) {
449
465
                                        goto cleanup;
 
466
                }
450
467
                                if(state->write(ogout.body,1,ogout.body_len, out) !=
451
 
                                                (size_t) ogout.body_len)
 
468
                                                (size_t) ogout.body_len) {
452
469
                                        goto cleanup;
 
470
                }
453
471
                        }
454
472
                }
455
473
                buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
469
487
 
470
488
        free(state->mainbuf);
471
489
        free(state->bookbuf);
 
490
    state->mainbuf = state->bookbuf = NULL;
472
491
 
473
 
        vcedit_clear_internals(state);
474
492
        if(!state->eosin)
475
493
        {
476
 
                state->lasterror =  
477
 
                        "Error writing stream to output. "
478
 
                        "Output stream may be corrupted or truncated.";
 
494
                state->lasterror =
 
495
                        _("Error writing stream to output. "
 
496
                        "Output stream may be corrupted or truncated.");
479
497
                return -1;
480
498
        }
481
499