static int write_header( flv_buffer *c )
{
- put_tag( c, "FLV" ); // Signature
- put_byte( c, 1 ); // Version
- put_byte( c, 1 ); // Video Only
- put_be32( c, 9 ); // DataOffset
- put_be32( c, 0 ); // PreviousTagSize0
+ x264_put_tag( c, "FLV" ); // Signature
+ x264_put_byte( c, 1 ); // Version
+ x264_put_byte( c, 1 ); // Video Only
+ x264_put_be32( c, 9 ); // DataOffset
+ x264_put_be32( c, 0 ); // PreviousTagSize0
return flv_flush_data( c );
}
flv_hnd_t *p_flv = handle;
flv_buffer *c = p_flv->c;
- put_byte( c, FLV_TAG_TYPE_META ); // Tag Type "script data"
+ x264_put_byte( c, FLV_TAG_TYPE_META ); // Tag Type "script data"
int start = c->d_cur;
- put_be24( c, 0 ); // data length
- put_be24( c, 0 ); // timestamp
- put_be32( c, 0 ); // reserved
+ x264_put_be24( c, 0 ); // data length
+ x264_put_be24( c, 0 ); // timestamp
+ x264_put_be32( c, 0 ); // reserved
- put_byte( c, AMF_DATA_TYPE_STRING );
- put_amf_string( c, "onMetaData" );
+ x264_put_byte( c, AMF_DATA_TYPE_STRING );
+ x264_put_amf_string( c, "onMetaData" );
- put_byte( c, AMF_DATA_TYPE_MIXEDARRAY );
- put_be32( c, 7 );
+ x264_put_byte( c, AMF_DATA_TYPE_MIXEDARRAY );
+ x264_put_be32( c, 7 );
- put_amf_string( c, "width" );
- put_amf_double( c, p_param->i_width );
+ x264_put_amf_string( c, "width" );
+ x264_put_amf_double( c, p_param->i_width );
- put_amf_string( c, "height" );
- put_amf_double( c, p_param->i_height );
+ x264_put_amf_string( c, "height" );
+ x264_put_amf_double( c, p_param->i_height );
- put_amf_string( c, "framerate" );
- put_amf_double( c, (double)p_param->i_fps_num / p_param->i_fps_den );
+ x264_put_amf_string( c, "framerate" );
+ x264_put_amf_double( c, (double)p_param->i_fps_num / p_param->i_fps_den );
- put_amf_string( c, "videocodecid" );
- put_amf_double( c, FLV_CODECID_H264 );
+ x264_put_amf_string( c, "videocodecid" );
+ x264_put_amf_double( c, FLV_CODECID_H264 );
- put_amf_string( c, "duration" );
+ x264_put_amf_string( c, "duration" );
p_flv->i_duration_pos = c->d_cur + c->d_total + 1; // + 1 because of the following AMF_DATA_TYPE_NUMBER byte
- put_amf_double( c, 0 ); // written at end of encoding
+ x264_put_amf_double( c, 0 ); // written at end of encoding
- put_amf_string( c, "filesize" );
+ x264_put_amf_string( c, "filesize" );
p_flv->i_filesize_pos = c->d_cur + c->d_total + 1;
- put_amf_double( c, 0 ); // written at end of encoding
+ x264_put_amf_double( c, 0 ); // written at end of encoding
- put_amf_string( c, "videodatarate" );
+ x264_put_amf_string( c, "videodatarate" );
p_flv->i_bitrate_pos = c->d_cur + c->d_total + 1;
- put_amf_double( c, 0 ); // written at end of encoding
+ x264_put_amf_double( c, 0 ); // written at end of encoding
- put_amf_string( c, "" );
- put_byte( c, AMF_END_OF_OBJECT );
+ x264_put_amf_string( c, "" );
+ x264_put_byte( c, AMF_END_OF_OBJECT );
unsigned length = c->d_cur - start;
rewrite_amf_be24( c, length - 10, start );
- put_be32( c, length + 1 ); // tag length
+ x264_put_be32( c, length + 1 ); // tag length
p_flv->i_fps_num = p_param->i_fps_num;
p_flv->i_fps_den = p_param->i_fps_den;
{
uint8_t *sps = p_nalu + 4;
- put_byte( c, FLV_TAG_TYPE_VIDEO );
- put_be24( c, 0 ); // rewrite later, pps size unknown
- put_be24( c, 0 ); // timestamp
- put_byte( c, 0 ); // timestamp extended
- put_be24( c, 0 ); // StreamID - Always 0
+ x264_put_byte( c, FLV_TAG_TYPE_VIDEO );
+ x264_put_be24( c, 0 ); // rewrite later, pps size unknown
+ x264_put_be24( c, 0 ); // timestamp
+ x264_put_byte( c, 0 ); // timestamp extended
+ x264_put_be24( c, 0 ); // StreamID - Always 0
p_flv->start = c->d_cur; // needed for overwriting length
- put_byte( c, 7 | FLV_FRAME_KEY ); // Frametype and CodecID
- put_byte( c, 0 ); // AVC sequence header
- put_be24( c, 0 ); // composition time
+ x264_put_byte( c, 7 | FLV_FRAME_KEY ); // Frametype and CodecID
+ x264_put_byte( c, 0 ); // AVC sequence header
+ x264_put_be24( c, 0 ); // composition time
- put_byte( c, 1 ); // version
- put_byte( c, sps[1] ); // profile
- put_byte( c, sps[2] ); // profile
- put_byte( c, sps[3] ); // level
- put_byte( c, 0xff ); // 6 bits reserved (111111) + 2 bits nal size length - 1 (11)
- put_byte( c, 0xe1 ); // 3 bits reserved (111) + 5 bits number of sps (00001)
+ x264_put_byte( c, 1 ); // version
+ x264_put_byte( c, sps[1] ); // profile
+ x264_put_byte( c, sps[2] ); // profile
+ x264_put_byte( c, sps[3] ); // level
+ x264_put_byte( c, 0xff ); // 6 bits reserved (111111) + 2 bits nal size length - 1 (11)
+ x264_put_byte( c, 0xe1 ); // 3 bits reserved (111) + 5 bits number of sps (00001)
- put_be16( c, i_size - 4 );
+ x264_put_be16( c, i_size - 4 );
flv_append_data( c, sps, i_size - 4 );
p_flv->b_sps = 1;
case 0x08:
if( !p_flv->b_pps )
{
- put_byte( c, 1 ); // number of pps
- put_be16( c, i_size - 4 );
+ x264_put_byte( c, 1 ); // number of pps
+ x264_put_be16( c, i_size - 4 );
flv_append_data( c, p_nalu + 4, i_size - 4 );
// rewrite data length info
unsigned length = c->d_cur - p_flv->start;
rewrite_amf_be24( c, length, p_flv->start - 10 );
- put_be32( c, length + 11 ); // Last tag size
+ x264_put_be32( c, length + 11 ); // Last tag size
p_flv->b_pps = 1;
}
if( !p_flv->b_write_length )
{
// A new frame - write packet header
- put_byte( c, FLV_TAG_TYPE_VIDEO );
- put_be24( c, 0 ); // calculated later
- put_be24( c, dts );
- put_byte( c, dts >> 24 );
- put_be24( c, 0 );
+ x264_put_byte( c, FLV_TAG_TYPE_VIDEO );
+ x264_put_be24( c, 0 ); // calculated later
+ x264_put_be24( c, dts );
+ x264_put_byte( c, dts >> 24 );
+ x264_put_be24( c, 0 );
p_flv->start = c->d_cur;
- put_byte( c, p_picture->i_type == X264_TYPE_IDR ? FLV_FRAME_KEY : FLV_FRAME_INTER );
- put_byte( c, 1 ); // AVC NALU
- put_be24( c, offset );
+ x264_put_byte( c, p_picture->i_type == X264_TYPE_IDR ? FLV_FRAME_KEY : FLV_FRAME_INTER );
+ x264_put_byte( c, 1 ); // AVC NALU
+ x264_put_be24( c, offset );
p_flv->b_write_length = 1;
}
{
unsigned length = c->d_cur - p_flv->start;
rewrite_amf_be24( c, length, p_flv->start - 10 );
- put_be32( c, 11 + length ); // Last tag size
+ x264_put_be32( c, 11 + length ); // Last tag size
CHECK( flv_flush_data( c ) );
p_flv->b_write_length = 0;
}
/* Put functions */
-void put_byte( flv_buffer *c, uint8_t b )
+void x264_put_byte( flv_buffer *c, uint8_t b )
{
flv_append_data( c, &b, 1 );
}
-void put_be32( flv_buffer *c, uint32_t val )
+void x264_put_be32( flv_buffer *c, uint32_t val )
{
- put_byte( c, val >> 24 );
- put_byte( c, val >> 16 );
- put_byte( c, val >> 8 );
- put_byte( c, val );
+ x264_put_byte( c, val >> 24 );
+ x264_put_byte( c, val >> 16 );
+ x264_put_byte( c, val >> 8 );
+ x264_put_byte( c, val );
}
-void put_be64( flv_buffer *c, uint64_t val )
+void x264_put_be64( flv_buffer *c, uint64_t val )
{
- put_be32( c, val >> 32 );
- put_be32( c, val );
+ x264_put_be32( c, val >> 32 );
+ x264_put_be32( c, val );
}
-void put_be16( flv_buffer *c, uint16_t val )
+void x264_put_be16( flv_buffer *c, uint16_t val )
{
- put_byte( c, val >> 8 );
- put_byte( c, val );
+ x264_put_byte( c, val >> 8 );
+ x264_put_byte( c, val );
}
-void put_be24( flv_buffer *c, uint32_t val )
+void x264_put_be24( flv_buffer *c, uint32_t val )
{
- put_be16( c, val >> 8 );
- put_byte( c, val );
+ x264_put_be16( c, val >> 8 );
+ x264_put_byte( c, val );
}
-void put_tag( flv_buffer *c, const char *tag )
+void x264_put_tag( flv_buffer *c, const char *tag )
{
while( *tag )
- put_byte( c, *tag++ );
+ x264_put_byte( c, *tag++ );
}
-void put_amf_string( flv_buffer *c, const char *str )
+void x264_put_amf_string( flv_buffer *c, const char *str )
{
uint16_t len = strlen( str );
- put_be16( c, len );
+ x264_put_be16( c, len );
flv_append_data( c, (uint8_t*)str, len );
}
-void put_amf_double( flv_buffer *c, double d )
+void x264_put_amf_double( flv_buffer *c, double d )
{
- put_byte( c, AMF_DATA_TYPE_NUMBER );
- put_be64( c, dbl2int( d ) );
+ x264_put_byte( c, AMF_DATA_TYPE_NUMBER );
+ x264_put_be64( c, dbl2int( d ) );
}
/* flv writing functions */