int ff_h264_decode_mb_cavlc(const H264Context *h, H264SliceContext *sl) { int mb_xy; int partition_count; unsigned int mb_type, cbp; int dct8x8_allowed= h->ps.pps->transform_8x8_mode; int decode_chroma = h->ps.sps->chroma_format_idc == 1 || h->ps.sps->chroma_format_idc == 2; const int pixel_shift = h->pixel_shift; mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride; ff_tlog(h->avctx, "pic:%d mb:%d/%d\n", h->poc.frame_num, sl->mb_x, sl->mb_y); cbp = 0; /* avoid warning. FIXME: find a solution without slowing down the code */ if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { if (sl->mb_skip_run == -1) sl->mb_skip_run = get_ue_golomb_long(&sl->gb); if (sl->mb_skip_run--) { if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) { if (sl->mb_skip_run == 0) sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb); } decode_mb_skip(h, sl); return 0; } } if (FRAME_MBAFF(h)) { if ((sl->mb_y & 1) == 0) sl->mb_mbaff = sl->mb_field_decoding_flag = get_bits1(&sl->gb); } sl->prev_mb_skipped = 0; mb_type= get_ue_golomb(&sl->gb); if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { if(mb_type < 23){ partition_count = ff_h264_b_mb_type_info[mb_type].partition_count; mb_type = ff_h264_b_mb_type_info[mb_type].type; }else{ mb_type -= 23; goto decode_intra_mb; } } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) { if(mb_type < 5){ partition_count = ff_h264_p_mb_type_info[mb_type].partition_count; mb_type = ff_h264_p_mb_type_info[mb_type].type; }else{ mb_type -= 5; goto decode_intra_mb; } }else{ av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_I); if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type) mb_type--; decode_intra_mb: if(mb_type > 25){ av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y); return -1; } partition_count=0; cbp = ff_h264_i_mb_type_info[mb_type].cbp; sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode; mb_type = ff_h264_i_mb_type_info[mb_type].type; } if (MB_FIELD(sl)) mb_type |= MB_TYPE_INTERLACED; h->slice_table[mb_xy] = sl->slice_num; if(IS_INTRA_PCM(mb_type)){ const int mb_size = ff_h264_mb_sizes[h->ps.sps->chroma_format_idc] * h->ps.sps->bit_depth_luma; // We assume these blocks are very rare so we do not optimize it. sl->intra_pcm_ptr = align_get_bits(&sl->gb); if (get_bits_left(&sl->gb) < mb_size) { av_log(h->avctx, AV_LOG_ERROR, "Not enough data for an intra PCM block.\n"); return AVERROR_INVALIDDATA; } skip_bits_long(&sl->gb, mb_size); // In deblocking, the quantizer is 0 h->cur_pic.qscale_table[mb_xy] = 0; // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 48); h->cur_pic.mb_type[mb_xy] = mb_type; return 0; } fill_decode_neighbors(h, sl, mb_type); fill_decode_caches(h, sl, mb_type); //mb_pred if(IS_INTRA(mb_type)){ int pred_mode; // init_top_left_availability(h); if(IS_INTRA4x4(mb_type)){ int i; int di = 1; if(dct8x8_allowed && get_bits1(&sl->gb)){ mb_type |= MB_TYPE_8x8DCT; di = 4; } // fill_intra4x4_pred_table(h); for(i=0; i<16; i+=di){ int mode = pred_intra_mode(h, sl, i); if(!get_bits1(&sl->gb)){ const int rem_mode= get_bits(&sl->gb, 3); mode = rem_mode + (rem_mode >= mode); } if(di==4) fill_rectangle(&sl->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1); else sl->intra4x4_pred_mode_cache[scan8[i]] = mode; } write_back_intra_pred_mode(h, sl); if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx, sl->top_samples_available, sl->left_samples_available) < 0) return -1; }else{ sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available, sl->left_samples_available, sl->intra16x16_pred_mode, 0); if (sl->intra16x16_pred_mode < 0) return -1; } if(decode_chroma){ pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available, sl->left_samples_available, get_ue_golomb_31(&sl->gb), 1); if(pred_mode < 0) return -1; sl->chroma_pred_mode = pred_mode; } else { sl->chroma_pred_mode = DC_128_PRED8x8; } }else if(partition_count==4){ int i, j, sub_partition_count[4], list, ref[2][4]; if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { for(i=0; i<4; i++){ sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb); if(sl->sub_mb_type[i] >=13){ av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y); return -1; } sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count; sl->sub_mb_type[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type; } if( IS_DIRECT(sl->sub_mb_type[0]|sl->sub_mb_type[1]|sl->sub_mb_type[2]|sl->sub_mb_type[3])) { ff_h264_pred_direct_motion(h, sl, &mb_type); sl->ref_cache[0][scan8[4]] = sl->ref_cache[1][scan8[4]] = sl->ref_cache[0][scan8[12]] = sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; } }else{ av_assert2(sl->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? for(i=0; i<4; i++){ sl->sub_mb_type[i]= get_ue_golomb_31(&sl->gb); if(sl->sub_mb_type[i] >=4){ av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", sl->sub_mb_type[i], sl->mb_x, sl->mb_y); return -1; } sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count; sl->sub_mb_type[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type; } } for (list = 0; list < sl->list_count; list++) { int ref_count = IS_REF0(mb_type) ? 1 : sl->ref_count[list] << MB_MBAFF(sl); for(i=0; i<4; i++){ if(IS_DIRECT(sl->sub_mb_type[i])) continue; if(IS_DIR(sl->sub_mb_type[i], 0, list)){ unsigned int tmp; if(ref_count == 1){ tmp= 0; }else if(ref_count == 2){ tmp= get_bits1(&sl->gb)^1; }else{ tmp= get_ue_golomb_31(&sl->gb); if(tmp>=ref_count){ av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); return -1; } } ref[list][i]= tmp; }else{ //FIXME ref[list][i] = -1; } } } if(dct8x8_allowed) dct8x8_allowed = get_dct8x8_allowed(h, sl); for (list = 0; list < sl->list_count; list++) { for(i=0; i<4; i++){ if(IS_DIRECT(sl->sub_mb_type[i])) { sl->ref_cache[list][ scan8[4*i] ] = sl->ref_cache[list][ scan8[4*i]+1 ]; continue; } sl->ref_cache[list][ scan8[4*i] ]=sl->ref_cache[list][ scan8[4*i]+1 ]= sl->ref_cache[list][ scan8[4*i]+8 ]=sl->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; if(IS_DIR(sl->sub_mb_type[i], 0, list)){ const int sub_mb_type= sl->sub_mb_type[i]; const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; for(j=0; j<sub_partition_count[i]; j++){ int mx, my; const int index= 4*i + block_width*j; int16_t (* mv_cache)[2]= &sl->mv_cache[list][ scan8[index] ]; pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my); mx += get_se_golomb(&sl->gb); my += get_se_golomb(&sl->gb); ff_tlog(h->avctx, "final mv:%d %d\n", mx, my); if(IS_SUB_8X8(sub_mb_type)){ mv_cache[ 1 ][0]= mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; mv_cache[ 1 ][1]= mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; }else if(IS_SUB_8X4(sub_mb_type)){ mv_cache[ 1 ][0]= mx; mv_cache[ 1 ][1]= my; }else if(IS_SUB_4X8(sub_mb_type)){ mv_cache[ 8 ][0]= mx; mv_cache[ 8 ][1]= my; } mv_cache[ 0 ][0]= mx; mv_cache[ 0 ][1]= my; } }else{ uint32_t *p= (uint32_t *)&sl->mv_cache[list][ scan8[4*i] ][0]; p[0] = p[1]= p[8] = p[9]= 0; } } } }else if(IS_DIRECT(mb_type)){ ff_h264_pred_direct_motion(h, sl, &mb_type); dct8x8_allowed &= h->ps.sps->direct_8x8_inference_flag; }else{ int list, mx, my, i; //FIXME we should set ref_idx_l? to 0 if we use that later ... if(IS_16X16(mb_type)){ for (list = 0; list < sl->list_count; list++) { unsigned int val; if(IS_DIR(mb_type, 0, list)){ unsigned rc = sl->ref_count[list] << MB_MBAFF(sl); if (rc == 1) { val= 0; } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ val= get_ue_golomb_31(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); } } for (list = 0; list < sl->list_count; list++) { if(IS_DIR(mb_type, 0, list)){ pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my); mx += get_se_golomb(&sl->gb); my += get_se_golomb(&sl->gb); ff_tlog(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); } } } else if(IS_16X8(mb_type)){ for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ unsigned rc = sl->ref_count[list] << MB_MBAFF(sl); if (rc == 1) { val= 0; } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ val= get_ue_golomb_31(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } }else val= LIST_NOT_USED&0xFF; fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); } } for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my); mx += get_se_golomb(&sl->gb); my += get_se_golomb(&sl->gb); ff_tlog(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else val=0; fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4); } } }else{ av_assert2(IS_8X16(mb_type)); for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ //FIXME optimize unsigned rc = sl->ref_count[list] << MB_MBAFF(sl); if (rc == 1) { val= 0; } else if (rc == 2) { val= get_bits1(&sl->gb)^1; }else{ val= get_ue_golomb_31(&sl->gb); if (val >= rc) { av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } }else val= LIST_NOT_USED&0xFF; fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); } } for (list = 0; list < sl->list_count; list++) { for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); mx += get_se_golomb(&sl->gb); my += get_se_golomb(&sl->gb); ff_tlog(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else val=0; fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4); } } } } if(IS_INTER(mb_type)) write_back_motion(h, sl, mb_type); if(!IS_INTRA16x16(mb_type)){ cbp= get_ue_golomb(&sl->gb); if(decode_chroma){ if(cbp > 47){ av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y); return -1; } if (IS_INTRA4x4(mb_type)) cbp = ff_h264_golomb_to_intra4x4_cbp[cbp]; else cbp = ff_h264_golomb_to_inter_cbp[cbp]; }else{ if(cbp > 15){ av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, sl->mb_x, sl->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; else cbp= golomb_to_inter_cbp_gray[cbp]; } } else { if (!decode_chroma && cbp>15) { av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n"); return AVERROR_INVALIDDATA; } } if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ mb_type |= MB_TYPE_8x8DCT*get_bits1(&sl->gb); } sl->cbp= h->cbp_table[mb_xy]= cbp; h->cur_pic.mb_type[mb_xy] = mb_type; if(cbp || IS_INTRA16x16(mb_type)){ int i4x4, i8x8, chroma_idx; int dquant; int ret; GetBitContext *gb = &sl->gb; const uint8_t *scan, *scan8x8; const int max_qp = 51 + 6 * (h->ps.sps->bit_depth_luma - 8); if(IS_INTERLACED(mb_type)){ scan8x8 = sl->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; scan = sl->qscale ? h->field_scan : h->field_scan_q0; }else{ scan8x8 = sl->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; scan = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0; } dquant= get_se_golomb(&sl->gb); sl->qscale += dquant; if (((unsigned)sl->qscale) > max_qp){ if (sl->qscale < 0) sl->qscale += max_qp + 1; else sl->qscale -= max_qp+1; if (((unsigned)sl->qscale) > max_qp){ av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, sl->mb_x, sl->mb_y); return -1; } } sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale); sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale); if ((ret = decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ) { return -1; } h->cbp_table[mb_xy] |= ret << 12; if (CHROMA444(h)) { if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ) { return -1; } if (decode_luma_residual(h, sl, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ) { return -1; } } else { const int num_c8x8 = h->ps.sps->chroma_format_idc; if(cbp&0x30){ for(chroma_idx=0; chroma_idx<2; chroma_idx++) if (decode_residual(h, sl, gb, sl->mb + ((256 + 16*16*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX + chroma_idx, CHROMA422(h) ? ff_h264_chroma422_dc_scan : ff_h264_chroma_dc_scan, NULL, 4 * num_c8x8) < 0) { return -1; } } if(cbp&0x20){ for(chroma_idx=0; chroma_idx<2; chroma_idx++){ const uint32_t *qmul = h->ps.pps->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[chroma_idx]]; int16_t *mb = sl->mb + (16*(16 + 16*chroma_idx) << pixel_shift); for (i8x8 = 0; i8x8<num_c8x8; i8x8++) { for (i4x4 = 0; i4x4 < 4; i4x4++) { const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4; if (decode_residual(h, sl, gb, mb, index, scan + 1, qmul, 15) < 0) return -1; mb += 16 << pixel_shift; } } } }else{ fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } } }else{ fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } h->cur_pic.qscale_table[mb_xy] = sl->qscale; write_back_non_zero_count(h, sl); return 0; }


static void client_close(NBDClient *client) { if (client->closing) { return; } client->closing = true; /* Force requests to finish. They will drop their own references, * then we'll close the socket and free the NBDClient. */ qio_channel_shutdown(client->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); /* Also tell the client, so that they release their reference. */ if (client->close) { client->close(client); } }


static int init_tile(Jpeg2000DecoderContext *s, int tileno) { int compno; int tilex = tileno % s->numXtiles; int tiley = tileno / s->numXtiles; Jpeg2000Tile *tile = s->tile + tileno; if (!tile->comp) return AVERROR(ENOMEM); tile->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x); tile->coord[0][1] = FFMIN((tilex + 1) * s->tile_width + s->tile_offset_x, s->width); tile->coord[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y); tile->coord[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height); for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno; Jpeg2000QuantStyle *qntsty = tile->qntsty + compno; int ret; // global bandno comp->coord_o[0][0] = tile->coord[0][0]; comp->coord_o[0][1] = tile->coord[0][1]; comp->coord_o[1][0] = tile->coord[1][0]; comp->coord_o[1][1] = tile->coord[1][1]; if (compno) { comp->coord_o[0][0] /= s->cdx[compno]; comp->coord_o[0][1] /= s->cdx[compno]; comp->coord_o[1][0] /= s->cdy[compno]; comp->coord_o[1][1] /= s->cdy[compno]; } comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor); comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor); comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor); comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor); if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno], s->avctx)) return ret; } return 0; }


void ff_avg_h264_qpel8_mc11_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_hv_qrt_and_aver_dst_8x8_msa(src - 2, src - (stride * 2), stride, dst, stride); }


int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length) { AVBufferRef *pps_buf; const SPS *sps; unsigned int pps_id = get_ue_golomb(gb); PPS *pps; int qp_bd_offset; int bits_left; int ret; if (pps_id >= MAX_PPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); return AVERROR_INVALIDDATA; pps_buf = av_buffer_allocz(sizeof(*pps)); if (!pps_buf) return AVERROR(ENOMEM); pps = (PPS*)pps_buf->data; pps->data_size = gb->buffer_end - gb->buffer; if (pps->data_size > sizeof(pps->data)) { av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS " "(%"SIZE_SPECIFIER" > %"SIZE_SPECIFIER")\n", pps->data_size, sizeof(pps->data)); pps->data_size = sizeof(pps->data); memcpy(pps->data, gb->buffer, pps->data_size); pps->sps_id = get_ue_golomb_31(gb); if ((unsigned)pps->sps_id >= MAX_SPS_COUNT || !ps->sps_list[pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "sps_id %u out of range\n", pps->sps_id); sps = (const SPS*)ps->sps_list[pps->sps_id]->data; if (sps->bit_depth_luma > 14) { av_log(avctx, AV_LOG_ERROR, "Invalid luma bit depth=%d\n", sps->bit_depth_luma); } else if (sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13) { av_log(avctx, AV_LOG_ERROR, "Unimplemented luma bit depth=%d\n", sps->bit_depth_luma); ret = AVERROR_PATCHWELCOME; pps->cabac = get_bits1(gb); pps->pic_order_present = get_bits1(gb); pps->slice_group_count = get_ue_golomb(gb) + 1; if (pps->slice_group_count > 1) { pps->mb_slice_group_map_type = get_ue_golomb(gb); av_log(avctx, AV_LOG_ERROR, "FMO not supported\n"); switch (pps->mb_slice_group_map_type) { case 0: #if 0 | for (i = 0; i <= num_slice_groups_minus1; i++) | | | | run_length[i] |1 |ue(v) | #endif break; case 2: #if 0 | for (i = 0; i < num_slice_groups_minus1; i++) { | | | | top_left_mb[i] |1 |ue(v) | | bottom_right_mb[i] |1 |ue(v) | | } | | | #endif break; case 3: case 4: case 5: #if 0 | slice_group_change_direction_flag |1 |u(1) | | slice_group_change_rate_minus1 |1 |ue(v) | #endif break; case 6: #if 0 | slice_group_id_cnt_minus1 |1 |ue(v) | | for (i = 0; i <= slice_group_id_cnt_minus1; i++)| | | | slice_group_id[i] |1 |u(v) | #endif break; pps->ref_count[0] = get_ue_golomb(gb) + 1; pps->ref_count[1] = get_ue_golomb(gb) + 1; if (pps->ref_count[0] - 1 > 32 - 1 || pps->ref_count[1] - 1 > 32 - 1) { av_log(avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); qp_bd_offset = 6 * (sps->bit_depth_luma - 8); pps->weighted_pred = get_bits1(gb); pps->weighted_bipred_idc = get_bits(gb, 2); pps->init_qp = get_se_golomb(gb) + 26 + qp_bd_offset; pps->init_qs = get_se_golomb(gb) + 26 + qp_bd_offset; pps->chroma_qp_index_offset[0] = get_se_golomb(gb); if (pps->chroma_qp_index_offset[0] < -12 || pps->chroma_qp_index_offset[0] > 12) { pps->deblocking_filter_parameters_present = get_bits1(gb); pps->constrained_intra_pred = get_bits1(gb); pps->redundant_pic_cnt_present = get_bits1(gb); pps->transform_8x8_mode = 0; memcpy(pps->scaling_matrix4, sps->scaling_matrix4, sizeof(pps->scaling_matrix4)); memcpy(pps->scaling_matrix8, sps->scaling_matrix8, sizeof(pps->scaling_matrix8)); bits_left = bit_length - get_bits_count(gb); if (bits_left > 0 && more_rbsp_data_in_pps(sps, avctx)) { pps->transform_8x8_mode = get_bits1(gb); decode_scaling_matrices(gb, sps, pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); // second_chroma_qp_index_offset pps->chroma_qp_index_offset[1] = get_se_golomb(gb); } else { pps->chroma_qp_index_offset[1] = pps->chroma_qp_index_offset[0]; build_qp_table(pps, 0, pps->chroma_qp_index_offset[0], sps->bit_depth_luma); build_qp_table(pps, 1, pps->chroma_qp_index_offset[1], sps->bit_depth_luma); init_dequant_tables(pps, sps); if (pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) pps->chroma_qp_diff = 1; if (avctx->debug & FF_DEBUG_PICT_INFO) { av_log(avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n", pps_id, pps->sps_id, pps->cabac ? "CABAC" : "CAVLC", pps->slice_group_count, pps->ref_count[0], pps->ref_count[1], pps->weighted_pred ? "weighted" : "", pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], pps->deblocking_filter_parameters_present ? "LPAR" : "", pps->constrained_intra_pred ? "CONSTR" : "", pps->redundant_pic_cnt_present ? "REDU" : "", pps->transform_8x8_mode ? "8x8DCT" : ""); remove_pps(ps, pps_id); ps->pps_list[pps_id] = pps_buf; return 0; fail: av_buffer_unref(&pps_buf); return ret;


static int vmdk_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { BDRVVmdkState *s = bs->opaque; int index_in_cluster, n, ret; uint64_t cluster_offset; while (nb_sectors > 0) { cluster_offset = get_cluster_offset(bs, sector_num << 9, 0); index_in_cluster = sector_num % s->cluster_sectors; n = s->cluster_sectors - index_in_cluster; if (n > nb_sectors) n = nb_sectors; if (!cluster_offset) { // try to read from parent image, if exist if (s->hd->backing_hd) { if (!vmdk_is_cid_valid(bs)) return -1; ret = bdrv_read(s->hd->backing_hd, sector_num, buf, n); if (ret < 0) return -1; } else { memset(buf, 0, 512 * n); } } else { if(bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512) != n * 512) return -1; } nb_sectors -= n; sector_num += n; buf += n * 512; } return 0; }


int32_t ff_mlp_pack_output(int32_t lossless_check_data, uint16_t blockpos, int32_t (*sample_buffer)[MAX_CHANNELS], void *data, uint8_t *ch_assign, int8_t *output_shift, uint8_t max_matrix_channel, int is32) { unsigned int i, out_ch = 0; int32_t *data_32 = data; int16_t *data_16 = data; for (i = 0; i < blockpos; i++) { for (out_ch = 0; out_ch <= max_matrix_channel; out_ch++) { int mat_ch = ch_assign[out_ch]; int32_t sample = sample_buffer[i][mat_ch] << output_shift[mat_ch]; lossless_check_data ^= (sample & 0xffffff) << mat_ch; if (is32) *data_32++ = sample << 8; else *data_16++ = sample >> 8; } } return lossless_check_data; }


static void an5206_init(MachineState *machine) { ram_addr_t ram_size = machine->ram_size; const char *cpu_model = machine->cpu_model; const char *kernel_filename = machine->kernel_filename; M68kCPU *cpu; CPUM68KState *env; int kernel_size; uint64_t elf_entry; hwaddr entry; MemoryRegion *address_space_mem = get_system_memory(); MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *sram = g_new(MemoryRegion, 1); if (!cpu_model) { cpu_model = "m5206"; } cpu = M68K_CPU(cpu_generic_init(TYPE_M68K_CPU, cpu_model)); if (!cpu) { error_report("Unable to find m68k CPU definition"); exit(1); } env = &cpu->env; /* Initialize CPU registers. */ env->vbr = 0; /* TODO: allow changing MBAR and RAMBAR. */ env->mbar = AN5206_MBAR_ADDR | 1; env->rambar0 = AN5206_RAMBAR_ADDR | 1; /* DRAM at address zero */ memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size); memory_region_add_subregion(address_space_mem, 0, ram); /* Internal SRAM. */ memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal); memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram); mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu); /* Load kernel. */ if (!kernel_filename) { if (qtest_enabled()) { return; } fprintf(stderr, "Kernel image must be specified\n"); exit(1); } kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry, NULL, NULL, 1, EM_68K, 0, 0); entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL, NULL, NULL); } if (kernel_size < 0) { kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, ram_size - KERNEL_LOAD_ADDR); entry = KERNEL_LOAD_ADDR; } if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } env->pc = entry; }


static int mv_read_header(AVFormatContext *avctx) { MvContext *mv = avctx->priv_data; AVIOContext *pb = avctx->pb; AVStream *ast = NULL, *vst = NULL; //initialization to suppress warning int version, i; avio_skip(pb, 4); version = avio_rb16(pb); if (version == 2) { uint64_t timestamp; int v; avio_skip(pb, 22); /* allocate audio track first to prevent unnecessary seeking (audio packet always precede video packet for a given frame) */ ast = avformat_new_stream(avctx, NULL); if (!ast) return AVERROR(ENOMEM); vst = avformat_new_stream(avctx, NULL); if (!vst) return AVERROR(ENOMEM); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->time_base = (AVRational){1, 15}; vst->nb_frames = avio_rb32(pb); v = avio_rb32(pb); switch (v) { case 1: vst->codec->codec_id = AV_CODEC_ID_MVC1; break; case 2: vst->codec->pix_fmt = AV_PIX_FMT_ARGB; vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; break; default: av_log_ask_for_sample(avctx, "unknown video compression %i\n", v); break; } vst->codec->codec_tag = 0; vst->codec->width = avio_rb32(pb); vst->codec->height = avio_rb32(pb); avio_skip(pb, 12); ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->nb_frames = vst->nb_frames; ast->codec->sample_rate = avio_rb32(pb); avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate); ast->codec->channels = avio_rb32(pb); ast->codec->channel_layout = (ast->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; v = avio_rb32(pb); if (v == AUDIO_FORMAT_SIGNED) { ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; } else { av_log_ask_for_sample(avctx, "unknown audio compression (format %i)\n", v); } avio_skip(pb, 12); var_read_metadata(avctx, "title", 0x80); var_read_metadata(avctx, "comment", 0x100); avio_skip(pb, 0x80); timestamp = 0; for (i = 0; i < vst->nb_frames; i++) { uint32_t pos = avio_rb32(pb); uint32_t asize = avio_rb32(pb); uint32_t vsize = avio_rb32(pb); avio_skip(pb, 8); av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME); av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME); timestamp += asize / (ast->codec->channels * 2); } } else if (!version && avio_rb16(pb) == 3) { avio_skip(pb, 4); read_table(avctx, NULL, parse_global_var); if (mv->nb_audio_tracks > 1) { av_log_ask_for_sample(avctx, "multiple audio streams\n"); return AVERROR_PATCHWELCOME; } else if (mv->nb_audio_tracks) { ast = avformat_new_stream(avctx, NULL); if (!ast) return AVERROR(ENOMEM); ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; /* temporarily store compression value in codec_tag; format value in codec_id */ read_table(avctx, ast, parse_audio_var); if (ast->codec->codec_tag == 100 && ast->codec->codec_id == AUDIO_FORMAT_SIGNED && ast->codec->bits_per_coded_sample == 16) { ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; } else { av_log_ask_for_sample(avctx, "unknown audio compression %i (format %i, width %i)\n", ast->codec->codec_tag, ast->codec->codec_id, ast->codec->bits_per_coded_sample); ast->codec->codec_id = AV_CODEC_ID_NONE; } ast->codec->codec_tag = 0; } if (mv->nb_video_tracks > 1) { av_log_ask_for_sample(avctx, "multiple video streams\n"); return AVERROR_PATCHWELCOME; } else if (mv->nb_video_tracks) { vst = avformat_new_stream(avctx, NULL); if (!vst) return AVERROR(ENOMEM); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; read_table(avctx, vst, parse_video_var); } if (mv->nb_audio_tracks) read_index(pb, ast); if (mv->nb_video_tracks) read_index(pb, vst); } else { av_log_ask_for_sample(avctx, "unknown version %i\n", version); return AVERROR_PATCHWELCOME; } return 0; }


void qsb_free(QEMUSizedBuffer *qsb) { size_t i; if (!qsb) { return; } for (i = 0; i < qsb->n_iov; i++) { g_free(qsb->iov[i].iov_base); } g_free(qsb->iov); g_free(qsb); }


static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MPADecodeContext *s = avctx->priv_data; uint32_t header; int out_size; OUT_INT *out_samples = data; if(buf_size < HEADER_SIZE) return -1; header = AV_RB32(buf); if(ff_mpa_check_header(header) < 0){ av_log(avctx, AV_LOG_ERROR, "Header missing\n"); return -1; } if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { /* free format: prepare to compute frame size */ s->frame_size = -1; return -1; } /* update codec info */ avctx->channels = s->nb_channels; avctx->bit_rate = s->bit_rate; avctx->sub_id = s->layer; if(*data_size < 1152*avctx->channels*sizeof(OUT_INT)) return -1; if(s->frame_size<=0 || s->frame_size > buf_size){ av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); return -1; }else if(s->frame_size < buf_size){ av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n"); buf_size= s->frame_size; } out_size = mp_decode_frame(s, out_samples, buf, buf_size); if(out_size>=0){ *data_size = out_size; avctx->sample_rate = s->sample_rate; //FIXME maybe move the other codec info stuff from above here too }else av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed s->frame_size = 0; return buf_size; }


static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory, hwaddr base, qemu_irq irq, omap_clk clk) { struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) g_malloc0(sizeof(struct omap_32khz_timer_s)); s->timer.irq = irq; s->timer.clk = clk; s->timer.timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_timer_tick, &s->timer); omap_os_timer_reset(s); omap_timer_clk_setup(&s->timer); memory_region_init_io(&s->iomem, NULL, &omap_os_timer_ops, s, "omap-os-timer", 0x800); memory_region_add_subregion(memory, base, &s->iomem); return s; }


static bool check_irqchip_in_kernel(void) { if (kvm_irqchip_in_kernel()) { return true; } error_report("pci-assign: error: requires KVM with in-kernel irqchip " "enabled"); return false; }


static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){ RateControlContext *rcc= &s->rc_context; AVCodecContext *a= s->avctx; double q, bits; const int pict_type= rce->new_pict_type; const double mb_num= s->mb_num; int i; double const_values[]={ M_PI, M_E, rce->i_tex_bits*rce->qscale, rce->p_tex_bits*rce->qscale, (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale, rce->mv_bits/mb_num, rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code, rce->i_count/mb_num, rce->mc_mb_var_sum/mb_num, rce->mb_var_sum/mb_num, rce->pict_type == I_TYPE, rce->pict_type == P_TYPE, rce->pict_type == B_TYPE, rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type], a->qcompress, /* rcc->last_qscale_for[I_TYPE], rcc->last_qscale_for[P_TYPE], rcc->last_qscale_for[B_TYPE], rcc->next_non_b_qscale,*/ rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE], rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE], rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE], rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE], (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type], 0 }; bits= ff_parse_eval(rcc->rc_eq_eval, const_values, rce); if (isnan(bits)) { av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq); return -1; } rcc->pass1_rc_eq_output_sum+= bits; bits*=rate_factor; if(bits<0.0) bits=0.0; bits+= 1.0; //avoid 1/0 issues /* user override */ for(i=0; i<s->avctx->rc_override_count; i++){ RcOverride *rco= s->avctx->rc_override; if(rco[i].start_frame > frame_num) continue; if(rco[i].end_frame < frame_num) continue; if(rco[i].qscale) bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it? else bits*= rco[i].quality_factor; } q= bits2qp(rce, bits); /* I/B difference */ if (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0) q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset; else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0) q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset; return q; }


static int hpet_start_timer(struct qemu_alarm_timer *t) { struct hpet_info info; int r, fd; fd = open("/dev/hpet", O_RDONLY); if (fd < 0) return -1; /* Set frequency */ r = ioctl(fd, HPET_IRQFREQ, RTC_FREQ); if (r < 0) { fprintf(stderr, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n" "error, but for better emulation accuracy type:\n" "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n"); goto fail; } /* Check capabilities */ r = ioctl(fd, HPET_INFO, &info); if (r < 0) goto fail; /* Enable periodic mode */ r = ioctl(fd, HPET_EPI, 0); if (info.hi_flags && (r < 0)) goto fail; /* Enable interrupt */ r = ioctl(fd, HPET_IE_ON, 0); if (r < 0) goto fail; enable_sigio_timer(fd); t->priv = (void *)(long)fd; return 0; fail: close(fd); return -1; }


static void cmd_read_cd(IDEState *s, uint8_t* buf) { int nb_sectors, lba, transfer_request; nb_sectors = (buf[6] << 16) | (buf[7] << 8) | buf[8]; lba = ube32_to_cpu(buf + 2); if (nb_sectors == 0) { ide_atapi_cmd_ok(s); return; } transfer_request = buf[9]; switch(transfer_request & 0xf8) { case 0x00: /* nothing */ ide_atapi_cmd_ok(s); break; case 0x10: /* normal read */ ide_atapi_cmd_read(s, lba, nb_sectors, 2048); break; case 0xf8: /* read all data */ ide_atapi_cmd_read(s, lba, nb_sectors, 2352); break; default: ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_INV_FIELD_IN_CMD_PACKET); break; } }


static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end, const char *in, int x1, int y1, int x2, int y2) { char c, *param, buffer[128], tmp[128]; int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0; SrtStack stack[16]; stack[0].tag[0] = 0; strcpy(stack[0].param[PARAM_SIZE], "{\\fs}"); strcpy(stack[0].param[PARAM_COLOR], "{\\c}"); strcpy(stack[0].param[PARAM_FACE], "{\\fn}"); if (x1 >= 0 && y1 >= 0) { if (x2 >= 0 && y2 >= 0 && (x2 != x1 || y2 != y1)) out += snprintf(out, out_end-out, "{\\an1}{\\move(%d,%d,%d,%d)}", x1, y1, x2, y2); else out += snprintf(out, out_end-out, "{\\an1}{\\pos(%d,%d)}", x1, y1); } for (; out < out_end && !end && *in; in++) { switch (*in) { case '\r': break; case '\n': if (line_start) { end = 1; break; } while (out[-1] == ' ') out--; out += snprintf(out, out_end-out, "\\N"); line_start = 1; break; case ' ': if (!line_start) *out++ = *in; break; case '{': /* skip all {\xxx} substrings except for {\an%d} and all microdvd like styles such as {Y:xxx} */ an += sscanf(in, "{\\an%*1u}%c", &c) == 1; if ((an != 1 && sscanf(in, "{\\%*[^}]}%n%c", &len, &c) > 0) || sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]}%n%c", &len, &c) > 0) { in += len - 1; } else *out++ = *in; break; case '<': tag_close = in[1] == '/'; if (sscanf(in+tag_close+1, "%127[^>]>%n%c", buffer, &len,&c) >= 2) { if ((param = strchr(buffer, ' '))) *param++ = 0; if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) || ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, buffer))) { int i, j, unknown = 0; in += len + tag_close; if (!tag_close) memset(stack+sptr, 0, sizeof(*stack)); if (!strcmp(buffer, "font")) { if (tag_close) { for (i=PARAM_NUMBER-1; i>=0; i--) if (stack[sptr-1].param[i][0]) for (j=sptr-2; j>=0; j--) if (stack[j].param[i][0]) { out += snprintf(out, out_end-out, stack[j].param[i]); break; } } else { while (param) { if (!strncmp(param, "size=", 5)) { unsigned font_size; param += 5 + (param[5] == '"'); if (sscanf(param, "%u", &font_size) == 1) { snprintf(stack[sptr].param[PARAM_SIZE], sizeof(stack[0].param[PARAM_SIZE]), "{\\fs%u}", font_size); } } else if (!strncmp(param, "color=", 6)) { param += 6 + (param[6] == '"'); snprintf(stack[sptr].param[PARAM_COLOR], sizeof(stack[0].param[PARAM_COLOR]), "{\\c&H%X&}", html_color_parse(avctx, param)); } else if (!strncmp(param, "face=", 5)) { param += 5 + (param[5] == '"'); len = strcspn(param, param[-1] == '"' ? "\"" :" "); av_strlcpy(tmp, param, FFMIN(sizeof(tmp), len+1)); param += len; snprintf(stack[sptr].param[PARAM_FACE], sizeof(stack[0].param[PARAM_FACE]), "{\\fn%s}", tmp); } if ((param = strchr(param, ' '))) param++; } for (i=0; i<PARAM_NUMBER; i++) if (stack[sptr].param[i][0]) out += snprintf(out, out_end-out, stack[sptr].param[i]); } } else if (!buffer[1] && strspn(buffer, "bisu") == 1) { out += snprintf(out, out_end-out, "{\\%c%d}", buffer[0], !tag_close); } else { unknown = 1; snprintf(tmp, sizeof(tmp), "</%s>", buffer); } if (tag_close) { sptr--; } else if (unknown && !strstr(in, tmp)) { in -= len + tag_close; *out++ = *in; } else av_strlcpy(stack[sptr++].tag, buffer, sizeof(stack[0].tag)); break; } } default: *out++ = *in; break; } if (*in != ' ' && *in != '\r' && *in != '\n') line_start = 0; } out = FFMIN(out, out_end-3); while (!strncmp(out-2, "\\N", 2)) out -= 2; while (out[-1] == ' ') out--; out += snprintf(out, out_end-out, "\r\n"); return in; }


void tcg_prologue_init(TCGContext *s) { /* init global prologue and epilogue */ s->code_buf = s->code_gen_prologue; s->code_ptr = s->code_buf; tcg_target_qemu_prologue(s); flush_icache_range((tcg_target_ulong)s->code_buf, (tcg_target_ulong)s->code_ptr);


static int decode_slice(AVCodecContext *c, void *arg) { FFV1Context *fs = *(void **)arg; FFV1Context *f = fs->avctx->priv_data; int width, height, x, y, ret; const int ps = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR) ? (c->bits_per_raw_sample > 8) + 1 : 4; AVFrame *const p = f->cur; if (f->version > 2) { if (decode_slice_header(f, fs) < 0) { fs->slice_damaged = 1; return AVERROR_INVALIDDATA; } } if ((ret = ffv1_init_slice_state(f, fs)) < 0) return ret; if (f->cur->key_frame) ffv1_clear_slice_state(f, fs); width = fs->slice_width; height = fs->slice_height; x = fs->slice_x; y = fs->slice_y; if (!fs->ac) { if (f->version == 3 && f->minor_version > 1 || f->version > 3) get_rac(&fs->c, (uint8_t[]) { 129 }); fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; init_get_bits(&fs->gb, fs->c.bytestream_start + fs->ac_byte_count, (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8); } av_assert1(width && height); if (f->colorspace == 0) { const int chroma_width = -((-width) >> f->chroma_h_shift); const int chroma_height = -((-height) >> f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; decode_plane(fs, p->data[0] + ps * x + y * p->linesize[0], width, height, p->linesize[0], 0); if (f->chroma_planes) { decode_plane(fs, p->data[1] + ps * cx + cy * p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1); decode_plane(fs, p->data[2] + ps * cx + cy * p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1); } if (fs->transparency) decode_plane(fs, p->data[3] + ps * x + y * p->linesize[3], width, height, p->linesize[3], 2); } else { uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2] }; decode_rgb_frame(fs, planes, width, height, p->linesize); } if (fs->ac && f->version > 2) { int v; get_rac(&fs->c, (uint8_t[]) { 129 }); v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5 * f->ec; if (v) { av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); fs->slice_damaged = 1; } } emms_c(); return 0; }


int text_console_init(QemuOpts *opts, CharDriverState **_chr) { CharDriverState *chr; TextConsole *s; unsigned width; unsigned height; chr = g_malloc0(sizeof(CharDriverState)); if (n_text_consoles == 128) { fprintf(stderr, "Too many text consoles\n"); exit(1); } text_consoles[n_text_consoles] = chr; n_text_consoles++; width = qemu_opt_get_number(opts, "width", 0); if (width == 0) width = qemu_opt_get_number(opts, "cols", 0) * FONT_WIDTH; height = qemu_opt_get_number(opts, "height", 0); if (height == 0) height = qemu_opt_get_number(opts, "rows", 0) * FONT_HEIGHT; if (width == 0 || height == 0) { s = new_console(NULL, TEXT_CONSOLE); } else { s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE); } if (!s) { g_free(chr); return -EBUSY; } s->chr = chr; s->g_width = width; s->g_height = height; chr->opaque = s; chr->chr_set_echo = text_console_set_echo; *_chr = chr; return 0; }


_eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags, size_t rthdr_offset, struct ip6_ext_hdr *ext_hdr, struct in6_address *dst_addr) { struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr; if ((rthdr->rtype == 2) && (rthdr->len == sizeof(struct in6_address) / 8) && (rthdr->segleft == 1)) { size_t input_size = iov_size(pkt, pkt_frags); size_t bytes_read; if (input_size < rthdr_offset + sizeof(*ext_hdr)) { return false; } bytes_read = iov_to_buf(pkt, pkt_frags, rthdr_offset + sizeof(*ext_hdr), dst_addr, sizeof(*dst_addr)); return bytes_read == sizeof(dst_addr); } return false; }


USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, uint64_t id) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); USBPacket *p; while ((p = QTAILQ_FIRST(&uep->queue)) != NULL) { if (p->id == id) { return p; } } return NULL; }


void pci_bridge_exitfn(PCIDevice *pci_dev) { PCIBridge *s = DO_UPCAST(PCIBridge, dev, pci_dev); assert(QLIST_EMPTY(&s->sec_bus.child)); QLIST_REMOVE(&s->sec_bus, sibling); pci_bridge_region_cleanup(s); memory_region_destroy(&s->address_space_mem); memory_region_destroy(&s->address_space_io); /* qbus_free() is called automatically by qdev_free() */ }


static void superh_cpu_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); CPUClass *cc = CPU_CLASS(oc); SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc); scc->parent_realize = dc->realize; dc->realize = superh_cpu_realizefn; scc->parent_reset = cc->reset; cc->reset = superh_cpu_reset; cc->class_by_name = superh_cpu_class_by_name; cc->has_work = superh_cpu_has_work; cc->do_interrupt = superh_cpu_do_interrupt; cc->cpu_exec_interrupt = superh_cpu_exec_interrupt; cc->dump_state = superh_cpu_dump_state; cc->set_pc = superh_cpu_set_pc; cc->synchronize_from_tb = superh_cpu_synchronize_from_tb; cc->gdb_read_register = superh_cpu_gdb_read_register; cc->gdb_write_register = superh_cpu_gdb_write_register; #ifdef CONFIG_USER_ONLY cc->handle_mmu_fault = superh_cpu_handle_mmu_fault; #else cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; #endif cc->disas_set_info = superh_cpu_disas_set_info; cc->gdb_num_core_regs = 59; dc->vmsd = &vmstate_sh_cpu; /* * Reason: superh_cpu_initfn() calls cpu_exec_init(), which saves * the object in cpus -> dangling pointer after final * object_unref(). */ dc->cannot_destroy_with_object_finalize_yet = true; }


uint64_t HELPER(neon_abdl_u32)(uint32_t a, uint32_t b) { uint64_t tmp; uint64_t result; DO_ABD(result, a, b, uint16_t); DO_ABD(tmp, a >> 16, b >> 16, uint16_t); return result | (tmp << 32); }


void RENAME(swri_noise_shaping)(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count){ int i, j, pos, ch; int taps = s->dither.ns_taps; float S = s->dither.ns_scale; float S_1 = s->dither.ns_scale_1; av_assert2((taps&3) != 2); av_assert2((taps&3) != 3 || s->dither.ns_coeffs[taps] == 0); for (ch=0; ch<srcs->ch_count; ch++) { const float *noise = ((const float *)noises->ch[ch]) + s->dither.noise_pos; const DELEM *src = (const DELEM*)srcs->ch[ch]; DELEM *dst = (DELEM*)dsts->ch[ch]; float *ns_errors = s->dither.ns_errors[ch]; const float *ns_coeffs = s->dither.ns_coeffs; pos = s->dither.ns_pos; for (i=0; i<count; i++) { double d1, d = src[i]*S_1; for(j=0; j<taps-2; j+=4) { d -= ns_coeffs[j ] * ns_errors[pos + j ] +ns_coeffs[j + 1] * ns_errors[pos + j + 1] +ns_coeffs[j + 2] * ns_errors[pos + j + 2] +ns_coeffs[j + 3] * ns_errors[pos + j + 3]; } if(j < taps) d -= ns_coeffs[j] * ns_errors[pos + j]; pos = pos ? pos - 1 : taps - 1; d1 = rint(d + noise[i]); ns_errors[pos + taps] = ns_errors[pos] = d1 - d; d1 *= S; CLIP(d1); dst[i] = d1; } } s->dither.ns_pos = pos; }


static int64_t expr_unary(Monitor *mon) { int64_t n; char *p; int ret; switch(*pch) { case '+': next(); n = expr_unary(mon); break; case '-': next(); n = -expr_unary(mon); break; case '~': next(); n = ~expr_unary(mon); break; case '(': next(); n = expr_sum(mon); if (*pch != ')') { expr_error(mon, "')' expected"); } next(); break; case '\'': pch++; if (*pch == '\0') expr_error(mon, "character constant expected"); n = *pch; pch++; if (*pch != '\'') expr_error(mon, "missing terminating \' character"); next(); break; case '$': { char buf[128], *q; target_long reg=0; pch++; q = buf; while ((*pch >= 'a' && *pch <= 'z') || (*pch >= 'A' && *pch <= 'Z') || (*pch >= '0' && *pch <= '9') || *pch == '_' || *pch == '.') { if ((q - buf) < sizeof(buf) - 1) *q++ = *pch; pch++; } while (qemu_isspace(*pch)) pch++; *q = 0; ret = get_monitor_def(&reg, buf); if (ret == -1) expr_error(mon, "unknown register"); else if (ret == -2) expr_error(mon, "no cpu defined"); n = reg; } break; case '\0': expr_error(mon, "unexpected end of expression"); n = 0; break; default: #if TARGET_PHYS_ADDR_BITS > 32 n = strtoull(pch, &p, 0); #else n = strtoul(pch, &p, 0); #endif if (pch == p) { expr_error(mon, "invalid char in expression"); } pch = p; while (qemu_isspace(*pch)) pch++; break; } return n; }


static av_cold void uninit(AVFilterContext *ctx) { DynamicAudioNormalizerContext *s = ctx->priv; int c; av_freep(&s->prev_amplification_factor); av_freep(&s->dc_correction_value); av_freep(&s->compress_threshold); av_freep(&s->fade_factors[0]); av_freep(&s->fade_factors[1]); for (c = 0; c < s->channels; c++) { cqueue_free(s->gain_history_original[c]); cqueue_free(s->gain_history_minimum[c]); cqueue_free(s->gain_history_smoothed[c]); } av_freep(&s->gain_history_original); av_freep(&s->gain_history_minimum); av_freep(&s->gain_history_smoothed); av_freep(&s->weights); ff_bufqueue_discard_all(&s->queue); }


static int RENAME(dct_quantize)(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow) { x86_reg last_non_zero_p1; int level=0, q; //=0 is because gcc says uninitialized ... const uint16_t *qmat, *bias; LOCAL_ALIGNED_16(int16_t, temp_block, [64]); av_assert2((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly? //s->fdct (block); RENAMEl(ff_fdct) (block); //cannot be anything else ... if(s->dct_error_sum) s->denoise_dct(s, block); if (s->mb_intra) { int dummy; if (n < 4){ q = s->y_dc_scale; bias = s->q_intra_matrix16[qscale][1]; qmat = s->q_intra_matrix16[qscale][0]; }else{ q = s->c_dc_scale; bias = s->q_chroma_intra_matrix16[qscale][1]; qmat = s->q_chroma_intra_matrix16[qscale][0]; } /* note: block[0] is assumed to be positive */ if (!s->h263_aic) { __asm__ volatile ( "mul %%ecx \n\t" : "=d" (level), "=a"(dummy) : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1]) ); } else /* For AIC we skip quant/dequant of INTRADC */ level = (block[0] + 4)>>3; block[0]=0; //avoid fake overflow // temp_block[0] = (block[0] + (q >> 1)) / q; last_non_zero_p1 = 1; } else { last_non_zero_p1 = 0; bias = s->q_inter_matrix16[qscale][1]; qmat = s->q_inter_matrix16[qscale][0]; } if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){ __asm__ volatile( "movd %%"REG_a", "MM"3 \n\t" // last_non_zero_p1 SPREADW(MM"3") "pxor "MM"7, "MM"7 \n\t" // 0 "pxor "MM"4, "MM"4 \n\t" // 0 MOVQ" (%2), "MM"5 \n\t" // qmat[0] "pxor "MM"6, "MM"6 \n\t" "psubw (%3), "MM"6 \n\t" // -bias[0] "mov $-128, %%"REG_a" \n\t" ".p2align 4 \n\t" "1: \n\t" MOVQ" (%1, %%"REG_a"), "MM"0 \n\t" // block[i] SAVE_SIGN(MM"1", MM"0") // ABS(block[i]) "psubusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0] "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16 "por "MM"0, "MM"4 \n\t" RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) MOVQ" "MM"0, (%5, %%"REG_a") \n\t" "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t" MOVQ" "MM"7, (%1, %%"REG_a") \n\t" // 0 "pandn "MM"1, "MM"0 \n\t" PMAXW(MM"0", MM"3") "add $"MMREG_WIDTH", %%"REG_a" \n\t" " js 1b \n\t" PMAX(MM"3", MM"0") "movd "MM"3, %%"REG_a" \n\t" "movzbl %%al, %%eax \n\t" // last_non_zero_p1 : "+a" (last_non_zero_p1) : "r" (block+64), "r" (qmat), "r" (bias), "r" (inv_zigzag_direct16 + 64), "r" (temp_block + 64) XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7") ); }else{ // FMT_H263 __asm__ volatile( "movd %%"REG_a", "MM"3 \n\t" // last_non_zero_p1 SPREADW(MM"3") "pxor "MM"7, "MM"7 \n\t" // 0 "pxor "MM"4, "MM"4 \n\t" // 0 "mov $-128, %%"REG_a" \n\t" ".p2align 4 \n\t" "1: \n\t" MOVQ" (%1, %%"REG_a"), "MM"0 \n\t" // block[i] SAVE_SIGN(MM"1", MM"0") // ABS(block[i]) MOVQ" (%3, %%"REG_a"), "MM"6 \n\t" // bias[0] "paddusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0] MOVQ" (%2, %%"REG_a"), "MM"5 \n\t" // qmat[i] "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16 "por "MM"0, "MM"4 \n\t" RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) MOVQ" "MM"0, (%5, %%"REG_a") \n\t" "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00 MOVQ" (%4, %%"REG_a"), "MM"1 \n\t" MOVQ" "MM"7, (%1, %%"REG_a") \n\t" // 0 "pandn "MM"1, "MM"0 \n\t" PMAXW(MM"0", MM"3") "add $"MMREG_WIDTH", %%"REG_a" \n\t" " js 1b \n\t" PMAX(MM"3", MM"0") "movd "MM"3, %%"REG_a" \n\t" "movzbl %%al, %%eax \n\t" // last_non_zero_p1 : "+a" (last_non_zero_p1) : "r" (block+64), "r" (qmat+64), "r" (bias+64), "r" (inv_zigzag_direct16 + 64), "r" (temp_block + 64) XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7") ); } __asm__ volatile( "movd %1, "MM"1 \n\t" // max_qcoeff SPREADW(MM"1") "psubusw "MM"1, "MM"4 \n\t" "packuswb "MM"4, "MM"4 \n\t" #if COMPILE_TEMPLATE_SSE2 "packuswb "MM"4, "MM"4 \n\t" #endif "movd "MM"4, %0 \n\t" // *overflow : "=g" (*overflow) : "g" (s->max_qcoeff) ); if(s->mb_intra) block[0]= level; else block[0]= temp_block[0]; if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){ if(last_non_zero_p1 <= 1) goto end; block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08]; block[0x20] = temp_block[0x10]; if(last_non_zero_p1 <= 4) goto end; block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02]; block[0x09] = temp_block[0x03]; if(last_non_zero_p1 <= 7) goto end; block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11]; block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20]; if(last_non_zero_p1 <= 11) goto end; block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12]; block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04]; block[0x0C] = temp_block[0x05]; if(last_non_zero_p1 <= 16) goto end; block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13]; block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21]; block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30]; block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22]; if(last_non_zero_p1 <= 24) goto end; block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14]; block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06]; block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E]; block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C]; if(last_non_zero_p1 <= 32) goto end; block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A]; block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38]; block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32]; block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24]; if(last_non_zero_p1 <= 40) goto end; block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16]; block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17]; block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25]; block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33]; if(last_non_zero_p1 <= 48) goto end; block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B]; block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D]; block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F]; block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E]; if(last_non_zero_p1 <= 56) goto end; block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C]; block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36]; block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37]; block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F]; }else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){ if(last_non_zero_p1 <= 1) goto end; block[0x04] = temp_block[0x01]; block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10]; if(last_non_zero_p1 <= 4) goto end; block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02]; block[0x05] = temp_block[0x03]; if(last_non_zero_p1 <= 7) goto end; block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11]; block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20]; if(last_non_zero_p1 <= 11) goto end; block[0x1C] = temp_block[0x19]; block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B]; block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05]; if(last_non_zero_p1 <= 16) goto end; block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13]; block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21]; block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30]; block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22]; if(last_non_zero_p1 <= 24) goto end; block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14]; block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06]; block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E]; block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C]; if(last_non_zero_p1 <= 32) goto end; block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A]; block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38]; block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32]; block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24]; if(last_non_zero_p1 <= 40) goto end; block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16]; block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17]; block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25]; block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33]; if(last_non_zero_p1 <= 48) goto end; block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B]; block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D]; block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F]; block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E]; if(last_non_zero_p1 <= 56) goto end; block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C]; block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36]; block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37]; block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F]; }else{ if(last_non_zero_p1 <= 1) goto end; block[0x01] = temp_block[0x01]; block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10]; if(last_non_zero_p1 <= 4) goto end; block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02]; block[0x03] = temp_block[0x03]; if(last_non_zero_p1 <= 7) goto end; block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11]; block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20]; if(last_non_zero_p1 <= 11) goto end; block[0x19] = temp_block[0x19]; block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B]; block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05]; if(last_non_zero_p1 <= 16) goto end; block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13]; block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21]; block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30]; block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22]; if(last_non_zero_p1 <= 24) goto end; block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14]; block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06]; block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E]; block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C]; if(last_non_zero_p1 <= 32) goto end; block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A]; block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38]; block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32]; block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24]; if(last_non_zero_p1 <= 40) goto end; block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16]; block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17]; block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25]; block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33]; if(last_non_zero_p1 <= 48) goto end; block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B]; block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D]; block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F]; block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E]; if(last_non_zero_p1 <= 56) goto end; block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C]; block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36]; block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37]; block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F]; } end: return last_non_zero_p1 - 1; }


static int mxf_read_sequence(void *arg, AVIOContext *pb, int tag, int size, UID uid) { MXFSequence *sequence = arg; switch(tag) { case 0x0202: sequence->duration = avio_rb64(pb); break; case 0x0201: avio_read(pb, sequence->data_definition_ul, 16); break; case 0x1001: sequence->structural_components_count = avio_rb32(pb); if (sequence->structural_components_count >= UINT_MAX / sizeof(UID)) return -1; sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID)); if (!sequence->structural_components_refs) return -1; avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID)); break; } return 0; }


World *world_alloc(Rocker *r, size_t sizeof_private, enum rocker_world_type type, WorldOps *ops) { World *w = g_malloc0(sizeof(World) + sizeof_private); if (w) { w->r = r; w->type = type; w->ops = ops; if (w->ops->init) { w->ops->init(w); } } return w; }


void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { int frame_size; *pnum = 0; *pden = 0; switch(st->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: if (st->avg_frame_rate.num) { *pnum = st->avg_frame_rate.den; *pden = st->avg_frame_rate.num; } else if(st->time_base.num*1000LL > st->time_base.den) { *pnum = st->time_base.num; *pden = st->time_base.den; }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){ *pnum = st->codec->time_base.num; *pden = st->codec->time_base.den; if (pc && pc->repeat_pict) { *pnum = (*pnum) * (1 + pc->repeat_pict); } //If this codec can be interlaced or progressive then we need a parser to compute duration of a packet //Thus if we have no parser in such case leave duration undefined. if(st->codec->ticks_per_frame>1 && !pc){ *pnum = *pden = 0; } } break; case AVMEDIA_TYPE_AUDIO: frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 0); if (frame_size <= 0 || st->codec->sample_rate <= 0) break; *pnum = frame_size; *pden = st->codec->sample_rate; break; default: break; } }


static uint64_t serial_ioport_read(void *opaque, hwaddr addr, unsigned size) { SerialState *s = opaque; uint32_t ret; addr &= 7; switch(addr) { default: case 0: if (s->lcr & UART_LCR_DLAB) { ret = s->divider & 0xff; } else { if(s->fcr & UART_FCR_FE) { ret = fifo8_is_full(&s->recv_fifo) ? 0 : fifo8_pop(&s->recv_fifo); if (s->recv_fifo.num == 0) { s->lsr &= ~(UART_LSR_DR | UART_LSR_BI); } else { qemu_mod_timer(s->fifo_timeout_timer, qemu_get_clock_ns (vm_clock) + s->char_transmit_time * 4); } s->timeout_ipending = 0; } else { ret = s->rbr; s->lsr &= ~(UART_LSR_DR | UART_LSR_BI); } serial_update_irq(s); if (!(s->mcr & UART_MCR_LOOP)) { /* in loopback mode, don't receive any data */ qemu_chr_accept_input(s->chr); } } break; case 1: if (s->lcr & UART_LCR_DLAB) { ret = (s->divider >> 8) & 0xff; } else { ret = s->ier; } break; case 2: ret = s->iir; if ((ret & UART_IIR_ID) == UART_IIR_THRI) { s->thr_ipending = 0; serial_update_irq(s); } break; case 3: ret = s->lcr; break; case 4: ret = s->mcr; break; case 5: ret = s->lsr; /* Clear break and overrun interrupts */ if (s->lsr & (UART_LSR_BI|UART_LSR_OE)) { s->lsr &= ~(UART_LSR_BI|UART_LSR_OE); serial_update_irq(s); } break; case 6: if (s->mcr & UART_MCR_LOOP) { /* in loopback, the modem output pins are connected to the inputs */ ret = (s->mcr & 0x0c) << 4; ret |= (s->mcr & 0x02) << 3; ret |= (s->mcr & 0x01) << 5; } else { if (s->poll_msl >= 0) serial_update_msl(s); ret = s->msr; /* Clear delta bits & msr int after read, if they were set */ if (s->msr & UART_MSR_ANY_DELTA) { s->msr &= 0xF0; serial_update_irq(s); } } break; case 7: ret = s->scr; break; } DPRINTF("read addr=0x%" HWADDR_PRIx " val=0x%02x\n", addr, ret); return ret; }


create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) { size_t *sizes = g_new0(size_t, nr_iov); size_t count = 0; void *buf = NULL; void *p; int i; for (i = 0; i < nr_iov; i++) { char *arg = argv[i]; int64_t len; len = cvtnum(arg); if (len < 0) { print_cvtnum_err(len, arg); goto fail; } if (len > SIZE_MAX) { printf("Argument '%s' exceeds maximum size %llu\n", arg, (unsigned long long)SIZE_MAX); goto fail; } sizes[i] = len; count += len; } qemu_iovec_init(qiov, nr_iov); buf = p = qemu_io_alloc(blk, count, pattern); for (i = 0; i < nr_iov; i++) { qemu_iovec_add(qiov, p, sizes[i]); p += sizes[i]; } fail: g_free(sizes); return buf; }


static bool main_loop_should_exit(void) { RunState r; if (qemu_debug_requested()) { vm_stop(RUN_STATE_DEBUG); } if (qemu_suspend_requested()) { qemu_system_suspend(); } if (qemu_shutdown_requested()) { qemu_kill_report(); monitor_protocol_event(QEVENT_SHUTDOWN, NULL); if (no_shutdown) { vm_stop(RUN_STATE_SHUTDOWN); } else { return true; } } if (qemu_reset_requested()) { pause_all_vcpus(); cpu_synchronize_all_states(); qemu_system_reset(VMRESET_REPORT); resume_all_vcpus(); if (runstate_check(RUN_STATE_INTERNAL_ERROR) || runstate_check(RUN_STATE_SHUTDOWN)) { runstate_set(RUN_STATE_PAUSED); } } if (qemu_wakeup_requested()) { pause_all_vcpus(); cpu_synchronize_all_states(); qemu_system_reset(VMRESET_SILENT); resume_all_vcpus(); monitor_protocol_event(QEVENT_WAKEUP, NULL); } if (qemu_powerdown_requested()) { qemu_system_powerdown(); } if (qemu_vmstop_requested(&r)) { vm_stop(r); } return false; }


int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) { AVStream *st; MOVStreamContext *sc; int j, pseudo_stream_id; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams-1]; sc = st->priv_data; for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) { //Parsing Sample description table enum CodecID id; int dref_id = 1; MOVAtom a = { AV_RL32("stsd") }; int64_t start_pos = avio_tell(pb); int size = avio_rb32(pb); /* size */ uint32_t format = avio_rl32(pb); /* data format */ if (size >= 16) { avio_rb32(pb); /* reserved */ avio_rb16(pb); /* reserved */ dref_id = avio_rb16(pb); } if (st->codec->codec_tag && st->codec->codec_tag != format && (c->fc->video_codec_id ? ff_codec_get_id(codec_movvideo_tags, format) != c->fc->video_codec_id : st->codec->codec_tag != MKTAG('j','p','e','g')) ){ /* Multiple fourcc, we skip JPEG. This is not correct, we should * export it as a separate AVStream but this needs a few changes * in the MOV demuxer, patch welcome. */ multiple_stsd: av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n"); avio_skip(pb, size - (avio_tell(pb) - start_pos)); continue; } /* we cannot demux concatenated h264 streams because of different extradata */ if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1")) goto multiple_stsd; sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id; sc->dref_id= dref_id; st->codec->codec_tag = format; id = ff_codec_get_id(codec_movaudio_tags, format); if (id<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8))) id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF); if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && /* do not overwrite codec type */ format && format != MKTAG('m','p','4','s')) { /* skip old asf mpeg4 tag */ id = ff_codec_get_id(codec_movvideo_tags, format); if (id <= 0) id = ff_codec_get_id(ff_codec_bmp_tags, format); if (id > 0) st->codec->codec_type = AVMEDIA_TYPE_VIDEO; else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){ id = ff_codec_get_id(ff_codec_movsubtitle_tags, format); if (id > 0) st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; } } av_dlog(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size, (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, st->codec->codec_type); if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { unsigned int color_depth, len; int color_greyscale; st->codec->codec_id = id; avio_rb16(pb); /* version */ avio_rb16(pb); /* revision level */ avio_rb32(pb); /* vendor */ avio_rb32(pb); /* temporal quality */ avio_rb32(pb); /* spatial quality */ st->codec->width = avio_rb16(pb); /* width */ st->codec->height = avio_rb16(pb); /* height */ avio_rb32(pb); /* horiz resolution */ avio_rb32(pb); /* vert resolution */ avio_rb32(pb); /* data size, always 0 */ avio_rb16(pb); /* frames per samples */ len = avio_r8(pb); /* codec name, pascal string */ if (len > 31) len = 31; mov_read_mac_string(c, pb, len, st->codec->codec_name, 32); if (len < 31) avio_skip(pb, 31 - len); /* codec_tag YV12 triggers an UV swap in rawdec.c */ if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25)) st->codec->codec_tag=MKTAG('I', '4', '2', '0'); st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */ st->codec->color_table_id = avio_rb16(pb); /* colortable id */ av_dlog(c->fc, "depth %d, ctab id %d\n", st->codec->bits_per_coded_sample, st->codec->color_table_id); /* figure out the palette situation */ color_depth = st->codec->bits_per_coded_sample & 0x1F; color_greyscale = st->codec->bits_per_coded_sample & 0x20; /* if the depth is 2, 4, or 8 bpp, file is palettized */ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) { /* for palette traversal */ unsigned int color_start, color_count, color_end; unsigned char r, g, b; if (color_greyscale) { int color_index, color_dec; /* compute the greyscale palette */ st->codec->bits_per_coded_sample = color_depth; color_count = 1 << color_depth; color_index = 255; color_dec = 256 / (color_count - 1); for (j = 0; j < color_count; j++) { if (id == CODEC_ID_CINEPAK){ r = g = b = color_count - 1 - color_index; }else r = g = b = color_index; sc->palette[j] = (r << 16) | (g << 8) | (b); color_index -= color_dec; if (color_index < 0) color_index = 0; } } else if (st->codec->color_table_id) { const uint8_t *color_table; /* if flag bit 3 is set, use the default palette */ color_count = 1 << color_depth; if (color_depth == 2) color_table = ff_qt_default_palette_4; else if (color_depth == 4) color_table = ff_qt_default_palette_16; else color_table = ff_qt_default_palette_256; for (j = 0; j < color_count; j++) { r = color_table[j * 3 + 0]; g = color_table[j * 3 + 1]; b = color_table[j * 3 + 2]; sc->palette[j] = (r << 16) | (g << 8) | (b); } } else { /* load the palette from the file */ color_start = avio_rb32(pb); color_count = avio_rb16(pb); color_end = avio_rb16(pb); if ((color_start <= 255) && (color_end <= 255)) { for (j = color_start; j <= color_end; j++) { /* each R, G, or B component is 16 bits; * only use the top 8 bits; skip alpha bytes * up front */ avio_r8(pb); avio_r8(pb); r = avio_r8(pb); avio_r8(pb); g = avio_r8(pb); avio_r8(pb); b = avio_r8(pb); avio_r8(pb); sc->palette[j] = (r << 16) | (g << 8) | (b); } } } sc->has_palette = 1; } } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { int bits_per_sample, flags; uint16_t version = avio_rb16(pb); st->codec->codec_id = id; avio_rb16(pb); /* revision level */ avio_rb32(pb); /* vendor */ st->codec->channels = avio_rb16(pb); /* channel count */ av_dlog(c->fc, "audio channels %d\n", st->codec->channels); st->codec->bits_per_coded_sample = avio_rb16(pb); /* sample size */ sc->audio_cid = avio_rb16(pb); avio_rb16(pb); /* packet size = 0 */ st->codec->sample_rate = ((avio_rb32(pb) >> 16)); //Read QT version 1 fields. In version 0 these do not exist. av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom); if (!c->isom) { if (version==1) { sc->samples_per_frame = avio_rb32(pb); avio_rb32(pb); /* bytes per packet */ sc->bytes_per_frame = avio_rb32(pb); avio_rb32(pb); /* bytes per sample */ } else if (version==2) { avio_rb32(pb); /* sizeof struct only */ st->codec->sample_rate = av_int2double(avio_rb64(pb)); /* float 64 */ st->codec->channels = avio_rb32(pb); avio_rb32(pb); /* always 0x7F000000 */ st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */ flags = avio_rb32(pb); /* lpcm format specific flag */ sc->bytes_per_frame = avio_rb32(pb); /* bytes per audio packet if constant */ sc->samples_per_frame = avio_rb32(pb); /* lpcm frames per audio packet if constant */ if (format == MKTAG('l','p','c','m')) st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); } } switch (st->codec->codec_id) { case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: if (st->codec->bits_per_coded_sample == 16) st->codec->codec_id = CODEC_ID_PCM_S16BE; break; case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: if (st->codec->bits_per_coded_sample == 8) st->codec->codec_id = CODEC_ID_PCM_S8; else if (st->codec->bits_per_coded_sample == 24) st->codec->codec_id = st->codec->codec_id == CODEC_ID_PCM_S16BE ? CODEC_ID_PCM_S24BE : CODEC_ID_PCM_S24LE; break; /* set values for old format before stsd version 1 appeared */ case CODEC_ID_MACE3: sc->samples_per_frame = 6; sc->bytes_per_frame = 2*st->codec->channels; break; case CODEC_ID_MACE6: sc->samples_per_frame = 6; sc->bytes_per_frame = 1*st->codec->channels; break; case CODEC_ID_ADPCM_IMA_QT: sc->samples_per_frame = 64; sc->bytes_per_frame = 34*st->codec->channels; break; case CODEC_ID_GSM: sc->samples_per_frame = 160; sc->bytes_per_frame = 33; break; default: break; } bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); if (bits_per_sample) { st->codec->bits_per_coded_sample = bits_per_sample; sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; } } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ // ttxt stsd contains display flags, justification, background // color, fonts, and default styles, so fake an atom to read it MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) }; if (format != AV_RL32("mp4s")) // mp4s contains a regular esds atom mov_read_glbl(c, pb, fake_atom); st->codec->codec_id= id; st->codec->width = sc->width; st->codec->height = sc->height; } else { if (st->codec->codec_tag == MKTAG('t','m','c','d')) { int val; avio_rb32(pb); /* reserved */ val = avio_rb32(pb); /* flags */ if (val & 1) st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE; avio_rb32(pb); avio_rb32(pb); st->codec->time_base.den = avio_r8(pb); st->codec->time_base.num = 1; } /* other codec type, just skip (rtp, mp4s, ...) */ avio_skip(pb, size - (avio_tell(pb) - start_pos)); } /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ a.size = size - (avio_tell(pb) - start_pos); if (a.size > 8) { if (mov_read_default(c, pb, a) < 0) } else if (a.size > 0) avio_skip(pb, a.size); } if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) st->codec->sample_rate= sc->time_scale; /* special codec parameters handling */ switch (st->codec->codec_id) { #if CONFIG_DV_DEMUXER case CODEC_ID_DVAUDIO: c->dv_fctx = avformat_alloc_context(); c->dv_demux = avpriv_dv_init_demux(c->dv_fctx); if (!c->dv_demux) { av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); } sc->dv_audio_container = 1; st->codec->codec_id = CODEC_ID_PCM_S16LE; break; #endif /* no ifdef since parameters are always those */ case CODEC_ID_QCELP: // force sample rate for qcelp when not stored in mov if (st->codec->codec_tag != MKTAG('Q','c','l','p')) st->codec->sample_rate = 8000; st->codec->frame_size= 160; st->codec->channels= 1; /* really needed */ break; case CODEC_ID_AMR_NB: st->codec->channels= 1; /* really needed */ /* force sample rate for amr, stsd in 3gp does not store sample rate */ st->codec->sample_rate = 8000; /* force frame_size, too, samples_per_frame isn't always set properly */ st->codec->frame_size = 160; break; case CODEC_ID_AMR_WB: st->codec->channels = 1; st->codec->sample_rate = 16000; st->codec->frame_size = 320; break; case CODEC_ID_MP2: case CODEC_ID_MP3: st->codec->codec_type = AVMEDIA_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ st->need_parsing = AVSTREAM_PARSE_FULL; break; case CODEC_ID_GSM: case CODEC_ID_ADPCM_MS: case CODEC_ID_ADPCM_IMA_WAV: st->codec->frame_size = sc->samples_per_frame; st->codec->block_align = sc->bytes_per_frame; break; case CODEC_ID_ALAC: if (st->codec->extradata_size == 36) { st->codec->frame_size = AV_RB32(st->codec->extradata+12); st->codec->channels = AV_RB8 (st->codec->extradata+21); st->codec->sample_rate = AV_RB32(st->codec->extradata+32); } break; case CODEC_ID_AC3: st->need_parsing = AVSTREAM_PARSE_FULL; break; case CODEC_ID_MPEG1VIDEO: st->need_parsing = AVSTREAM_PARSE_FULL; break; default: break; } return 0; }


static void test_tco_max_timeout(void) { TestData d; const uint16_t ticks = 0xffff; uint32_t val; int ret; d.args = NULL; d.noreboot = true; test_init(&d); stop_tco(&d); clear_tco_status(&d); reset_on_second_timeout(false); set_tco_timeout(&d, ticks); load_tco(&d); start_tco(&d); clock_step(((ticks & TCO_TMR_MASK) - 1) * TCO_TICK_NSEC); val = qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD); g_assert_cmpint(val & TCO_RLD_MASK, ==, 1); val = qpci_io_readw(d.dev, d.tco_io_base + TCO1_STS); ret = val & TCO_TIMEOUT ? 1 : 0; g_assert(ret == 0); clock_step(TCO_TICK_NSEC); val = qpci_io_readw(d.dev, d.tco_io_base + TCO1_STS); ret = val & TCO_TIMEOUT ? 1 : 0; g_assert(ret == 1); stop_tco(&d); qtest_end(); }


YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE) YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE) YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE) YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE) /* * Write out 2 RGB pixels in the target pixel format. This function takes a * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of * things like endianness conversion and shifting. The caller takes care of * setting the correct offset in these tables from the chroma (U/V) values. * This function then uses the luminance (Y1/Y2) values to write out the * correct RGB values into the destination buffer. */ static av_always_inline void yuv2rgb_write(uint8_t *_dest, int i, unsigned Y1, unsigned Y2, unsigned A1, unsigned A2, const void *_r, const void *_g, const void *_b, int y, enum PixelFormat target, int hasAlpha) { if (target == PIX_FMT_ARGB || target == PIX_FMT_RGBA || target == PIX_FMT_ABGR || target == PIX_FMT_BGRA) { uint32_t *dest = (uint32_t *) _dest; const uint32_t *r = (const uint32_t *) _r; const uint32_t *g = (const uint32_t *) _g; const uint32_t *b = (const uint32_t *) _b; #if CONFIG_SMALL int sh = hasAlpha ? ((target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24) : 0; dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0); dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0); #else if (hasAlpha) { int sh = (target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24; dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh); dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh); } else { dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1]; dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2]; } #endif } else if (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) { uint8_t *dest = (uint8_t *) _dest; const uint8_t *r = (const uint8_t *) _r; const uint8_t *g = (const uint8_t *) _g; const uint8_t *b = (const uint8_t *) _b; #define r_b ((target == PIX_FMT_RGB24) ? r : b) #define b_r ((target == PIX_FMT_RGB24) ? b : r) dest[i * 6 + 0] = r_b[Y1]; dest[i * 6 + 1] = g[Y1]; dest[i * 6 + 2] = b_r[Y1]; dest[i * 6 + 3] = r_b[Y2]; dest[i * 6 + 4] = g[Y2]; dest[i * 6 + 5] = b_r[Y2]; #undef r_b #undef b_r } else if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565 || target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555 || target == PIX_FMT_RGB444 || target == PIX_FMT_BGR444) { uint16_t *dest = (uint16_t *) _dest; const uint16_t *r = (const uint16_t *) _r; const uint16_t *g = (const uint16_t *) _g; const uint16_t *b = (const uint16_t *) _b; int dr1, dg1, db1, dr2, dg2, db2; if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565) { dr1 = dither_2x2_8[ y & 1 ][0]; dg1 = dither_2x2_4[ y & 1 ][0]; db1 = dither_2x2_8[(y & 1) ^ 1][0]; dr2 = dither_2x2_8[ y & 1 ][1]; dg2 = dither_2x2_4[ y & 1 ][1]; db2 = dither_2x2_8[(y & 1) ^ 1][1]; } else if (target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555) { dr1 = dither_2x2_8[ y & 1 ][0]; dg1 = dither_2x2_8[ y & 1 ][1]; db1 = dither_2x2_8[(y & 1) ^ 1][0]; dr2 = dither_2x2_8[ y & 1 ][1]; dg2 = dither_2x2_8[ y & 1 ][0]; db2 = dither_2x2_8[(y & 1) ^ 1][1]; } else { dr1 = dither_4x4_16[ y & 3 ][0]; dg1 = dither_4x4_16[ y & 3 ][1]; db1 = dither_4x4_16[(y & 3) ^ 3][0]; dr2 = dither_4x4_16[ y & 3 ][1]; dg2 = dither_4x4_16[ y & 3 ][0]; db2 = dither_4x4_16[(y & 3) ^ 3][1]; } dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1]; dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]; } else /* 8/4-bit */ { uint8_t *dest = (uint8_t *) _dest; const uint8_t *r = (const uint8_t *) _r; const uint8_t *g = (const uint8_t *) _g; const uint8_t *b = (const uint8_t *) _b; int dr1, dg1, db1, dr2, dg2, db2; if (target == PIX_FMT_RGB8 || target == PIX_FMT_BGR8) { const uint8_t * const d64 = dither_8x8_73[y & 7]; const uint8_t * const d32 = dither_8x8_32[y & 7]; dr1 = dg1 = d32[(i * 2 + 0) & 7]; db1 = d64[(i * 2 + 0) & 7]; dr2 = dg2 = d32[(i * 2 + 1) & 7]; db2 = d64[(i * 2 + 1) & 7]; } else { const uint8_t * const d64 = dither_8x8_73 [y & 7]; const uint8_t * const d128 = dither_8x8_220[y & 7]; dr1 = db1 = d128[(i * 2 + 0) & 7]; dg1 = d64[(i * 2 + 0) & 7]; dr2 = db2 = d128[(i * 2 + 1) & 7]; dg2 = d64[(i * 2 + 1) & 7]; } if (target == PIX_FMT_RGB4 || target == PIX_FMT_BGR4) { dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] + ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4); } else { dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1]; dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]; } } }


int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops; nc->vring_enable = enable; if (!net) { return 0; } vhost_ops = net->dev.vhost_ops; if (vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }


static int get_channel_idx(char **map, int *ch, char delim, int max_ch) { char *next = split(*map, delim); int len; int n = 0; if (!next && delim == '-') len = strlen(*map); sscanf(*map, "%d%n", ch, &n); if (n != len) if (*ch < 0 || *ch > max_ch) *map = next; return 0; }


static void piix3_xen_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); dc->desc = "ISA bridge"; dc->vmsd = &vmstate_piix3; dc->no_user = 1; k->no_hotplug = 1; k->init = piix3_initfn; k->config_write = piix3_write_config_xen; k->vendor_id = PCI_VENDOR_ID_INTEL; /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */ k->device_id = PCI_DEVICE_ID_INTEL_82371SB_0; k->class_id = PCI_CLASS_BRIDGE_ISA; };


qio_channel_websock_source_check(GSource *source) { QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source; GIOCondition cond = 0; if (wsource->wioc->rawinput.offset) { cond |= G_IO_IN; } if (wsource->wioc->rawoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) { cond |= G_IO_OUT; } return cond & wsource->condition; }


static int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); const vector unsigned char permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0}; vector unsigned char perm1 = vec_lvsl(0, pix1); vector unsigned char perm2 = vec_lvsl(0, pix2); vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sad; vector signed int sumdiffs; sad = (vector unsigned int)vec_splat_u32(0); for (i = 0; i < h; i++) { /* Read potentially unaligned pixels into t1 and t2 Since we're reading 16 pixels, and actually only want 8, mask out the last 8 pixels. The 0s don't change the sum. */ vector unsigned char pix1l = vec_ld( 0, pix1); vector unsigned char pix1r = vec_ld(15, pix1); vector unsigned char pix2l = vec_ld( 0, pix2); vector unsigned char pix2r = vec_ld(15, pix2); t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear); t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); /* Calculate a sum of abs differences vector */ t3 = vec_max(t1, t2); t4 = vec_min(t1, t2); t5 = vec_sub(t3, t4); /* Add each 4 pixel group together and put 4 results into sad */ sad = vec_sum4s(t5, sad); pix1 += line_size; pix2 += line_size; } /* Sum up the four partial sums, and put the result into s */ sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); sumdiffs = vec_splat(sumdiffs, 3); vec_ste(sumdiffs, 0, &s); return s; }


static void move_audio(vorbis_enc_context *venc, float **audio, int *samples, int sf_size) { AVFrame *cur = NULL; int frame_size = 1 << (venc->log2_blocksize[1] - 1); int subframes = frame_size / sf_size; for (int sf = 0; sf < subframes; sf++) { cur = ff_bufqueue_get(&venc->bufqueue); *samples += cur->nb_samples; for (int ch = 0; ch < venc->channels; ch++) { const float *input = (float *) cur->extended_data[ch]; const size_t len = cur->nb_samples * sizeof(float); memcpy(&audio[ch][sf*sf_size], input, len); } av_frame_free(&cur); } }


static void svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc) { const int qmul = svq3_dequant_coeff[qp]; int i; if (dc) { dc = 13 * 13 * (dc == 1 ? 1538U* block[0] : qmul * (block[0] >> 3) / 2); block[0] = 0; } for (i = 0; i < 4; i++) { const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]); const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]); const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i]; const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i]; block[0 + 4 * i] = z0 + z3; block[1 + 4 * i] = z1 + z2; block[2 + 4 * i] = z1 - z2; block[3 + 4 * i] = z0 - z3; } for (i = 0; i < 4; i++) { const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]); const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]); const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3]; const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3]; const int rr = (dc + 0x80000); dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20)); dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20)); dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20)); dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20)); } memset(block, 0, 16 * sizeof(int16_t)); }


static char *vnc_socket_local_addr(const char *format, int fd) { struct sockaddr_storage sa; socklen_t salen; salen = sizeof(sa); if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) return NULL; return addr_to_string(format, &sa, salen); }


static int dca_subframe_header(DCAContext *s, int base_channel, int block_index) { /* Primary audio coding side information */ int j, k; if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; if (!base_channel) { s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1; s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3); } for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) s->prediction_mode[j][k] = get_bits(&s->gb, 1); } /* Get prediction codebook */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) { if (s->prediction_mode[j][k] > 0) { /* (Prediction coefficient VQ address) */ s->prediction_vq[j][k] = get_bits(&s->gb, 12); } } } /* Bit allocation index */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->vq_start_subband[j]; k++) { if (s->bitalloc_huffman[j] == 6) s->bitalloc[j][k] = get_bits(&s->gb, 5); else if (s->bitalloc_huffman[j] == 5) s->bitalloc[j][k] = get_bits(&s->gb, 4); else if (s->bitalloc_huffman[j] == 7) { av_log(s->avctx, AV_LOG_ERROR, "Invalid bit allocation index\n"); return AVERROR_INVALIDDATA; } else { s->bitalloc[j][k] = get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); } if (s->bitalloc[j][k] > 26) { // av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index [%i][%i] too big (%i)\n", // j, k, s->bitalloc[j][k]); return AVERROR_INVALIDDATA; } } } /* Transition mode */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) { s->transition_mode[j][k] = 0; if (s->subsubframes[s->current_subframe] > 1 && k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) { s->transition_mode[j][k] = get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]); } } } if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; for (j = base_channel; j < s->prim_channels; j++) { const uint32_t *scale_table; int scale_sum, log_size; memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); if (s->scalefactor_huffman[j] == 6) { scale_table = scale_factor_quant7; log_size = 7; } else { scale_table = scale_factor_quant6; log_size = 6; } /* When huffman coded, only the difference is encoded */ scale_sum = 0; for (k = 0; k < s->subband_activity[j]; k++) { if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size); s->scale_factor[j][k][0] = scale_table[scale_sum]; } if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { /* Get second scale factor */ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size); s->scale_factor[j][k][1] = scale_table[scale_sum]; } } } /* Joint subband scale factor codebook select */ for (j = base_channel; j < s->prim_channels; j++) { /* Transmitted only if joint subband coding enabled */ if (s->joint_intensity[j] > 0) s->joint_huff[j] = get_bits(&s->gb, 3); } if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; /* Scale factors for joint subband coding */ for (j = base_channel; j < s->prim_channels; j++) { int source_channel; /* Transmitted only if joint subband coding enabled */ if (s->joint_intensity[j] > 0) { int scale = 0; source_channel = s->joint_intensity[j] - 1; /* When huffman coded, only the difference is encoded * (is this valid as well for joint scales ???) */ for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { scale = get_scale(&s->gb, s->joint_huff[j], 64 /* bias */, 7); s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ } if (!(s->debug_flag & 0x02)) { av_log(s->avctx, AV_LOG_DEBUG, "Joint stereo coding not supported\n"); s->debug_flag |= 0x02; } } } /* Stereo downmix coefficients */ if (!base_channel && s->prim_channels > 2) { if (s->downmix) { for (j = base_channel; j < s->prim_channels; j++) { s->downmix_coef[j][0] = get_bits(&s->gb, 7); s->downmix_coef[j][1] = get_bits(&s->gb, 7); } } else { int am = s->amode & DCA_CHANNEL_MASK; if (am >= FF_ARRAY_ELEMS(dca_default_coeffs)) { av_log(s->avctx, AV_LOG_ERROR, "Invalid channel mode %d\n", am); return AVERROR_INVALIDDATA; } for (j = base_channel; j < s->prim_channels; j++) { s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; } } } /* Dynamic range coefficient */ if (!base_channel && s->dynrange) s->dynrange_coef = get_bits(&s->gb, 8); /* Side information CRC check word */ if (s->crc_present) { get_bits(&s->gb, 16); } /* * Primary audio data arrays */ /* VQ encoded high frequency subbands */ for (j = base_channel; j < s->prim_channels; j++) for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) /* 1 vector -> 32 samples */ s->high_freq_vq[j][k] = get_bits(&s->gb, 10); /* Low frequency effect data */ if (!base_channel && s->lfe) { int quant7; /* LFE samples */ int lfe_samples = 2 * s->lfe * (4 + block_index); int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]); float lfe_scale; for (j = lfe_samples; j < lfe_end_sample; j++) { /* Signed 8 bits int */ s->lfe_data[j] = get_sbits(&s->gb, 8); } /* Scale factor index */ quant7 = get_bits(&s->gb, 8); if (quant7 > 127) { av_log_ask_for_sample(s->avctx, "LFEScaleIndex larger than 127\n"); return AVERROR_INVALIDDATA; } s->lfe_scale_factor = scale_factor_quant7[quant7]; /* Quantization step size * scale factor */ lfe_scale = 0.035 * s->lfe_scale_factor; for (j = lfe_samples; j < lfe_end_sample; j++) s->lfe_data[j] *= lfe_scale; } #ifdef TRACE av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes[s->current_subframe]); av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n", s->partial_samples[s->current_subframe]); for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:"); for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "prediction coefs: %f, %f, %f, %f\n", (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: "); for (k = 0; k < s->vq_start_subband[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:"); for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:"); for (k = 0; k < s->subband_activity[j]; k++) { if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]); if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]); } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { if (s->joint_intensity[j] > 0) { int source_channel = s->joint_intensity[j] - 1; av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n"); for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } } if (!base_channel && s->prim_channels > 2 && s->downmix) { av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n"); for (j = 0; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Channel 0, %d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]); av_log(s->avctx, AV_LOG_DEBUG, "Channel 1, %d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]); } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]); if (!base_channel && s->lfe) { int lfe_samples = 2 * s->lfe * (4 + block_index); int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]); av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n"); for (j = lfe_samples; j < lfe_end_sample; j++) av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } #endif return 0; }


static void gen_neon_dup_u8(TCGv var, int shift) { TCGv tmp = new_tmp(); if (shift) tcg_gen_shri_i32(var, var, shift); tcg_gen_ext8u_i32(var, var); tcg_gen_shli_i32(tmp, var, 8); tcg_gen_or_i32(var, var, tmp); tcg_gen_shli_i32(tmp, var, 16); tcg_gen_or_i32(var, var, tmp); dead_tmp(tmp); }


static target_ulong helper_udiv_common(CPUSPARCState *env, target_ulong a, target_ulong b, int cc) { SPARCCPU *cpu = sparc_env_get_cpu(env); int overflow = 0; uint64_t x0; uint32_t x1; x0 = (a & 0xffffffff) | ((int64_t) (env->y) << 32); x1 = (b & 0xffffffff); if (x1 == 0) { cpu_restore_state(CPU(cpu), GETPC()); helper_raise_exception(env, TT_DIV_ZERO); } x0 = x0 / x1; if (x0 > 0xffffffff) { x0 = 0xffffffff; overflow = 1; } if (cc) { env->cc_dst = x0; env->cc_src2 = overflow; env->cc_op = CC_OP_DIV; } return x0; }


static BlockStats *bdrv_query_stats(const BlockDriverState *bs, bool query_backing) { BlockStats *s; s = g_malloc0(sizeof(*s)); if (bdrv_get_device_name(bs)[0]) { s->has_device = true; s->device = g_strdup(bdrv_get_device_name(bs)); } if (bdrv_get_node_name(bs)[0]) { s->has_node_name = true; s->node_name = g_strdup(bdrv_get_node_name(bs)); } s->stats = g_malloc0(sizeof(*s->stats)); if (bs->blk) { BlockAcctStats *stats = blk_get_stats(bs->blk); s->stats->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ]; s->stats->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE]; s->stats->rd_operations = stats->nr_ops[BLOCK_ACCT_READ]; s->stats->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE]; s->stats->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ]; s->stats->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE]; s->stats->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH]; s->stats->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ]; s->stats->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE]; s->stats->invalid_flush_operations = stats->invalid_ops[BLOCK_ACCT_FLUSH]; s->stats->rd_merged = stats->merged[BLOCK_ACCT_READ]; s->stats->wr_merged = stats->merged[BLOCK_ACCT_WRITE]; s->stats->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH]; s->stats->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE]; s->stats->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ]; s->stats->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH]; s->stats->has_idle_time_ns = stats->last_access_time_ns > 0; if (s->stats->has_idle_time_ns) { s->stats->idle_time_ns = block_acct_idle_time_ns(stats); } } s->stats->wr_highest_offset = bs->wr_highest_offset; if (bs->file) { s->has_parent = true; s->parent = bdrv_query_stats(bs->file->bs, query_backing); } if (query_backing && bs->backing) { s->has_backing = true; s->backing = bdrv_query_stats(bs->backing->bs, query_backing); } return s; }


static uint64_t hb_regs_read(void *opaque, hwaddr offset, unsigned size) { uint32_t *regs = opaque; uint32_t value = regs[offset/4]; if ((offset == 0x100) || (offset == 0x108) || (offset == 0x10C)) { value |= 0x30000000; } return value; }


static unsigned acpi_data_len(GArray *table) { #if GLIB_CHECK_VERSION(2, 14, 0) assert(g_array_get_element_size(table) == 1); #endif return table->len; }


static void init_excp_970 (CPUPPCState *env) { #if !defined(CONFIG_USER_ONLY) env->excp_vectors[POWERPC_EXCP_RESET] = 0x00000100; env->excp_vectors[POWERPC_EXCP_MCHECK] = 0x00000200; env->excp_vectors[POWERPC_EXCP_DSI] = 0x00000300; env->excp_vectors[POWERPC_EXCP_DSEG] = 0x00000380; env->excp_vectors[POWERPC_EXCP_ISI] = 0x00000400; env->excp_vectors[POWERPC_EXCP_ISEG] = 0x00000480; env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500; env->excp_vectors[POWERPC_EXCP_ALIGN] = 0x00000600; env->excp_vectors[POWERPC_EXCP_PROGRAM] = 0x00000700; env->excp_vectors[POWERPC_EXCP_FPU] = 0x00000800; env->excp_vectors[POWERPC_EXCP_DECR] = 0x00000900; #if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */ env->excp_vectors[POWERPC_EXCP_HDECR] = 0x00000980; #endif env->excp_vectors[POWERPC_EXCP_SYSCALL] = 0x00000C00; env->excp_vectors[POWERPC_EXCP_TRACE] = 0x00000D00; env->excp_vectors[POWERPC_EXCP_PERFM] = 0x00000F00; env->excp_vectors[POWERPC_EXCP_VPU] = 0x00000F20; env->excp_vectors[POWERPC_EXCP_IABR] = 0x00001300; env->excp_vectors[POWERPC_EXCP_MAINT] = 0x00001600; env->excp_vectors[POWERPC_EXCP_VPUA] = 0x00001700; env->excp_vectors[POWERPC_EXCP_THERM] = 0x00001800; env->excp_prefix = 0x00000000FFF00000ULL; /* Hardware reset vector */ env->hreset_vector = 0x0000000000000100ULL; #endif }


static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path, mode_t st_mode, uint64_t *st_gen) { int err; /* Do not try to open special files like device nodes, fifos etc * we can get fd for regular files and directories only */ if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) { errno = ENOTTY; return -1; } err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, "s", path); if (err < 0) { errno = -err; err = -1; } return err; }


void vga_common_init(VGACommonState *s) { int i, j, v, b; for(i = 0;i < 256; i++) { v = 0; for(j = 0; j < 8; j++) { v |= ((i >> j) & 1) << (j * 4); } expand4[i] = v; v = 0; for(j = 0; j < 4; j++) { v |= ((i >> (2 * j)) & 3) << (j * 4); } expand2[i] = v; } for(i = 0; i < 16; i++) { v = 0; for(j = 0; j < 4; j++) { b = ((i >> j) & 1); v |= b << (2 * j); v |= b << (2 * j + 1); } expand4to8[i] = v; } /* valid range: 1 MB -> 256 MB */ s->vram_size = 1024 * 1024; while (s->vram_size < (s->vram_size_mb << 20) && s->vram_size < (256 << 20)) { s->vram_size <<= 1; } s->vram_size_mb = s->vram_size >> 20; s->is_vbe_vmstate = 1; memory_region_init_ram(&s->vram, "vga.vram", s->vram_size); vmstate_register_ram_global(&s->vram); xen_register_framebuffer(&s->vram); s->vram_ptr = memory_region_get_ram_ptr(&s->vram); s->get_bpp = vga_get_bpp; s->get_offsets = vga_get_offsets; s->get_resolution = vga_get_resolution; s->update = vga_update_display; s->invalidate = vga_invalidate_display; s->screen_dump = vga_screen_dump; s->text_update = vga_update_text; switch (vga_retrace_method) { case VGA_RETRACE_DUMB: s->retrace = vga_dumb_retrace; s->update_retrace_info = vga_dumb_update_retrace_info; break; case VGA_RETRACE_PRECISE: s->retrace = vga_precise_retrace; s->update_retrace_info = vga_precise_update_retrace_info; break; } vga_dirty_log_start(s); }


static uint32_t do_mac_read(lan9118_state *s, int reg) { switch (reg) { case MAC_CR: return s->mac_cr; case MAC_ADDRH: return s->conf.macaddr.a[4] | (s->conf.macaddr.a[5] << 8); case MAC_ADDRL: return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8) | (s->conf.macaddr.a[2] << 16) | (s->conf.macaddr.a[3] << 24); case MAC_HASHH: return s->mac_hashh; break; case MAC_HASHL: return s->mac_hashl; break; case MAC_MII_ACC: return s->mac_mii_acc; case MAC_MII_DATA: return s->mac_mii_data; case MAC_FLOW: return s->mac_flow; default: hw_error("lan9118: Unimplemented MAC register read: %d\n", s->mac_cmd & 0xf); } }


void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp) { int64_t value; if (v->type_uint32) { v->type_uint32(v, obj, name, errp); } else { value = *obj; v->type_int64(v, &value, name, errp); if (value < 0 || value > UINT32_MAX) { /* FIXME questionable reuse of errp if callback changed value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "uint32_t"); return; } *obj = value; } }


static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ AVFormatContext *s= nut->avf; ByteIOContext *bc = &s->pb; int size, stream_id, flags, discard; int64_t pts, last_IP_pts; size= decode_frame_header(nut, &flags, &pts, &stream_id, frame_code); if(size < 0) return -1; if (flags & FLAG_KEY) nut->stream[stream_id].skip_until_key_frame=0; discard= s->streams[ stream_id ]->discard; last_IP_pts= s->streams[ stream_id ]->last_IP_pts; if( (discard >= AVDISCARD_NONKEY && !(flags & FLAG_KEY)) ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) || discard >= AVDISCARD_ALL || nut->stream[stream_id].skip_until_key_frame){ url_fskip(bc, size); return 1; } av_get_packet(bc, pkt, size); pkt->stream_index = stream_id; if (flags & FLAG_KEY) pkt->flags |= PKT_FLAG_KEY; pkt->pts = pts; return 0; }