int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) { struct kvm_msi msi; KVMMSIRoute *route; if (s->direct_msi) { msi.address_lo = (uint32_t)msg.address; msi.address_hi = msg.address >> 32; msi.data = le32_to_cpu(msg.data); msi.flags = 0; memset(msi.pad, 0, sizeof(msi.pad)); return kvm_vm_ioctl(s, KVM_SIGNAL_MSI, &msi); } route = kvm_lookup_msi_route(s, msg); if (!route) { int virq; virq = kvm_irqchip_get_virq(s); if (virq < 0) { return virq; } route = g_malloc(sizeof(KVMMSIRoute)); route->kroute.gsi = virq; route->kroute.type = KVM_IRQ_ROUTING_MSI; route->kroute.flags = 0; route->kroute.u.msi.address_lo = (uint32_t)msg.address; route->kroute.u.msi.address_hi = msg.address >> 32; route->kroute.u.msi.data = le32_to_cpu(msg.data); kvm_add_routing_entry(s, &route->kroute); kvm_irqchip_commit_routes(s); QTAILQ_INSERT_TAIL(&s->msi_hashtab[kvm_hash_msi(msg.data)], route, entry); } assert(route->kroute.type == KVM_IRQ_ROUTING_MSI); return kvm_set_irq(s, route->kroute.gsi, 1); }


void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) { sd->readonly_cb = readonly; sd->inserted_cb = insert; qemu_set_irq(readonly, bdrv_is_read_only(sd->bdrv)); qemu_set_irq(insert, bdrv_is_inserted(sd->bdrv)); }


static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags) { MOVStreamContext *sc = st->priv_data; int sample, time_sample; int i; sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; sc->current_sample = sample; av_log(s, AV_LOG_TRACE, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ if (sc->ctts_data) { time_sample = 0; for (i = 0; i < sc->ctts_count; i++) { int next = time_sample + sc->ctts_data[i].count; if (next > sc->current_sample) { sc->ctts_index = i; sc->ctts_sample = sc->current_sample - time_sample; break; } time_sample = next; } } /* adjust stsd index */ time_sample = 0; for (i = 0; i < sc->stsc_count; i++) { int next = time_sample + mov_get_stsc_samples(sc, i); if (next > sc->current_sample) { sc->stsc_index = i; sc->stsc_sample = sc->current_sample - time_sample; break; } time_sample = next; } return sample; }


static int advanced_decode_i_mbs(VC9Context *v) { MpegEncContext *s = &v->s; GetBitContext *gb = &v->s.gb; int mqdiff, mquant, current_mb = 0, over_flags_mb = 0; for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++) { for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++) { if (v->ac_pred_plane.is_raw) s->ac_pred = get_bits(gb, 1); else s->ac_pred = v->ac_pred_plane.data[current_mb]; if (v->condover == 3 && v->over_flags_plane.is_raw) over_flags_mb = get_bits(gb, 1); GET_MQUANT(); /* TODO: lots */ } current_mb++; } return 0; }


static int altivec_uyvy_rgb32 (SwsContext *c, unsigned char **in, int *instrides, int srcSliceY, int srcSliceH, unsigned char **oplanes, int *outstrides) { int w = c->srcW; int h = srcSliceH; int i,j; vector unsigned char uyvy; vector signed short Y,U,V; vector signed short R0,G0,B0,R1,G1,B1; vector unsigned char R,G,B; vector unsigned char *out; ubyte *img; img = in[0]; out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]); for (i=0;i<h;i++) { for (j=0;j<w/16;j++) { uyvy = vec_ld (0, img); U = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u); V = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v); Y = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y); cvtyuvtoRGB (c, Y,U,V,&R0,&G0,&B0); uyvy = vec_ld (16, img); U = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_u); V = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_v); Y = (vector signed short) vec_perm (uyvy, (vector unsigned char)AVV(0), demux_y); cvtyuvtoRGB (c, Y,U,V,&R1,&G1,&B1); R = vec_packclp (R0,R1); G = vec_packclp (G0,G1); B = vec_packclp (B0,B1); // vec_mstbgr24 (R,G,B, out); out_rgba (R,G,B,out); img += 32; } } return srcSliceH; }


static void test_primitives(gconstpointer opaque) { TestArgs *args = (TestArgs *) opaque; const SerializeOps *ops = args->ops; PrimitiveType *pt = args->test_data; PrimitiveType *pt_copy = g_malloc0(sizeof(*pt_copy)); Error *err = NULL; void *serialize_data; char *double1, *double2; pt_copy->type = pt->type; ops->serialize(pt, &serialize_data, visit_primitive_type, &err); ops->deserialize((void **)&pt_copy, serialize_data, visit_primitive_type, &err); g_assert(err == NULL); g_assert(pt_copy != NULL); if (pt->type == PTYPE_STRING) { g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string); g_free((char *)pt_copy->value.string); } else if (pt->type == PTYPE_NUMBER) { /* we serialize with %f for our reference visitors, so rather than fuzzy * floating math to test "equality", just compare the formatted values */ double1 = g_malloc0(calc_float_string_storage(pt->value.number)); double2 = g_malloc0(calc_float_string_storage(pt_copy->value.number)); g_assert_cmpstr(double1, ==, double2); g_free(double1); g_free(double2); } else if (pt->type == PTYPE_BOOLEAN) { g_assert_cmpint(!!pt->value.max, ==, !!pt->value.max); } else { g_assert_cmpint(pt->value.max, ==, pt_copy->value.max); } ops->cleanup(serialize_data); g_free(args); g_free(pt_copy); }


static int qcow_write_snapshots(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; QCowSnapshotHeader h; int i, name_size, id_str_size, snapshots_size; uint64_t data64; uint32_t data32; int64_t offset, snapshots_offset; /* compute the size of the snapshots */ offset = 0; for(i = 0; i < s->nb_snapshots; i++) { sn = s->snapshots + i; offset = align_offset(offset, 8); offset += sizeof(h); offset += strlen(sn->id_str); offset += strlen(sn->name); } snapshots_size = offset; snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); offset = snapshots_offset; if (offset < 0) { return offset; } for(i = 0; i < s->nb_snapshots; i++) { sn = s->snapshots + i; memset(&h, 0, sizeof(h)); h.l1_table_offset = cpu_to_be64(sn->l1_table_offset); h.l1_size = cpu_to_be32(sn->l1_size); h.vm_state_size = cpu_to_be32(sn->vm_state_size); h.date_sec = cpu_to_be32(sn->date_sec); h.date_nsec = cpu_to_be32(sn->date_nsec); h.vm_clock_nsec = cpu_to_be64(sn->vm_clock_nsec); id_str_size = strlen(sn->id_str); name_size = strlen(sn->name); h.id_str_size = cpu_to_be16(id_str_size); h.name_size = cpu_to_be16(name_size); offset = align_offset(offset, 8); if (bdrv_pwrite(bs->file, offset, &h, sizeof(h)) != sizeof(h)) goto fail; offset += sizeof(h); if (bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size) != id_str_size) goto fail; offset += id_str_size; if (bdrv_pwrite(bs->file, offset, sn->name, name_size) != name_size) goto fail; offset += name_size; } /* update the various header fields */ data64 = cpu_to_be64(snapshots_offset); if (bdrv_pwrite(bs->file, offsetof(QCowHeader, snapshots_offset), &data64, sizeof(data64)) != sizeof(data64)) goto fail; data32 = cpu_to_be32(s->nb_snapshots); if (bdrv_pwrite(bs->file, offsetof(QCowHeader, nb_snapshots), &data32, sizeof(data32)) != sizeof(data32)) goto fail; /* free the old snapshot table */ qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size); s->snapshots_offset = snapshots_offset; s->snapshots_size = snapshots_size; return 0; fail: return -1; }


void sigaction_invoke(struct sigaction *action, struct qemu_signalfd_siginfo *info) { siginfo_t si = { 0 }; si.si_signo = info->ssi_signo; si.si_errno = info->ssi_errno; si.si_code = info->ssi_code; /* Convert the minimal set of fields defined by POSIX. * Positive si_code values are reserved for kernel-generated * signals, where the valid siginfo fields are determined by * the signal number. But according to POSIX, it is unspecified * whether SI_USER and SI_QUEUE have values less than or equal to * zero. */ if (info->ssi_code == SI_USER || info->ssi_code == SI_QUEUE || info->ssi_code <= 0) { /* SIGTERM, etc. */ si.si_pid = info->ssi_pid; si.si_uid = info->ssi_uid; } else if (info->ssi_signo == SIGILL || info->ssi_signo == SIGFPE || info->ssi_signo == SIGSEGV || info->ssi_signo == SIGBUS) { si.si_addr = (void *)(uintptr_t)info->ssi_addr; } else if (info->ssi_signo == SIGCHLD) { si.si_pid = info->ssi_pid; si.si_status = info->ssi_status; si.si_uid = info->ssi_uid; } action->sa_sigaction(info->ssi_signo, &si, NULL); }


static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { PixdescTestContext *priv = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; AVFilterBufferRef *outpicref; int i; outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); outpicref = outlink->out_buf; avfilter_copy_buffer_ref_props(outpicref, picref); for (i = 0; i < 4; i++) { int h = outlink->h; h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h; if (outpicref->data[i]) { uint8_t *data = outpicref->data[i] + (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1)); memset(data, 0, FFABS(outpicref->linesize[i]) * h); } } /* copy palette */ if (priv->pix_desc->flags & PIX_FMT_PAL) memcpy(outpicref->data[1], outpicref->data[1], 256*4); avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0)); }


void av_noreturn exit_program(int ret) { int i, j; for (i = 0; i < nb_filtergraphs; i++) { avfilter_graph_free(&filtergraphs[i]->graph); for (j = 0; j < filtergraphs[i]->nb_inputs; j++) av_freep(&filtergraphs[i]->inputs[j]); av_freep(&filtergraphs[i]->inputs); for (j = 0; j < filtergraphs[i]->nb_outputs; j++) av_freep(&filtergraphs[i]->outputs[j]); av_freep(&filtergraphs[i]->outputs); av_freep(&filtergraphs[i]); } av_freep(&filtergraphs); /* close files */ for (i = 0; i < nb_output_files; i++) { AVFormatContext *s = output_files[i]->ctx; if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) avio_close(s->pb); avformat_free_context(s); av_dict_free(&output_files[i]->opts); av_freep(&output_files[i]); } for (i = 0; i < nb_output_streams; i++) { AVBitStreamFilterContext *bsfc = output_streams[i]->bitstream_filters; while (bsfc) { AVBitStreamFilterContext *next = bsfc->next; av_bitstream_filter_close(bsfc); bsfc = next; } output_streams[i]->bitstream_filters = NULL; if (output_streams[i]->output_frame) { AVFrame *frame = output_streams[i]->output_frame; if (frame->extended_data != frame->data) av_freep(&frame->extended_data); av_freep(&frame); } av_freep(&output_streams[i]->filtered_frame); av_freep(&output_streams[i]); } for (i = 0; i < nb_input_files; i++) { avformat_close_input(&input_files[i]->ctx); av_freep(&input_files[i]); } for (i = 0; i < nb_input_streams; i++) { av_freep(&input_streams[i]->decoded_frame); av_dict_free(&input_streams[i]->opts); free_buffer_pool(input_streams[i]); av_freep(&input_streams[i]->filters); av_freep(&input_streams[i]); } if (vstats_file) fclose(vstats_file); av_free(vstats_filename); av_freep(&input_streams); av_freep(&input_files); av_freep(&output_streams); av_freep(&output_files); uninit_opts(); av_freep(&audio_buf); allocated_audio_buf_size = 0; av_freep(&async_buf); allocated_async_buf_size = 0; avfilter_uninit(); avformat_network_deinit(); if (received_sigterm) { av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n", (int) received_sigterm); exit (255); } exit(ret); /* not all OS-es handle main() return value */ }


static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) { OpenRISCCPU *cpu = (OpenRISCCPU *)opaque; CPUState *cs = CPU(cpu); uint32_t irq_bit = 1 << irq; if (irq > 31 || irq < 0) { return; } if (level) { cpu->env.picsr |= irq_bit; } else { cpu->env.picsr &= ~irq_bit; } if (cpu->env.picsr & cpu->env.picmr) { cpu_interrupt(cs, CPU_INTERRUPT_HARD); } else { cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); cpu->env.picsr = 0; } }


static int mov_read_aclr(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int ret = 0; int length = 0; uint64_t original_size; if (c->fc->nb_streams >= 1) { AVCodecContext *codec = c->fc->streams[c->fc->nb_streams-1]->codec; if (codec->codec_id == AV_CODEC_ID_H264) return 0; if (atom.size == 16) { original_size = codec->extradata_size; ret = mov_realloc_extradata(codec, atom); if (!ret) { length = mov_read_atom_into_extradata(c, pb, atom, codec, codec->extradata + original_size); if (length == atom.size) { const uint8_t range_value = codec->extradata[original_size + 19]; switch (range_value) { case 1: codec->color_range = AVCOL_RANGE_MPEG; break; case 2: codec->color_range = AVCOL_RANGE_JPEG; break; default: av_log(c, AV_LOG_WARNING, "ignored unknown aclr value (%d)\n", range_value); break; } av_dlog(c, "color_range: %d\n", codec->color_range); } else { /* For some reason the whole atom was not added to the extradata */ av_log(c, AV_LOG_ERROR, "aclr not decoded - incomplete atom\n"); } } else { av_log(c, AV_LOG_ERROR, "aclr not decoded - unable to add atom to extradata\n"); } } else { av_log(c, AV_LOG_WARNING, "aclr not decoded - unexpected size %"PRId64"\n", atom.size); } } return ret; }


static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, VP8FilterStrength *f ) { int interior_limit, filter_level; if (s->segmentation.enabled) { filter_level = s->segmentation.filter_level[s->segment]; if (!s->segmentation.absolute_vals) filter_level += s->filter.level; } else filter_level = s->filter.level; if (s->lf_delta.enabled) { filter_level += s->lf_delta.ref[mb->ref_frame]; filter_level += s->lf_delta.mode[mb->mode]; } /* Like av_clip for inputs 0 and max, where max is equal to (2^n-1) */ #define POW2CLIP(x,max) (((x) & ~max) ? (-(x))>>31 & max : (x)); filter_level = POW2CLIP(filter_level, 63); interior_limit = filter_level; if (s->filter.sharpness) { interior_limit >>= s->filter.sharpness > 4 ? 2 : 1; interior_limit = FFMIN(interior_limit, 9 - s->filter.sharpness); } interior_limit = FFMAX(interior_limit, 1); f->filter_level = filter_level; f->inner_limit = interior_limit; f->inner_filter = !mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT; }


void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size) { long i; long num_pixels = src_size >> 1; for(i=0; i<num_pixels; i++) { unsigned b,g,r; register uint16_t rgb; rgb = src[2*i]; r = rgb&0x1F; g = (rgb&0x3E0)>>5; b = (rgb&0x7C00)>>10; dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11); } }


static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int opc) { int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits; #if defined(CONFIG_SOFTMMU) uint32_t *label1_ptr, *label2_ptr; data_reg = *args++; addr_reg = *args++; mem_index = *args; s_bits = opc & 3; arg0 = TCG_REG_O0; arg1 = TCG_REG_O1; arg2 = TCG_REG_O2; #if defined(CONFIG_SOFTMMU) /* srl addr_reg, x, arg1 */ tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS, SHIFT_SRL); tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1), ARITH_AND); /* and arg1, x, arg1 */ tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS); /* add arg1, x, arg1 */ tcg_out_addi(s, arg1, offsetof(CPUState, tlb_table[mem_index][0].addr_read)); /* add env, arg1, arg1 */ tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD); /* ld [arg1], arg2 */ tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) | INSN_RS2(TCG_REG_G0)); /* subcc arg0, arg2, %g0 */ tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC); /* will become: be label1 */ label1_ptr = (uint32_t *)s->code_ptr; tcg_out32(s, 0); /* mov (delay slot) */ tcg_out_mov(s, arg0, addr_reg); /* mov */ tcg_out_movi(s, TCG_TYPE_I32, arg1, mem_index); /* XXX: move that code at the end of the TB */ /* qemu_ld_helper[s_bits](arg0, arg1) */ tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits] - (tcg_target_ulong)s->code_ptr) >> 2) & 0x3fffffff)); /* Store AREG0 in stack to avoid ugly glibc bugs that mangle global registers */ // delay slot tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_ST_OP); tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK, TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_LD_OP); /* data_reg = sign_extend(arg0) */ switch(opc) { case 0 | 4: /* sll arg0, 24/56, data_reg */ tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8, HOST_SLL_OP); /* sra data_reg, 24/56, data_reg */ tcg_out_arithi(s, data_reg, data_reg, (int)sizeof(tcg_target_long) * 8 - 8, HOST_SRA_OP); break; case 1 | 4: /* sll arg0, 16/48, data_reg */ tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 16, HOST_SLL_OP); /* sra data_reg, 16/48, data_reg */ tcg_out_arithi(s, data_reg, data_reg, (int)sizeof(tcg_target_long) * 8 - 16, HOST_SRA_OP); break; case 2 | 4: /* sll arg0, 32, data_reg */ tcg_out_arithi(s, data_reg, arg0, 32, HOST_SLL_OP); /* sra data_reg, 32, data_reg */ tcg_out_arithi(s, data_reg, data_reg, 32, HOST_SRA_OP); break; case 0: case 1: case 2: case 3: default: /* mov */ tcg_out_mov(s, data_reg, arg0); break; } /* will become: ba label2 */ label2_ptr = (uint32_t *)s->code_ptr; tcg_out32(s, 0); /* nop (delay slot */ tcg_out_nop(s); /* label1: */ *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) | INSN_OFF22((unsigned long)s->code_ptr - (unsigned long)label1_ptr)); /* ld [arg1 + x], arg1 */ tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) - offsetof(CPUTLBEntry, addr_read), HOST_LD_OP); /* add addr_reg, arg1, arg0 */ tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD); arg0 = addr_reg; switch(opc) { case 0: /* ldub [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDUB); break; case 0 | 4: /* ldsb [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDSB); break; case 1: #ifdef TARGET_WORDS_BIGENDIAN /* lduh [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDUH); /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */ tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE); break; case 1 | 4: #ifdef TARGET_WORDS_BIGENDIAN /* ldsh [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDSH); /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */ tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE); break; case 2: #ifdef TARGET_WORDS_BIGENDIAN /* lduw [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDUW); /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */ tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE); break; case 2 | 4: #ifdef TARGET_WORDS_BIGENDIAN /* ldsw [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDSW); /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */ tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE); break; case 3: #ifdef TARGET_WORDS_BIGENDIAN /* ldx [arg0], data_reg */ tcg_out_ldst(s, data_reg, arg0, 0, LDX); /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */ tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE); break; default: tcg_abort(); } #if defined(CONFIG_SOFTMMU) /* label2: */ *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) | INSN_OFF22((unsigned long)s->code_ptr - (unsigned long)label2_ptr)); }


static int mxf_read_index_table_segment(MXFIndexTableSegment *segment, ByteIOContext *pb, int tag) { switch(tag) { case 0x3F05: dprintf(NULL, "EditUnitByteCount %d\n", get_be32(pb)); break; case 0x3F06: dprintf(NULL, "IndexSID %d\n", get_be32(pb)); break; case 0x3F07: dprintf(NULL, "BodySID %d\n", get_be32(pb)); break; case 0x3F0B: dprintf(NULL, "IndexEditRate %d/%d\n", get_be32(pb), get_be32(pb)); break; case 0x3F0C: dprintf(NULL, "IndexStartPosition %lld\n", get_be64(pb)); break; case 0x3F0D: dprintf(NULL, "IndexDuration %lld\n", get_be64(pb)); break; } return 0; }


static const char *vnc_auth_name(VncDisplay *vd) { switch (vd->auth) { case VNC_AUTH_INVALID: return "invalid"; case VNC_AUTH_NONE: return "none"; case VNC_AUTH_VNC: return "vnc"; case VNC_AUTH_RA2: return "ra2"; case VNC_AUTH_RA2NE: return "ra2ne"; case VNC_AUTH_TIGHT: return "tight"; case VNC_AUTH_ULTRA: return "ultra"; case VNC_AUTH_TLS: return "tls"; case VNC_AUTH_VENCRYPT: #ifdef CONFIG_VNC_TLS switch (vd->subauth) { case VNC_AUTH_VENCRYPT_PLAIN: return "vencrypt+plain"; case VNC_AUTH_VENCRYPT_TLSNONE: return "vencrypt+tls+none"; case VNC_AUTH_VENCRYPT_TLSVNC: return "vencrypt+tls+vnc"; case VNC_AUTH_VENCRYPT_TLSPLAIN: return "vencrypt+tls+plain"; case VNC_AUTH_VENCRYPT_X509NONE: return "vencrypt+x509+none"; case VNC_AUTH_VENCRYPT_X509VNC: return "vencrypt+x509+vnc"; case VNC_AUTH_VENCRYPT_X509PLAIN: return "vencrypt+x509+plain"; case VNC_AUTH_VENCRYPT_TLSSASL: return "vencrypt+tls+sasl"; case VNC_AUTH_VENCRYPT_X509SASL: return "vencrypt+x509+sasl"; default: return "vencrypt"; } #else return "vencrypt"; #endif case VNC_AUTH_SASL: return "sasl"; } return "unknown"; }


static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp) { CPUX86State *env = &cpu->env; x86_def_t def1, *def = &def1; memset(def, 0, sizeof(*def)); if (cpu_x86_find_by_name(cpu, def, name) < 0) { error_setg(errp, "Unable to find CPU definition: %s", name); return; } if (kvm_enabled()) { def->features[FEAT_KVM] |= kvm_default_features; } def->features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR; object_property_set_str(OBJECT(cpu), def->vendor, "vendor", errp); object_property_set_int(OBJECT(cpu), def->level, "level", errp); object_property_set_int(OBJECT(cpu), def->family, "family", errp); object_property_set_int(OBJECT(cpu), def->model, "model", errp); object_property_set_int(OBJECT(cpu), def->stepping, "stepping", errp); env->features[FEAT_1_EDX] = def->features[FEAT_1_EDX]; env->features[FEAT_1_ECX] = def->features[FEAT_1_ECX]; env->features[FEAT_8000_0001_EDX] = def->features[FEAT_8000_0001_EDX]; env->features[FEAT_8000_0001_ECX] = def->features[FEAT_8000_0001_ECX]; object_property_set_int(OBJECT(cpu), def->xlevel, "xlevel", errp); env->features[FEAT_KVM] = def->features[FEAT_KVM]; env->features[FEAT_SVM] = def->features[FEAT_SVM]; env->features[FEAT_C000_0001_EDX] = def->features[FEAT_C000_0001_EDX]; env->features[FEAT_7_0_EBX] = def->features[FEAT_7_0_EBX]; env->cpuid_xlevel2 = def->xlevel2; object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp); }


int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf1, int count1) { BlockDriver *drv = bs->drv; if (!drv) return -ENOMEDIUM; if (!drv->bdrv_pwrite) return bdrv_pwrite_em(bs, offset, buf1, count1); return drv->bdrv_pwrite(bs, offset, buf1, count1); }


static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) { enum PixelFormat dstFormat = c->dstFormat; //FIXME Optimize (just quickly written not optimized..) int i; for (i=0; i<dstW; i++) { int val=1<<18; int j; for (j=0; j<lumFilterSize; j++) val += lumSrc[j][i] * lumFilter[j]; dest[i]= av_clip_uint8(val>>19); } if (!uDest) return; if (dstFormat == PIX_FMT_NV12) for (i=0; i<chrDstW; i++) { int u=1<<18; int v=1<<18; int j; for (j=0; j<chrFilterSize; j++) { u += chrUSrc[j][i] * chrFilter[j]; v += chrVSrc[j][i] * chrFilter[j]; } uDest[2*i]= av_clip_uint8(u>>19); uDest[2*i+1]= av_clip_uint8(v>>19); } else for (i=0; i<chrDstW; i++) { int u=1<<18; int v=1<<18; int j; for (j=0; j<chrFilterSize; j++) { u += chrUSrc[j][i] * chrFilter[j]; v += chrVSrc[j][i] * chrFilter[j]; } uDest[2*i]= av_clip_uint8(v>>19); uDest[2*i+1]= av_clip_uint8(u>>19); } }


static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes, QEMUIOVector *qiov, CoroutineEntry co_entry, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) { BlkAioEmAIOCB *acb; Coroutine *co; bdrv_inc_in_flight(blk_bs(blk)); acb = blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco = (BlkRwCo) { .blk = blk, .offset = offset, .qiov = qiov, .flags = flags, .ret = NOT_DONE, }; acb->bytes = bytes; acb->has_returned = false; co = qemu_coroutine_create(co_entry, acb); qemu_coroutine_enter(co); acb->has_returned = true; if (acb->rwco.ret != NOT_DONE) { aio_bh_schedule_oneshot(blk_get_aio_context(blk), blk_aio_complete_bh, acb); } return &acb->common; }


static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int buf_size2) { MpegEncContext *s = avctx->priv_data; int mb_count, mb_pos, left, start_mb_x; init_get_bits(&s->gb, buf, buf_size*8); if(s->codec_id ==CODEC_ID_RV10) mb_count = rv10_decode_picture_header(s); else mb_count = rv20_decode_picture_header(s); if (mb_count < 0) { av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n"); return -1; } if (s->mb_x >= s->mb_width || s->mb_y >= s->mb_height) { av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y); return -1; } mb_pos = s->mb_y * s->mb_width + s->mb_x; left = s->mb_width * s->mb_height - mb_pos; if (mb_count > left) { av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n"); return -1; } if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) { if(s->current_picture_ptr){ //FIXME write parser so we always have complete frames? ff_er_frame_end(s); ff_MPV_frame_end(s); s->mb_x= s->mb_y = s->resync_mb_x = s->resync_mb_y= 0; } if(ff_MPV_frame_start(s, avctx) < 0) return -1; ff_er_frame_start(s); } else { if (s->current_picture_ptr->f.pict_type != s->pict_type) { av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); return -1; } } av_dlog(avctx, "qscale=%d\n", s->qscale); /* default quantization values */ if(s->codec_id== CODEC_ID_RV10){ if(s->mb_y==0) s->first_slice_line=1; }else{ s->first_slice_line=1; s->resync_mb_x= s->mb_x; } start_mb_x= s->mb_x; s->resync_mb_y= s->mb_y; if(s->h263_aic){ s->y_dc_scale_table= s->c_dc_scale_table= ff_aic_dc_scale_table; }else{ s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg1_dc_scale_table; } if(s->modified_quant) s->chroma_qscale_table= ff_h263_chroma_qscale_table; ff_set_qscale(s, s->qscale); s->rv10_first_dc_coded[0] = 0; s->rv10_first_dc_coded[1] = 0; s->rv10_first_dc_coded[2] = 0; s->block_wrap[0]= s->block_wrap[1]= s->block_wrap[2]= s->block_wrap[3]= s->b8_stride; s->block_wrap[4]= s->block_wrap[5]= s->mb_stride; ff_init_block_index(s); /* decode each macroblock */ for(s->mb_num_left= mb_count; s->mb_num_left>0; s->mb_num_left--) { int ret; ff_update_block_index(s); av_dlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y); s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; ret=ff_h263_decode_mb(s, s->block); if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){ av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2); s->gb.size_in_bits= 8*buf_size2; ret= SLICE_OK; } if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) { av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y); return -1; } if(s->pict_type != AV_PICTURE_TYPE_B) ff_h263_update_motion_val(s); ff_MPV_decode_mb(s, s->block); if(s->loop_filter) ff_h263_loop_filter(s); if (++s->mb_x == s->mb_width) { s->mb_x = 0; s->mb_y++; ff_init_block_index(s); } if(s->mb_x == s->resync_mb_x) s->first_slice_line=0; if(ret == SLICE_END) break; } ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return s->gb.size_in_bits; }


static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, struct iovec *iov, int niov, bool create, enum AIOCBState aiocb_type) { int nr_copies = s->inode.nr_copies; SheepdogObjReq hdr; unsigned int wlen = 0; int ret; uint64_t oid = aio_req->oid; unsigned int datalen = aio_req->data_len; uint64_t offset = aio_req->offset; uint8_t flags = aio_req->flags; uint64_t old_oid = aio_req->base_oid; if (!nr_copies) { error_report("bug"); } memset(&hdr, 0, sizeof(hdr)); switch (aiocb_type) { case AIOCB_FLUSH_CACHE: hdr.opcode = SD_OP_FLUSH_VDI; break; case AIOCB_READ_UDATA: hdr.opcode = SD_OP_READ_OBJ; hdr.flags = flags; break; case AIOCB_WRITE_UDATA: if (create) { hdr.opcode = SD_OP_CREATE_AND_WRITE_OBJ; } else { hdr.opcode = SD_OP_WRITE_OBJ; } wlen = datalen; hdr.flags = SD_FLAG_CMD_WRITE | flags; break; case AIOCB_DISCARD_OBJ: hdr.opcode = SD_OP_DISCARD_OBJ; break; } if (s->cache_flags) { hdr.flags |= s->cache_flags; } hdr.oid = oid; hdr.cow_oid = old_oid; hdr.copies = s->inode.nr_copies; hdr.data_length = datalen; hdr.offset = offset; hdr.id = aio_req->id; qemu_co_mutex_lock(&s->lock); s->co_send = qemu_coroutine_self(); aio_set_fd_handler(s->aio_context, s->fd, co_read_response, co_write_request, s); socket_set_cork(s->fd, 1); /* send a header */ ret = qemu_co_send(s->fd, &hdr, sizeof(hdr)); if (ret != sizeof(hdr)) { error_report("failed to send a req, %s", strerror(errno)); goto out; } if (wlen) { ret = qemu_co_sendv(s->fd, iov, niov, aio_req->iov_offset, wlen); if (ret != wlen) { error_report("failed to send a data, %s", strerror(errno)); } } out: socket_set_cork(s->fd, 0); aio_set_fd_handler(s->aio_context, s->fd, co_read_response, NULL, s); s->co_send = NULL; qemu_co_mutex_unlock(&s->lock); }


static void init_proc_750gx (CPUPPCState *env) { gen_spr_ne_601(env); gen_spr_7xx(env); /* XXX : not implemented (XXX: different from 750fx) */ spr_register(env, SPR_L2CR, "L2CR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, NULL, 0x00000000); /* Time base */ gen_tbl(env); /* Thermal management */ gen_spr_thrm(env); /* XXX : not implemented */ spr_register(env, SPR_750_THRM4, "THRM4", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* Hardware implementation registers */ /* XXX : not implemented (XXX: different from 750fx) */ spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_HID1, "HID1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented (XXX: different from 750fx) */ spr_register(env, SPR_750FX_HID2, "HID2", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* Memory management */ gen_low_BATs(env); /* PowerPC 750fx & 750gx has 8 DBATs and 8 IBATs */ gen_high_BATs(env); init_excp_7x0(env); env->dcache_line_size = 32; env->icache_line_size = 32; /* Allocate hardware IRQ controller */ ppc6xx_irq_init(env); }


static int cloop_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVCloopState *s = bs->opaque; uint32_t offsets_size, max_compressed_block_size = 1, i; int ret; bs->read_only = 1; /* read header */ ret = bdrv_pread(bs->file, 128, &s->block_size, 4); if (ret < 0) { return ret; } s->block_size = be32_to_cpu(s->block_size); if (s->block_size % 512) { error_setg(errp, "block_size %u must be a multiple of 512", s->block_size); return -EINVAL; } if (s->block_size == 0) { error_setg(errp, "block_size cannot be zero"); return -EINVAL; } /* cloop's create_compressed_fs.c warns about block sizes beyond 256 KB but * we can accept more. Prevent ridiculous values like 4 GB - 1 since we * need a buffer this big. */ if (s->block_size > MAX_BLOCK_SIZE) { error_setg(errp, "block_size %u must be %u MB or less", s->block_size, MAX_BLOCK_SIZE / (1024 * 1024)); return -EINVAL; } ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4); if (ret < 0) { return ret; } s->n_blocks = be32_to_cpu(s->n_blocks); /* read offsets */ if (s->n_blocks > UINT32_MAX / sizeof(uint64_t)) { /* Prevent integer overflow */ error_setg(errp, "n_blocks %u must be %zu or less", s->n_blocks, UINT32_MAX / sizeof(uint64_t)); return -EINVAL; } offsets_size = s->n_blocks * sizeof(uint64_t); if (offsets_size > 512 * 1024 * 1024) { /* Prevent ridiculous offsets_size which causes memory allocation to * fail or overflows bdrv_pread() size. In practice the 512 MB * offsets[] limit supports 16 TB images at 256 KB block size. */ error_setg(errp, "image requires too many offsets, " "try increasing block size"); return -EINVAL; } s->offsets = g_malloc(offsets_size); ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size); if (ret < 0) { goto fail; } for(i=0;i<s->n_blocks;i++) { s->offsets[i] = be64_to_cpu(s->offsets[i]); if (i > 0) { uint32_t size = s->offsets[i] - s->offsets[i - 1]; if (size > max_compressed_block_size) { max_compressed_block_size = size; } } } /* initialize zlib engine */ s->compressed_block = g_malloc(max_compressed_block_size + 1); s->uncompressed_block = g_malloc(s->block_size); if (inflateInit(&s->zstream) != Z_OK) { ret = -EINVAL; goto fail; } s->current_block = s->n_blocks; s->sectors_per_block = s->block_size/512; bs->total_sectors = s->n_blocks * s->sectors_per_block; qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->offsets); g_free(s->compressed_block); g_free(s->uncompressed_block); return ret; }


static void spapr_tce_table_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_spapr_tce_table; dc->init = spapr_tce_table_realize; dc->reset = spapr_tce_reset; QLIST_INIT(&spapr_tce_tables); /* hcall-tce */ spapr_register_hypercall(H_PUT_TCE, h_put_tce); }


static void gmc1_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture) { uint8_t *ptr; int src_x, src_y, motion_x, motion_y; ptrdiff_t offset, linesize, uvlinesize; int emu = 0; motion_x = s->sprite_offset[0][0]; motion_y = s->sprite_offset[0][1]; src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1)); src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1)); motion_x <<= (3 - s->sprite_warping_accuracy); motion_y <<= (3 - s->sprite_warping_accuracy); src_x = av_clip(src_x, -16, s->width); if (src_x == s->width) motion_x = 0; src_y = av_clip(src_y, -16, s->height); if (src_y == s->height) motion_y = 0; linesize = s->linesize; uvlinesize = s->uvlinesize; ptr = ref_picture[0] + src_y * linesize + src_x; if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) { s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, linesize, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); ptr = s->sc.edge_emu_buffer; } if ((motion_x | motion_y) & 7) { s->mdsp.gmc1(dest_y, ptr, linesize, 16, motion_x & 15, motion_y & 15, 128 - s->no_rounding); s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16, motion_x & 15, motion_y & 15, 128 - s->no_rounding); } else { int dxy; dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2); if (s->no_rounding) { s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); } else { s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); } } if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY) return; motion_x = s->sprite_offset[1][0]; motion_y = s->sprite_offset[1][1]; src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1)); src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1)); motion_x <<= (3 - s->sprite_warping_accuracy); motion_y <<= (3 - s->sprite_warping_accuracy); src_x = av_clip(src_x, -8, s->width >> 1); if (src_x == s->width >> 1) motion_x = 0; src_y = av_clip(src_y, -8, s->height >> 1); if (src_y == s->height >> 1) motion_y = 0; offset = (src_y * uvlinesize) + src_x; ptr = ref_picture[1] + offset; if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) || (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) { s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, uvlinesize, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ptr = s->sc.edge_emu_buffer; emu = 1; } s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x & 15, motion_y & 15, 128 - s->no_rounding); ptr = ref_picture[2] + offset; if (emu) { s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, uvlinesize, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ptr = s->sc.edge_emu_buffer; } s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x & 15, motion_y & 15, 128 - s->no_rounding); }


static void gxf_write_padding(ByteIOContext *pb, offset_t to_pad) { while (to_pad--) { put_byte(pb, 0); } }


static int aea_read_header(AVFormatContext *s) { AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); /* Parse the amount of channels and skip to pos 2048(0x800) */ avio_skip(s->pb, 264); st->codec->channels = avio_r8(s->pb); avio_skip(s->pb, 1783); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = AV_CODEC_ID_ATRAC1; st->codec->sample_rate = 44100; st->codec->bit_rate = 292000; if (st->codec->channels != 1 && st->codec->channels != 2) { av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); return -1; } st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; st->codec->block_align = AT1_SU_SIZE * st->codec->channels; return 0; }


static void spr_write_ibatl (void *opaque, int sprn) { DisasContext *ctx = opaque; gen_op_store_ibatl((sprn - SPR_IBAT0L) / 2); RET_STOP(ctx); }


static void gen_eob_inhibit_irq(DisasContext *s, bool inhibit) { gen_update_cc_op(s); /* If several instructions disable interrupts, only the first does it. */ if (inhibit && !(s->flags & HF_INHIBIT_IRQ_MASK)) { gen_set_hflag(s, HF_INHIBIT_IRQ_MASK); } else { gen_reset_hflag(s, HF_INHIBIT_IRQ_MASK); } if (s->tb->flags & HF_RF_MASK) { gen_helper_reset_rf(cpu_env); } if (s->singlestep_enabled) { gen_helper_debug(cpu_env); } else if (s->tf) { gen_helper_single_step(cpu_env); } else { tcg_gen_exit_tb(0); } s->is_jmp = DISAS_TB_JUMP; }


void tb_invalidate_page_range(target_ulong start, target_ulong end) { /* XXX: cannot enable it yet because it yields to MMU exception where NIP != read address on PowerPC */ #if 0 target_ulong phys_addr; phys_addr = get_phys_addr_code(env, start); tb_invalidate_phys_page_range(phys_addr, phys_addr + end - start, 0); #endif }


static bool kvmppc_is_pr(KVMState *ks) { /* Assume KVM-PR if the GET_PVINFO capability is available */ return kvm_check_extension(ks, KVM_CAP_PPC_GET_PVINFO) != 0; }


void aio_set_fd_handler(AioContext *ctx, int fd, IOHandler *io_read, IOHandler *io_write, AioFlushHandler *io_flush, void *opaque) { AioHandler *node; node = find_aio_handler(ctx, fd); /* Are we deleting the fd handler? */ if (!io_read && !io_write) { if (node) { /* If the lock is held, just mark the node as deleted */ if (ctx->walking_handlers) node->deleted = 1; else { /* Otherwise, delete it for real. We can't just mark it as * deleted because deleted nodes are only cleaned up after * releasing the walking_handlers lock. */ QLIST_REMOVE(node, node); g_free(node); } } } else { if (node == NULL) { /* Alloc and insert if it's not already there */ node = g_malloc0(sizeof(AioHandler)); node->fd = fd; QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node); } /* Update handler with latest information */ node->io_read = io_read; node->io_write = io_write; node->io_flush = io_flush; node->opaque = opaque; } }


static uint64_t gic_do_cpu_read(void *opaque, target_phys_addr_t addr, unsigned size) { GICState **backref = (GICState **)opaque; GICState *s = *backref; int id = (backref - s->backref); return gic_cpu_read(s, id, addr); }


void bdrv_io_unplug(BlockDriverState *bs) { BlockDriver *drv = bs->drv; if (drv && drv->bdrv_io_unplug) { drv->bdrv_io_unplug(bs); } else if (bs->file) { bdrv_io_unplug(bs->file->bs); } }


static void ehci_advance_async_state(EHCIState *ehci) { const int async = 1; switch(ehci_get_state(ehci, async)) { case EST_INACTIVE: if (!ehci_async_enabled(ehci)) { break; } ehci_set_state(ehci, async, EST_ACTIVE); // No break, fall through to ACTIVE case EST_ACTIVE: if (!ehci_async_enabled(ehci)) { ehci_queues_rip_all(ehci, async); ehci_set_state(ehci, async, EST_INACTIVE); break; } /* make sure guest has acknowledged the doorbell interrupt */ /* TO-DO: is this really needed? */ if (ehci->usbsts & USBSTS_IAA) { DPRINTF("IAA status bit still set.\n"); break; } /* check that address register has been set */ if (ehci->asynclistaddr == 0) { break; } ehci_set_state(ehci, async, EST_WAITLISTHEAD); ehci_advance_state(ehci, async); /* If the doorbell is set, the guest wants to make a change to the * schedule. The host controller needs to release cached data. * (section 4.8.2) */ if (ehci->usbcmd & USBCMD_IAAD) { /* Remove all unseen qhs from the async qhs queue */ ehci_queues_rip_unused(ehci, async, 1); DPRINTF("ASYNC: doorbell request acknowledged\n"); ehci->usbcmd &= ~USBCMD_IAAD; ehci_set_interrupt(ehci, USBSTS_IAA); } break; default: /* this should only be due to a developer mistake */ fprintf(stderr, "ehci: Bad asynchronous state %d. " "Resetting to active\n", ehci->astate); assert(0); } }


static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVIOContext *pb = s->pb; RPLContext *rpl = s->priv_data; AVStream *vst = NULL, *ast = NULL; int total_audio_size; int error = 0; uint32_t i; int32_t audio_format, chunk_catalog_offset, number_of_chunks; AVRational fps; char line[RPL_LINE_LENGTH]; // The header for RPL/ARMovie files is 21 lines of text // containing the various header fields. The fields are always // in the same order, and other text besides the first // number usually isn't important. // (The spec says that there exists some significance // for the text in a few cases; samples needed.) error |= read_line(pb, line, sizeof(line)); // ARMovie error |= read_line(pb, line, sizeof(line)); // movie name av_dict_set(&s->metadata, "title" , line, 0); error |= read_line(pb, line, sizeof(line)); // date/copyright av_dict_set(&s->metadata, "copyright", line, 0); error |= read_line(pb, line, sizeof(line)); // author and other av_dict_set(&s->metadata, "author" , line, 0); // video headers vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_tag = read_line_and_int(pb, &error); // video format vst->codec->width = read_line_and_int(pb, &error); // video width vst->codec->height = read_line_and_int(pb, &error); // video height vst->codec->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample error |= read_line(pb, line, sizeof(line)); // video frames per second fps = read_fps(line, &error); avpriv_set_pts_info(vst, 32, fps.den, fps.num); // Figure out the video codec switch (vst->codec->codec_tag) { #if 0 case 122: vst->codec->codec_id = CODEC_ID_ESCAPE122; break; #endif case 124: vst->codec->codec_id = CODEC_ID_ESCAPE124; // The header is wrong here, at least sometimes vst->codec->bits_per_coded_sample = 16; break; case 130: vst->codec->codec_id = CODEC_ID_ESCAPE130; break; default: av_log(s, AV_LOG_WARNING, "RPL video format %i not supported yet!\n", vst->codec->codec_tag); vst->codec->codec_id = CODEC_ID_NONE; } // Audio headers // ARMovie supports multiple audio tracks; I don't have any // samples, though. This code will ignore additional tracks. audio_format = read_line_and_int(pb, &error); // audio format ID if (audio_format) { ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_tag = audio_format; ast->codec->sample_rate = read_line_and_int(pb, &error); // audio bitrate ast->codec->channels = read_line_and_int(pb, &error); // number of audio channels ast->codec->bits_per_coded_sample = read_line_and_int(pb, &error); // audio bits per sample // At least one sample uses 0 for ADPCM, which is really 4 bits // per sample. if (ast->codec->bits_per_coded_sample == 0) ast->codec->bits_per_coded_sample = 4; ast->codec->bit_rate = ast->codec->sample_rate * ast->codec->bits_per_coded_sample * ast->codec->channels; ast->codec->codec_id = CODEC_ID_NONE; switch (audio_format) { case 1: if (ast->codec->bits_per_coded_sample == 16) { // 16-bit audio is always signed ast->codec->codec_id = CODEC_ID_PCM_S16LE; break; } // There are some other formats listed as legal per the spec; // samples needed. break; case 101: if (ast->codec->bits_per_coded_sample == 8) { // The samples with this kind of audio that I have // are all unsigned. ast->codec->codec_id = CODEC_ID_PCM_U8; break; } else if (ast->codec->bits_per_coded_sample == 4) { ast->codec->codec_id = CODEC_ID_ADPCM_IMA_EA_SEAD; break; } break; } if (ast->codec->codec_id == CODEC_ID_NONE) { av_log(s, AV_LOG_WARNING, "RPL audio format %i not supported yet!\n", audio_format); } avpriv_set_pts_info(ast, 32, 1, ast->codec->bit_rate); } else { for (i = 0; i < 3; i++) error |= read_line(pb, line, sizeof(line)); } rpl->frames_per_chunk = read_line_and_int(pb, &error); // video frames per chunk if (rpl->frames_per_chunk > 1 && vst->codec->codec_tag != 124) av_log(s, AV_LOG_WARNING, "Don't know how to split frames for video format %i. " "Video stream will be broken!\n", vst->codec->codec_tag); number_of_chunks = read_line_and_int(pb, &error); // number of chunks in the file // The number in the header is actually the index of the last chunk. number_of_chunks++; error |= read_line(pb, line, sizeof(line)); // "even" chunk size in bytes error |= read_line(pb, line, sizeof(line)); // "odd" chunk size in bytes chunk_catalog_offset = // offset of the "chunk catalog" read_line_and_int(pb, &error); // (file index) error |= read_line(pb, line, sizeof(line)); // offset to "helpful" sprite error |= read_line(pb, line, sizeof(line)); // size of "helpful" sprite error |= read_line(pb, line, sizeof(line)); // offset to key frame list // Read the index avio_seek(pb, chunk_catalog_offset, SEEK_SET); total_audio_size = 0; for (i = 0; i < number_of_chunks; i++) { int64_t offset, video_size, audio_size; error |= read_line(pb, line, sizeof(line)); if (3 != sscanf(line, "%"PRId64" , %"PRId64" ; %"PRId64, &offset, &video_size, &audio_size)) error = -1; av_add_index_entry(vst, offset, i * rpl->frames_per_chunk, video_size, rpl->frames_per_chunk, 0); if (ast) av_add_index_entry(ast, offset + video_size, total_audio_size, audio_size, audio_size * 8, 0); total_audio_size += audio_size * 8; } if (error) return AVERROR(EIO); return 0; }


static QDict *monitor_parse_arguments(Monitor *mon, const char **endp, const mon_cmd_t *cmd) { const char *typestr; char *key; int c; const char *p = *endp; char buf[1024]; QDict *qdict = qdict_new(); /* parse the parameters */ typestr = cmd->args_type; for(;;) { typestr = key_get_info(typestr, &key); if (!typestr) break; c = *typestr; typestr++; switch(c) { case 'F': case 'B': case 's': { int ret; while (qemu_isspace(*p)) p++; if (*typestr == '?') { typestr++; if (*p == '\0') { /* no optional string: NULL argument */ break; } } ret = get_str(buf, sizeof(buf), &p); if (ret < 0) { switch(c) { case 'F': monitor_printf(mon, "%s: filename expected\n", cmd->name); break; case 'B': monitor_printf(mon, "%s: block device name expected\n", cmd->name); break; default: monitor_printf(mon, "%s: string expected\n", cmd->name); break; } goto fail; } qdict_put(qdict, key, qstring_from_str(buf)); } break; case 'O': { QemuOptsList *opts_list; QemuOpts *opts; opts_list = qemu_find_opts(key); if (!opts_list || opts_list->desc->name) { goto bad_type; } while (qemu_isspace(*p)) { p++; } if (!*p) break; if (get_str(buf, sizeof(buf), &p) < 0) { goto fail; } opts = qemu_opts_parse_noisily(opts_list, buf, true); if (!opts) { goto fail; } qemu_opts_to_qdict(opts, qdict); qemu_opts_del(opts); } break; case '/': { int count, format, size; while (qemu_isspace(*p)) p++; if (*p == '/') { /* format found */ p++; count = 1; if (qemu_isdigit(*p)) { count = 0; while (qemu_isdigit(*p)) { count = count * 10 + (*p - '0'); p++; } } size = -1; format = -1; for(;;) { switch(*p) { case 'o': case 'd': case 'u': case 'x': case 'i': case 'c': format = *p++; break; case 'b': size = 1; p++; break; case 'h': size = 2; p++; break; case 'w': size = 4; p++; break; case 'g': case 'L': size = 8; p++; break; default: goto next; } } next: if (*p != '\0' && !qemu_isspace(*p)) { monitor_printf(mon, "invalid char in format: '%c'\n", *p); goto fail; } if (format < 0) format = default_fmt_format; if (format != 'i') { /* for 'i', not specifying a size gives -1 as size */ if (size < 0) size = default_fmt_size; default_fmt_size = size; } default_fmt_format = format; } else { count = 1; format = default_fmt_format; if (format != 'i') { size = default_fmt_size; } else { size = -1; } } qdict_put(qdict, "count", qint_from_int(count)); qdict_put(qdict, "format", qint_from_int(format)); qdict_put(qdict, "size", qint_from_int(size)); } break; case 'i': case 'l': case 'M': { int64_t val; while (qemu_isspace(*p)) p++; if (*typestr == '?' || *typestr == '.') { if (*typestr == '?') { if (*p == '\0') { typestr++; break; } } else { if (*p == '.') { p++; while (qemu_isspace(*p)) p++; } else { typestr++; break; } } typestr++; } if (get_expr(mon, &val, &p)) goto fail; /* Check if 'i' is greater than 32-bit */ if ((c == 'i') && ((val >> 32) & 0xffffffff)) { monitor_printf(mon, "\'%s\' has failed: ", cmd->name); monitor_printf(mon, "integer is for 32-bit values\n"); goto fail; } else if (c == 'M') { if (val < 0) { monitor_printf(mon, "enter a positive value\n"); goto fail; } val <<= 20; } qdict_put(qdict, key, qint_from_int(val)); } break; case 'o': { int64_t val; char *end; while (qemu_isspace(*p)) { p++; } if (*typestr == '?') { typestr++; if (*p == '\0') { break; } } val = qemu_strtosz_MiB(p, &end); if (val < 0) { monitor_printf(mon, "invalid size\n"); goto fail; } qdict_put(qdict, key, qint_from_int(val)); p = end; } break; case 'T': { double val; while (qemu_isspace(*p)) p++; if (*typestr == '?') { typestr++; if (*p == '\0') { break; } } if (get_double(mon, &val, &p) < 0) { goto fail; } if (p[0] && p[1] == 's') { switch (*p) { case 'm': val /= 1e3; p += 2; break; case 'u': val /= 1e6; p += 2; break; case 'n': val /= 1e9; p += 2; break; } } if (*p && !qemu_isspace(*p)) { monitor_printf(mon, "Unknown unit suffix\n"); goto fail; } qdict_put(qdict, key, qfloat_from_double(val)); } break; case 'b': { const char *beg; bool val; while (qemu_isspace(*p)) { p++; } beg = p; while (qemu_isgraph(*p)) { p++; } if (p - beg == 2 && !memcmp(beg, "on", p - beg)) { val = true; } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { val = false; } else { monitor_printf(mon, "Expected 'on' or 'off'\n"); goto fail; } qdict_put(qdict, key, qbool_from_bool(val)); } break; case '-': { const char *tmp = p; int skip_key = 0; /* option */ c = *typestr++; if (c == '\0') goto bad_type; while (qemu_isspace(*p)) p++; if (*p == '-') { p++; if(c != *p) { if(!is_valid_option(p, typestr)) { monitor_printf(mon, "%s: unsupported option -%c\n", cmd->name, *p); goto fail; } else { skip_key = 1; } } if(skip_key) { p = tmp; } else { /* has option */ p++; qdict_put(qdict, key, qbool_from_bool(true)); } } } break; case 'S': { /* package all remaining string */ int len; while (qemu_isspace(*p)) { p++; } if (*typestr == '?') { typestr++; if (*p == '\0') { /* no remaining string: NULL argument */ break; } } len = strlen(p); if (len <= 0) { monitor_printf(mon, "%s: string expected\n", cmd->name); goto fail; } qdict_put(qdict, key, qstring_from_str(p)); p += len; } break; default: bad_type: monitor_printf(mon, "%s: unknown type '%c'\n", cmd->name, c); goto fail; } g_free(key); key = NULL; } /* check that all arguments were parsed */ while (qemu_isspace(*p)) p++; if (*p != '\0') { monitor_printf(mon, "%s: extraneous characters at the end of line\n", cmd->name); goto fail; } return qdict; fail: QDECREF(qdict); g_free(key); return NULL; }


static void visitor_input_teardown(TestInputVisitorData *data, const void *unused) { qobject_decref(data->obj); data->obj = NULL; if (data->qiv) { visit_free(data->qiv); data->qiv = NULL; } }


MigrationState *migrate_get_current(void) { static bool once; static MigrationState current_migration = { .state = MIGRATION_STATUS_NONE, .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, .mbps = -1, .parameters = { .compress_level = DEFAULT_MIGRATE_COMPRESS_LEVEL, .compress_threads = DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT, .decompress_threads = DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT, .cpu_throttle_initial = DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL, .cpu_throttle_increment = DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT, .max_bandwidth = MAX_THROTTLE, .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME, .x_checkpoint_delay = DEFAULT_MIGRATE_X_CHECKPOINT_DELAY, }, }; if (!once) { current_migration.parameters.tls_creds = g_strdup(""); current_migration.parameters.tls_hostname = g_strdup(""); once = true; } return &current_migration; }


static int coroutine_fn qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb = opaque; BDRVQEDState *s = acb_to_s(acb); BlockDriverState *bs = acb->bs; /* Adjust offset into cluster */ offset += qed_offset_into_cluster(s, acb->cur_pos); trace_qed_aio_read_data(s, acb, ret, offset, len); qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); /* Handle zero cluster and backing file reads */ if (ret == QED_CLUSTER_ZERO) { qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size); return 0; } else if (ret != QED_CLUSTER_FOUND) { return qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, &acb->backing_qiov); } BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); ret = bdrv_co_preadv(bs->file, offset, acb->cur_qiov.size, &acb->cur_qiov, 0); if (ret < 0) { return ret; } return 0; }


static void portio_list_add_1(PortioList *piolist, const MemoryRegionPortio *pio_init, unsigned count, unsigned start, unsigned off_low, unsigned off_high) { MemoryRegionPortio *pio; MemoryRegionOps *ops; MemoryRegion *region, *alias; unsigned i; /* Copy the sub-list and null-terminate it. */ pio = g_new(MemoryRegionPortio, count + 1); memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count); memset(pio + count, 0, sizeof(MemoryRegionPortio)); /* Adjust the offsets to all be zero-based for the region. */ for (i = 0; i < count; ++i) { pio[i].offset -= off_low; } ops = g_new0(MemoryRegionOps, 1); ops->old_portio = pio; region = g_new(MemoryRegion, 1); alias = g_new(MemoryRegion, 1); /* * Use an alias so that the callback is called with an absolute address, * rather than an offset relative to to start + off_low. */ memory_region_init_io(region, ops, piolist->opaque, piolist->name, INT64_MAX); memory_region_init_alias(alias, piolist->name, region, start + off_low, off_high - off_low); memory_region_add_subregion(piolist->address_space, start + off_low, alias); piolist->regions[piolist->nr] = region; piolist->aliases[piolist->nr] = alias; ++piolist->nr; }


static int bochs_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { int ret; while (nb_sectors > 0) { int64_t block_offset = seek_to_sector(bs, sector_num); if (block_offset >= 0) { ret = bdrv_pread(bs->file, block_offset, buf, 512); if (ret != 512) { return -1; } } else memset(buf, 0, 512); nb_sectors--; sector_num++; buf += 512; } return 0; }


static void visit_nested_struct_list(Visitor *v, void **native, Error **errp) { visit_type_UserDefNestedList(v, (UserDefNestedList **)native, NULL, errp); }


int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Context *h0) { unsigned int first_mb_in_slice; unsigned int pps_id; int ret; unsigned int slice_type, tmp, i, j; int default_ref_list_done = 0; int last_pic_structure, last_pic_droppable; int needs_reinit = 0; int field_pic_flag, bottom_field_flag; h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab; h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab; first_mb_in_slice = get_ue_golomb(&h->gb); if (first_mb_in_slice == 0) { // FIXME better field boundary detection if (h0->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) { ff_h264_field_end(h, sl, 1); } h0->current_slice = 0; if (!h0->first_field) { if (h->cur_pic_ptr && !h->droppable) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, h->picture_structure == PICT_BOTTOM_FIELD); } h->cur_pic_ptr = NULL; } } slice_type = get_ue_golomb_31(&h->gb); if (slice_type > 9) { av_log(h->avctx, AV_LOG_ERROR, "slice type %d too large at %d %d\n", slice_type, h->mb_x, h->mb_y); return AVERROR_INVALIDDATA; } if (slice_type > 4) { slice_type -= 5; sl->slice_type_fixed = 1; } else sl->slice_type_fixed = 0; slice_type = golomb_to_pict_type[slice_type]; if (slice_type == AV_PICTURE_TYPE_I || (h0->current_slice != 0 && slice_type == h0->last_slice_type)) { default_ref_list_done = 1; } sl->slice_type = slice_type; sl->slice_type_nos = slice_type & 3; if (h->nal_unit_type == NAL_IDR_SLICE && sl->slice_type_nos != AV_PICTURE_TYPE_I) { av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); return AVERROR_INVALIDDATA; } // to make a few old functions happy, it's wrong though h->pict_type = sl->slice_type; pps_id = get_ue_golomb(&h->gb); if (pps_id >= MAX_PPS_COUNT) { av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); return AVERROR_INVALIDDATA; } if (!h0->pps_buffers[pps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id); return AVERROR_INVALIDDATA; } h->pps = *h0->pps_buffers[pps_id]; if (!h0->sps_buffers[h->pps.sps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id); return AVERROR_INVALIDDATA; } if (h->pps.sps_id != h->sps.sps_id || h0->sps_buffers[h->pps.sps_id]->new) { h0->sps_buffers[h->pps.sps_id]->new = 0; h->sps = *h0->sps_buffers[h->pps.sps_id]; if (h->bit_depth_luma != h->sps.bit_depth_luma || h->chroma_format_idc != h->sps.chroma_format_idc) { h->bit_depth_luma = h->sps.bit_depth_luma; h->chroma_format_idc = h->sps.chroma_format_idc; needs_reinit = 1; } if ((ret = ff_h264_set_parameter_from_sps(h)) < 0) return ret; } h->avctx->profile = ff_h264_get_profile(&h->sps); h->avctx->level = h->sps.level_idc; h->avctx->refs = h->sps.ref_frame_count; if (h->mb_width != h->sps.mb_width || h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag)) needs_reinit = 1; h->mb_width = h->sps.mb_width; h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->mb_num = h->mb_width * h->mb_height; h->mb_stride = h->mb_width + 1; h->b_stride = h->mb_width * 4; h->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p h->width = 16 * h->mb_width; h->height = 16 * h->mb_height; ret = init_dimensions(h); if (ret < 0) return ret; if (h->sps.video_signal_type_present_flag) { h->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if (h->sps.colour_description_present_flag) { if (h->avctx->colorspace != h->sps.colorspace) needs_reinit = 1; h->avctx->color_primaries = h->sps.color_primaries; h->avctx->color_trc = h->sps.color_trc; h->avctx->colorspace = h->sps.colorspace; } } if (h->context_initialized && needs_reinit) { if (h != h0) { av_log(h->avctx, AV_LOG_ERROR, "changing width %d -> %d / height %d -> %d on " "slice %d\n", h->width, h->avctx->coded_width, h->height, h->avctx->coded_height, h0->current_slice + 1); return AVERROR_INVALIDDATA; } ff_h264_flush_change(h); if ((ret = get_pixel_format(h)) < 0) return ret; h->avctx->pix_fmt = ret; av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, " "pix_fmt: %d\n", h->width, h->height, h->avctx->pix_fmt); if ((ret = h264_slice_header_init(h, 1)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (!h->context_initialized) { if (h != h0) { av_log(h->avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); return AVERROR_PATCHWELCOME; } if ((ret = get_pixel_format(h)) < 0) return ret; h->avctx->pix_fmt = ret; if ((ret = h264_slice_header_init(h, 0)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (h == h0 && h->dequant_coeff_pps != pps_id) { h->dequant_coeff_pps = pps_id; h264_init_dequant_tables(h); } h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num); h->mb_mbaff = 0; h->mb_aff_frame = 0; last_pic_structure = h0->picture_structure; last_pic_droppable = h0->droppable; h->droppable = h->nal_ref_idc == 0; if (h->sps.frame_mbs_only_flag) { h->picture_structure = PICT_FRAME; } else { field_pic_flag = get_bits1(&h->gb); if (field_pic_flag) { bottom_field_flag = get_bits1(&h->gb); h->picture_structure = PICT_TOP_FIELD + bottom_field_flag; } else { h->picture_structure = PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } h->mb_field_decoding_flag = h->picture_structure != PICT_FRAME; if (h0->current_slice != 0) { if (last_pic_structure != h->picture_structure || last_pic_droppable != h->droppable) { av_log(h->avctx, AV_LOG_ERROR, "Changing field mode (%d -> %d) between slices is not allowed\n", last_pic_structure, h->picture_structure); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; } else if (!h0->cur_pic_ptr) { av_log(h->avctx, AV_LOG_ERROR, "unset cur_pic_ptr on slice %d\n", h0->current_slice + 1); return AVERROR_INVALIDDATA; } } else { /* Shorten frame num gaps so we don't have to allocate reference * frames just to throw them away */ if (h->frame_num != h->prev_frame_num) { int unwrap_prev_frame_num = h->prev_frame_num; int max_frame_num = 1 << h->sps.log2_max_frame_num; if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num; if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) { unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1; if (unwrap_prev_frame_num < 0) unwrap_prev_frame_num += max_frame_num; h->prev_frame_num = unwrap_prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * Here, we're using that to see if we should mark previously * decode frames as "finished". * We have to do that before the "dummy" in-between frame allocation, * since that can modify s->current_picture_ptr. */ if (h0->first_field) { assert(h0->cur_pic_ptr); assert(h0->cur_pic_ptr->f.buf[0]); assert(h0->cur_pic_ptr->reference != DELAYED_PIC_REF); /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ if (!last_pic_droppable && last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h0->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { if (h0->cur_pic_ptr->frame_num != h->frame_num) { /* This and previous field were reference, but had * different frame_nums. Consider this field first in * pair. Throw away previous field except for reference * purposes. */ if (!last_pic_droppable && last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h0->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { /* Second field in complementary pair */ if (!((last_pic_structure == PICT_TOP_FIELD && h->picture_structure == PICT_BOTTOM_FIELD) || (last_pic_structure == PICT_BOTTOM_FIELD && h->picture_structure == PICT_TOP_FIELD))) { av_log(h->avctx, AV_LOG_ERROR, "Invalid field mode combination %d/%d\n", last_pic_structure, h->picture_structure); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; } else if (last_pic_droppable != h->droppable) { avpriv_request_sample(h->avctx, "Found reference and non-reference fields in the same frame, which"); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_PATCHWELCOME; } } } } while (h->frame_num != h->prev_frame_num && h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) { H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); ret = h264_frame_start(h); if (ret < 0) { h0->first_field = 0; return ret; } h->prev_frame_num++; h->prev_frame_num %= 1 << h->sps.log2_max_frame_num; h->cur_pic_ptr->frame_num = h->prev_frame_num; ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); ret = ff_generate_sliding_window_mmcos(h, 1); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; /* Error concealment: If a ref is missing, copy the previous ref * in its place. * FIXME: Avoiding a memcpy would be nice, but ref handling makes * many assumptions about there being no actual duplicates. * FIXME: This does not copy padding for out-of-frame motion * vectors. Given we are concealing a lost frame, this probably * is not noticeable by comparison, but it should be fixed. */ if (h->short_ref_count) { if (prev) { av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, (const uint8_t **)prev->f.data, prev->f.linesize, h->avctx->pix_fmt, h->mb_width * 16, h->mb_height * 16); h->short_ref[0]->poc = prev->poc + 2; } h->short_ref[0]->frame_num = h->prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * We're using that to see whether to continue decoding in that * frame, or to allocate a new one. */ if (h0->first_field) { assert(h0->cur_pic_ptr); assert(h0->cur_pic_ptr->f.buf[0]); assert(h0->cur_pic_ptr->reference != DELAYED_PIC_REF); /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ h0->cur_pic_ptr = NULL; h0->first_field = FIELD_PICTURE(h); } else { if (h0->cur_pic_ptr->frame_num != h->frame_num) { /* This and the previous field had different frame_nums. * Consider this field first in pair. Throw away previous * one except for reference purposes. */ h0->first_field = 1; h0->cur_pic_ptr = NULL; } else { /* Second field in complementary pair */ h0->first_field = 0; } } } else { /* Frame or first field in a potentially complementary pair */ h0->first_field = FIELD_PICTURE(h); } if (!FIELD_PICTURE(h) || h0->first_field) { if (h264_frame_start(h) < 0) { h0->first_field = 0; return AVERROR_INVALIDDATA; } } else { release_unused_pictures(h, 0); } } if (h != h0 && (ret = clone_slice(h, h0)) < 0) return ret; h->cur_pic_ptr->frame_num = h->frame_num; // FIXME frame_num cleanup assert(h->mb_num == h->mb_width * h->mb_height); if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || first_mb_in_slice >= h->mb_num) { av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return AVERROR_INVALIDDATA; } h->resync_mb_x = h->mb_x = first_mb_in_slice % h->mb_width; h->resync_mb_y = h->mb_y = (first_mb_in_slice / h->mb_width) << FIELD_OR_MBAFF_PICTURE(h); if (h->picture_structure == PICT_BOTTOM_FIELD) h->resync_mb_y = h->mb_y = h->mb_y + 1; assert(h->mb_y < h->mb_height); if (h->picture_structure == PICT_FRAME) { h->curr_pic_num = h->frame_num; h->max_pic_num = 1 << h->sps.log2_max_frame_num; } else { h->curr_pic_num = 2 * h->frame_num + 1; h->max_pic_num = 1 << (h->sps.log2_max_frame_num + 1); } if (h->nal_unit_type == NAL_IDR_SLICE) get_ue_golomb(&h->gb); /* idr_pic_id */ if (h->sps.poc_type == 0) { h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc_bottom = get_se_golomb(&h->gb); } if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) { h->delta_poc[0] = get_se_golomb(&h->gb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc[1] = get_se_golomb(&h->gb); } ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc); if (h->pps.redundant_pic_cnt_present) h->redundant_pic_count = get_ue_golomb(&h->gb); ret = ff_set_ref_count(h, sl); if (ret < 0) return ret; else if (ret == 1) default_ref_list_done = 0; if (!default_ref_list_done) ff_h264_fill_default_ref_list(h, sl); if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { ret = ff_h264_decode_ref_pic_list_reordering(h, sl); if (ret < 0) { sl->ref_count[1] = sl->ref_count[0] = 0; return ret; } } if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B)) ff_pred_weight_table(h, sl); else if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, -1); } else { sl->use_weight = 0; for (i = 0; i < 2; i++) { sl->luma_weight_flag[i] = 0; sl->chroma_weight_flag[i] = 0; } } // If frame-mt is enabled, only update mmco tables for the first slice // in a field. Subsequent slices can temporarily clobber h->mmco_index // or h->mmco, which will cause ref list mix-ups and decoding errors // further down the line. This may break decoding if the first slice is // corrupt, thus we only do this if frame-mt is enabled. if (h->nal_ref_idc) { ret = ff_h264_decode_ref_pic_marking(h0, &h->gb, !(h->avctx->active_thread_type & FF_THREAD_FRAME) || h0->current_slice == 0); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return AVERROR_INVALIDDATA; } if (FRAME_MBAFF(h)) { ff_h264_fill_mbaff_ref_list(h, sl); if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, 0); implicit_weight_table(h, sl, 1); } } if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) ff_h264_direct_dist_scale_factor(h, sl); ff_h264_direct_ref_list_init(h, sl); if (sl->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) { tmp = get_ue_golomb_31(&h->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); return AVERROR_INVALIDDATA; } h->cabac_init_idc = tmp; } sl->last_qscale_diff = 0; tmp = h->pps.init_qp + get_se_golomb(&h->gb); if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) { av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return AVERROR_INVALIDDATA; } sl->qscale = tmp; sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale); sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale); // FIXME qscale / qp ... stuff if (sl->slice_type == AV_PICTURE_TYPE_SP) get_bits1(&h->gb); /* sp_for_switch_flag */ if (sl->slice_type == AV_PICTURE_TYPE_SP || sl->slice_type == AV_PICTURE_TYPE_SI) get_se_golomb(&h->gb); /* slice_qs_delta */ h->deblocking_filter = 1; h->slice_alpha_c0_offset = 0; h->slice_beta_offset = 0; if (h->pps.deblocking_filter_parameters_present) { tmp = get_ue_golomb_31(&h->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return AVERROR_INVALIDDATA; } h->deblocking_filter = tmp; if (h->deblocking_filter < 2) h->deblocking_filter ^= 1; // 1<->0 if (h->deblocking_filter) { h->slice_alpha_c0_offset = get_se_golomb(&h->gb) * 2; h->slice_beta_offset = get_se_golomb(&h->gb) * 2; if (h->slice_alpha_c0_offset > 12 || h->slice_alpha_c0_offset < -12 || h->slice_beta_offset > 12 || h->slice_beta_offset < -12) { av_log(h->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", h->slice_alpha_c0_offset, h->slice_beta_offset); return AVERROR_INVALIDDATA; } } } if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) h->deblocking_filter = 0; if (h->deblocking_filter == 1 && h0->max_contexts > 1) { if (h->avctx->flags2 & CODEC_FLAG2_FAST) { /* Cheat slightly for speed: * Do not bother to deblock across slices. */ h->deblocking_filter = 2; } else { h0->max_contexts = 1; if (!h0->single_decode_warning) { av_log(h->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); h0->single_decode_warning = 1; } if (h != h0) { av_log(h->avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); return 1; } } } sl->qp_thresh = 15 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]) + 6 * (h->sps.bit_depth_luma - 8); h0->last_slice_type = slice_type; sl->slice_num = ++h0->current_slice; if (sl->slice_num >= MAX_SLICES) { av_log(h->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n"); } for (j = 0; j < 2; j++) { int id_list[16]; int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; for (i = 0; i < 16; i++) { id_list[i] = 60; if (j < sl->list_count && i < sl->ref_count[j] && sl->ref_list[j][i].f.buf[0]) { int k; AVBuffer *buf = sl->ref_list[j][i].f.buf[0]->buffer; for (k = 0; k < h->short_ref_count; k++) if (h->short_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = k; break; } for (k = 0; k < h->long_ref_count; k++) if (h->long_ref[k] && h->long_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = h->short_ref_count + k; break; } } } ref2frm[0] = ref2frm[1] = -1; for (i = 0; i < 16; i++) ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); ref2frm[18 + 0] = ref2frm[18 + 1] = -1; for (i = 16; i < 48; i++) ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + (sl->ref_list[j][i].reference & 3); } if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", sl->slice_num, (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_picture_type_char(sl->slice_type), sl->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", pps_id, h->frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], sl->ref_count[0], sl->ref_count[1], sl->qscale, h->deblocking_filter, h->slice_alpha_c0_offset, h->slice_beta_offset, sl->use_weight, sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "", sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); } return 0; }


Object *qio_task_get_source(QIOTask *task) { object_ref(task->source); return task->source; }


static void gen_ldx(DisasContext *dc, uint32_t code, uint32_t flags) { I_TYPE(instr, code); TCGv addr = tcg_temp_new(); TCGv data; /* * WARNING: Loads into R_ZERO are ignored, but we must generate the * memory access itself to emulate the CPU precisely. Load * from a protected page to R_ZERO will cause SIGSEGV on * the Nios2 CPU. */ if (likely(instr.b != R_ZERO)) { data = dc->cpu_R[instr.b]; } else { data = tcg_temp_new(); } tcg_gen_addi_tl(addr, load_gpr(dc, instr.a), instr.imm16s); tcg_gen_qemu_ld_tl(data, addr, dc->mem_idx, flags); if (unlikely(instr.b == R_ZERO)) { tcg_temp_free(data); } tcg_temp_free(addr); }


static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { MpegTSContext *ts = s->priv_data; int64_t pos; int pos47 = ts->pos47_full % ts->raw_packet_size; pos = ((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) * ts->raw_packet_size + pos47; ff_read_frame_flush(s); if (avio_seek(s->pb, pos, SEEK_SET) < 0) return AV_NOPTS_VALUE; while(pos < pos_limit) { int ret; AVPacket pkt; av_init_packet(&pkt); ret= av_read_frame(s, &pkt); if(ret < 0) return AV_NOPTS_VALUE; av_free_packet(&pkt); if(pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0){ ff_reduce_index(s, pkt.stream_index); av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); if(pkt.stream_index == stream_index){ *ppos= pkt.pos; return pkt.dts; } } pos = pkt.pos; } return AV_NOPTS_VALUE; }


static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m) { BDRVQcowState *s = bs->opaque; int l2_index; uint64_t *l2_table; uint64_t entry; unsigned int nb_clusters; int ret; uint64_t alloc_cluster_offset; trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset, *bytes); assert(*bytes > 0); /* * Calculate the number of clusters to look for. We stop at L2 table * boundaries to keep things simple. */ nb_clusters = size_to_clusters(s, offset_into_cluster(s, guest_offset) + *bytes); l2_index = offset_to_l2_index(s, guest_offset); nb_clusters = MIN(nb_clusters, s->l2_size - l2_index); /* Find L2 entry for the first involved cluster */ ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index); if (ret < 0) { return ret; entry = be64_to_cpu(l2_table[l2_index]); /* For the moment, overwrite compressed clusters one by one */ if (entry & QCOW_OFLAG_COMPRESSED) { nb_clusters = 1; } else { nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index); /* This function is only called when there were no non-COW clusters, so if * we can't find any unallocated or COW clusters either, something is * wrong with our code. */ assert(nb_clusters > 0); ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); if (ret < 0) { return ret; /* Allocate, if necessary at a given offset in the image file */ alloc_cluster_offset = start_of_cluster(s, *host_offset); ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset, &nb_clusters); if (ret < 0) { /* Can't extend contiguous allocation */ if (nb_clusters == 0) { *bytes = 0; return 0; /* * Save info needed for meta data update. * * requested_sectors: Number of sectors from the start of the first * newly allocated cluster to the end of the (possibly shortened * before) write request. * * avail_sectors: Number of sectors from the start of the first * newly allocated to the end of the last newly allocated cluster. * * nb_sectors: The number of sectors from the start of the first * newly allocated cluster to the end of the area that the write * request actually writes to (excluding COW at the end) */ int requested_sectors = (*bytes + offset_into_cluster(s, guest_offset)) >> BDRV_SECTOR_BITS; int avail_sectors = nb_clusters << (s->cluster_bits - BDRV_SECTOR_BITS); int alloc_n_start = offset_into_cluster(s, guest_offset) >> BDRV_SECTOR_BITS; int nb_sectors = MIN(requested_sectors, avail_sectors); QCowL2Meta *old_m = *m; *m = g_malloc0(sizeof(**m)); **m = (QCowL2Meta) { .next = old_m, .alloc_offset = alloc_cluster_offset, .offset = start_of_cluster(s, guest_offset), .nb_clusters = nb_clusters, .nb_available = nb_sectors, .cow_start = { .offset = 0, .nb_sectors = alloc_n_start, }, .cow_end = { .offset = nb_sectors * BDRV_SECTOR_SIZE, .nb_sectors = avail_sectors - nb_sectors, }, }; qemu_co_queue_init(&(*m)->dependent_requests); QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); *host_offset = alloc_cluster_offset + offset_into_cluster(s, guest_offset); *bytes = MIN(*bytes, (nb_sectors * BDRV_SECTOR_SIZE) - offset_into_cluster(s, guest_offset)); assert(*bytes != 0); return 1; fail: if (*m && (*m)->nb_clusters > 0) { QLIST_REMOVE(*m, next_in_flight); return ret;


static int rv10_decode_frame(AVCodecContext *avctx, void *data, int *data_size, UINT8 *buf, int buf_size) { MpegEncContext *s = avctx->priv_data; int i, mb_count, mb_pos, left; DCTELEM block[6][64]; AVPicture *pict = data; #ifdef DEBUG printf("*****frame %d size=%d\n", avctx->frame_number, buf_size); #endif /* no supplementary picture */ if (buf_size == 0) { *data_size = 0; return 0; } init_get_bits(&s->gb, buf, buf_size); mb_count = rv10_decode_picture_header(s); if (mb_count < 0) { #ifdef DEBUG printf("HEADER ERROR\n"); #endif return -1; } if (s->mb_x >= s->mb_width || s->mb_y >= s->mb_height) { #ifdef DEBUG printf("POS ERROR %d %d\n", s->mb_x, s->mb_y); #endif return -1; } mb_pos = s->mb_y * s->mb_width + s->mb_x; left = s->mb_width * s->mb_height - mb_pos; if (mb_count > left) { #ifdef DEBUG printf("COUNT ERROR\n"); #endif return -1; } if (s->mb_x == 0 && s->mb_y == 0) { MPV_frame_start(s, avctx); } #ifdef DEBUG printf("qscale=%d\n", s->qscale); #endif /* default quantization values */ s->y_dc_scale = 8; s->c_dc_scale = 8; s->rv10_first_dc_coded[0] = 0; s->rv10_first_dc_coded[1] = 0; s->rv10_first_dc_coded[2] = 0; s->block_wrap[0]= s->block_wrap[1]= s->block_wrap[2]= s->block_wrap[3]= s->mb_width*2 + 2; s->block_wrap[4]= s->block_wrap[5]= s->mb_width + 2; s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2; s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1) + s->mb_x*2; s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2; s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2) + s->mb_x*2; s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; /* decode each macroblock */ for(i=0;i<mb_count;i++) { s->block_index[0]+=2; s->block_index[1]+=2; s->block_index[2]+=2; s->block_index[3]+=2; s->block_index[4]++; s->block_index[5]++; #ifdef DEBUG printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); #endif memset(block, 0, sizeof(block)); s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; if (h263_decode_mb(s, block) < 0) { #ifdef DEBUG printf("ERROR\n"); #endif return -1; } MPV_decode_mb(s, block); if (++s->mb_x == s->mb_width) { s->mb_x = 0; s->mb_y++; s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1; s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1); s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1; s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2); s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); } } if (s->mb_x == 0 && s->mb_y == s->mb_height) { MPV_frame_end(s); pict->data[0] = s->current_picture[0]; pict->data[1] = s->current_picture[1]; pict->data[2] = s->current_picture[2]; pict->linesize[0] = s->linesize; pict->linesize[1] = s->uvlinesize; pict->linesize[2] = s->uvlinesize; avctx->quality = s->qscale; *data_size = sizeof(AVPicture); } else { *data_size = 0; } return buf_size; }


static int http_open(URLContext *h, const char *uri, int flags) { HTTPContext *s = h->priv_data; h->is_streamed = 1; s->filesize = -1; av_strlcpy(s->location, uri, sizeof(s->location)); if (s->headers) { int len = strlen(s->headers); if (len < 2 || strcmp("\r\n", s->headers + len - 2)) av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n"); } return http_open_cnx(h); }


static inline void softusb_read_pmem(MilkymistSoftUsbState *s, uint32_t offset, uint8_t *buf, uint32_t len) { if (offset + len >= s->pmem_size) { error_report("milkymist_softusb: read pmem out of bounds " "at offset 0x%x, len %d", offset, len); return; } memcpy(buf, s->pmem_ptr + offset, len); }


int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { int i, ret; const uint8_t *src2[4] = { srcSlice[0], srcSlice[1], srcSlice[2], srcSlice[3] }; uint8_t *dst2[4] = { dst[0], dst[1], dst[2], dst[3] }; uint8_t *rgb0_tmp = NULL; // do not mess up sliceDir if we have a "trailing" 0-size slice if (srcSliceH == 0) return 0; if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) { av_log(c, AV_LOG_ERROR, "bad src image pointers\n"); return 0; } if (!check_image_pointers((const uint8_t* const*)dst, c->dstFormat, dstStride)) { av_log(c, AV_LOG_ERROR, "bad dst image pointers\n"); return 0; } if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); return 0; } if (c->sliceDir == 0) { if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; } if (usePal(c->srcFormat)) { for (i = 0; i < 256; i++) { int p, r, g, b, y, u, v, a = 0xff; if (c->srcFormat == AV_PIX_FMT_PAL8) { p = ((const uint32_t *)(srcSlice[1]))[i]; a = (p >> 24) & 0xFF; r = (p >> 16) & 0xFF; g = (p >> 8) & 0xFF; b = p & 0xFF; } else if (c->srcFormat == AV_PIX_FMT_RGB8) { r = ( i >> 5 ) * 36; g = ((i >> 2) & 7) * 36; b = ( i & 3) * 85; } else if (c->srcFormat == AV_PIX_FMT_BGR8) { b = ( i >> 6 ) * 85; g = ((i >> 3) & 7) * 36; r = ( i & 7) * 36; } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) { r = ( i >> 3 ) * 255; g = ((i >> 1) & 3) * 85; b = ( i & 1) * 255; } else if (c->srcFormat == AV_PIX_FMT_GRAY8 || c->srcFormat == AV_PIX_FMT_GRAY8A) { r = g = b = i; } else { av_assert1(c->srcFormat == AV_PIX_FMT_BGR4_BYTE); b = ( i >> 3 ) * 255; g = ((i >> 1) & 3) * 85; r = ( i & 1) * 255; } #define RGB2YUV_SHIFT 15 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); c->pal_yuv[i]= y + (u<<8) + (v<<16) + (a<<24); switch (c->dstFormat) { case AV_PIX_FMT_BGR32: #if !HAVE_BIGENDIAN case AV_PIX_FMT_RGB24: #endif c->pal_rgb[i]= r + (g<<8) + (b<<16) + (a<<24); break; case AV_PIX_FMT_BGR32_1: #if HAVE_BIGENDIAN case AV_PIX_FMT_BGR24: #endif c->pal_rgb[i]= a + (r<<8) + (g<<16) + (b<<24); break; case AV_PIX_FMT_RGB32_1: #if HAVE_BIGENDIAN case AV_PIX_FMT_RGB24: #endif c->pal_rgb[i]= a + (b<<8) + (g<<16) + (r<<24); break; case AV_PIX_FMT_RGB32: #if !HAVE_BIGENDIAN case AV_PIX_FMT_BGR24: #endif default: c->pal_rgb[i]= b + (g<<8) + (r<<16) + (a<<24); } } } if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) { uint8_t *base; int x,y; rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32); base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp; for (y=0; y<srcSliceH; y++){ memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->srcW); for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) { base[ srcStride[0]*y + x] = 0xFF; } } src2[0] = base; } // copy strides, so they can safely be modified if (c->sliceDir == 1) { // slices go from top to bottom int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2], srcStride[3] }; int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2], dstStride[3] }; reset_ptr(src2, c->srcFormat); reset_ptr((void*)dst2, c->dstFormat); /* reset slice direction at end of frame */ if (srcSliceY + srcSliceH == c->srcH) c->sliceDir = 0; ret = c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2, dstStride2); } else { // slices go from bottom to top => we flip the image internally int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2], -srcStride[3] }; int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2], -dstStride[3] }; src2[0] += (srcSliceH - 1) * srcStride[0]; if (!usePal(c->srcFormat)) src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1]; src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2]; src2[3] += (srcSliceH - 1) * srcStride[3]; dst2[0] += ( c->dstH - 1) * dstStride[0]; dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1]; dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2]; dst2[3] += ( c->dstH - 1) * dstStride[3]; reset_ptr(src2, c->srcFormat); reset_ptr((void*)dst2, c->dstFormat); /* reset slice direction at end of frame */ if (!srcSliceY) c->sliceDir = 0; ret = c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); } av_free(rgb0_tmp); return ret; }


static av_cold int MPA_encode_init(AVCodecContext *avctx) { MpegAudioContext *s = avctx->priv_data; int freq = avctx->sample_rate; int bitrate = avctx->bit_rate; int channels = avctx->channels; int i, v, table; float a; if (channels <= 0 || channels > 2){ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels); return AVERROR(EINVAL); } bitrate = bitrate / 1000; s->nb_channels = channels; avctx->frame_size = MPA_FRAME_SIZE; avctx->delay = 512 - 32 + 1; /* encoding freq */ s->lsf = 0; for(i=0;i<3;i++) { if (avpriv_mpa_freq_tab[i] == freq) break; if ((avpriv_mpa_freq_tab[i] / 2) == freq) { s->lsf = 1; break; } } if (i == 3){ av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); return AVERROR(EINVAL); } s->freq_index = i; /* encoding bitrate & frequency */ for(i=0;i<15;i++) { if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate) break; } if (i == 15){ av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); return AVERROR(EINVAL); } s->bitrate_index = i; /* compute total header size & pad bit */ a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0); s->frame_size = ((int)a) * 8; /* frame fractional size to compute padding */ s->frame_frac = 0; s->frame_frac_incr = (int)((a - floor(a)) * 65536.0); /* select the right allocation table */ table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf); /* number of used subbands */ s->sblimit = ff_mpa_sblimit_table[table]; s->alloc_table = ff_mpa_alloc_tables[table]; av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n", bitrate, freq, s->frame_size, table, s->frame_frac_incr); for(i=0;i<s->nb_channels;i++) s->samples_offset[i] = 0; for(i=0;i<257;i++) { int v; v = ff_mpa_enwindow[i]; #if WFRAC_BITS != 16 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); #endif s->filter_bank[i] = v; if ((i & 63) != 0) v = -v; if (i != 0) s->filter_bank[512 - i] = v; } for(i=0;i<64;i++) { v = (int)(exp2((3 - i) / 3.0) * (1 << 20)); if (v <= 0) v = 1; s->scale_factor_table[i] = v; #if USE_FLOATS s->scale_factor_inv_table[i] = exp2(-(3 - i) / 3.0) / (float)(1 << 20); #else #define P 15 s->scale_factor_shift[i] = 21 - P - (i / 3); s->scale_factor_mult[i] = (1 << P) * exp2((i % 3) / 3.0); #endif } for(i=0;i<128;i++) { v = i - 64; if (v <= -3) v = 0; else if (v < 0) v = 1; else if (v == 0) v = 2; else if (v < 3) v = 3; else v = 4; s->scale_diff_table[i] = v; } for(i=0;i<17;i++) { v = ff_mpa_quant_bits[i]; if (v < 0) v = -v; else v = v * 3; s->total_quant_bits[i] = 12 * v; } return 0; }


static av_cold int vc1_decode_init(AVCodecContext *avctx) { VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; GetBitContext gb; int ret; /* save the container output size for WMImage */ v->output_width = avctx->width; v->output_height = avctx->height; if (!avctx->extradata_size || !avctx->extradata) return -1; if (!(avctx->flags & CODEC_FLAG_GRAY)) avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts); else avctx->pix_fmt = AV_PIX_FMT_GRAY8; v->s.avctx = avctx; if ((ret = ff_vc1_init_common(v)) < 0) return ret; // ensure static VLC tables are initialized if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) return ret; if ((ret = ff_vc1_decode_init_alloc_tables(v)) < 0) return ret; // Hack to ensure the above functions will be called // again once we know all necessary settings. // That this is necessary might indicate a bug. ff_vc1_decode_end(avctx); ff_blockdsp_init(&s->bdsp, avctx); ff_h264chroma_init(&v->h264chroma, 8); ff_qpeldsp_init(&s->qdsp); if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) { int count = 0; // looks like WMV3 has a sequence header stored in the extradata // advanced sequence header may be before the first frame // the last byte of the extradata is a version number, 1 for the // samples we can decode init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8); if ((ret = ff_vc1_decode_sequence_header(avctx, v, &gb)) < 0) return ret; count = avctx->extradata_size*8 - get_bits_count(&gb); if (count > 0) { av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", count, get_bits(&gb, count)); } else if (count < 0) { av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); } } else { // VC1/WVC1/WVP2 const uint8_t *start = avctx->extradata; uint8_t *end = avctx->extradata + avctx->extradata_size; const uint8_t *next; int size, buf2_size; uint8_t *buf2 = NULL; int seq_initialized = 0, ep_initialized = 0; if (avctx->extradata_size < 16) { av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size); return -1; } buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv next = start; for (; next < end; start = next) { next = find_next_marker(start + 4, end); size = next - start - 4; if (size <= 0) continue; buf2_size = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); switch (AV_RB32(start)) { case VC1_CODE_SEQHDR: if ((ret = ff_vc1_decode_sequence_header(avctx, v, &gb)) < 0) { av_free(buf2); return ret; } seq_initialized = 1; break; case VC1_CODE_ENTRYPOINT: if ((ret = ff_vc1_decode_entry_point(avctx, v, &gb)) < 0) { av_free(buf2); return ret; } ep_initialized = 1; break; } } av_free(buf2); if (!seq_initialized || !ep_initialized) { av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); return -1; } v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE); } v->sprite_output_frame = av_frame_alloc(); if (!v->sprite_output_frame) avctx->profile = v->profile; if (v->profile == PROFILE_ADVANCED) avctx->level = v->level; avctx->has_b_frames = !!avctx->max_b_frames; if (v->color_prim == 1 || v->color_prim == 5 || v->color_prim == 6) avctx->color_primaries = v->color_prim; if (v->transfer_char == 1 || v->transfer_char == 7) avctx->color_trc = v->transfer_char; if (v->matrix_coef == 1 || v->matrix_coef == 6 || v->matrix_coef == 7) avctx->colorspace = v->matrix_coef; s->mb_width = (avctx->coded_width + 15) >> 4; s->mb_height = (avctx->coded_height + 15) >> 4; if (v->profile == PROFILE_ADVANCED || v->res_fasttx) { ff_vc1_init_transposed_scantables(v); } else { memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64); v->left_blk_sh = 3; v->top_blk_sh = 0; } if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { v->sprite_width = avctx->coded_width; v->sprite_height = avctx->coded_height; avctx->coded_width = avctx->width = v->output_width; avctx->coded_height = avctx->height = v->output_height; // prevent 16.16 overflows if (v->sprite_width > 1 << 14 || v->sprite_height > 1 << 14 || v->output_width > 1 << 14 || v->output_height > 1 << 14) return -1; if ((v->sprite_width&1) || (v->sprite_height&1)) { avpriv_request_sample(avctx, "odd sprites support"); return AVERROR_PATCHWELCOME; } } return 0; }


int ff_h264_fill_default_ref_list(H264Context *h) { int i, len; if (h->slice_type_nos == AV_PICTURE_TYPE_B) { Picture *sorted[32]; int cur_poc, list; int lens[2]; if (FIELD_PICTURE(h)) cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; else cur_poc = h->cur_pic_ptr->poc; for (list = 0; list < 2; list++) { len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list); len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list); assert(len <= 32); len = build_def_list(h->default_ref_list[list], sorted, len, 0, h->picture_structure); len += build_def_list(h->default_ref_list[list] + len, h->long_ref, 16, 1, h->picture_structure); assert(len <= 32); if (len < h->ref_count[list]) memset(&h->default_ref_list[list][len], 0, sizeof(Picture) * (h->ref_count[list] - len)); lens[list] = len; } if (lens[0] == lens[1] && lens[1] > 1) { for (i = 0; i < lens[0] && h->default_ref_list[0][i].f.buf[0]->buffer == h->default_ref_list[1][i].f.buf[0]->buffer; i++); if (i == lens[0]) { Picture tmp; COPY_PICTURE(&tmp, &h->default_ref_list[1][0]); COPY_PICTURE(&h->default_ref_list[1][0], &h->default_ref_list[1][1]); COPY_PICTURE(&h->default_ref_list[1][1], &tmp); } } } else { len = build_def_list(h->default_ref_list[0], h->short_ref, h->short_ref_count, 0, h->picture_structure); len += build_def_list(h->default_ref_list[0] + len, h-> long_ref, 16, 1, h->picture_structure); assert(len <= 32); if (len < h->ref_count[0]) memset(&h->default_ref_list[0][len], 0, sizeof(Picture) * (h->ref_count[0] - len)); } #ifdef TRACE for (i = 0; i < h->ref_count[0]; i++) { tprintf(h->avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); } if (h->slice_type_nos == AV_PICTURE_TYPE_B) { for (i = 0; i < h->ref_count[1]; i++) { tprintf(h->avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].f.data[0]); } } #endif return 0; }


static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { AVFilterContext *ctx = link->dst; CropContext *crop = ctx->priv; AVFilterBufferRef *ref2; int i; picref->video->w = crop->w; picref->video->h = crop->h; ref2 = avfilter_ref_buffer(picref, ~0); crop->var_values[VAR_T] = picref->pts == AV_NOPTS_VALUE ? NAN : picref->pts * av_q2d(link->time_base); crop->var_values[VAR_POS] = picref->pos == -1 ? NAN : picref->pos; crop->var_values[VAR_X] = av_expr_eval(crop->x_pexpr, crop->var_values, NULL); crop->var_values[VAR_Y] = av_expr_eval(crop->y_pexpr, crop->var_values, NULL); crop->var_values[VAR_X] = av_expr_eval(crop->x_pexpr, crop->var_values, NULL); normalize_double(&crop->x, crop->var_values[VAR_X]); normalize_double(&crop->y, crop->var_values[VAR_Y]); if (crop->x < 0) crop->x = 0; if (crop->y < 0) crop->y = 0; if ((unsigned)crop->x + (unsigned)crop->w > link->w) crop->x = link->w - crop->w; if ((unsigned)crop->y + (unsigned)crop->h > link->h) crop->y = link->h - crop->h; crop->x &= ~((1 << crop->hsub) - 1); crop->y &= ~((1 << crop->vsub) - 1); av_log(ctx, AV_LOG_DEBUG, "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", (int)crop->var_values[VAR_N], crop->var_values[VAR_T], crop->x, crop->y, crop->x+crop->w, crop->y+crop->h); ref2->data[0] += crop->y * ref2->linesize[0]; ref2->data[0] += crop->x * crop->max_step[0]; if (!(av_pix_fmt_descriptors[link->format].flags & PIX_FMT_PAL)) { for (i = 1; i < 3; i ++) { if (ref2->data[i]) { ref2->data[i] += (crop->y >> crop->vsub) * ref2->linesize[i]; ref2->data[i] += (crop->x * crop->max_step[i]) >> crop->hsub; } } } /* alpha plane */ if (ref2->data[3]) { ref2->data[3] += crop->y * ref2->linesize[3]; ref2->data[3] += crop->x * crop->max_step[3]; } avfilter_start_frame(link->dst->outputs[0], ref2); }


static void gen_tlbsx_440(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); #else TCGv t0; if (unlikely(ctx->pr)) { gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; } t0 = tcg_temp_new(); gen_addr_reg_index(ctx, t0); gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); tcg_temp_free(t0); if (Rc(ctx->opcode)) { TCGLabel *l1 = gen_new_label(); tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); gen_set_label(l1); } #endif }


static void blockdev_backup_prepare(BlkActionState *common, Error **errp) { BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); BlockdevBackup *backup; BlockDriverState *bs, *target; Error *local_err = NULL; assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); backup = common->action->u.blockdev_backup.data; bs = qmp_get_root_bs(backup->device, errp); if (!bs) { return; } target = bdrv_lookup_bs(backup->target, backup->target, errp); if (!target) { return; } /* AioContext is released in .clean() */ state->aio_context = bdrv_get_aio_context(bs); if (state->aio_context != bdrv_get_aio_context(target)) { state->aio_context = NULL; error_setg(errp, "Backup between two IO threads is not implemented"); return; } aio_context_acquire(state->aio_context); state->bs = bs; bdrv_drained_begin(state->bs); do_blockdev_backup(backup, common->block_job_txn, &local_err); if (local_err) { error_propagate(errp, local_err); return; } state->job = state->bs->job; }