theorautils.h 5.32 KB
Newer Older
Jan Gerber's avatar
Jan Gerber committed
1
/* -*- tab-width:4;c-file-style:"cc-mode"; -*- */
2
/*
Jan Gerber's avatar
Jan Gerber committed
3
 * theorautils.h -- Ogg Theora/Ogg Vorbis Abstraction and Muxing
4
 * Copyright (C) 2003-2009 <j@v2v.cc>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 2 of the License, or
9
10
11
12
13
14
15
16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
17
 * along with This program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
#ifndef _F2T_THEORAUTILS_H_
#define _F2T_THEORAUTILS_H_
21
22

#include <stdint.h>
Jan Gerber's avatar
Jan Gerber committed
23
#include <time.h>
Jan Gerber's avatar
Jan Gerber committed
24
#include "theora/theoraenc.h"
25
26
#include "vorbis/codec.h"
#include "vorbis/vorbisenc.h"
27
28
29
#ifdef HAVE_KATE
#include "kate/kate.h"
#endif
30
#include "ogg/ogg.h"
31
#include "index.h"
32

33
//#define OGGMUX_DEBUG
34

35
36
#define FISHEAD_IDENTIFIER "fishead\0"
#define FISBONE_IDENTIFIER "fisbone\0"
37
#define INDEX_IDENTIFIER "index\0"
38
39
#define FISBONE_SIZE 52
#define FISBONE_MESSAGE_HEADER_OFFSET 44
40
41
#define KEYPOINT_SIZE 20
#define SKELETON_VERSION(major, minor) (((major)<<16)|(minor))
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
typedef struct
{
#ifdef HAVE_KATE
    kate_state k;
    kate_info ki;
    kate_comment kc;
#endif
    ogg_stream_state ko;    /* take physical pages, weld into a logical
                             * stream of packets */
    int katepage_valid;
    unsigned char *katepage;
    int katepage_len;
    int katepage_buffer_length;
    double katetime;
57
58
    seek_index index;
    ogg_int64_t last_end_time;
59
60
61
}
oggmux_kate_stream;

62
63
64
65
66
67
enum SeekableState {
    MAYBE_SEEKABLE = -1,
    NOT_SEEKABLE = 0,
    SEEKABLE = 1,
};

68
69
typedef struct
{
Jan Gerber's avatar
Jan Gerber committed
70
71
    /* the file the mixed ogg stream is written to */
    FILE *outfile;
72
73
74
    /* Greather than zero if outfile is seekable.
       Value one of SeekableState. */
    int output_seekable;
Jan Gerber's avatar
Jan Gerber committed
75

76
    char oshash[32];
Jan Gerber's avatar
Jan Gerber committed
77
78
    int audio_only;
    int video_only;
79
    int with_skeleton;
80
    int skeleton_3;
81
    int index_interval;
Jan Gerber's avatar
Jan Gerber committed
82
83
    int theora_index_reserve;
    int vorbis_index_reserve;
84
    int kate_index_reserve;
85
    int indexing_complete;
86
    FILE *frontend;
Jan Gerber's avatar
Jan Gerber committed
87
    /* vorbis settings */
Jan Gerber's avatar
Jan Gerber committed
88
89
90
91
    int sample_rate;
    int channels;
    double vorbis_quality;
    int vorbis_bitrate;
92

Jan Gerber's avatar
Jan Gerber committed
93
94
    vorbis_info vi;       /* struct that stores all the static vorbis bitstream settings */
    vorbis_comment vc;    /* struct that stores all the user comments */
95

Jan Gerber's avatar
Jan Gerber committed
96
    /* theora settings */
Jan Gerber's avatar
Jan Gerber committed
97
98
    th_info ti;
    th_comment tc;
Jan Gerber's avatar
Jan Gerber committed
99
    int speed_level;
100

Jan Gerber's avatar
Jan Gerber committed
101
    /* state info */
Jan Gerber's avatar
Jan Gerber committed
102
    th_enc_ctx *td;
Jan Gerber's avatar
Jan Gerber committed
103
104
    vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
    vorbis_block vb;     /* local working space for packet->PCM decode */
Jan Gerber's avatar
Jan Gerber committed
105

106
107
    int with_kate;

Jan Gerber's avatar
Jan Gerber committed
108
109
110
111
112
    /* used for muxing */
    ogg_stream_state to;    /* take physical pages, weld into a logical
                             * stream of packets */
    ogg_stream_state vo;    /* take physical pages, weld into a logical
                             * stream of packets */
113
    ogg_stream_state so;    /* take physical pages, weld into a logical
Jan Gerber's avatar
Jan Gerber committed
114
                             * stream of packets, used for skeleton stream */
115
116
117
118
119
120
121
122
123

    int audiopage_valid;
    int videopage_valid;
    unsigned char *audiopage;
    unsigned char *videopage;
    int videopage_len;
    int audiopage_len;
    int videopage_buffer_length;
    int audiopage_buffer_length;
124

Jan Gerber's avatar
Jan Gerber committed
125
126
127
    /* some stats */
    double audiotime;
    double videotime;
128
    double duration;
Jan Gerber's avatar
Jan Gerber committed
129

Jan Gerber's avatar
Jan Gerber committed
130
131
132
133
    int vkbps;
    int akbps;
    ogg_int64_t audio_bytesout;
    ogg_int64_t video_bytesout;
134
    ogg_int64_t kate_bytesout;
135
    time_t start_time;
136
137
138
139

    //to do some manual page flusing
    int v_pkg;
    int a_pkg;
140
    int k_pkg;
141
142
143
#ifdef OGGMUX_DEBUG
    int a_page;
    int v_page;
144
    int k_page;
145
#endif
146

Jan Gerber's avatar
Jan Gerber committed
147
148
149
150
    FILE *twopass_file;
    int twopass;
    int passno;

151
152
    int n_kate_streams;
    oggmux_kate_stream *kate_streams;
153
154
155

    seek_index theora_index;
    seek_index vorbis_index;
156
157
    int prev_vorbis_window; /* Window size of previous vorbis block. Used to
                               calculate duration of vorbis packets. */
Jan Gerber's avatar
Jan Gerber committed
158
    /* The offset of the first non header page in bytes. */
159
    ogg_int64_t content_offset;
160
161
    /* Granulepos of the last encoded packet. */
    ogg_int64_t vorbis_granulepos;
162
163

    ogg_int32_t serialno;
Jan Gerber's avatar
Jan Gerber committed
164
165
166
}
oggmux_info;

167
void init_info(oggmux_info *info);
168
extern void oggmux_setup_kate_streams(oggmux_info *info, int n_kate_streams);
Jan Gerber's avatar
Jan Gerber committed
169
extern void oggmux_init (oggmux_info *info);
Jan Gerber's avatar
Jan Gerber committed
170
extern void oggmux_add_video (oggmux_info *info, th_ycbcr_buffer ycbcr, int e_o_s);
Jan Gerber's avatar
Jan Gerber committed
171
extern void oggmux_add_audio (oggmux_info *info, int16_t * readbuffer, int bytesread, int samplesread,int e_o_s);
172
#ifdef HAVE_KATE
173
extern void oggmux_add_kate_text (oggmux_info *info, int idx, double t0, double t1, const char *text, size_t len, int x1, int x2, int y1, int y2);
174
extern void oggmux_add_kate_image (oggmux_info *info, int idx, double t0, double t1, const kate_region *kr, const kate_palette *kp, const kate_bitmap *kb);
175
extern void oggmux_add_kate_end_packet (oggmux_info *info, int idx, double t);
176
#endif
Jan Gerber's avatar
Jan Gerber committed
177
178
extern void oggmux_flush (oggmux_info *info, int e_o_s);
extern void oggmux_close (oggmux_info *info);
179

180
181
extern int write_seek_index (oggmux_info* info);

Jan Gerber's avatar
Jan Gerber committed
182

183
#endif