Ejemplo n.º 1
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_sei_pic_timing_write( x264_t *h, bs_t *s )
{
    x264_sps_t *sps = h->sps;
    bs_t q;
    uint8_t tmp_buf[100];
    bs_init( &q, tmp_buf, 100 );

    bs_realign( &q );

    if( sps->vui.b_nal_hrd_parameters_present || sps->vui.b_vcl_hrd_parameters_present )
    {
        bs_write( &q, sps->vui.hrd.i_cpb_removal_delay_length, h->fenc->i_cpb_delay - h->i_cpb_delay_pir_offset );
        bs_write( &q, sps->vui.hrd.i_dpb_output_delay_length, h->fenc->i_dpb_output_delay );
    }

    if( sps->vui.b_pic_struct_present )
    {
        bs_write( &q, 4, h->fenc->i_pic_struct-1 ); // We use index 0 for "Auto"

        // These clock timestamps are not standardised so we don't set them
        // They could be time of origin, capture or alternative ideal display
        for( int i = 0; i < num_clock_ts[h->fenc->i_pic_struct]; i++ )
            bs_write1( &q, 0 ); // clock_timestamp_flag
    }

    bs_align_10( &q );
    bs_flush( &q );

    x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_PIC_TIMING );
}
Ejemplo n.º 2
0
Archivo: ip.c Proyecto: gz818/obe-rt
static int write_rtp_pkt( hnd_t handle, uint8_t *data, int len, int64_t timestamp )
{
    obe_rtp_ctx *p_rtp = handle;
    uint8_t pkt[RTP_HEADER_SIZE+TS_PACKETS_SIZE];
    bs_t s;
    bs_init( &s, pkt, RTP_HEADER_SIZE+TS_PACKETS_SIZE );

    bs_write( &s, 2, RTP_VERSION ); // version
    bs_write1( &s, 0 );             // padding
    bs_write1( &s, 0 );             // extension
    bs_write( &s, 4, 0 );           // CSRC count
    bs_write1( &s, 0 );             // marker
    bs_write( &s, 7, MPEG_TS_PAYLOAD_TYPE ); // payload type
    bs_write( &s, 16, p_rtp->seq++ ); // sequence number
    bs_write32( &s, timestamp / 300 ); // timestamp
    bs_write32( &s, p_rtp->ssrc );    // ssrc
    bs_flush( &s );

    memcpy( &pkt[RTP_HEADER_SIZE], data, len );

    if( udp_write( p_rtp->udp_handle, pkt, RTP_HEADER_SIZE+TS_PACKETS_SIZE ) < 0 )
        return -1;

    p_rtp->pkt_cnt++;
    p_rtp->octet_cnt += len;

    return 0;
}
Ejemplo n.º 3
0
void x264_sei_pic_timing_write( x264_t *h, bs_t *s )
{
    x264_sps_t *sps = h->sps;
    bs_realign( s );
    uint8_t *p_start = x264_sei_write_header( s, SEI_PIC_TIMING );

    if( sps->vui.b_nal_hrd_parameters_present || sps->vui.b_vcl_hrd_parameters_present )
    {
        bs_write( s, sps->vui.hrd.i_cpb_removal_delay_length, h->fenc->i_cpb_delay );
        bs_write( s, sps->vui.hrd.i_dpb_output_delay_length, h->fenc->i_dpb_output_delay );
    }

    if( sps->vui.b_pic_struct_present )
    {
        bs_write( s, 4, h->fenc->i_pic_struct-1 ); // We use index 0 for "Auto"

        // These clock timestamps are not standardised so we don't set them
        // They could be time of origin, capture or alternative ideal display
        for( int i = 0; i < num_clock_ts[h->fenc->i_pic_struct]; i++ )
            bs_write1( s, 0 ); // clock_timestamp_flag
    }

    x264_sei_write( s, p_start );
    bs_flush( s );
}
Ejemplo n.º 4
0
Archivo: ip.c Proyecto: gz818/obe-rt
static int write_rtcp_pkt( hnd_t handle )
{
    obe_rtp_ctx *p_rtp = handle;
    uint64_t ntp_time = obe_ntp_time();
    uint8_t pkt[100];
    bs_t s;
    bs_init( &s, pkt, RTCP_PACKET_SIZE );

    bs_write( &s, 2, RTP_VERSION ); // version
    bs_write1( &s, 0 );             // padding
    bs_write( &s, 5, 0 );           // reception report count
    bs_write( &s, 8, RTCP_SR_PACKET_TYPE ); // packet type
    bs_write( &s, 8, 6 );           // length (length in words - 1)
    bs_write32( &s, p_rtp->ssrc );  // ssrc
    bs_write32( &s, ntp_time / 1000000 ); // NTP timestamp, most significant word
    bs_write32( &s, ((ntp_time % 1000000) << 32) / 1000000 ); // NTP timestamp, least significant word
    bs_write32( &s, 0 );            // RTP timestamp FIXME
    bs_write32( &s, p_rtp->pkt_cnt ); // sender's packet count
    bs_write32( &s, p_rtp->octet_cnt ); // sender's octet count
    bs_flush( &s );

    if( udp_write( p_rtp->udp_handle, pkt, RTCP_PACKET_SIZE ) < 0 )
        return -1;

    return 0;
}
Ejemplo n.º 5
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_filler_write( x264_t *h, bs_t *s, int filler )
{
    bs_realign( s );

    for( int i = 0; i < filler; i++ )
        bs_write( s, 8, 0xff );

    bs_rbsp_trailing( s );
    bs_flush( s );
}
Ejemplo n.º 6
0
static void x264_sei_write( bs_t *s, uint8_t *p_start )
{
    bs_align_10( s );
    bs_flush( s );

    p_start[0] = s->p - p_start - 1; // -1 for the length byte
    bs_realign( s );

    bs_rbsp_trailing( s );
}
Ejemplo n.º 7
0
static void write_bytes( bs_t *s, uint8_t *bytes, int length )
{
    bs_flush( s );
    uint8_t *p_start = s->p_start;

    memcpy( s->p, bytes, length );
    s->p += length;

    bs_init( s, s->p, s->p_end - s->p );
    s->p_start = p_start;
}
Ejemplo n.º 8
0
static uint8_t *x264_sei_write_header( bs_t *s, int payload_type )
{
    bs_write( s, 8, payload_type );

    bs_flush( s );
    uint8_t *p_start = s->p;
    bs_realign( s );

    bs_write( s, 8, 0 );
    return p_start;
}
Ejemplo n.º 9
0
void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
{
    bs_realign( s );
    uint8_t *p_start = x264_sei_write_header( s, SEI_RECOVERY_POINT );

    bs_write_ue( s, recovery_frame_cnt ); // recovery_frame_cnt
    bs_write( s, 1, 1 ); //exact_match_flag 1
    bs_write( s, 1, 0 ); //broken_link_flag 0
    bs_write( s, 2, 0 ); //changing_slice_group 0

    x264_sei_write( s, p_start );
    bs_flush( s );
}
Ejemplo n.º 10
0
static int write_708_cc( obe_user_data_t *user_data, uint8_t *start, int cc_count )
{
    bs_t s;
    uint8_t temp[1000];
    const char *user_identifier = "GA94";
    const int data_type_code    = 0x03;

    /* TODO: when MPEG-2 is added make this do the right thing */
    /* FIXME: enable echostar captions and add more types */

    bs_init( &s, temp, 1000 );

    /* N.B MPEG-4 only */
    write_itu_t_codes( &s );

    for( int i = 0; i < 4; i++ )
        bs_write( &s, 8, user_identifier[i] ); // user_identifier

    bs_write( &s, 8, data_type_code ); // user_data_type_code

    // user_data_type_structure (echostar)
    // cc_data
    bs_write1( &s, 1 );     // reserved
    bs_write1( &s, 1 );     // process_cc_data_flag
    bs_write1( &s, 0 );     // zero_bit / additional_data_flag
    bs_write( &s, 5, cc_count ); // cc_count
    bs_write( &s, 8, 0xff ); // reserved

    write_bytes( &s, start, cc_count*3 );

    bs_write( &s, 8, 0xff ); // marker_bits
    bs_flush( &s );

    user_data->type = USER_DATA_AVC_REGISTERED_ITU_T35;
    user_data->len = bs_pos( &s ) >> 3;

    free( user_data->data );

    user_data->data = malloc( user_data->len );
    if( !user_data->data )
    {
        syslog( LOG_ERR, "Malloc failed\n" );
        return -1;
    }

    memcpy( user_data->data, temp, user_data->len );

    return 0;
}
Ejemplo n.º 11
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_pps_write( bs_t *s, x264_pps_t *pps )
{
    bs_realign( s );
    bs_write_ue( s, pps->i_id );
    bs_write_ue( s, pps->i_sps_id );

    bs_write1( s, pps->b_cabac );
    bs_write1( s, pps->b_pic_order );
    bs_write_ue( s, pps->i_num_slice_groups - 1 );

    bs_write_ue( s, pps->i_num_ref_idx_l0_default_active - 1 );
    bs_write_ue( s, pps->i_num_ref_idx_l1_default_active - 1 );
    bs_write1( s, pps->b_weighted_pred );
    bs_write( s, 2, pps->b_weighted_bipred );

    bs_write_se( s, pps->i_pic_init_qp - 26 - QP_BD_OFFSET );
    bs_write_se( s, pps->i_pic_init_qs - 26 - QP_BD_OFFSET );
    bs_write_se( s, pps->i_chroma_qp_index_offset );

    bs_write1( s, pps->b_deblocking_filter_control );
    bs_write1( s, pps->b_constrained_intra_pred );
    bs_write1( s, pps->b_redundant_pic_cnt );

    if( pps->b_transform_8x8_mode || pps->i_cqm_preset != X264_CQM_FLAT )
    {
        bs_write1( s, pps->b_transform_8x8_mode );
        bs_write1( s, (pps->i_cqm_preset != X264_CQM_FLAT) );
        if( pps->i_cqm_preset != X264_CQM_FLAT )
        {
            scaling_list_write( s, pps, CQM_4IY );
            scaling_list_write( s, pps, CQM_4IC );
            bs_write1( s, 0 ); // Cr = Cb
            scaling_list_write( s, pps, CQM_4PY );
            scaling_list_write( s, pps, CQM_4PC );
            bs_write1( s, 0 ); // Cr = Cb
            if( pps->b_transform_8x8_mode )
            {
                scaling_list_write( s, pps, CQM_8IY+4 );
                scaling_list_write( s, pps, CQM_8PY+4 );
            }
        }
        bs_write_se( s, pps->i_chroma_qp_index_offset );
    }

    bs_rbsp_trailing( s );
    bs_flush( s );
}
Ejemplo n.º 12
0
void x264_sei_buffering_period_write( x264_t *h, bs_t *s )
{
    x264_sps_t *sps = h->sps;
    bs_realign( s );
    uint8_t *p_start = x264_sei_write_header( s, SEI_BUFFERING_PERIOD );

    bs_write_ue( s, sps->i_id );

    if( sps->vui.b_nal_hrd_parameters_present )
    {
        bs_write( s, sps->vui.hrd.i_initial_cpb_removal_delay_length, h->initial_cpb_removal_delay );
        bs_write( s, sps->vui.hrd.i_initial_cpb_removal_delay_length, h->initial_cpb_removal_delay_offset );
    }

    x264_sei_write( s, p_start );
    bs_flush( s );
}
Ejemplo n.º 13
0
int x264_sei_version_write( x264_t *h, bs_t *s )
{
    int i;
    // random ID number generated according to ISO-11578
    static const uint8_t uuid[16] =
    {
        0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7,
        0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef
    };
    char *opts = x264_param2string( &h->param, 0 );
    char *version;
    int length;

    if( !opts )
        return -1;
    CHECKED_MALLOC( version, 200 + strlen( opts ) );

    sprintf( version, "x264 - core %d%s - H.264/MPEG-4 AVC codec - "
             "Copyleft 2003-2010 - http://www.videolan.org/x264.html - options: %s",
             X264_BUILD, X264_VERSION, opts );
    length = strlen(version)+1+16;

    bs_realign( s );
    bs_write( s, 8, SEI_USER_DATA_UNREGISTERED );
    // payload_size
    for( i = 0; i <= length-255; i += 255 )
        bs_write( s, 8, 255 );
    bs_write( s, 8, length-i );

    for( int j = 0; j < 16; j++ )
        bs_write( s, 8, uuid[j] );
    for( int j = 0; j < length-16; j++ )
        bs_write( s, 8, version[j] );

    bs_rbsp_trailing( s );
    bs_flush( s );

    x264_free( opts );
    x264_free( version );
    return 0;
fail:
    x264_free( opts );
    return -1;
}
Ejemplo n.º 14
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
{
    bs_t q;
    uint8_t tmp_buf[100];
    bs_init( &q, tmp_buf, 100 );

    bs_realign( &q );

    bs_write_ue( &q, recovery_frame_cnt ); // recovery_frame_cnt
    bs_write1( &q, 1 );   //exact_match_flag 1
    bs_write1( &q, 0 );   //broken_link_flag 0
    bs_write( &q, 2, 0 ); //changing_slice_group 0

    bs_align_10( &q );
    bs_flush( &q );

    x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_RECOVERY_POINT );

}
Ejemplo n.º 15
0
void x264_sei_write( bs_t *s, uint8_t *payload, int payload_size, int payload_type )
{
    int i;

    bs_realign( s );

    for( i = 0; i <= payload_type-255; i += 255 )
        bs_write( s, 8, 255 );
    bs_write( s, 8, payload_type-i );

    for( i = 0; i <= payload_size-255; i += 255 )
        bs_write( s, 8, 255 );
    bs_write( s, 8, payload_size-i );

    for( i = 0; i < payload_size; i++ )
        bs_write( s, 8, payload[i] );

    bs_rbsp_trailing( s );
    bs_flush( s );
}
Ejemplo n.º 16
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_sei_buffering_period_write( x264_t *h, bs_t *s )
{
    x264_sps_t *sps = h->sps;
    bs_t q;
    uint8_t tmp_buf[100];
    bs_init( &q, tmp_buf, 100 );

    bs_realign( &q );
    bs_write_ue( &q, sps->i_id );

    if( sps->vui.b_nal_hrd_parameters_present )
    {
        bs_write( &q, sps->vui.hrd.i_initial_cpb_removal_delay_length, h->initial_cpb_removal_delay );
        bs_write( &q, sps->vui.hrd.i_initial_cpb_removal_delay_length, h->initial_cpb_removal_delay_offset );
    }

    bs_align_10( &q );
    bs_flush( &q );

    x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_BUFFERING_PERIOD );
}
Ejemplo n.º 17
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_sei_frame_packing_write( x264_t *h, bs_t *s )
{
    bs_t q;
    uint8_t tmp_buf[100];
    bs_init( &q, tmp_buf, 100 );

    bs_realign( &q );

    bs_write_ue( &q, 0 );                         // frame_packing_arrangement_id
    bs_write1( &q, 0 );                           // frame_packing_arrangement_cancel_flag
    bs_write ( &q, 7, h->param.i_frame_packing ); // frame_packing_arrangement_type
    bs_write1( &q, 0 );                           // quincunx_sampling_flag

    // 0: views are unrelated, 1: left view is on the left, 2: left view is on the right
    bs_write ( &q, 6, 1 );                        // content_interpretation_type

    bs_write1( &q, 0 );                           // spatial_flipping_flag
    bs_write1( &q, 0 );                           // frame0_flipped_flag
    bs_write1( &q, 0 );                           // field_views_flag
    bs_write1( &q, h->param.i_frame_packing == 5 && !(h->fenc->i_frame&1) ); // current_frame_is_frame0_flag
    bs_write1( &q, 0 );                           // frame0_self_contained_flag
    bs_write1( &q, 0 );                           // frame1_self_contained_flag
    if ( /* quincunx_sampling_flag == 0 && */ h->param.i_frame_packing != 5 )
    {
        bs_write( &q, 4, 0 );                     // frame0_grid_position_x
        bs_write( &q, 4, 0 );                     // frame0_grid_position_y
        bs_write( &q, 4, 0 );                     // frame1_grid_position_x
        bs_write( &q, 4, 0 );                     // frame1_grid_position_y
    }
    bs_write( &q, 8, 0 );                         // frame_packing_arrangement_reserved_byte
    bs_write_ue( &q, 1 );                         // frame_packing_arrangement_repetition_period
    bs_write1( &q, 0 );                           // frame_packing_arrangement_extension_flag

    bs_align_10( &q );
    bs_flush( &q );

    x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_FRAME_PACKING );
}
Ejemplo n.º 18
0
void x264_vp8_slice_header_write( x264_t *h, bs_t *s, x264_slice_header_t *sh )
{
    int chroma_qp_delta = h->chroma_qp_table[sh->i_qp] - sh->i_qp;
    int filter_level = sh->i_disable_deblocking_filter_idc ? 0 : x264_vp8_deblock_level_table[sh->i_qp];
    int keyframe = sh->i_idr_pic_id >= 0;
    int header_byte = (!keyframe               << 0)
                    + (0 /* regular profile */ << 1)
                    + (1 /* not invisible */   << 4);
    h->vp8.header_ptr = s->p;
    /* We go back and fix this later. */
    int header_size = 0;
    int header = (header_size << 5) + header_byte;
    /* Stupid little-endian headers */
    bs_write( s, 8, (header>> 0)&0xff );
    bs_write( s, 8, (header>> 8)&0xff );
    bs_write( s, 8, (header>>16)      );

    if( keyframe )
    {
        /* Startcode */
        bs_write( s, 24, 0x9d012a );

        /* Fixme: make sure to cap resolutions at 0x3fff to avoid hscale/vscale */
        bs_write( s, 8, h->param.i_width&0xff  );
        bs_write( s, 8, h->param.i_width>>8    );
        bs_write( s, 8, h->param.i_height&0xff );
        bs_write( s, 8, h->param.i_height>>8   );
    }
    bs_flush( s );

    x264_vp8rac_t *cb = &h->vp8.header_rac;
    x264_vp8rac_encode_init( cb, s->p, s->p_end );
    if( keyframe )
    {
        x264_vp8rac_encode_bypass( cb, 0 ); /* colorspace */
        x264_vp8rac_encode_bypass( cb, 0 ); /* don't skip DSP clamping */
    }

    x264_vp8rac_encode_bypass( cb, 0 ); /* no segmentation for now */
    x264_vp8rac_encode_bypass( cb, 0 ); /* normal filter
                                         * TODO: simple filter */
    x264_vp8rac_encode_uint_bypass( cb, filter_level, 6 ); /* filter level */
    x264_vp8rac_encode_uint_bypass( cb, 0, 3 ); /* filter sharpness */
    x264_vp8rac_encode_bypass( cb, 0 ); /* no lf deltas */
    x264_vp8rac_encode_uint_bypass( cb, 0, 2 ); /* No bitstream partitions */

    /* TODO: use correct deltas for dc/chroma blocks */
    x264_vp8rac_encode_uint_bypass( cb, sh->i_qp, 7 ); /* yac_qi */
    x264_vp8rac_encode_sint_bypass( cb, 0, 4 );       /* ydc_delta */
    x264_vp8rac_encode_sint_bypass( cb, 0, 4 );       /* y2dc_delta */
    x264_vp8rac_encode_sint_bypass( cb, 0, 4 );       /* y2ac_delta */
    x264_vp8rac_encode_sint_bypass( cb, chroma_qp_delta, 4 );       /* uvdc_delta */
    x264_vp8rac_encode_sint_bypass( cb, chroma_qp_delta, 4 );       /* uvac_delta */

    if( !keyframe )
    {
        x264_vp8rac_encode_bypass( cb, 1 ); /* Update golden with current frame */
        x264_vp8rac_encode_bypass( cb, 1 ); /* Update altref with current frame */
        x264_vp8rac_encode_bypass( cb, 0 ); /* No golden sign bias */
        x264_vp8rac_encode_bypass( cb, 0 ); /* No altref sign bias */
    }

    x264_vp8rac_encode_bypass( cb, 0 ); /* don't save updated probability tables */
    if( !keyframe )
        x264_vp8rac_encode_bypass( cb, 1 ); /* This frame is referenced, update the last ref */

    /* Let's not update probabilities yet */
    for( int i = 0; i < 4; i++ )
        for( int j = 0; j < 8; j++ )
            for( int k = 0; k < 3; k++ )
                for( int l = 0; l < NUM_DCT_TOKENS-1; l++ )
                    x264_vp8rac_encode_decision( cb, x264_vp8_dct_update_probs[i][j][k][l], 0 );

    x264_vp8rac_encode_bypass( cb, 1 ); /* mb skip enabled */
    x264_vp8rac_encode_uint_bypass( cb, 0x80, 8 ); /* Just set even probability for now. */
    if( !keyframe )
    {
        x264_vp8rac_encode_uint_bypass( cb, 0x80, 8 ); /* Even intra mb probability */
        x264_vp8rac_encode_uint_bypass( cb, 0x80, 8 ); /* Even last ref probability */
        x264_vp8rac_encode_uint_bypass( cb, 0x80, 8 ); /* Even golden ref probability */
        x264_vp8rac_encode_bypass( cb, 0 ); /* Don't update I16x16 mode probabilities */
        x264_vp8rac_encode_bypass( cb, 0 ); /* Don't update chroma intra mode probabilities */
        /* Don't update MV probabilities */
        for( int i = 0; i < 2; i++ )
            for( int j = 0; j < 19; j++ )
                x264_vp8rac_encode_decision( cb, x264_vp8_mv_update_probs[i][j], 0 );
    }
}
Ejemplo n.º 19
0
/* TODO: factor shared code out from 608 and 708 */
int write_608_cc( obe_user_data_t *user_data, obe_raw_frame_t *raw_frame )
{
    bs_t q, r;
    uint8_t temp[1000];
    uint8_t temp2[500];
    const char *user_identifier = "GA94";
    const int data_type_code    = 0x03;
    int cc_count                = 0;
    const int echostar_captions = 0;

    /* TODO: when MPEG-2 is added make this do the right thing */
    /* FIXME: enable echostar captions and add more types */

    for( int i = 0; cc_timecode[i].timebase_num != 0; i++ )
    {
        if( raw_frame->timebase_num == cc_timecode[i].timebase_num && raw_frame->timebase_den == cc_timecode[i].timebase_den )
            cc_count = cc_timecode[i].cc_count;
    }

    if( !cc_count )
    {
        syslog( LOG_ERR, "[cc]: Unsupported framerate for captions\n" );
        return -1;
    }

    bs_init( &r, temp, 1000 );

    /* N.B MPEG-4 only */
    write_itu_t_codes( &r );

    if( !echostar_captions )
    {
        for( int i = 0; i < 4; i++ )
            bs_write( &r, 8, user_identifier[i] ); // user_identifier
    }

    bs_write( &r, 8, data_type_code ); // user_data_type_code

    bs_init( &q, temp2, 500 );

    // user_data_type_structure (echostar)
    // cc_data
    bs_write1( &q, 1 );     // reserved
    bs_write1( &q, 1 );     // process_cc_data_flag
    bs_write1( &q, 0 );     // zero_bit / additional_data_flag
    bs_write( &q, 5, cc_count ); // cc_count
    bs_write( &q, 8, 0xff ); // reserved

    for( int i = 0; i < cc_count; i++ )
    {
        bs_write1( &q, 1 );     // one_bit
        bs_write( &q, 4, 0xf ); // reserved

        if( i <= 1 && user_data->len >= (i+1)*2 )
        {
            bs_write1( &q, 1 );   // cc_valid
            bs_write( &q, 2, i ); // cc_type
            bs_write( &q, 8, user_data->data[2*i] );   // c_data_1
            bs_write( &q, 8, user_data->data[2*i+1] ); // c_data_2
        }
        else /* nothing to write so maintain a constant bitrate */
            write_invalid( &q );
    }

    bs_write( &q, 8, 0xff ); // marker_bits
    bs_flush( &q );

    if( echostar_captions )
    {
        // ATSC1_data
        bs_write( &r, 8, bs_pos( &q ) >> 3 ); // user_data_code_length
    }

    write_bytes( &r, temp2, bs_pos( &q ) >> 3 );

    bs_flush( &r );

    user_data->type = USER_DATA_AVC_REGISTERED_ITU_T35;
    user_data->len = bs_pos( &r ) >> 3;

    free( user_data->data );

    user_data->data = malloc( user_data->len );
    if( !user_data->data )
    {
        syslog( LOG_ERR, "Malloc failed\n" );
        return -1;
    }

    memcpy( user_data->data, temp, user_data->len );

    return 0;
}
Ejemplo n.º 20
0
Archivo: set.c Proyecto: submux/obe-vod
void x264_sps_write( bs_t *s, x264_sps_t *sps )
{
    bs_realign( s );
    bs_write( s, 8, sps->i_profile_idc );
    bs_write1( s, sps->b_constraint_set0 );
    bs_write1( s, sps->b_constraint_set1 );
    bs_write1( s, sps->b_constraint_set2 );
    bs_write1( s, sps->b_constraint_set3 );

    bs_write( s, 4, 0 );    /* reserved */

    bs_write( s, 8, sps->i_level_idc );

    bs_write_ue( s, sps->i_id );

    if( sps->i_profile_idc >= PROFILE_HIGH )
    {
        bs_write_ue( s, 1 ); // chroma_format_idc = 4:2:0
        bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_luma_minus8
        bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_chroma_minus8
        bs_write1( s, sps->b_qpprime_y_zero_transform_bypass );
        bs_write1( s, 0 ); // seq_scaling_matrix_present_flag
    }

    bs_write_ue( s, sps->i_log2_max_frame_num - 4 );
    bs_write_ue( s, sps->i_poc_type );
    if( sps->i_poc_type == 0 )
    {
        bs_write_ue( s, sps->i_log2_max_poc_lsb - 4 );
    }
    else if( sps->i_poc_type == 1 )
    {
        bs_write1( s, sps->b_delta_pic_order_always_zero );
        bs_write_se( s, sps->i_offset_for_non_ref_pic );
        bs_write_se( s, sps->i_offset_for_top_to_bottom_field );
        bs_write_ue( s, sps->i_num_ref_frames_in_poc_cycle );

        for( int i = 0; i < sps->i_num_ref_frames_in_poc_cycle; i++ )
            bs_write_se( s, sps->i_offset_for_ref_frame[i] );
    }
    bs_write_ue( s, sps->i_num_ref_frames );
    bs_write1( s, sps->b_gaps_in_frame_num_value_allowed );
    bs_write_ue( s, sps->i_mb_width - 1 );
    bs_write_ue( s, (sps->i_mb_height >> !sps->b_frame_mbs_only) - 1);
    bs_write1( s, sps->b_frame_mbs_only );
    if( !sps->b_frame_mbs_only )
        bs_write1( s, sps->b_mb_adaptive_frame_field );
    bs_write1( s, sps->b_direct8x8_inference );

    bs_write1( s, sps->b_crop );
    if( sps->b_crop )
    {
        bs_write_ue( s, sps->crop.i_left   / 2 );
        bs_write_ue( s, sps->crop.i_right  / 2 );
        bs_write_ue( s, sps->crop.i_top    / 2 );
        bs_write_ue( s, sps->crop.i_bottom / 2 );
    }

    bs_write1( s, sps->b_vui );
    if( sps->b_vui )
    {
        bs_write1( s, sps->vui.b_aspect_ratio_info_present );
        if( sps->vui.b_aspect_ratio_info_present )
        {
            int i;
            static const struct { uint8_t w, h, sar; } sar[] =
            {
                // aspect_ratio_idc = 0 -> unspecified
                {  1,  1, 1 }, { 12, 11, 2 }, { 10, 11, 3 }, { 16, 11, 4 },
                { 40, 33, 5 }, { 24, 11, 6 }, { 20, 11, 7 }, { 32, 11, 8 },
                { 80, 33, 9 }, { 18, 11, 10}, { 15, 11, 11}, { 64, 33, 12},
                {160, 99, 13}, {  4,  3, 14}, {  3,  2, 15}, {  2,  1, 16},
                // aspect_ratio_idc = [17..254] -> reserved
                { 0, 0, 255 }
            };
            for( i = 0; sar[i].sar != 255; i++ )
            {
                if( sar[i].w == sps->vui.i_sar_width &&
                    sar[i].h == sps->vui.i_sar_height )
                    break;
            }
            bs_write( s, 8, sar[i].sar );
            if( sar[i].sar == 255 ) /* aspect_ratio_idc (extended) */
            {
                bs_write( s, 16, sps->vui.i_sar_width );
                bs_write( s, 16, sps->vui.i_sar_height );
            }
        }

        bs_write1( s, sps->vui.b_overscan_info_present );
        if( sps->vui.b_overscan_info_present )
            bs_write1( s, sps->vui.b_overscan_info );

        bs_write1( s, sps->vui.b_signal_type_present );
        if( sps->vui.b_signal_type_present )
        {
            bs_write( s, 3, sps->vui.i_vidformat );
            bs_write1( s, sps->vui.b_fullrange );
            bs_write1( s, sps->vui.b_color_description_present );
            if( sps->vui.b_color_description_present )
            {
                bs_write( s, 8, sps->vui.i_colorprim );
                bs_write( s, 8, sps->vui.i_transfer );
                bs_write( s, 8, sps->vui.i_colmatrix );
            }
        }

        bs_write1( s, sps->vui.b_chroma_loc_info_present );
        if( sps->vui.b_chroma_loc_info_present )
        {
            bs_write_ue( s, sps->vui.i_chroma_loc_top );
            bs_write_ue( s, sps->vui.i_chroma_loc_bottom );
        }

        bs_write1( s, sps->vui.b_timing_info_present );
        if( sps->vui.b_timing_info_present )
        {
            bs_write32( s, sps->vui.i_num_units_in_tick );
            bs_write32( s, sps->vui.i_time_scale );
            bs_write1( s, sps->vui.b_fixed_frame_rate );
        }

        bs_write1( s, sps->vui.b_nal_hrd_parameters_present );
        if( sps->vui.b_nal_hrd_parameters_present )
        {
            bs_write_ue( s, sps->vui.hrd.i_cpb_cnt - 1 );
            bs_write( s, 4, sps->vui.hrd.i_bit_rate_scale );
            bs_write( s, 4, sps->vui.hrd.i_cpb_size_scale );

            bs_write_ue( s, sps->vui.hrd.i_bit_rate_value - 1 );
            bs_write_ue( s, sps->vui.hrd.i_cpb_size_value - 1 );

            bs_write1( s, sps->vui.hrd.b_cbr_hrd );

            bs_write( s, 5, sps->vui.hrd.i_initial_cpb_removal_delay_length - 1 );
            bs_write( s, 5, sps->vui.hrd.i_cpb_removal_delay_length - 1 );
            bs_write( s, 5, sps->vui.hrd.i_dpb_output_delay_length - 1 );
            bs_write( s, 5, sps->vui.hrd.i_time_offset_length );
        }

        bs_write1( s, sps->vui.b_vcl_hrd_parameters_present );

        if( sps->vui.b_nal_hrd_parameters_present || sps->vui.b_vcl_hrd_parameters_present )
            bs_write1( s, 0 );   /* low_delay_hrd_flag */

        bs_write1( s, sps->vui.b_pic_struct_present );
        bs_write1( s, sps->vui.b_bitstream_restriction );
        if( sps->vui.b_bitstream_restriction )
        {
            bs_write1( s, sps->vui.b_motion_vectors_over_pic_boundaries );
            bs_write_ue( s, sps->vui.i_max_bytes_per_pic_denom );
            bs_write_ue( s, sps->vui.i_max_bits_per_mb_denom );
            bs_write_ue( s, sps->vui.i_log2_max_mv_length_horizontal );
            bs_write_ue( s, sps->vui.i_log2_max_mv_length_vertical );
            bs_write_ue( s, sps->vui.i_num_reorder_frames );
            bs_write_ue( s, sps->vui.i_max_dec_frame_buffering );
        }
    }

    bs_rbsp_trailing( s );
    bs_flush( s );
}