1 #ifndef __VCUT_H
2 #define __VCUT_H
3 
4 #include <stdio.h>
5 #include <ogg/ogg.h>
6 #include <vorbis/codec.h>
7 
8 typedef struct {
9 	int length;
10 	unsigned char *packet;
11 } vcut_packet;
12 
13 /* this structure stores data associated with a single input stream; it will be
14    cleared between streams if the input file has multiple chained streams */
15 typedef struct {
16 	ogg_stream_state stream_in;
17 	vorbis_dsp_state vd;
18 	vorbis_block vb;
19 	vorbis_info vi;
20 	vorbis_comment vc;
21 	int prevW;
22 
23 	/* granulepos is -1 before any packets are seen, and 0 after the first
24 	   packet; otherwise it's the GP of the last sample seen */
25 	ogg_int64_t granulepos;
26 
27 	/* the granulepos of the first sample (>= 0, since samples with a negative
28 	   GP are discarded); always 0 for files produced by oggenc or vcut, but
29 	   may be > 0 for data recorded from a stream (for example) */
30 	ogg_int64_t initial_granpos;
31 
32 	/* the number of samples already cut from this stream (all
33 	   granule positions  */
34 	ogg_int64_t samples_cut;
35 
36 	unsigned int serial;
37 	vcut_packet headers[3];
38 	vcut_packet last_packet;
39 } vcut_vorbis_stream;
40 
41 typedef struct vcut_segment {
42 	double cuttime;        /* number of seconds at which to cut;
43 	                          -1 if cutting by sample number */
44 	ogg_int64_t cutpoint;  /* sample number at which to cut */
45 	char *filename;        /* name of the file to contain data after the CP */
46 	struct vcut_segment *next;  /* data for next cut, or NULL */
47 } vcut_segment;
48 
49 typedef struct {
50 	/* pointer to a linked list of segments/cutpoints */
51 	vcut_segment *next_segment;
52 
53 	/* the input file may have multiple chained streams; these variables store
54 	   the number of samples and seconds that passed before the beginning of
55 	   the current stream */
56 	ogg_int64_t prevstream_samples;  /* # of samples in prev. streams */
57 	double prevstream_time;          /* # of seconds past before this stream */
58 
59 	FILE *in;
60 	ogg_sync_state sync_in;
61 	int input_corrupt;            /* 1 if we've complained about corruption */
62 	int vorbis_init;              /* 1 if vorbis_stream initialized */
63 	vcut_vorbis_stream vorbis_stream;
64 
65 	FILE *out;
66 	char *output_filename;
67 	int drop_output;              /* 1 if we don't want any output */
68 	int output_stream_open;       /* 1 if stream_out initialized */
69 	ogg_stream_state stream_out;
70 	unsigned int serial_out;      /* serial # for the next output stream */
71 } vcut_state;
72 
73 int vcut_process(vcut_state *state);
74 void vcut_clear(vcut_state *state);
75 void vcut_vorbis_clear(vcut_vorbis_stream *state);
76 int write_packet(vcut_state *s, ogg_packet *packet);
77 
78 #endif /* __VCUT_H */
79