]> git.sesse.net Git - x264/blob - output/flv_bytestream.h
Periodic intra refresh
[x264] / output / flv_bytestream.h
1 /*****************************************************************************
2  * flv_bytestream.h:
3  *****************************************************************************
4  * Copyright (C) 2009 Kieran Kunhya
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  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19  *****************************************************************************/
20
21 #ifndef X264_FLV_BYTESTREAM_H
22 #define X264_FLV_BYTESTREAM_H
23
24 /* offsets for packed values */
25 #define FLV_AUDIO_SAMPLESSIZE_OFFSET 1
26 #define FLV_AUDIO_SAMPLERATE_OFFSET  2
27 #define FLV_AUDIO_CODECID_OFFSET     4
28
29 #define FLV_VIDEO_FRAMETYPE_OFFSET   4
30
31 /* bitmasks to isolate specific values */
32 #define FLV_AUDIO_CHANNEL_MASK    0x01
33 #define FLV_AUDIO_SAMPLESIZE_MASK 0x02
34 #define FLV_AUDIO_SAMPLERATE_MASK 0x0c
35 #define FLV_AUDIO_CODECID_MASK    0xf0
36
37 #define FLV_VIDEO_CODECID_MASK    0x0f
38 #define FLV_VIDEO_FRAMETYPE_MASK  0xf0
39
40 #define AMF_END_OF_OBJECT         0x09
41
42 enum
43 {
44     FLV_HEADER_FLAG_HASVIDEO = 1,
45     FLV_HEADER_FLAG_HASAUDIO = 4,
46 };
47
48 enum
49 {
50     FLV_TAG_TYPE_AUDIO = 0x08,
51     FLV_TAG_TYPE_VIDEO = 0x09,
52     FLV_TAG_TYPE_META  = 0x12,
53 };
54
55 enum
56 {
57     FLV_MONO   = 0,
58     FLV_STEREO = 1,
59 };
60
61 enum
62 {
63     FLV_SAMPLESSIZE_8BIT  = 0,
64     FLV_SAMPLESSIZE_16BIT = 1 << FLV_AUDIO_SAMPLESSIZE_OFFSET,
65 };
66
67 enum
68 {
69     FLV_SAMPLERATE_SPECIAL = 0, /**< signifies 5512Hz and 8000Hz in the case of NELLYMOSER */
70     FLV_SAMPLERATE_11025HZ = 1 << FLV_AUDIO_SAMPLERATE_OFFSET,
71     FLV_SAMPLERATE_22050HZ = 2 << FLV_AUDIO_SAMPLERATE_OFFSET,
72     FLV_SAMPLERATE_44100HZ = 3 << FLV_AUDIO_SAMPLERATE_OFFSET,
73 };
74
75 enum
76 {
77     FLV_CODECID_MP3 = 2 << FLV_AUDIO_CODECID_OFFSET,
78     FLV_CODECID_AAC = 10<< FLV_AUDIO_CODECID_OFFSET,
79 };
80
81 enum
82 {
83     FLV_CODECID_H264 = 7,
84 };
85
86 enum
87 {
88     FLV_FRAME_KEY   = 1 << FLV_VIDEO_FRAMETYPE_OFFSET | 7,
89     FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET | 7,
90 };
91
92 typedef enum
93 {
94     AMF_DATA_TYPE_NUMBER      = 0x00,
95     AMF_DATA_TYPE_BOOL        = 0x01,
96     AMF_DATA_TYPE_STRING      = 0x02,
97     AMF_DATA_TYPE_OBJECT      = 0x03,
98     AMF_DATA_TYPE_NULL        = 0x05,
99     AMF_DATA_TYPE_UNDEFINED   = 0x06,
100     AMF_DATA_TYPE_REFERENCE   = 0x07,
101     AMF_DATA_TYPE_MIXEDARRAY  = 0x08,
102     AMF_DATA_TYPE_OBJECT_END  = 0x09,
103     AMF_DATA_TYPE_ARRAY       = 0x0a,
104     AMF_DATA_TYPE_DATE        = 0x0b,
105     AMF_DATA_TYPE_LONG_STRING = 0x0c,
106     AMF_DATA_TYPE_UNSUPPORTED = 0x0d,
107 } AMFDataType;
108
109 typedef struct flv_buffer
110 {
111     uint8_t *data;
112     unsigned d_cur;
113     unsigned d_max;
114     FILE *fp;
115     uint64_t d_total;
116 } flv_buffer;
117
118 flv_buffer *flv_create_writer( const char *filename );
119 int flv_append_data( flv_buffer *c, uint8_t *data, unsigned size );
120 int flv_write_byte( flv_buffer *c, uint8_t *byte );
121 int flv_flush_data( flv_buffer *c );
122 void rewrite_amf_be24( flv_buffer *c, unsigned length, unsigned start );
123
124 uint64_t dbl2int( double value );
125 uint64_t get_amf_double( double value );
126 void x264_put_byte( flv_buffer *c, uint8_t b );
127 void x264_put_be32( flv_buffer *c, uint32_t val );
128 void x264_put_be64( flv_buffer *c, uint64_t val );
129 void x264_put_be16( flv_buffer *c, uint16_t val );
130 void x264_put_be24( flv_buffer *c, uint32_t val );
131 void x264_put_tag( flv_buffer *c, const char *tag );
132 void x264_put_amf_string( flv_buffer *c, const char *str );
133 void x264_put_amf_double( flv_buffer *c, double d );
134
135 #endif