int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) { const CodecMime *mime = ff_id3v2_mime_tags; enum AVCodecID id = AV_CODEC_ID_NONE; AVBufferRef *data = NULL; uint8_t mimetype[64], *desc = NULL; AVIOContext *pb = NULL; AVStream *st; int type, width, height; int len, ret = 0; pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL); if (!pb) return AVERROR(ENOMEM); /* read the picture type */ type = avio_rb32(pb); if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type); if (s->error_recognition & AV_EF_EXPLODE) { ret = AVERROR_INVALIDDATA; goto fail; } type = 0; } /* picture mimetype */ len = avio_rb32(pb); if (len <= 0 || avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) { av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached " "picture.\n"); if (s->error_recognition & AV_EF_EXPLODE) ret = AVERROR_INVALIDDATA; goto fail; } mimetype[len] = 0; while (mime->id != AV_CODEC_ID_NONE) { if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { id = mime->id; break; } mime++; } if (id == AV_CODEC_ID_NONE) { av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", mimetype); if (s->error_recognition & AV_EF_EXPLODE) ret = AVERROR_INVALIDDATA; goto fail; } /* picture description */ len = avio_rb32(pb); if (len > 0) { if (!(desc = av_malloc(len + 1))) { ret = AVERROR(ENOMEM); goto fail; } if (avio_read(pb, desc, len) != len) { av_log(s, AV_LOG_ERROR, "Error reading attached picture description.\n"); if (s->error_recognition & AV_EF_EXPLODE) ret = AVERROR(EIO); goto fail; } desc[len] = 0; } /* picture metadata */ width = avio_rb32(pb); height = avio_rb32(pb); avio_skip(pb, 8); /* picture data */ len = avio_rb32(pb); if (len <= 0) { av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len); if (s->error_recognition & AV_EF_EXPLODE) ret = AVERROR_INVALIDDATA; goto fail; } if (!(data = av_buffer_alloc(len))) { ret = AVERROR(ENOMEM); goto fail; } if (avio_read(pb, data->data, len) != len) { av_log(s, AV_LOG_ERROR, "Error reading attached picture data.\n"); if (s->error_recognition & AV_EF_EXPLODE) ret = AVERROR(EIO); goto fail; } st = avformat_new_stream(s, NULL); if (!st) { ret = AVERROR(ENOMEM); goto fail; } av_init_packet(&st->attached_pic); st->attached_pic.buf = data; st->attached_pic.data = data->data; st->attached_pic.size = len; st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; st->disposition |= AV_DISPOSITION_ATTACHED_PIC; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = id; st->codec->width = width; st->codec->height = height; av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0); if (desc) av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); av_freep(&pb); return 0; fail: av_buffer_unref(&data); av_freep(&desc); av_freep(&pb); return ret; }


int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) { int sample_rate, frame_size, mpeg25, padding; int sample_rate_index, bitrate_index; if (header & (1<<20)) { s->lsf = (header & (1<<19)) ? 0 : 1; mpeg25 = 0; } else { s->lsf = 1; mpeg25 = 1; } s->layer = 4 - ((header >> 17) & 3); /* extract frequency */ sample_rate_index = (header >> 10) & 3; sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); sample_rate_index += 3 * (s->lsf + mpeg25); s->sample_rate_index = sample_rate_index; s->error_protection = ((header >> 16) & 1) ^ 1; s->sample_rate = sample_rate; bitrate_index = (header >> 12) & 0xf; padding = (header >> 9) & 1; //extension = (header >> 8) & 1; s->mode = (header >> 6) & 3; s->mode_ext = (header >> 4) & 3; //copyright = (header >> 3) & 1; //original = (header >> 2) & 1; //emphasis = header & 3; if (s->mode == MPA_MONO) s->nb_channels = 1; else s->nb_channels = 2; if (bitrate_index != 0) { frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; s->bit_rate = frame_size * 1000; switch(s->layer) { case 1: frame_size = (frame_size * 12000) / sample_rate; frame_size = (frame_size + padding) * 4; break; case 2: frame_size = (frame_size * 144000) / sample_rate; frame_size += padding; break; default: case 3: frame_size = (frame_size * 144000) / (sample_rate << s->lsf); frame_size += padding; break; } s->frame_size = frame_size; } else { /* if no frame size computed, signal it */ return 1; } #if defined(DEBUG) av_dlog(NULL, "layer%d, %d Hz, %d kbits/s, ", s->layer, s->sample_rate, s->bit_rate); if (s->nb_channels == 2) { if (s->layer == 3) { if (s->mode_ext & MODE_EXT_MS_STEREO) av_dlog(NULL, "ms-"); if (s->mode_ext & MODE_EXT_I_STEREO) av_dlog(NULL, "i-"); } av_dlog(NULL, "stereo"); } else { av_dlog(NULL, "mono"); } av_dlog(NULL, "\n"); #endif return 0; }


static int vhost_set_vring(struct vhost_dev *dev, unsigned long int request, struct vhost_vring_state *ring) { VhostUserMsg msg = { .request = request, .flags = VHOST_USER_VERSION, .state = *ring, .size = sizeof(*ring), }; vhost_user_write(dev, &msg, NULL, 0); return 0; }


static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { MpegEncContext * const s = avctx->priv_data; MJpegContext * const m = s->mjpeg_ctx; const int width= s->width; const int height= s->height; AVFrame * const p = &s->current_picture.f; const int predictor= avctx->prediction_method+1; const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0]; const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0]; int ret, max_pkt_size = FF_MIN_BUFFER_SIZE; if (avctx->pix_fmt == AV_PIX_FMT_BGRA) max_pkt_size += width * height * 3 * 4; else { max_pkt_size += mb_width * mb_height * 3 * 4 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]; if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size)) < 0) init_put_bits(&s->pb, pkt->data, pkt->size); *p = *pict; p->pict_type= AV_PICTURE_TYPE_I; p->key_frame= 1; ff_mjpeg_encode_picture_header(s); s->header_bits= put_bits_count(&s->pb); if(avctx->pix_fmt == AV_PIX_FMT_BGR0 || avctx->pix_fmt == AV_PIX_FMT_BGRA || avctx->pix_fmt == AV_PIX_FMT_BGR24){ int x, y, i; const int linesize= p->linesize[0]; uint16_t (*buffer)[4]= (void *) s->rd_scratchpad; int left[3], top[3], topleft[3]; for(i=0; i<3; i++){ buffer[0][i]= 1 << (9 - 1); for(y = 0; y < height; y++) { const int modified_predictor= y ? predictor : 1; uint8_t *ptr = p->data[0] + (linesize * y); if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; for(i=0; i<3; i++){ top[i]= left[i]= topleft[i]= buffer[0][i]; for(x = 0; x < width; x++) { if(avctx->pix_fmt == AV_PIX_FMT_BGR24){ buffer[x][1] = ptr[3*x+0] - ptr[3*x+1] + 0x100; buffer[x][2] = ptr[3*x+2] - ptr[3*x+1] + 0x100; buffer[x][0] = (ptr[3*x+0] + 2*ptr[3*x+1] + ptr[3*x+2])>>2; }else{ buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100; buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100; buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2; for(i=0;i<3;i++) { int pred, diff; PREDICT(pred, topleft[i], top[i], left[i], modified_predictor); topleft[i]= top[i]; top[i]= buffer[x+1][i]; left[i]= buffer[x][i]; diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100; if(i==0) ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly else ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); }else{ int mb_x, mb_y, i; for(mb_y = 0; mb_y < mb_height; mb_y++) { if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; for(mb_x = 0; mb_x < mb_width; mb_x++) { if(mb_x==0 || mb_y==0){ for(i=0;i<3;i++) { uint8_t *ptr; int x, y, h, v, linesize; h = s->mjpeg_hsample[i]; v = s->mjpeg_vsample[i]; linesize= p->linesize[i]; for(y=0; y<v; y++){ for(x=0; x<h; x++){ int pred; ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap if(y==0 && mb_y==0){ if(x==0 && mb_x==0){ pred= 128; }else{ pred= ptr[-1]; }else{ if(x==0 && mb_x==0){ pred= ptr[-linesize]; }else{ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); if(i==0) ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly else ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); }else{ for(i=0;i<3;i++) { uint8_t *ptr; int x, y, h, v, linesize; h = s->mjpeg_hsample[i]; v = s->mjpeg_vsample[i]; linesize= p->linesize[i]; for(y=0; y<v; y++){ for(x=0; x<h; x++){ int pred; ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); if(i==0) ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly else ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); emms_c(); av_assert0(s->esc_pos == s->header_bits >> 3); ff_mjpeg_encode_stuffing(s); ff_mjpeg_encode_picture_trailer(s); s->picture_number++; flush_put_bits(&s->pb); pkt->size = put_bits_ptr(&s->pb) - s->pb.buf; pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; return 0; // return (put_bits_count(&f->pb)+7)/8;


static void dump_regs(struct ucontext *uc) { }


static void do_wav_capture(Monitor *mon, const QDict *qdict) { const char *path = qdict_get_str(qdict, "path"); int has_freq = qdict_haskey(qdict, "freq"); int freq = qdict_get_try_int(qdict, "freq", -1); int has_bits = qdict_haskey(qdict, "bits"); int bits = qdict_get_try_int(qdict, "bits", -1); int has_channels = qdict_haskey(qdict, "nchannels"); int nchannels = qdict_get_try_int(qdict, "nchannels", -1); CaptureState *s; s = qemu_mallocz (sizeof (*s)); freq = has_freq ? freq : 44100; bits = has_bits ? bits : 16; nchannels = has_channels ? nchannels : 2; if (wav_start_capture (s, path, freq, bits, nchannels)) { monitor_printf(mon, "Faied to add wave capture\n"); qemu_free (s); } LIST_INSERT_HEAD (&capture_head, s, entries); }


static struct mm_struct *vma_init(void) { struct mm_struct *mm; if ((mm = qemu_malloc(sizeof (*mm))) == NULL) return (NULL); mm->mm_count = 0; TAILQ_INIT(&mm->mm_mmap); return (mm); }


CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, CoroutineAction action) { CoroutineWin32 *from = DO_UPCAST(CoroutineWin32, base, from_); CoroutineWin32 *to = DO_UPCAST(CoroutineWin32, base, to_); current = to_; to->action = action; SwitchToFiber(to->fiber); return from->action; }


av_cold void ff_rv34dsp_init_x86(RV34DSPContext* c, DSPContext *dsp) { #if HAVE_YASM int mm_flags = av_get_cpu_flags(); if (mm_flags & AV_CPU_FLAG_MMX) c->rv34_idct_dc_add = ff_rv34_idct_dc_add_mmx; if (mm_flags & AV_CPU_FLAG_MMXEXT) { c->rv34_inv_transform_dc = ff_rv34_idct_dc_noround_mmx2; c->rv34_idct_add = ff_rv34_idct_add_mmx2; } if (mm_flags & AV_CPU_FLAG_SSE4) c->rv34_idct_dc_add = ff_rv34_idct_dc_add_sse4; #endif /* HAVE_YASM */ }


int64_t helper_fqtox(CPUSPARCState *env) { int64_t ret; clear_float_exceptions(env); ret = float128_to_int64_round_to_zero(QT1, &env->fp_status); check_ieee_exceptions(env); return ret; }


static void io_region_add(MemoryListener *listener, MemoryRegionSection *section) { MemoryRegionIORange *mrio = g_new(MemoryRegionIORange, 1); mrio->mr = section->mr; mrio->offset = section->offset_within_region; iorange_init(&mrio->iorange, &memory_region_iorange_ops, section->offset_within_address_space, int128_get64(section->size)); ioport_register(&mrio->iorange); }


build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info) { AcpiTableMcfg *mcfg; const char *sig; int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]); mcfg = acpi_data_push(table_data, len); mcfg->allocation[0].address = cpu_to_le64(info->mcfg_base); /* Only a single allocation so no need to play with segments */ mcfg->allocation[0].pci_segment = cpu_to_le16(0); mcfg->allocation[0].start_bus_number = 0; mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->mcfg_size - 1); /* MCFG is used for ECAM which can be enabled or disabled by guest. * To avoid table size changes (which create migration issues), * always create the table even if there are no allocations, * but set the signature to a reserved value in this case. * ACPI spec requires OSPMs to ignore such tables. */ if (info->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) { /* Reserved signature: ignored by OSPM */ sig = "QEMU"; } else { sig = "MCFG"; } build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL, NULL); }


static void ide_resize_cb(void *opaque) { IDEState *s = opaque; uint64_t nb_sectors; if (!s->identify_set) { return; } bdrv_get_geometry(s->bs, &nb_sectors); s->nb_sectors = nb_sectors; /* Update the identify data buffer. */ if (s->drive_kind == IDE_CFATA) { ide_cfata_identify_size(s); } else { /* IDE_CD uses a different set of callbacks entirely. */ assert(s->drive_kind != IDE_CD); ide_identify_size(s); } }


static void reset_all_temps(int nb_temps) { int i; for (i = 0; i < nb_temps; i++) { temps[i].state = TCG_TEMP_UNDEF; temps[i].mask = -1; } }


static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi, int mem_index, TCGMemOp opc, tcg_insn_unit **label_ptr, int which) { const TCGReg r0 = TCG_REG_L0; const TCGReg r1 = TCG_REG_L1; TCGType ttype = TCG_TYPE_I32; TCGType tlbtype = TCG_TYPE_I32; int trexw = 0, hrexw = 0, tlbrexw = 0; int s_mask = (1 << (opc & MO_SIZE)) - 1; bool aligned = (opc & MO_AMASK) == MO_ALIGN || s_mask == 0; if (TCG_TARGET_REG_BITS == 64) { if (TARGET_LONG_BITS == 64) { ttype = TCG_TYPE_I64; trexw = P_REXW; } if (TCG_TYPE_PTR == TCG_TYPE_I64) { hrexw = P_REXW; if (TARGET_PAGE_BITS + CPU_TLB_BITS > 32) { tlbtype = TCG_TYPE_I64; tlbrexw = P_REXW; } } } tcg_out_mov(s, tlbtype, r0, addrlo); if (aligned) { tcg_out_mov(s, ttype, r1, addrlo); } else { /* For unaligned access check that we don't cross pages using the page address of the last byte. */ tcg_out_modrm_offset(s, OPC_LEA + trexw, r1, addrlo, s_mask); } tcg_out_shifti(s, SHIFT_SHR + tlbrexw, r0, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS); tgen_arithi(s, ARITH_AND + trexw, r1, TARGET_PAGE_MASK | (aligned ? s_mask : 0), 0); tgen_arithi(s, ARITH_AND + tlbrexw, r0, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS, 0); tcg_out_modrm_sib_offset(s, OPC_LEA + hrexw, r0, TCG_AREG0, r0, 0, offsetof(CPUArchState, tlb_table[mem_index][0]) + which); /* cmp 0(r0), r1 */ tcg_out_modrm_offset(s, OPC_CMP_GvEv + trexw, r1, r0, 0); /* Prepare for both the fast path add of the tlb addend, and the slow path function argument setup. There are two cases worth note: For 32-bit guest and x86_64 host, MOVL zero-extends the guest address before the fastpath ADDQ below. For 64-bit guest and x32 host, MOVQ copies the entire guest address for the slow path, while truncation for the 32-bit host happens with the fastpath ADDL below. */ tcg_out_mov(s, ttype, r1, addrlo); /* jne slow_path */ tcg_out_opc(s, OPC_JCC_long + JCC_JNE, 0, 0, 0); label_ptr[0] = s->code_ptr; s->code_ptr += 4; if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) { /* cmp 4(r0), addrhi */ tcg_out_modrm_offset(s, OPC_CMP_GvEv, addrhi, r0, 4); /* jne slow_path */ tcg_out_opc(s, OPC_JCC_long + JCC_JNE, 0, 0, 0); label_ptr[1] = s->code_ptr; s->code_ptr += 4; } /* TLB Hit. */ /* add addend(r0), r1 */ tcg_out_modrm_offset(s, OPC_ADD_GvEv + hrexw, r1, r0, offsetof(CPUTLBEntry, addend) - which); }


uint64_t helper_load_fpcr (void) { uint64_t ret = 0; #ifdef CONFIG_SOFTFLOAT ret |= env->fp_status.float_exception_flags << 52; if (env->fp_status.float_exception_flags) ret |= 1ULL << 63; env->ipr[IPR_EXC_SUM] &= ~0x3E: env->ipr[IPR_EXC_SUM] |= env->fp_status.float_exception_flags << 1; #endif switch (env->fp_status.float_rounding_mode) { case float_round_nearest_even: ret |= 2ULL << 58; break; case float_round_down: ret |= 1ULL << 58; break; case float_round_up: ret |= 3ULL << 58; break; case float_round_to_zero: break; } return ret; }


static void common_end(SnowContext *s){ av_freep(&s->spatial_dwt_buffer); av_freep(&s->mb_band.buf); av_freep(&s->mv_band[0].buf); av_freep(&s->mv_band[1].buf); av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); av_freep(&s->m.me.score_map); av_freep(&s->mb_type); av_freep(&s->mb_mean); av_freep(&s->dummy); av_freep(&s->motion_val8); av_freep(&s->motion_val16); }


static void imx_ccm_write(void *opaque, target_phys_addr_t offset, uint64_t value, unsigned size) { IMXCCMState *s = (IMXCCMState *)opaque; DPRINTF("write(offset=%x, value = %x)\n", offset >> 2, (unsigned int)value); switch (offset >> 2) { case 0: s->ccmr = CCMR_FPMF | (value & 0x3b6fdfff); break; case 1: s->pdr0 = value & 0xff9f3fff; break; case 2: s->pdr1 = value; break; case 4: s->mpctl = value & 0xbfff3fff; break; case 6: s->spctl = value & 0xbfff3fff; break; case 8: s->cgr[0] = value; return; case 9: s->cgr[1] = value; return; case 10: s->cgr[2] = value; return; default: return; } update_clocks(s); }


static void dump_regs(TCGContext *s) { TCGTemp *ts; int i; char buf[64]; for(i = 0; i < s->nb_temps; i++) { ts = &s->temps[i]; printf(" %10s: ", tcg_get_arg_str_idx(s, buf, sizeof(buf), i)); switch(ts->val_type) { case TEMP_VAL_REG: printf("%s", tcg_target_reg_names[ts->reg]); break; case TEMP_VAL_MEM: printf("%d(%s)", (int)ts->mem_offset, tcg_target_reg_names[ts->mem_reg]); break; case TEMP_VAL_CONST: printf("$0x%" TCG_PRIlx, ts->val); break; case TEMP_VAL_DEAD: printf("D"); break; default: printf("???"); break; } printf("\n"); } for(i = 0; i < TCG_TARGET_NB_REGS; i++) { if (s->reg_to_temp[i] >= 0) { printf("%s: %s\n", tcg_target_reg_names[i], tcg_get_arg_str_idx(s, buf, sizeof(buf), s->reg_to_temp[i])); } } }


static int pci_piix3_xen_ide_unplug(DeviceState *dev) { PCIDevice *pci_dev; PCIIDEState *pci_ide; DriveInfo *di; int i = 0; pci_dev = DO_UPCAST(PCIDevice, qdev, dev); pci_ide = DO_UPCAST(PCIIDEState, dev, pci_dev); for (; i < 3; i++) { di = drive_get_by_index(IF_IDE, i); if (di != NULL && di->bdrv != NULL && !di->bdrv->removable) { DeviceState *ds = bdrv_get_attached(di->bdrv); if (ds) { bdrv_detach(di->bdrv, ds); } bdrv_close(di->bdrv); pci_ide->bus[di->bus].ifs[di->unit].bs = NULL; drive_put_ref(di); } } qdev_reset_all(&(pci_ide->dev.qdev)); return 0; }


int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx, target_ulong eaddr, int rw, int type) { hwaddr hash; target_ulong vsid; int pr, target_page_bits; int ret, ret2; pr = msr_pr; ctx->eaddr = eaddr; ppc_slb_t *slb; target_ulong pageaddr; int segment_bits; LOG_MMU("Check SLBs\n"); slb = slb_lookup(env, eaddr); if (!slb) { return -5; } if (slb->vsid & SLB_VSID_B) { vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T; segment_bits = 40; } else { vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT; segment_bits = 28; } target_page_bits = (slb->vsid & SLB_VSID_L) ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS; ctx->key = !!(pr ? (slb->vsid & SLB_VSID_KP) : (slb->vsid & SLB_VSID_KS)); ctx->nx = !!(slb->vsid & SLB_VSID_N); pageaddr = eaddr & ((1ULL << segment_bits) - (1ULL << target_page_bits)); if (slb->vsid & SLB_VSID_B) { hash = vsid ^ (vsid << 25) ^ (pageaddr >> target_page_bits); } else { hash = vsid ^ (pageaddr >> target_page_bits); } /* Only 5 bits of the page index are used in the AVPN */ ctx->ptem = (slb->vsid & SLB_VSID_PTEM) | ((pageaddr >> 16) & ((1ULL << segment_bits) - 0x80)); LOG_MMU("pte segment: key=%d nx %d vsid " TARGET_FMT_lx "\n", ctx->key, ctx->nx, vsid); ret = -1; /* Check if instruction fetch is allowed, if needed */ if (type != ACCESS_CODE || ctx->nx == 0) { /* Page address translation */ LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx " hash " TARGET_FMT_plx "\n", env->htab_base, env->htab_mask, hash); ctx->hash[0] = hash; ctx->hash[1] = ~hash; /* Initialize real address with an invalid value */ ctx->raddr = (hwaddr)-1ULL; LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx " hash=" TARGET_FMT_plx "\n", env->htab_base, env->htab_mask, vsid, ctx->ptem, ctx->hash[0]); /* Primary table lookup */ ret = find_pte64(env, ctx, 0, rw, type, target_page_bits); if (ret < 0) { /* Secondary table lookup */ LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx " hash=" TARGET_FMT_plx "\n", env->htab_base, env->htab_mask, vsid, ctx->ptem, ctx->hash[1]); ret2 = find_pte64(env, ctx, 1, rw, type, target_page_bits); if (ret2 != -1) { ret = ret2; } } } else { LOG_MMU("No access allowed\n"); ret = -3; } return ret; }


static uint64_t cirrus_vga_mem_read(void *opaque, target_phys_addr_t addr, uint32_t size) { CirrusVGAState *s = opaque; unsigned bank_index; unsigned bank_offset; uint32_t val; if ((s->vga.sr[0x07] & 0x01) == 0) { return vga_mem_readb(&s->vga, addr); } if (addr < 0x10000) { /* XXX handle bitblt */ /* video memory */ bank_index = addr >> 15; bank_offset = addr & 0x7fff; if (bank_offset < s->cirrus_bank_limit[bank_index]) { bank_offset += s->cirrus_bank_base[bank_index]; if ((s->vga.gr[0x0B] & 0x14) == 0x14) { bank_offset <<= 4; } else if (s->vga.gr[0x0B] & 0x02) { bank_offset <<= 3; } bank_offset &= s->cirrus_addr_mask; val = *(s->vga.vram_ptr + bank_offset); } else val = 0xff; } else if (addr >= 0x18000 && addr < 0x18100) { /* memory-mapped I/O */ val = 0xff; if ((s->vga.sr[0x17] & 0x44) == 0x04) { val = cirrus_mmio_blt_read(s, addr & 0xff); } } else { val = 0xff; #ifdef DEBUG_CIRRUS printf("cirrus: mem_readb " TARGET_FMT_plx "\n", addr); #endif } return val; }


static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) { XlnxZynqMPState *s = XLNX_ZYNQMP(dev); MemoryRegion *system_memory = get_system_memory(); uint8_t i; uint64_t ram_size; const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]"; ram_addr_t ddr_low_size, ddr_high_size; qemu_irq gic_spi[GIC_NUM_SPI_INTR]; Error *err = NULL; ram_size = memory_region_size(s->ddr_ram); /* Create the DDR Memory Regions. User friendly checks should happen at * the board level */ if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) { /* The RAM size is above the maximum available for the low DDR. * Create the high DDR memory region as well. */ assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE); ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; memory_region_init_alias(&s->ddr_ram_high, NULL, "ddr-ram-high", s->ddr_ram, ddr_low_size, ddr_high_size); memory_region_add_subregion(get_system_memory(), XLNX_ZYNQMP_HIGH_RAM_START, &s->ddr_ram_high); } else { /* RAM must be non-zero */ assert(ram_size); ddr_low_size = ram_size; } memory_region_init_alias(&s->ddr_ram_low, NULL, "ddr-ram-low", s->ddr_ram, 0, ddr_low_size); memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low); /* Create the four OCM banks */ for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) { char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i); memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name, XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal); vmstate_register_ram_global(&s->ocm_ram[i]); memory_region_add_subregion(get_system_memory(), XLNX_ZYNQMP_OCM_RAM_0_ADDRESS + i * XLNX_ZYNQMP_OCM_RAM_SIZE, &s->ocm_ram[i]); g_free(ocm_name); } qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32); qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2); qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", XLNX_ZYNQMP_NUM_APU_CPUS); object_property_set_bool(OBJECT(&s->gic), true, "realized", &err); if (err) { error_propagate(errp, err); return; } assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS); for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) { SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic); const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i]; MemoryRegion *mr = sysbus_mmio_get_region(gic, r->region_index); uint32_t addr = r->address; int j; sysbus_mmio_map(gic, r->region_index, addr); for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) { MemoryRegion *alias = &s->gic_mr[i][j]; addr += XLNX_ZYNQMP_GIC_REGION_SIZE; memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr, 0, XLNX_ZYNQMP_GIC_REGION_SIZE); memory_region_add_subregion(system_memory, addr, alias); } } for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) { qemu_irq irq; char *name; object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC, "psci-conduit", &error_abort); name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i])); if (strcmp(name, boot_cpu)) { /* Secondary CPUs start in PSCI powered-down state */ object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "start-powered-off", &error_abort); } else { s->boot_cpu_ptr = &s->apu_cpu[i]; } g_free(name); object_property_set_bool(OBJECT(&s->apu_cpu[i]), s->secure, "has_el3", NULL); object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR, "reset-cbar", &error_abort); object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized", &err); if (err) { error_propagate(errp, err); return; } sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i, qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), ARM_CPU_IRQ)); irq = qdev_get_gpio_in(DEVICE(&s->gic), arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI)); qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 0, irq); irq = qdev_get_gpio_in(DEVICE(&s->gic), arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI)); qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 1, irq); } for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) { char *name; name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i])); if (strcmp(name, boot_cpu)) { /* Secondary CPUs start in PSCI powered-down state */ object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "start-powered-off", &error_abort); } else { s->boot_cpu_ptr = &s->rpu_cpu[i]; } g_free(name); object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs", &error_abort); object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized", &err); if (err) { error_propagate(errp, err); return; } } if (!s->boot_cpu_ptr) { error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu); return; } for (i = 0; i < GIC_NUM_SPI_INTR; i++) { gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i); } for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) { NICInfo *nd = &nd_table[i]; if (nd->used) { qemu_check_nic_model(nd, TYPE_CADENCE_GEM); qdev_set_nic_properties(DEVICE(&s->gem[i]), nd); } object_property_set_bool(OBJECT(&s->gem[i]), true, "realized", &err); if (err) { error_propagate(errp, err); return; } sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]); sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0, gic_spi[gem_intr[i]]); } for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) { object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err); if (err) { error_propagate(errp, err); return; } sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]); sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0, gic_spi[uart_intr[i]]); } object_property_set_int(OBJECT(&s->sata), SATA_NUM_PORTS, "num-ports", &error_abort); object_property_set_bool(OBJECT(&s->sata), true, "realized", &err); if (err) { error_propagate(errp, err); return; } sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR); sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]); for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { char *bus_name; object_property_set_bool(OBJECT(&s->sdhci[i]), true, "realized", &err); if (err) { error_propagate(errp, err); return; } sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci[i]), 0, sdhci_addr[i]); sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci[i]), 0, gic_spi[sdhci_intr[i]]); /* Alias controller SD bus to the SoC itself */ bus_name = g_strdup_printf("sd-bus%d", i); object_property_add_alias(OBJECT(s), bus_name, OBJECT(&s->sdhci[i]), "sd-bus", &error_abort); g_free(bus_name); } for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { gchar *bus_name; object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err); sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]); sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0, gic_spi[spi_intr[i]]); /* Alias controller SPI bus to the SoC itself */ bus_name = g_strdup_printf("spi%d", i); object_property_add_alias(OBJECT(s), bus_name, OBJECT(&s->spi[i]), "spi0", &error_abort); g_free(bus_name); } }


static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) { VirtioPCIClass *vpciklass = VIRTIO_PCI_GET_CLASS(qdev); VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev); PCIDevice *pci_dev = &proxy->pci_dev; if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) && !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN)) { pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; } vpciklass->parent_dc_realize(qdev, errp); }


static void v9fs_symlink(void *opaque) { V9fsPDU *pdu = opaque; V9fsString name; V9fsString symname; V9fsString fullname; V9fsFidState *dfidp; V9fsQID qid; struct stat stbuf; int32_t dfid; int err = 0; gid_t gid; size_t offset = 7; v9fs_string_init(&fullname); pdu_unmarshal(pdu, offset, "dssd", &dfid, &name, &symname, &gid); dfidp = get_fid(pdu->s, dfid); if (dfidp == NULL) { err = -EINVAL; goto out_nofid; } v9fs_string_sprintf(&fullname, "%s/%s", dfidp->path.data, name.data); err = v9fs_co_symlink(pdu->s, dfidp, symname.data, fullname.data, gid); if (err < 0) { goto out; } err = v9fs_co_lstat(pdu->s, &fullname, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); offset += pdu_marshal(pdu, offset, "Q", &qid); err = offset; out: put_fid(pdu->s, dfidp); out_nofid: complete_pdu(pdu->s, pdu, err); v9fs_string_free(&name); v9fs_string_free(&symname); v9fs_string_free(&fullname); }


static void s390_pci_generate_error_event(uint16_t pec, uint32_t fh, uint32_t fid, uint64_t faddr, uint32_t e) { s390_pci_generate_event(1, pec, fh, fid, faddr, e); }


int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt) { AVCodecInternal *avci = avctx->internal; int planar, channels; int ret = 0; *got_frame_ptr = 0; avctx->pkt = avpkt; if (!avpkt->data && avpkt->size) { av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); return AVERROR(EINVAL); } apply_param_change(avctx, avpkt); avcodec_get_frame_defaults(frame); if (!avctx->refcounted_frames) av_frame_unref(&avci->to_free); if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) { ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt); if (ret >= 0 && *got_frame_ptr) { avctx->frame_number++; frame->pkt_dts = avpkt->dts; if (frame->format == AV_SAMPLE_FMT_NONE) frame->format = avctx->sample_fmt; if (!avctx->refcounted_frames) { avci->to_free = *frame; avci->to_free.extended_data = avci->to_free.data; memset(frame->buf, 0, sizeof(frame->buf)); frame->extended_buf = NULL; frame->nb_extended_buf = 0; } } else if (frame->data[0]) av_frame_unref(frame); } /* many decoders assign whole AVFrames, thus overwriting extended_data; * make sure it's set correctly; assume decoders that actually use * extended_data are doing it correctly */ planar = av_sample_fmt_is_planar(frame->format); channels = av_get_channel_layout_nb_channels(frame->channel_layout); if (!(planar && channels > AV_NUM_DATA_POINTERS)) frame->extended_data = frame->data; return ret; }


struct HCIInfo *hci_init(const char *str) { char *endp; struct bt_scatternet_s *vlan = 0; if (!strcmp(str, "null")) /* null */ return &null_hci; else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) /* host[:hciN] */ return bt_host_hci(str[4] ? str + 5 : "hci0"); else if (!strncmp(str, "hci", 3)) { /* hci[,vlan=n] */ if (str[3]) { if (!strncmp(str + 3, ",vlan=", 6)) { vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); if (*endp) vlan = 0; } } else vlan = qemu_find_bt_vlan(0); if (vlan) return bt_new_hci(vlan); } fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); return 0; }


static int read_matrix_params(MLPDecodeContext *m, SubStream *s, GetBitContext *gbp) { unsigned int mat, ch; s->num_primitive_matrices = get_bits(gbp, 4); m->matrix_changed++; for (mat = 0; mat < s->num_primitive_matrices; mat++) { int frac_bits, max_chan; s->matrix_out_ch[mat] = get_bits(gbp, 4); frac_bits = get_bits(gbp, 4); s->lsb_bypass [mat] = get_bits1(gbp); if (s->matrix_out_ch[mat] > s->max_matrix_channel) { av_log(m->avctx, AV_LOG_ERROR, "Invalid channel %d specified as output from matrix.\n", s->matrix_out_ch[mat]); return -1; } if (frac_bits > 14) { av_log(m->avctx, AV_LOG_ERROR, "Too many fractional bits specified.\n"); return -1; } max_chan = s->max_matrix_channel; if (!s->noise_type) max_chan+=2; for (ch = 0; ch <= max_chan; ch++) { int coeff_val = 0; if (get_bits1(gbp)) coeff_val = get_sbits(gbp, frac_bits + 2); s->matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits); } if (s->noise_type) s->matrix_noise_shift[mat] = get_bits(gbp, 4); else s->matrix_noise_shift[mat] = 0; } return 0; }


static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { int ret; gsm_signal *samples = (gsm_signal *)frame->data[0]; struct gsm_state *state = avctx->priv_data; if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align))) return ret; switch(avctx->codec_id) { case AV_CODEC_ID_GSM: gsm_encode(state, samples, avpkt->data); break; case AV_CODEC_ID_GSM_MS: gsm_encode(state, samples, avpkt->data); gsm_encode(state, samples + GSM_FRAME_SIZE, avpkt->data + 32); } *got_packet_ptr = 1; return 0; }


static void ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride) { int dc = (block[0] + 32) >> 6; __asm__ volatile( "movd %0, %%mm0 \n\t" "pshufw $0, %%mm0, %%mm0 \n\t" "pxor %%mm1, %%mm1 \n\t" "psubw %%mm0, %%mm1 \n\t" "packuswb %%mm0, %%mm0 \n\t" "packuswb %%mm1, %%mm1 \n\t" ::"r"(dc) ); __asm__ volatile( "movd %0, %%mm2 \n\t" "movd %1, %%mm3 \n\t" "movd %2, %%mm4 \n\t" "movd %3, %%mm5 \n\t" "paddusb %%mm0, %%mm2 \n\t" "paddusb %%mm0, %%mm3 \n\t" "paddusb %%mm0, %%mm4 \n\t" "paddusb %%mm0, %%mm5 \n\t" "psubusb %%mm1, %%mm2 \n\t" "psubusb %%mm1, %%mm3 \n\t" "psubusb %%mm1, %%mm4 \n\t" "psubusb %%mm1, %%mm5 \n\t" "movd %%mm2, %0 \n\t" "movd %%mm3, %1 \n\t" "movd %%mm4, %2 \n\t" "movd %%mm5, %3 \n\t" :"+m"(*(uint32_t*)(dst+0*stride)), "+m"(*(uint32_t*)(dst+1*stride)), "+m"(*(uint32_t*)(dst+2*stride)), "+m"(*(uint32_t*)(dst+3*stride)) ); }


void ff_xvmc_field_end(MpegEncContext *s) { struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f->data[2]; assert(render); if (render->filled_mv_blocks_num > 0) ff_mpeg_draw_horiz_band(s, 0, 0); }


static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, int src_size) { int width, height; int hdr, zsize, npal, tidx = -1, ret; int i, j; const uint8_t *src_end = src + src_size; uint8_t pal[768], transp[3]; uLongf dlen = (c->tile_width + 1) * c->tile_height; int sub_type; int nblocks, cblocks, bstride; int bits, bitbuf, coded; uint8_t *dst = c->framebuf + tile_x * c->tile_width * 3 + tile_y * c->tile_height * c->framebuf_stride; if (src_size < 2) return AVERROR_INVALIDDATA; width = FFMIN(c->width - tile_x * c->tile_width, c->tile_width); height = FFMIN(c->height - tile_y * c->tile_height, c->tile_height); hdr = *src++; sub_type = hdr >> 5; if (sub_type == 0) { int j; memcpy(transp, src, 3); src += 3; for (j = 0; j < height; j++, dst += c->framebuf_stride) for (i = 0; i < width; i++) memcpy(dst + i * 3, transp, 3); return 0; } else if (sub_type == 1) { return jpg_decode_data(&c->jc, width, height, src, src_end - src, dst, c->framebuf_stride, NULL, 0, 0, 0); } if (sub_type != 2) { memcpy(transp, src, 3); src += 3; } npal = *src++ + 1; memcpy(pal, src, npal * 3); src += npal * 3; if (sub_type != 2) { for (i = 0; i < npal; i++) { if (!memcmp(pal + i * 3, transp, 3)) { tidx = i; break; } } } if (src_end - src < 2) return 0; zsize = (src[0] << 8) | src[1]; src += 2; if (src_end - src < zsize) return AVERROR_INVALIDDATA; ret = uncompress(c->kempf_buf, &dlen, src, zsize); if (ret) return AVERROR_INVALIDDATA; src += zsize; if (sub_type == 2) { kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride, NULL, 0, width, height, pal, npal, tidx); return 0; } nblocks = *src++ + 1; cblocks = 0; bstride = FFALIGN(width, 16) >> 4; // blocks are coded LSB and we need normal bitreader for JPEG data bits = 0; for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) { for (j = 0; j < (FFALIGN(width, 16) >> 4); j++) { if (!bits) { bitbuf = *src++; bits = 8; } coded = bitbuf & 1; bits--; bitbuf >>= 1; cblocks += coded; if (cblocks > nblocks) return AVERROR_INVALIDDATA; c->kempf_flags[j + i * bstride] = coded; } } memset(c->jpeg_tile, 0, c->tile_stride * height); jpg_decode_data(&c->jc, width, height, src, src_end - src, c->jpeg_tile, c->tile_stride, c->kempf_flags, bstride, nblocks, 0); kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride, c->jpeg_tile, c->tile_stride, width, height, pal, npal, tidx); return 0; }


static void vnc_dpy_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { VncDisplay *vd = container_of(dcl, VncDisplay, dcl); struct VncSurface *s = &vd->guest; int width = surface_width(vd->ds); int height = surface_height(vd->ds); /* this is needed this to ensure we updated all affected * blocks if x % VNC_DIRTY_PIXELS_PER_BIT != 0 */ w += (x % VNC_DIRTY_PIXELS_PER_BIT); x -= (x % VNC_DIRTY_PIXELS_PER_BIT); x = MIN(x, width); y = MIN(y, height); w = MIN(x + w, width) - x; h = MIN(y + h, height); for (; y < h; y++) { bitmap_set(s->dirty[y], x / VNC_DIRTY_PIXELS_PER_BIT, DIV_ROUND_UP(w, VNC_DIRTY_PIXELS_PER_BIT)); } }


static int channelmap_config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ChannelMapContext *s = ctx->priv; int i, err = 0; const char *channel_name; char layout_name[256]; if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) { for (i = 0; i < s->nch; i++) { s->map[i].in_channel_idx = av_get_channel_layout_channel_index( inlink->channel_layout, s->map[i].in_channel); if (s->map[i].in_channel_idx < 0) { channel_name = av_get_channel_name(s->map[i].in_channel); av_get_channel_layout_string(layout_name, sizeof(layout_name), 0, inlink->channel_layout); av_log(ctx, AV_LOG_ERROR, "input channel '%s' not available from input layout '%s'\n", channel_name, layout_name); err = AVERROR(EINVAL); } } } return err; }


static void decode_format80(const unsigned char *src, int src_size, unsigned char *dest, int dest_size, int check_size) { int src_index = 0; int dest_index = 0; int count; int src_pos; unsigned char color; int i; while (src_index < src_size) { av_dlog(NULL, " opcode %02X: ", src[src_index]); /* 0x80 means that frame is finished */ if (src[src_index] == 0x80) if (dest_index >= dest_size) { av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n", dest_index, dest_size); } if (src[src_index] == 0xFF) { src_index++; count = AV_RL16(&src[src_index]); src_index += 2; src_pos = AV_RL16(&src[src_index]); src_index += 2; av_dlog(NULL, "(1) copy %X bytes from absolute pos %X\n", count, src_pos); CHECK_COUNT(); if (src_pos + count > dest_size) for (i = 0; i < count; i++) dest[dest_index + i] = dest[src_pos + i]; dest_index += count; } else if (src[src_index] == 0xFE) { src_index++; count = AV_RL16(&src[src_index]); src_index += 2; color = src[src_index++]; av_dlog(NULL, "(2) set %X bytes to %02X\n", count, color); CHECK_COUNT(); memset(&dest[dest_index], color, count); dest_index += count; } else if ((src[src_index] & 0xC0) == 0xC0) { count = (src[src_index++] & 0x3F) + 3; src_pos = AV_RL16(&src[src_index]); src_index += 2; av_dlog(NULL, "(3) copy %X bytes from absolute pos %X\n", count, src_pos); CHECK_COUNT(); if (src_pos + count > dest_size) for (i = 0; i < count; i++) dest[dest_index + i] = dest[src_pos + i]; dest_index += count; } else if (src[src_index] > 0x80) { count = src[src_index++] & 0x3F; av_dlog(NULL, "(4) copy %X bytes from source to dest\n", count); CHECK_COUNT(); memcpy(&dest[dest_index], &src[src_index], count); src_index += count; dest_index += count; } else { count = ((src[src_index] & 0x70) >> 4) + 3; src_pos = AV_RB16(&src[src_index]) & 0x0FFF; src_index += 2; av_dlog(NULL, "(5) copy %X bytes from relpos %X\n", count, src_pos); CHECK_COUNT(); for (i = 0; i < count; i++) dest[dest_index + i] = dest[dest_index - src_pos + i]; dest_index += count; } } /* validate that the entire destination buffer was filled; this is * important for decoding frame maps since each vector needs to have a * codebook entry; it is not important for compressed codebooks because * not every entry needs to be filled */ if (check_size) if (dest_index < dest_size) av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n", dest_index, dest_size); }


void do_info_roms(Monitor *mon, const QDict *qdict) { Rom *rom; QTAILQ_FOREACH(rom, &roms, next) { if (!rom->fw_file) { monitor_printf(mon, "addr=" TARGET_FMT_plx " size=0x%06zx mem=%s name=\"%s\"\n", rom->addr, rom->romsize, rom->isrom ? "rom" : "ram", rom->name); } else { monitor_printf(mon, "fw=%s/%s" " size=0x%06zx name=\"%s\"\n", rom->fw_dir, rom->fw_file, rom->romsize, rom->name); } } }


static void migration_end(void) { if (migration_bitmap) { memory_global_dirty_log_stop(); g_free(migration_bitmap); migration_bitmap = NULL; } if (XBZRLE.cache) { cache_fini(XBZRLE.cache); g_free(XBZRLE.cache); g_free(XBZRLE.encoded_buf); g_free(XBZRLE.current_buf); g_free(XBZRLE.decoded_buf); XBZRLE.cache = NULL; } }


static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) { AVFilterContext *ctx = inlink->dst; Stereo3DContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out, *oleft, *oright, *ileft, *iright; int out_off_left[4], out_off_right[4]; int i; if (s->in.format == s->out.format) return ff_filter_frame(outlink, inpicref); switch (s->in.format) { case ALTERNATING_LR: case ALTERNATING_RL: if (!s->prev) { s->prev = inpicref; return 0; } ileft = s->prev; iright = inpicref; if (s->in.format == ALTERNATING_RL) FFSWAP(AVFrame *, ileft, iright); break; default: ileft = iright = inpicref; }; if ((s->out.format == ALTERNATING_LR || s->out.format == ALTERNATING_RL) && (s->in.format == SIDE_BY_SIDE_LR || s->in.format == SIDE_BY_SIDE_RL || s->in.format == SIDE_BY_SIDE_2_LR || s->in.format == SIDE_BY_SIDE_2_RL || s->in.format == ABOVE_BELOW_LR || s->in.format == ABOVE_BELOW_RL || s->in.format == ABOVE_BELOW_2_LR || s->in.format == ABOVE_BELOW_2_RL)) { oright = av_frame_clone(inpicref); oleft = av_frame_clone(inpicref); if (!oright || !oleft) { av_frame_free(&oright); av_frame_free(&oleft); av_frame_free(&s->prev); av_frame_free(&inpicref); return AVERROR(ENOMEM); } } else if ((s->out.format == MONO_L || s->out.format == MONO_R) && (s->in.format == SIDE_BY_SIDE_LR || s->in.format == SIDE_BY_SIDE_RL || s->in.format == SIDE_BY_SIDE_2_LR || s->in.format == SIDE_BY_SIDE_2_RL || s->in.format == ABOVE_BELOW_LR || s->in.format == ABOVE_BELOW_RL || s->in.format == ABOVE_BELOW_2_LR || s->in.format == ABOVE_BELOW_2_RL)) { out = oleft = oright = av_frame_clone(inpicref); if (!out) { av_frame_free(&s->prev); av_frame_free(&inpicref); return AVERROR(ENOMEM); } } else { out = oleft = oright = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { av_frame_free(&s->prev); av_frame_free(&inpicref); return AVERROR(ENOMEM); } av_frame_copy_props(out, inpicref); if (s->out.format == ALTERNATING_LR || s->out.format == ALTERNATING_RL) { oright = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!oright) { av_frame_free(&oleft); av_frame_free(&s->prev); av_frame_free(&inpicref); return AVERROR(ENOMEM); } av_frame_copy_props(oright, inpicref); } } for (i = 0; i < 4; i++) { int hsub = i == 1 || i == 2 ? s->hsub : 0; int vsub = i == 1 || i == 2 ? s->vsub : 0; s->in_off_left[i] = (FF_CEIL_RSHIFT(s->in.row_left, vsub) + s->in.off_lstep) * ileft->linesize[i] + FF_CEIL_RSHIFT(s->in.off_left * s->pixstep[i], hsub); s->in_off_right[i] = (FF_CEIL_RSHIFT(s->in.row_right, vsub) + s->in.off_rstep) * iright->linesize[i] + FF_CEIL_RSHIFT(s->in.off_right * s->pixstep[i], hsub); out_off_left[i] = (FF_CEIL_RSHIFT(s->out.row_left, vsub) + s->out.off_lstep) * oleft->linesize[i] + FF_CEIL_RSHIFT(s->out.off_left * s->pixstep[i], hsub); out_off_right[i] = (FF_CEIL_RSHIFT(s->out.row_right, vsub) + s->out.off_rstep) * oright->linesize[i] + FF_CEIL_RSHIFT(s->out.off_right * s->pixstep[i], hsub); } switch (s->out.format) { case ALTERNATING_LR: case ALTERNATING_RL: switch (s->in.format) { case ABOVE_BELOW_LR: case ABOVE_BELOW_RL: case ABOVE_BELOW_2_LR: case ABOVE_BELOW_2_RL: case SIDE_BY_SIDE_LR: case SIDE_BY_SIDE_RL: case SIDE_BY_SIDE_2_LR: case SIDE_BY_SIDE_2_RL: oleft->width = outlink->w; oright->width = outlink->w; oleft->height = outlink->h; oright->height = outlink->h; for (i = 0; i < s->nb_planes; i++) { oleft->data[i] += s->in_off_left[i]; oright->data[i] += s->in_off_right[i]; } break; default: goto copy; break; } break; case HDMI: for (i = 0; i < s->nb_planes; i++) { int j, h = s->height >> ((i == 1 || i == 2) ? s->vsub : 0); int b = (s->blanks) >> ((i == 1 || i == 2) ? s->vsub : 0); for (j = h; j < h + b; j++) memset(oleft->data[i] + j * s->linesize[i], 0, s->linesize[i]); } case SIDE_BY_SIDE_LR: case SIDE_BY_SIDE_RL: case SIDE_BY_SIDE_2_LR: case SIDE_BY_SIDE_2_RL: case ABOVE_BELOW_LR: case ABOVE_BELOW_RL: case ABOVE_BELOW_2_LR: case ABOVE_BELOW_2_RL: case INTERLEAVE_ROWS_LR: case INTERLEAVE_ROWS_RL: copy: for (i = 0; i < s->nb_planes; i++) { av_image_copy_plane(oleft->data[i] + out_off_left[i], oleft->linesize[i] * s->out.row_step, ileft->data[i] + s->in_off_left[i], ileft->linesize[i] * s->in.row_step, s->linesize[i], s->pheight[i]); av_image_copy_plane(oright->data[i] + out_off_right[i], oright->linesize[i] * s->out.row_step, iright->data[i] + s->in_off_right[i], iright->linesize[i] * s->in.row_step, s->linesize[i], s->pheight[i]); } break; case MONO_L: iright = ileft; case MONO_R: switch (s->in.format) { case ABOVE_BELOW_LR: case ABOVE_BELOW_RL: case ABOVE_BELOW_2_LR: case ABOVE_BELOW_2_RL: case SIDE_BY_SIDE_LR: case SIDE_BY_SIDE_RL: case SIDE_BY_SIDE_2_LR: case SIDE_BY_SIDE_2_RL: out->width = outlink->w; out->height = outlink->h; for (i = 0; i < s->nb_planes; i++) { out->data[i] += s->in_off_left[i]; } break; default: for (i = 0; i < s->nb_planes; i++) { av_image_copy_plane(out->data[i], out->linesize[i], iright->data[i] + s->in_off_left[i], iright->linesize[i] * s->in.row_step, s->linesize[i], s->pheight[i]); } break; } break; case ANAGLYPH_RB_GRAY: case ANAGLYPH_RG_GRAY: case ANAGLYPH_RC_GRAY: case ANAGLYPH_RC_HALF: case ANAGLYPH_RC_COLOR: case ANAGLYPH_RC_DUBOIS: case ANAGLYPH_GM_GRAY: case ANAGLYPH_GM_HALF: case ANAGLYPH_GM_COLOR: case ANAGLYPH_GM_DUBOIS: case ANAGLYPH_YB_GRAY: case ANAGLYPH_YB_HALF: case ANAGLYPH_YB_COLOR: case ANAGLYPH_YB_DUBOIS: { ThreadData td; td.ileft = ileft; td.iright = iright; td.out = out; ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(s->out.height, ctx->graph->nb_threads)); break; } case CHECKERBOARD_RL: case CHECKERBOARD_LR: for (i = 0; i < s->nb_planes; i++) { int x, y; for (y = 0; y < s->pheight[i]; y++) { uint8_t *dst = out->data[i] + out->linesize[i] * y; uint8_t *left = ileft->data[i] + ileft->linesize[i] * y + s->in_off_left[i]; uint8_t *right = iright->data[i] + iright->linesize[i] * y + s->in_off_right[i]; int p, b; if (s->out.format == CHECKERBOARD_RL) FFSWAP(uint8_t*, left, right); switch (s->pixstep[i]) { case 1: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=2, p++, b++) { dst[x ] = (b&1) == (y&1) ? left[p] : right[p]; dst[x+1] = (b&1) != (y&1) ? left[p] : right[p]; } break; case 2: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=4, p+=2, b++) { AV_WN16(&dst[x ], (b&1) == (y&1) ? AV_RN16(&left[p]) : AV_RN16(&right[p])); AV_WN16(&dst[x+2], (b&1) != (y&1) ? AV_RN16(&left[p]) : AV_RN16(&right[p])); } break; case 3: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=6, p+=3, b++) { AV_WB24(&dst[x ], (b&1) == (y&1) ? AV_RB24(&left[p]) : AV_RB24(&right[p])); AV_WB24(&dst[x+3], (b&1) != (y&1) ? AV_RB24(&left[p]) : AV_RB24(&right[p])); } break; case 4: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=8, p+=4, b++) { AV_WN32(&dst[x ], (b&1) == (y&1) ? AV_RN32(&left[p]) : AV_RN32(&right[p])); AV_WN32(&dst[x+4], (b&1) != (y&1) ? AV_RN32(&left[p]) : AV_RN32(&right[p])); } break; case 6: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=12, p+=6, b++) { AV_WB48(&dst[x ], (b&1) == (y&1) ? AV_RB48(&left[p]) : AV_RB48(&right[p])); AV_WB48(&dst[x+6], (b&1) != (y&1) ? AV_RB48(&left[p]) : AV_RB48(&right[p])); } break; case 8: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=16, p+=8, b++) { AV_WN64(&dst[x ], (b&1) == (y&1) ? AV_RN64(&left[p]) : AV_RN64(&right[p])); AV_WN64(&dst[x+8], (b&1) != (y&1) ? AV_RN64(&left[p]) : AV_RN64(&right[p])); } break; } } } break; case INTERLEAVE_COLS_LR: case INTERLEAVE_COLS_RL: for (i = 0; i < s->nb_planes; i++) { int x, y; for (y = 0; y < s->pheight[i]; y++) { uint8_t *dst = out->data[i] + out->linesize[i] * y; uint8_t *left = ileft->data[i] + ileft->linesize[i] * y * s->in.row_step + s->in_off_left[i]; uint8_t *right = iright->data[i] + iright->linesize[i] * y * s->in.row_step + s->in_off_right[i]; int p, b; if (s->out.format == INTERLEAVE_COLS_LR) FFSWAP(uint8_t*, left, right); switch (s->pixstep[i]) { case 1: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=2, p++, b++) { dst[x ] = b&1 ? left[p] : right[p]; dst[x+1] = !(b&1) ? left[p] : right[p]; } break; case 2: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=4, p+=2, b++) { AV_WN16(&dst[x ], b&1 ? AV_RN16(&left[p]) : AV_RN16(&right[p])); AV_WN16(&dst[x+2], !(b&1) ? AV_RN16(&left[p]) : AV_RN16(&right[p])); } break; case 3: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=6, p+=3, b++) { AV_WB24(&dst[x ], b&1 ? AV_RB24(&left[p]) : AV_RB24(&right[p])); AV_WB24(&dst[x+3], !(b&1) ? AV_RB24(&left[p]) : AV_RB24(&right[p])); } break; case 4: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=8, p+=4, b++) { AV_WN32(&dst[x ], b&1 ? AV_RN32(&left[p]) : AV_RN32(&right[p])); AV_WN32(&dst[x+4], !(b&1) ? AV_RN32(&left[p]) : AV_RN32(&right[p])); } break; case 6: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=12, p+=6, b++) { AV_WB48(&dst[x ], b&1 ? AV_RB48(&left[p]) : AV_RB48(&right[p])); AV_WB48(&dst[x+6], !(b&1) ? AV_RB48(&left[p]) : AV_RB48(&right[p])); } break; case 8: for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=16, p+=8, b++) { AV_WN64(&dst[x ], b&1 ? AV_RN64(&left[p]) : AV_RN64(&right[p])); AV_WN64(&dst[x+8], !(b&1) ? AV_RN64(&left[p]) : AV_RN64(&right[p])); } break; } } } break; default: av_assert0(0); } av_frame_free(&inpicref); av_frame_free(&s->prev); if (oright != oleft) { if (s->out.format == ALTERNATING_LR) FFSWAP(AVFrame *, oleft, oright); oright->pts = outlink->frame_count * s->ts_unit; ff_filter_frame(outlink, oright); out = oleft; oleft->pts = outlink->frame_count * s->ts_unit; } else if (s->in.format == ALTERNATING_LR || s->in.format == ALTERNATING_RL) { out->pts = outlink->frame_count * s->ts_unit; } return ff_filter_frame(outlink, out); }


static int unpack_parse_unit(DiracParseUnit *pu, DiracParseContext *pc, int offset) { int8_t *start; if (offset < 0 || pc->index - 13 < offset) return 0; start = pc->buffer + offset; pu->pu_type = start[4]; pu->next_pu_offset = AV_RB32(start + 5); pu->prev_pu_offset = AV_RB32(start + 9); if (pu->pu_type == 0x10 && pu->next_pu_offset == 0) pu->next_pu_offset = 13; if (pu->next_pu_offset && pu->next_pu_offset < 13) { av_log(NULL, AV_LOG_ERROR, "next_pu_offset %d is invalid\n", pu->next_pu_offset); return 0; } if (pu->prev_pu_offset && pu->prev_pu_offset < 13) { av_log(NULL, AV_LOG_ERROR, "prev_pu_offset %d is invalid\n", pu->prev_pu_offset); return 0; } return 1; }


static void quantize_all(DCAEncContext *c) { int sample, band, ch; for (sample = 0; sample < SUBBAND_SAMPLES; sample++) for (band = 0; band < 32; band++) for (ch = 0; ch < c->fullband_channels; ch++) c->quantized[sample][band][ch] = quantize_value(c->subband[sample][band][ch], c->quant[band][ch]); }


static int video_thread(void *arg) { VideoState *is = arg; AVPacket pkt1, *pkt = &pkt1; int len1, got_picture; AVFrame *frame= avcodec_alloc_frame(); double pts; for(;;) { while (is->paused && !is->videoq.abort_request) { SDL_Delay(10); } if (packet_queue_get(&is->videoq, pkt, 1) < 0) break; if(pkt->data == flush_pkt.data){ avcodec_flush_buffers(is->video_st->codec); is->last_dts_for_fault_detection= is->last_pts_for_fault_detection= INT64_MIN; continue; } /* NOTE: ipts is the PTS of the _first_ picture beginning in this packet, if any */ is->video_st->codec->reordered_opaque= pkt->pts; len1 = avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt); if(pkt->dts != AV_NOPTS_VALUE){ is->faulty_dts += pkt->dts <= is->last_dts_for_fault_detection; is->last_dts_for_fault_detection= pkt->dts; } if(frame->reordered_opaque != AV_NOPTS_VALUE){ is->faulty_pts += frame->reordered_opaque <= is->last_pts_for_fault_detection; is->last_pts_for_fault_detection= frame->reordered_opaque; } if( ( decoder_reorder_pts==1 || decoder_reorder_pts && is->faulty_pts<is->faulty_dts || pkt->dts == AV_NOPTS_VALUE) && frame->reordered_opaque != AV_NOPTS_VALUE) pts= frame->reordered_opaque; else if(pkt->dts != AV_NOPTS_VALUE) pts= pkt->dts; else pts= 0; pts *= av_q2d(is->video_st->time_base); // if (len1 < 0) // break; if (got_picture) { if (output_picture2(is, frame, pts) < 0) goto the_end; } av_free_packet(pkt); if (step) if (cur_stream) stream_pause(cur_stream); } the_end: av_free(frame); return 0; }


static int nut_write_header(AVFormatContext *s) { NUTContext *nut = s->priv_data; AVIOContext *bc = s->pb; int i, j, ret; nut->avf = s; nut->version = FFMAX(NUT_STABLE_VERSION, 3 + !!nut->flags); if (nut->flags && s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { av_log(s, AV_LOG_ERROR, "The additional syncpoint modes require version %d, " "that is currently not finalized, " "please set -f_strict experimental in order to enable it.\n", nut->version); return AVERROR_EXPERIMENTAL; } nut->stream = av_calloc(s->nb_streams, sizeof(*nut->stream )); nut->chapter = av_calloc(s->nb_chapters, sizeof(*nut->chapter)); nut->time_base= av_calloc(s->nb_streams + s->nb_chapters, sizeof(*nut->time_base)); if (!nut->stream || !nut->chapter || !nut->time_base) { av_freep(&nut->stream); av_freep(&nut->chapter); av_freep(&nut->time_base); return AVERROR(ENOMEM); } for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; int ssize; AVRational time_base; ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num); if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->sample_rate) { time_base = (AVRational) {1, st->codec->sample_rate}; } else { time_base = ff_choose_timebase(s, st, 48000); } avpriv_set_pts_info(st, 64, time_base.num, time_base.den); for (j = 0; j < nut->time_base_count; j++) if (!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))) { break; } nut->time_base[j] = time_base; nut->stream[i].time_base = &nut->time_base[j]; if (j == nut->time_base_count) nut->time_base_count++; if (INT64_C(1000) * time_base.num >= time_base.den) nut->stream[i].msb_pts_shift = 7; else nut->stream[i].msb_pts_shift = 14; nut->stream[i].max_pts_distance = FFMAX(time_base.den, time_base.num) / time_base.num; } for (i = 0; i < s->nb_chapters; i++) { AVChapter *ch = s->chapters[i]; for (j = 0; j < nut->time_base_count; j++) if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational))) break; nut->time_base[j] = ch->time_base; nut->chapter[i].time_base = &nut->time_base[j]; if (j == nut->time_base_count) nut->time_base_count++; } nut->max_distance = MAX_DISTANCE; build_elision_headers(s); build_frame_code(s); av_assert0(nut->frame_code['N'].flags == FLAG_INVALID); avio_write(bc, ID_STRING, strlen(ID_STRING)); avio_w8(bc, 0); if ((ret = write_headers(s, bc)) < 0) return ret; if (s->avoid_negative_ts < 0) s->avoid_negative_ts = 1; avio_flush(bc); return 0; }


static void skip_input(DBEContext *s, int nb_words) { s->input += nb_words * s->word_bytes; s->input_size -= nb_words; }


static void g364fb_screen_dump(void *opaque, const char *filename) { G364State *s = opaque; int y, x; uint8_t index; uint8_t *data_buffer; FILE *f; if (s->depth != 8) { error_report("g364: unknown guest depth %d", s->depth); return; } f = fopen(filename, "wb"); if (!f) return; if (s->ctla & CTLA_FORCE_BLANK) { /* blank screen */ fprintf(f, "P4\n%d %d\n", s->width, s->height); for (y = 0; y < s->height; y++) for (x = 0; x < s->width; x++) fputc(0, f); } else { data_buffer = s->vram + s->top_of_screen; fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255); for (y = 0; y < s->height; y++) for (x = 0; x < s->width; x++, data_buffer++) { index = *data_buffer; fputc(s->color_palette[index][0], f); fputc(s->color_palette[index][1], f); fputc(s->color_palette[index][2], f); } } fclose(f); }


int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { Coroutine *co; DiscardCo rwco = { .bs = bs, .sector_num = sector_num, .nb_sectors = nb_sectors, .ret = NOT_DONE, }; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_discard_co_entry(&rwco); } else { AioContext *aio_context = bdrv_get_aio_context(bs); co = qemu_coroutine_create(bdrv_discard_co_entry); qemu_coroutine_enter(co, &rwco); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } } return rwco.ret; }


static void cg3_realizefn(DeviceState *dev, Error **errp) { SysBusDevice *sbd = SYS_BUS_DEVICE(dev); CG3State *s = CG3(dev); int ret; char *fcode_filename; /* FCode ROM */ vmstate_register_ram_global(&s->rom); fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, CG3_ROM_FILE); if (fcode_filename) { ret = load_image_targphys(fcode_filename, s->prom_addr, FCODE_MAX_ROM_SIZE); g_free(fcode_filename); if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) { error_report("cg3: could not load prom '%s'", CG3_ROM_FILE); } } memory_region_init_ram(&s->vram_mem, NULL, "cg3.vram", s->vram_size, &error_abort); memory_region_set_log(&s->vram_mem, true, DIRTY_MEMORY_VGA); vmstate_register_ram_global(&s->vram_mem); sysbus_init_mmio(sbd, &s->vram_mem); sysbus_init_irq(sbd, &s->irq); s->con = graphic_console_init(DEVICE(dev), 0, &cg3_ops, s); qemu_console_resize(s->con, s->width, s->height); }


static void virtio_gpu_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_simple_resource *res; struct virtio_gpu_scanout *scanout; pixman_format_code_t format; uint32_t offset; int bpp; struct virtio_gpu_set_scanout ss; VIRTIO_GPU_FILL_CMD(ss); trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, ss.r.width, ss.r.height, ss.r.x, ss.r.y); if (ss.scanout_id >= g->conf.max_outputs) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", __func__, ss.scanout_id); cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; return; } g->enable = 1; if (ss.resource_id == 0) { scanout = &g->scanout[ss.scanout_id]; if (scanout->resource_id) { res = virtio_gpu_find_resource(g, scanout->resource_id); if (res) { res->scanout_bitmask &= ~(1 << ss.scanout_id); } } if (ss.scanout_id == 0) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", __func__, ss.scanout_id); cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; return; } dpy_gfx_replace_surface(g->scanout[ss.scanout_id].con, NULL); scanout->ds = NULL; scanout->width = 0; scanout->height = 0; return; } /* create a surface for this scanout */ res = virtio_gpu_find_resource(g, ss.resource_id); if (!res) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\n", __func__, ss.resource_id); cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } if (ss.r.x > res->width || ss.r.y > res->height || ss.r.width > res->width || ss.r.height > res->height || ss.r.x + ss.r.width > res->width || ss.r.y + ss.r.height > res->height) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout %d bounds for" " resource %d, (%d,%d)+%d,%d vs %d %d\n", __func__, ss.scanout_id, ss.resource_id, ss.r.x, ss.r.y, ss.r.width, ss.r.height, res->width, res->height); cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; return; } scanout = &g->scanout[ss.scanout_id]; format = pixman_image_get_format(res->image); bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8; offset = (ss.r.x * bpp) + ss.r.y * pixman_image_get_stride(res->image); if (!scanout->ds || surface_data(scanout->ds) != ((uint8_t *)pixman_image_get_data(res->image) + offset) || scanout->width != ss.r.width || scanout->height != ss.r.height) { pixman_image_t *rect; void *ptr = (uint8_t *)pixman_image_get_data(res->image) + offset; rect = pixman_image_create_bits(format, ss.r.width, ss.r.height, ptr, pixman_image_get_stride(res->image)); pixman_image_ref(res->image); pixman_image_set_destroy_function(rect, virtio_unref_resource, res->image); /* realloc the surface ptr */ scanout->ds = qemu_create_displaysurface_pixman(rect); if (!scanout->ds) { cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC; return; } dpy_gfx_replace_surface(g->scanout[ss.scanout_id].con, scanout->ds); } res->scanout_bitmask |= (1 << ss.scanout_id); scanout->resource_id = ss.resource_id; scanout->x = ss.r.x; scanout->y = ss.r.y; scanout->width = ss.r.width; scanout->height = ss.r.height; }


void kbd_put_keycode(int keycode) { QEMUPutKbdEntry *entry = QTAILQ_FIRST(&kbd_handlers); if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { return; } if (entry) { entry->put_kbd(entry->opaque, keycode); } }


static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth); if (!ctx->api) ctx->api = x265_api_get(0); ctx->params = ctx->api->param_alloc(); if (!ctx->params) { av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n"); return AVERROR(ENOMEM); if (ctx->api->param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) { int i; av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune); av_log(avctx, AV_LOG_INFO, "Possible presets:"); for (i = 0; x265_preset_names[i]; i++) av_log(avctx, AV_LOG_INFO, " %s", x265_preset_names[i]); av_log(avctx, AV_LOG_INFO, "\n"); av_log(avctx, AV_LOG_INFO, "Possible tunes:"); for (i = 0; x265_tune_names[i]; i++) av_log(avctx, AV_LOG_INFO, " %s", x265_tune_names[i]); av_log(avctx, AV_LOG_INFO, "\n"); return AVERROR(EINVAL); ctx->params->frameNumThreads = avctx->thread_count; ctx->params->fpsNum = avctx->time_base.den; ctx->params->fpsDenom = avctx->time_base.num * avctx->ticks_per_frame; ctx->params->sourceWidth = avctx->width; ctx->params->sourceHeight = avctx->height; ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR); if ((avctx->color_primaries <= AVCOL_PRI_BT2020 && avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) || (avctx->color_trc <= AVCOL_TRC_BT2020_12 && avctx->color_trc != AVCOL_TRC_UNSPECIFIED) || (avctx->colorspace <= AVCOL_SPC_BT2020_CL && avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) { ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1; ctx->params->vui.bEnableColorDescriptionPresentFlag = 1; // x265 validates the parameters internally ctx->params->vui.colorPrimaries = avctx->color_primaries; ctx->params->vui.transferCharacteristics = avctx->color_trc; ctx->params->vui.matrixCoeffs = avctx->colorspace; if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { char sar[12]; int sar_num, sar_den; av_reduce(&sar_num, &sar_den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 65535); snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); if (ctx->api->param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); switch (avctx->pix_fmt) { case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV420P10: case AV_PIX_FMT_YUV420P12: ctx->params->internalCsp = X265_CSP_I420; case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV422P10: case AV_PIX_FMT_YUV422P12: ctx->params->internalCsp = X265_CSP_I422; case AV_PIX_FMT_GBRP: case AV_PIX_FMT_GBRP10: case AV_PIX_FMT_GBRP12: ctx->params->vui.matrixCoeffs = AVCOL_SPC_RGB; ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1; ctx->params->vui.bEnableColorDescriptionPresentFlag = 1; case AV_PIX_FMT_YUV444P: case AV_PIX_FMT_YUV444P10: case AV_PIX_FMT_YUV444P12: ctx->params->internalCsp = X265_CSP_I444; if (ctx->crf >= 0) { char crf[6]; snprintf(crf, sizeof(crf), "%2.2f", ctx->crf); if (ctx->api->param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) { av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf); return AVERROR(EINVAL); } else if (avctx->bit_rate > 0) { ctx->params->rc.bitrate = avctx->bit_rate / 1000; ctx->params->rc.rateControlMode = X265_RC_ABR; if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) ctx->params->bRepeatHeaders = 1; if (ctx->x265_opts) { AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; if (!av_dict_parse_string(&dict, ctx->x265_opts, "=", ":", 0)) { while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value); switch (parse_ret) { case X265_PARAM_BAD_NAME: av_log(avctx, AV_LOG_WARNING, "Unknown option: %s.\n", en->key); case X265_PARAM_BAD_VALUE: av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: %s.\n", en->key, en->value); default: av_dict_free(&dict); ctx->encoder = ctx->api->encoder_open(ctx->params); if (!ctx->encoder) { av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n"); libx265_encode_close(avctx); if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { x265_nal *nal; int nnal; avctx->extradata_size = ctx->api->encoder_headers(ctx->encoder, &nal, &nnal); if (avctx->extradata_size <= 0) { av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n"); libx265_encode_close(avctx); avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!avctx->extradata) { "Cannot allocate HEVC header of size %d.\n", avctx->extradata_size); libx265_encode_close(avctx); return AVERROR(ENOMEM); memcpy(avctx->extradata, nal[0].payload, avctx->extradata_size); return 0;


static void nbd_coroutine_end(BlockDriverState *bs, NBDRequest *request) { NBDClientSession *s = nbd_get_client_session(bs); int i = HANDLE_TO_INDEX(s, request->handle); s->recv_coroutine[i] = NULL; s->in_flight--; qemu_co_queue_next(&s->free_sema); /* Kick the read_reply_co to get the next reply. */ if (s->read_reply_co) { aio_co_wake(s->read_reply_co); } }


static int dump_init(DumpState *s, int fd, bool has_format, DumpGuestMemoryFormat format, bool paging, bool has_filter, int64_t begin, int64_t length, Error **errp) { CPUState *cpu; int nr_cpus; Error *err = NULL; int ret; /* kdump-compressed is conflict with paging and filter */ if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) { assert(!paging && !has_filter); } if (runstate_is_running()) { vm_stop(RUN_STATE_SAVE_VM); s->resume = true; } else { s->resume = false; } /* If we use KVM, we should synchronize the registers before we get dump * info or physmap info. */ cpu_synchronize_all_states(); nr_cpus = 0; CPU_FOREACH(cpu) { nr_cpus++; } s->fd = fd; s->has_filter = has_filter; s->begin = begin; s->length = length; guest_phys_blocks_init(&s->guest_phys_blocks); guest_phys_blocks_append(&s->guest_phys_blocks); s->start = get_start_block(s); if (s->start == -1) { error_set(errp, QERR_INVALID_PARAMETER, "begin"); goto cleanup; } /* get dump info: endian, class and architecture. * If the target architecture is not supported, cpu_get_dump_info() will * return -1. */ ret = cpu_get_dump_info(&s->dump_info, &s->guest_phys_blocks); if (ret < 0) { error_set(errp, QERR_UNSUPPORTED); goto cleanup; } s->note_size = cpu_get_note_size(s->dump_info.d_class, s->dump_info.d_machine, nr_cpus); if (s->note_size < 0) { error_set(errp, QERR_UNSUPPORTED); goto cleanup; } /* get memory mapping */ memory_mapping_list_init(&s->list); if (paging) { qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err); if (err != NULL) { error_propagate(errp, err); goto cleanup; } } else { qemu_get_guest_simple_memory_mapping(&s->list, &s->guest_phys_blocks); } s->nr_cpus = nr_cpus; get_max_mapnr(s); uint64_t tmp; tmp = DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), TARGET_PAGE_SIZE); s->len_dump_bitmap = tmp * TARGET_PAGE_SIZE; /* init for kdump-compressed format */ if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) { switch (format) { case DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB: s->flag_compress = DUMP_DH_COMPRESSED_ZLIB; break; case DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO: #ifdef CONFIG_LZO if (lzo_init() != LZO_E_OK) { error_setg(errp, "failed to initialize the LZO library"); goto cleanup; } #endif s->flag_compress = DUMP_DH_COMPRESSED_LZO; break; case DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY: s->flag_compress = DUMP_DH_COMPRESSED_SNAPPY; break; default: s->flag_compress = 0; } return 0; } if (s->has_filter) { memory_mapping_filter(&s->list, s->begin, s->length); } /* * calculate phdr_num * * the type of ehdr->e_phnum is uint16_t, so we should avoid overflow */ s->phdr_num = 1; /* PT_NOTE */ if (s->list.num < UINT16_MAX - 2) { s->phdr_num += s->list.num; s->have_section = false; } else { s->have_section = true; s->phdr_num = PN_XNUM; s->sh_info = 1; /* PT_NOTE */ /* the type of shdr->sh_info is uint32_t, so we should avoid overflow */ if (s->list.num <= UINT32_MAX - 1) { s->sh_info += s->list.num; } else { s->sh_info = UINT32_MAX; } } if (s->dump_info.d_class == ELFCLASS64) { if (s->have_section) { s->memory_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info + sizeof(Elf64_Shdr) + s->note_size; } else { s->memory_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num + s->note_size; } } else { if (s->have_section) { s->memory_offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info + sizeof(Elf32_Shdr) + s->note_size; } else { s->memory_offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num + s->note_size; } } return 0; cleanup: guest_phys_blocks_free(&s->guest_phys_blocks); if (s->resume) { vm_start(); } return -1; }


static int64_t ff_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) { return wrap_timestamp(s->streams[stream_index], read_timestamp(s, stream_index, ppos, pos_limit)); }


gboolean vnc_client_io(QIOChannel *ioc G_GNUC_UNUSED, GIOCondition condition, void *opaque) { VncState *vs = opaque; if (condition & G_IO_IN) { vnc_client_read(vs); } if (condition & G_IO_OUT) { vnc_client_write(vs); } return TRUE; }


float128 float128_scalbn( float128 a, int n STATUS_PARAM ) { flag aSign; int32 aExp; uint64_t aSig0, aSig1; aSig1 = extractFloat128Frac1( a ); aSig0 = extractFloat128Frac0( a ); aExp = extractFloat128Exp( a ); aSign = extractFloat128Sign( a ); if ( aExp == 0x7FFF ) { return a; } if ( aExp != 0 ) aSig0 |= LIT64( 0x0001000000000000 ); else if ( aSig0 == 0 && aSig1 == 0 ) return a; aExp += n - 1; return normalizeRoundAndPackFloat128( aSign, aExp, aSig0, aSig1 STATUS_VAR ); }


static void process_synthesis_subpackets(QDM2Context *q, QDM2SubPNode *list) { QDM2SubPNode *nodes[4]; nodes[0] = qdm2_search_subpacket_type_in_list(list, 9); if (nodes[0] != NULL) process_subpacket_9(q, nodes[0]); nodes[1] = qdm2_search_subpacket_type_in_list(list, 10); if (nodes[1] != NULL) process_subpacket_10(q, nodes[1]); else process_subpacket_10(q, NULL); nodes[2] = qdm2_search_subpacket_type_in_list(list, 11); if (nodes[0] != NULL && nodes[1] != NULL && nodes[2] != NULL) process_subpacket_11(q, nodes[2]); else process_subpacket_11(q, NULL); nodes[3] = qdm2_search_subpacket_type_in_list(list, 12); if (nodes[0] != NULL && nodes[1] != NULL && nodes[3] != NULL) process_subpacket_12(q, nodes[3]); else process_subpacket_12(q, NULL); }


static int ffm_read_data(AVFormatContext *s, uint8_t *buf, int size, int header) { FFMContext *ffm = s->priv_data; AVIOContext *pb = s->pb; int len, fill_size, size1, frame_offset, id; int64_t last_pos = -1; size1 = size; while (size > 0) { redo: len = ffm->packet_end - ffm->packet_ptr; if (len < 0) return -1; if (len > size) len = size; if (len == 0) { if (avio_tell(pb) == ffm->file_size) avio_seek(pb, ffm->packet_size, SEEK_SET); retry_read: if (pb->buffer_size != ffm->packet_size) { int64_t tell = avio_tell(pb); ffio_set_buf_size(pb, ffm->packet_size); avio_seek(pb, tell, SEEK_SET); } id = avio_rb16(pb); /* PACKET_ID */ if (id != PACKET_ID) { if (ffm_resync(s, id) < 0) return -1; last_pos = avio_tell(pb); } fill_size = avio_rb16(pb); ffm->dts = avio_rb64(pb); frame_offset = avio_rb16(pb); avio_read(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); if (ffm->packet_end < ffm->packet || frame_offset < 0) return -1; /* if first packet or resynchronization packet, we must handle it specifically */ if (ffm->first_packet || (frame_offset & 0x8000)) { if (!frame_offset) { /* This packet has no frame headers in it */ if (avio_tell(pb) >= ffm->packet_size * 3LL) { int64_t seekback = FFMIN(ffm->packet_size * 2LL, avio_tell(pb) - last_pos); seekback = FFMAX(seekback, 0); avio_seek(pb, -seekback, SEEK_CUR); goto retry_read; } /* This is bad, we cannot find a valid frame header */ return 0; } ffm->first_packet = 0; if ((frame_offset & 0x7fff) < FFM_HEADER_SIZE) return -1; ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE; if (!header) break; } else { ffm->packet_ptr = ffm->packet; } goto redo; } memcpy(buf, ffm->packet_ptr, len); buf += len; ffm->packet_ptr += len; size -= len; header = 0; } return size1 - size; }


static int udp_close(URLContext *h) { UDPContext *s = h->priv_data; int ret; if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); closesocket(s->udp_fd); av_fifo_free(s->fifo); #if HAVE_PTHREADS if (s->thread_started) { pthread_cancel(s->circular_buffer_thread); ret = pthread_join(s->circular_buffer_thread, NULL); if (ret != 0) av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret)); } pthread_mutex_destroy(&s->mutex); pthread_cond_destroy(&s->cond); #endif return 0; }