static uint32_t slavio_led_mem_reads(void *opaque, target_phys_addr_t addr) { MiscState *s = opaque; uint32_t ret = 0, saddr; saddr = addr & LED_MAXADDR; switch (saddr) { case 0: ret = s->leds; break; default: break; } MISC_DPRINTF("Read diagnostic LED reg 0x" TARGET_FMT_plx " = %x\n", addr, ret); return ret; }


static int proxy_init(FsContext *ctx) { V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy)); int sock_id; if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { sock_id = connect_namedsocket(ctx->fs_root); } else { sock_id = atoi(ctx->fs_root); if (sock_id < 0) { fprintf(stderr, "socket descriptor not initialized\n"); } } if (sock_id < 0) { g_free(proxy); return -1; } g_free(ctx->fs_root); ctx->fs_root = NULL; proxy->in_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); proxy->in_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; proxy->out_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); proxy->out_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; ctx->private = proxy; proxy->sockfd = sock_id; qemu_mutex_init(&proxy->mutex); ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; ctx->exops.get_st_gen = proxy_ioc_getversion; return 0; }


static void scsi_flush_complete(void * opaque, int ret) { SCSIDiskReq *r = (SCSIDiskReq *)opaque; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); if (r->req.aiocb != NULL) { r->req.aiocb = NULL; bdrv_acct_done(s->qdev.conf.bs, &r->acct); } if (ret < 0) { if (scsi_handle_rw_error(r, -ret)) { goto done; } } scsi_req_complete(&r->req, GOOD); done: if (!r->req.io_canceled) { scsi_req_unref(&r->req); } }


void fork_end(int child) { mmap_fork_end(child); if (child) { CPUState *cpu, *next_cpu; /* Child processes created by fork() only have a single thread. Discard information about the parent threads. */ CPU_FOREACH_SAFE(cpu, next_cpu) { if (cpu != thread_cpu) { QTAILQ_REMOVE(&cpus, thread_cpu, node); } } pending_cpus = 0; pthread_mutex_init(&exclusive_lock, NULL); pthread_mutex_init(&cpu_list_mutex, NULL); pthread_cond_init(&exclusive_cond, NULL); pthread_cond_init(&exclusive_resume, NULL); pthread_mutex_init(&tcg_ctx.tb_ctx.tb_lock, NULL); gdbserver_fork(thread_cpu); } else { pthread_mutex_unlock(&exclusive_lock); pthread_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); } }


static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) { sPAPRDRConnector *drc = spapr_drc_by_index(idx); sPAPRDRConnectorClass *drck; if (!drc) { return RTAS_OUT_PARAM_ERROR; } drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); return drck->set_allocation_state(drc, state); }


static void nic_save(QEMUFile * f, void *opaque) { EEPRO100State *s = opaque; int i; pci_device_save(&s->dev, f); qemu_put_8s(f, &s->rxcr); qemu_put_8s(f, &s->cmd); qemu_put_be32s(f, &s->start); qemu_put_be32s(f, &s->stop); qemu_put_8s(f, &s->boundary); qemu_put_8s(f, &s->tsr); qemu_put_8s(f, &s->tpsr); qemu_put_be16s(f, &s->tcnt); qemu_put_be16s(f, &s->rcnt); qemu_put_be32s(f, &s->rsar); qemu_put_8s(f, &s->rsr); qemu_put_8s(f, &s->isr); qemu_put_8s(f, &s->dcfg); qemu_put_8s(f, &s->imr); qemu_put_buffer(f, s->phys, 6); qemu_put_8s(f, &s->curpag); qemu_put_buffer(f, s->mult, 8); qemu_put_buffer(f, s->mem, sizeof(s->mem)); /* Save all members of struct between scv_stat and mem. */ qemu_put_8s(f, &s->scb_stat); qemu_put_8s(f, &s->int_stat); for (i = 0; i < 3; i++) { qemu_put_be32s(f, &s->region[i]); } qemu_put_buffer(f, s->macaddr, 6); for (i = 0; i < 19; i++) { qemu_put_be32s(f, &s->statcounter[i]); } for (i = 0; i < 32; i++) { qemu_put_be16s(f, &s->mdimem[i]); } /* The eeprom should be saved and restored by its own routines. */ qemu_put_be32s(f, &s->device); qemu_put_be32s(f, &s->pointer); qemu_put_be32s(f, &s->cu_base); qemu_put_be32s(f, &s->cu_offset); qemu_put_be32s(f, &s->ru_base); qemu_put_be32s(f, &s->ru_offset); qemu_put_be32s(f, &s->statsaddr); /* Save epro100_stats_t statistics. */ qemu_put_be32s(f, &s->statistics.tx_good_frames); qemu_put_be32s(f, &s->statistics.tx_max_collisions); qemu_put_be32s(f, &s->statistics.tx_late_collisions); qemu_put_be32s(f, &s->statistics.tx_underruns); qemu_put_be32s(f, &s->statistics.tx_lost_crs); qemu_put_be32s(f, &s->statistics.tx_deferred); qemu_put_be32s(f, &s->statistics.tx_single_collisions); qemu_put_be32s(f, &s->statistics.tx_multiple_collisions); qemu_put_be32s(f, &s->statistics.tx_total_collisions); qemu_put_be32s(f, &s->statistics.rx_good_frames); qemu_put_be32s(f, &s->statistics.rx_crc_errors); qemu_put_be32s(f, &s->statistics.rx_alignment_errors); qemu_put_be32s(f, &s->statistics.rx_resource_errors); qemu_put_be32s(f, &s->statistics.rx_overrun_errors); qemu_put_be32s(f, &s->statistics.rx_cdt_errors); qemu_put_be32s(f, &s->statistics.rx_short_frame_errors); qemu_put_be32s(f, &s->statistics.fc_xmt_pause); qemu_put_be32s(f, &s->statistics.fc_rcv_pause); qemu_put_be32s(f, &s->statistics.fc_rcv_unsupported); qemu_put_be16s(f, &s->statistics.xmt_tco_frames); qemu_put_be16s(f, &s->statistics.rcv_tco_frames); qemu_put_be32s(f, &s->statistics.complete); #if 0 qemu_put_be16s(f, &s->status); #endif /* Configuration bytes. */ qemu_put_buffer(f, s->configuration, sizeof(s->configuration)); }


static void terrier_init(int ram_size, int vga_ram_size, int boot_device, DisplayState *ds, const char **fd_filename, int snapshot, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { spitz_common_init(ram_size, vga_ram_size, ds, kernel_filename, kernel_cmdline, initrd_filename, terrier, 0x33f); }


int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush) { int ret = -EINPROGRESS; qed_write_l2_table(s, request, index, n, flush, qed_sync_cb, &ret); while (ret == -EINPROGRESS) { aio_poll(bdrv_get_aio_context(s->bs), true); } return ret; }


static void encode_picture(MpegEncContext *s, int picture_number) { int mb_x, mb_y, pdif = 0; int i; int bits; MpegEncContext best_s, backup_s; uint8_t bit_buf[2][3000]; uint8_t bit_buf2[2][3000]; uint8_t bit_buf_tex[2][3000]; PutBitContext pb[2], pb2[2], tex_pb[2]; for(i=0; i<2; i++){ init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); } s->picture_number = picture_number; s->block_wrap[0]= s->block_wrap[1]= s->block_wrap[2]= s->block_wrap[3]= s->mb_width*2 + 2; s->block_wrap[4]= s->block_wrap[5]= s->mb_width + 2; /* Reset the average MB variance */ s->current_picture.mb_var_sum = 0; s->current_picture.mc_mb_var_sum = 0; #ifdef CONFIG_RISKY /* we need to initialize some time vars before we can encode b-frames */ // RAL: Condition added for MPEG1VIDEO if (s->codec_id == CODEC_ID_MPEG1VIDEO || (s->h263_pred && !s->h263_msmpeg4)) ff_set_mpeg4_time(s, s->picture_number); #endif s->scene_change_score=0; s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration if(s->msmpeg4_version){ if(s->pict_type==I_TYPE) s->no_rounding=1; else if(s->flipflop_rounding) s->no_rounding ^= 1; }else if(s->out_format == FMT_H263){ if(s->pict_type==I_TYPE) s->no_rounding=0; else if(s->pict_type!=B_TYPE) s->no_rounding ^= 1; } /* Estimate motion for every MB */ s->mb_intra=0; //for the rate distoration & bit compare functions if(s->pict_type != I_TYPE){ if(s->pict_type != B_TYPE){ if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ s->me.pre_pass=1; s->me.dia_size= s->avctx->pre_dia_size; for(mb_y=s->mb_height-1; mb_y >=0 ; mb_y--) { for(mb_x=s->mb_width-1; mb_x >=0 ; mb_x--) { s->mb_x = mb_x; s->mb_y = mb_y; ff_pre_estimate_p_frame_motion(s, mb_x, mb_y); } } s->me.pre_pass=0; } } s->me.dia_size= s->avctx->dia_size; for(mb_y=0; mb_y < s->mb_height; mb_y++) { s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); for(mb_x=0; mb_x < s->mb_width; mb_x++) { s->mb_x = mb_x; s->mb_y = mb_y; s->block_index[0]+=2; s->block_index[1]+=2; s->block_index[2]+=2; s->block_index[3]+=2; /* compute motion vector & mb_type and store in context */ if(s->pict_type==B_TYPE) ff_estimate_b_frame_motion(s, mb_x, mb_y); else ff_estimate_p_frame_motion(s, mb_x, mb_y); } } }else /* if(s->pict_type == I_TYPE) */{ /* I-Frame */ //FIXME do we need to zero them? memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_width+2)*(s->mb_height+2)*2); memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height); if(!s->fixed_qscale){ /* finding spatial complexity for I-frame rate control */ for(mb_y=0; mb_y < s->mb_height; mb_y++) { for(mb_x=0; mb_x < s->mb_width; mb_x++) { int xx = mb_x * 16; int yy = mb_y * 16; uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; int varc; int sum = s->dsp.pix_sum(pix, s->linesize); varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; s->current_picture.mb_var [s->mb_width * mb_y + mb_x] = varc; s->current_picture.mb_mean[s->mb_width * mb_y + mb_x] = (sum+128)>>8; s->current_picture.mb_var_sum += varc; } } } } emms_c(); if(s->scene_change_score > 0 && s->pict_type == P_TYPE){ s->pict_type= I_TYPE; memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height); //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); } if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); // RAL: Next call moved into that bloc ff_fix_long_p_mvs(s); } // RAL: All this bloc changed if(s->pict_type==B_TYPE){ int a, b; a = ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, MB_TYPE_BIDIR); s->f_code = FFMAX(a, b); a = ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, MB_TYPE_BIDIR); s->b_code = FFMAX(a, b); ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR); } if (s->fixed_qscale) s->frame_qscale = s->current_picture.quality; else s->frame_qscale = ff_rate_estimate_qscale(s); if(s->adaptive_quant){ #ifdef CONFIG_RISKY switch(s->codec_id){ case CODEC_ID_MPEG4: ff_clean_mpeg4_qscales(s); break; case CODEC_ID_H263: case CODEC_ID_H263P: ff_clean_h263_qscales(s); break; } #endif s->qscale= s->current_picture.qscale_table[0]; }else s->qscale= (int)(s->frame_qscale + 0.5); if (s->out_format == FMT_MJPEG) { /* for mjpeg, we do include qscale in the matrix */ s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; for(i=1;i<64;i++){ int j= s->idct_permutation[i]; s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); } convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8); } //FIXME var duplication s->current_picture.key_frame= s->pict_type == I_TYPE; s->current_picture.pict_type= s->pict_type; if(s->current_picture.key_frame) s->picture_in_gop_number=0; s->last_bits= get_bit_count(&s->pb); switch(s->out_format) { case FMT_MJPEG: mjpeg_picture_header(s); break; #ifdef CONFIG_RISKY case FMT_H263: if (s->codec_id == CODEC_ID_WMV2) ff_wmv2_encode_picture_header(s, picture_number); else if (s->h263_msmpeg4) msmpeg4_encode_picture_header(s, picture_number); else if (s->h263_pred) mpeg4_encode_picture_header(s, picture_number); else if (s->h263_rv10) rv10_encode_picture_header(s, picture_number); else h263_encode_picture_header(s, picture_number); break; #endif case FMT_MPEG1: mpeg1_encode_picture_header(s, picture_number); break; } bits= get_bit_count(&s->pb); s->header_bits= bits - s->last_bits; s->last_bits= bits; s->mv_bits=0; s->misc_bits=0; s->i_tex_bits=0; s->p_tex_bits=0; s->i_count=0; s->f_count=0; s->b_count=0; s->skip_count=0; for(i=0; i<3; i++){ /* init last dc values */ /* note: quant matrix value (8) is implied here */ s->last_dc[i] = 128; s->current_picture.error[i] = 0; } s->mb_incr = 1; s->last_mv[0][0][0] = 0; s->last_mv[0][0][1] = 0; s->last_mv[1][0][0] = 0; s->last_mv[1][0][1] = 0; s->last_mv_dir = 0; #ifdef CONFIG_RISKY if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P) s->gob_index = ff_h263_get_gob_height(s); if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) ff_mpeg4_init_partitions(s); #endif s->resync_mb_x=0; s->resync_mb_y=0; s->first_slice_line = 1; s->ptr_lastgob = s->pb.buf; s->ptr_last_mb_line = s->pb.buf; for(mb_y=0; mb_y < s->mb_height; mb_y++) { s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); for(mb_x=0; mb_x < s->mb_width; mb_x++) { int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; // int d; int dmin=10000000; s->mb_x = mb_x; s->mb_y = mb_y; s->block_index[0]+=2; s->block_index[1]+=2; s->block_index[2]+=2; s->block_index[3]+=2; s->block_index[4]++; s->block_index[5]++; /* write gob / video packet header */ #ifdef CONFIG_RISKY if(s->rtp_mode){ int current_packet_size, is_gob_start; current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; is_gob_start=0; if(s->codec_id==CODEC_ID_MPEG4){ if(current_packet_size + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size && s->mb_y + s->mb_x>0){ if(s->partitioned_frame){ ff_mpeg4_merge_partitions(s); ff_mpeg4_init_partitions(s); } ff_mpeg4_encode_video_packet_header(s); if(s->flags&CODEC_FLAG_PASS1){ int bits= get_bit_count(&s->pb); s->misc_bits+= bits - s->last_bits; s->last_bits= bits; } ff_mpeg4_clean_buffers(s); is_gob_start=1; } }else{ if(current_packet_size + s->mb_line_avgsize*s->gob_index >= s->rtp_payload_size && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){ h263_encode_gob_header(s, mb_y); is_gob_start=1; } } if(is_gob_start){ s->ptr_lastgob = pbBufPtr(&s->pb); s->first_slice_line=1; s->resync_mb_x=mb_x; s->resync_mb_y=mb_y; } } #endif if( (s->resync_mb_x == s->mb_x) && s->resync_mb_y+1 == s->mb_y){ s->first_slice_line=0; } if(mb_type & (mb_type-1)){ // more than 1 MB type possible int next_block=0; int pb_bits_count, pb2_bits_count, tex_pb_bits_count; copy_context_before_encode(&backup_s, s, -1); backup_s.pb= s->pb; best_s.data_partitioning= s->data_partitioning; best_s.partitioned_frame= s->partitioned_frame; if(s->data_partitioning){ backup_s.pb2= s->pb2; backup_s.tex_pb= s->tex_pb; } if(mb_type&MB_TYPE_INTER){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->p_mv_table[xy][0]; s->mv[0][0][1] = s->p_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&MB_TYPE_INTER4V){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; } encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&MB_TYPE_FORWARD){ s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&MB_TYPE_BACKWARD){ s->mv_dir = MV_DIR_BACKWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[1][0][0] = s->b_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_back_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); } if(mb_type&MB_TYPE_BIDIR){ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mv_type = MV_TYPE_16X16; s->mb_intra= 0; s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&MB_TYPE_DIRECT){ int mx= s->b_direct_mv_table[xy][0]; int my= s->b_direct_mv_table[xy][1]; s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; s->mb_intra= 0; #ifdef CONFIG_RISKY ff_mpeg4_set_direct_mv(s, mx, my); #endif encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, &dmin, &next_block, mx, my); } if(mb_type&MB_TYPE_INTRA){ s->mv_dir = 0; s->mv_type = MV_TYPE_16X16; s->mb_intra= 1; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); /* force cleaning of ac/dc pred stuff if needed ... */ if(s->h263_pred || s->h263_aic) s->mbintra_table[mb_x + mb_y*s->mb_width]=1; } copy_context_after_encode(s, &best_s, -1); pb_bits_count= get_bit_count(&s->pb); flush_put_bits(&s->pb); ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); s->pb= backup_s.pb; if(s->data_partitioning){ pb2_bits_count= get_bit_count(&s->pb2); flush_put_bits(&s->pb2); ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); s->pb2= backup_s.pb2; tex_pb_bits_count= get_bit_count(&s->tex_pb); flush_put_bits(&s->tex_pb); ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); s->tex_pb= backup_s.tex_pb; } s->last_bits= get_bit_count(&s->pb); } else { int motion_x, motion_y; int intra_score; int inter_score= s->current_picture.mb_cmp_score[mb_x + mb_y*s->mb_width]; if(!(s->flags&CODEC_FLAG_HQ) && s->pict_type==P_TYPE){ /* get luma score */ if((s->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ intra_score= (s->current_picture.mb_var[mb_x + mb_y*s->mb_width]<<8) - 500; //FIXME dont scale it down so we dont have to fix it }else{ uint8_t *dest_y; int mean= s->current_picture.mb_mean[mb_x + mb_y*s->mb_width]; //FIXME mean*= 0x01010101; dest_y = s->new_picture.data[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; for(i=0; i<16; i++){ *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 0]) = mean; *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 4]) = mean; *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 8]) = mean; *(uint32_t*)(&s->me.scratchpad[i*s->linesize+12]) = mean; } s->mb_intra=1; intra_score= s->dsp.mb_cmp[0](s, s->me.scratchpad, dest_y, s->linesize); /* printf("intra:%7d inter:%7d var:%7d mc_var.%7d\n", intra_score>>8, inter_score>>8, s->current_picture.mb_var[mb_x + mb_y*s->mb_width], s->current_picture.mc_mb_var[mb_x + mb_y*s->mb_width]);*/ } /* get chroma score */ if(s->avctx->mb_cmp&FF_CMP_CHROMA){ int i; s->mb_intra=1; for(i=1; i<3; i++){ uint8_t *dest_c; int mean; if(s->out_format == FMT_H263){ mean= (s->dc_val[i][mb_x + (mb_y+1)*(s->mb_width+2)] + 4)>>3; //FIXME not exact but simple ;) }else{ mean= (s->last_dc[i] + 4)>>3; } dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; mean*= 0x01010101; for(i=0; i<8; i++){ *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 0]) = mean; *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 4]) = mean; } intra_score+= s->dsp.mb_cmp[1](s, s->me.scratchpad, dest_c, s->uvlinesize); } } /* bias */ switch(s->avctx->mb_cmp&0xFF){ default: case FF_CMP_SAD: intra_score+= 32*s->qscale; break; case FF_CMP_SSE: intra_score+= 24*s->qscale*s->qscale; break; case FF_CMP_SATD: intra_score+= 96*s->qscale; break; case FF_CMP_DCT: intra_score+= 48*s->qscale; break; case FF_CMP_BIT: intra_score+= 16; break; case FF_CMP_PSNR: case FF_CMP_RD: intra_score+= (s->qscale*s->qscale*109*8 + 64)>>7; break; } if(intra_score < inter_score) mb_type= MB_TYPE_INTRA; } s->mv_type=MV_TYPE_16X16; // only one MB-Type possible switch(mb_type){ case MB_TYPE_INTRA: s->mv_dir = 0; s->mb_intra= 1; motion_x= s->mv[0][0][0] = 0; motion_y= s->mv[0][0][1] = 0; break; case MB_TYPE_INTER: s->mv_dir = MV_DIR_FORWARD; s->mb_intra= 0; motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; break; case MB_TYPE_INTER4V: s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_8X8; s->mb_intra= 0; for(i=0; i<4; i++){ s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; } motion_x= motion_y= 0; break; case MB_TYPE_DIRECT: s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; s->mb_intra= 0; motion_x=s->b_direct_mv_table[xy][0]; motion_y=s->b_direct_mv_table[xy][1]; #ifdef CONFIG_RISKY ff_mpeg4_set_direct_mv(s, motion_x, motion_y); #endif break; case MB_TYPE_BIDIR: s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; s->mb_intra= 0; motion_x=0; motion_y=0; s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; break; case MB_TYPE_BACKWARD: s->mv_dir = MV_DIR_BACKWARD; s->mb_intra= 0; motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; break; case MB_TYPE_FORWARD: s->mv_dir = MV_DIR_FORWARD; s->mb_intra= 0; motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; // printf(" %d %d ", motion_x, motion_y); break; default: motion_x=motion_y=0; //gcc warning fix printf("illegal MB type\n"); } encode_mb(s, motion_x, motion_y); // RAL: Update last macrobloc type s->last_mv_dir = s->mv_dir; } /* clean the MV table in IPS frames for direct mode in B frames */ if(s->mb_intra /* && I,P,S_TYPE */){ s->p_mv_table[xy][0]=0; s->p_mv_table[xy][1]=0; } MPV_decode_mb(s, s->block); if(s->flags&CODEC_FLAG_PSNR){ int w= 16; int h= 16; if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; s->current_picture.error[0] += sse( s, s->new_picture .data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->current_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, w, h, s->linesize); s->current_picture.error[1] += sse( s, s->new_picture .data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, s->current_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, w>>1, h>>1, s->uvlinesize); s->current_picture.error[2] += sse( s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, s->current_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, w>>1, h>>1, s->uvlinesize); } //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); } /* Obtain average mb_row size for RTP */ if (s->rtp_mode) { if (mb_y==0) s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; else { s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; } s->ptr_last_mb_line = pbBufPtr(&s->pb); } } emms_c(); #ifdef CONFIG_RISKY if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) ff_mpeg4_merge_partitions(s); if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) msmpeg4_encode_ext_header(s); if(s->codec_id==CODEC_ID_MPEG4) ff_mpeg4_stuffing(&s->pb); #endif //if (s->gob_number) // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); /* Send the last GOB if RTP */ if (s->rtp_mode) { flush_put_bits(&s->pb); pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; /* Call the RTP callback to send the last GOB */ if (s->rtp_callback) s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); s->ptr_lastgob = pbBufPtr(&s->pb); //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); } }


static void *spapr_create_fdt_skel(hwaddr initrd_base, hwaddr initrd_size, hwaddr kernel_size, bool little_endian, const char *kernel_cmdline, uint32_t epow_irq) { void *fdt; uint32_t start_prop = cpu_to_be32(initrd_base); uint32_t end_prop = cpu_to_be32(initrd_base + initrd_size); GString *hypertas = g_string_sized_new(256); GString *qemu_hypertas = g_string_sized_new(256); uint32_t refpoints[] = {cpu_to_be32(0x4), cpu_to_be32(0x4)}; uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(max_cpus)}; unsigned char vec5[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x80}; char *buf; add_str(hypertas, "hcall-pft"); add_str(hypertas, "hcall-term"); add_str(hypertas, "hcall-dabr"); add_str(hypertas, "hcall-interrupt"); add_str(hypertas, "hcall-tce"); add_str(hypertas, "hcall-vio"); add_str(hypertas, "hcall-splpar"); add_str(hypertas, "hcall-bulk"); add_str(hypertas, "hcall-set-mode"); add_str(hypertas, "hcall-sprg0"); add_str(hypertas, "hcall-copy"); add_str(hypertas, "hcall-debug"); add_str(qemu_hypertas, "hcall-memop1"); fdt = g_malloc0(FDT_MAX_SIZE); _FDT((fdt_create(fdt, FDT_MAX_SIZE))); if (kernel_size) { _FDT((fdt_add_reservemap_entry(fdt, KERNEL_LOAD_ADDR, kernel_size))); } if (initrd_size) { _FDT((fdt_add_reservemap_entry(fdt, initrd_base, initrd_size))); } _FDT((fdt_finish_reservemap(fdt))); /* Root node */ _FDT((fdt_begin_node(fdt, ""))); _FDT((fdt_property_string(fdt, "device_type", "chrp"))); _FDT((fdt_property_string(fdt, "model", "IBM pSeries (emulated by qemu)"))); _FDT((fdt_property_string(fdt, "compatible", "qemu,pseries"))); /* * Add info to guest to indentify which host is it being run on * and what is the uuid of the guest */ if (kvmppc_get_host_model(&buf)) { _FDT((fdt_property_string(fdt, "host-model", buf))); g_free(buf); } if (kvmppc_get_host_serial(&buf)) { _FDT((fdt_property_string(fdt, "host-serial", buf))); g_free(buf); } buf = g_strdup_printf(UUID_FMT, qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], qemu_uuid[15]); _FDT((fdt_property_string(fdt, "vm,uuid", buf))); if (qemu_uuid_set) { _FDT((fdt_property_string(fdt, "system-id", buf))); } g_free(buf); if (qemu_get_vm_name()) { _FDT((fdt_property_string(fdt, "ibm,partition-name", qemu_get_vm_name()))); } _FDT((fdt_property_cell(fdt, "#address-cells", 0x2))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x2))); /* /chosen */ _FDT((fdt_begin_node(fdt, "chosen"))); /* Set Form1_affinity */ _FDT((fdt_property(fdt, "ibm,architecture-vec-5", vec5, sizeof(vec5)))); _FDT((fdt_property_string(fdt, "bootargs", kernel_cmdline))); _FDT((fdt_property(fdt, "linux,initrd-start", &start_prop, sizeof(start_prop)))); _FDT((fdt_property(fdt, "linux,initrd-end", &end_prop, sizeof(end_prop)))); if (kernel_size) { uint64_t kprop[2] = { cpu_to_be64(KERNEL_LOAD_ADDR), cpu_to_be64(kernel_size) }; _FDT((fdt_property(fdt, "qemu,boot-kernel", &kprop, sizeof(kprop)))); if (little_endian) { _FDT((fdt_property(fdt, "qemu,boot-kernel-le", NULL, 0))); } } if (boot_menu) { _FDT((fdt_property_cell(fdt, "qemu,boot-menu", boot_menu))); } _FDT((fdt_property_cell(fdt, "qemu,graphic-width", graphic_width))); _FDT((fdt_property_cell(fdt, "qemu,graphic-height", graphic_height))); _FDT((fdt_property_cell(fdt, "qemu,graphic-depth", graphic_depth))); _FDT((fdt_end_node(fdt))); /* RTAS */ _FDT((fdt_begin_node(fdt, "rtas"))); if (!kvm_enabled() || kvmppc_spapr_use_multitce()) { add_str(hypertas, "hcall-multi-tce"); } _FDT((fdt_property(fdt, "ibm,hypertas-functions", hypertas->str, hypertas->len))); g_string_free(hypertas, TRUE); _FDT((fdt_property(fdt, "qemu,hypertas-functions", qemu_hypertas->str, qemu_hypertas->len))); g_string_free(qemu_hypertas, TRUE); _FDT((fdt_property(fdt, "ibm,associativity-reference-points", refpoints, sizeof(refpoints)))); _FDT((fdt_property_cell(fdt, "rtas-error-log-max", RTAS_ERROR_LOG_MAX))); _FDT((fdt_property_cell(fdt, "rtas-event-scan-rate", RTAS_EVENT_SCAN_RATE))); if (msi_nonbroken) { _FDT((fdt_property(fdt, "ibm,change-msix-capable", NULL, 0))); } /* * According to PAPR, rtas ibm,os-term does not guarantee a return * back to the guest cpu. * * While an additional ibm,extended-os-term property indicates that * rtas call return will always occur. Set this property. */ _FDT((fdt_property(fdt, "ibm,extended-os-term", NULL, 0))); _FDT((fdt_end_node(fdt))); /* interrupt controller */ _FDT((fdt_begin_node(fdt, "interrupt-controller"))); _FDT((fdt_property_string(fdt, "device_type", "PowerPC-External-Interrupt-Presentation"))); _FDT((fdt_property_string(fdt, "compatible", "IBM,ppc-xicp"))); _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); _FDT((fdt_property(fdt, "ibm,interrupt-server-ranges", interrupt_server_ranges_prop, sizeof(interrupt_server_ranges_prop)))); _FDT((fdt_property_cell(fdt, "#interrupt-cells", 2))); _FDT((fdt_property_cell(fdt, "linux,phandle", PHANDLE_XICP))); _FDT((fdt_property_cell(fdt, "phandle", PHANDLE_XICP))); _FDT((fdt_end_node(fdt))); /* vdevice */ _FDT((fdt_begin_node(fdt, "vdevice"))); _FDT((fdt_property_string(fdt, "device_type", "vdevice"))); _FDT((fdt_property_string(fdt, "compatible", "IBM,vdevice"))); _FDT((fdt_property_cell(fdt, "#address-cells", 0x1))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x0))); _FDT((fdt_property_cell(fdt, "#interrupt-cells", 0x2))); _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); _FDT((fdt_end_node(fdt))); /* event-sources */ spapr_events_fdt_skel(fdt, epow_irq); /* /hypervisor node */ if (kvm_enabled()) { uint8_t hypercall[16]; /* indicate KVM hypercall interface */ _FDT((fdt_begin_node(fdt, "hypervisor"))); _FDT((fdt_property_string(fdt, "compatible", "linux,kvm"))); if (kvmppc_has_cap_fixup_hcalls()) { /* * Older KVM versions with older guest kernels were broken with the * magic page, don't allow the guest to map it. */ if (!kvmppc_get_hypercall(first_cpu->env_ptr, hypercall, sizeof(hypercall))) { _FDT((fdt_property(fdt, "hcall-instructions", hypercall, sizeof(hypercall)))); } } _FDT((fdt_end_node(fdt))); } _FDT((fdt_end_node(fdt))); /* close root node */ _FDT((fdt_finish(fdt))); return fdt; }


static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, QEMUTimer *timer, void (*raise_excp)(PowerPCCPU *), uint32_t decr, uint32_t value, int is_excp) { CPUPPCState *env = &cpu->env; ppc_tb_t *tb_env = env->tb_env; uint64_t now, next; LOG_TB("%s: %08" PRIx32 " => %08" PRIx32 "\n", __func__, decr, value); if (kvm_enabled()) { /* KVM handles decrementer exceptions, we don't need our own timer */ return; } now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); next = now + muldiv64(value, get_ticks_per_sec(), tb_env->decr_freq); if (is_excp) { next += *nextp - now; } if (next == now) { next++; } *nextp = next; /* Adjust timer */ timer_mod(timer, next); /* If we set a negative value and the decrementer was positive, raise an * exception. */ if ((tb_env->flags & PPC_DECR_UNDERFLOW_TRIGGERED) && (value & 0x80000000) && !(decr & 0x80000000)) { (*raise_excp)(cpu); } }


static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async) { if (async) { #if SPICE_INTERFACE_QXL_MINOR < 1 abort(); #else spice_qxl_destroy_surfaces_async(&qxl->ssd.qxl, 0); #endif } else { qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker); qxl_spice_destroy_surfaces_complete(qxl); } }


static inline void gen_neon_mull(TCGv dest, TCGv a, TCGv b, int size, int u) { TCGv tmp; switch ((size << 1) | u) { case 0: gen_helper_neon_mull_s8(dest, a, b); break; case 1: gen_helper_neon_mull_u8(dest, a, b); break; case 2: gen_helper_neon_mull_s16(dest, a, b); break; case 3: gen_helper_neon_mull_u16(dest, a, b); break; case 4: tmp = gen_muls_i64_i32(a, b); tcg_gen_mov_i64(dest, tmp); break; case 5: tmp = gen_mulu_i64_i32(a, b); tcg_gen_mov_i64(dest, tmp); break; default: abort(); } if (size < 2) { dead_tmp(b); dead_tmp(a); } }


static void imx_timerp_write(void *opaque, target_phys_addr_t offset, uint64_t value, unsigned size) { IMXTimerPState *s = (IMXTimerPState *)opaque; DPRINTF("p-write(offset=%x, value = %x)\n", (unsigned int)offset >> 2, (unsigned int)value); switch (offset >> 2) { case 0: /* CR */ if (value & CR_SWR) { imx_timerp_reset(&s->busdev.qdev); value &= ~CR_SWR; } s->cr = value & 0x03ffffff; set_timerp_freq(s); if (s->freq && (s->cr & CR_EN)) { if (!(s->cr & CR_ENMOD)) { ptimer_set_count(s->timer, s->lr); } ptimer_run(s->timer, 0); } else { ptimer_stop(s->timer); } break; case 1: /* SR - ACK*/ s->int_level = 0; imx_timerp_update(s); break; case 2: /* LR - set ticks */ s->lr = value; ptimer_set_limit(s->timer, value, !!(s->cr & CR_IOVW)); break; case 3: /* CMP */ s->cmp = value; if (value) { IPRINTF( "Values for EPIT comparison other than zero not supported\n" ); } break; default: IPRINTF("imx_timerp_write: Bad offset %x\n", (int)offset >> 2); } }


static int nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply, int len) { NBDClient *client = req->client; int csock = client->sock; int rc, ret; qemu_co_mutex_lock(&client->send_lock); qemu_set_fd_handler2(csock, NULL, nbd_read, nbd_restart_write, client); client->send_coroutine = qemu_coroutine_self(); if (!len) { rc = nbd_send_reply(csock, reply); if (rc == -1) { rc = -errno; } } else { socket_set_cork(csock, 1); rc = nbd_send_reply(csock, reply); if (rc != -1) { ret = qemu_co_send(csock, req->data, len); if (ret != len) { errno = EIO; rc = -1; } } if (rc == -1) { rc = -errno; } socket_set_cork(csock, 0); } client->send_coroutine = NULL; qemu_set_fd_handler2(csock, NULL, nbd_read, NULL, client); qemu_co_mutex_unlock(&client->send_lock); return rc; }


static uint32_t get_features(VirtIODevice *vdev, uint32_t features) { VirtIOSerial *vser; vser = VIRTIO_SERIAL(vdev); if (vser->bus.max_nr_ports > 1) { features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT); } return features; }


static int proxy_fsync(FsContext *ctx, int fid_type, V9fsFidOpenState *fs, int datasync) { int fd; if (fid_type == P9_FID_DIR) { fd = dirfd(fs->dir); } else { fd = fs->fd; } if (datasync) { return qemu_fdatasync(fd); } else { return fsync(fd); } }


static int xen_pt_bar_reg_read(XenPCIPassthroughState *s, XenPTReg *cfg_entry, uint32_t *value, uint32_t valid_mask) { XenPTRegInfo *reg = cfg_entry->reg; uint32_t valid_emu_mask = 0; uint32_t bar_emu_mask = 0; int index; /* get BAR index */ index = xen_pt_bar_offset_to_index(reg->offset); if (index < 0 || index >= PCI_NUM_REGIONS - 1) { XEN_PT_ERR(&s->dev, "Internal error: Invalid BAR index [%d].\n", index); return -1; } /* use fixed-up value from kernel sysfs */ *value = base_address_with_flags(&s->real_device.io_regions[index]); /* set emulate mask depend on BAR flag */ switch (s->bases[index].bar_flag) { case XEN_PT_BAR_FLAG_MEM: bar_emu_mask = XEN_PT_BAR_MEM_EMU_MASK; break; case XEN_PT_BAR_FLAG_IO: bar_emu_mask = XEN_PT_BAR_IO_EMU_MASK; break; case XEN_PT_BAR_FLAG_UPPER: bar_emu_mask = XEN_PT_BAR_ALLF; break; default: break; } /* emulate BAR */ valid_emu_mask = bar_emu_mask & valid_mask; *value = XEN_PT_MERGE_VALUE(*value, cfg_entry->data, ~valid_emu_mask); return 0; }


uint32_t ssi_transfer(SSIBus *bus, uint32_t val) { DeviceState *dev; SSISlave *slave; dev = LIST_FIRST(&bus->qbus.children); if (!dev) { return 0; } slave = SSI_SLAVE_FROM_QDEV(dev); return slave->info->transfer(slave, val); }


int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t sector_num, int nb_sectors, int *pnum) { BlockDriverState *intermediate; int ret, n = nb_sectors; intermediate = top; while (intermediate && intermediate != base) { int pnum_inter; ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors, &pnum_inter); if (ret < 0) { return ret; } else if (ret) { *pnum = pnum_inter; return 1; } /* * [sector_num, nb_sectors] is unallocated on top but intermediate * might have * * [sector_num+x, nr_sectors] allocated. */ if (n > pnum_inter && (intermediate == top || sector_num + pnum_inter < intermediate->total_sectors)) { n = pnum_inter; } intermediate = intermediate->backing_hd; } *pnum = n; return 0; }


static void do_info_kqemu(Monitor *mon) { #ifdef CONFIG_KQEMU CPUState *env; int val; val = 0; env = mon_get_cpu(); if (!env) { monitor_printf(mon, "No cpu initialized yet"); return; } val = env->kqemu_enabled; monitor_printf(mon, "kqemu support: "); switch(val) { default: case 0: monitor_printf(mon, "disabled\n"); break; case 1: monitor_printf(mon, "enabled for user code\n"); break; case 2: monitor_printf(mon, "enabled for user and kernel code\n"); break; } #else monitor_printf(mon, "kqemu support: not compiled\n"); #endif }


static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset, uint32_t value) { m5206_mbar_state *s = (m5206_mbar_state *)opaque; int width; offset &= 0x3ff; if (offset >= 0x200) { hw_error("Bad MBAR write offset 0x%x", (int)offset); } width = m5206_mbar_width[offset >> 2]; if (width > 1) { uint32_t tmp; tmp = m5206_mbar_readw(opaque, offset & ~1); if (offset & 1) { tmp = (tmp & 0xff00) | value; } else { tmp = (tmp & 0x00ff) | (value << 8); } m5206_mbar_writew(opaque, offset & ~1, tmp); return; } m5206_mbar_write(s, offset, value, 1); }


static void mv88w8618_pit_write(void *opaque, target_phys_addr_t offset, uint32_t value) { mv88w8618_pit_state *s = opaque; mv88w8618_timer_state *t; int i; switch (offset) { case MP_PIT_TIMER1_LENGTH ... MP_PIT_TIMER4_LENGTH: t = &s->timer[offset >> 2]; t->limit = value; ptimer_set_limit(t->ptimer, t->limit, 1); break; case MP_PIT_CONTROL: for (i = 0; i < 4; i++) { if (value & 0xf) { t = &s->timer[i]; ptimer_set_limit(t->ptimer, t->limit, 0); ptimer_set_freq(t->ptimer, t->freq); ptimer_run(t->ptimer, 0); } value >>= 4; } break; case MP_BOARD_RESET: if (value == MP_BOARD_RESET_MAGIC) { qemu_system_reset_request(); } break; } }


static void audio_detach_capture (HWVoiceOut *hw) { SWVoiceCap *sc = hw->cap_head.lh_first; while (sc) { SWVoiceCap *sc1 = sc->entries.le_next; SWVoiceOut *sw = &sc->sw; CaptureVoiceOut *cap = sc->cap; int was_active = sw->active; if (sw->rate) { st_rate_stop (sw->rate); sw->rate = NULL; } LIST_REMOVE (sw, entries); LIST_REMOVE (sc, entries); qemu_free (sc); if (was_active) { /* We have removed soft voice from the capture: this might have changed the overall status of the capture since this might have been the only active voice */ audio_recalc_and_notify_capture (cap); } sc = sc1; } }


unsigned s390_del_running_cpu(S390CPU *cpu) { CPUState *cs = CPU(cpu); if (cs->halted == 0) { assert(s390_running_cpus >= 1); s390_running_cpus--; cs->halted = 1; cs->exception_index = EXCP_HLT; } return s390_running_cpus; }


static int raw_fd_pool_get(BDRVRawState *s) { int i; for (i = 0; i < RAW_FD_POOL_SIZE; i++) { /* already in use */ if (s->fd_pool[i] != -1) continue; /* try to dup file descriptor */ s->fd_pool[i] = dup(s->fd); if (s->fd_pool[i] != -1) return s->fd_pool[i]; } /* we couldn't dup the file descriptor so just use the main one */ return s->fd; }


static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts) { const char *filename = opts->device; CharDriverState *chr; WinCharState *s; chr = g_malloc0(sizeof(CharDriverState)); s = g_malloc0(sizeof(WinCharState)); chr->opaque = s; chr->chr_write = win_chr_write; chr->chr_close = win_chr_close; if (win_chr_pipe_init(chr, filename) < 0) { g_free(s); g_free(chr); return NULL; } return chr; }


static void cirrus_linear_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { CirrusVGAState *s = opaque; unsigned mode; addr &= s->cirrus_addr_mask; if (((s->vga.sr[0x17] & 0x44) == 0x44) && ((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) { /* memory-mapped I/O */ cirrus_mmio_blt_write(s, addr & 0xff, val); } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) { /* bitblt */ *s->cirrus_srcptr++ = (uint8_t) val; if (s->cirrus_srcptr >= s->cirrus_srcptr_end) { cirrus_bitblt_cputovideo_next(s); } } else { /* video memory */ if ((s->vga.gr[0x0B] & 0x14) == 0x14) { addr <<= 4; } else if (s->vga.gr[0x0B] & 0x02) { addr <<= 3; } addr &= s->cirrus_addr_mask; mode = s->vga.gr[0x05] & 0x7; if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) { *(s->vga.vram_ptr + addr) = (uint8_t) val; memory_region_set_dirty(&s->vga.vram, addr, 1); } else { if ((s->vga.gr[0x0B] & 0x14) != 0x14) { cirrus_mem_writeb_mode4and5_8bpp(s, mode, addr, val); } else { cirrus_mem_writeb_mode4and5_16bpp(s, mode, addr, val); } } } }


static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) { GDBState *s = opaque; int i; for (i = 0; i < size; i++) { gdb_read_byte(s, buf[i]); } }


get_pointer_coordinates(int *x, int *y, Display *dpy, AVFormatContext *s1) { Window mrootwindow, childwindow; int dummy; mrootwindow = DefaultRootWindow(dpy); if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow, x, y, &dummy, &dummy, (unsigned int*)&dummy)) { } else { av_log(s1, AV_LOG_INFO, "couldn't find mouse pointer\n"); *x = -1; *y = -1; } }


uint64_t helper_stq_c_raw(uint64_t t0, uint64_t t1) { uint64_t ret; if (t1 == env->lock) { stq_raw(t1, t0); ret = 0; } else ret = 1; env->lock = 1; return ret; }


av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx) { const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8; c->diff_pixels = diff_pixels_c; switch (avctx->bits_per_raw_sample) { case 9: case 10: case 12: case 14: c->get_pixels = get_pixels_16_c; break; default: if (avctx->bits_per_raw_sample<=8 || avctx->codec_type != AVMEDIA_TYPE_VIDEO) { c->get_pixels = get_pixels_8_c; } break; } if (ARCH_ALPHA) ff_pixblockdsp_init_alpha(c, avctx, high_bit_depth); if (ARCH_ARM) ff_pixblockdsp_init_arm(c, avctx, high_bit_depth); if (ARCH_PPC) ff_pixblockdsp_init_ppc(c, avctx, high_bit_depth); if (ARCH_X86) ff_pixblockdsp_init_x86(c, avctx, high_bit_depth); if (ARCH_MIPS) ff_pixblockdsp_init_mips(c, avctx, high_bit_depth); }


static void gen_pusha(DisasContext *s) { int i; gen_op_movl_A0_reg(R_ESP); gen_op_addl_A0_im(-8 << s->dflag); if (!s->ss32) tcg_gen_ext16u_tl(cpu_A0, cpu_A0); tcg_gen_mov_tl(cpu_T[1], cpu_A0); if (s->addseg) gen_op_addl_A0_seg(s, R_SS); for(i = 0;i < 8; i++) { gen_op_mov_v_reg(MO_32, cpu_T[0], 7 - i); gen_op_st_v(s, s->dflag, cpu_T[0], cpu_A0); gen_op_addl_A0_im(1 << s->dflag); } gen_op_mov_reg_v(MO_16 + s->ss32, R_ESP, cpu_T[1]); }


static void usbredir_buffered_bulk_packet(void *priv, uint64_t id, struct usb_redir_buffered_bulk_packet_header *buffered_bulk_packet, uint8_t *data, int data_len) { USBRedirDevice *dev = priv; uint8_t status, ep = buffered_bulk_packet->endpoint; void *free_on_destroy; int i, len; DPRINTF("buffered-bulk-in status %d ep %02X len %d id %"PRIu64"\n", buffered_bulk_packet->status, ep, data_len, id); if (dev->endpoint[EP2I(ep)].type != USB_ENDPOINT_XFER_BULK) { ERROR("received buffered-bulk packet for non bulk ep %02X\n", ep); free(data); return; } if (dev->endpoint[EP2I(ep)].bulk_receiving_started == 0) { DPRINTF("received buffered-bulk packet on not started ep %02X\n", ep); free(data); return; } /* Data must be in maxp chunks for buffered_bulk_add_*_data_to_packet */ len = dev->endpoint[EP2I(ep)].max_packet_size; status = usb_redir_success; free_on_destroy = NULL; for (i = 0; i < data_len; i += len) { if (len >= (data_len - i)) { len = data_len - i; status = buffered_bulk_packet->status; free_on_destroy = data; } /* bufp_alloc also adds the packet to the ep queue */ bufp_alloc(dev, data + i, len, status, ep, free_on_destroy); } if (dev->endpoint[EP2I(ep)].pending_async_packet) { USBPacket *p = dev->endpoint[EP2I(ep)].pending_async_packet; dev->endpoint[EP2I(ep)].pending_async_packet = NULL; usbredir_buffered_bulk_in_complete(dev, p, ep); usb_packet_complete(&dev->dev, p); } }


static int poll_frame(AVFilterLink *link) { AVFilterContext *s = link->src; OverlayContext *over = s->priv; int ret = avfilter_poll_frame(s->inputs[OVERLAY]); if (ret == AVERROR_EOF) ret = !!over->overpicref; return ret && avfilter_poll_frame(s->inputs[MAIN]); }


static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, float *out, float X[2][38][64], float mdct_buf[2][64], float *v0, int *v_off, const unsigned int div) { int i, n; const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; float *v; for (i = 0; i < 32; i++) { if (*v_off == 0) { int saved_samples = (1280 - 128) >> div; memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div); } else { *v_off -= 128 >> div; } v = v0 + *v_off; if (div) { for (n = 0; n < 32; n++) { X[0][i][ n] = -X[0][i][n]; X[0][i][32+n] = X[1][i][31-n]; } mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); for (n = 0; n < 32; n++) { v[ n] = mdct_buf[0][63 - 2*n]; v[63 - n] = -mdct_buf[0][62 - 2*n]; } } else { for (n = 1; n < 64; n+=2) { X[1][i][n] = -X[1][i][n]; } mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); for (n = 0; n < 64; n++) { v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; } } dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div); dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); out += 64 >> div; } }


void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data) { VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); uint8_t val = data; if (addr > (vdev->config_len - sizeof(val))) return; stb_p(vdev->config + addr, val); if (k->set_config) { k->set_config(vdev, vdev->config); } }


static int get_qcx(J2kDecoderContext *s, int n, J2kQuantStyle *q) { int i, x; if (s->buf_end - s->buf < 1) return AVERROR(EINVAL); x = bytestream_get_byte(&s->buf); // Sqcd q->nguardbits = x >> 5; q->quantsty = x & 0x1f; if (q->quantsty == J2K_QSTY_NONE){ n -= 3; if (s->buf_end - s->buf < n) return AVERROR(EINVAL); for (i = 0; i < n; i++) q->expn[i] = bytestream_get_byte(&s->buf) >> 3; } else if (q->quantsty == J2K_QSTY_SI){ if (s->buf_end - s->buf < 2) return AVERROR(EINVAL); x = bytestream_get_be16(&s->buf); q->expn[0] = x >> 11; q->mant[0] = x & 0x7ff; for (i = 1; i < 32 * 3; i++){ int curexpn = FFMAX(0, q->expn[0] - (i-1)/3); q->expn[i] = curexpn; q->mant[i] = q->mant[0]; } } else{ n = (n - 3) >> 1; if (s->buf_end - s->buf < n) return AVERROR(EINVAL); for (i = 0; i < n; i++){ x = bytestream_get_be16(&s->buf); q->expn[i] = x >> 11; q->mant[i] = x & 0x7ff; } } return 0; }


static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track) { int pos = url_ftell(pb); char compressor_name[32]; int tag; put_be32(pb, 0); /* size */ tag = track->enc->codec_tag; if (!tag) tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id); // if no mac fcc found, try with Microsoft tags if (!tag) tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id); put_le32(pb, tag); // store it byteswapped put_be32(pb, 0); /* Reserved */ put_be16(pb, 0); /* Reserved */ put_be16(pb, 1); /* Data-reference index */ put_be16(pb, 0); /* Codec stream version */ put_be16(pb, 0); /* Codec stream revision (=0) */ put_tag(pb, "FFMP"); /* Vendor */ if(track->enc->codec_id == CODEC_ID_RAWVIDEO) { put_be32(pb, 0); /* Temporal Quality */ put_be32(pb, 0x400); /* Spatial Quality = lossless*/ } else { put_be32(pb, 0x200); /* Temporal Quality = normal */ put_be32(pb, 0x200); /* Spatial Quality = normal */ } put_be16(pb, track->enc->width); /* Video width */ put_be16(pb, track->enc->height); /* Video height */ put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */ put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */ put_be32(pb, 0); /* Data size (= 0) */ put_be16(pb, 1); /* Frame count (= 1) */ memset(compressor_name,0,32); if (track->enc->codec->name) strncpy(compressor_name,track->enc->codec->name,31); put_byte(pb, FFMAX(strlen(compressor_name),32) ); put_buffer(pb, compressor_name, 31); put_be16(pb, 0x18); /* Reserved */ put_be16(pb, 0xffff); /* Reserved */ if(track->enc->codec_id == CODEC_ID_MPEG4) mov_write_esds_tag(pb, track); else if(track->enc->codec_id == CODEC_ID_H263) mov_write_d263_tag(pb); else if(track->enc->codec_id == CODEC_ID_SVQ3) mov_write_svq3_tag(pb); return updateSize (pb, pos); }


yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW, int big_endian, int output_bits) { int i; int shift = 19 - output_bits; for (i = 0; i < dstW; i++) { int val = src[i] + (1 << (shift - 1)); output_pixel(&dest[i], val, 0, uint); } }


void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src) { MpegEncContext bak; int i; // FIXME copy only needed parts // START_TIMER backup_duplicate_context(&bak, dst); memcpy(dst, src, sizeof(MpegEncContext)); backup_duplicate_context(dst, &bak); for (i = 0; i < 12; i++) { dst->pblocks[i] = &dst->block[i]; } // STOP_TIMER("update_duplicate_context") // about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads }


static int mpeg_mux_read_header(AVFormatContext *s, AVFormatParameters *ap) { MpegDemuxContext *m; int size, startcode, c, rate_bound, audio_bound, video_bound, mux_rate, val; int codec_id, n, i, type; AVStream *st; m = av_mallocz(sizeof(MpegDemuxContext)); if (!m) return -ENOMEM; s->priv_data = m; /* search first pack header */ m->header_state = 0xff; size = MAX_SYNC_SIZE; for(;;) { while (size > 0) { startcode = find_start_code(&s->pb, &size, &m->header_state); if (startcode == PACK_START_CODE) goto found; } return -ENODATA; found: /* search system header just after pack header */ /* parse pack header */ get_byte(&s->pb); /* ts1 */ get_be16(&s->pb); /* ts2 */ get_be16(&s->pb); /* ts3 */ mux_rate = get_byte(&s->pb) << 16; mux_rate |= get_byte(&s->pb) << 8; mux_rate |= get_byte(&s->pb); mux_rate &= (1 << 22) - 1; m->mux_rate = mux_rate; startcode = find_start_code(&s->pb, &size, &m->header_state); if (startcode == SYSTEM_HEADER_START_CODE) break; } size = get_be16(&s->pb); rate_bound = get_byte(&s->pb) << 16; rate_bound |= get_byte(&s->pb) << 8; rate_bound |= get_byte(&s->pb); rate_bound = (rate_bound >> 1) & ((1 << 22) - 1); audio_bound = get_byte(&s->pb) >> 2; video_bound = get_byte(&s->pb) & 0x1f; get_byte(&s->pb); /* reserved byte */ #if 0 printf("mux_rate=%d kbit/s\n", (m->mux_rate * 50 * 8) / 1000); printf("rate_bound=%d\n", rate_bound); printf("audio_bound=%d\n", audio_bound); printf("video_bound=%d\n", video_bound); #endif size -= 6; s->nb_streams = 0; while (size > 0) { c = get_byte(&s->pb); size--; if ((c & 0x80) == 0) break; val = get_be16(&s->pb); size -= 2; if (c >= 0xc0 && c <= 0xdf) { /* mpeg audio stream */ type = CODEC_TYPE_AUDIO; codec_id = CODEC_ID_MP2; n = 1; c = c | 0x100; } else if (c >= 0xe0 && c <= 0xef) { type = CODEC_TYPE_VIDEO; codec_id = CODEC_ID_MPEG1VIDEO; n = 1; c = c | 0x100; } else if (c == 0xb8) { /* all audio streams */ /* XXX: hack for DVD: we force AC3, although we do not know that this codec will be used */ type = CODEC_TYPE_AUDIO; codec_id = CODEC_ID_AC3; n = audio_bound; c = 0x80; /* c = 0x1c0; */ } else if (c == 0xb9) { /* all video streams */ type = CODEC_TYPE_VIDEO; codec_id = CODEC_ID_MPEG1VIDEO; n = video_bound; c = 0x1e0; } else { type = 0; codec_id = 0; n = 0; } for(i=0;i<n;i++) { st = av_mallocz(sizeof(AVStream)); if (!st) return -ENOMEM; s->streams[s->nb_streams++] = st; st->id = c + i; st->codec.codec_type = type; st->codec.codec_id = codec_id; } } return 0; }


static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, size_t elt_ofs, target_ulong page) { size_t vidx; for (vidx = 0; vidx < CPU_VTLB_SIZE; ++vidx) { CPUTLBEntry *vtlb = &env->tlb_v_table[mmu_idx][vidx]; target_ulong cmp = *(target_ulong *)((uintptr_t)vtlb + elt_ofs); if (cmp == page) { /* Found entry in victim tlb, swap tlb and iotlb. */ CPUTLBEntry tmptlb, *tlb = &env->tlb_table[mmu_idx][index]; CPUIOTLBEntry tmpio, *io = &env->iotlb[mmu_idx][index]; CPUIOTLBEntry *vio = &env->iotlb_v[mmu_idx][vidx]; tmptlb = *tlb; *tlb = *vtlb; *vtlb = tmptlb; tmpio = *io; *io = *vio; *vio = tmpio; return true; } } return false; }


static inline unsigned in_reg(IVState *s, enum Reg reg) { const char *name = reg2str(reg); QTestState *qtest = global_qtest; unsigned res; global_qtest = s->qtest; res = qpci_io_readl(s->dev, s->reg_base + reg); g_test_message("*%s -> %x\n", name, res); global_qtest = qtest; return res; }


static void fw_cfg_init1(DeviceState *dev) { FWCfgState *s = FW_CFG(dev); MachineState *machine = MACHINE(qdev_get_machine()); uint32_t version = FW_CFG_VERSION; assert(!object_resolve_path(FW_CFG_PATH, NULL)); object_property_add_child(OBJECT(machine), FW_CFG_NAME, OBJECT(s), NULL); qdev_init_nofail(dev); fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4); fw_cfg_add_bytes(s, FW_CFG_UUID, &qemu_uuid, 16); fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics); fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu); fw_cfg_bootsplash(s); fw_cfg_reboot(s); if (s->dma_enabled) { version |= FW_CFG_VERSION_DMA; } fw_cfg_add_i32(s, FW_CFG_ID, version); s->machine_ready.notify = fw_cfg_machine_ready; qemu_add_machine_init_done_notifier(&s->machine_ready); }


static void bmdma_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type) { PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); int i; for(i = 0;i < 2; i++) { BMDMAState *bm = &d->bmdma[i]; d->bus[i].bmdma = bm; bm->bus = d->bus+i; qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm); register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm); register_ioport_write(addr + 1, 3, 1, bmdma_writeb, bm); register_ioport_read(addr, 4, 1, bmdma_readb, bm); register_ioport_write(addr + 4, 4, 1, bmdma_addr_writeb, bm); register_ioport_read(addr + 4, 4, 1, bmdma_addr_readb, bm); register_ioport_write(addr + 4, 4, 2, bmdma_addr_writew, bm); register_ioport_read(addr + 4, 4, 2, bmdma_addr_readw, bm); register_ioport_write(addr + 4, 4, 4, bmdma_addr_writel, bm); register_ioport_read(addr + 4, 4, 4, bmdma_addr_readl, bm); addr += 8; } }


static uint32_t softfloat_mul(uint32_t x, uint64_t mantissa) { uint64_t l = x * (mantissa & 0xffffffff); uint64_t h = x * (mantissa >> 32); h += l >> 32; l &= 0xffffffff; l += 1 << av_log2(h >> 21); h += l >> 32; return h >> 20; }


static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) { int last_index = gb->size_in_bits; const uint8_t *scan_table = mb->scan_table; const uint32_t *factor_table = mb->factor_table; int pos = mb->pos; int partial_bit_count = mb->partial_bit_count; int level, run, vlc_len, index; OPEN_READER(re, gb); UPDATE_CACHE(re, gb); /* if we must parse a partial VLC, we do it here */ if (partial_bit_count > 0) { re_cache = ((unsigned)re_cache >> partial_bit_count) | (mb->partial_bit_buffer << (sizeof(re_cache) * 8 - partial_bit_count)); re_index -= partial_bit_count; mb->partial_bit_count = 0; } /* get the AC coefficients until last_index is reached */ for (;;) { av_dlog(NULL, "%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), re_index); /* our own optimized GET_RL_VLC */ index = NEG_USR32(re_cache, TEX_VLC_BITS); vlc_len = dv_rl_vlc[index].len; if (vlc_len < 0) { index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level; vlc_len = TEX_VLC_BITS - vlc_len; } level = dv_rl_vlc[index].level; run = dv_rl_vlc[index].run; /* gotta check if we're still within gb boundaries */ if (re_index + vlc_len > last_index) { /* should be < 16 bits otherwise a codeword could have been parsed */ mb->partial_bit_count = last_index - re_index; mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count); re_index = last_index; break; } re_index += vlc_len; av_dlog(NULL, "run=%d level=%d\n", run, level); pos += run; if (pos >= 64) break; level = (level * factor_table[pos] + (1 << (dv_iweight_bits - 1))) >> dv_iweight_bits; block[scan_table[pos]] = level; UPDATE_CACHE(re, gb); } CLOSE_READER(re, gb); mb->pos = pos; }


void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(OBJECT(hotplug_dev)); sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc = CPU_CORE(dev); CPUState *cs = CPU(core->threads); sPAPRDRConnector *drc; sPAPRDRConnectorClass *drck; Error *local_err = NULL; void *fdt = NULL; int fdt_offset = 0; int index = cc->core_id / smp_threads; int smt = kvmppc_smt_threads(); g_assert(smc->dr_cpu_enabled); drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index * smt); spapr->cores[index] = OBJECT(dev); g_assert(drc); /* * Setup CPU DT entries only for hotplugged CPUs. For boot time or * coldplugged CPUs DT entries are setup in spapr_finalize_fdt(). */ if (dev->hotplugged) { fdt = spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr); } drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err); if (local_err) { g_free(fdt); spapr->cores[index] = NULL; error_propagate(errp, local_err); return; } if (dev->hotplugged) { /* * Send hotplug notification interrupt to the guest only in case * of hotplugged CPUs. */ spapr_hotplug_req_add_by_index(drc); } else { /* * Set the right DRC states for cold plugged CPU. */ drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE); drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOLATED); } }


static void spatial_compose53i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){ int y= cs->y; DWTELEM *b0= cs->b0; DWTELEM *b1= cs->b1; DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; {START_TIMER if(b1 <= b3) vertical_compose53iL0(b1, b2, b3, width); if(b0 <= b2) vertical_compose53iH0(b0, b1, b2, width); STOP_TIMER("vertical_compose53i*")} {START_TIMER if(y-1 >= 0) horizontal_compose53i(b0, width); if(b0 <= b2) horizontal_compose53i(b1, width); STOP_TIMER("horizontal_compose53i")} cs->b0 = b2; cs->b1 = b3; cs->y += 2; }


static int cng_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { AVFrame *frame = data; CNGContext *p = avctx->priv_data; int buf_size = avpkt->size; int ret, i; int16_t *buf_out; float e = 1.0; float scaling; if (avpkt->size) { int dbov = -avpkt->data[0]; p->target_energy = 1081109975 * ff_exp10(dbov / 10.0) * 0.75; memset(p->target_refl_coef, 0, p->order * sizeof(*p->target_refl_coef)); for (i = 0; i < FFMIN(avpkt->size - 1, p->order); i++) { p->target_refl_coef[i] = (avpkt->data[1 + i] - 127) / 128.0; } } if (avctx->internal->skip_samples > 10 * avctx->frame_size) { avctx->internal->skip_samples = 0; return AVERROR_INVALIDDATA; } if (p->inited) { p->energy = p->energy / 2 + p->target_energy / 2; for (i = 0; i < p->order; i++) p->refl_coef[i] = 0.6 *p->refl_coef[i] + 0.4 * p->target_refl_coef[i]; } else { p->energy = p->target_energy; memcpy(p->refl_coef, p->target_refl_coef, p->order * sizeof(*p->refl_coef)); p->inited = 1; } make_lpc_coefs(p->lpc_coef, p->refl_coef, p->order); for (i = 0; i < p->order; i++) e *= 1.0 - p->refl_coef[i]*p->refl_coef[i]; scaling = sqrt(e * p->energy / 1081109975); for (i = 0; i < avctx->frame_size; i++) { int r = (av_lfg_get(&p->lfg) & 0xffff) - 0x8000; p->excitation[i] = scaling * r; } ff_celp_lp_synthesis_filterf(p->filter_out + p->order, p->lpc_coef, p->excitation, avctx->frame_size, p->order); frame->nb_samples = avctx->frame_size; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; buf_out = (int16_t *)frame->data[0]; for (i = 0; i < avctx->frame_size; i++) buf_out[i] = p->filter_out[i + p->order]; memcpy(p->filter_out, p->filter_out + avctx->frame_size, p->order * sizeof(*p->filter_out)); *got_frame_ptr = 1; return buf_size; }


static av_cold int vdadec_init(AVCodecContext *avctx) { VDADecoderContext *ctx = avctx->priv_data; struct vda_context *vda_ctx = &ctx->vda_ctx; OSStatus status; int ret; ctx->h264_initialized = 0; /* init pix_fmts of codec */ if (!ff_h264_vda_decoder.pix_fmts) { if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7) ff_h264_vda_decoder.pix_fmts = vda_pixfmts_prior_10_7; else ff_h264_vda_decoder.pix_fmts = vda_pixfmts; /* init vda */ memset(vda_ctx, 0, sizeof(struct vda_context)); vda_ctx->width = avctx->width; vda_ctx->height = avctx->height; vda_ctx->format = 'avc1'; vda_ctx->use_sync_decoding = 1; vda_ctx->use_ref_buffer = 1; ctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); switch (ctx->pix_fmt) { case AV_PIX_FMT_UYVY422: vda_ctx->cv_pix_fmt_type = '2vuy'; break; case AV_PIX_FMT_YUYV422: vda_ctx->cv_pix_fmt_type = 'yuvs'; break; case AV_PIX_FMT_NV12: vda_ctx->cv_pix_fmt_type = '420v'; break; case AV_PIX_FMT_YUV420P: vda_ctx->cv_pix_fmt_type = 'y420'; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n", avctx->pix_fmt); status = ff_vda_create_decoder(vda_ctx, avctx->extradata, avctx->extradata_size); if (status != kVDADecoderNoErr) { av_log(avctx, AV_LOG_ERROR, "Failed to init VDA decoder: %d.\n", status); /* init H.264 decoder */ set_context(avctx); ret = ff_h264_decoder.init(avctx); restore_context(avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to open H.264 decoder.\n"); ctx->h264_initialized = 1; return 0; failed: vdadec_close(avctx); return -1;


static void inner_add_yblock_bw_16_obmc_32_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h, int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){ snow_inner_add_yblock_mmx_header snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0") snow_inner_add_yblock_mmx_accum("2", "16", "0") snow_inner_add_yblock_mmx_accum("1", "512", "0") snow_inner_add_yblock_mmx_accum("0", "528", "0") snow_inner_add_yblock_mmx_mix("0", "0") snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8") snow_inner_add_yblock_mmx_accum("2", "24", "8") snow_inner_add_yblock_mmx_accum("1", "520", "8") snow_inner_add_yblock_mmx_accum("0", "536", "8") snow_inner_add_yblock_mmx_mix("32", "8") snow_inner_add_yblock_mmx_end("32") }


static void blend_frames16_c(BLEND_FUNC_PARAMS) { int line, pixel; uint16_t *dstw = (uint16_t *)dst; uint16_t *src1w = (uint16_t *)src1; uint16_t *src2w = (uint16_t *)src2; width /= 2; src1_linesize /= 2; src2_linesize /= 2; dst_linesize /= 2; for (line = 0; line < height; line++) { for (pixel = 0; pixel < width; pixel++) dstw[pixel] = ((src1w[pixel] * factor1) + (src2w[pixel] * factor2) + half) >> shift; src1w += src1_linesize; src2w += src2_linesize; dstw += dst_linesize; } }


static int cinepak_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { CinepakEncContext *s = avctx->priv_data; AVFrame *frame = data; int ret; s->lambda = frame->quality ? frame->quality - 1 : 2 * FF_LAMBDA_SCALE; frame->key_frame = s->curframe == 0; frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; ret = rd_frame(s, frame, buf, buf_size); FFSWAP(AVFrame, s->last_frame, s->best_frame); if (++s->curframe >= s->keyint) s->curframe = 0; return ret; }


void qemu_bh_schedule_idle(QEMUBH *bh) { if (bh->scheduled) return; bh->idle = 1; /* Make sure that idle & any writes needed by the callback are done * before the locations are read in the aio_bh_poll. */ smp_wmb(); bh->scheduled = 1; }


static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; MOVStreamContext *sc = st->priv_data; int version = get_byte(pb); int lang; if (version > 1) return -1; /* unsupported */ get_be24(pb); /* flags */ if (version == 1) { get_be64(pb); get_be64(pb); } else { get_be32(pb); /* creation time */ get_be32(pb); /* modification time */ } sc->time_scale = get_be32(pb); st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ lang = get_be16(pb); /* language */ ff_mov_lang_to_iso639(lang, st->language); get_be16(pb); /* quality */ return 0; }


void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { va_list ap; va_start(ap, fmt); error_setv(errp, err_class, fmt, ap); va_end(ap); }


void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio) { assert(!aux_slave->mmio); aux_slave->mmio = mmio; }


static void s390_virtio_bridge_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); k->init = s390_virtio_bridge_init; dc->no_user = 1; }


static void start_auth_vencrypt_subauth(VncState *vs) { switch (vs->subauth) { case VNC_AUTH_VENCRYPT_TLSNONE: case VNC_AUTH_VENCRYPT_X509NONE: VNC_DEBUG("Accept TLS auth none\n"); vnc_write_u32(vs, 0); /* Accept auth completion */ start_client_init(vs); break; case VNC_AUTH_VENCRYPT_TLSVNC: case VNC_AUTH_VENCRYPT_X509VNC: VNC_DEBUG("Start TLS auth VNC\n"); start_auth_vnc(vs); break; #ifdef CONFIG_VNC_SASL case VNC_AUTH_VENCRYPT_TLSSASL: case VNC_AUTH_VENCRYPT_X509SASL: VNC_DEBUG("Start TLS auth SASL\n"); start_auth_sasl(vs); break; #endif /* CONFIG_VNC_SASL */ default: /* Should not be possible, but just in case */ VNC_DEBUG("Reject subauth %d server bug\n", vs->auth); vnc_write_u8(vs, 1); if (vs->minor >= 8) { static const char err[] = "Unsupported authentication type"; vnc_write_u32(vs, sizeof(err)); vnc_write(vs, err, sizeof(err)); } vnc_client_error(vs); } }


static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, int stride, int width, int height) { int i; int code; int c0, c1; int run, copy; int filled = 0; int rows_to_go; rows_to_go = height; height--; dst = dst + height * stride; while((size > 0) && (rows_to_go > 0)) { code = *src++; size--; run = copy = 0; if(code == 0xFC) /* end-of-picture code */ break; if(code >= 0xF8) { /* very long run */ c0 = *src++; c1 = *src++; size -= 2; run = ((code & 0x7) << 16) + (c0 << 8) + c1 + 2; } else if (code >= 0xF0) { /* long run */ c0 = *src++; size--; run = ((code & 0xF) << 8) + c0 + 2; } else if (code >= 0xE0) { /* short run */ run = (code & 0x1F) + 2; } else if (code >= 0xC0) { /* very long copy */ c0 = *src++; c1 = *src++; size -= 2; copy = ((code & 0x3F) << 16) + (c0 << 8) + c1 + 1; } else if (code >= 0x80) { /* long copy */ c0 = *src++; size--; copy = ((code & 0x7F) << 8) + c0 + 1; } else { /* short copy */ copy = code + 1; } /* perform actual run or copy */ if(run) { int p; p = *src++; size--; for(i = 0; i < run; i++) { dst[filled++] = p; if (filled >= width) { filled = 0; dst -= stride; rows_to_go--; if(rows_to_go <= 0) break; } } } else { size -= copy; for(i = 0; i < copy; i++) { dst[filled++] = *src++; if (filled >= width) { filled = 0; dst -= stride; rows_to_go--; if(rows_to_go <= 0) break; } } } } }


static void parse_drive(DeviceState *dev, const char *str, void **ptr, const char *propname, Error **errp) { BlockBackend *blk; blk = blk_by_name(str); if (!blk) { error_setg(errp, "Property '%s.%s' can't find value '%s'", object_get_typename(OBJECT(dev)), propname, str); return; } if (blk_attach_dev(blk, dev) < 0) { DriveInfo *dinfo = blk_legacy_dinfo(blk); if (dinfo && dinfo->type != IF_NONE) { error_setg(errp, "Drive '%s' is already in use because " "it has been automatically connected to another " "device (did you need 'if=none' in the drive options?)", str); } else { error_setg(errp, "Drive '%s' is already in use by another device", str); } return; } *ptr = blk; }


int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; VP56Context *s = avctx->priv_data; AVFrame *const p = s->frames[VP56_FRAME_CURRENT]; int remaining_buf_size = avpkt->size; int av_uninit(alpha_offset); int i, res; int ret; if (s->has_alpha) { if (remaining_buf_size < 3) return AVERROR_INVALIDDATA; alpha_offset = bytestream_get_be24(&buf); remaining_buf_size -= 3; if (remaining_buf_size < alpha_offset) return AVERROR_INVALIDDATA; } res = s->parse_header(s, buf, remaining_buf_size); if (res < 0) return res; if (res == VP56_SIZE_CHANGE) { for (i = 0; i < 4; i++) { av_frame_unref(s->frames[i]); if (s->alpha_context) av_frame_unref(s->alpha_context->frames[i]); } } ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF); if (ret < 0) return ret; if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) { av_frame_unref(s->alpha_context->frames[VP56_FRAME_CURRENT]); if ((ret = av_frame_ref(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) { av_frame_unref(p); return ret; } } if (res == VP56_SIZE_CHANGE) { if (vp56_size_changed(s)) { av_frame_unref(p); return AVERROR_INVALIDDATA; } } if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) { int bak_w = avctx->width; int bak_h = avctx->height; int bak_cw = avctx->coded_width; int bak_ch = avctx->coded_height; buf += alpha_offset; remaining_buf_size -= alpha_offset; res = s->alpha_context->parse_header(s->alpha_context, buf, remaining_buf_size); if (res != 0) { if(res==VP56_SIZE_CHANGE) { av_log(avctx, AV_LOG_ERROR, "Alpha reconfiguration\n"); avctx->width = bak_w; avctx->height = bak_h; avctx->coded_width = bak_cw; avctx->coded_height = bak_ch; } av_frame_unref(p); return AVERROR_INVALIDDATA; } } avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) + 1); if ((res = av_frame_ref(data, p)) < 0) return res; *got_frame = 1; return avpkt->size; }


static int analyze(const uint8_t *buf, int size, int packet_size, int *index) { int stat[TS_MAX_PACKET_SIZE]; int i; int x = 0; int best_score = 0; memset(stat, 0, packet_size * sizeof(int)); for (x = i = 0; i < size - 3; i++) { if (buf[i] == 0x47 && !(buf[i + 1] & 0x80) && (buf[i + 3] & 0x30)) { stat[x]++; if (stat[x] > best_score) { best_score = stat[x]; if (index) *index = x; } } x++; if (x == packet_size) x = 0; } return best_score; }


static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { BDRVQcowState *s = bs->opaque; uint64_t cluster_offset; int ret; *pnum = nb_sectors; /* FIXME We can get errors here, but the bdrv_co_is_allocated interface * can't pass them on today */ qemu_co_mutex_lock(&s->lock); ret = qcow2_get_cluster_offset(bs, sector_num << 9, pnum, &cluster_offset); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { *pnum = 0; } return (cluster_offset != 0) || (ret == QCOW2_CLUSTER_ZERO); }


static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, uint32_t val) { UNINState *s = opaque; s->config_reg = val; }


static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) { AVCodecContext *avctx = s->avctx; Mpeg1Context *s1 = (Mpeg1Context *) s; /* start frame decoding */ if (s->first_field || s->picture_structure == PICT_FRAME) { AVFrameSideData *pan_scan; if (ff_MPV_frame_start(s, avctx) < 0) return -1; ff_mpeg_er_frame_start(s); /* first check if we must repeat the frame */ s->current_picture_ptr->f.repeat_pict = 0; if (s->repeat_first_field) { if (s->progressive_sequence) { if (s->top_field_first) s->current_picture_ptr->f.repeat_pict = 4; else s->current_picture_ptr->f.repeat_pict = 2; } else if (s->progressive_frame) { s->current_picture_ptr->f.repeat_pict = 1; } } pan_scan = av_frame_new_side_data(&s->current_picture_ptr->f, AV_FRAME_DATA_PANSCAN, sizeof(s1->pan_scan)); if (!pan_scan) return AVERROR(ENOMEM); memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan)); if (s1->a53_caption) { AVFrameSideData *sd = av_frame_new_side_data( &s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC, s1->a53_caption_size); if (sd) memcpy(sd->data, s1->a53_caption, s1->a53_caption_size); av_freep(&s1->a53_caption); } if (s1->has_stereo3d) { AVStereo3D *stereo = av_stereo3d_create_side_data(&s->current_picture_ptr->f); if (!stereo) return AVERROR(ENOMEM); *stereo = s1->stereo3d; s1->has_stereo3d = 0; } if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME)) ff_thread_finish_setup(avctx); } else { // second field int i; if (!s->current_picture_ptr) { av_log(s->avctx, AV_LOG_ERROR, "first field missing\n"); return -1; } if (s->avctx->hwaccel && (s->avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) { if (s->avctx->hwaccel->end_frame(s->avctx) < 0) av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode first field\n"); } for (i = 0; i < 4; i++) { s->current_picture.f.data[i] = s->current_picture_ptr->f.data[i]; if (s->picture_structure == PICT_BOTTOM_FIELD) s->current_picture.f.data[i] += s->current_picture_ptr->f.linesize[i]; } } if (avctx->hwaccel) { if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) return -1; } #if FF_API_XVMC FF_DISABLE_DEPRECATION_WARNINGS // MPV_frame_start will call this function too, // but we need to call it on every field if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) if (ff_xvmc_field_start(s, avctx) < 0) return -1; FF_ENABLE_DEPRECATION_WARNINGS #endif /* FF_API_XVMC */ return 0; }


static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb, RMDemuxContext *rm, RMStream *vst, AVPacket *pkt, int len) { int hdr, seq, pic_num, len2, pos; int type; hdr = get_byte(pb); len--; type = hdr >> 6; if(type != 3){ // not frame as a part of packet seq = get_byte(pb); len--; } if(type != 1){ // not whole frame len2 = get_num(pb, &len); pos = get_num(pb, &len); pic_num = get_byte(pb); len--; } if(len<0) return -1; rm->remaining_len = len; if(type&1){ // frame, not slice if(type == 3) // frame as a part of packet len= len2; if(rm->remaining_len < len) return -1; rm->remaining_len -= len; if(av_new_packet(pkt, len + 9) < 0) return AVERROR(EIO); pkt->data[0] = 0; AV_WL32(pkt->data + 1, 1); AV_WL32(pkt->data + 5, 0); get_buffer(pb, pkt->data + 9, len); return 0; } //now we have to deal with single slice if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){ vst->slices = ((hdr & 0x3F) << 1) + 1; vst->videobufsize = len2 + 8*vst->slices + 1; av_free_packet(&vst->pkt); //FIXME this should be output. if(av_new_packet(&vst->pkt, vst->videobufsize) < 0) return AVERROR(ENOMEM); vst->videobufpos = 8*vst->slices + 1; vst->cur_slice = 0; vst->curpic_num = pic_num; vst->pktpos = url_ftell(pb); } if(type == 2) len = FFMIN(len, pos); if(++vst->cur_slice > vst->slices) return 1; AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1); AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1); if(vst->videobufpos + len > vst->videobufsize) return 1; if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len) return AVERROR(EIO); vst->videobufpos += len; rm->remaining_len-= len; if(type == 2 || (vst->videobufpos) == vst->videobufsize){ vst->pkt.data[0] = vst->cur_slice-1; *pkt= vst->pkt; vst->pkt.data= vst->pkt.size= 0; if(vst->slices != vst->cur_slice) //FIXME find out how to set slices correct from the begin memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices, vst->videobufpos - 1 - 8*vst->slices); pkt->size += 8*(vst->cur_slice - vst->slices); pkt->pts = AV_NOPTS_VALUE; pkt->pos = vst->pktpos; return 0; } return 1; }


static ExitStatus gen_call_pal(DisasContext *ctx, int palcode) { /* We're emulating OSF/1 PALcode. Many of these are trivial access to internal cpu registers. */ /* Unprivileged PAL call */ if (palcode >= 0x80 && palcode < 0xC0) { switch (palcode) { case 0x86: /* IMB */ /* No-op inside QEMU. */ break; case 0x9E: /* RDUNIQUE */ tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_unique); break; case 0x9F: /* WRUNIQUE */ tcg_gen_mov_i64(cpu_unique, cpu_ir[IR_A0]); break; default: palcode &= 0xbf; goto do_call_pal; } return NO_EXIT; } #ifndef CONFIG_USER_ONLY /* Privileged PAL code */ if (palcode < 0x40 && (ctx->tb->flags & TB_FLAGS_USER_MODE) == 0) { switch (palcode) { case 0x01: /* CFLUSH */ /* No-op inside QEMU. */ break; case 0x02: /* DRAINA */ /* No-op inside QEMU. */ break; case 0x2D: /* WRVPTPTR */ tcg_gen_st_i64(cpu_ir[IR_A0], cpu_env, offsetof(CPUAlphaState, vptptr)); break; case 0x31: /* WRVAL */ tcg_gen_mov_i64(cpu_sysval, cpu_ir[IR_A0]); break; case 0x32: /* RDVAL */ tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_sysval); break; case 0x35: { /* SWPIPL */ TCGv tmp; /* Note that we already know we're in kernel mode, so we know that PS only contains the 3 IPL bits. */ tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUAlphaState, ps)); /* But make sure and store only the 3 IPL bits from the user. */ tmp = tcg_temp_new(); tcg_gen_andi_i64(tmp, cpu_ir[IR_A0], PS_INT_MASK); tcg_gen_st8_i64(tmp, cpu_env, offsetof(CPUAlphaState, ps)); tcg_temp_free(tmp); break; } case 0x36: /* RDPS */ tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUAlphaState, ps)); break; case 0x38: /* WRUSP */ tcg_gen_mov_i64(cpu_usp, cpu_ir[IR_A0]); break; case 0x3A: /* RDUSP */ tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_usp); break; case 0x3C: /* WHAMI */ tcg_gen_ld32s_i64(cpu_ir[IR_V0], cpu_env, -offsetof(AlphaCPU, env) + offsetof(CPUState, cpu_index)); break; default: palcode &= 0x3f; goto do_call_pal; } return NO_EXIT; } #endif return gen_invalid(ctx); do_call_pal: #ifdef CONFIG_USER_ONLY return gen_excp(ctx, EXCP_CALL_PAL, palcode); #else { TCGv pc = tcg_const_i64(ctx->pc); TCGv entry = tcg_const_i64(palcode & 0x80 ? 0x2000 + (palcode - 0x80) * 64 : 0x1000 + palcode * 64); gen_helper_call_pal(cpu_env, pc, entry); tcg_temp_free(entry); tcg_temp_free(pc); /* Since the destination is running in PALmode, we don't really need the page permissions check. We'll see the existence of the page when we create the TB, and we'll flush all TBs if we change the PAL base register. */ if (!ctx->singlestep_enabled && !(ctx->tb->cflags & CF_LAST_IO)) { tcg_gen_goto_tb(0); tcg_gen_exit_tb((uintptr_t)ctx->tb); return EXIT_GOTO_TB; } return EXIT_PC_UPDATED; } #endif }


void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s) { if (!s) { return; } virtio_blk_data_plane_stop(s); blk_op_unblock_all(s->conf->conf.blk, s->blocker); error_free(s->blocker); object_unref(OBJECT(s->iothread)); qemu_bh_delete(s->bh); g_free(s); }


static void uhci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class); UHCIInfo *info = data; k->init = info->initfn ? info->initfn : usb_uhci_common_initfn; k->exit = info->unplug ? usb_uhci_exit : NULL; k->vendor_id = info->vendor_id; k->device_id = info->device_id; k->revision = info->revision; k->class_id = PCI_CLASS_SERIAL_USB; dc->vmsd = &vmstate_uhci; dc->props = uhci_properties; u->info = *info; }


static int openfile(char *name, int flags, bool writethrough, bool force_share, QDict *opts) { Error *local_err = NULL; BlockDriverState *bs; if (qemuio_blk) { error_report("file open already, try 'help close'"); QDECREF(opts); return 1; } if (force_share) { if (!opts) { opts = qdict_new(); } if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE) && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) { error_report("-U conflicts with image options"); QDECREF(opts); return 1; } qdict_put_bool(opts, BDRV_OPT_FORCE_SHARE, true); } qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err); if (!qemuio_blk) { error_reportf_err(local_err, "can't open%s%s: ", name ? " device " : "", name ?: ""); return 1; } bs = blk_bs(qemuio_blk); if (bdrv_is_encrypted(bs) && bdrv_key_required(bs)) { char password[256]; printf("Disk image '%s' is encrypted.\n", name); if (qemu_read_password(password, sizeof(password)) < 0) { error_report("No password given"); goto error; } if (bdrv_set_key(bs, password) < 0) { error_report("invalid password"); goto error; } } blk_set_enable_write_cache(qemuio_blk, !writethrough); return 0; error: blk_unref(qemuio_blk); qemuio_blk = NULL; return 1; }


static void powerpc_get_compat(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { char *value = (char *)""; Property *prop = opaque; uint32_t *max_compat = qdev_get_prop_ptr(DEVICE(obj), prop); switch (*max_compat) { case CPU_POWERPC_LOGICAL_2_05: value = (char *)"power6"; break; case CPU_POWERPC_LOGICAL_2_06: value = (char *)"power7"; break; case CPU_POWERPC_LOGICAL_2_07: value = (char *)"power8"; break; case 0: break; default: error_report("Internal error: compat is set to %x", *max_compat); abort(); break; } visit_type_str(v, name, &value, errp); }


int cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata) { CacheItem *it = NULL; g_assert(cache); g_assert(cache->page_cache); /* actual update of entry */ it = cache_get_by_addr(cache, addr); /* allocate page */ if (!it->it_data) { it->it_data = g_try_malloc(cache->page_size); if (!it->it_data) { DPRINTF("Error allocating page\n"); return -1; } cache->num_items++; } memcpy(it->it_data, pdata, cache->page_size); it->it_age = ++cache->max_item_age; it->it_addr = addr; return 0; }


int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11 const int mb_array_size= s->mb_stride*s->mb_height; const int b8_array_size= s->b8_stride*s->mb_height*2; const int b4_array_size= s->b4_stride*s->mb_height*4; int i; int r= -1; if(shared){ assert(pic->data[0]); assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); pic->type= FF_BUFFER_TYPE_SHARED; }else{ assert(!pic->data[0]); if (alloc_frame_buffer(s, pic) < 0) return -1; s->linesize = pic->linesize[0]; s->uvlinesize= pic->linesize[1]; } if(pic->qscale_table==NULL){ if (s->encoding) { FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail) } FF_ALLOCZ_OR_GOTO(s->avctx, pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2, fail) //the +2 is for the slice end check FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table , mb_array_size * sizeof(uint8_t) , fail) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail) pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1; if(s->out_format == FMT_H264){ for(i=0; i<2; i++){ FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail) pic->motion_val[i]= pic->motion_val_base[i]+4; FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) } pic->motion_subsample_log2= 2; }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ for(i=0; i<2; i++){ FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail) pic->motion_val[i]= pic->motion_val_base[i]+4; FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) } pic->motion_subsample_log2= 3; } if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail) } pic->qstride= s->mb_stride; FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail) } /* It might be nicer if the application would keep track of these * but it would require an API change. */ memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1); s->prev_pict_types[0]= s->dropable ? AV_PICTURE_TYPE_B : s->pict_type; if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == AV_PICTURE_TYPE_B) pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway. pic->owner2 = NULL; return 0; fail: //for the FF_ALLOCZ_OR_GOTO macro if(r>=0) free_frame_buffer(s, pic); return -1; }


static int raw_open_common(BlockDriverState *bs, QDict *options, int bdrv_flags, int open_flags, Error **errp) { BDRVRawState *s = bs->opaque; QemuOpts *opts; Error *local_err = NULL; const char *filename = NULL; BlockdevAioOptions aio, aio_default; int fd, ret; struct stat st; OnOffAuto locking; opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } filename = qemu_opt_get(opts, "filename"); ret = raw_normalize_devicepath(&filename); if (ret != 0) { error_setg_errno(errp, -ret, "Could not normalize device path"); goto fail; } aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE : BLOCKDEV_AIO_OPTIONS_THREADS; aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), BLOCKDEV_AIO_OPTIONS__MAX, aio_default, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE); locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"), ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } switch (locking) { case ON_OFF_AUTO_ON: s->use_lock = true; #ifndef F_OFD_SETLK fprintf(stderr, "File lock requested but OFD locking syscall is unavailable, " "falling back to POSIX file locks.\n" "Due to the implementation, locks can be lost unexpectedly.\n"); #endif break; case ON_OFF_AUTO_OFF: s->use_lock = false; break; case ON_OFF_AUTO_AUTO: #ifdef F_OFD_SETLK s->use_lock = true; #else s->use_lock = false; #endif break; default: abort(); } s->open_flags = open_flags; raw_parse_flags(bdrv_flags, &s->open_flags); s->fd = -1; fd = qemu_open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not open '%s'", filename); if (ret == -EROFS) { ret = -EACCES; } goto fail; } s->fd = fd; s->lock_fd = -1; if (s->use_lock) { fd = qemu_open(filename, s->open_flags); if (fd < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not open '%s' for locking", filename); qemu_close(s->fd); goto fail; } s->lock_fd = fd; } s->perm = 0; s->shared_perm = BLK_PERM_ALL; #ifdef CONFIG_LINUX_AIO /* Currently Linux does AIO only for files opened with O_DIRECT */ if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) { error_setg(errp, "aio=native was specified, but it requires " "cache.direct=on, which was not specified."); ret = -EINVAL; goto fail; } #else if (s->use_linux_aio) { error_setg(errp, "aio=native was specified, but is not supported " "in this build."); ret = -EINVAL; goto fail; } #endif /* !defined(CONFIG_LINUX_AIO) */ s->has_discard = true; s->has_write_zeroes = true; bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP; if ((bs->open_flags & BDRV_O_NOCACHE) != 0) { s->needs_alignment = true; } if (fstat(s->fd, &st) < 0) { ret = -errno; error_setg_errno(errp, errno, "Could not stat file"); goto fail; } if (S_ISREG(st.st_mode)) { s->discard_zeroes = true; s->has_fallocate = true; } if (S_ISBLK(st.st_mode)) { #ifdef BLKDISCARDZEROES unsigned int arg; if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) { s->discard_zeroes = true; } #endif #ifdef __linux__ /* On Linux 3.10, BLKDISCARD leaves stale data in the page cache. Do * not rely on the contents of discarded blocks unless using O_DIRECT. * Same for BLKZEROOUT. */ if (!(bs->open_flags & BDRV_O_NOCACHE)) { s->discard_zeroes = false; s->has_write_zeroes = false; } #endif } #ifdef __FreeBSD__ if (S_ISCHR(st.st_mode)) { /* * The file is a char device (disk), which on FreeBSD isn't behind * a pager, so force all requests to be aligned. This is needed * so QEMU makes sure all IO operations on the device are aligned * to sector size, or else FreeBSD will reject them with EINVAL. */ s->needs_alignment = true; } #endif #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) { s->is_xfs = true; } #endif ret = 0; fail: if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) { unlink(filename); } qemu_opts_del(opts); return ret; }


int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y) { int mx, my, range, dmin; int xmin, ymin, xmax, ymax; int rel_xmin, rel_ymin, rel_xmax, rel_ymax; int pred_x=0, pred_y=0; int P[10][2]; const int shift= 1+s->quarter_sample; uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; const int mv_stride= s->mb_width + 2; const int xy= mb_x + 1 + (mb_y + 1)*mv_stride; assert(s->quarter_sample==0 || s->quarter_sample==1); s->me.pre_penalty_factor = get_penalty_factor(s, s->avctx->me_pre_cmp); get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code); rel_xmin= xmin - mb_x*16; rel_xmax= xmax - mb_x*16; rel_ymin= ymin - mb_y*16; rel_ymax= ymax - mb_y*16; s->me.skip=0; P_LEFT[0] = s->p_mv_table[xy + 1][0]; P_LEFT[1] = s->p_mv_table[xy + 1][1]; if(P_LEFT[0] < (rel_xmin<<shift)) P_LEFT[0] = (rel_xmin<<shift); /* special case for first line */ if (mb_y == s->mb_height-1) { pred_x= P_LEFT[0]; pred_y= P_LEFT[1]; P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]= P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME } else { P_TOP[0] = s->p_mv_table[xy + mv_stride ][0]; P_TOP[1] = s->p_mv_table[xy + mv_stride ][1]; P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0]; P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1]; if(P_TOP[1] < (rel_ymin<<shift)) P_TOP[1] = (rel_ymin<<shift); if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift); if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift); P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); pred_x = P_MEDIAN[0]; pred_y = P_MEDIAN[1]; } dmin = s->me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); s->p_mv_table[xy][0] = mx<<shift; s->p_mv_table[xy][1] = my<<shift; return dmin; }


int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format); const AVComponentDescriptor *c; unsigned i, nb_planes = 0; int pixelstep[MAX_PLANES] = { 0 }; if (!desc->name) return AVERROR(EINVAL); if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA)) return AVERROR(ENOSYS); for (i = 0; i < desc->nb_components; i++) { c = &desc->comp[i]; /* for now, only 8-bits formats */ if (c->depth_minus1 != 8 - 1) return AVERROR(ENOSYS); if (c->plane >= MAX_PLANES) return AVERROR(ENOSYS); /* strange interleaving */ if (pixelstep[c->plane] != 0 && pixelstep[c->plane] != c->step_minus1 + 1) return AVERROR(ENOSYS); pixelstep[c->plane] = c->step_minus1 + 1; if (pixelstep[c->plane] >= 8) return AVERROR(ENOSYS); nb_planes = FFMAX(nb_planes, c->plane + 1); } if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3) return AVERROR(ENOSYS); /* exclude NV12 and NV21 */ memset(draw, 0, sizeof(*draw)); draw->desc = desc; draw->format = format; draw->nb_planes = nb_planes; memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep)); draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w; draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h; for (i = 0; i < ((desc->nb_components - 1) | 1); i++) draw->comp_mask[desc->comp[i].plane] |= 1 << (desc->comp[i].offset_plus1 - 1); return 0; }


static int htab_save_complete(QEMUFile *f, void *opaque) { sPAPRMachineState *spapr = opaque; int fd; /* Iteration header */ qemu_put_be32(f, 0); if (!spapr->htab) { int rc; assert(kvm_enabled()); fd = get_htab_fd(spapr); if (fd < 0) { return fd; } rc = kvmppc_save_htab(f, fd, MAX_KVM_BUF_SIZE, -1); if (rc < 0) { return rc; } close_htab_fd(spapr); } else { if (spapr->htab_first_pass) { htab_save_first_pass(f, spapr, -1); } htab_save_later_pass(f, spapr, -1); } /* End marker */ qemu_put_be32(f, 0); qemu_put_be16(f, 0); qemu_put_be16(f, 0); return 0; }


struct pxa2xx_gpio_info_s *pxa2xx_gpio_init(target_phys_addr_t base, CPUState *env, qemu_irq *pic, int lines) { int iomemtype; struct pxa2xx_gpio_info_s *s; s = (struct pxa2xx_gpio_info_s *) qemu_mallocz(sizeof(struct pxa2xx_gpio_info_s)); memset(s, 0, sizeof(struct pxa2xx_gpio_info_s)); s->base = base; s->pic = pic; s->lines = lines; s->cpu_env = env; iomemtype = cpu_register_io_memory(0, pxa2xx_gpio_readfn, pxa2xx_gpio_writefn, s); cpu_register_physical_memory(base, 0x00000fff, iomemtype); register_savevm("pxa2xx_gpio", 0, 0, pxa2xx_gpio_save, pxa2xx_gpio_load, s); return s; }


AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) { AVFilterFormats *ret; unsigned i, j, k = 0; ret = av_mallocz(sizeof(AVFilterFormats)); /* merge list of formats */ ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count, b->format_count)); for(i = 0; i < a->format_count; i ++) for(j = 0; j < b->format_count; j ++) if(a->formats[i] == b->formats[j]) ret->formats[k++] = a->formats[i]; ret->format_count = k; /* check that there was at least one common format */ if(!ret->format_count) { av_free(ret->formats); av_free(ret); return NULL; } ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount)); merge_ref(ret, a); merge_ref(ret, b); return ret; }


void console_select(unsigned int index) { TextConsole *s; if (index >= MAX_CONSOLES) return; if (active_console) { active_console->g_width = ds_get_width(active_console->ds); active_console->g_height = ds_get_height(active_console->ds); } s = consoles[index]; if (s) { DisplayState *ds = s->ds; if (active_console->cursor_timer) { qemu_del_timer(active_console->cursor_timer); } active_console = s; if (ds_get_bits_per_pixel(s->ds)) { ds->surface = qemu_resize_displaysurface(ds, s->g_width, s->g_height); } else { s->ds->surface->width = s->width; s->ds->surface->height = s->height; } if (s->cursor_timer) { qemu_mod_timer(s->cursor_timer, qemu_get_clock_ms(rt_clock) + CONSOLE_CURSOR_PERIOD / 2); } dpy_resize(s->ds); vga_hw_invalidate(); } }


static av_always_inline int simple_limit(uint8_t *p, ptrdiff_t stride, int flim) { LOAD_PIXELS return 2*FFABS(p0-q0) + (FFABS(p1-q1) >> 1) <= flim; }


dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; AVPacketList *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); } if (ctx->graph) { IEnumFilters *fenum; int r; r = IGraphBuilder_EnumFilters(ctx->graph, &fenum); if (r == S_OK) { IBaseFilter *f; IEnumFilters_Reset(fenum); while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK) { if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK) IEnumFilters_Reset(fenum); /* When a filter is removed, * the list must be reset. */ IBaseFilter_Release(f); } IEnumFilters_Release(fenum); } IGraphBuilder_Release(ctx->graph); } if (ctx->capture_pin[VideoDevice]) libAVPin_Release(ctx->capture_pin[VideoDevice]); if (ctx->capture_pin[AudioDevice]) libAVPin_Release(ctx->capture_pin[AudioDevice]); if (ctx->capture_filter[VideoDevice]) libAVFilter_Release(ctx->capture_filter[VideoDevice]); if (ctx->capture_filter[AudioDevice]) libAVFilter_Release(ctx->capture_filter[AudioDevice]); if (ctx->device_pin[VideoDevice]) IPin_Release(ctx->device_pin[VideoDevice]); if (ctx->device_pin[AudioDevice]) IPin_Release(ctx->device_pin[AudioDevice]); if (ctx->device_filter[VideoDevice]) IBaseFilter_Release(ctx->device_filter[VideoDevice]); if (ctx->device_filter[AudioDevice]) IBaseFilter_Release(ctx->device_filter[AudioDevice]); if (ctx->device_name[0]) av_free(ctx->device_name[0]); if (ctx->device_name[1]) av_free(ctx->device_name[1]); if(ctx->mutex) CloseHandle(ctx->mutex); if(ctx->event) CloseHandle(ctx->event); pktl = ctx->pktl; while (pktl) { AVPacketList *next = pktl->next; av_destruct_packet(&pktl->pkt); av_free(pktl); pktl = next; } return 0; }


static int ftp_conn_control_block_control(void *data) { FTPContext *s = data; return s->conn_control_block_flag; }


static int probe_file(const char *filename) { AVFormatContext *fmt_ctx; int ret, i; if ((ret = open_input_file(&fmt_ctx, filename))) return ret; if (do_show_packets) show_packets(fmt_ctx); if (do_show_streams) for (i = 0; i < fmt_ctx->nb_streams; i++) show_stream(fmt_ctx, i); if (do_show_format) show_format(fmt_ctx); close_input_file(&fmt_ctx); return 0; }


av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data; if (!s->picture_ptr) { s->picture = av_frame_alloc(); if (!s->picture) return AVERROR(ENOMEM); s->picture_ptr = s->picture; } s->avctx = avctx; ff_blockdsp_init(&s->bdsp, avctx); ff_hpeldsp_init(&s->hdsp, avctx->flags); ff_idctdsp_init(&s->idsp, avctx); ff_init_scantable(s->idsp.idct_permutation, &s->scantable, ff_zigzag_direct); s->buffer_size = 0; s->buffer = NULL; s->start_code = -1; s->first_picture = 1; s->org_height = avctx->coded_height; avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; avctx->colorspace = AVCOL_SPC_BT470BG; build_basic_mjpeg_vlc(s); if (s->extern_huff) { int ret; av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8); if ((ret = ff_mjpeg_decode_dht(s))) { av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table\n"); return ret; } } if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */ s->interlace_polarity = 1; /* bottom field first */ av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); } if (avctx->codec->id == AV_CODEC_ID_AMV) s->flipped = 1; return 0; }