static int hls_slice_header(HEVCContext *s) { GetBitContext *gb = &s->HEVClc->gb; SliceHeader *sh = &s->sh; int i, j, ret; // Coded parameters sh->first_slice_in_pic_flag = get_bits1(gb); if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) { s->seq_decode = (s->seq_decode + 1) & 0xff; s->max_ra = INT_MAX; if (IS_IDR(s)) ff_hevc_clear_refs(s); } sh->no_output_of_prior_pics_flag = 0; if (IS_IRAP(s)) sh->no_output_of_prior_pics_flag = get_bits1(gb); sh->pps_id = get_ue_golomb_long(gb); if (sh->pps_id >= MAX_PPS_COUNT || !s->pps_list[sh->pps_id]) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); return AVERROR_INVALIDDATA; } if (!sh->first_slice_in_pic_flag && s->pps != (HEVCPPS*)s->pps_list[sh->pps_id]->data) { av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); return AVERROR_INVALIDDATA; } s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]->data; if (s->nal_unit_type == NAL_CRA_NUT && s->last_eos == 1) sh->no_output_of_prior_pics_flag = 1; if (s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]->data) { const HEVCSPS* last_sps = s->sps; s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]->data; if (last_sps && IS_IRAP(s) && s->nal_unit_type != NAL_CRA_NUT) { if (s->sps->width != last_sps->width || s->sps->height != last_sps->height || s->sps->temporal_layer[s->sps->max_sub_layers - 1].max_dec_pic_buffering != last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering) sh->no_output_of_prior_pics_flag = 0; } ff_hevc_clear_refs(s); ret = set_sps(s, s->sps, AV_PIX_FMT_NONE); if (ret < 0) return ret; s->seq_decode = (s->seq_decode + 1) & 0xff; s->max_ra = INT_MAX; } sh->dependent_slice_segment_flag = 0; if (!sh->first_slice_in_pic_flag) { int slice_address_length; if (s->pps->dependent_slice_segments_enabled_flag) sh->dependent_slice_segment_flag = get_bits1(gb); slice_address_length = av_ceil_log2(s->sps->ctb_width * s->sps->ctb_height); sh->slice_segment_addr = get_bits(gb, slice_address_length); if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) { av_log(s->avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", sh->slice_segment_addr); return AVERROR_INVALIDDATA; } if (!sh->dependent_slice_segment_flag) { sh->slice_addr = sh->slice_segment_addr; s->slice_idx++; } } else { sh->slice_segment_addr = sh->slice_addr = 0; s->slice_idx = 0; s->slice_initialized = 0; } if (!sh->dependent_slice_segment_flag) { s->slice_initialized = 0; for (i = 0; i < s->pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] sh->slice_type = get_ue_golomb_long(gb); if (!(sh->slice_type == I_SLICE || sh->slice_type == P_SLICE || sh->slice_type == B_SLICE)) { av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", sh->slice_type); return AVERROR_INVALIDDATA; } if (IS_IRAP(s) && sh->slice_type != I_SLICE) { av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); return AVERROR_INVALIDDATA; } // when flag is not present, picture is inferred to be output sh->pic_output_flag = 1; if (s->pps->output_flag_present_flag) sh->pic_output_flag = get_bits1(gb); if (s->sps->separate_colour_plane_flag) sh->colour_plane_id = get_bits(gb, 2); if (!IS_IDR(s)) { int poc; sh->pic_order_cnt_lsb = get_bits(gb, s->sps->log2_max_poc_lsb); poc = ff_hevc_compute_poc(s, sh->pic_order_cnt_lsb); if (!sh->first_slice_in_pic_flag && poc != s->poc) { av_log(s->avctx, AV_LOG_WARNING, "Ignoring POC change between slices: %d -> %d\n", s->poc, poc); if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; poc = s->poc; } s->poc = poc; sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); if (!sh->short_term_ref_pic_set_sps_flag) { int pos = get_bits_left(gb); ret = ff_hevc_decode_short_term_rps(s, &sh->slice_rps, s->sps, 1); if (ret < 0) return ret; sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); sh->short_term_rps = &sh->slice_rps; } else { int numbits, rps_idx; if (!s->sps->nb_st_rps) { av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); return AVERROR_INVALIDDATA; } numbits = av_ceil_log2(s->sps->nb_st_rps); rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; sh->short_term_rps = &s->sps->st_rps[rps_idx]; } ret = decode_lt_rps(s, &sh->long_term_rps, gb); if (ret < 0) { av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } if (s->sps->sps_temporal_mvp_enabled_flag) sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); else sh->slice_temporal_mvp_enabled_flag = 0; } else { s->sh.short_term_rps = NULL; s->poc = 0; } /* 8.3.1 */ if (s->temporal_id == 0 && s->nal_unit_type != NAL_TRAIL_N && s->nal_unit_type != NAL_TSA_N && s->nal_unit_type != NAL_STSA_N && s->nal_unit_type != NAL_RADL_N && s->nal_unit_type != NAL_RADL_R && s->nal_unit_type != NAL_RASL_N && s->nal_unit_type != NAL_RASL_R) s->pocTid0 = s->poc; if (s->sps->sao_enabled) { sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); if (s->sps->chroma_format_idc) { sh->slice_sample_adaptive_offset_flag[1] = sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); } } else { sh->slice_sample_adaptive_offset_flag[0] = 0; sh->slice_sample_adaptive_offset_flag[1] = 0; sh->slice_sample_adaptive_offset_flag[2] = 0; } sh->nb_refs[L0] = sh->nb_refs[L1] = 0; if (sh->slice_type == P_SLICE || sh->slice_type == B_SLICE) { int nb_refs; sh->nb_refs[L0] = s->pps->num_ref_idx_l0_default_active; if (sh->slice_type == B_SLICE) sh->nb_refs[L1] = s->pps->num_ref_idx_l1_default_active; if (get_bits1(gb)) { // num_ref_idx_active_override_flag sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1; if (sh->slice_type == B_SLICE) sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1; } if (sh->nb_refs[L0] > MAX_REFS || sh->nb_refs[L1] > MAX_REFS) { av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", sh->nb_refs[L0], sh->nb_refs[L1]); return AVERROR_INVALIDDATA; } sh->rpl_modification_flag[0] = 0; sh->rpl_modification_flag[1] = 0; nb_refs = ff_hevc_frame_nb_refs(s); if (!nb_refs) { av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); return AVERROR_INVALIDDATA; } if (s->pps->lists_modification_present_flag && nb_refs > 1) { sh->rpl_modification_flag[0] = get_bits1(gb); if (sh->rpl_modification_flag[0]) { for (i = 0; i < sh->nb_refs[L0]; i++) sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); } if (sh->slice_type == B_SLICE) { sh->rpl_modification_flag[1] = get_bits1(gb); if (sh->rpl_modification_flag[1] == 1) for (i = 0; i < sh->nb_refs[L1]; i++) sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); } } if (sh->slice_type == B_SLICE) sh->mvd_l1_zero_flag = get_bits1(gb); if (s->pps->cabac_init_present_flag) sh->cabac_init_flag = get_bits1(gb); else sh->cabac_init_flag = 0; sh->collocated_ref_idx = 0; if (sh->slice_temporal_mvp_enabled_flag) { sh->collocated_list = L0; if (sh->slice_type == B_SLICE) sh->collocated_list = !get_bits1(gb); if (sh->nb_refs[sh->collocated_list] > 1) { sh->collocated_ref_idx = get_ue_golomb_long(gb); if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { av_log(s->avctx, AV_LOG_ERROR, "Invalid collocated_ref_idx: %d.\n", sh->collocated_ref_idx); return AVERROR_INVALIDDATA; } } } if ((s->pps->weighted_pred_flag && sh->slice_type == P_SLICE) || (s->pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) { pred_weight_table(s, gb); } sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { av_log(s->avctx, AV_LOG_ERROR, "Invalid number of merging MVP candidates: %d.\n", sh->max_num_merge_cand); return AVERROR_INVALIDDATA; } } sh->slice_qp_delta = get_se_golomb(gb); if (s->pps->pic_slice_level_chroma_qp_offsets_present_flag) { sh->slice_cb_qp_offset = get_se_golomb(gb); sh->slice_cr_qp_offset = get_se_golomb(gb); } else { sh->slice_cb_qp_offset = 0; sh->slice_cr_qp_offset = 0; } if (s->pps->chroma_qp_offset_list_enabled_flag) sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); else sh->cu_chroma_qp_offset_enabled_flag = 0; if (s->pps->deblocking_filter_control_present_flag) { int deblocking_filter_override_flag = 0; if (s->pps->deblocking_filter_override_enabled_flag) deblocking_filter_override_flag = get_bits1(gb); if (deblocking_filter_override_flag) { sh->disable_deblocking_filter_flag = get_bits1(gb); if (!sh->disable_deblocking_filter_flag) { sh->beta_offset = get_se_golomb(gb) * 2; sh->tc_offset = get_se_golomb(gb) * 2; } } else { sh->disable_deblocking_filter_flag = s->pps->disable_dbf; sh->beta_offset = s->pps->beta_offset; sh->tc_offset = s->pps->tc_offset; } } else { sh->disable_deblocking_filter_flag = 0; sh->beta_offset = 0; sh->tc_offset = 0; } if (s->pps->seq_loop_filter_across_slices_enabled_flag && (sh->slice_sample_adaptive_offset_flag[0] || sh->slice_sample_adaptive_offset_flag[1] || !sh->disable_deblocking_filter_flag)) { sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); } else { sh->slice_loop_filter_across_slices_enabled_flag = s->pps->seq_loop_filter_across_slices_enabled_flag; } } else if (!s->slice_initialized) { av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); return AVERROR_INVALIDDATA; } sh->num_entry_point_offsets = 0; if (s->pps->tiles_enabled_flag || s->pps->entropy_coding_sync_enabled_flag) { unsigned num_entry_point_offsets = get_ue_golomb_long(gb); // It would be possible to bound this tighter but this here is simpler if (sh->num_entry_point_offsets > get_bits_left(gb)) { av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); return AVERROR_INVALIDDATA; } sh->num_entry_point_offsets = num_entry_point_offsets; if (sh->num_entry_point_offsets > 0) { int offset_len = get_ue_golomb_long(gb) + 1; if (offset_len < 1 || offset_len > 32) { sh->num_entry_point_offsets = 0; av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); return AVERROR_INVALIDDATA; } av_freep(&sh->entry_point_offset); av_freep(&sh->offset); av_freep(&sh->size); sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); if (!sh->entry_point_offset || !sh->offset || !sh->size) { sh->num_entry_point_offsets = 0; av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); return AVERROR(ENOMEM); } for (i = 0; i < sh->num_entry_point_offsets; i++) { unsigned val = get_bits_long(gb, offset_len); sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size } if (s->threads_number > 1 && (s->pps->num_tile_rows > 1 || s->pps->num_tile_columns > 1)) { s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here s->threads_number = 1; } else s->enable_parallel_tiles = 0; } else s->enable_parallel_tiles = 0; } if (s->pps->slice_header_extension_present_flag) { unsigned int length = get_ue_golomb_long(gb); if (length*8LL > get_bits_left(gb)) { av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); return AVERROR_INVALIDDATA; } for (i = 0; i < length; i++) skip_bits(gb, 8); // slice_header_extension_data_byte } // Inferred parameters sh->slice_qp = 26U + s->pps->pic_init_qp_minus26 + sh->slice_qp_delta; if (sh->slice_qp > 51 || sh->slice_qp < -s->sps->qp_bd_offset) { av_log(s->avctx, AV_LOG_ERROR, "The slice_qp %d is outside the valid range " "[%d, 51].\n", sh->slice_qp, -s->sps->qp_bd_offset); return AVERROR_INVALIDDATA; } sh->slice_ctb_addr_rs = sh->slice_segment_addr; if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) { av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); return AVERROR_INVALIDDATA; } if (get_bits_left(gb) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Overread slice header by %d bits\n", -get_bits_left(gb)); return AVERROR_INVALIDDATA; } s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag; if (!s->pps->cu_qp_delta_enabled_flag) s->HEVClc->qp_y = s->sh.slice_qp; s->slice_initialized = 1; s->HEVClc->tu.cu_qp_offset_cb = 0; s->HEVClc->tu.cu_qp_offset_cr = 0; return 0; }


static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color) { int x, y, fr, f; sx = av_clip(sx, 0, w - 1); sy = av_clip(sy, 0, h - 1); ex = av_clip(ex, 0, w - 1); ey = av_clip(ey, 0, h - 1); buf[sy * stride + sx] += color; if (FFABS(ex - sx) > FFABS(ey - sy)) { if (sx > ex) { FFSWAP(int, sx, ex); FFSWAP(int, sy, ey); } buf += sx + sy * stride; ex -= sx; f = ((ey - sy) << 16) / ex; for (x = 0; x = ex; x++) { y = (x * f) >> 16; fr = (x * f) & 0xFFFF; buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; buf[(y + 1) * stride + x] += (color * fr ) >> 16; } } else { if (sy > ey) { FFSWAP(int, sx, ex); FFSWAP(int, sy, ey); } buf += sx + sy * stride; ey -= sy; if (ey) f = ((ex - sx) << 16) / ey; else f = 0; for (y = 0; y = ey; y++) { x = (y * f) >> 16; fr = (y * f) & 0xFFFF; buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; buf[y * stride + x + 1] += (color * fr ) >> 16; } } }


static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags) { Coroutine *co; RwCo rwco = { .bs = bs, .offset = offset, .qiov = qiov, .is_write = is_write, .ret = NOT_DONE, .flags = flags, }; /** * In sync call context, when the vcpu is blocked, this throttling timer * will not fire; so the I/O throttling function has to be disabled here * if it has been enabled. */ if (bs->io_limits_enabled) { fprintf(stderr, "Disabling I/O throttling on '%s' due " "to synchronous I/O.\n", bdrv_get_device_name(bs)); bdrv_io_limits_disable(bs); } if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_rw_co_entry(&rwco); } else { AioContext *aio_context = bdrv_get_aio_context(bs); co = qemu_coroutine_create(bdrv_rw_co_entry); qemu_coroutine_enter(co, &rwco); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } } return rwco.ret; }


static uint64_t omap_mcbsp_read(void *opaque, hwaddr addr, unsigned size) { struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; int offset = addr & OMAP_MPUI_REG_MASK; uint16_t ret; if (size != 2) { return omap_badwidth_read16(opaque, addr); } switch (offset) { case 0x00: /* DRR2 */ if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */ return 0x0000; /* Fall through. */ case 0x02: /* DRR1 */ if (s->rx_req < 2) { printf("%s: Rx FIFO underrun\n", __FUNCTION__); omap_mcbsp_rx_done(s); } else { s->tx_req -= 2; if (s->codec && s->codec->in.len >= 2) { ret = s->codec->in.fifo[s->codec->in.start ++] << 8; ret |= s->codec->in.fifo[s->codec->in.start ++]; s->codec->in.len -= 2; } else ret = 0x0000; if (!s->tx_req) omap_mcbsp_rx_done(s); return ret; } return 0x0000; case 0x04: /* DXR2 */ case 0x06: /* DXR1 */ return 0x0000; case 0x08: /* SPCR2 */ return s->spcr[1]; case 0x0a: /* SPCR1 */ return s->spcr[0]; case 0x0c: /* RCR2 */ return s->rcr[1]; case 0x0e: /* RCR1 */ return s->rcr[0]; case 0x10: /* XCR2 */ return s->xcr[1]; case 0x12: /* XCR1 */ return s->xcr[0]; case 0x14: /* SRGR2 */ return s->srgr[1]; case 0x16: /* SRGR1 */ return s->srgr[0]; case 0x18: /* MCR2 */ return s->mcr[1]; case 0x1a: /* MCR1 */ return s->mcr[0]; case 0x1c: /* RCERA */ return s->rcer[0]; case 0x1e: /* RCERB */ return s->rcer[1]; case 0x20: /* XCERA */ return s->xcer[0]; case 0x22: /* XCERB */ return s->xcer[1]; case 0x24: /* PCR0 */ return s->pcr; case 0x26: /* RCERC */ return s->rcer[2]; case 0x28: /* RCERD */ return s->rcer[3]; case 0x2a: /* XCERC */ return s->xcer[2]; case 0x2c: /* XCERD */ return s->xcer[3]; case 0x2e: /* RCERE */ return s->rcer[4]; case 0x30: /* RCERF */ return s->rcer[5]; case 0x32: /* XCERE */ return s->xcer[4]; case 0x34: /* XCERF */ return s->xcer[5]; case 0x36: /* RCERG */ return s->rcer[6]; case 0x38: /* RCERH */ return s->rcer[7]; case 0x3a: /* XCERG */ return s->xcer[6]; case 0x3c: /* XCERH */ return s->xcer[7]; } OMAP_BAD_REG(addr); return 0; }


static void check_suspend_mode(GuestSuspendMode mode, Error **errp) { SYSTEM_POWER_CAPABILITIES sys_pwr_caps; Error *local_err = NULL; ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps)); if (!GetPwrCapabilities(&sys_pwr_caps)) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "failed to determine guest suspend capabilities"); goto out; } switch (mode) { case GUEST_SUSPEND_MODE_DISK: if (!sys_pwr_caps.SystemS4) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "suspend-to-disk not supported by OS"); } break; case GUEST_SUSPEND_MODE_RAM: if (!sys_pwr_caps.SystemS3) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "suspend-to-ram not supported by OS"); } break; default: error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode", "GuestSuspendMode"); } out: if (local_err) { error_propagate(errp, local_err); } }


av_cold static int lavfi_read_header(AVFormatContext *avctx) { LavfiContext *lavfi = avctx->priv_data; AVFilterInOut *input_links = NULL, *output_links = NULL, *inout; AVFilter *buffersink, *abuffersink; int *pix_fmts = create_all_formats(AV_PIX_FMT_NB); enum AVMediaType type; int ret = 0, i, n; #define FAIL(ERR) { ret = ERR; goto end; } if (!pix_fmts) FAIL(AVERROR(ENOMEM)); avfilter_register_all(); buffersink = avfilter_get_by_name("buffersink"); abuffersink = avfilter_get_by_name("abuffersink"); if (lavfi->graph_filename && lavfi->graph_str) { av_log(avctx, AV_LOG_ERROR, "Only one of the graph or graph_file options must be specified\n"); FAIL(AVERROR(EINVAL)); } if (lavfi->graph_filename) { uint8_t *file_buf, *graph_buf; size_t file_bufsize; ret = av_file_map(lavfi->graph_filename, &file_buf, &file_bufsize, 0, avctx); if (ret < 0) goto end; /* create a 0-terminated string based on the read file */ graph_buf = av_malloc(file_bufsize + 1); if (!graph_buf) { av_file_unmap(file_buf, file_bufsize); FAIL(AVERROR(ENOMEM)); } memcpy(graph_buf, file_buf, file_bufsize); graph_buf[file_bufsize] = 0; av_file_unmap(file_buf, file_bufsize); lavfi->graph_str = graph_buf; } if (!lavfi->graph_str) lavfi->graph_str = av_strdup(avctx->filename); /* parse the graph, create a stream for each open output */ if (!(lavfi->graph = avfilter_graph_alloc())) FAIL(AVERROR(ENOMEM)); if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str, &input_links, &output_links, avctx)) < 0) FAIL(ret); if (input_links) { av_log(avctx, AV_LOG_ERROR, "Open inputs in the filtergraph are not acceptable\n"); FAIL(AVERROR(EINVAL)); } /* count the outputs */ for (n = 0, inout = output_links; inout; n++, inout = inout->next); if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); if (!(lavfi->sink_eof = av_mallocz(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); for (i = 0; i < n; i++) lavfi->stream_sink_map[i] = -1; /* parse the output link names - they need to be of the form out0, out1, ... * create a mapping between them and the streams */ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { int stream_idx; if (!strcmp(inout->name, "out")) stream_idx = 0; else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) { av_log(avctx, AV_LOG_ERROR, "Invalid outpad name '%s'\n", inout->name); FAIL(AVERROR(EINVAL)); } if ((unsigned)stream_idx >= n) { av_log(avctx, AV_LOG_ERROR, "Invalid index was specified in output '%s', " "must be a non-negative value < %d\n", inout->name, n); FAIL(AVERROR(EINVAL)); } /* is an audio or video output? */ type = inout->filter_ctx->output_pads[inout->pad_idx].type; if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { av_log(avctx, AV_LOG_ERROR, "Output '%s' is not a video or audio output, not yet supported\n", inout->name); FAIL(AVERROR(EINVAL)); } if (lavfi->stream_sink_map[stream_idx] != -1) { av_log(avctx, AV_LOG_ERROR, "An output with stream index %d was already specified\n", stream_idx); FAIL(AVERROR(EINVAL)); } lavfi->sink_stream_map[i] = stream_idx; lavfi->stream_sink_map[stream_idx] = i; } /* for each open output create a corresponding stream */ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { AVStream *st; if (!(st = avformat_new_stream(avctx, NULL))) FAIL(AVERROR(ENOMEM)); st->id = i; } /* create a sink for each output and connect them to the graph */ lavfi->sinks = av_malloc(sizeof(AVFilterContext *) * avctx->nb_streams); if (!lavfi->sinks) FAIL(AVERROR(ENOMEM)); for (i = 0, inout = output_links; inout; i++, inout = inout->next) { AVFilterContext *sink; type = inout->filter_ctx->output_pads[inout->pad_idx].type; if (type == AVMEDIA_TYPE_VIDEO && ! buffersink || type == AVMEDIA_TYPE_AUDIO && ! abuffersink) { av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n"); FAIL(AVERROR_FILTER_NOT_FOUND); } if (type == AVMEDIA_TYPE_VIDEO) { ret = avfilter_graph_create_filter(&sink, buffersink, inout->name, NULL, NULL, lavfi->graph); av_opt_set_int_list(sink, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto end; } else if (type == AVMEDIA_TYPE_AUDIO) { enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL, -1 }; ret = avfilter_graph_create_filter(&sink, abuffersink, inout->name, NULL, NULL, lavfi->graph); av_opt_set_int_list(sink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto end; } lavfi->sinks[i] = sink; if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0) FAIL(ret); } /* configure the graph */ if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0) FAIL(ret); if (lavfi->dump_graph) { char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph); fputs(dump, stderr); fflush(stderr); av_free(dump); } /* fill each stream with the information in the corresponding sink */ for (i = 0; i < avctx->nb_streams; i++) { AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0]; AVStream *st = avctx->streams[i]; st->codec->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); if (link->type == AVMEDIA_TYPE_VIDEO) { st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; st->codec->pix_fmt = link->format; st->codec->time_base = link->time_base; st->codec->width = link->w; st->codec->height = link->h; st ->sample_aspect_ratio = st->codec->sample_aspect_ratio = link->sample_aspect_ratio; avctx->probesize = FFMAX(avctx->probesize, link->w * link->h * av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(link->format)) * 30); } else if (link->type == AVMEDIA_TYPE_AUDIO) { st->codec->codec_id = av_get_pcm_codec(link->format, -1); st->codec->channels = av_get_channel_layout_nb_channels(link->channel_layout); st->codec->sample_fmt = link->format; st->codec->sample_rate = link->sample_rate; st->codec->time_base = link->time_base; st->codec->channel_layout = link->channel_layout; if (st->codec->codec_id == AV_CODEC_ID_NONE) av_log(avctx, AV_LOG_ERROR, "Could not find PCM codec for sample format %s.\n", av_get_sample_fmt_name(link->format)); } } if (!(lavfi->decoded_frame = av_frame_alloc())) FAIL(AVERROR(ENOMEM)); end: av_free(pix_fmts); avfilter_inout_free(&input_links); avfilter_inout_free(&output_links); if (ret < 0) lavfi_read_close(avctx); return ret; }


int do_balloon(Monitor *mon, const QDict *params, MonitorCompletion cb, void *opaque) { int ret; if (kvm_enabled() && !kvm_has_sync_mmu()) { qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return -1; } ret = qemu_balloon(qdict_get_int(params, "value")); if (ret == 0) { qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); return -1; } cb(opaque, NULL); return 0; }


static av_cold int movie_init(AVFilterContext *ctx, const char *args) { MovieContext *movie = ctx->priv; AVInputFormat *iformat = NULL; int64_t timestamp; int nb_streams, ret, i; char default_streams[16], *stream_specs, *spec, *cursor; char name[16]; AVStream *st; movie->class = &movie_class; av_opt_set_defaults(movie); if (args) movie->file_name = av_get_token(&args, ":"); if (!movie->file_name || !*movie->file_name) { av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); return AVERROR(EINVAL); } if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) return ret; movie->seek_point = movie->seek_point_d * 1000000 + 0.5; stream_specs = movie->stream_specs; if (!stream_specs) { snprintf(default_streams, sizeof(default_streams), "d%c%d", !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v', movie->stream_index); stream_specs = default_streams; } for (cursor = stream_specs, nb_streams = 1; *cursor; cursor++) if (*cursor == '+') nb_streams++; if (movie->loop_count != 1 && nb_streams != 1) { av_log(ctx, AV_LOG_ERROR, "Loop with several streams is currently unsupported\n"); return AVERROR_PATCHWELCOME; } av_register_all(); // Try to find the movie format (container) iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL; movie->format_ctx = NULL; if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to avformat_open_input '%s'\n", movie->file_name); return ret; } if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0) av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n"); // if seeking requested, we execute it if (movie->seek_point > 0) { timestamp = movie->seek_point; // add the stream start time, should it exist if (movie->format_ctx->start_time != AV_NOPTS_VALUE) { if (timestamp > INT64_MAX - movie->format_ctx->start_time) { av_log(ctx, AV_LOG_ERROR, "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n", movie->file_name, movie->format_ctx->start_time, movie->seek_point); return AVERROR(EINVAL); } timestamp += movie->format_ctx->start_time; } if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) { av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n", movie->file_name, timestamp); return ret; } } for (i = 0; i < movie->format_ctx->nb_streams; i++) movie->format_ctx->streams[i]->discard = AVDISCARD_ALL; movie->st = av_calloc(nb_streams, sizeof(*movie->st)); if (!movie->st) return AVERROR(ENOMEM); for (i = 0; i < nb_streams; i++) { spec = av_strtok(stream_specs, "+", &cursor); if (!spec) return AVERROR_BUG; stream_specs = NULL; /* for next strtok */ st = find_stream(ctx, movie->format_ctx, spec); if (!st) return AVERROR(EINVAL); st->discard = AVDISCARD_DEFAULT; movie->st[i].st = st; movie->max_stream_index = FFMAX(movie->max_stream_index, st->index); } if (av_strtok(NULL, "+", &cursor)) return AVERROR_BUG; movie->out_index = av_calloc(movie->max_stream_index + 1, sizeof(*movie->out_index)); if (!movie->out_index) return AVERROR(ENOMEM); for (i = 0; i <= movie->max_stream_index; i++) movie->out_index[i] = -1; for (i = 0; i < nb_streams; i++) movie->out_index[movie->st[i].st->index] = i; for (i = 0; i < nb_streams; i++) { AVFilterPad pad = { 0 }; snprintf(name, sizeof(name), "out%d", i); pad.type = movie->st[i].st->codec->codec_type; pad.name = av_strdup(name); pad.config_props = movie_config_output_props; pad.request_frame = movie_request_frame; ff_insert_outpad(ctx, i, &pad); ret = open_stream(ctx, &movie->st[i]); if (ret < 0) return ret; if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO && !movie->st[i].st->codec->channel_layout) { ret = guess_channel_layout(&movie->st[i], i, ctx); if (ret < 0) return ret; } } if (!(movie->frame = avcodec_alloc_frame()) ) { av_log(log, AV_LOG_ERROR, "Failed to alloc frame\n"); return AVERROR(ENOMEM); } av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n", movie->seek_point, movie->format_name, movie->file_name, movie->stream_index); return 0; }


void cpu_outl(pio_addr_t addr, uint32_t val) { LOG_IOPORT("outl: %04"FMT_pioaddr" %08"PRIx32"\n", addr, val); trace_cpu_out(addr, val); ioport_write(2, addr, val); }


static void do_loadvm(int argc, const char **argv) { if (argc != 2) { help_cmd(argv[0]); return; } if (qemu_loadvm(argv[1]) < 0) term_printf("I/O error when loading VM from '%s'\n", argv[1]); }


static void vmdk_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVVmdkState *s = bs->opaque; int i; for (i = 0; i < s->num_extents; i++) { if (!s->extents[i].flat) { bs->bl.write_zeroes_alignment = MAX(bs->bl.write_zeroes_alignment, s->extents[i].cluster_sectors); } } }


static int handle_cmd(AHCIState *s, int port, int slot) { IDEState *ide_state; uint32_t opts; uint64_t tbl_addr; AHCICmdHdr *cmd; uint8_t *cmd_fis; dma_addr_t cmd_len; if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { /* Engine currently busy, try again later */ DPRINTF(port, "engine busy\n"); return -1; } cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot]; if (!s->dev[port].lst) { DPRINTF(port, "error: lst not given but cmd handled"); return -1; } /* remember current slot handle for later */ s->dev[port].cur_cmd = cmd; opts = le32_to_cpu(cmd->opts); tbl_addr = le64_to_cpu(cmd->tbl_addr); cmd_len = 0x80; cmd_fis = dma_memory_map(s->as, tbl_addr, &cmd_len, DMA_DIRECTION_FROM_DEVICE); if (!cmd_fis) { DPRINTF(port, "error: guest passed us an invalid cmd fis\n"); return -1; } /* The device we are working for */ ide_state = &s->dev[port].port.ifs[0]; if (!ide_state->bs) { DPRINTF(port, "error: guest accessed unused port"); goto out; } debug_print_fis(cmd_fis, 0x90); //debug_print_fis(cmd_fis, (opts & AHCI_CMD_HDR_CMD_FIS_LEN) * 4); switch (cmd_fis[0]) { case SATA_FIS_TYPE_REGISTER_H2D: break; default: DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x " "cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1], cmd_fis[2]); goto out; break; } switch (cmd_fis[1]) { case SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER: break; case 0: break; default: DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x " "cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1], cmd_fis[2]); goto out; break; } switch (s->dev[port].port_state) { case STATE_RUN: if (cmd_fis[15] & ATA_SRST) { s->dev[port].port_state = STATE_RESET; } break; case STATE_RESET: if (!(cmd_fis[15] & ATA_SRST)) { ahci_reset_port(s, port); } break; } if (cmd_fis[1] == SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER) { /* Check for NCQ command */ if ((cmd_fis[2] == READ_FPDMA_QUEUED) || (cmd_fis[2] == WRITE_FPDMA_QUEUED)) { process_ncq_command(s, port, cmd_fis, slot); goto out; } /* Decompose the FIS */ ide_state->nsector = (int64_t)((cmd_fis[13] << 8) | cmd_fis[12]); ide_state->feature = cmd_fis[3]; if (!ide_state->nsector) { ide_state->nsector = 256; } if (ide_state->drive_kind != IDE_CD) { /* * We set the sector depending on the sector defined in the FIS. * Unfortunately, the spec isn't exactly obvious on this one. * * Apparently LBA48 commands set fis bytes 10,9,8,6,5,4 to the * 48 bit sector number. ATA_CMD_READ_DMA_EXT is an example for * such a command. * * Non-LBA48 commands however use 7[lower 4 bits],6,5,4 to define a * 28-bit sector number. ATA_CMD_READ_DMA is an example for such * a command. * * Since the spec doesn't explicitly state what each field should * do, I simply assume non-used fields as reserved and OR everything * together, independent of the command. */ ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40) | ((uint64_t)cmd_fis[9] << 32) /* This is used for LBA48 commands */ | ((uint64_t)cmd_fis[8] << 24) /* This is used for non-LBA48 commands */ | ((uint64_t)(cmd_fis[7] & 0xf) << 24) | ((uint64_t)cmd_fis[6] << 16) | ((uint64_t)cmd_fis[5] << 8) | cmd_fis[4]); } /* Copy the ACMD field (ATAPI packet, if any) from the AHCI command * table to ide_state->io_buffer */ if (opts & AHCI_CMD_ATAPI) { memcpy(ide_state->io_buffer, &cmd_fis[AHCI_COMMAND_TABLE_ACMD], 0x10); ide_state->lcyl = 0x14; ide_state->hcyl = 0xeb; debug_print_fis(ide_state->io_buffer, 0x10); ide_state->feature = IDE_FEATURE_DMA; s->dev[port].done_atapi_packet = false; /* XXX send PIO setup FIS */ } ide_state->error = 0; /* Reset transferred byte counter */ cmd->status = 0; /* We're ready to process the command in FIS byte 2. */ ide_exec_cmd(&s->dev[port].port, cmd_fis[2]); } out: dma_memory_unmap(s->as, cmd_fis, cmd_len, DMA_DIRECTION_FROM_DEVICE, cmd_len); if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { /* async command, complete later */ s->dev[port].busy_slot = slot; return -1; } /* done handling the command */ return 0; }


static void virtio_rng_process(VirtIORNG *vrng) { size_t size; if (!is_guest_ready(vrng)) { return; } size = get_request_size(vrng->vq); size = MIN(vrng->quota_remaining, size); if (size) { rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); } }


static int vhost_verify_ring_part_mapping(void *part, uint64_t part_addr, uint64_t part_size, uint64_t start_addr, uint64_t size) { hwaddr l; void *p; int r = 0; if (!ranges_overlap(start_addr, size, part_addr, part_size)) { return 0; } l = part_size; p = cpu_physical_memory_map(part_addr, &l, 1); if (!p || l != part_size) { r = -ENOMEM; } if (p != part) { r = -EBUSY; } cpu_physical_memory_unmap(p, l, 0, 0); return r; }


bool block_job_is_paused(BlockJob *job) { return job->paused; }


int qemu_register_machine(QEMUMachine *m) { char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL); TypeInfo ti = { .name = name, .parent = TYPE_MACHINE, .class_init = machine_class_init, .class_data = (void *)m, }; type_register(&ti); g_free(name); return 0; }


static int tosa_dac_event(I2CSlave *i2c, enum i2c_event event) { TosaDACState *s = TOSA_DAC(i2c); s->len = 0; switch (event) { case I2C_START_SEND: break; case I2C_START_RECV: printf("%s: recv not supported!!!\n", __FUNCTION__); break; case I2C_FINISH: #ifdef VERBOSE if (s->len < 2) printf("%s: message too short (%i bytes)\n", __FUNCTION__, s->len); if (s->len > 2) printf("%s: message too long\n", __FUNCTION__); #endif break; default: break; } return 0; }


av_cold void ff_vp8dsp_init_neon(VP8DSPContext *dsp) { dsp->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_neon; dsp->vp8_idct_add = ff_vp8_idct_add_neon; dsp->vp8_idct_dc_add = ff_vp8_idct_dc_add_neon; dsp->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_neon; dsp->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_neon; dsp->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16_neon; dsp->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16_neon; dsp->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_neon; dsp->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_neon; dsp->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16_inner_neon; dsp->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16_inner_neon; dsp->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_neon; dsp->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_neon; dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter16_simple_neon; dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter16_simple_neon; dsp->put_vp8_epel_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon; dsp->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_neon; dsp->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_neon; dsp->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_neon; dsp->put_vp8_epel_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon; dsp->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_neon; dsp->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_neon; dsp->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_neon; dsp->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_neon; dsp->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_neon; dsp->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_neon; dsp->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_neon; dsp->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_neon; dsp->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_neon; dsp->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_neon; dsp->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_neon; dsp->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_neon; dsp->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_neon; dsp->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_neon; dsp->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_neon; dsp->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_neon; dsp->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon; dsp->put_vp8_bilinear_pixels_tab[0][0][1] = ff_put_vp8_bilin16_h_neon; dsp->put_vp8_bilinear_pixels_tab[0][0][2] = ff_put_vp8_bilin16_h_neon; dsp->put_vp8_bilinear_pixels_tab[0][1][0] = ff_put_vp8_bilin16_v_neon; dsp->put_vp8_bilinear_pixels_tab[0][1][1] = ff_put_vp8_bilin16_hv_neon; dsp->put_vp8_bilinear_pixels_tab[0][1][2] = ff_put_vp8_bilin16_hv_neon; dsp->put_vp8_bilinear_pixels_tab[0][2][0] = ff_put_vp8_bilin16_v_neon; dsp->put_vp8_bilinear_pixels_tab[0][2][1] = ff_put_vp8_bilin16_hv_neon; dsp->put_vp8_bilinear_pixels_tab[0][2][2] = ff_put_vp8_bilin16_hv_neon; dsp->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon; dsp->put_vp8_bilinear_pixels_tab[1][0][1] = ff_put_vp8_bilin8_h_neon; dsp->put_vp8_bilinear_pixels_tab[1][0][2] = ff_put_vp8_bilin8_h_neon; dsp->put_vp8_bilinear_pixels_tab[1][1][0] = ff_put_vp8_bilin8_v_neon; dsp->put_vp8_bilinear_pixels_tab[1][1][1] = ff_put_vp8_bilin8_hv_neon; dsp->put_vp8_bilinear_pixels_tab[1][1][2] = ff_put_vp8_bilin8_hv_neon; dsp->put_vp8_bilinear_pixels_tab[1][2][0] = ff_put_vp8_bilin8_v_neon; dsp->put_vp8_bilinear_pixels_tab[1][2][1] = ff_put_vp8_bilin8_hv_neon; dsp->put_vp8_bilinear_pixels_tab[1][2][2] = ff_put_vp8_bilin8_hv_neon; dsp->put_vp8_bilinear_pixels_tab[2][0][1] = ff_put_vp8_bilin4_h_neon; dsp->put_vp8_bilinear_pixels_tab[2][0][2] = ff_put_vp8_bilin4_h_neon; dsp->put_vp8_bilinear_pixels_tab[2][1][0] = ff_put_vp8_bilin4_v_neon; dsp->put_vp8_bilinear_pixels_tab[2][1][1] = ff_put_vp8_bilin4_hv_neon; dsp->put_vp8_bilinear_pixels_tab[2][1][2] = ff_put_vp8_bilin4_hv_neon; dsp->put_vp8_bilinear_pixels_tab[2][2][0] = ff_put_vp8_bilin4_v_neon; dsp->put_vp8_bilinear_pixels_tab[2][2][1] = ff_put_vp8_bilin4_hv_neon; dsp->put_vp8_bilinear_pixels_tab[2][2][2] = ff_put_vp8_bilin4_hv_neon; }


static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested, uint32_t *byte_len) { int num_cq_events = 0, ret = 0; struct ibv_cq *cq; void *cq_ctx; uint64_t wr_id = RDMA_WRID_NONE, wr_id_in; if (ibv_req_notify_cq(rdma->cq, 0)) { return -1; } /* poll cq first */ while (wr_id != wrid_requested) { ret = qemu_rdma_poll(rdma, &wr_id_in, byte_len); if (ret < 0) { return ret; } wr_id = wr_id_in & RDMA_WRID_TYPE_MASK; if (wr_id == RDMA_WRID_NONE) { break; } if (wr_id != wrid_requested) { trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested), wrid_requested, print_wrid(wr_id), wr_id); } } if (wr_id == wrid_requested) { return 0; } while (1) { /* * Coroutine doesn't start until migration_fd_process_incoming() * so don't yield unless we know we're running inside of a coroutine. */ if (rdma->migration_started_on_destination) { yield_until_fd_readable(rdma->comp_channel->fd); } ret = ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx); if (ret) { perror("ibv_get_cq_event"); goto err_block_for_wrid; } num_cq_events++; ret = -ibv_req_notify_cq(cq, 0); if (ret) { goto err_block_for_wrid; } while (wr_id != wrid_requested) { ret = qemu_rdma_poll(rdma, &wr_id_in, byte_len); if (ret < 0) { goto err_block_for_wrid; } wr_id = wr_id_in & RDMA_WRID_TYPE_MASK; if (wr_id == RDMA_WRID_NONE) { break; } if (wr_id != wrid_requested) { trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested), wrid_requested, print_wrid(wr_id), wr_id); } } if (wr_id == wrid_requested) { goto success_block_for_wrid; } } success_block_for_wrid: if (num_cq_events) { ibv_ack_cq_events(cq, num_cq_events); } return 0; err_block_for_wrid: if (num_cq_events) { ibv_ack_cq_events(cq, num_cq_events); } rdma->error_state = ret; return ret; }


static void mmio_ide_cmd_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { MMIOState *s = opaque; ide_cmd_write(&s->bus, 0, val); }


static void xenfb_copy_mfns(int mode, int count, unsigned long *dst, void *src) { uint32_t *src32 = src; uint64_t *src64 = src; int i; for (i = 0; i < count; i++) dst[i] = (mode == 32) ? src32[i] : src64[i]; }


void memory_region_unregister_iommu_notifier(MemoryRegion *mr, Notifier *n) { notifier_remove(n); if (mr->iommu_ops->notify_stopped && QLIST_EMPTY(&mr->iommu_notify.notifiers)) { mr->iommu_ops->notify_stopped(mr); } }


int inet_connect(const char *str, bool block, Error **errp) { QemuOpts *opts; int sock = -1; opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL); if (inet_parse(opts, str) == 0) { if (block) { qemu_opt_set(opts, "block", "on"); } sock = inet_connect_opts(opts, errp); } else { error_set(errp, QERR_SOCKET_CREATE_FAILED); } qemu_opts_del(opts); return sock; }


static void eth_send(mv88w8618_eth_state *s, int queue_index) { uint32_t desc_addr = s->tx_queue[queue_index]; mv88w8618_tx_desc desc; uint8_t buf[2048]; int len; do { eth_tx_desc_get(desc_addr, &desc); if (desc.cmdstat & MP_ETH_TX_OWN) { len = desc.bytes; if (len < 2048) { cpu_physical_memory_read(desc.buffer, buf, len); qemu_send_packet(s->vc, buf, len); } desc.cmdstat &= ~MP_ETH_TX_OWN; s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index); eth_tx_desc_put(desc_addr, &desc); } desc_addr = desc.next; } while (desc_addr != s->tx_queue[queue_index]); }


static void test_submit_aio(void) { WorkerTestData data = { .n = 0, .ret = -EINPROGRESS }; data.aiocb = thread_pool_submit_aio(worker_cb, &data, done_cb, &data); /* The callbacks are not called until after the first wait. */ active = 1; g_assert_cmpint(data.ret, ==, -EINPROGRESS); qemu_aio_flush(); g_assert_cmpint(active, ==, 0); g_assert_cmpint(data.n, ==, 1); g_assert_cmpint(data.ret, ==, 0); }


static int hls_start(AVFormatContext *s) { HLSContext *c = s->priv_data; AVFormatContext *oc = c->avf; int err = 0; if (c->wrap) c->number %= c->wrap; if (av_get_frame_filename(oc->filename, sizeof(oc->filename), c->basename, c->number++) < 0) return AVERROR(EINVAL); if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL)) < 0) return err; if (oc->oformat->priv_class && oc->priv_data) av_opt_set(oc->priv_data, "mpegts_flags", "resend_headers", 0); return 0; }


void migrate_decompress_threads_create(void) { int i, thread_count; thread_count = migrate_decompress_threads(); decompress_threads = g_new0(QemuThread, thread_count); decomp_param = g_new0(DecompressParam, thread_count); quit_decomp_thread = false; qemu_mutex_init(&decomp_done_lock); qemu_cond_init(&decomp_done_cond); for (i = 0; i < thread_count; i++) { qemu_mutex_init(&decomp_param[i].mutex); qemu_cond_init(&decomp_param[i].cond); decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE)); decomp_param[i].done = true; qemu_thread_create(decompress_threads + i, "decompress", do_data_decompress, decomp_param + i, QEMU_THREAD_JOINABLE); } }


void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE); }


static void ppc_spapr_reset(void) { sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); PowerPCCPU *first_ppc_cpu; uint32_t rtas_limit; /* Check for unknown sysbus devices */ foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL); /* Reset the hash table & recalc the RMA */ spapr_reset_htab(spapr); qemu_devices_reset(); /* * We place the device tree and RTAS just below either the top of the RMA, * or just below 2GB, whichever is lowere, so that it can be * processed with 32-bit real mode code if necessary */ rtas_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR); spapr->rtas_addr = rtas_limit - RTAS_MAX_SIZE; spapr->fdt_addr = spapr->rtas_addr - FDT_MAX_SIZE; /* Load the fdt */ spapr_finalize_fdt(spapr, spapr->fdt_addr, spapr->rtas_addr, spapr->rtas_size); /* Copy RTAS over */ cpu_physical_memory_write(spapr->rtas_addr, spapr->rtas_blob, spapr->rtas_size); /* Set up the entry state */ first_ppc_cpu = POWERPC_CPU(first_cpu); first_ppc_cpu->env.gpr[3] = spapr->fdt_addr; first_ppc_cpu->env.gpr[5] = 0; first_cpu->halted = 0; first_ppc_cpu->env.nip = spapr->entry_point; }


static void create_one_flash(const char *name, hwaddr flashbase, hwaddr flashsize) { /* Create and map a single flash device. We use the same * parameters as the flash devices on the Versatile Express board. */ DriveInfo *dinfo = drive_get_next(IF_PFLASH); DeviceState *dev = qdev_create(NULL, "cfi.pflash01"); const uint64_t sectorlength = 256 * 1024; if (dinfo && qdev_prop_set_drive(dev, "drive", blk_bs(blk_by_legacy_dinfo(dinfo)))) { abort(); } qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength); qdev_prop_set_uint64(dev, "sector-length", sectorlength); qdev_prop_set_uint8(dev, "width", 4); qdev_prop_set_uint8(dev, "device-width", 2); qdev_prop_set_uint8(dev, "big-endian", 0); qdev_prop_set_uint16(dev, "id0", 0x89); qdev_prop_set_uint16(dev, "id1", 0x18); qdev_prop_set_uint16(dev, "id2", 0x00); qdev_prop_set_uint16(dev, "id3", 0x00); qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, flashbase); }


gdb_handlesig (CPUState *env, int sig) { GDBState *s; char buf[256]; int n; s = &gdbserver_state; if (gdbserver_fd < 0 || s->fd < 0) return sig; /* disable single step if it was enabled */ cpu_single_step(env, 0); tb_flush(env); if (sig != 0) { snprintf(buf, sizeof(buf), "S%02x", sig); put_packet(s, buf); } /* put_packet() might have detected that the peer terminated the connection. */ if (s->fd < 0) return sig; sig = 0; s->state = RS_IDLE; s->running_state = 0; while (s->running_state == 0) { n = read (s->fd, buf, 256); if (n > 0) { int i; for (i = 0; i < n; i++) gdb_read_byte (s, buf[i]); } else if (n == 0 || errno != EAGAIN) { /* XXX: Connection closed. Should probably wait for annother connection before continuing. */ return sig; } } sig = s->signal; s->signal = 0; return sig; }


uint32_t HELPER(csst)(CPUS390XState *env, uint32_t r3, uint64_t a1, uint64_t a2) { #if !defined(CONFIG_USER_ONLY) || defined(CONFIG_ATOMIC128) uint32_t mem_idx = cpu_mmu_index(env, false); #endif uintptr_t ra = GETPC(); uint32_t fc = extract32(env->regs[0], 0, 8); uint32_t sc = extract32(env->regs[0], 8, 8); uint64_t pl = get_address(env, 1) & -16; uint64_t svh, svl; uint32_t cc; /* Sanity check the function code and storage characteristic. */ if (fc > 1 || sc > 3) { if (!s390_has_feat(S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2)) { goto spec_exception; } if (fc > 2 || sc > 4 || (fc == 2 && (r3 & 1))) { goto spec_exception; } } /* Sanity check the alignments. */ if (extract32(a1, 0, 4 << fc) || extract32(a2, 0, 1 << sc)) { goto spec_exception; } /* Sanity check writability of the store address. */ #ifndef CONFIG_USER_ONLY probe_write(env, a2, mem_idx, ra); #endif /* Note that the compare-and-swap is atomic, and the store is atomic, but the complete operation is not. Therefore we do not need to assert serial context in order to implement this. That said, restart early if we can't support either operation that is supposed to be atomic. */ if (parallel_cpus) { int mask = 0; #if !defined(CONFIG_ATOMIC64) mask = -8; #elif !defined(CONFIG_ATOMIC128) mask = -16; #endif if (((4 << fc) | (1 << sc)) & mask) { cpu_loop_exit_atomic(ENV_GET_CPU(env), ra); } } /* All loads happen before all stores. For simplicity, load the entire store value area from the parameter list. */ svh = cpu_ldq_data_ra(env, pl + 16, ra); svl = cpu_ldq_data_ra(env, pl + 24, ra); switch (fc) { case 0: { uint32_t nv = cpu_ldl_data_ra(env, pl, ra); uint32_t cv = env->regs[r3]; uint32_t ov; if (parallel_cpus) { #ifdef CONFIG_USER_ONLY uint32_t *haddr = g2h(a1); ov = atomic_cmpxchg__nocheck(haddr, cv, nv); #else TCGMemOpIdx oi = make_memop_idx(MO_TEUL | MO_ALIGN, mem_idx); ov = helper_atomic_cmpxchgl_be_mmu(env, a1, cv, nv, oi, ra); #endif } else { ov = cpu_ldl_data_ra(env, a1, ra); cpu_stl_data_ra(env, a1, (ov == cv ? nv : ov), ra); } cc = (ov != cv); env->regs[r3] = deposit64(env->regs[r3], 32, 32, ov); } break; case 1: { uint64_t nv = cpu_ldq_data_ra(env, pl, ra); uint64_t cv = env->regs[r3]; uint64_t ov; if (parallel_cpus) { #ifdef CONFIG_ATOMIC64 # ifdef CONFIG_USER_ONLY uint64_t *haddr = g2h(a1); ov = atomic_cmpxchg__nocheck(haddr, cv, nv); # else TCGMemOpIdx oi = make_memop_idx(MO_TEQ | MO_ALIGN, mem_idx); ov = helper_atomic_cmpxchgq_be_mmu(env, a1, cv, nv, oi, ra); # endif #else /* Note that we asserted !parallel_cpus above. */ g_assert_not_reached(); #endif } else { ov = cpu_ldq_data_ra(env, a1, ra); cpu_stq_data_ra(env, a1, (ov == cv ? nv : ov), ra); } cc = (ov != cv); env->regs[r3] = ov; } break; case 2: { uint64_t nvh = cpu_ldq_data_ra(env, pl, ra); uint64_t nvl = cpu_ldq_data_ra(env, pl + 8, ra); Int128 nv = int128_make128(nvl, nvh); Int128 cv = int128_make128(env->regs[r3 + 1], env->regs[r3]); Int128 ov; if (parallel_cpus) { #ifdef CONFIG_ATOMIC128 TCGMemOpIdx oi = make_memop_idx(MO_TEQ | MO_ALIGN_16, mem_idx); ov = helper_atomic_cmpxchgo_be_mmu(env, a1, cv, nv, oi, ra); cc = !int128_eq(ov, cv); #else /* Note that we asserted !parallel_cpus above. */ g_assert_not_reached(); #endif } else { uint64_t oh = cpu_ldq_data_ra(env, a1 + 0, ra); uint64_t ol = cpu_ldq_data_ra(env, a1 + 8, ra); ov = int128_make128(ol, oh); cc = !int128_eq(ov, cv); if (cc) { nv = ov; } cpu_stq_data_ra(env, a1 + 0, int128_gethi(nv), ra); cpu_stq_data_ra(env, a1 + 8, int128_getlo(nv), ra); } env->regs[r3 + 0] = int128_gethi(ov); env->regs[r3 + 1] = int128_getlo(ov); } break; default: g_assert_not_reached(); } /* Store only if the comparison succeeded. Note that above we use a pair of 64-bit big-endian loads, so for sc < 3 we must extract the value from the most-significant bits of svh. */ if (cc == 0) { switch (sc) { case 0: cpu_stb_data_ra(env, a2, svh >> 56, ra); break; case 1: cpu_stw_data_ra(env, a2, svh >> 48, ra); break; case 2: cpu_stl_data_ra(env, a2, svh >> 32, ra); break; case 3: cpu_stq_data_ra(env, a2, svh, ra); break; case 4: if (parallel_cpus) { #ifdef CONFIG_ATOMIC128 TCGMemOpIdx oi = make_memop_idx(MO_TEQ | MO_ALIGN_16, mem_idx); Int128 sv = int128_make128(svl, svh); helper_atomic_sto_be_mmu(env, a2, sv, oi, ra); #else /* Note that we asserted !parallel_cpus above. */ g_assert_not_reached(); #endif } else { cpu_stq_data_ra(env, a2 + 0, svh, ra); cpu_stq_data_ra(env, a2 + 8, svl, ra); } break; default: g_assert_not_reached(); } } return cc; spec_exception: cpu_restore_state(ENV_GET_CPU(env), ra); program_interrupt(env, PGM_SPECIFICATION, 6); g_assert_not_reached(); }


static void nbd_request_put(NBDRequest *req) { NBDClient *client = req->client; if (req->data) { qemu_vfree(req->data); } g_slice_free(NBDRequest, req); if (client->nb_requests-- == MAX_NBD_REQUESTS) { qemu_notify_event(); } nbd_client_put(client); }


void timerlistgroup_deinit(QEMUTimerListGroup *tlg) { QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { timerlist_free(tlg->tl[type]); } }


static int nbd_receive_options(NBDClient *client) { int csock = client->sock; uint32_t flags; /* Client sends: [ 0 .. 3] client flags [ 0 .. 7] NBD_OPTS_MAGIC [ 8 .. 11] NBD option [12 .. 15] Data length ... Rest of request [ 0 .. 7] NBD_OPTS_MAGIC [ 8 .. 11] Second NBD option [12 .. 15] Data length ... Rest of request */ if (read_sync(csock, &flags, sizeof(flags)) != sizeof(flags)) { LOG("read failed"); return -EIO; } TRACE("Checking client flags"); be32_to_cpus(&flags); if (flags != 0 && flags != NBD_FLAG_C_FIXED_NEWSTYLE) { LOG("Bad client flags received"); return -EIO; } while (1) { int ret; uint32_t tmp, length; uint64_t magic; if (read_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) { LOG("read failed"); return -EINVAL; } TRACE("Checking opts magic"); if (magic != be64_to_cpu(NBD_OPTS_MAGIC)) { LOG("Bad magic received"); return -EINVAL; } if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) { LOG("read failed"); return -EINVAL; } if (read_sync(csock, &length, sizeof(length)) != sizeof(length)) { LOG("read failed"); return -EINVAL; } length = be32_to_cpu(length); TRACE("Checking option"); switch (be32_to_cpu(tmp)) { case NBD_OPT_LIST: ret = nbd_handle_list(client, length); if (ret < 0) { return ret; } break; case NBD_OPT_ABORT: return -EINVAL; case NBD_OPT_EXPORT_NAME: return nbd_handle_export_name(client, length); default: tmp = be32_to_cpu(tmp); LOG("Unsupported option 0x%x", tmp); nbd_send_rep(client->sock, NBD_REP_ERR_UNSUP, tmp); return -EINVAL; } } }


void xtensa_breakpoint_handler(CPUState *cs) { XtensaCPU *cpu = XTENSA_CPU(cs); CPUXtensaState *env = &cpu->env; if (cs->watchpoint_hit) { if (cs->watchpoint_hit->flags & BP_CPU) { uint32_t cause; cs->watchpoint_hit = NULL; cause = check_hw_breakpoints(env); if (cause) { debug_exception_env(env, cause); } cpu_resume_from_signal(cs, NULL); } } }


static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename) { const QCowHeader *cow_header = (const void *)buf; if (buf_size >= sizeof(QCowHeader) && be32_to_cpu(cow_header->magic) == QCOW_MAGIC && be32_to_cpu(cow_header->version) >= QCOW_VERSION) return 100; else return 0; }


static int read_header(AVFormatContext *s, AVFormatParameters *ap) { BinkDemuxContext *bink = s->priv_data; AVIOContext *pb = s->pb; uint32_t fps_num, fps_den; AVStream *vst, *ast; unsigned int i; uint32_t pos, next_pos; uint16_t flags; int keyframe; vst = av_new_stream(s, 0); if (!vst) return AVERROR(ENOMEM); vst->codec->codec_tag = avio_rl32(pb); bink->file_size = avio_rl32(pb) + 8; vst->duration = avio_rl32(pb); if (vst->duration > 1000000) { av_log(s, AV_LOG_ERROR, "invalid header: more than 1000000 frames\n"); return AVERROR(EIO); } if (avio_rl32(pb) > bink->file_size) { av_log(s, AV_LOG_ERROR, "invalid header: largest frame size greater than file size\n"); return AVERROR(EIO); } avio_skip(pb, 4); vst->codec->width = avio_rl32(pb); vst->codec->height = avio_rl32(pb); fps_num = avio_rl32(pb); fps_den = avio_rl32(pb); if (fps_num == 0 || fps_den == 0) { av_log(s, AV_LOG_ERROR, "invalid header: invalid fps (%d/%d)\n", fps_num, fps_den); return AVERROR(EIO); } av_set_pts_info(vst, 64, fps_den, fps_num); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_BINKVIDEO; vst->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); vst->codec->extradata_size = 4; avio_read(pb, vst->codec->extradata, 4); bink->num_audio_tracks = avio_rl32(pb); if (bink->num_audio_tracks > BINK_MAX_AUDIO_TRACKS) { av_log(s, AV_LOG_ERROR, "invalid header: more than "AV_STRINGIFY(BINK_MAX_AUDIO_TRACKS)" audio tracks (%d)\n", bink->num_audio_tracks); return AVERROR(EIO); } if (bink->num_audio_tracks) { avio_skip(pb, 4 * bink->num_audio_tracks); for (i = 0; i < bink->num_audio_tracks; i++) { ast = av_new_stream(s, 1); if (!ast) return AVERROR(ENOMEM); ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_tag = vst->codec->codec_tag; ast->codec->sample_rate = avio_rl16(pb); av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); flags = avio_rl16(pb); ast->codec->codec_id = flags & BINK_AUD_USEDCT ? CODEC_ID_BINKAUDIO_DCT : CODEC_ID_BINKAUDIO_RDFT; ast->codec->channels = flags & BINK_AUD_STEREO ? 2 : 1; } for (i = 0; i < bink->num_audio_tracks; i++) s->streams[i + 1]->id = avio_rl32(pb); } /* frame index table */ next_pos = avio_rl32(pb); for (i = 0; i < vst->duration; i++) { pos = next_pos; if (i == vst->duration - 1) { next_pos = bink->file_size; keyframe = 0; } else { next_pos = avio_rl32(pb); keyframe = pos & 1; } pos &= ~1; next_pos &= ~1; if (next_pos <= pos) { av_log(s, AV_LOG_ERROR, "invalid frame index table\n"); return AVERROR(EIO); } av_add_index_entry(vst, pos, i, next_pos - pos, 0, keyframe ? AVINDEX_KEYFRAME : 0); } avio_skip(pb, 4); bink->current_track = -1; return 0; }


static int ftp_status(FTPContext *s, char **line, const int response_codes[]) { int err, i, result = 0, pref_code_found = 0, wait_count = 100; char buf[CONTROL_BUFFER_SIZE]; /* Set blocking mode */ s->conn_control_block_flag = 0; for (;;) { if ((err = ftp_get_line(s, buf, sizeof(buf))) < 0) { if (err == AVERROR_EXIT) { if (!pref_code_found && wait_count--) { av_usleep(10000); continue; } } return result; } av_log(s, AV_LOG_DEBUG, "%s\n", buf); if (!pref_code_found) { if (strlen(buf) < 3) continue; err = 0; for (i = 0; i < 3; ++i) { if (buf[i] < '0' || buf[i] > '9') continue; err *= 10; err += buf[i] - '0'; } for (i = 0; response_codes[i]; ++i) { if (err == response_codes[i]) { /* first code received. Now get all lines in non blocking mode */ s->conn_control_block_flag = 1; pref_code_found = 1; result = err; if (line) *line = av_strdup(buf); break; } } } } return result; }


static void unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) { int i, j, k; int coding_mode; int motion_x[6]; int motion_y[6]; int last_motion_x = 0; int last_motion_y = 0; int prior_last_motion_x = 0; int prior_last_motion_y = 0; int current_macroblock; int current_fragment; debug_vp3(" vp3: unpacking motion vectors\n"); if (s->keyframe) { debug_vp3(" keyframe-- there are no motion vectors\n"); } else { memset(motion_x, 0, 6 * sizeof(int)); memset(motion_y, 0, 6 * sizeof(int)); /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */ coding_mode = get_bits(gb, 1); debug_vectors(" using %s scheme for unpacking motion vectors\n", (coding_mode == 0) ? "VLC" : "fixed-length"); /* iterate through all of the macroblocks that contain 1 or more * coded fragments */ for (i = 0; i < s->u_superblock_start; i++) { for (j = 0; j < 4; j++) { current_macroblock = s->superblock_macroblocks[i * 4 + j]; if ((current_macroblock == -1) || (!s->macroblock_coded[current_macroblock])) continue; current_fragment = s->macroblock_fragments[current_macroblock * 6]; switch (s->all_fragments[current_fragment].coding_method) { case MODE_INTER_PLUS_MV: case MODE_GOLDEN_MV: /* all 6 fragments use the same motion vector */ if (coding_mode == 0) { motion_x[0] = get_motion_vector_vlc(gb); motion_y[0] = get_motion_vector_vlc(gb); } else { motion_x[0] = get_motion_vector_fixed(gb); motion_y[0] = get_motion_vector_fixed(gb); } for (k = 1; k < 6; k++) { motion_x[k] = motion_x[0]; motion_y[k] = motion_y[0]; } /* vector maintenance, only on MODE_INTER_PLUS_MV */ if (s->all_fragments[current_fragment].coding_method == MODE_INTER_PLUS_MV) { prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; } break; case MODE_INTER_FOURMV: /* fetch 4 vectors from the bitstream, one for each * Y fragment, then average for the C fragment vectors */ motion_x[4] = motion_y[4] = 0; for (k = 0; k < 4; k++) { if (coding_mode == 0) { motion_x[k] = get_motion_vector_vlc(gb); motion_y[k] = get_motion_vector_vlc(gb); } else { motion_x[k] = get_motion_vector_fixed(gb); motion_y[k] = get_motion_vector_fixed(gb); } motion_x[4] += motion_x[k]; motion_y[4] += motion_y[k]; } if (motion_x[4] >= 0) motion_x[4] = (motion_x[4] + 2) / 4; else motion_x[4] = (motion_x[4] - 2) / 4; motion_x[5] = motion_x[4]; if (motion_y[4] >= 0) motion_y[4] = (motion_y[4] + 2) / 4; else motion_y[4] = (motion_y[4] - 2) / 4; motion_y[5] = motion_y[4]; /* vector maintenance; vector[3] is treated as the * last vector in this case */ prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[3]; last_motion_y = motion_y[3]; break; case MODE_INTER_LAST_MV: /* all 6 fragments use the last motion vector */ motion_x[0] = last_motion_x; motion_y[0] = last_motion_y; for (k = 1; k < 6; k++) { motion_x[k] = motion_x[0]; motion_y[k] = motion_y[0]; } /* no vector maintenance (last vector remains the * last vector) */ break; case MODE_INTER_PRIOR_LAST: /* all 6 fragments use the motion vector prior to the * last motion vector */ motion_x[0] = prior_last_motion_x; motion_y[0] = prior_last_motion_y; for (k = 1; k < 6; k++) { motion_x[k] = motion_x[0]; motion_y[k] = motion_y[0]; } /* vector maintenance */ prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; break; default: /* covers intra, inter without MV, golden without MV */ memset(motion_x, 0, 6 * sizeof(int)); memset(motion_y, 0, 6 * sizeof(int)); /* no vector maintenance */ break; } /* assign the motion vectors to the correct fragments */ debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n", current_fragment, s->all_fragments[current_fragment].coding_method); for (k = 0; k < 6; k++) { current_fragment = s->macroblock_fragments[current_macroblock * 6 + k]; s->all_fragments[current_fragment].motion_halfpel_index = adjust_vector(&motion_x[k], &motion_y[k], ((k == 4) || (k == 5))); s->all_fragments[current_fragment].motion_x = motion_x[k]; s->all_fragments[current_fragment].motion_y = motion_y[k]; debug_vectors(" vector %d: fragment %d = (%d, %d), index %d\n", k, current_fragment, motion_x[k], motion_y[k], s->all_fragments[current_fragment].motion_halfpel_index); } } } } }


static void ipvideo_decode_opcodes(IpvideoContext *s, AVFrame *frame) { int x, y; unsigned char opcode; int ret; GetBitContext gb; bytestream2_skip(&s->stream_ptr, 14); /* data starts 14 bytes in */ if (!s->is_16bpp) { /* this is PAL8, so make the palette available */ memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); s->stride = frame->linesize[0]; } else { s->stride = frame->linesize[0] >> 1; s->mv_ptr = s->stream_ptr; bytestream2_skip(&s->mv_ptr, bytestream2_get_le16(&s->stream_ptr)); } s->line_inc = s->stride - 8; s->upper_motion_limit_offset = (s->avctx->height - 8) * frame->linesize[0] + (s->avctx->width - 8) * (1 + s->is_16bpp); init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8); for (y = 0; y < s->avctx->height; y += 8) { for (x = 0; x < s->avctx->width; x += 8) { if (get_bits_left(&gb) < 4) return; opcode = get_bits(&gb, 4); ff_tlog(s->avctx, " block @ (%3d, %3d): encoding 0x%X, data ptr offset %d\n", x, y, opcode, bytestream2_tell(&s->stream_ptr)); if (!s->is_16bpp) { s->pixel_ptr = frame->data[0] + x + y*frame->linesize[0]; ret = ipvideo_decode_block[opcode](s, frame); } else { s->pixel_ptr = frame->data[0] + x*2 + y*frame->linesize[0]; ret = ipvideo_decode_block16[opcode](s, frame); } if (ret != 0) { av_log(s->avctx, AV_LOG_ERROR, "decode problem on frame %d, @ block (%d, %d)\n", s->avctx->frame_number, x, y); return; } } } if (bytestream2_get_bytes_left(&s->stream_ptr) > 1) { av_log(s->avctx, AV_LOG_DEBUG, "decode finished with %d bytes left over\n", bytestream2_get_bytes_left(&s->stream_ptr)); } }


static int cinvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; CinVideoContext *cin = avctx->priv_data; int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size, res = 0; palette_type = buf[0]; palette_colors_count = AV_RL16(buf+1); bitmap_frame_type = buf[3]; buf += 4; bitmap_frame_size = buf_size - 4; /* handle palette */ if (bitmap_frame_size < palette_colors_count * (3 + (palette_type != 0))) return AVERROR_INVALIDDATA; if (palette_type == 0) { if (palette_colors_count > 256) return AVERROR_INVALIDDATA; for (i = 0; i < palette_colors_count; ++i) { cin->palette[i] = 0xFFU << 24 | bytestream_get_le24(&buf); bitmap_frame_size -= 3; } } else { for (i = 0; i < palette_colors_count; ++i) { cin->palette[buf[0]] = 0xFFU << 24 | AV_RL24(buf+1); buf += 4; bitmap_frame_size -= 4; } } /* note: the decoding routines below assumes that surface.width = surface.pitch */ switch (bitmap_frame_type) { case 9: cin_decode_rle(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 34: cin_decode_rle(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 35: cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 36: bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 37: cin_decode_huffman(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 38: res = cin_decode_lzss(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); if (res < 0) return res; break; case 39: res = cin_decode_lzss(buf, bitmap_frame_size, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); if (res < 0) return res; cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; } cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if ((res = avctx->reget_buffer(avctx, &cin->frame))) { av_log(cin->avctx, AV_LOG_ERROR, "failed to allocate a frame\n"); return res; } memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette)); cin->frame.palette_has_changed = 1; for (y = 0; y < cin->avctx->height; ++y) memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0], cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width, cin->avctx->width); FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]); *data_size = sizeof(AVFrame); *(AVFrame *)data = cin->frame; return buf_size; }


static void check_threshold_8(void){ LOCAL_ALIGNED_32(uint8_t, in , [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, threshold, [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, min , [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, max , [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, out_ref , [WIDTH_PADDED]); LOCAL_ALIGNED_32(uint8_t, out_new , [WIDTH_PADDED]); ptrdiff_t line_size = WIDTH_PADDED; int w = WIDTH; ThresholdContext s; s.depth = 8; ff_threshold_init(&s); declare_func(void, const uint8_t *in, const uint8_t *threshold, const uint8_t *min, const uint8_t *max, uint8_t *out, ptrdiff_t ilinesize, ptrdiff_t tlinesize, ptrdiff_t flinesize, ptrdiff_t slinesize, ptrdiff_t olinesize, int w, int h); memset(in, 0, WIDTH_PADDED); memset(threshold, 0, WIDTH_PADDED); memset(min, 0, WIDTH_PADDED); memset(max, 0, WIDTH_PADDED); memset(out_ref, 0, WIDTH_PADDED); memset(out_new, 0, WIDTH_PADDED); randomize_buffers(in, WIDTH); randomize_buffers(threshold, WIDTH); randomize_buffers(min, WIDTH); randomize_buffers(max, WIDTH); if (check_func(s.threshold, "threshold8")) { call_ref(in, threshold, min, max, out_ref, line_size, line_size, line_size, line_size, line_size, w, 1); call_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1); if (memcmp(out_ref, out_new, w)) fail(); bench_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1); } }


static void gen_rp_realize(DeviceState *dev, Error **errp) { PCIDevice *d = PCI_DEVICE(dev); GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d); PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d); rpc->parent_realize(dev, errp); int rc = pci_bridge_qemu_reserve_cap_init(d, 0, grp->bus_reserve, grp->io_reserve, grp->mem_reserve, grp->pref32_reserve, grp->pref64_reserve, errp); if (rc < 0) { rpc->parent_class.exit(d); return; } if (!grp->io_reserve) { pci_word_test_and_clear_mask(d->wmask + PCI_COMMAND, PCI_COMMAND_IO); d->wmask[PCI_IO_BASE] = 0; d->wmask[PCI_IO_LIMIT] = 0; } }


static bool megasas_use_msi(MegasasState *s) { return s->msi != ON_OFF_AUTO_OFF; }


int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) { int64_t nb_sectors; uint32_t lba; uint32_t len; int cmdlen; int is_write; s->command = buf[0]; s->tag = tag; s->sector_count = 0; s->buf_pos = 0; s->buf_len = 0; is_write = 0; DPRINTF("Command: 0x%02x", buf[0]); switch (s->command >> 5) { case 0: lba = buf[3] | (buf[2] << 8) | ((buf[1] & 0x1f) << 16); len = buf[4]; cmdlen = 6; break; case 1: case 2: lba = buf[5] | (buf[4] << 8) | (buf[3] << 16) | (buf[2] << 24); len = buf[8] | (buf[7] << 8); cmdlen = 10; break; case 4: lba = buf[5] | (buf[4] << 8) | (buf[3] << 16) | (buf[2] << 24); len = buf[13] | (buf[12] << 8) | (buf[11] << 16) | (buf[10] << 24); cmdlen = 16; break; case 5: lba = buf[5] | (buf[4] << 8) | (buf[3] << 16) | (buf[2] << 24); len = buf[9] | (buf[8] << 8) | (buf[7] << 16) | (buf[6] << 24); cmdlen = 12; break; default: BADF("Unsupported command length, command %x\n", s->command); goto fail; } #ifdef DEBUG_SCSI { int i; for (i = 1; i < cmdlen; i++) { printf(" 0x%02x", buf[i]); } printf("\n"); } #endif if (lun || buf[1] >> 5) { /* Only LUN 0 supported. */ DPRINTF("Unimplemented LUN %d\n", lun ? lun : buf[1] >> 5); goto fail; } switch (s->command) { case 0x0: DPRINTF("Test Unit Ready\n"); break; case 0x03: DPRINTF("Request Sense (len %d)\n", len); if (len < 4) goto fail; memset(buf, 0, 4); s->buf[0] = 0xf0; s->buf[1] = 0; s->buf[2] = s->sense; s->buf_len = 4; break; case 0x12: DPRINTF("Inquiry (len %d)\n", len); if (len < 36) { BADF("Inquiry buffer too small (%d)\n", len); } memset(s->buf, 0, 36); if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { s->buf[0] = 5; s->buf[1] = 0x80; memcpy(&s->buf[16], "QEMU CD-ROM ", 16); } else { s->buf[0] = 0; memcpy(&s->buf[16], "QEMU HARDDISK ", 16); } memcpy(&s->buf[8], "QEMU ", 8); memcpy(&s->buf[32], QEMU_VERSION, 4); /* Identify device as SCSI-3 rev 1. Some later commands are also implemented. */ s->buf[2] = 3; s->buf[3] = 2; /* Format 2 */ s->buf[4] = 32; s->buf_len = 36; break; case 0x16: DPRINTF("Reserve(6)\n"); if (buf[1] & 1) goto fail; break; case 0x17: DPRINTF("Release(6)\n"); if (buf[1] & 1) goto fail; break; case 0x1a: case 0x5a: { char *p; int page; page = buf[2] & 0x3f; DPRINTF("Mode Sense (page %d, len %d)\n", page, len); p = s->buf; memset(p, 0, 4); s->buf[1] = 0; /* Default media type. */ s->buf[3] = 0; /* Block descriptor length. */ if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) { s->buf[2] = 0x80; /* Readonly. */ } p += 4; if ((page == 8 || page == 0x3f)) { /* Caching page. */ p[0] = 8; p[1] = 0x12; p[2] = 4; /* WCE */ p += 19; } if ((page == 0x3f || page == 0x2a) && (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM)) { /* CD Capabilities and Mechanical Status page. */ p[0] = 0x2a; p[1] = 0x14; p[2] = 3; // CD-R & CD-RW read p[3] = 0; // Writing not supported p[4] = 0x7f; /* Audio, composite, digital out, mode 2 form 1&2, multi session */ p[5] = 0xff; /* CD DA, DA accurate, RW supported, RW corrected, C2 errors, ISRC, UPC, Bar code */ p[6] = 0x2d | (bdrv_is_locked(s->bdrv)? 2 : 0); /* Locking supported, jumper present, eject, tray */ p[7] = 0; /* no volume & mute control, no changer */ p[8] = (50 * 176) >> 8; // 50x read speed p[9] = (50 * 176) & 0xff; p[10] = 0 >> 8; // No volume p[11] = 0 & 0xff; p[12] = 2048 >> 8; // 2M buffer p[13] = 2048 & 0xff; p[14] = (16 * 176) >> 8; // 16x read speed current p[15] = (16 * 176) & 0xff; p[18] = (16 * 176) >> 8; // 16x write speed p[19] = (16 * 176) & 0xff; p[20] = (16 * 176) >> 8; // 16x write speed current p[21] = (16 * 176) & 0xff; p += 21; } s->buf_len = p - s->buf; s->buf[0] = s->buf_len - 4; if (s->buf_len > len) s->buf_len = len; } break; case 0x1b: DPRINTF("Start Stop Unit\n"); break; case 0x1e: DPRINTF("Prevent Allow Medium Removal (prevent = %d)\n", buf[4] & 3); bdrv_set_locked(s->bdrv, buf[4] & 1); break; case 0x25: DPRINTF("Read Capacity\n"); /* The normal LEN field for this command is zero. */ memset(s->buf, 0, 8); bdrv_get_geometry(s->bdrv, &nb_sectors); s->buf[0] = (nb_sectors >> 24) & 0xff; s->buf[1] = (nb_sectors >> 16) & 0xff; s->buf[2] = (nb_sectors >> 8) & 0xff; s->buf[3] = nb_sectors & 0xff; s->buf[4] = 0; s->buf[5] = 0; s->buf[6] = s->cluster_size * 2; s->buf[7] = 0; s->buf_len = 8; break; case 0x08: case 0x28: DPRINTF("Read (sector %d, count %d)\n", lba, len); s->sector = lba * s->cluster_size; s->sector_count = len * s->cluster_size; break; case 0x0a: case 0x2a: DPRINTF("Write (sector %d, count %d)\n", lba, len); s->sector = lba * s->cluster_size; s->sector_count = len * s->cluster_size; is_write = 1; break; case 0x35: DPRINTF("Syncronise cache (sector %d, count %d)\n", lba, len); bdrv_flush(s->bdrv); break; case 0x43: { int start_track, format, msf, toclen; msf = buf[1] & 2; format = buf[2] & 0xf; start_track = buf[6]; bdrv_get_geometry(s->bdrv, &nb_sectors); DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1); switch(format) { case 0: toclen = cdrom_read_toc(nb_sectors, s->buf, msf, start_track); break; case 1: /* multi session : only a single session defined */ toclen = 12; memset(s->buf, 0, 12); s->buf[1] = 0x0a; s->buf[2] = 0x01; s->buf[3] = 0x01; break; case 2: toclen = cdrom_read_toc_raw(nb_sectors, s->buf, msf, start_track); break; default: goto error_cmd; } if (toclen > 0) { if (len > toclen) len = toclen; s->buf_len = len; break; } error_cmd: DPRINTF("Read TOC error\n"); goto fail; } case 0x46: DPRINTF("Get Configuration (rt %d, maxlen %d)\n", buf[1] & 3, len); memset(s->buf, 0, 8); /* ??? This shoud probably return much more information. For now just return the basic header indicating the CD-ROM profile. */ s->buf[7] = 8; // CD-ROM s->buf_len = 8; break; case 0x56: DPRINTF("Reserve(10)\n"); if (buf[1] & 3) goto fail; break; case 0x57: DPRINTF("Release(10)\n"); if (buf[1] & 3) goto fail; break; case 0xa0: DPRINTF("Report LUNs (len %d)\n", len); if (len < 16) goto fail; memset(s->buf, 0, 16); s->buf[3] = 8; s->buf_len = 16; break; default: DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]); fail: scsi_command_complete(s, SENSE_ILLEGAL_REQUEST); return 0; } if (s->sector_count == 0 && s->buf_len == 0) { scsi_command_complete(s, SENSE_NO_SENSE); } len = s->sector_count * 512 + s->buf_len; return is_write ? -len : len; }


static int vda_h264_uninit(AVCodecContext *avctx) { VDAContext *vda = avctx->internal->hwaccel_priv_data; av_freep(&vda->bitstream); if (vda->frame) CVPixelBufferRelease(vda->frame); return 0; }


static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) { MTPState *s = USB_MTP(dev); MTPControl cmd; mtp_container container; uint32_t params[5]; int i, rc; switch (p->ep->nr) { case EP_DATA_IN: if (s->data_out != NULL) { /* guest bug */ trace_usb_mtp_stall(s->dev.addr, "awaiting data-out"); p->status = USB_RET_STALL; return; } if (p->iov.size < sizeof(container)) { trace_usb_mtp_stall(s->dev.addr, "packet too small"); p->status = USB_RET_STALL; return; } if (s->data_in != NULL) { MTPData *d = s->data_in; int dlen = d->length - d->offset; if (d->first) { trace_usb_mtp_data_in(s->dev.addr, d->trans, d->length); container.length = cpu_to_le32(d->length + sizeof(container)); container.type = cpu_to_le16(TYPE_DATA); container.code = cpu_to_le16(d->code); container.trans = cpu_to_le32(d->trans); usb_packet_copy(p, &container, sizeof(container)); d->first = false; if (dlen > p->iov.size - sizeof(container)) { dlen = p->iov.size - sizeof(container); } } else { if (dlen > p->iov.size) { dlen = p->iov.size; } } if (d->fd == -1) { usb_packet_copy(p, d->data + d->offset, dlen); } else { if (d->alloc < p->iov.size) { d->alloc = p->iov.size; d->data = g_realloc(d->data, d->alloc); } rc = read(d->fd, d->data, dlen); if (rc != dlen) { memset(d->data, 0, dlen); s->result->code = RES_INCOMPLETE_TRANSFER; } usb_packet_copy(p, d->data, dlen); } d->offset += dlen; if (d->offset == d->length) { usb_mtp_data_free(s->data_in); s->data_in = NULL; } } else if (s->result != NULL) { MTPControl *r = s->result; int length = sizeof(container) + r->argc * sizeof(uint32_t); if (r->code == RES_OK) { trace_usb_mtp_success(s->dev.addr, r->trans, (r->argc > 0) ? r->argv[0] : 0, (r->argc > 1) ? r->argv[1] : 0); } else { trace_usb_mtp_error(s->dev.addr, r->code, r->trans, (r->argc > 0) ? r->argv[0] : 0, (r->argc > 1) ? r->argv[1] : 0); } container.length = cpu_to_le32(length); container.type = cpu_to_le16(TYPE_RESPONSE); container.code = cpu_to_le16(r->code); container.trans = cpu_to_le32(r->trans); for (i = 0; i < r->argc; i++) { params[i] = cpu_to_le32(r->argv[i]); } usb_packet_copy(p, &container, sizeof(container)); usb_packet_copy(p, &params, length - sizeof(container)); g_free(s->result); s->result = NULL; } break; case EP_DATA_OUT: if (p->iov.size < sizeof(container)) { trace_usb_mtp_stall(s->dev.addr, "packet too small"); p->status = USB_RET_STALL; return; } usb_packet_copy(p, &container, sizeof(container)); switch (le16_to_cpu(container.type)) { case TYPE_COMMAND: if (s->data_in || s->data_out || s->result) { trace_usb_mtp_stall(s->dev.addr, "transaction inflight"); p->status = USB_RET_STALL; return; } cmd.code = le16_to_cpu(container.code); cmd.argc = (le32_to_cpu(container.length) - sizeof(container)) / sizeof(uint32_t); cmd.trans = le32_to_cpu(container.trans); if (cmd.argc > ARRAY_SIZE(cmd.argv)) { cmd.argc = ARRAY_SIZE(cmd.argv); } if (p->iov.size < sizeof(container) + cmd.argc * sizeof(uint32_t)) { trace_usb_mtp_stall(s->dev.addr, "packet too small"); p->status = USB_RET_STALL; return; } usb_packet_copy(p, &params, cmd.argc * sizeof(uint32_t)); for (i = 0; i < cmd.argc; i++) { cmd.argv[i] = le32_to_cpu(params[i]); } trace_usb_mtp_command(s->dev.addr, cmd.code, cmd.trans, (cmd.argc > 0) ? cmd.argv[0] : 0, (cmd.argc > 1) ? cmd.argv[1] : 0, (cmd.argc > 2) ? cmd.argv[2] : 0, (cmd.argc > 3) ? cmd.argv[3] : 0, (cmd.argc > 4) ? cmd.argv[4] : 0); usb_mtp_command(s, &cmd); break; default: /* not needed as long as the mtp device is read-only */ p->status = USB_RET_STALL; return; } break; case EP_EVENT: #ifdef __linux__ if (!QTAILQ_EMPTY(&s->events)) { struct MTPMonEntry *e = QTAILQ_LAST(&s->events, events); uint32_t handle; int len = sizeof(container) + sizeof(uint32_t); if (p->iov.size < len) { trace_usb_mtp_stall(s->dev.addr, "packet too small to send event"); p->status = USB_RET_STALL; return; } QTAILQ_REMOVE(&s->events, e, next); container.length = cpu_to_le32(len); container.type = cpu_to_le32(TYPE_EVENT); container.code = cpu_to_le16(e->event); container.trans = 0; /* no trans specific events */ handle = cpu_to_le32(e->handle); usb_packet_copy(p, &container, sizeof(container)); usb_packet_copy(p, &handle, sizeof(uint32_t)); g_free(e); return; } #endif p->status = USB_RET_NAK; return; default: trace_usb_mtp_stall(s->dev.addr, "invalid endpoint"); p->status = USB_RET_STALL; return; } if (p->actual_length == 0) { trace_usb_mtp_nak(s->dev.addr, p->ep->nr); p->status = USB_RET_NAK; return; } else { trace_usb_mtp_xfer(s->dev.addr, p->ep->nr, p->actual_length, p->iov.size); return; } }


ReadLineState *readline_init(ReadLinePrintfFunc *printf_func, ReadLineFlushFunc *flush_func, void *opaque, ReadLineCompletionFunc *completion_finder) { ReadLineState *rs = g_malloc0(sizeof(*rs)); rs->hist_entry = -1; rs->opaque = opaque; rs->printf_func = printf_func; rs->flush_func = flush_func; rs->completion_finder = completion_finder; return rs; }


static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int32_t offset) { AHCICmdHdr *cmd = ad->cur_cmd; uint16_t opts = le16_to_cpu(cmd->opts); uint16_t prdtl = le16_to_cpu(cmd->prdtl); uint64_t cfis_addr = le64_to_cpu(cmd->tbl_addr); uint64_t prdt_addr = cfis_addr + 0x80; dma_addr_t prdt_len = (prdtl * sizeof(AHCI_SG)); dma_addr_t real_prdt_len = prdt_len; uint8_t *prdt; int i; int r = 0; uint64_t sum = 0; int off_idx = -1; int64_t off_pos = -1; int tbl_entry_size; IDEBus *bus = &ad->port; BusState *qbus = BUS(bus); /* * Note: AHCI PRDT can describe up to 256GiB. SATA/ATA only support * transactions of up to 32MiB as of ATA8-ACS3 rev 1b, assuming a * 512 byte sector size. We limit the PRDT in this implementation to * a reasonably large 2GiB, which can accommodate the maximum transfer * request for sector sizes up to 32K. */ if (!prdtl) { DPRINTF(ad->port_no, "no sg list given by guest: 0x%08x\n", opts); return -1; } /* map PRDT */ if (!(prdt = dma_memory_map(ad->hba->as, prdt_addr, &prdt_len, DMA_DIRECTION_TO_DEVICE))){ DPRINTF(ad->port_no, "map failed\n"); return -1; } if (prdt_len < real_prdt_len) { DPRINTF(ad->port_no, "mapped less than expected\n"); r = -1; goto out; } /* Get entries in the PRDT, init a qemu sglist accordingly */ if (prdtl > 0) { AHCI_SG *tbl = (AHCI_SG *)prdt; sum = 0; for (i = 0; i < prdtl; i++) { /* flags_size is zero-based */ tbl_entry_size = prdt_tbl_entry_size(&tbl[i]); if (offset <= (sum + tbl_entry_size)) { off_idx = i; off_pos = offset - sum; break; } sum += tbl_entry_size; } if ((off_idx == -1) || (off_pos < 0) || (off_pos > tbl_entry_size)) { DPRINTF(ad->port_no, "%s: Incorrect offset! " "off_idx: %d, off_pos: %"PRId64"\n", __func__, off_idx, off_pos); r = -1; goto out; } qemu_sglist_init(sglist, qbus->parent, (prdtl - off_idx), ad->hba->as); qemu_sglist_add(sglist, le64_to_cpu(tbl[off_idx].addr) + off_pos, prdt_tbl_entry_size(&tbl[off_idx]) - off_pos); for (i = off_idx + 1; i < prdtl; i++) { /* flags_size is zero-based */ qemu_sglist_add(sglist, le64_to_cpu(tbl[i].addr), prdt_tbl_entry_size(&tbl[i])); if (sglist->size > INT32_MAX) { error_report("AHCI Physical Region Descriptor Table describes " "more than 2 GiB.\n"); qemu_sglist_destroy(sglist); r = -1; goto out; } } } out: dma_memory_unmap(ad->hba->as, prdt, prdt_len, DMA_DIRECTION_TO_DEVICE, prdt_len); return r; }


static void simple_varargs(void) { QObject *embedded_obj; QObject *obj; LiteralQObject decoded = QLIT_QLIST(((LiteralQObject[]){ QLIT_QINT(1), QLIT_QINT(2), QLIT_QLIST(((LiteralQObject[]){ QLIT_QINT(32), QLIT_QINT(42), {}})), {}})); embedded_obj = qobject_from_json("[32, 42]", NULL); g_assert(embedded_obj != NULL); obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj); g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1); qobject_decref(obj); }


static ram_addr_t ram_block_add(RAMBlock *new_block, Error **errp) { RAMBlock *block; RAMBlock *last_block = NULL; ram_addr_t old_ram_size, new_ram_size; old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; qemu_mutex_lock_ramlist(); new_block->offset = find_ram_offset(new_block->max_length); if (!new_block->host) { if (xen_enabled()) { xen_ram_alloc(new_block->offset, new_block->max_length, new_block->mr); } else { new_block->host = phys_mem_alloc(new_block->max_length, &new_block->mr->align); if (!new_block->host) { error_setg_errno(errp, errno, "cannot set up guest memory '%s'", memory_region_name(new_block->mr)); qemu_mutex_unlock_ramlist(); return -1; memory_try_enable_merging(new_block->host, new_block->max_length); /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ, * QLIST (which has an RCU-friendly variant) does not have insertion at * tail, so save the last element in last_block. */ QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { last_block = block; if (block->max_length < new_block->max_length) { break; if (block) { QLIST_INSERT_BEFORE_RCU(block, new_block, next); } else if (last_block) { QLIST_INSERT_AFTER_RCU(last_block, new_block, next); } else { /* list is empty */ QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next); ram_list.mru_block = NULL; /* Write list before version */ smp_wmb(); ram_list.version++; qemu_mutex_unlock_ramlist(); new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; int i; /* ram_list.dirty_memory[] is protected by the iothread lock. */ for (i = 0; i < DIRTY_MEMORY_NUM; i++) { ram_list.dirty_memory[i] = bitmap_zero_extend(ram_list.dirty_memory[i], old_ram_size, new_ram_size); cpu_physical_memory_set_dirty_range(new_block->offset, new_block->used_length, DIRTY_CLIENTS_ALL); if (new_block->host) { qemu_ram_setup_dump(new_block->host, new_block->max_length); qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_HUGEPAGE); qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_DONTFORK); if (kvm_enabled()) { kvm_setup_guest_memory(new_block->host, new_block->max_length); return new_block->offset;


void qemu_set_log(int log_flags, bool use_own_buffers) { qemu_loglevel = log_flags; if (qemu_loglevel && !qemu_logfile) { qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); if (!qemu_logfile) { perror(logfilename); _exit(1); } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ if (use_own_buffers) { static char logfile_buf[4096]; setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); } else { #if defined(_WIN32) /* Win32 doesn't support line-buffering, so use unbuffered output. */ setvbuf(qemu_logfile, NULL, _IONBF, 0); #else setvbuf(qemu_logfile, NULL, _IOLBF, 0); #endif log_append = 1; } } if (!qemu_loglevel && qemu_logfile) { fclose(qemu_logfile); qemu_logfile = NULL; } }


static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom) { const uint32_t ddts_size = 20; AVStream *st = NULL; uint8_t *buf = NULL; uint32_t frame_duration_code = 0; uint32_t channel_layout_code = 0; GetBitContext gb; buf = av_malloc(ddts_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!buf) { return AVERROR(ENOMEM); } if (avio_read(pb, buf, ddts_size) < ddts_size) { return AVERROR_INVALIDDATA; } init_get_bits(&gb, buf, 8*ddts_size); if (c->fc->nb_streams < 1) { return 0; } st = c->fc->streams[c->fc->nb_streams-1]; st->codecpar->sample_rate = get_bits_long(&gb, 32); if (st->codecpar->sample_rate <= 0) { av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate); return AVERROR_INVALIDDATA; } skip_bits_long(&gb, 32); /* max bitrate */ st->codecpar->bit_rate = get_bits_long(&gb, 32); st->codecpar->bits_per_coded_sample = get_bits(&gb, 8); frame_duration_code = get_bits(&gb, 2); skip_bits(&gb, 30); /* various fields */ channel_layout_code = get_bits(&gb, 16); st->codecpar->frame_size = (frame_duration_code == 0) ? 512 : (frame_duration_code == 1) ? 1024 : (frame_duration_code == 2) ? 2048 : (frame_duration_code == 3) ? 4096 : 0; if (channel_layout_code > 0xff) { av_log(c->fc, AV_LOG_WARNING, "Unsupported DTS audio channel layout"); } st->codecpar->channel_layout = ((channel_layout_code & 0x1) ? AV_CH_FRONT_CENTER : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_LEFT : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_RIGHT : 0) | ((channel_layout_code & 0x4) ? AV_CH_SIDE_LEFT : 0) | ((channel_layout_code & 0x4) ? AV_CH_SIDE_RIGHT : 0) | ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0); st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); return 0; }


void OPPROTO op_check_subfo_64 (void) { if (likely(!(((uint64_t)(~T2) ^ (uint64_t)T1 ^ UINT64_MAX) & ((uint64_t)(~T2) ^ (uint64_t)T0) & (1ULL << 63)))) { xer_ov = 0; } else { xer_ov = 1; xer_so = 1; } RETURN(); }


void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len) { PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr); uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); if (!pci_dev) return; PCI_DPRINTF("%s: %s: addr=%02" PRIx32 " val=%08" PRIx32 " len=%d\n", __func__, pci_dev->name, config_addr, val, len); pci_dev->config_write(pci_dev, config_addr, val, len); }


static int mkv_write_tags(AVFormatContext *s) { ebml_master tags = {0}; int i, ret; ff_metadata_conv_ctx(s, ff_mkv_metadata_conv, NULL); if (av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) { ret = mkv_write_tag(s, s->metadata, 0, 0, &tags); if (ret < 0) return ret; } for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (!av_dict_get(st->metadata, "", 0, AV_DICT_IGNORE_SUFFIX)) continue; ret = mkv_write_tag(s, st->metadata, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, &tags); if (ret < 0) return ret; } for (i = 0; i < s->nb_chapters; i++) { AVChapter *ch = s->chapters[i]; if (!av_dict_get(ch->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) continue; ret = mkv_write_tag(s, ch->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id, &tags); if (ret < 0) return ret; } if (tags.pos) end_ebml_master(s->pb, tags); return 0; }


static av_always_inline void mc_chroma_dir(VP9Context *s, vp9_mc_func(*mc)[2], uint8_t *dst_u, uint8_t *dst_v, ptrdiff_t dst_stride, const uint8_t *ref_u, ptrdiff_t src_stride_u, const uint8_t *ref_v, ptrdiff_t src_stride_v, ThreadFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP56mv *mv, int bw, int bh, int w, int h) { int mx = mv->x, my = mv->y; int th; y += my >> 4; x += mx >> 4; ref_u += y * src_stride_u + x; ref_v += y * src_stride_v + x; mx &= 15; my &= 15; // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + bh + 4 * !!my + 7) >> 5; ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); // FIXME bilinear filter only needs 0/1 pixels, not 3/4 if (x < !!mx * 3 || y < !!my * 3 || x + !!mx * 4 > w - bw || y + !!my * 4 > h - bh) { s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ref_u - !!my * 3 * src_stride_u - !!mx * 3, 80, src_stride_u, bw + !!mx * 7, bh + !!my * 7, x - !!mx * 3, y - !!my * 3, w, h); ref_u = s->edge_emu_buffer + !!my * 3 * 80 + !!mx * 3; mc[!!mx][!!my](dst_u, dst_stride, ref_u, 80, bh, mx, my); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ref_v - !!my * 3 * src_stride_v - !!mx * 3, 80, src_stride_v, bw + !!mx * 7, bh + !!my * 7, x - !!mx * 3, y - !!my * 3, w, h); ref_v = s->edge_emu_buffer + !!my * 3 * 80 + !!mx * 3; mc[!!mx][!!my](dst_v, dst_stride, ref_v, 80, bh, mx, my); } else { mc[!!mx][!!my](dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my); mc[!!mx][!!my](dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my); } }


void qmp_drive_mirror(DriveMirror *arg, Error **errp) { BlockDriverState *bs; BlockDriverState *source, *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode; Error *local_err = NULL; QDict *options = NULL; int flags; int64_t size; const char *format = arg->format; bs = qmp_get_root_bs(arg->device, errp); if (!bs) { return; } aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); if (!arg->has_mode) { arg->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; } if (!arg->has_format) { format = (arg->mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name); } flags = bs->open_flags | BDRV_O_RDWR; source = backing_bs(bs); if (!source && arg->sync == MIRROR_SYNC_MODE_TOP) { arg->sync = MIRROR_SYNC_MODE_FULL; } if (arg->sync == MIRROR_SYNC_MODE_NONE) { source = bs; } size = bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); goto out; } if (arg->has_replaces) { BlockDriverState *to_replace_bs; AioContext *replace_aio_context; int64_t replace_size; if (!arg->has_node_name) { error_setg(errp, "a node-name must be provided when replacing a" " named node of the graph"); goto out; } to_replace_bs = check_to_replace_node(bs, arg->replaces, &local_err); if (!to_replace_bs) { error_propagate(errp, local_err); goto out; } replace_aio_context = bdrv_get_aio_context(to_replace_bs); aio_context_acquire(replace_aio_context); replace_size = bdrv_getlength(to_replace_bs); aio_context_release(replace_aio_context); if (size != replace_size) { error_setg(errp, "cannot replace image with a mirror image of " "different size"); goto out; } } if (arg->mode == NEW_IMAGE_MODE_ABSOLUTE_PATHS) { backing_mode = MIRROR_SOURCE_BACKING_CHAIN; } else { backing_mode = MIRROR_OPEN_BACKING_CHAIN; } if ((arg->sync == MIRROR_SYNC_MODE_FULL || !source) && arg->mode != NEW_IMAGE_MODE_EXISTING) { /* create new image w/o backing file */ assert(format); bdrv_img_create(arg->target, format, NULL, NULL, NULL, size, flags, false, &local_err); } else { switch (arg->mode) { case NEW_IMAGE_MODE_EXISTING: break; case NEW_IMAGE_MODE_ABSOLUTE_PATHS: /* create new image with backing file */ bdrv_img_create(arg->target, format, source->filename, source->drv->format_name, NULL, size, flags, false, &local_err); break; default: abort(); } } if (local_err) { error_propagate(errp, local_err); goto out; } options = qdict_new(); if (arg->has_node_name) { qdict_put_str(options, "node-name", arg->node_name); } if (format) { qdict_put_str(options, "driver", format); } /* Mirroring takes care of copy-on-write using the source's backing * file. */ target_bs = bdrv_open(arg->target, NULL, options, flags | BDRV_O_NO_BACKING, errp); if (!target_bs) { goto out; } bdrv_set_aio_context(target_bs, aio_context); blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs, arg->has_replaces, arg->replaces, arg->sync, backing_mode, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size, arg->has_on_source_error, arg->on_source_error, arg->has_on_target_error, arg->on_target_error, arg->has_unmap, arg->unmap, false, NULL, &local_err); bdrv_unref(target_bs); error_propagate(errp, local_err); out: aio_context_release(aio_context); }


void ff_thread_report_progress(ThreadFrame *f, int n, int field) { PerThreadContext *p; atomic_int *progress = f->progress ? (atomic_int*)f->progress->data : NULL; if (!progress || atomic_load_explicit(&progress[field], memory_order_relaxed) >= n) return; p = f->owner[field]->internal->thread_ctx; if (f->owner[field]->debug&FF_DEBUG_THREADS) av_log(f->owner[field], AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); pthread_mutex_lock(&p->progress_mutex); atomic_store_explicit(&progress[field], n, memory_order_release); pthread_cond_broadcast(&p->progress_cond); pthread_mutex_unlock(&p->progress_mutex); }


static inline int64_t bs_get_v(const uint8_t **bs) { int64_t v = 0; int br = 0; int c; do { c = **bs; (*bs)++; v <<= 7; v |= c & 0x7F; br++; if (br > 10) return -1; } while (c & 0x80); return v - br; }


static int nbd_receive_request(int csock, struct nbd_request *request) { uint8_t buf[4 + 4 + 8 + 8 + 4]; uint32_t magic; if (read_sync(csock, buf, sizeof(buf)) != sizeof(buf)) { LOG("read failed"); errno = EINVAL; return -1; } /* Request [ 0 .. 3] magic (NBD_REQUEST_MAGIC) [ 4 .. 7] type (0 == READ, 1 == WRITE) [ 8 .. 15] handle [16 .. 23] from [24 .. 27] len */ magic = be32_to_cpup((uint32_t*)buf); request->type = be32_to_cpup((uint32_t*)(buf + 4)); request->handle = be64_to_cpup((uint64_t*)(buf + 8)); request->from = be64_to_cpup((uint64_t*)(buf + 16)); request->len = be32_to_cpup((uint32_t*)(buf + 24)); TRACE("Got request: " "{ magic = 0x%x, .type = %d, from = %" PRIu64" , len = %u }", magic, request->type, request->from, request->len); if (magic != NBD_REQUEST_MAGIC) { LOG("invalid magic (got 0x%x)", magic); errno = EINVAL; return -1; } return 0; }


static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size) { VP56RangeCoder *c = &s->c; int parse_filter_info = 0; int coeff_offset = 0; int vrt_shift = 0; int sub_version; int rows, cols; int res = 0; int ret; int separated_coeff = buf[0] & 1; s->frames[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80); ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F); if (s->frames[VP56_FRAME_CURRENT]->key_frame) { sub_version = buf[1] >> 3; if (sub_version > 8) return AVERROR_INVALIDDATA; s->filter_header = buf[1] & 0x06; if (buf[1] & 1) { avpriv_report_missing_feature(s->avctx, "Interlacing"); return AVERROR_PATCHWELCOME; } if (separated_coeff || !s->filter_header) { coeff_offset = AV_RB16(buf+2) - 2; buf += 2; buf_size -= 2; } rows = buf[2]; /* number of stored macroblock rows */ cols = buf[3]; /* number of stored macroblock cols */ /* buf[4] is number of displayed macroblock rows */ /* buf[5] is number of displayed macroblock cols */ if (!rows || !cols) { av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4); return AVERROR_INVALIDDATA; } if (!s->macroblocks || /* first frame */ 16*cols != s->avctx->coded_width || 16*rows != s->avctx->coded_height) { if (s->avctx->extradata_size == 0 && FFALIGN(s->avctx->width, 16) == 16 * cols && FFALIGN(s->avctx->height, 16) == 16 * rows) { // We assume this is properly signalled container cropping, // in an F4V file. Just set the coded_width/height, don't // touch the cropped ones. s->avctx->coded_width = 16 * cols; s->avctx->coded_height = 16 * rows; } else { ret = ff_set_dimensions(s->avctx, 16 * cols, 16 * rows); if (ret < 0) return ret; if (s->avctx->extradata_size == 1) { s->avctx->width -= s->avctx->extradata[0] >> 4; s->avctx->height -= s->avctx->extradata[0] & 0x0F; } } res = VP56_SIZE_CHANGE; } ret = ff_vp56_init_range_decoder(c, buf+6, buf_size-6); if (ret < 0) return ret; vp56_rac_gets(c, 2); parse_filter_info = s->filter_header; if (sub_version < 8) vrt_shift = 5; s->sub_version = sub_version; s->golden_frame = 0; } else { if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height) return AVERROR_INVALIDDATA; if (separated_coeff || !s->filter_header) { coeff_offset = AV_RB16(buf+1) - 2; buf += 2; buf_size -= 2; } ret = ff_vp56_init_range_decoder(c, buf+1, buf_size-1); if (ret < 0) return ret; s->golden_frame = vp56_rac_get(c); if (s->filter_header) { s->deblock_filtering = vp56_rac_get(c); if (s->deblock_filtering) vp56_rac_get(c); if (s->sub_version > 7) parse_filter_info = vp56_rac_get(c); } } if (parse_filter_info) { if (vp56_rac_get(c)) { s->filter_mode = 2; s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift; s->max_vector_length = 2 << vp56_rac_gets(c, 3); } else if (vp56_rac_get(c)) { s->filter_mode = 1; } else { s->filter_mode = 0; } if (s->sub_version > 7) s->filter_selection = vp56_rac_gets(c, 4); else s->filter_selection = 16; } s->use_huffman = vp56_rac_get(c); s->parse_coeff = vp6_parse_coeff; if (coeff_offset) { buf += coeff_offset; buf_size -= coeff_offset; if (buf_size < 0) { if (s->frames[VP56_FRAME_CURRENT]->key_frame) ff_set_dimensions(s->avctx, 0, 0); return AVERROR_INVALIDDATA; } if (s->use_huffman) { s->parse_coeff = vp6_parse_coeff_huffman; init_get_bits(&s->gb, buf, buf_size<<3); } else { ret = ff_vp56_init_range_decoder(&s->cc, buf, buf_size); if (ret < 0) return ret; s->ccp = &s->cc; } } else { s->ccp = &s->c; } return res; }


static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256]) { int i, j, k, m; double l2tab[256]; for (i = 1; i < 256; i++) l2tab[i] = log2(i / 256.0); for (i = 0; i < 256; i++) { double best_len[256]; double p = i / 256.0; for (j = 0; j < 256; j++) best_len[j] = 1 << 30; for (j = FFMAX(i - 10, 1); j < FFMIN(i + 11, 256); j++) { double occ[256] = { 0 }; double len = 0; occ[j] = 1.0; for (k = 0; k < 256; k++) { double newocc[256] = { 0 }; for (m = 1; m < 256; m++) if (occ[m]) { len -= occ[m] * (p * l2tab[m] + (1 - p) * l2tab[256 - m]); } if (len < best_len[k]) { best_len[k] = len; best_state[i][k] = j; } for (m = 0; m < 256; m++) if (occ[m]) { newocc[one_state[m]] += occ[m] * p; newocc[256 - one_state[256 - m]] += occ[m] * (1 - p); } memcpy(occ, newocc, sizeof(occ)); } } } }


static ExitStatus gen_bcond(DisasContext *ctx, TCGCond cond, int ra, int32_t disp, int mask) { TCGv cmp_tmp; if (mask) { cmp_tmp = tcg_temp_new(); tcg_gen_andi_i64(cmp_tmp, load_gpr(ctx, ra), 1); } else { cmp_tmp = load_gpr(ctx, ra); } return gen_bcond_internal(ctx, cond, cmp_tmp, disp); }