id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
6,582
static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp, const float *v1, const float *v2) { LOCAL_ALIGNED(32, float, cdst, [LEN]); LOCAL_ALIGNED(32, float, odst, [LEN]); int ret; cdsp->vector_fmul_reverse(cdst, v1, v2, LEN); fdsp->vector_fmul_reverse(odst, v1, v2, LEN); if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON)) av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n"); return ret; }
false
FFmpeg
e53c9065ca08a9153ecc73a6a8940bcc6d667e58
6,583
static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s) { unsigned char B; int x, y; /* copy 8x8 block from current frame from an up/left block */ /* need 1 more byte for motion */ CHECK_STREAM_PTR(1); B = *s->stream_ptr++; if (B < 56) { x = -(8 + (B % 7)); y = -(B / 7); } else { x = -(-14 + ((B - 56) % 29)); y = -( 8 + ((B - 56) / 29)); } debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); return copy_from(s, &s->current_frame, x, y); }
false
FFmpeg
80ca19f766aea8f4724aac1b3faa772d25163c8a
6,584
static int set_params(AVFilterContext *ctx, const char *params) { Frei0rContext *s = ctx->priv; int i; if (!params) return 0; for (i = 0; i < s->plugin_info.num_params; i++) { f0r_param_info_t info; char *param; int ret; s->get_param_info(&info, i); if (*params) { if (!(param = av_get_token(&params, "|"))) return AVERROR(ENOMEM); params++; /* skip ':' */ ret = set_param(ctx, info, i, param); av_free(param); if (ret < 0) return ret; } av_log(ctx, AV_LOG_VERBOSE, "idx:%d name:'%s' type:%s explanation:'%s' ", i, info.name, info.type == F0R_PARAM_BOOL ? "bool" : info.type == F0R_PARAM_DOUBLE ? "double" : info.type == F0R_PARAM_COLOR ? "color" : info.type == F0R_PARAM_POSITION ? "position" : info.type == F0R_PARAM_STRING ? "string" : "unknown", info.explanation); #ifdef DEBUG av_log(ctx, AV_LOG_DEBUG, "value:"); switch (info.type) { void *v; double d; char s[128]; f0r_param_color_t col; f0r_param_position_t pos; case F0R_PARAM_BOOL: v = &d; s->get_param_value(s->instance, v, i); av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n"); break; case F0R_PARAM_DOUBLE: v = &d; s->get_param_value(s->instance, v, i); av_log(ctx, AV_LOG_DEBUG, "%f", d); break; case F0R_PARAM_COLOR: v = &col; s->get_param_value(s->instance, v, i); av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b); break; case F0R_PARAM_POSITION: v = &pos; s->get_param_value(s->instance, v, i); av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y); break; default: /* F0R_PARAM_STRING */ v = s; s->get_param_value(s->instance, v, i); av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s); break; } #endif av_log(ctx, AV_LOG_VERBOSE, "\n"); } return 0; }
false
FFmpeg
02a6ee51685eb74f7a878dd49553ecc1f8da9fb2
6,585
static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s) { int y; unsigned char pix; /* 1-color encoding: the whole block is 1 solid color */ CHECK_STREAM_PTR(1); pix = *s->stream_ptr++; for (y = 0; y < 8; y++) { memset(s->pixel_ptr, pix, 8); s->pixel_ptr += s->stride; } /* report success */ return 0; }
false
FFmpeg
80ca19f766aea8f4724aac1b3faa772d25163c8a
6,586
static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4}; static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; RA144Context *ractx = avctx->priv_data; PutBitContext pb; int32_t lpc_data[NBLOCKS * BLOCKSIZE]; int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER]; int shift[LPC_ORDER]; int16_t block_coefs[NBLOCKS][LPC_ORDER]; int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */ unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */ const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; int energy = 0; int i, idx, ret; if (ractx->last_frame) return 0; if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE))) return ret; /** * Since the LPC coefficients are calculated on a frame centered over the * fourth subframe, to encode a given frame, data from the next frame is * needed. In each call to this function, the previous frame (whose data are * saved in the encoder context) is encoded, and data from the current frame * are saved in the encoder context to be used in the next function call. */ for (i = 0; i < (2 * BLOCKSIZE + BLOCKSIZE / 2); i++) { lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i]; energy += (lpc_data[i] * lpc_data[i]) >> 4; } if (frame) { int j; for (j = 0; j < frame->nb_samples && i < NBLOCKS * BLOCKSIZE; i++, j++) { lpc_data[i] = samples[j] >> 2; energy += (lpc_data[i] * lpc_data[i]) >> 4; } } if (i < NBLOCKS * BLOCKSIZE) memset(&lpc_data[i], 0, (NBLOCKS * BLOCKSIZE - i) * sizeof(*lpc_data)); energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab, 32)]; ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER, LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON, 0, ORDER_METHOD_EST, 12, 0); for (i = 0; i < LPC_ORDER; i++) block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] << (12 - shift[LPC_ORDER - 1])); /** * TODO: apply perceptual weighting of the input speech through bandwidth * expansion of the LPC filter. */ if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) { /** * The filter is unstable: use the coefficients of the previous frame. */ ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]); if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) { /* the filter is still unstable. set reflection coeffs to zero. */ memset(lpc_refl, 0, sizeof(lpc_refl)); } } init_put_bits(&pb, avpkt->data, avpkt->size); for (i = 0; i < LPC_ORDER; i++) { idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]); put_bits(&pb, bit_sizes[i], idx); lpc_refl[i] = ff_lpc_refl_cb[i][idx]; } ractx->lpc_refl_rms[0] = ff_rms(lpc_refl); ff_eval_coefs(ractx->lpc_coef[0], lpc_refl); refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy); refl_rms[1] = ff_interp(ractx, block_coefs[1], 2, energy <= ractx->old_energy, ff_t_sqrt(energy * ractx->old_energy) >> 12); refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy); refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy); ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]); put_bits(&pb, 5, quantize(energy, ff_energy_tab, 32)); for (i = 0; i < NBLOCKS; i++) ra144_encode_subblock(ractx, ractx->curr_block + i * BLOCKSIZE, block_coefs[i], refl_rms[i], &pb); flush_put_bits(&pb); ractx->old_energy = energy; ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); /* copy input samples to current block for processing in next call */ i = 0; if (frame) { for (; i < frame->nb_samples; i++) ractx->curr_block[i] = samples[i] >> 2; if ((ret = ff_af_queue_add(&ractx->afq, frame)) < 0) return ret; } else ractx->last_frame = 1; memset(&ractx->curr_block[i], 0, (NBLOCKS * BLOCKSIZE - i) * sizeof(*ractx->curr_block)); /* Get the next frame pts/duration */ ff_af_queue_remove(&ractx->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); avpkt->size = FRAMESIZE; *got_packet_ptr = 1; return 0; }
false
FFmpeg
bcaf64b605442e1622d16da89d4ec0e7730b8a8c
6,587
static off_t read_uint32(int fd, int64_t offset) { uint32_t buffer; if (pread(fd, &buffer, 4, offset) < 4) return 0; return be32_to_cpu(buffer); }
false
qemu
64a31d5c3d73396a88563d7a504654edc85aa854
6,588
static int tosa_dac_send(I2CSlave *i2c, uint8_t data) { TosaDACState *s = TOSA_DAC(i2c); s->buf[s->len] = data; if (s->len ++ > 2) { #ifdef VERBOSE fprintf(stderr, "%s: message too long (%i bytes)\n", __FUNCTION__, s->len); #endif return 1; } if (s->len == 2) { fprintf(stderr, "dac: channel %d value 0x%02x\n", s->buf[0], s->buf[1]); } return 0; }
false
qemu
a89f364ae8740dfc31b321eed9ee454e996dc3c1
6,589
static void socket_start_incoming_migration(SocketAddress *saddr, Error **errp) { QIOChannelSocket *listen_ioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(listen_ioc), "migration-socket-listener"); if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) { object_unref(OBJECT(listen_ioc)); qapi_free_SocketAddress(saddr); return; } qio_channel_add_watch(QIO_CHANNEL(listen_ioc), G_IO_IN, socket_accept_incoming_migration, listen_ioc, (GDestroyNotify)object_unref); qapi_free_SocketAddress(saddr); }
false
qemu
dfd100f242370886bb6732f70f1f7cbd8eb9fedc
6,590
static void mpc8544ds_init(ram_addr_t ram_size, const char *boot_device, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { PCIBus *pci_bus; CPUState *env; uint64_t elf_entry; uint64_t elf_lowaddr; target_phys_addr_t entry=0; target_phys_addr_t loadaddr=UIMAGE_LOAD_BASE; target_long kernel_size=0; target_ulong dt_base=DTB_LOAD_BASE; target_ulong initrd_base=INITRD_LOAD_BASE; target_long initrd_size=0; void *fdt; int i=0; unsigned int pci_irq_nrs[4] = {1, 2, 3, 4}; qemu_irq *irqs, *mpic, *pci_irqs; SerialState * serial[2]; /* Setup CPU */ env = cpu_ppc_init("e500v2_v30"); if (!env) { fprintf(stderr, "Unable to initialize CPU!\n"); exit(1); } /* Fixup Memory size on a alignment boundary */ ram_size &= ~(RAM_SIZES_ALIGN - 1); /* Register Memory */ cpu_register_physical_memory(0, ram_size, qemu_ram_alloc(ram_size)); /* MPIC */ irqs = qemu_mallocz(sizeof(qemu_irq) * OPENPIC_OUTPUT_NB); irqs[OPENPIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_INT]; irqs[OPENPIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_CINT]; mpic = mpic_init(MPC8544_MPIC_REGS_BASE, 1, &irqs, NULL); /* Serial */ if (serial_hds[0]) serial[0] = serial_mm_init(MPC8544_SERIAL0_REGS_BASE, 0, mpic[12+26], 399193, serial_hds[0], 1); if (serial_hds[1]) serial[0] = serial_mm_init(MPC8544_SERIAL1_REGS_BASE, 0, mpic[12+26], 399193, serial_hds[0], 1); /* PCI */ pci_irqs = qemu_malloc(sizeof(qemu_irq) * 4); pci_irqs[0] = mpic[pci_irq_nrs[0]]; pci_irqs[1] = mpic[pci_irq_nrs[1]]; pci_irqs[2] = mpic[pci_irq_nrs[2]]; pci_irqs[3] = mpic[pci_irq_nrs[3]]; pci_bus = ppce500_pci_init(pci_irqs, MPC8544_PCI_REGS_BASE); if (!pci_bus) printf("couldn't create PCI controller!\n"); isa_mmio_init(MPC8544_PCI_IO, MPC8544_PCI_IOLEN); if (pci_bus) { /* Register network interfaces. */ for (i = 0; i < nb_nics; i++) { pci_nic_init_nofail(&nd_table[i], "virtio", NULL); } } /* Load kernel. */ if (kernel_filename) { kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL); if (kernel_size < 0) { kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr, NULL, 1, ELF_MACHINE, 0); entry = elf_entry; loadaddr = elf_lowaddr; } /* XXX try again as binary */ if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } } /* Load initrd. */ if (initrd_filename) { initrd_size = load_image_targphys(initrd_filename, initrd_base, ram_size - initrd_base); if (initrd_size < 0) { fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", initrd_filename); exit(1); } } /* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { fdt = mpc8544_load_device_tree(dt_base, ram_size, initrd_base, initrd_size, kernel_cmdline); if (fdt == NULL) { fprintf(stderr, "couldn't load device tree\n"); exit(1); } cpu_synchronize_state(env); /* Set initial guest state. */ env->gpr[1] = (16<<20) - 8; env->gpr[3] = dt_base; env->nip = entry; /* XXX we currently depend on KVM to create some initial TLB entries. */ } if (kvm_enabled()) kvmppc_init(); return; }
false
qemu
04088adbe0c5adca66adb6022723362ad90ed0fc
6,591
static void test_visitor_out_native_list_bool(TestOutputVisitorData *data, const void *unused) { test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN); }
false
qemu
b3db211f3c80bb996a704d665fe275619f728bd4
6,592
static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f, int version_id) { VirtIOBlock *s = VIRTIO_BLK(vdev); while (qemu_get_sbyte(f)) { unsigned nvqs = s->conf.num_queues; unsigned vq_idx = 0; VirtIOBlockReq *req; if (nvqs > 1) { vq_idx = qemu_get_be32(f); if (vq_idx >= nvqs) { error_report("Invalid virtqueue index in request list: %#x", vq_idx); return -EINVAL; } } req = qemu_get_virtqueue_element(f, sizeof(VirtIOBlockReq)); virtio_blk_init_request(s, virtio_get_queue(vdev, vq_idx), req); req->next = s->rq; s->rq = req; } return 0; }
false
qemu
8607f5c3072caeebbe0217df28651fffd3a79fd9
6,593
void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { PCIDevice *dev = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); const char *type = qdict_get_str(qdict, "type"); const char *opts = qdict_get_try_str(qdict, "opts"); /* strip legacy tag */ if (!strncmp(pci_addr, "pci_addr=", 9)) { pci_addr += 9; } if (!opts) { opts = ""; } if (!strcmp(pci_addr, "auto")) pci_addr = NULL; if (strcmp(type, "nic") == 0) dev = qemu_pci_hot_add_nic(mon, pci_addr, opts); else if (strcmp(type, "storage") == 0) dev = qemu_pci_hot_add_storage(mon, pci_addr, opts); else monitor_printf(mon, "invalid type: %s\n", type); if (dev) { *ret_data = qobject_from_jsonf("{ 'domain': 0, 'bus': %d, 'slot': %d, " "'function': %d }", pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); assert(*ret_data != NULL); } else monitor_printf(mon, "failed to add %s\n", opts); }
false
qemu
ba14414174b72fa231997243a9650feaa520d054
6,596
static int tta_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; TTAContext *s = avctx->priv_data; int i, ret; int cur_chan = 0, framelen = s->frame_length; int32_t *p; if (avctx->err_recognition & AV_EF_CRCCHECK) { if (buf_size < 4 || tta_check_crc(s, buf, buf_size - 4)) return AVERROR_INVALIDDATA; } init_get_bits(&s->gb, buf, buf_size*8); // FIXME: seeking s->total_frames--; if (!s->total_frames && s->last_frame_length) framelen = s->last_frame_length; /* get output buffer */ s->frame.nb_samples = framelen; if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } // decode directly to output buffer for 24-bit sample format if (s->bps == 3) s->decode_buffer = (int32_t *)s->frame.data[0]; // init per channel states for (i = 0; i < s->channels; i++) { s->ch_ctx[i].predictor = 0; ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]); rice_init(&s->ch_ctx[i].rice, 10, 10); } for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) { int32_t *predictor = &s->ch_ctx[cur_chan].predictor; TTAFilter *filter = &s->ch_ctx[cur_chan].filter; TTARice *rice = &s->ch_ctx[cur_chan].rice; uint32_t unary, depth, k; int32_t value; unary = tta_get_unary(&s->gb); if (unary == 0) { depth = 0; k = rice->k0; } else { depth = 1; k = rice->k1; unary--; } if (get_bits_left(&s->gb) < k) { ret = AVERROR_INVALIDDATA; goto error; } if (k) { if (k > MIN_CACHE_BITS) { ret = AVERROR_INVALIDDATA; goto error; } value = (unary << k) + get_bits(&s->gb, k); } else value = unary; // FIXME: copy paste from original switch (depth) { case 1: rice->sum1 += value - (rice->sum1 >> 4); if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) rice->k1--; else if(rice->sum1 > shift_16[rice->k1 + 1]) rice->k1++; value += shift_1[rice->k0]; default: rice->sum0 += value - (rice->sum0 >> 4); if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) rice->k0--; else if(rice->sum0 > shift_16[rice->k0 + 1]) rice->k0++; } // extract coded value *p = 1 + ((value >> 1) ^ ((value & 1) - 1)); // run hybrid filter ttafilter_process(filter, p); // fixed order prediction #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k) switch (s->bps) { case 1: *p += PRED(*predictor, 4); break; case 2: case 3: *p += PRED(*predictor, 5); break; case 4: *p += *predictor; break; } *predictor = *p; // flip channels if (cur_chan < (s->channels-1)) cur_chan++; else { // decorrelate in case of multiple channels if (s->channels > 1) { int32_t *r = p - 1; for (*p += *r / 2; r > p - s->channels; r--) *r = *(r + 1) - *r; } cur_chan = 0; } } if (get_bits_left(&s->gb) < 32) { ret = AVERROR_INVALIDDATA; goto error; } skip_bits_long(&s->gb, 32); // frame crc // convert to output buffer if (s->bps == 2) { int16_t *samples = (int16_t *)s->frame.data[0]; for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) *samples++ = *p; } else { // shift samples for 24-bit sample format int32_t *samples = (int32_t *)s->frame.data[0]; for (i = 0; i < framelen * s->channels; i++) *samples++ <<= 8; // reset decode buffer s->decode_buffer = NULL; } *got_frame_ptr = 1; *(AVFrame *)data = s->frame; return buf_size; error: // reset decode buffer if (s->bps == 3) s->decode_buffer = NULL; return ret; }
false
FFmpeg
5778299c7ed3f82c624589bd35c82f597a8e0b64
6,597
static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_user) { /* Return true if we should use the default memory map as a * "background" region if there are no hits against any MPU regions. */ CPUARMState *env = &cpu->env; if (is_user) { return false; } if (arm_feature(env, ARM_FEATURE_M)) { return env->v7m.mpu_ctrl & R_V7M_MPU_CTRL_PRIVDEFENA_MASK; } else { return regime_sctlr(env, mmu_idx) & SCTLR_BR; } }
false
qemu
ecf5e8eae8b0b5fa41f00b53d67747b42fd1b8b9
6,598
static void rtas_system_reboot(sPAPREnvironment *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { if (nargs != 0 || nret != 1) { rtas_st(rets, 0, -3); return; } qemu_system_reset_request(); rtas_st(rets, 0, 0); }
false
qemu
210b580b106fa798149e28aa13c66b325a43204e
6,599
static int preallocate(BlockDriverState *bs) { uint64_t nb_sectors; uint64_t offset; uint64_t host_offset = 0; int num; int ret; QCowL2Meta *meta; nb_sectors = bdrv_getlength(bs) >> 9; offset = 0; while (nb_sectors) { num = MIN(nb_sectors, INT_MAX >> 9); ret = qcow2_alloc_cluster_offset(bs, offset, &num, &host_offset, &meta); if (ret < 0) { return ret; } ret = qcow2_alloc_cluster_link_l2(bs, meta); if (ret < 0) { qcow2_free_any_clusters(bs, meta->alloc_offset, meta->nb_clusters, QCOW2_DISCARD_NEVER); return ret; } /* There are no dependent requests, but we need to remove our request * from the list of in-flight requests */ if (meta != NULL) { QLIST_REMOVE(meta, next_in_flight); } /* TODO Preallocate data if requested */ nb_sectors -= num; offset += num << 9; } /* * It is expected that the image file is large enough to actually contain * all of the allocated clusters (otherwise we get failing reads after * EOF). Extend the image to the last allocated sector. */ if (host_offset != 0) { uint8_t buf[512]; memset(buf, 0, 512); ret = bdrv_write(bs->file, (host_offset >> 9) + num - 1, buf, 1); if (ret < 0) { return ret; } } return 0; }
false
qemu
7c2bbf4aa66ca5a9fc2ca147e0e6cb6f407a3aa2
6,600
static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, MSIMessage *msg, IOHandler *handler) { VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); VFIOMSIVector *vector; int ret; trace_vfio_msix_vector_do_use(vdev->vbasedev.name, nr); vector = &vdev->msi_vectors[nr]; if (!vector->use) { vector->vdev = vdev; vector->virq = -1; if (event_notifier_init(&vector->interrupt, 0)) { error_report("vfio: Error: event_notifier_init failed"); } vector->use = true; msix_vector_use(pdev, nr); } qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt), handler, NULL, vector); /* * Attempt to enable route through KVM irqchip, * default to userspace handling if unavailable. */ if (vector->virq >= 0) { if (!msg) { vfio_remove_kvm_msi_virq(vector); } else { vfio_update_kvm_msi_virq(vector, *msg); } } else { vfio_add_kvm_msi_virq(vector, msg, true); } /* * We don't want to have the host allocate all possible MSI vectors * for a device if they're not in use, so we shutdown and incrementally * increase them as needed. */ if (vdev->nr_vectors < nr + 1) { vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); vdev->nr_vectors = nr + 1; ret = vfio_enable_vectors(vdev, true); if (ret) { error_report("vfio: failed to enable vectors, %d", ret); } } else { int argsz; struct vfio_irq_set *irq_set; int32_t *pfd; argsz = sizeof(*irq_set) + sizeof(*pfd); irq_set = g_malloc0(argsz); irq_set->argsz = argsz; irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER; irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX; irq_set->start = nr; irq_set->count = 1; pfd = (int32_t *)&irq_set->data; if (vector->virq >= 0) { *pfd = event_notifier_get_fd(&vector->kvm_interrupt); } else { *pfd = event_notifier_get_fd(&vector->interrupt); } ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); g_free(irq_set); if (ret) { error_report("vfio: failed to modify vector, %d", ret); } } return 0; }
false
qemu
46746dbaa8c2c421b9bda78193caad57d7fb1136
6,601
int virtio_load(VirtIODevice *vdev, QEMUFile *f) { int i, ret; int32_t config_len; uint32_t num; uint32_t features; uint32_t supported_features; BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); if (k->load_config) { ret = k->load_config(qbus->parent, f); if (ret) return ret; } qemu_get_8s(f, &vdev->status); qemu_get_8s(f, &vdev->isr); qemu_get_be16s(f, &vdev->queue_sel); if (vdev->queue_sel >= VIRTIO_PCI_QUEUE_MAX) { return -1; } qemu_get_be32s(f, &features); if (virtio_set_features(vdev, features) < 0) { supported_features = k->get_features(qbus->parent); error_report("Features 0x%x unsupported. Allowed features: 0x%x", features, supported_features); return -1; } config_len = qemu_get_be32(f); if (config_len != vdev->config_len) { error_report("Unexpected config length 0x%x. Expected 0x%zx", config_len, vdev->config_len); return -1; } qemu_get_buffer(f, vdev->config, vdev->config_len); num = qemu_get_be32(f); if (num > VIRTIO_PCI_QUEUE_MAX) { error_report("Invalid number of PCI queues: 0x%x", num); return -1; } for (i = 0; i < num; i++) { vdev->vq[i].vring.num = qemu_get_be32(f); if (k->has_variable_vring_alignment) { vdev->vq[i].vring.align = qemu_get_be32(f); } vdev->vq[i].pa = qemu_get_be64(f); qemu_get_be16s(f, &vdev->vq[i].last_avail_idx); vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; if (vdev->vq[i].pa) { uint16_t nheads; virtqueue_init(&vdev->vq[i]); nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx; /* Check it isn't doing very strange things with descriptor numbers. */ if (nheads > vdev->vq[i].vring.num) { error_report("VQ %d size 0x%x Guest index 0x%x " "inconsistent with Host index 0x%x: delta 0x%x", i, vdev->vq[i].vring.num, vring_avail_idx(&vdev->vq[i]), vdev->vq[i].last_avail_idx, nheads); return -1; } } else if (vdev->vq[i].last_avail_idx) { error_report("VQ %d address 0x0 " "inconsistent with Host index 0x%x", i, vdev->vq[i].last_avail_idx); return -1; } if (k->load_queue) { ret = k->load_queue(qbus->parent, i, f); if (ret) return ret; } } virtio_notify_vector(vdev, VIRTIO_NO_VECTOR); return 0; }
false
qemu
2f5732e9648fcddc8759a8fd25c0b41a38352be6
6,602
static int pci_vmsvga_initfn(PCIDevice *dev) { struct pci_vmsvga_state_s *s = DO_UPCAST(struct pci_vmsvga_state_s, card, dev); pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE); pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID); pci_config_set_class(s->card.config, PCI_CLASS_DISPLAY_VGA); s->card.config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */ s->card.config[PCI_LATENCY_TIMER] = 0x40; /* Latency timer */ s->card.config[PCI_SUBSYSTEM_VENDOR_ID] = PCI_VENDOR_ID_VMWARE & 0xff; s->card.config[PCI_SUBSYSTEM_VENDOR_ID + 1] = PCI_VENDOR_ID_VMWARE >> 8; s->card.config[PCI_SUBSYSTEM_ID] = SVGA_PCI_DEVICE_ID & 0xff; s->card.config[PCI_SUBSYSTEM_ID + 1] = SVGA_PCI_DEVICE_ID >> 8; s->card.config[PCI_INTERRUPT_LINE] = 0xff; /* End */ pci_register_bar(&s->card, 0, 0x10, PCI_BASE_ADDRESS_SPACE_IO, pci_vmsvga_map_ioport); pci_register_bar(&s->card, 1, VGA_RAM_SIZE, PCI_BASE_ADDRESS_MEM_PREFETCH, pci_vmsvga_map_mem); pci_register_bar(&s->card, 2, SVGA_FIFO_SIZE, PCI_BASE_ADDRESS_MEM_PREFETCH, pci_vmsvga_map_fifo); vmsvga_init(&s->chip, VGA_RAM_SIZE); if (!dev->rom_bar) { /* compatibility with pc-0.13 and older */ vga_init_vbe(&s->chip.vga); } return 0; }
false
qemu
310faaede80a2eb270a021a26183d6afbde81180
6,603
static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table) { QEMUIOVector qiov; int noffsets; int i, ret; struct iovec iov = { .iov_base = table->offsets, .iov_len = s->header.cluster_size * s->header.table_size, }; qemu_iovec_init_external(&qiov, &iov, 1); trace_qed_read_table(s, offset, table); ret = bdrv_preadv(s->bs->file, offset, &qiov); if (ret < 0) { goto out; } /* Byteswap offsets */ qed_acquire(s); noffsets = qiov.size / sizeof(uint64_t); for (i = 0; i < noffsets; i++) { table->offsets[i] = le64_to_cpu(table->offsets[i]); } qed_release(s); ret = 0; out: /* Completion */ trace_qed_read_table_cb(s, table, ret); return ret; }
false
qemu
1f01e50b8330c24714ddca5841fdbb703076b121
6,604
long do_sigreturn(CPUState *env) { struct target_signal_frame *sf; uint32_t up_psr, pc, npc; target_sigset_t set; sigset_t host_set; abi_ulong fpu_save; int err, i; sf = (struct target_signal_frame *)g2h(env->regwptr[UREG_FP]); #if 0 fprintf(stderr, "sigreturn\n"); fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]); #endif //cpu_dump_state(env, stderr, fprintf, 0); /* 1. Make sure we are not getting garbage from the user */ #if 0 if (verify_area (VERIFY_READ, sf, sizeof (*sf))) goto segv_and_exit; #endif if (((uint) sf) & 3) goto segv_and_exit; err = __get_user(pc, &sf->info.si_regs.pc); err |= __get_user(npc, &sf->info.si_regs.npc); if ((pc | npc) & 3) goto segv_and_exit; /* 2. Restore the state */ err |= __get_user(up_psr, &sf->info.si_regs.psr); /* User can only change condition codes and FPU enabling in %psr. */ env->psr = (up_psr & (PSR_ICC /* | PSR_EF */)) | (env->psr & ~(PSR_ICC /* | PSR_EF */)); env->pc = pc; env->npc = npc; err |= __get_user(env->y, &sf->info.si_regs.y); for (i=0; i < 8; i++) { err |= __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]); } for (i=0; i < 8; i++) { err |= __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]); } err |= __get_user(fpu_save, (abi_ulong *)&sf->fpu_save); //if (fpu_save) // err |= restore_fpu_state(env, fpu_save); /* This is pretty much atomic, no amount locking would prevent * the races which exist anyways. */ err |= __get_user(set.sig[0], &sf->info.si_mask); for(i = 1; i < TARGET_NSIG_WORDS; i++) { err |= (__get_user(set.sig[i], &sf->extramask[i - 1])); } target_to_host_sigset_internal(&host_set, &set); sigprocmask(SIG_SETMASK, &host_set, NULL); if (err) goto segv_and_exit; return env->regwptr[0]; segv_and_exit: force_sig(TARGET_SIGSEGV); }
false
qemu
f8b0aa25599782eef91edc00ebf620bd14db720c
6,606
int cpu_exec(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); #ifdef TARGET_I386 X86CPU *x86_cpu = X86_CPU(cpu); CPUArchState *env = &x86_cpu->env; #endif int ret, interrupt_request; TranslationBlock *tb; uint8_t *tc_ptr; uintptr_t next_tb; SyncClocks sc; if (cpu->halted) { #if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY) if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { apic_poll_irq(x86_cpu->apic_state); cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL); } #endif if (!cpu_has_work(cpu)) { return EXCP_HALTED; } cpu->halted = 0; } current_cpu = cpu; atomic_mb_set(&tcg_current_cpu, cpu); rcu_read_lock(); if (unlikely(atomic_mb_read(&exit_request))) { cpu->exit_request = 1; } cc->cpu_exec_enter(cpu); /* Calculate difference between guest clock and host clock. * This delay includes the delay of the last cycle, so * what we have to do is sleep until it is 0. As for the * advance/delay we gain here, we try to fix it next time. */ init_delay_params(&sc, cpu); /* prepare setjmp context for exception handling */ for(;;) { if (sigsetjmp(cpu->jmp_env, 0) == 0) { /* if an exception is pending, we execute it here */ if (cpu->exception_index >= 0) { if (cpu->exception_index >= EXCP_INTERRUPT) { /* exit request from the cpu execution loop */ ret = cpu->exception_index; if (ret == EXCP_DEBUG) { cpu_handle_debug_exception(cpu); } cpu->exception_index = -1; break; } else { #if defined(CONFIG_USER_ONLY) /* if user mode only, we simulate a fake exception which will be handled outside the cpu execution loop */ #if defined(TARGET_I386) cc->do_interrupt(cpu); #endif ret = cpu->exception_index; cpu->exception_index = -1; break; #else cc->do_interrupt(cpu); cpu->exception_index = -1; #endif } } next_tb = 0; /* force lookup of first TB */ for(;;) { interrupt_request = cpu->interrupt_request; if (unlikely(interrupt_request)) { if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) { /* Mask out external interrupts for this step. */ interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; } if (interrupt_request & CPU_INTERRUPT_DEBUG) { cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG; cpu->exception_index = EXCP_DEBUG; cpu_loop_exit(cpu); } if (interrupt_request & CPU_INTERRUPT_HALT) { cpu->interrupt_request &= ~CPU_INTERRUPT_HALT; cpu->halted = 1; cpu->exception_index = EXCP_HLT; cpu_loop_exit(cpu); } #if defined(TARGET_I386) if (interrupt_request & CPU_INTERRUPT_INIT) { cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0); do_cpu_init(x86_cpu); cpu->exception_index = EXCP_HALTED; cpu_loop_exit(cpu); } #else if (interrupt_request & CPU_INTERRUPT_RESET) { cpu_reset(cpu); } #endif /* The target hook has 3 exit conditions: False when the interrupt isn't processed, True when it is, and we should restart on a new TB, and via longjmp via cpu_loop_exit. */ if (cc->cpu_exec_interrupt(cpu, interrupt_request)) { next_tb = 0; } /* Don't use the cached interrupt_request value, do_interrupt may have updated the EXITTB flag. */ if (cpu->interrupt_request & CPU_INTERRUPT_EXITTB) { cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB; /* ensure that no TB jump will be modified as the program flow was changed */ next_tb = 0; } } if (unlikely(cpu->exit_request)) { cpu->exit_request = 0; cpu->exception_index = EXCP_INTERRUPT; cpu_loop_exit(cpu); } tb_lock(); tb = tb_find_fast(cpu); /* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */ if (tcg_ctx.tb_ctx.tb_invalidated_flag) { /* as some TB could have been invalidated because of memory exceptions while generating the code, we must recompute the hash index here */ next_tb = 0; tcg_ctx.tb_ctx.tb_invalidated_flag = 0; } if (qemu_loglevel_mask(CPU_LOG_EXEC)) { qemu_log("Trace %p [" TARGET_FMT_lx "] %s\n", tb->tc_ptr, tb->pc, lookup_symbol(tb->pc)); } /* see if we can patch the calling TB. When the TB spans two pages, we cannot safely do a direct jump. */ if (next_tb != 0 && tb->page_addr[1] == -1 && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { tb_add_jump((TranslationBlock *)(next_tb & ~TB_EXIT_MASK), next_tb & TB_EXIT_MASK, tb); } tb_unlock(); if (likely(!cpu->exit_request)) { trace_exec_tb(tb, tb->pc); tc_ptr = tb->tc_ptr; /* execute the generated code */ cpu->current_tb = tb; next_tb = cpu_tb_exec(cpu, tc_ptr); cpu->current_tb = NULL; switch (next_tb & TB_EXIT_MASK) { case TB_EXIT_REQUESTED: /* Something asked us to stop executing * chained TBs; just continue round the main * loop. Whatever requested the exit will also * have set something else (eg exit_request or * interrupt_request) which we will handle * next time around the loop. But we need to * ensure the tcg_exit_req read in generated code * comes before the next read of cpu->exit_request * or cpu->interrupt_request. */ smp_rmb(); next_tb = 0; break; case TB_EXIT_ICOUNT_EXPIRED: { /* Instruction counter expired. */ int insns_left = cpu->icount_decr.u32; if (cpu->icount_extra && insns_left >= 0) { /* Refill decrementer and continue execution. */ cpu->icount_extra += insns_left; insns_left = MIN(0xffff, cpu->icount_extra); cpu->icount_extra -= insns_left; cpu->icount_decr.u16.low = insns_left; } else { if (insns_left > 0) { /* Execute remaining instructions. */ tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK); cpu_exec_nocache(cpu, insns_left, tb); align_clocks(&sc, cpu); } cpu->exception_index = EXCP_INTERRUPT; next_tb = 0; cpu_loop_exit(cpu); } break; } default: break; } } /* Try to align the host and virtual clocks if the guest is in advance */ align_clocks(&sc, cpu); /* reset soft MMU for next block (it can currently only be set by a memory fault) */ } /* for(;;) */ } else { /* Reload env after longjmp - the compiler may have smashed all * local variables as longjmp is marked 'noreturn'. */ cpu = current_cpu; cc = CPU_GET_CLASS(cpu); cpu->can_do_io = 1; #ifdef TARGET_I386 x86_cpu = X86_CPU(cpu); env = &x86_cpu->env; #endif tb_lock_reset(); } } /* for(;;) */ cc->cpu_exec_exit(cpu); rcu_read_unlock(); /* fail safe : never use current_cpu outside cpu_exec() */ current_cpu = NULL; /* Does not need atomic_mb_set because a spurious wakeup is okay. */ atomic_set(&tcg_current_cpu, NULL); return ret; }
false
qemu
56c0269a9ec105d3848d9f900b5e38e6b35e2478
6,607
static int dvbsub_parse_clut_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { DVBSubContext *ctx = avctx->priv_data; const uint8_t *buf_end = buf + buf_size; int i, clut_id; int version; DVBSubCLUT *clut; int entry_id, depth , full_range; int y, cr, cb, alpha; int r, g, b, r_add, g_add, b_add; ff_dlog(avctx, "DVB clut packet:\n"); for (i=0; i < buf_size; i++) { ff_dlog(avctx, "%02x ", buf[i]); if (i % 16 == 15) ff_dlog(avctx, "\n"); } if (i % 16) ff_dlog(avctx, "\n"); clut_id = *buf++; version = ((*buf)>>4)&15; buf += 1; clut = get_clut(ctx, clut_id); if (!clut) { clut = av_malloc(sizeof(DVBSubCLUT)); if (!clut) return AVERROR(ENOMEM); memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); clut->id = clut_id; clut->version = -1; clut->next = ctx->clut_list; ctx->clut_list = clut; } if (clut->version != version) { clut->version = version; while (buf + 4 < buf_end) { entry_id = *buf++; depth = (*buf) & 0xe0; if (depth == 0) { av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf); return 0; } full_range = (*buf++) & 1; if (full_range) { y = *buf++; cr = *buf++; cb = *buf++; alpha = *buf++; } else { y = buf[0] & 0xfc; cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4; cb = (buf[1] << 2) & 0xf0; alpha = (buf[1] << 6) & 0xc0; buf += 2; } if (y == 0) alpha = 0xff; YUV_TO_RGB1_CCIR(cb, cr); YUV_TO_RGB2_CCIR(r, g, b, y); ff_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) { ff_dlog(avctx, "More than one bit level marked: %x\n", depth); if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL) return AVERROR_INVALIDDATA; } if (depth & 0x80) clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha); else if (depth & 0x40) clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha); else if (depth & 0x20) clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha); } } return 0; }
false
FFmpeg
e5774f28d15887d36da25ae1ef2f1b3d7a75f449
6,608
static void load_word(DBDMA_channel *ch, int key, uint32_t addr, uint16_t len) { dbdma_cmd *current = &ch->current; uint32_t val; DBDMA_DPRINTF("load_word\n"); /* only implements KEY_SYSTEM */ if (key != KEY_SYSTEM) { printf("DBDMA: LOAD_WORD, unimplemented key %x\n", key); kill_channel(ch); return; } cpu_physical_memory_read(addr, (uint8_t*)&val, len); if (len == 2) val = (val << 16) | (current->cmd_dep & 0x0000ffff); else if (len == 1) val = (val << 24) | (current->cmd_dep & 0x00ffffff); current->cmd_dep = val; if (conditional_wait(ch)) goto wait; current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); dbdma_cmdptr_save(ch); ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH); conditional_interrupt(ch); next(ch); wait: qemu_bh_schedule(dbdma_bh); }
false
qemu
ad674e53b5cce265fadafbde2c6a4f190345cd00
6,610
static void nvdimm_dsm_device(NvdimmDsmIn *in, hwaddr dsm_mem_addr) { /* See the comments in nvdimm_dsm_root(). */ if (!in->function) { nvdimm_dsm_function0(0 /* No function supported other than function 0 */, dsm_mem_addr); return; } /* No function except function 0 is supported yet. */ nvdimm_dsm_no_payload(1 /* Not Supported */, dsm_mem_addr); }
false
qemu
5797dcdc7ade30e8c4080d9282cd9e51b3566e14
6,611
static void bdrv_co_em_bh(void *opaque) { BlockAIOCBCoroutine *acb = opaque; acb->common.cb(acb->common.opaque, acb->req.error); qemu_bh_delete(acb->bh); qemu_aio_unref(acb); }
false
qemu
0b5a24454fc551f0294fe93821e8c643214a55f5
6,613
static int qcow2_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt) { /* Backing file format doesn't make sense without a backing file */ if (backing_fmt && !backing_file) { return -EINVAL; } pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: ""); pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: ""); return qcow2_update_header(bs); }
false
qemu
5f3777945d22248d805fb7c134e206c2d943b77b
6,614
void helper_fcmp_eq_DT(CPUSH4State *env, float64 t0, float64 t1) { int relation; set_float_exception_flags(0, &env->fp_status); relation = float64_compare(t0, t1, &env->fp_status); if (unlikely(relation == float_relation_unordered)) { update_fpscr(env, GETPC()); } else { env->sr_t = (relation == float_relation_equal); } }
false
qemu
fea7d77d3ea287d3b1878648f3049fc6bb4fd57b
6,615
int qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offset, int l1_size, int addend) { BDRVQcow2State *s = bs->opaque; uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount; bool l1_allocated = false; int64_t old_offset, old_l2_offset; int i, j, l1_modified = 0, nb_csectors; int ret; assert(addend >= -1 && addend <= 1); l2_table = NULL; l1_table = NULL; l1_size2 = l1_size * sizeof(uint64_t); s->cache_discards = true; /* WARNING: qcow2_snapshot_goto relies on this function not using the * l1_table_offset when it is the current s->l1_table_offset! Be careful * when changing this! */ if (l1_table_offset != s->l1_table_offset) { l1_table = g_try_malloc0(align_offset(l1_size2, 512)); if (l1_size2 && l1_table == NULL) { ret = -ENOMEM; goto fail; } l1_allocated = true; ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2); if (ret < 0) { goto fail; } for(i = 0;i < l1_size; i++) be64_to_cpus(&l1_table[i]); } else { assert(l1_size == s->l1_size); l1_table = s->l1_table; l1_allocated = false; } for(i = 0; i < l1_size; i++) { l2_offset = l1_table[i]; if (l2_offset) { old_l2_offset = l2_offset; l2_offset &= L1E_OFFSET_MASK; if (offset_into_cluster(s, l2_offset)) { qcow2_signal_corruption(bs, true, -1, -1, "L2 table offset %#" PRIx64 " unaligned (L1 index: %#x)", l2_offset, i); ret = -EIO; goto fail; } ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, (void**) &l2_table); if (ret < 0) { goto fail; } for(j = 0; j < s->l2_size; j++) { uint64_t cluster_index; offset = be64_to_cpu(l2_table[j]); old_offset = offset; offset &= ~QCOW_OFLAG_COPIED; switch (qcow2_get_cluster_type(offset)) { case QCOW2_CLUSTER_COMPRESSED: nb_csectors = ((offset >> s->csize_shift) & s->csize_mask) + 1; if (addend != 0) { ret = update_refcount(bs, (offset & s->cluster_offset_mask) & ~511, nb_csectors * 512, abs(addend), addend < 0, QCOW2_DISCARD_SNAPSHOT); if (ret < 0) { goto fail; } } /* compressed clusters are never modified */ refcount = 2; break; case QCOW2_CLUSTER_NORMAL: case QCOW2_CLUSTER_ZERO: if (offset_into_cluster(s, offset & L2E_OFFSET_MASK)) { qcow2_signal_corruption(bs, true, -1, -1, "Data " "cluster offset %#llx " "unaligned (L2 offset: %#" PRIx64 ", L2 index: %#x)", offset & L2E_OFFSET_MASK, l2_offset, j); ret = -EIO; goto fail; } cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits; if (!cluster_index) { /* unallocated */ refcount = 0; break; } if (addend != 0) { ret = qcow2_update_cluster_refcount(bs, cluster_index, abs(addend), addend < 0, QCOW2_DISCARD_SNAPSHOT); if (ret < 0) { goto fail; } } ret = qcow2_get_refcount(bs, cluster_index, &refcount); if (ret < 0) { goto fail; } break; case QCOW2_CLUSTER_UNALLOCATED: refcount = 0; break; default: abort(); } if (refcount == 1) { offset |= QCOW_OFLAG_COPIED; } if (offset != old_offset) { if (addend > 0) { qcow2_cache_set_dependency(bs, s->l2_table_cache, s->refcount_block_cache); } l2_table[j] = cpu_to_be64(offset); qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table); } } qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); if (addend != 0) { ret = qcow2_update_cluster_refcount(bs, l2_offset >> s->cluster_bits, abs(addend), addend < 0, QCOW2_DISCARD_SNAPSHOT); if (ret < 0) { goto fail; } } ret = qcow2_get_refcount(bs, l2_offset >> s->cluster_bits, &refcount); if (ret < 0) { goto fail; } else if (refcount == 1) { l2_offset |= QCOW_OFLAG_COPIED; } if (l2_offset != old_l2_offset) { l1_table[i] = l2_offset; l1_modified = 1; } } } ret = bdrv_flush(bs); fail: if (l2_table) { qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); } s->cache_discards = false; qcow2_process_discards(bs, ret); /* Update L1 only if it isn't deleted anyway (addend = -1) */ if (ret == 0 && addend >= 0 && l1_modified) { for (i = 0; i < l1_size; i++) { cpu_to_be64s(&l1_table[i]); } ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table, l1_size2); for (i = 0; i < l1_size; i++) { be64_to_cpus(&l1_table[i]); } } if (l1_allocated) g_free(l1_table); return ret; }
false
qemu
b32cbae11107e9e172e5c58425a2a8362e7382ed
6,616
static int enable_write_target(BDRVVVFATState *s, Error **errp) { BlockDriver *bdrv_qcow = NULL; QemuOpts *opts = NULL; int ret; int size = sector2cluster(s, s->sector_count); s->used_clusters = calloc(size, 1); array_init(&(s->commits), sizeof(commit_t)); s->qcow_filename = g_malloc(1024); ret = get_tmp_filename(s->qcow_filename, 1024); if (ret < 0) { error_setg_errno(errp, -ret, "can't create temporary file"); goto err; } bdrv_qcow = bdrv_find_format("qcow"); if (!bdrv_qcow) { error_setg(errp, "Failed to locate qcow driver"); ret = -ENOENT; goto err; } opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512); qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:"); ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp); qemu_opts_del(opts); if (ret < 0) { goto err; } s->qcow = NULL; ret = bdrv_open(&s->qcow, s->qcow_filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow, errp); if (ret < 0) { goto err; } #ifndef _WIN32 unlink(s->qcow_filename); #endif bdrv_set_backing_hd(s->bs, bdrv_new()); s->bs->backing_hd->drv = &vvfat_write_target; s->bs->backing_hd->opaque = g_new(void *, 1); *(void**)s->bs->backing_hd->opaque = s; return 0; err: g_free(s->qcow_filename); s->qcow_filename = NULL; return ret; }
false
qemu
9a29e18f7dfd5a0e80d1c60fc856ebba18ddb738
6,617
static void dca_init_vlcs(void) { static int vlcs_inited = 0; int i, j; if (vlcs_inited) return; dca_bitalloc_index.offset = 1; dca_bitalloc_index.wrap = 2; for (i = 0; i < 5; i++) init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12, bitalloc_12_bits[i], 1, 1, bitalloc_12_codes[i], 2, 2, 1); dca_scalefactor.offset = -64; dca_scalefactor.wrap = 2; for (i = 0; i < 5; i++) init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129, scales_bits[i], 1, 1, scales_codes[i], 2, 2, 1); dca_tmode.offset = 0; dca_tmode.wrap = 1; for (i = 0; i < 4; i++) init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4, tmode_bits[i], 1, 1, tmode_codes[i], 2, 2, 1); for(i = 0; i < 10; i++) for(j = 0; j < 7; j++){ if(!bitalloc_codes[i][j]) break; dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], bitalloc_sizes[i], bitalloc_bits[i][j], 1, 1, bitalloc_codes[i][j], 2, 2, 1); } vlcs_inited = 1; }
false
FFmpeg
5e53486545726987ab4482321d4dcf7e23e7652f
6,620
static inline int is_yuv_planar(PixFmtInfo *ps) { return (ps->color_type == FF_COLOR_YUV || ps->color_type == FF_COLOR_YUV_JPEG) && !ps->is_packed; }
false
FFmpeg
7e7e59409294af9caa63808e56c5cc824c98b4fc
6,621
AVFilter *avfilter_get_by_name(const char *name) { int i; for (i = 0; registered_avfilters[i]; i++) if (!strcmp(registered_avfilters[i]->name, name)) return registered_avfilters[i]; return NULL; }
false
FFmpeg
fa2a34cd40d124161c748bb0f430dc63c94dd0da
6,623
static int output_frame(H264Context *h, AVFrame *dst, AVFrame *src) { int i; int ret = av_frame_ref(dst, src); if (ret < 0) return ret; if (!h->sps.crop) return 0; for (i = 0; i < 3; i++) { int hshift = (i > 0) ? h->chroma_x_shift : 0; int vshift = (i > 0) ? h->chroma_y_shift : 0; int off = ((h->sps.crop_left >> hshift) << h->pixel_shift) + (h->sps.crop_top >> vshift) * dst->linesize[i]; dst->data[i] += off; } return 0; }
false
FFmpeg
3176217c60ca7828712985092d9102d331ea4f3d
6,624
static inline void futex_wake(QemuEvent *ev, int n) { if (n == 1) { pthread_cond_signal(&ev->cond); } else { pthread_cond_broadcast(&ev->cond); } }
true
qemu
158ef8cbb7e0fe8bb430310924b8bebe5f186e6e
6,625
void vnc_flush(VncState *vs) { if (vs->output.offset) vnc_client_write(vs); }
true
qemu
198a0039c5fca224a77e9761e2350dd9cc102ad0
6,629
static void get_private_data(OutputStream *os) { AVCodecContext *codec = os->ctx->streams[0]->codec; uint8_t *ptr = codec->extradata; int size = codec->extradata_size; int i; if (codec->codec_id == AV_CODEC_ID_H264) { ff_avc_write_annexb_extradata(ptr, &ptr, &size); if (!ptr) ptr = codec->extradata; } if (!ptr) return; os->private_str = av_mallocz(2*size + 1); if (!os->private_str) return; for (i = 0; i < size; i++) snprintf(&os->private_str[2*i], 3, "%02x", ptr[i]); if (ptr != codec->extradata) av_free(ptr); }
true
FFmpeg
a863c97e99bf30a88baa74f83bab9e3ab25984dc
6,631
static int bdrv_qed_open(BlockDriverState *bs, int flags) { BDRVQEDState *s = bs->opaque; QEDHeader le_header; int64_t file_size; int ret; s->bs = bs; QSIMPLEQ_INIT(&s->allocating_write_reqs); ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); if (ret < 0) { return ret; } ret = 0; /* ret should always be 0 or -errno */ qed_header_le_to_cpu(&le_header, &s->header); if (s->header.magic != QED_MAGIC) { return -EINVAL; } if (s->header.features & ~QED_FEATURE_MASK) { /* image uses unsupported feature bits */ char buf[64]; snprintf(buf, sizeof(buf), "%" PRIx64, s->header.features & ~QED_FEATURE_MASK); qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, bs->device_name, "QED", buf); return -ENOTSUP; } if (!qed_is_cluster_size_valid(s->header.cluster_size)) { return -EINVAL; } /* Round down file size to the last cluster */ file_size = bdrv_getlength(bs->file); if (file_size < 0) { return file_size; } s->file_size = qed_start_of_cluster(s, file_size); if (!qed_is_table_size_valid(s->header.table_size)) { return -EINVAL; } if (!qed_is_image_size_valid(s->header.image_size, s->header.cluster_size, s->header.table_size)) { return -EINVAL; } if (!qed_check_table_offset(s, s->header.l1_table_offset)) { return -EINVAL; } s->table_nelems = (s->header.cluster_size * s->header.table_size) / sizeof(uint64_t); s->l2_shift = ffs(s->header.cluster_size) - 1; s->l2_mask = s->table_nelems - 1; s->l1_shift = s->l2_shift + ffs(s->table_nelems) - 1; if ((s->header.features & QED_F_BACKING_FILE)) { if ((uint64_t)s->header.backing_filename_offset + s->header.backing_filename_size > s->header.cluster_size * s->header.header_size) { return -EINVAL; } ret = qed_read_string(bs->file, s->header.backing_filename_offset, s->header.backing_filename_size, bs->backing_file, sizeof(bs->backing_file)); if (ret < 0) { return ret; } if (s->header.features & QED_F_BACKING_FORMAT_NO_PROBE) { pstrcpy(bs->backing_format, sizeof(bs->backing_format), "raw"); } } /* Reset unknown autoclear feature bits. This is a backwards * compatibility mechanism that allows images to be opened by older * programs, which "knock out" unknown feature bits. When an image is * opened by a newer program again it can detect that the autoclear * feature is no longer valid. */ if ((s->header.autoclear_features & ~QED_AUTOCLEAR_FEATURE_MASK) != 0 && !bdrv_is_read_only(bs->file)) { s->header.autoclear_features &= QED_AUTOCLEAR_FEATURE_MASK; ret = qed_write_header_sync(s); if (ret) { return ret; } /* From here on only known autoclear feature bits are valid */ bdrv_flush(bs->file); } s->l1_table = qed_alloc_table(s); qed_init_l2_cache(&s->l2_cache); ret = qed_read_l1_table_sync(s); if (ret) { goto out; } /* If image was not closed cleanly, check consistency */ if (s->header.features & QED_F_NEED_CHECK) { /* Read-only images cannot be fixed. There is no risk of corruption * since write operations are not possible. Therefore, allow * potentially inconsistent images to be opened read-only. This can * aid data recovery from an otherwise inconsistent image. */ if (!bdrv_is_read_only(bs->file)) { BdrvCheckResult result = {0}; ret = qed_check(s, &result, true); if (!ret && !result.corruptions && !result.check_errors) { /* Ensure fixes reach storage before clearing check bit */ bdrv_flush(s->bs); s->header.features &= ~QED_F_NEED_CHECK; qed_write_header_sync(s); } } } out: if (ret) { qed_free_l2_cache(&s->l2_cache); qemu_vfree(s->l1_table); } return ret; }
true
qemu
6f321e93abb27b4e7ceb228b4204aa304e95daad
6,633
static void do_key_event(VncState *vs, int down, int keycode, int sym) { /* QEMU console switch */ switch(keycode) { case 0x2a: /* Left Shift */ case 0x36: /* Right Shift */ case 0x1d: /* Left CTRL */ case 0x9d: /* Right CTRL */ case 0x38: /* Left ALT */ case 0xb8: /* Right ALT */ if (down) vs->modifiers_state[keycode] = 1; else vs->modifiers_state[keycode] = 0; break; case 0x02 ... 0x0a: /* '1' to '9' keys */ if (down && vs->modifiers_state[0x1d] && vs->modifiers_state[0x38]) { /* Reset the modifiers sent to the current console */ reset_keys(vs); console_select(keycode - 0x02); return; break; case 0x3a: /* CapsLock */ case 0x45: /* NumLock */ if (!down) vs->modifiers_state[keycode] ^= 1; break; if (keycode_is_keypad(vs->vd->kbd_layout, keycode)) { /* If the numlock state needs to change then simulate an additional toggles numlock away from the VNC window. if (keysym_is_numlock(vs->vd->kbd_layout, sym & 0xFFFF)) { if (!vs->modifiers_state[0x45]) { vs->modifiers_state[0x45] = 1; press_key(vs, 0xff7f); if (vs->modifiers_state[0x45]) { vs->modifiers_state[0x45] = 0; press_key(vs, 0xff7f); if (is_graphic_console()) { if (keycode & 0x80) kbd_put_keycode(0xe0); if (down) kbd_put_keycode(keycode & 0x7f); else kbd_put_keycode(keycode | 0x80); /* QEMU console emulation */ if (down) { int numlock = vs->modifiers_state[0x45]; switch (keycode) { case 0x2a: /* Left Shift */ case 0x36: /* Right Shift */ case 0x1d: /* Left CTRL */ case 0x9d: /* Right CTRL */ case 0x38: /* Left ALT */ case 0xb8: /* Right ALT */ break; case 0xc8: kbd_put_keysym(QEMU_KEY_UP); break; case 0xd0: kbd_put_keysym(QEMU_KEY_DOWN); break; case 0xcb: kbd_put_keysym(QEMU_KEY_LEFT); break; case 0xcd: kbd_put_keysym(QEMU_KEY_RIGHT); break; case 0xd3: kbd_put_keysym(QEMU_KEY_DELETE); break; case 0xc7: kbd_put_keysym(QEMU_KEY_HOME); break; case 0xcf: kbd_put_keysym(QEMU_KEY_END); break; case 0xc9: kbd_put_keysym(QEMU_KEY_PAGEUP); break; case 0xd1: kbd_put_keysym(QEMU_KEY_PAGEDOWN); break; case 0x47: kbd_put_keysym(numlock ? '7' : QEMU_KEY_HOME); break; case 0x48: kbd_put_keysym(numlock ? '8' : QEMU_KEY_UP); break; case 0x49: kbd_put_keysym(numlock ? '9' : QEMU_KEY_PAGEUP); break; case 0x4b: kbd_put_keysym(numlock ? '4' : QEMU_KEY_LEFT); break; case 0x4c: kbd_put_keysym('5'); break; case 0x4d: kbd_put_keysym(numlock ? '6' : QEMU_KEY_RIGHT); break; case 0x4f: kbd_put_keysym(numlock ? '1' : QEMU_KEY_END); break; case 0x50: kbd_put_keysym(numlock ? '2' : QEMU_KEY_DOWN); break; case 0x51: kbd_put_keysym(numlock ? '3' : QEMU_KEY_PAGEDOWN); break; case 0x52: kbd_put_keysym('0'); break; case 0x53: kbd_put_keysym(numlock ? '.' : QEMU_KEY_DELETE); break; case 0xb5: kbd_put_keysym('/'); break; case 0x37: kbd_put_keysym('*'); break; case 0x4a: kbd_put_keysym('-'); break; case 0x4e: kbd_put_keysym('+'); break; case 0x9c: kbd_put_keysym('\n'); break; default: kbd_put_keysym(sym); break;
true
qemu
6b1325029d80455b9da7cd7bd84a88cb915b867c
6,634
void set_link_completion(ReadLineState *rs, int nb_args, const char *str) { size_t len; len = strlen(str); readline_set_completion_index(rs, len); if (nb_args == 2) { NetClientState *ncs[MAX_QUEUE_NUM]; int count, i; count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NONE, MAX_QUEUE_NUM); for (i = 0; i < count; i++) { const char *name = ncs[i]->name; if (!strncmp(str, name, len)) { readline_add_completion(rs, name); } } } else if (nb_args == 3) { add_completion_option(rs, str, "on"); add_completion_option(rs, str, "off"); } }
true
qemu
bcfa4d60144fb879f0ffef0a6d174faa37b2df82
6,636
static void bufp_alloc(USBRedirDevice *dev, uint8_t *data, uint16_t len, uint8_t status, uint8_t ep, void *free_on_destroy) { struct buf_packet *bufp; if (!dev->endpoint[EP2I(ep)].bufpq_dropping_packets && dev->endpoint[EP2I(ep)].bufpq_size > 2 * dev->endpoint[EP2I(ep)].bufpq_target_size) { DPRINTF("bufpq overflow, dropping packets ep %02X\n", ep); dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 1; } /* Since we're interupting the stream anyways, drop enough packets to get back to our target buffer size */ if (dev->endpoint[EP2I(ep)].bufpq_dropping_packets) { if (dev->endpoint[EP2I(ep)].bufpq_size > dev->endpoint[EP2I(ep)].bufpq_target_size) { free(data); return; } dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0; } bufp = g_new(struct buf_packet, 1); bufp->data = data; bufp->len = len; bufp->offset = 0; bufp->status = status; bufp->free_on_destroy = free_on_destroy; QTAILQ_INSERT_TAIL(&dev->endpoint[EP2I(ep)].bufpq, bufp, next); dev->endpoint[EP2I(ep)].bufpq_size++; }
true
qemu
e8ce12d9eaeedeb7f8d9debcd4c9b993903f1abb
6,637
static inline void check_hwrena(CPUMIPSState *env, int reg) { if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << reg))) { return; } do_raise_exception(env, EXCP_RI, GETPC()); }
true
qemu
d96391c1ffeb30a0afa695c86579517c69d9a889
6,638
static bool xen_host_pci_dev_is_virtfn(XenHostPCIDevice *d) { char path[PATH_MAX]; struct stat buf; if (xen_host_pci_sysfs_path(d, "physfn", path, sizeof (path))) { return false; } return !stat(path, &buf); }
true
qemu
599d0c45615b7d099d256738a586d0f63bc707e6
6,639
static gboolean guest_exec_output_watch(GIOChannel *ch, GIOCondition cond, gpointer p_) { GuestExecIOData *p = (GuestExecIOData *)p_; gsize bytes_read; GIOStatus gstatus; if (cond == G_IO_HUP || cond == G_IO_ERR) { goto close; } if (p->size == p->length) { gpointer t = NULL; if (!p->truncated && p->size < GUEST_EXEC_MAX_OUTPUT) { t = g_try_realloc(p->data, p->size + GUEST_EXEC_IO_SIZE); } if (t == NULL) { /* ignore truncated output */ gchar buf[GUEST_EXEC_IO_SIZE]; p->truncated = true; gstatus = g_io_channel_read_chars(ch, buf, sizeof(buf), &bytes_read, NULL); if (gstatus == G_IO_STATUS_EOF || gstatus == G_IO_STATUS_ERROR) { goto close; } return true; } p->size += GUEST_EXEC_IO_SIZE; p->data = t; } /* Calling read API once. * On next available data our callback will be called again */ gstatus = g_io_channel_read_chars(ch, (gchar *)p->data + p->length, p->size - p->length, &bytes_read, NULL); if (gstatus == G_IO_STATUS_EOF || gstatus == G_IO_STATUS_ERROR) { goto close; } p->length += bytes_read; return true; close: g_io_channel_unref(ch); g_atomic_int_set(&p->closed, 1); return false; }
true
qemu
3005c2c2fa2875a3413af97e9db368856d3330fd
6,640
static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], int qsel, int is_chroma, int is_hqa) { const int32_t *q; int val, pos = 1; memset(block, 0, 64 * sizeof(*block)); if (!is_hqa) { block[0] = get_sbits(gb, 9) << 6; q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)]; } else { q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)]; block[0] = get_sbits(gb, 9) << 6; } for (;;) { val = get_vlc2(gb, c->hq_ac_vlc.table, 9, 2); pos += ff_hq_ac_skips[val]; if (pos >= 64) break; block[ff_zigzag_direct[pos]] = (ff_hq_ac_syms[val] * q[pos]) >> 12; pos++; } return 0; }
false
FFmpeg
28eddef689f2b4843a84f7d05fd9614246f92cc4
6,642
static void final(const short *i1, const short *i2, void *out, int *statbuf, int len) { int x, i; unsigned short int work[50]; short *ptr = work; memcpy(work, statbuf,20); memcpy(work + 10, i2, len * 2); for (i=0; i<len; i++) { int sum = 0; for(x=0; x<10; x++) sum += i1[9-x] * ptr[x]; sum >>= 12; if (ptr[10] - sum < -32768 || ptr[10] - sum > 32767) { memset(out, 0, len * 2); memset(statbuf, 0, 20); return; } ptr[10] -= sum; ptr++; } memcpy(out, work+10, len * 2); memcpy(statbuf, work + 40, 20); }
true
FFmpeg
13b6729361d45b9f308d731dd6b82dac01428dc3
6,643
static int showspectrumpic_request_frame(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; ShowSpectrumContext *s = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; ret = ff_request_frame(inlink); if (ret == AVERROR_EOF && s->outpicref) { int samples = av_audio_fifo_size(s->fifo); int consumed = 0; int y, x = 0, sz = s->orientation == VERTICAL ? s->w : s->h; int ch, spf, spb; AVFrame *fin; spf = s->win_size * (samples / ((s->win_size * sz) * ceil(samples / (float)(s->win_size * sz)))); spb = (samples / (spf * sz)) * spf; fin = ff_get_audio_buffer(inlink, s->win_size); if (!fin) return AVERROR(ENOMEM); while (x < sz) { ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size); if (ret < 0) { av_frame_free(&fin); return ret; } av_audio_fifo_drain(s->fifo, spf); if (ret < s->win_size) { for (ch = 0; ch < s->nb_display_channels; ch++) { memset(fin->extended_data[ch] + ret * sizeof(float), 0, (s->win_size - ret) * sizeof(float)); } } ctx->internal->execute(ctx, run_channel_fft, fin, NULL, s->nb_display_channels); acalc_magnitudes(s); consumed += spf; if (consumed >= spb) { int h = s->orientation == VERTICAL ? s->h : s->w; scale_magnitudes(s, 1. / (consumed / spf)); plot_spectrum_column(inlink, fin); consumed = 0; x++; for (ch = 0; ch < s->nb_display_channels; ch++) memset(s->magnitudes[ch], 0, h * sizeof(float)); } } av_frame_free(&fin); s->outpicref->pts = 0; if (s->legend) { int multi = (s->mode == SEPARATE && s->color_mode == CHANNEL); float spp = samples / (float)sz; uint8_t *dst; drawtext(s->outpicref, 2, outlink->h - 10, "CREATED BY LIBAVFILTER", 0); dst = s->outpicref->data[0] + (s->start_y - 1) * s->outpicref->linesize[0] + s->start_x - 1; for (x = 0; x < s->w + 1; x++) dst[x] = 200; dst = s->outpicref->data[0] + (s->start_y + s->h) * s->outpicref->linesize[0] + s->start_x - 1; for (x = 0; x < s->w + 1; x++) dst[x] = 200; for (y = 0; y < s->h + 2; y++) { dst = s->outpicref->data[0] + (y + s->start_y - 1) * s->outpicref->linesize[0]; dst[s->start_x - 1] = 200; dst[s->start_x + s->w] = 200; } if (s->orientation == VERTICAL) { int h = s->mode == SEPARATE ? s->h / s->nb_display_channels : s->h; for (ch = 0; ch < (s->mode == SEPARATE ? s->nb_display_channels : 1); ch++) { for (y = 0; y < h; y += 20) { dst = s->outpicref->data[0] + (s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[0]; dst[s->start_x - 2] = 200; dst[s->start_x + s->w + 1] = 200; } for (y = 0; y < h; y += 40) { dst = s->outpicref->data[0] + (s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[0]; dst[s->start_x - 3] = 200; dst[s->start_x + s->w + 2] = 200; } dst = s->outpicref->data[0] + (s->start_y - 2) * s->outpicref->linesize[0] + s->start_x; for (x = 0; x < s->w; x+=40) dst[x] = 200; dst = s->outpicref->data[0] + (s->start_y - 3) * s->outpicref->linesize[0] + s->start_x; for (x = 0; x < s->w; x+=80) dst[x] = 200; dst = s->outpicref->data[0] + (s->h + s->start_y + 1) * s->outpicref->linesize[0] + s->start_x; for (x = 0; x < s->w; x+=40) { dst[x] = 200; } dst = s->outpicref->data[0] + (s->h + s->start_y + 2) * s->outpicref->linesize[0] + s->start_x; for (x = 0; x < s->w; x+=80) { dst[x] = 200; } for (y = 0; y < h; y += 40) { float hertz = y * (inlink->sample_rate / 2) / (float)(1 << (int)ceil(log2(h))); char *units; if (hertz == 0) units = av_asprintf("DC"); else units = av_asprintf("%.2f", hertz); if (!units) return AVERROR(ENOMEM); drawtext(s->outpicref, s->start_x - 8 * strlen(units) - 4, h * (ch + 1) + s->start_y - y - 4, units, 0); av_free(units); } } for (x = 0; x < s->w; x+=80) { float seconds = x * spp / inlink->sample_rate; char *units; if (x == 0) units = av_asprintf("0"); else if (log10(seconds) > 6) units = av_asprintf("%.2fh", seconds / (60 * 60)); else if (log10(seconds) > 3) units = av_asprintf("%.2fm", seconds / 60); else units = av_asprintf("%.2fs", seconds); if (!units) return AVERROR(ENOMEM); drawtext(s->outpicref, s->start_x + x - 4 * strlen(units), s->h + s->start_y + 6, units, 0); drawtext(s->outpicref, s->start_x + x - 4 * strlen(units), s->start_y - 12, units, 0); av_free(units); } drawtext(s->outpicref, outlink->w / 2 - 4 * 4, outlink->h - s->start_y / 2, "TIME", 0); drawtext(s->outpicref, s->start_x / 7, outlink->h / 2 - 14 * 4, "FREQUENCY (Hz)", 1); } else { int w = s->mode == SEPARATE ? s->w / s->nb_display_channels : s->w; for (y = 0; y < s->h; y += 20) { dst = s->outpicref->data[0] + (s->start_y + y) * s->outpicref->linesize[0]; dst[s->start_x - 2] = 200; dst[s->start_x + s->w + 1] = 200; } for (y = 0; y < s->h; y += 40) { dst = s->outpicref->data[0] + (s->start_y + y) * s->outpicref->linesize[0]; dst[s->start_x - 3] = 200; dst[s->start_x + s->w + 2] = 200; } for (ch = 0; ch < (s->mode == SEPARATE ? s->nb_display_channels : 1); ch++) { dst = s->outpicref->data[0] + (s->start_y - 2) * s->outpicref->linesize[0] + s->start_x + w * ch; for (x = 0; x < w; x+=40) dst[x] = 200; dst = s->outpicref->data[0] + (s->start_y - 3) * s->outpicref->linesize[0] + s->start_x + w * ch; for (x = 0; x < w; x+=80) dst[x] = 200; dst = s->outpicref->data[0] + (s->h + s->start_y + 1) * s->outpicref->linesize[0] + s->start_x + w * ch; for (x = 0; x < w; x+=40) { dst[x] = 200; } dst = s->outpicref->data[0] + (s->h + s->start_y + 2) * s->outpicref->linesize[0] + s->start_x + w * ch; for (x = 0; x < w; x+=80) { dst[x] = 200; } for (x = 0; x < w; x += 80) { float hertz = x * (inlink->sample_rate / 2) / (float)(1 << (int)ceil(log2(w))); char *units; if (hertz == 0) units = av_asprintf("DC"); else units = av_asprintf("%.2f", hertz); if (!units) return AVERROR(ENOMEM); drawtext(s->outpicref, s->start_x - 4 * strlen(units) + x + w * ch, s->start_y - 12, units, 0); drawtext(s->outpicref, s->start_x - 4 * strlen(units) + x + w * ch, s->h + s->start_y + 6, units, 0); av_free(units); } } for (y = 0; y < s->h; y+=40) { float seconds = y * spp / inlink->sample_rate; char *units; if (x == 0) units = av_asprintf("0"); else if (log10(seconds) > 6) units = av_asprintf("%.2fh", seconds / (60 * 60)); else if (log10(seconds) > 3) units = av_asprintf("%.2fm", seconds / 60); else units = av_asprintf("%.2fs", seconds); if (!units) return AVERROR(ENOMEM); drawtext(s->outpicref, s->start_x - 8 * strlen(units) - 4, s->start_y + y - 4, units, 0); av_free(units); } drawtext(s->outpicref, s->start_x / 7, outlink->h / 2 - 4 * 4, "TIME", 1); drawtext(s->outpicref, outlink->w / 2 - 14 * 4, outlink->h - s->start_y / 2, "FREQUENCY (Hz)", 0); } for (ch = 0; ch < (multi ? s->nb_display_channels : 1); ch++) { int h = multi ? s->h / s->nb_display_channels : s->h; for (y = 0; y < h; y++) { float out[3] = { 0., 127.5, 127.5}; int chn; for (chn = 0; chn < (s->mode == SEPARATE ? 1 : s->nb_display_channels); chn++) { float yf, uf, vf; int channel = (multi) ? s->nb_display_channels - ch - 1 : chn; float lout[3]; color_range(s, channel, &yf, &uf, &vf); pick_color(s, yf, uf, vf, y / (float)h, lout); out[0] += lout[0]; out[1] += lout[1]; out[2] += lout[2]; } memset(s->outpicref->data[0]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[0] + s->w + s->start_x + 20, av_clip_uint8(out[0]), 10); memset(s->outpicref->data[1]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[1] + s->w + s->start_x + 20, av_clip_uint8(out[1]), 10); memset(s->outpicref->data[2]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[2] + s->w + s->start_x + 20, av_clip_uint8(out[2]), 10); } for (y = 0; ch == 0 && y < h; y += h / 10) { float value = 120.0 * log10(1. - y / (float)h); char *text; if (value < -120) break; text = av_asprintf("%.0f dB", value); if (!text) continue; drawtext(s->outpicref, s->w + s->start_x + 35, s->start_y + y - 5, text, 0); av_free(text); } } } ret = ff_filter_frame(outlink, s->outpicref); s->outpicref = NULL; } return ret; }
true
FFmpeg
836c8750b31329e71e5ac2a194523172875b77eb
6,645
static int usb_msd_initfn_storage(USBDevice *dev) { MSDState *s = DO_UPCAST(MSDState, dev, dev); BlockDriverState *bs = s->conf.bs; SCSIDevice *scsi_dev; Error *err = NULL; if (!bs) { error_report("drive property not set"); return -1; } blkconf_serial(&s->conf, &dev->serial); /* * Hack alert: this pretends to be a block device, but it's really * a SCSI bus that can serve only a single device, which it * creates automatically. But first it needs to detach from its * blockdev, or else scsi_bus_legacy_add_drive() dies when it * attaches again. * * The hack is probably a bad idea. */ bdrv_detach_dev(bs, &s->dev.qdev); s->conf.bs = NULL; usb_desc_create_serial(dev); usb_desc_init(dev); scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_storage, NULL); scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable, s->conf.bootindex, dev->serial, &err); if (!scsi_dev) { return -1; } s->bus.qbus.allow_hotplug = 0; usb_msd_handle_reset(dev); if (bdrv_key_required(bs)) { if (cur_mon) { monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, s); s->dev.auto_attach = 0; } else { autostart = 0; } } return 0; }
true
qemu
f0bc7fe3b75d2ae4aedb6da6f68ebb87f77d929b
6,647
static gnutls_anon_server_credentials_t vnc_tls_initialize_anon_cred(void) { gnutls_anon_server_credentials_t anon_cred; int ret; if ((ret = gnutls_anon_allocate_server_credentials(&anon_cred)) < 0) { VNC_DEBUG("Cannot allocate credentials %s\n", gnutls_strerror(ret)); return NULL; } gnutls_anon_set_server_dh_params(anon_cred, dh_params); return anon_cred; }
true
qemu
3e305e4a4752f70c0b5c3cf5b43ec957881714f7
6,648
static void hypercall_init(void) { /* hcall-pft */ spapr_register_hypercall(H_ENTER, h_enter); spapr_register_hypercall(H_REMOVE, h_remove); spapr_register_hypercall(H_PROTECT, h_protect); /* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall(KVMPPC_H_RTAS, h_rtas); }
true
qemu
821303f59b63ab832f0921f070db55e95bb21858
6,649
static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) { int64_t total_sectors = bmds->total_sectors; int64_t cur_sector = bmds->cur_sector; BlockDriverState *bs = bmds->bs; BlkMigBlock *blk; int nr_sectors; if (bmds->shared_base) { qemu_mutex_lock_iothread(); while (cur_sector < total_sectors && !bdrv_is_allocated(bs, cur_sector, MAX_IS_ALLOCATED_SEARCH, &nr_sectors)) { cur_sector += nr_sectors; } qemu_mutex_unlock_iothread(); } if (cur_sector >= total_sectors) { bmds->cur_sector = bmds->completed_sectors = total_sectors; return 1; } bmds->completed_sectors = cur_sector; cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1); /* we are going to transfer a full block even if it is not allocated */ nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK; if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) { nr_sectors = total_sectors - cur_sector; } blk = g_malloc(sizeof(BlkMigBlock)); blk->buf = g_malloc(BLOCK_SIZE); blk->bmds = bmds; blk->sector = cur_sector; blk->nr_sectors = nr_sectors; blk->iov.iov_base = blk->buf; blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&blk->qiov, &blk->iov, 1); blk_mig_lock(); block_mig_state.submitted++; blk_mig_unlock(); qemu_mutex_lock_iothread(); blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov, nr_sectors, blk_mig_read_cb, blk); bdrv_reset_dirty(bs, cur_sector, nr_sectors); qemu_mutex_unlock_iothread(); bmds->cur_sector = cur_sector + nr_sectors; return (bmds->cur_sector >= total_sectors); }
true
qemu
5839e53bbc0fec56021d758aab7610df421ed8c8
6,651
static int make_setup_request(AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge) { RTSPState *rt = s->priv_data; int rtx, j, i, err, interleave = 0; RTSPStream *rtsp_st; RTSPMessageHeader reply1, *reply = &reply1; char cmd[2048]; const char *trans_pref; if (rt->transport == RTSP_TRANSPORT_RDT) trans_pref = "x-pn-tng"; else trans_pref = "RTP/AVP"; /* default timeout: 1 minute */ rt->timeout = 60; /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each * RTSP stream */ for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { char transport[2048]; /** * WMS serves all UDP data over a single connection, the RTX, which * isn't necessarily the first in the SDP but has to be the first * to be set up, else the second/third SETUP will fail with a 461. */ if (lower_transport == RTSP_LOWER_TRANSPORT_UDP && rt->server_type == RTSP_SERVER_WMS) { if (i == 0) { /* rtx first */ for (rtx = 0; rtx < rt->nb_rtsp_streams; rtx++) { int len = strlen(rt->rtsp_streams[rtx]->control_url); if (len >= 4 && !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4, "/rtx")) break; } if (rtx == rt->nb_rtsp_streams) return -1; /* no RTX found */ rtsp_st = rt->rtsp_streams[rtx]; } else rtsp_st = rt->rtsp_streams[i > rtx ? i : i - 1]; } else rtsp_st = rt->rtsp_streams[i]; /* RTP/UDP */ if (lower_transport == RTSP_LOWER_TRANSPORT_UDP) { char buf[256]; if (rt->server_type == RTSP_SERVER_WMS && i > 1) { port = reply->transports[0].client_port_min; goto have_port; } /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while (j <= RTSP_RTP_PORT_MAX) { ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1, "?localport=%d", j); /* we will use two ports per rtp stream (rtp and rtcp) */ j += 2; if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) goto rtp_opened; } } #if 0 /* then try on any port */ if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { err = AVERROR_INVALIDDATA; goto fail; } #endif rtp_opened: port = rtp_get_local_rtp_port(rtsp_st->rtp_handle); have_port: snprintf(transport, sizeof(transport) - 1, "%s/UDP;", trans_pref); if (rt->server_type != RTSP_SERVER_REAL) av_strlcat(transport, "unicast;", sizeof(transport)); av_strlcatf(transport, sizeof(transport), "client_port=%d", port); if (rt->transport == RTSP_TRANSPORT_RTP && !(rt->server_type == RTSP_SERVER_WMS && i > 0)) av_strlcatf(transport, sizeof(transport), "-%d", port + 1); } /* RTP/TCP */ else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) { /** For WMS streams, the application streams are only used for * UDP. When trying to set it up for TCP streams, the server * will return an error. Therefore, we skip those streams. */ if (rt->server_type == RTSP_SERVER_WMS && s->streams[rtsp_st->stream_index]->codec->codec_type == AVMEDIA_TYPE_DATA) continue; snprintf(transport, sizeof(transport) - 1, "%s/TCP;", trans_pref); if (rt->server_type == RTSP_SERVER_WMS) av_strlcat(transport, "unicast;", sizeof(transport)); av_strlcatf(transport, sizeof(transport), "interleaved=%d-%d", interleave, interleave + 1); interleave += 2; } else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) { snprintf(transport, sizeof(transport) - 1, "%s/UDP;multicast", trans_pref); } if (s->oformat) { av_strlcat(transport, ";mode=receive", sizeof(transport)); } else if (rt->server_type == RTSP_SERVER_REAL || rt->server_type == RTSP_SERVER_WMS) av_strlcat(transport, ";mode=play", sizeof(transport)); snprintf(cmd, sizeof(cmd), "Transport: %s\r\n", transport); if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) { char real_res[41], real_csum[9]; ff_rdt_calc_response_and_checksum(real_res, real_csum, real_challenge); av_strlcatf(cmd, sizeof(cmd), "If-Match: %s\r\n" "RealChallenge2: %s, sd=%s\r\n", rt->session_id, real_res, real_csum); } ff_rtsp_send_cmd(s, "SETUP", rtsp_st->control_url, cmd, reply, NULL); if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) { err = 1; goto fail; } else if (reply->status_code != RTSP_STATUS_OK || reply->nb_transports != 1) { err = AVERROR_INVALIDDATA; goto fail; } /* XXX: same protocol for all streams is required */ if (i > 0) { if (reply->transports[0].lower_transport != rt->lower_transport || reply->transports[0].transport != rt->transport) { err = AVERROR_INVALIDDATA; goto fail; } } else { rt->lower_transport = reply->transports[0].lower_transport; rt->transport = reply->transports[0].transport; } /* close RTP connection if not chosen */ if (reply->transports[0].lower_transport != RTSP_LOWER_TRANSPORT_UDP && (lower_transport == RTSP_LOWER_TRANSPORT_UDP)) { url_close(rtsp_st->rtp_handle); rtsp_st->rtp_handle = NULL; } switch(reply->transports[0].lower_transport) { case RTSP_LOWER_TRANSPORT_TCP: rtsp_st->interleaved_min = reply->transports[0].interleaved_min; rtsp_st->interleaved_max = reply->transports[0].interleaved_max; break; case RTSP_LOWER_TRANSPORT_UDP: { char url[1024]; /* Use source address if specified */ if (reply->transports[0].source[0]) { ff_url_join(url, sizeof(url), "rtp", NULL, reply->transports[0].source, reply->transports[0].server_port_min, NULL); } else { ff_url_join(url, sizeof(url), "rtp", NULL, host, reply->transports[0].server_port_min, NULL); } if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { err = AVERROR_INVALIDDATA; goto fail; } /* Try to initialize the connection state in a * potential NAT router by sending dummy packets. * RTP/RTCP dummy packets are used for RDT, too. */ if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat && CONFIG_RTPDEC) rtp_send_punch_packets(rtsp_st->rtp_handle); break; } case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: { char url[1024], namebuf[50]; struct sockaddr_storage addr; int port, ttl; if (reply->transports[0].destination.ss_family) { addr = reply->transports[0].destination; port = reply->transports[0].port_min; ttl = reply->transports[0].ttl; } else { addr = rtsp_st->sdp_ip; port = rtsp_st->sdp_port; ttl = rtsp_st->sdp_ttl; } getnameinfo((struct sockaddr*) &addr, sizeof(addr), namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, port, "?ttl=%d", ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; } break; } } if ((err = rtsp_open_transport_ctx(s, rtsp_st))) goto fail; } if (reply->timeout > 0) rt->timeout = reply->timeout; if (rt->server_type == RTSP_SERVER_REAL) rt->need_subscription = 1; return 0; fail: for (i = 0; i < rt->nb_rtsp_streams; i++) { if (rt->rtsp_streams[i]->rtp_handle) { url_close(rt->rtsp_streams[i]->rtp_handle); rt->rtsp_streams[i]->rtp_handle = NULL; } } return err; }
true
FFmpeg
8c579c1c604306460436dcf1523117ca3b1aca82
6,652
void gic_update(GICState *s) { int best_irq; int best_prio; int irq; int irq_level, fiq_level; int cpu; int cm; for (cpu = 0; cpu < s->num_cpu; cpu++) { cm = 1 << cpu; s->current_pending[cpu] = 1023; if (!(s->ctlr & (GICD_CTLR_EN_GRP0 | GICD_CTLR_EN_GRP1)) || !(s->cpu_ctlr[cpu] & (GICC_CTLR_EN_GRP0 | GICC_CTLR_EN_GRP1))) { qemu_irq_lower(s->parent_irq[cpu]); qemu_irq_lower(s->parent_fiq[cpu]); continue; } best_prio = 0x100; best_irq = 1023; for (irq = 0; irq < s->num_irq; irq++) { if (GIC_TEST_ENABLED(irq, cm) && gic_test_pending(s, irq, cm) && (irq < GIC_INTERNAL || GIC_TARGET(irq) & cm)) { if (GIC_GET_PRIORITY(irq, cpu) < best_prio) { best_prio = GIC_GET_PRIORITY(irq, cpu); best_irq = irq; } } } if (best_irq != 1023) { trace_gic_update_bestirq(cpu, best_irq, best_prio, s->priority_mask[cpu], s->running_priority[cpu]); } irq_level = fiq_level = 0; if (best_prio < s->priority_mask[cpu]) { s->current_pending[cpu] = best_irq; if (best_prio < s->running_priority[cpu]) { int group = GIC_TEST_GROUP(best_irq, cm); if (extract32(s->ctlr, group, 1) && extract32(s->cpu_ctlr[cpu], group, 1)) { if (group == 0 && s->cpu_ctlr[cpu] & GICC_CTLR_FIQ_EN) { DPRINTF("Raised pending FIQ %d (cpu %d)\n", best_irq, cpu); fiq_level = 1; } else { DPRINTF("Raised pending IRQ %d (cpu %d)\n", best_irq, cpu); irq_level = 1; } } } } qemu_set_irq(s->parent_irq[cpu], irq_level); qemu_set_irq(s->parent_fiq[cpu], fiq_level); } }
true
qemu
2531088f6c1ce1f620f8d5a545f0af95598e69fc
6,653
static void residual_interp(int16_t *buf, int16_t *out, int lag, int gain, int *rseed) { int i; if (lag) { /* Voiced */ int16_t *vector_ptr = buf + PITCH_MAX; /* Attenuate */ for (i = 0; i < lag; i++) out[i] = vector_ptr[i - lag] * 3 >> 2; av_memcpy_backptr((uint8_t*)(out + lag), lag * sizeof(*out), (FRAME_LEN - lag) * sizeof(*out)); } else { /* Unvoiced */ for (i = 0; i < FRAME_LEN; i++) { *rseed = *rseed * 521 + 259; out[i] = gain * *rseed >> 15; } memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(*buf)); } }
true
FFmpeg
f2c539d3501111f10a2b4e9480ea54c0a3190680
6,655
static int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n) { int level, i, j, run; int code; RLTable *rl = &rl_mpeg1; const UINT8 *scan_table; const UINT16 *matrix; int mismatch; if (s->alternate_scan) scan_table = ff_alternate_vertical_scan; else scan_table = zigzag_direct; mismatch = 1; { int bit_cnt, v; UINT32 bit_buf; UINT8 *buf_ptr; i = 0; if (n < 4) matrix = s->non_intra_matrix; else matrix = s->chroma_non_intra_matrix; /* special case for the first coef. no need to add a second vlc table */ SAVE_BITS(&s->gb); SHOW_BITS(&s->gb, v, 2); if (v & 2) { run = 0; level = 1 - ((v & 1) << 1); FLUSH_BITS(2); RESTORE_BITS(&s->gb); goto add_coef; } RESTORE_BITS(&s->gb); } /* now quantify & encode AC coefs */ for(;;) { code = get_vlc(&s->gb, &rl->vlc); if (code < 0) return -1; if (code == 112) { break; } else if (code == 111) { /* escape */ run = get_bits(&s->gb, 6); level = get_bits(&s->gb, 12); level = (level << 20) >> 20; } else { run = rl->table_run[code]; level = rl->table_level[code]; if (get_bits1(&s->gb)) level = -level; } i += run; if (i >= 64) return -1; add_coef: j = scan_table[i]; dprintf("%d: run=%d level=%d\n", n, run, level); /* XXX: optimize */ if (level > 0) { level = ((level * 2 + 1) * s->qscale * matrix[j]) >> 5; } else { level = ((-level * 2 + 1) * s->qscale * matrix[j]) >> 5; level = -level; } /* XXX: is it really necessary to saturate since the encoder knows whats going on ? */ mismatch ^= level; block[j] = level; i++; } block[63] ^= (mismatch & 1); s->block_last_index[n] = i; return 0; }
true
FFmpeg
d7e9533aa06f4073a27812349b35ba5fede11ca1
6,656
static int aiff_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; AIFFOutputContext *aiff = s->priv_data; AVCodecParameters *par = s->streams[0]->codecpar; /* Chunks sizes must be even */ int64_t file_size, end_size; end_size = file_size = avio_tell(pb); if (file_size & 1) { avio_w8(pb, 0); end_size++; } if (s->pb->seekable) { /* File length */ avio_seek(pb, aiff->form, SEEK_SET); avio_wb32(pb, file_size - aiff->form - 4); /* Number of sample frames */ avio_seek(pb, aiff->frames, SEEK_SET); avio_wb32(pb, (file_size - aiff->ssnd - 12) / par->block_align); /* Sound Data chunk size */ avio_seek(pb, aiff->ssnd, SEEK_SET); avio_wb32(pb, file_size - aiff->ssnd - 4); /* return to the end */ avio_seek(pb, end_size, SEEK_SET); avio_flush(pb); } return 0; }
false
FFmpeg
83548fe894cdb455cc127f754d09905b6d23c173
6,657
static void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *buf1, const uint16_t *ubuf0, const uint16_t *ubuf1, const uint16_t *vbuf0, const uint16_t *vbuf1, const uint16_t *abuf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" "paddusb "RED_DITHER"(%5), %%mm5 \n\t" #endif WRITERGB16(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither) ); }
false
FFmpeg
13a099799e89a76eb921ca452e1b04a7a28a9855
6,658
struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe, int start, int w, int g, float ener0, float ener1, float ener01, int use_pcoeffs, int phase) { int i, w2; SingleChannelElement *sce0 = &cpe->ch[0]; SingleChannelElement *sce1 = &cpe->ch[1]; float *L = use_pcoeffs ? sce0->pcoeffs : sce0->coeffs; float *R = use_pcoeffs ? sce1->pcoeffs : sce1->coeffs; float *L34 = &s->scoefs[256*0], *R34 = &s->scoefs[256*1]; float *IS = &s->scoefs[256*2], *I34 = &s->scoefs[256*3]; float dist1 = 0.0f, dist2 = 0.0f; struct AACISError is_error = {0}; if (ener01 <= 0 || ener0 <= 0) { is_error.pass = 0; return is_error; } for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) { FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g]; FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g]; int is_band_type, is_sf_idx = FFMAX(1, sce0->sf_idx[(w+w2)*16+g]-4); float e01_34 = phase*pow(ener1/ener0, 3.0/4.0); float maxval, dist_spec_err = 0.0f; float minthr = FFMIN(band0->threshold, band1->threshold); for (i = 0; i < sce0->ics.swb_sizes[g]; i++) IS[i] = (L[start+(w+w2)*128+i] + phase*R[start+(w+w2)*128+i])*sqrt(ener0/ener01); abs_pow34_v(L34, &L[start+(w+w2)*128], sce0->ics.swb_sizes[g]); abs_pow34_v(R34, &R[start+(w+w2)*128], sce0->ics.swb_sizes[g]); abs_pow34_v(I34, IS, sce0->ics.swb_sizes[g]); maxval = find_max_val(1, sce0->ics.swb_sizes[g], I34); is_band_type = find_min_book(maxval, is_sf_idx); dist1 += quantize_band_cost(s, &L[start + (w+w2)*128], L34, sce0->ics.swb_sizes[g], sce0->sf_idx[(w+w2)*16+g], sce0->band_type[(w+w2)*16+g], s->lambda / band0->threshold, INFINITY, NULL, NULL, 0); dist1 += quantize_band_cost(s, &R[start + (w+w2)*128], R34, sce1->ics.swb_sizes[g], sce1->sf_idx[(w+w2)*16+g], sce1->band_type[(w+w2)*16+g], s->lambda / band1->threshold, INFINITY, NULL, NULL, 0); dist2 += quantize_band_cost(s, IS, I34, sce0->ics.swb_sizes[g], is_sf_idx, is_band_type, s->lambda / minthr, INFINITY, NULL, NULL, 0); for (i = 0; i < sce0->ics.swb_sizes[g]; i++) { dist_spec_err += (L34[i] - I34[i])*(L34[i] - I34[i]); dist_spec_err += (R34[i] - I34[i]*e01_34)*(R34[i] - I34[i]*e01_34); } dist_spec_err *= s->lambda / minthr; dist2 += dist_spec_err; } is_error.pass = dist2 <= dist1; is_error.phase = phase; is_error.error = fabsf(dist1 - dist2); is_error.dist1 = dist1; is_error.dist2 = dist2; is_error.ener01 = ener01; return is_error; }
false
FFmpeg
4dcb69cc12d00d46f93a07178e2087a8d27c8f64
6,659
static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) { HLSContext *hls = s->priv_data; AVFormatContext *oc = NULL; AVStream *st = s->streams[pkt->stream_index]; int64_t end_pts = hls->recording_time * hls->number; int is_ref_pkt = 1; int ret, can_split = 1; int stream_index = 0; if (hls->sequence - hls->nb_entries > hls->start_sequence && hls->init_time > 0) { /* reset end_pts, hls->recording_time at end of the init hls list */ int init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE; int after_init_list_dur = (hls->sequence - hls->nb_entries ) * hls->time * AV_TIME_BASE; hls->recording_time = hls->time * AV_TIME_BASE; end_pts = init_list_dur + after_init_list_dur ; } if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) { oc = hls->vtt_avf; stream_index = 0; } else { oc = hls->avf; stream_index = pkt->stream_index; } if (hls->start_pts == AV_NOPTS_VALUE) { hls->start_pts = pkt->pts; hls->end_pts = pkt->pts; } if (hls->has_video) { can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME)); is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; } if (pkt->pts == AV_NOPTS_VALUE) is_ref_pkt = can_split = 0; if (is_ref_pkt) { if (hls->new_start) { hls->new_start = 0; hls->duration = (double)(pkt->pts - hls->end_pts) * st->time_base.num / st->time_base.den; hls->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den; } else { hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den; } } if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base, end_pts, AV_TIME_BASE_Q) >= 0) { int64_t new_start_pos; char *old_filename = av_strdup(hls->avf->filename); if (!old_filename) { return AVERROR(ENOMEM); } av_write_frame(oc, NULL); /* Flush any buffered data */ new_start_pos = avio_tell(hls->avf->pb); hls->size = new_start_pos - hls->start_pos; ff_format_io_close(s, &oc->pb); if (hls->vtt_avf) { ff_format_io_close(s, &hls->vtt_avf->pb); } if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0]) { if (!(hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size <= 0)) if (hls->avf->oformat->priv_class && hls->avf->priv_data) av_opt_set(hls->avf->priv_data, "mpegts_flags", "resend_headers", 0); hls_rename_temp_file(s, oc); } ret = hls_append_segment(s, hls, hls->duration, hls->start_pos, hls->size); hls->start_pos = new_start_pos; if (ret < 0) { av_free(old_filename); return ret; } hls->end_pts = pkt->pts; hls->duration = 0; if (hls->flags & HLS_SINGLE_FILE) { hls->number++; } else if (hls->max_seg_size > 0) { if (hls->start_pos >= hls->max_seg_size) { hls->sequence++; sls_flag_file_rename(hls, old_filename); ret = hls_start(s); hls->start_pos = 0; /* When split segment by byte, the duration is short than hls_time, * so it is not enough one segment duration as hls_time, */ hls->number--; } hls->number++; } else { sls_flag_file_rename(hls, old_filename); ret = hls_start(s); } if (ret < 0) { av_free(old_filename); return ret; } if ((ret = hls_window(s, 0)) < 0) { av_free(old_filename); return ret; } } ret = ff_write_chained(oc, stream_index, pkt, s, 0); return ret; }
false
FFmpeg
d3ce067e7687203cf4a0a475ffd4b733b7c3b4f4
6,660
static void copy_cell(Indeo3DecodeContext *ctx, Plane *plane, Cell *cell) { int h, w, mv_x, mv_y, offset, offset_dst; uint8_t *src, *dst; /* setup output and reference pointers */ offset_dst = (cell->ypos << 2) * plane->pitch + (cell->xpos << 2); dst = plane->pixels[ctx->buf_sel] + offset_dst; mv_y = cell->mv_ptr[0]; mv_x = cell->mv_ptr[1]; offset = offset_dst + mv_y * plane->pitch + mv_x; src = plane->pixels[ctx->buf_sel ^ 1] + offset; h = cell->height << 2; for (w = cell->width; w > 0;) { /* copy using 16xH blocks */ if (!((cell->xpos << 2) & 15) && w >= 4) { for (; w >= 4; src += 16, dst += 16, w -= 4) ctx->dsp.put_no_rnd_pixels_tab[0][0](dst, src, plane->pitch, h); } /* copy using 8xH blocks */ if (!((cell->xpos << 2) & 7) && w >= 2) { ctx->dsp.put_no_rnd_pixels_tab[1][0](dst, src, plane->pitch, h); w -= 2; src += 8; dst += 8; } if (w >= 1) { copy_block4(dst, src, plane->pitch, plane->pitch, h); w--; src += 4; dst += 4; } } }
true
FFmpeg
e421b79d01a3bf18d1ff8d8c4639669b66d788a5
6,662
static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0); }
false
FFmpeg
dd561441b1e849df7d8681c6f32af82d4088dafd
6,663
static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, bool last_stage, ram_addr_t dirty_ram_abs) { int tmppages, pages = 0; size_t pagesize = qemu_ram_pagesize(pss->block); do { tmppages = ram_save_target_page(rs, pss, last_stage, dirty_ram_abs); if (tmppages < 0) { return tmppages; } pages += tmppages; pss->offset += TARGET_PAGE_SIZE; dirty_ram_abs += TARGET_PAGE_SIZE; } while (pss->offset & (pagesize - 1)); /* The offset we leave with is the last one we looked at */ pss->offset -= TARGET_PAGE_SIZE; return pages; }
true
qemu
06b106889a09277617fc8c542397a9f595ee605a
6,664
static void gen_check_privilege(DisasContext *dc) { if (dc->cring) { gen_exception_cause(dc, PRIVILEGED_CAUSE); dc->is_jmp = DISAS_UPDATE; } }
true
qemu
97e89ee914411384dcda771d38bf89f13726d71e
6,665
MigrationState *unix_start_outgoing_migration(Monitor *mon, const char *path, int64_t bandwidth_limit, int detach, int blk, int inc) { FdMigrationState *s; struct sockaddr_un addr; int ret; addr.sun_family = AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); s = qemu_mallocz(sizeof(*s)); s->get_error = unix_errno; s->write = unix_write; s->close = unix_close; s->mig_state.cancel = migrate_fd_cancel; s->mig_state.get_status = migrate_fd_get_status; s->mig_state.release = migrate_fd_release; s->mig_state.blk = blk; s->mig_state.shared = inc; s->state = MIG_STATE_ACTIVE; s->mon = NULL; s->bandwidth_limit = bandwidth_limit; s->fd = socket(PF_UNIX, SOCK_STREAM, 0); if (s->fd < 0) { dprintf("Unable to open socket"); goto err_after_alloc; } socket_set_nonblock(s->fd); if (!detach) { migrate_fd_monitor_suspend(s, mon); } do { ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret == -1) ret = -(s->get_error(s)); if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) qemu_set_fd_handler2(s->fd, NULL, NULL, unix_wait_for_connect, s); } while (ret == -EINTR); if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) { dprintf("connect failed\n"); goto err_after_open; } else if (ret >= 0) migrate_fd_connect(s); return &s->mig_state; err_after_open: close(s->fd); err_after_alloc: qemu_free(s); return NULL; }
true
qemu
40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4
6,666
static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { FDKAACDecContext *s = avctx->priv_data; AVFrame *frame = data; int ret; AAC_DECODER_ERROR err; UINT valid = avpkt->size; err = aacDecoder_Fill(s->handle, &avpkt->data, &avpkt->size, &valid); if (err != AAC_DEC_OK) { av_log(avctx, AV_LOG_ERROR, "aacDecoder_Fill() failed: %x\n", err); return AVERROR_INVALIDDATA; } err = aacDecoder_DecodeFrame(s->handle, (INT_PCM *) s->decoder_buffer, s->decoder_buffer_size, 0); if (err == AAC_DEC_NOT_ENOUGH_BITS) { ret = avpkt->size - valid; goto end; } if (err != AAC_DEC_OK) { av_log(avctx, AV_LOG_ERROR, "aacDecoder_DecodeFrame() failed: %x\n", err); ret = AVERROR_UNKNOWN; goto end; } if ((ret = get_stream_info(avctx)) < 0) goto end; frame->nb_samples = avctx->frame_size; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) goto end; memcpy(frame->extended_data[0], s->decoder_buffer, avctx->channels * avctx->frame_size * av_get_bytes_per_sample(avctx->sample_fmt)); *got_frame_ptr = 1; ret = avpkt->size - valid; end: return ret; }
true
FFmpeg
ca6776a993903dbcfef5ae8a18556c40ecf83e1c
6,667
static void readline_completion(ReadLineState *rs) { Monitor *mon = cur_mon; int len, i, j, max_width, nb_cols, max_prefix; char *cmdline; rs->nb_completions = 0; cmdline = g_malloc(rs->cmd_buf_index + 1); memcpy(cmdline, rs->cmd_buf, rs->cmd_buf_index); cmdline[rs->cmd_buf_index] = '\0'; rs->completion_finder(cmdline); g_free(cmdline); /* no completion found */ if (rs->nb_completions <= 0) return; if (rs->nb_completions == 1) { len = strlen(rs->completions[0]); for(i = rs->completion_index; i < len; i++) { readline_insert_char(rs, rs->completions[0][i]); /* extra space for next argument. XXX: make it more generic */ if (len > 0 && rs->completions[0][len - 1] != '/') readline_insert_char(rs, ' '); } else { monitor_printf(mon, "\n"); max_width = 0; max_prefix = 0; for(i = 0; i < rs->nb_completions; i++) { len = strlen(rs->completions[i]); if (i==0) { max_prefix = len; } else { if (len < max_prefix) max_prefix = len; for(j=0; j<max_prefix; j++) { if (rs->completions[i][j] != rs->completions[0][j]) max_prefix = j; if (len > max_width) max_width = len; if (max_prefix > 0) for(i = rs->completion_index; i < max_prefix; i++) { readline_insert_char(rs, rs->completions[0][i]); max_width += 2; if (max_width < 10) max_width = 10; else if (max_width > 80) max_width = 80; nb_cols = 80 / max_width; j = 0; for(i = 0; i < rs->nb_completions; i++) { monitor_printf(rs->mon, "%-*s", max_width, rs->completions[i]); if (++j == nb_cols || i == (rs->nb_completions - 1)) { monitor_printf(rs->mon, "\n"); j = 0; readline_show_prompt(rs);
true
qemu
fc9fa4bd0a295ac18808c4cd2cfac484bc4649d3
6,668
static av_cold int png_dec_init(AVCodecContext *avctx) { PNGDecContext *s = avctx->priv_data; s->avctx = avctx; s->previous_picture.f = av_frame_alloc(); s->last_picture.f = av_frame_alloc(); s->picture.f = av_frame_alloc(); if (!s->previous_picture.f || !s->last_picture.f || !s->picture.f) return AVERROR(ENOMEM); if (!avctx->internal->is_copy) { avctx->internal->allocate_progress = 1; ff_pngdsp_init(&s->dsp); } return 0; }
true
FFmpeg
6e9b060e4f0c24d2689bebd7fc03e52d75da25b2
6,669
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int width, int lines) { int i, ret = 0; int line; uint8_t *src2 = av_malloc((unsigned)size + AV_INPUT_BUFFER_PADDING_SIZE); if (!src2) { av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n"); return AVERROR(ENOMEM); } if (!s->fill_order) { memcpy(src2, src, size); } else { for (i = 0; i < size; i++) src2[i] = ff_reverse[src[i]]; } memset(src2 + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts); if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) for (line = 0; line < lines; line++) { horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0); dst += stride; } av_free(src2); return ret; }
true
FFmpeg
9221445fa001093307864a53f91c1172c239de18
6,671
int tlb_set_page_exec(CPUState *env, target_ulong vaddr, target_phys_addr_t paddr, int prot, int is_user, int is_softmmu) { PhysPageDesc *p; unsigned long pd; unsigned int index; target_ulong address; target_phys_addr_t addend; int ret; CPUTLBEntry *te; p = phys_page_find(paddr >> TARGET_PAGE_BITS); if (!p) { pd = IO_MEM_UNASSIGNED; } else { pd = p->phys_offset; } #if defined(DEBUG_TLB) printf("tlb_set_page: vaddr=" TARGET_FMT_lx " paddr=0x%08x prot=%x u=%d smmu=%d pd=0x%08lx\n", vaddr, (int)paddr, prot, is_user, is_softmmu, pd); #endif ret = 0; #if !defined(CONFIG_SOFTMMU) if (is_softmmu) #endif { if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) { /* IO memory case */ address = vaddr | pd; addend = paddr; } else { /* standard memory */ address = vaddr; addend = (unsigned long)phys_ram_base + (pd & TARGET_PAGE_MASK); } /* Make accesses to pages with watchpoints go via the watchpoint trap routines. */ for (i = 0; i < env->nb_watchpoints; i++) { if (vaddr == (env->watchpoint[i].vaddr & TARGET_PAGE_MASK)) { if (address & ~TARGET_PAGE_MASK) { env->watchpoint[i].is_ram = 0; address = vaddr | io_mem_watch; } else { env->watchpoint[i].is_ram = 1; /* TODO: Figure out how to make read watchpoints coexist with code. */ pd = (pd & TARGET_PAGE_MASK) | io_mem_watch | IO_MEM_ROMD; } } } index = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); addend -= vaddr; te = &env->tlb_table[is_user][index]; te->addend = addend; if (prot & PAGE_READ) { te->addr_read = address; } else { te->addr_read = -1; } if (prot & PAGE_EXEC) { te->addr_code = address; } else { te->addr_code = -1; } if (prot & PAGE_WRITE) { if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM || (pd & IO_MEM_ROMD)) { /* write access calls the I/O callback */ te->addr_write = vaddr | (pd & ~(TARGET_PAGE_MASK | IO_MEM_ROMD)); } else if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM && !cpu_physical_memory_is_dirty(pd)) { te->addr_write = vaddr | IO_MEM_NOTDIRTY; } else { te->addr_write = address; } } else { te->addr_write = -1; } } #if !defined(CONFIG_SOFTMMU) else { if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) { /* IO access: no mapping is done as it will be handled by the soft MMU */ if (!(env->hflags & HF_SOFTMMU_MASK)) ret = 2; } else { void *map_addr; if (vaddr >= MMAP_AREA_END) { ret = 2; } else { if (prot & PROT_WRITE) { if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM || #if defined(TARGET_HAS_SMC) || 1 first_tb || #endif ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM && !cpu_physical_memory_is_dirty(pd))) { /* ROM: we do as if code was inside */ /* if code is present, we only map as read only and save the original mapping */ VirtPageDesc *vp; vp = virt_page_find_alloc(vaddr >> TARGET_PAGE_BITS, 1); vp->phys_addr = pd; vp->prot = prot; vp->valid_tag = virt_valid_tag; prot &= ~PAGE_WRITE; } } map_addr = mmap((void *)vaddr, TARGET_PAGE_SIZE, prot, MAP_SHARED | MAP_FIXED, phys_ram_fd, (pd & TARGET_PAGE_MASK)); if (map_addr == MAP_FAILED) { cpu_abort(env, "mmap failed when mapped physical address 0x%08x to virtual address 0x%08x\n", paddr, vaddr); } } } } #endif return ret; }
true
qemu
6658ffb81ee56a510d7d77025872a508a9adce3a
6,672
static void do_video_out(AVFormatContext *s, AVOutputStream *ost, AVInputStream *ist, AVPicture *in_picture, int *frame_size, AVOutputStream *audio_sync) { int nb_frames, i, ret; AVPicture *final_picture, *formatted_picture; AVPicture picture_format_temp, picture_crop_temp; static uint8_t *video_buffer; uint8_t *buf = NULL, *buf1 = NULL; AVCodecContext *enc, *dec; #define VIDEO_BUFFER_SIZE (1024*1024) enc = &ost->st->codec; dec = &ist->st->codec; /* by default, we output a single frame */ nb_frames = 1; *frame_size = 0; /* NOTE: the A/V sync is always done by considering the audio is the master clock. It is suffisant for transcoding or playing, but not for the general case */ if (audio_sync) { /* compute the A-V delay and duplicate/remove frames if needed */ double adelta, vdelta, av_delay; adelta = audio_sync->sync_ipts - ((double)audio_sync->sync_opts * s->pts_num / s->pts_den); vdelta = ost->sync_ipts - ((double)ost->sync_opts * s->pts_num / s->pts_den); av_delay = adelta - vdelta; // printf("delay=%f\n", av_delay); if (av_delay < -AV_DELAY_MAX) nb_frames = 2; else if (av_delay > AV_DELAY_MAX) nb_frames = 0; } else { double vdelta; vdelta = (double)(ost->st->pts.val) * s->pts_num / s->pts_den - (ost->sync_ipts - ost->sync_ipts_offset); if (vdelta < 100 && vdelta > -100 && ost->sync_ipts_offset) { if (vdelta < -AV_DELAY_MAX) nb_frames = 2; else if (vdelta > AV_DELAY_MAX) nb_frames = 0; } else { ost->sync_ipts_offset -= vdelta; if (!ost->sync_ipts_offset) ost->sync_ipts_offset = 0.000001; /* one microsecond */ } } #if defined(AVSYNC_DEBUG) static char *action[] = { "drop frame", "copy frame", "dup frame" }; if (audio_sync) fprintf(stderr, "Input APTS %12.6f, output APTS %12.6f, ", (double) audio_sync->sync_ipts, (double) audio_sync->st->pts.val * s->pts_num / s->pts_den); fprintf(stderr, "Input VPTS %12.6f, output VPTS %12.6f: %s\n", (double) ost->sync_ipts, (double) ost->st->pts.val * s->pts_num / s->pts_den, action[nb_frames]); #endif if (nb_frames <= 0) return; if (!video_buffer) video_buffer = av_malloc(VIDEO_BUFFER_SIZE); if (!video_buffer) return; /* convert pixel format if needed */ if (enc->pix_fmt != dec->pix_fmt) { int size; /* create temporary picture */ size = avpicture_get_size(enc->pix_fmt, dec->width, dec->height); buf = av_malloc(size); if (!buf) return; formatted_picture = &picture_format_temp; avpicture_fill(formatted_picture, buf, enc->pix_fmt, dec->width, dec->height); if (img_convert(formatted_picture, enc->pix_fmt, in_picture, dec->pix_fmt, dec->width, dec->height) < 0) { fprintf(stderr, "pixel format conversion not handled\n"); goto the_end; } } else { formatted_picture = in_picture; } /* XXX: resampling could be done before raw format convertion in some cases to go faster */ /* XXX: only works for YUV420P */ if (ost->video_resample) { final_picture = &ost->pict_tmp; img_resample(ost->img_resample_ctx, final_picture, formatted_picture); } else if (ost->video_crop) { picture_crop_temp.data[0] = formatted_picture->data[0] + (ost->topBand * formatted_picture->linesize[0]) + ost->leftBand; picture_crop_temp.data[1] = formatted_picture->data[1] + ((ost->topBand >> 1) * formatted_picture->linesize[1]) + (ost->leftBand >> 1); picture_crop_temp.data[2] = formatted_picture->data[2] + ((ost->topBand >> 1) * formatted_picture->linesize[2]) + (ost->leftBand >> 1); picture_crop_temp.linesize[0] = formatted_picture->linesize[0]; picture_crop_temp.linesize[1] = formatted_picture->linesize[1]; picture_crop_temp.linesize[2] = formatted_picture->linesize[2]; final_picture = &picture_crop_temp; } else { final_picture = formatted_picture; } /* duplicates frame if needed */ /* XXX: pb because no interleaving */ for(i=0;i<nb_frames;i++) { if (s->oformat->flags & AVFMT_RAWPICTURE) { /* raw pictures are written as AVPicture structure to avoid any copies. We support temorarily the older method. */ av_write_frame(s, ost->index, (uint8_t *)final_picture, sizeof(AVPicture)); } else { AVFrame big_picture; memset(&big_picture, 0, sizeof(AVFrame)); *(AVPicture*)&big_picture= *final_picture; /* handles sameq here. This is not correct because it may not be a global option */ if (same_quality) { big_picture.quality = ist->st->quality; }else big_picture.quality = ost->st->quality; ret = avcodec_encode_video(enc, video_buffer, VIDEO_BUFFER_SIZE, &big_picture); //enc->frame_number = enc->real_pict_num; av_write_frame(s, ost->index, video_buffer, ret); *frame_size = ret; //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d", // enc->frame_number-1, enc->real_pict_num, ret, // enc->pict_type); /* if two pass, output log */ if (ost->logfile && enc->stats_out) { fprintf(ost->logfile, "%s", enc->stats_out); } } ost->frame_number++; } the_end: av_free(buf); av_free(buf1); }
true
FFmpeg
a686caf03ddd29b32abd1af5c6f887bc09e6d71b
6,675
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags) { NUTContext *nut = s->priv_data; AVStream *st = s->streams[stream_index]; Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE }; Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE }; Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp }; int64_t pos, pos2, ts; int i; if (nut->flags & NUT_PIPE) { return AVERROR(ENOSYS); } if (st->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index < 0) index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD); if (index < 0) return -1; pos2 = st->index_entries[index].pos; ts = st->index_entries[index].timestamp; } else { av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp, (void **) next_node); av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos, next_node[0]->ts, next_node[1]->ts); pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, next_node[0]->ts, next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); if (!(flags & AVSEEK_FLAG_BACKWARD)) { dummy.pos = pos + 16; next_node[1] = &nopts_sp; av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, (void **) next_node); pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); if (pos2 >= 0) pos = pos2; // FIXME dir but I think it does not matter } dummy.pos = pos; sp = av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, NULL); av_assert0(sp); pos2 = sp->back_ptr - 15; } av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2); pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2); avio_seek(s->pb, pos, SEEK_SET); nut->last_syncpoint_pos = pos; av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos); if (pos2 > pos || pos2 + 15 < pos) av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n"); for (i = 0; i < s->nb_streams; i++) nut->stream[i].skip_until_key_frame = 1; nut->last_resync_pos = 0; return 0; }
true
FFmpeg
60ec3007e69ce8c5ae540c81b0bd21c1ebe1543a
6,676
static QList *get_cpus(QDict **resp) { *resp = qmp("{ 'execute': 'query-cpus' }"); g_assert(*resp); g_assert(qdict_haskey(*resp, "return")); return qdict_get_qlist(*resp, "return"); }
true
qemu
5e39d89d20b17cf6fb7f09d181d34f17b2ae2160
6,677
QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list) { size_t num_opts, num_dst_opts; QemuOptDesc *desc; bool need_init = false; if (!list) { return dst; } /* If dst is NULL, after realloc, some area of dst should be initialized * before adding options to it. */ if (!dst) { need_init = true; } num_opts = count_opts_list(dst); num_dst_opts = num_opts; num_opts += count_opts_list(list); dst = g_realloc(dst, sizeof(QemuOptsList) + (num_opts + 1) * sizeof(QemuOptDesc)); if (need_init) { dst->name = NULL; dst->implied_opt_name = NULL; QTAILQ_INIT(&dst->head); dst->merge_lists = false; } dst->desc[num_dst_opts].name = NULL; /* append list->desc to dst->desc */ if (list) { desc = list->desc; while (desc && desc->name) { if (find_desc_by_name(dst->desc, desc->name) == NULL) { dst->desc[num_dst_opts++] = *desc; dst->desc[num_dst_opts].name = NULL; } desc++; } } return dst; }
true
qemu
a760715095e9cda6eb97486c040aa35f82297945
6,678
static void vnc_dpy_setdata(DisplayChangeListener *dcl, DisplayState *ds) { VncDisplay *vd = ds->opaque; qemu_pixman_image_unref(vd->guest.fb); vd->guest.fb = pixman_image_ref(ds->surface->image); vd->guest.format = ds->surface->format; vnc_dpy_update(dcl, ds, 0, 0, ds_get_width(ds), ds_get_height(ds)); }
true
qemu
21ef45d71221b4577330fe3aacfb06afad91ad46
6,680
static inline int cris_addc(int a, const int b) { asm ("addc\t%1, %0\n" : "+r" (a) : "r" (b)); return a; }
true
qemu
21ce148c7ec71ee32834061355a5ecfd1a11f90f
6,681
void acpi_setup(PcGuestInfo *guest_info) { AcpiBuildTables tables; AcpiBuildState *build_state; if (!guest_info->fw_cfg) { ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n"); return; } if (!guest_info->has_acpi_build) { ACPI_BUILD_DPRINTF("ACPI build disabled. Bailing out.\n"); return; } if (!acpi_enabled) { ACPI_BUILD_DPRINTF("ACPI disabled. Bailing out.\n"); return; } build_state = g_malloc0(sizeof *build_state); build_state->guest_info = guest_info; acpi_set_pci_info(); acpi_build_tables_init(&tables); acpi_build(build_state->guest_info, &tables); /* Now expose it all to Guest */ build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data, ACPI_BUILD_TABLE_FILE, ACPI_BUILD_TABLE_MAX_SIZE); assert(build_state->table_ram != RAM_ADDR_MAX); build_state->table_size = acpi_data_len(tables.table_data); acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader", 0); fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); /* * RSDP is small so it's easy to keep it immutable, no need to * bother with ROM blobs. */ fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE, tables.rsdp->data, acpi_data_len(tables.rsdp)); qemu_register_reset(acpi_build_reset, build_state); acpi_build_reset(build_state); vmstate_register(NULL, 0, &vmstate_acpi_build, build_state); /* Cleanup tables but don't free the memory: we track it * in build_state. */ acpi_build_tables_cleanup(&tables, false); }
true
qemu
d70414a5788c3d51f8ce4d2f437e669e6b99dc59
6,683
static void reset_used_window(DisasContext *dc) { dc->used_window = 0; }
true
qemu
2db59a76c421cdd1039d10e32a9798952d3ff5ba
6,684
static int decode_block(MJpegDecodeContext *s, int16_t *block, int component, int dc_index, int ac_index, uint16_t *quant_matrix) { int code, i, j, level, val; /* DC coef */ val = mjpeg_decode_dc(s, dc_index); if (val == 0xfffff) { av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); return AVERROR_INVALIDDATA; } val = val * quant_matrix[0] + s->last_dc[component]; val = FFMIN(val, 32767); s->last_dc[component] = val; block[0] = val; /* AC coefs */ i = 0; {OPEN_READER(re, &s->gb); do { UPDATE_CACHE(re, &s->gb); GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2); i += ((unsigned)code) >> 4; code &= 0xf; if (code) { if (code > MIN_CACHE_BITS - 16) UPDATE_CACHE(re, &s->gb); { int cache = GET_CACHE(re, &s->gb); int sign = (~cache) >> 31; level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; } LAST_SKIP_BITS(re, &s->gb, code); if (i > 63) { av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); return AVERROR_INVALIDDATA; } j = s->scantable.permutated[i]; block[j] = level * quant_matrix[i]; } } while (i < 63); CLOSE_READER(re, &s->gb);} return 0; }
true
FFmpeg
c28f648b19dd36ff9bc869ad527a1569a0b623e2
6,687
static int usb_host_scan(void *opaque, USBScanFunc *func) { FILE *f = 0; DIR *dir = 0; int ret = 0; const char *devices = "/devices"; const char *opened = "husb: opened %s%s\n"; const char *fs_type[] = {"unknown", "proc", "dev", "sys"}; char devpath[PATH_MAX]; /* only check the host once */ if (!usb_fs_type) { f = fopen(USBPROCBUS_PATH "/devices", "r"); if (f) { /* devices found in /proc/bus/usb/ */ strcpy(devpath, USBPROCBUS_PATH); usb_fs_type = USB_FS_PROC; fclose(f); dprintf(opened, USBPROCBUS_PATH, devices); } /* try additional methods if an access method hasn't been found yet */ f = fopen(USBDEVBUS_PATH "/devices", "r"); if (!usb_fs_type && f) { /* devices found in /dev/bus/usb/ */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_DEV; fclose(f); dprintf(opened, USBDEVBUS_PATH, devices); } dir = opendir(USBSYSBUS_PATH "/devices"); if (!usb_fs_type && dir) { /* devices found in /dev/bus/usb/ (yes - not a mistake!) */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_SYS; closedir(dir); dprintf(opened, USBSYSBUS_PATH, devices); } if (!usb_fs_type) { term_printf("husb: unable to access USB devices\n"); goto the_end; } /* the module setting (used later for opening devices) */ usb_host_device_path = qemu_mallocz(strlen(devpath)+1); if (usb_host_device_path) { strcpy(usb_host_device_path, devpath); term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path); } else { /* out of memory? */ perror("husb: unable to allocate memory for device path"); goto the_end; } } switch (usb_fs_type) { case USB_FS_PROC: case USB_FS_DEV: ret = usb_host_scan_dev(opaque, func); break; case USB_FS_SYS: ret = usb_host_scan_sys(opaque, func); break; } the_end: return ret; }
true
qemu
f16a0db323e1a8c0044696815cceeb98706f2243
6,688
static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) { int qscale; int shift=0; for(qscale=qmin; qscale<=qmax; qscale++){ int i; if (dsp->fdct == ff_jpeg_fdct_islow #ifdef FAAN_POSTSCALE || dsp->fdct == ff_faandct #endif ) { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* 16 <= qscale * quant_matrix[i] <= 7905 */ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); } } else if (dsp->fdct == fdct_ifast #ifndef FAAN_POSTSCALE || dsp->fdct == ff_faandct #endif ) { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* 16 <= qscale * quant_matrix[i] <= 7905 */ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) / (aanscales[i] * qscale * quant_matrix[j])); } } else { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* We can safely suppose that 16 <= quant_matrix[i] <= 255 So 16 <= qscale * quant_matrix[i] <= 7905 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 */ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); } } for(i=intra; i<64; i++){ while(((8191LL * qmat[qscale][i]) >> shift) > INT_MAX){ shift++; } } } if(shift){ av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger then %d, overflows possible\n", QMAT_SHIFT - shift); } }
true
FFmpeg
3c9ec07ef2f7a761bf0418b4d806b50ef57c41f3
6,689
static int process_frame_obj(SANMVideoContext *ctx) { uint16_t codec, top, left, w, h; codec = bytestream2_get_le16u(&ctx->gb); left = bytestream2_get_le16u(&ctx->gb); top = bytestream2_get_le16u(&ctx->gb); w = bytestream2_get_le16u(&ctx->gb); h = bytestream2_get_le16u(&ctx->gb); if (ctx->width < left + w || ctx->height < top + h) { if (av_image_check_size(FFMAX(left + w, ctx->width), FFMAX(top + h, ctx->height), 0, ctx->avctx) < 0) avcodec_set_dimensions(ctx->avctx, FFMAX(left + w, ctx->width), FFMAX(top + h, ctx->height)); init_sizes(ctx, FFMAX(left + w, ctx->width), FFMAX(top + h, ctx->height)); if (init_buffers(ctx)) { av_log(ctx->avctx, AV_LOG_ERROR, "error resizing buffers\n"); return AVERROR(ENOMEM); bytestream2_skip(&ctx->gb, 4); av_dlog(ctx->avctx, "subcodec %d\n", codec); switch (codec) { case 1: case 3: return old_codec1(ctx, top, left, w, h); break; case 37: return old_codec37(ctx, top, left, w, h); break; case 47: return old_codec47(ctx, top, left, w, h); break; default: avpriv_request_sample(ctx->avctx, "unknown subcodec %d", codec); return AVERROR_PATCHWELCOME;
true
FFmpeg
9dd04f6d8cdd1c10c28b2cb4252c1a41df581915
6,690
static int tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x) { int mode; int i; int8_t dc[6]; mode = bytestream2_get_byte(&s->gb); if (mode > 12) { GetBitContext gb; init_get_bits8(&gb, s->gb.buffer, FFMIN(bytestream2_get_bytes_left(&s->gb), mode)); for (i = 0; i < 6; i++) tgq_decode_block(s, s->block[i], &gb); tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y); bytestream2_skip(&s->gb, mode); } else { if (mode == 3) { memset(dc, bytestream2_get_byte(&s->gb), 4); dc[4] = bytestream2_get_byte(&s->gb); dc[5] = bytestream2_get_byte(&s->gb); } else if (mode == 6) { bytestream2_get_buffer(&s->gb, dc, 6); } else if (mode == 12) { for (i = 0; i < 6; i++) { dc[i] = bytestream2_get_byte(&s->gb); bytestream2_skip(&s->gb, 1); } } else { av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode); return -1; } tgq_idct_put_mb_dconly(s, frame, mb_x, mb_y, dc); } return 0; }
true
FFmpeg
c447ab0e746c6b4d8d703a55190ae7444199e502
6,691
static void stream_component_close(VideoState *is, int stream_index) { AVFormatContext *ic = is->ic; AVCodecContext *avctx; if (stream_index < 0 || stream_index >= ic->nb_streams) return; avctx = ic->streams[stream_index]->codec; switch(avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: packet_queue_abort(&is->audioq); SDL_CloseAudio(); packet_queue_end(&is->audioq); av_free_packet(&is->audio_pkt); if (is->reformat_ctx) av_audio_convert_free(is->reformat_ctx); is->reformat_ctx = NULL; if (is->rdft) { av_rdft_end(is->rdft); av_freep(&is->rdft_data); } break; case AVMEDIA_TYPE_VIDEO: packet_queue_abort(&is->videoq); /* note: we also signal this mutex to make sure we deblock the video thread in all cases */ SDL_LockMutex(is->pictq_mutex); SDL_CondSignal(is->pictq_cond); SDL_UnlockMutex(is->pictq_mutex); SDL_WaitThread(is->video_tid, NULL); packet_queue_end(&is->videoq); break; case AVMEDIA_TYPE_SUBTITLE: packet_queue_abort(&is->subtitleq); /* note: we also signal this mutex to make sure we deblock the video thread in all cases */ SDL_LockMutex(is->subpq_mutex); is->subtitle_stream_changed = 1; SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex); SDL_WaitThread(is->subtitle_tid, NULL); packet_queue_end(&is->subtitleq); break; default: break; } ic->streams[stream_index]->discard = AVDISCARD_ALL; avcodec_close(avctx); switch(avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: is->audio_st = NULL; is->audio_stream = -1; break; case AVMEDIA_TYPE_VIDEO: is->video_st = NULL; is->video_stream = -1; break; case AVMEDIA_TYPE_SUBTITLE: is->subtitle_st = NULL; is->subtitle_stream = -1; break; default: break; } }
true
FFmpeg
f9324d5adda6147b3faad5970b6d88263397c76b
6,692
void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, int is_write, hwaddr access_len) { if (buffer != bounce.buffer) { if (is_write) { ram_addr_t addr1 = qemu_ram_addr_from_host_nofail(buffer); while (access_len) { unsigned l; l = TARGET_PAGE_SIZE; if (l > access_len) l = access_len; invalidate_and_set_dirty(addr1, l); addr1 += l; access_len -= l; } } if (xen_enabled()) { xen_invalidate_map_cache_entry(buffer); } return; } if (is_write) { address_space_write(as, bounce.addr, bounce.buffer, access_len); } qemu_vfree(bounce.buffer); bounce.buffer = NULL; cpu_notify_map_clients(); }
true
qemu
7443b43758ba5eeca8f81ca15fe9fced8983be26
6,693
static inline void idct4col_put(uint8_t *dest, int line_size, const int16_t *col) { int c0, c1, c2, c3, a0, a1, a2, a3; a0 = col[8*0]; a1 = col[8*2]; a2 = col[8*4]; a3 = col[8*6]; c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT); dest += line_size; dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT); dest += line_size; dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT); dest += line_size; dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT); }
true
FFmpeg
28dc6e729137ba7927f46ba15c337417b8708fe8
6,694
int mmubooke_get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong address, int rw, int access_type) { ppcemb_tlb_t *tlb; target_phys_addr_t raddr; int i, prot, ret; ret = -1; raddr = -1; for (i = 0; i < env->nb_tlb; i++) { tlb = &env->tlb[i].tlbe; if (ppcemb_tlb_check(env, tlb, &raddr, address, env->spr[SPR_BOOKE_PID], 1, i) < 0) continue; if (msr_pr != 0) prot = tlb->prot & 0xF; else prot = (tlb->prot >> 4) & 0xF; /* Check the address space */ if (access_type == ACCESS_CODE) { if (msr_ir != (tlb->attr & 1)) continue; ctx->prot = prot; if (prot & PAGE_EXEC) { ret = 0; break; } ret = -3; } else { if (msr_dr != (tlb->attr & 1)) continue; ctx->prot = prot; if ((!rw && prot & PAGE_READ) || (rw && (prot & PAGE_WRITE))) { ret = 0; break; } ret = -2; } } if (ret >= 0) ctx->raddr = raddr; return ret; }
true
qemu
6f2d8978728c48ca46f5c01835438508aace5c64
6,695
void fifo_realloc(FifoBuffer *f, int new_size){ int old_size= f->end - f->buffer; if(old_size < new_size){ uint8_t *old= f->buffer; f->buffer= av_realloc(f->buffer, new_size); f->rptr += f->buffer - old; f->wptr += f->buffer - old; if(f->wptr < f->rptr){ memmove(f->rptr + new_size - old_size, f->rptr, f->buffer + old_size - f->rptr); f->rptr += new_size - old_size; } f->end= f->buffer + new_size; } }
true
FFmpeg
568e18b15e2ddf494fd8926707d34ca08c8edce5
6,696
FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime) { JNIEnv *env = NULL; FFAMediaCodec *codec = NULL; jstring mime_type = NULL; codec = av_mallocz(sizeof(FFAMediaCodec)); if (!codec) { return NULL; } codec->class = &amediacodec_class; env = ff_jni_get_env(codec); if (!env) { av_freep(&codec); return NULL; } if (ff_jni_init_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec) < 0) { goto fail; } mime_type = ff_jni_utf_chars_to_jstring(env, mime, codec); if (!mime_type) { goto fail; } codec->object = (*env)->CallStaticObjectMethod(env, codec->jfields.mediacodec_class, codec->jfields.create_decoder_by_type_id, mime_type); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; } codec->object = (*env)->NewGlobalRef(env, codec->object); if (!codec->object) { goto fail; } if (codec_init_static_fields(codec) < 0) { goto fail; } if (codec->jfields.get_input_buffer_id && codec->jfields.get_output_buffer_id) { codec->has_get_i_o_buffer = 1; } return codec; fail: ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec); if (mime_type) { (*env)->DeleteLocalRef(env, mime_type); } av_freep(&codec); return NULL; }
true
FFmpeg
1795dccde0ad22fc8201142f92fb8d58c234f3e4
6,698
int vnc_tls_validate_certificate(VncState *vs) { int ret; unsigned int status; const gnutls_datum_t *certs; unsigned int nCerts, i; time_t now; VNC_DEBUG("Validating client certificate\n"); if ((ret = gnutls_certificate_verify_peers2 (vs->tls.session, &status)) < 0) { VNC_DEBUG("Verify failed %s\n", gnutls_strerror(ret)); return -1; } if ((now = time(NULL)) == ((time_t)-1)) { return -1; } if (status != 0) { if (status & GNUTLS_CERT_INVALID) VNC_DEBUG("The certificate is not trusted.\n"); if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) VNC_DEBUG("The certificate hasn't got a known issuer.\n"); if (status & GNUTLS_CERT_REVOKED) VNC_DEBUG("The certificate has been revoked.\n"); if (status & GNUTLS_CERT_INSECURE_ALGORITHM) VNC_DEBUG("The certificate uses an insecure algorithm\n"); return -1; } else { VNC_DEBUG("Certificate is valid!\n"); } /* Only support x509 for now */ if (gnutls_certificate_type_get(vs->tls.session) != GNUTLS_CRT_X509) return -1; if (!(certs = gnutls_certificate_get_peers(vs->tls.session, &nCerts))) return -1; for (i = 0 ; i < nCerts ; i++) { gnutls_x509_crt_t cert; VNC_DEBUG ("Checking certificate chain %d\n", i); if (gnutls_x509_crt_init (&cert) < 0) return -1; if (gnutls_x509_crt_import(cert, &certs[i], GNUTLS_X509_FMT_DER) < 0) { gnutls_x509_crt_deinit (cert); return -1; } if (gnutls_x509_crt_get_expiration_time (cert) < now) { VNC_DEBUG("The certificate has expired\n"); gnutls_x509_crt_deinit (cert); return -1; } if (gnutls_x509_crt_get_activation_time (cert) > now) { VNC_DEBUG("The certificate is not yet activated\n"); gnutls_x509_crt_deinit (cert); return -1; } if (gnutls_x509_crt_get_activation_time (cert) > now) { VNC_DEBUG("The certificate is not yet activated\n"); gnutls_x509_crt_deinit (cert); return -1; } if (i == 0) { size_t dnameSize = 1024; vs->tls.dname = g_malloc(dnameSize); requery: if ((ret = gnutls_x509_crt_get_dn (cert, vs->tls.dname, &dnameSize)) != 0) { if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) { vs->tls.dname = g_realloc(vs->tls.dname, dnameSize); goto requery; } gnutls_x509_crt_deinit (cert); VNC_DEBUG("Cannot get client distinguished name: %s", gnutls_strerror (ret)); return -1; } if (vs->vd->tls.x509verify) { int allow; if (!vs->vd->tls.acl) { VNC_DEBUG("no ACL activated, allowing access"); gnutls_x509_crt_deinit (cert); continue; } allow = qemu_acl_party_is_allowed(vs->vd->tls.acl, vs->tls.dname); VNC_DEBUG("TLS x509 ACL check for %s is %s\n", vs->tls.dname, allow ? "allowed" : "denied"); if (!allow) { gnutls_x509_crt_deinit (cert); return -1; } } } gnutls_x509_crt_deinit (cert); } return 0; }
true
qemu
3e305e4a4752f70c0b5c3cf5b43ec957881714f7
6,700
static void vc1_interp_mc(VC1Context *v) { MpegEncContext *s = &v->s; H264ChromaContext *h264chroma = &v->h264chroma; uint8_t *srcY, *srcU, *srcV; int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; int off, off_uv; int v_edge_pos = s->v_edge_pos >> v->field_mode; int use_ic = v->next_use_ic; if (!v->field_mode && !v->s.next_picture.f.data[0]) return; mx = s->mv[1][0][0]; my = s->mv[1][0][1]; uvmx = (mx + ((mx & 3) == 3)) >> 1; uvmy = (my + ((my & 3) == 3)) >> 1; if (v->field_mode) { if (v->cur_field_type != v->ref_field_type[1]) my = my - 2 + 4 * v->cur_field_type; uvmy = uvmy - 2 + 4 * v->cur_field_type; } if (v->fastuvmc) { uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1)); uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1)); } srcY = s->next_picture.f.data[0]; srcU = s->next_picture.f.data[1]; srcV = s->next_picture.f.data[2]; src_x = s->mb_x * 16 + (mx >> 2); src_y = s->mb_y * 16 + (my >> 2); uvsrc_x = s->mb_x * 8 + (uvmx >> 2); uvsrc_y = s->mb_y * 8 + (uvmy >> 2); if (v->profile != PROFILE_ADVANCED) { src_x = av_clip( src_x, -16, s->mb_width * 16); src_y = av_clip( src_y, -16, s->mb_height * 16); uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); } else { src_x = av_clip( src_x, -17, s->avctx->coded_width); src_y = av_clip( src_y, -18, s->avctx->coded_height + 1); uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); } srcY += src_y * s->linesize + src_x; srcU += uvsrc_y * s->uvlinesize + uvsrc_x; srcV += uvsrc_y * s->uvlinesize + uvsrc_x; if (v->field_mode && v->ref_field_type[1]) { srcY += s->current_picture_ptr->f.linesize[0]; srcU += s->current_picture_ptr->f.linesize[1]; srcV += s->current_picture_ptr->f.linesize[2]; } /* for grayscale we should not try to read from unknown area */ if (s->flags & CODEC_FLAG_GRAY) { srcU = s->edge_emu_buffer + 18 * s->linesize; srcV = s->edge_emu_buffer + 18 * s->linesize; } if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22 || use_ic || (unsigned)(src_x - 1) > s->h_edge_pos - (mx & 3) - 16 - 3 || (unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) { uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; srcY -= s->mspel * (1 + s->linesize); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, s->linesize, 17 + s->mspel * 2, 17 + s->mspel * 2, src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, v_edge_pos); srcY = s->edge_emu_buffer; s->vdsp.emulated_edge_mc(uvbuf, srcU, s->uvlinesize, s->uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); s->vdsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, s->uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); srcU = uvbuf; srcV = uvbuf + 16; /* if we deal with range reduction we need to scale source blocks */ if (v->rangeredfrm) { int i, j; uint8_t *src, *src2; src = srcY; for (j = 0; j < 17 + s->mspel * 2; j++) { for (i = 0; i < 17 + s->mspel * 2; i++) src[i] = ((src[i] - 128) >> 1) + 128; src += s->linesize; } src = srcU; src2 = srcV; for (j = 0; j < 9; j++) { for (i = 0; i < 9; i++) { src[i] = ((src[i] - 128) >> 1) + 128; src2[i] = ((src2[i] - 128) >> 1) + 128; } src += s->uvlinesize; src2 += s->uvlinesize; } } if (use_ic) { uint8_t (*luty )[256] = v->next_luty; uint8_t (*lutuv)[256] = v->next_lutuv; int i, j; uint8_t *src, *src2; src = srcY; for (j = 0; j < 17 + s->mspel * 2; j++) { int f = v->field_mode ? v->ref_field_type[1] : ((j+src_y - s->mspel) & 1); for (i = 0; i < 17 + s->mspel * 2; i++) src[i] = luty[f][src[i]]; src += s->linesize; } src = srcU; src2 = srcV; for (j = 0; j < 9; j++) { int f = v->field_mode ? v->ref_field_type[1] : ((j+uvsrc_y) & 1); for (i = 0; i < 9; i++) { src[i] = lutuv[f][src[i]]; src2[i] = lutuv[f][src2[i]]; } src += s->uvlinesize; src2 += s->uvlinesize; } } srcY += s->mspel * (1 + s->linesize); } off = 0; off_uv = 0; if (s->mspel) { dxy = ((my & 3) << 2) | (mx & 3); v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd); v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd); srcY += s->linesize * 8; v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd); v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd); } else { // hpel mc dxy = (my & 2) | ((mx & 2) >> 1); if (!v->rnd) s->hdsp.avg_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16); else s->hdsp.avg_no_rnd_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, 16); } if (s->flags & CODEC_FLAG_GRAY) return; /* Chroma MC always uses qpel blilinear */ uvmx = (uvmx & 3) << 1; uvmy = (uvmy & 3) << 1; if (!v->rnd) { h264chroma->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); h264chroma->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); } else { v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); } }
true
FFmpeg
f6774f905fb3cfdc319523ac640be30b14c1bc55
6,701
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, bool is_read) { BlockErrorAction action = blk_get_error_action(req->dev->blk, is_read, error); VirtIOBlock *s = req->dev; if (action == BLOCK_ERROR_ACTION_STOP) { req->next = s->rq; s->rq = req; } else if (action == BLOCK_ERROR_ACTION_REPORT) { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); block_acct_done(blk_get_stats(s->blk), &req->acct); virtio_blk_free_request(req); } blk_error_action(s->blk, action, is_read, error); return action != BLOCK_ERROR_ACTION_IGNORE; }
true
qemu
01762e03222154fef6d98087ce391aed8a157be5
6,702
static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field) { static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; int i, cid; if (buf_size < 0x280) return -1; if (memcmp(buf, header_prefix, 5)) { av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n"); return -1; } if (buf[5] & 2) { /* interlaced */ ctx->cur_field = buf[5] & 1; ctx->picture.interlaced_frame = 1; ctx->picture.top_field_first = first_field ^ ctx->cur_field; av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field); } ctx->height = AV_RB16(buf + 0x18); ctx->width = AV_RB16(buf + 0x1a); av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height); if (buf[0x21] & 0x40) { ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; ctx->avctx->bits_per_raw_sample = 10; if (ctx->bit_depth != 10) { ff_dsputil_init(&ctx->dsp, ctx->avctx); ctx->bit_depth = 10; ctx->decode_dct_block = dnxhd_decode_dct_block_10; } } else { ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P; ctx->avctx->bits_per_raw_sample = 8; if (ctx->bit_depth != 8) { ff_dsputil_init(&ctx->dsp, ctx->avctx); ctx->bit_depth = 8; ctx->decode_dct_block = dnxhd_decode_dct_block_8; } } cid = AV_RB32(buf + 0x28); av_dlog(ctx->avctx, "compression id %d\n", cid); if (dnxhd_init_vlc(ctx, cid) < 0) return -1; if (buf_size < ctx->cid_table->coding_unit_size) { av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n"); return -1; } ctx->mb_width = ctx->width>>4; ctx->mb_height = buf[0x16d]; av_dlog(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height); if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame) ctx->height <<= 1; if (ctx->mb_height > 68 || (ctx->mb_height<<ctx->picture.interlaced_frame) > (ctx->height+15)>>4) { av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height); return -1; } for (i = 0; i < ctx->mb_height; i++) { ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2)); av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); if (buf_size < ctx->mb_scan_index[i] + 0x280) { av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); return -1; } } return 0; }
true
FFmpeg
4a2da83a787b24c4027aa963d9db9b453e91f413
6,703
static int ogg_write_trailer(AVFormatContext *s) { int i; /* flush current page */ for (i = 0; i < s->nb_streams; i++) ogg_buffer_page(s, s->streams[i]->priv_data); ogg_write_pages(s, 1); for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OGGStreamContext *oggstream = st->priv_data; if (st->codec->codec_id == CODEC_ID_FLAC || st->codec->codec_id == CODEC_ID_SPEEX) { av_free(oggstream->header[0]); } av_freep(&st->priv_data); } return 0; }
true
FFmpeg
dacf07661467bc349d17bdab06516daceabffb23
6,704
static void do_inject_mce(Monitor *mon, const QDict *qdict) { CPUState *cenv; int cpu_index = qdict_get_int(qdict, "cpu_index"); int bank = qdict_get_int(qdict, "bank"); uint64_t status = qdict_get_int(qdict, "status"); uint64_t mcg_status = qdict_get_int(qdict, "mcg_status"); uint64_t addr = qdict_get_int(qdict, "addr"); uint64_t misc = qdict_get_int(qdict, "misc"); for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) if (cenv->cpu_index == cpu_index && cenv->mcg_cap) { cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc); break; } }
true
qemu
31ce5e0c49821d92fb30cce2f3055ef33613b287
6,705
static int avi_sync(AVFormatContext *s, int exit_early) { AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; int n; unsigned int d[8]; unsigned int size; int64_t i, sync; start_sync: memset(d, -1, sizeof(d)); for (i = sync = avio_tell(pb); !avio_feof(pb); i++) { int j; for (j = 0; j < 7; j++) d[j] = d[j + 1]; d[7] = avio_r8(pb); size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24); n = get_stream_idx(d + 2); ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n); if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127) continue; // parse ix## if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) || // parse JUNK (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') || (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') || (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) { avio_skip(pb, size); goto start_sync; } // parse stray LIST if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') { avio_skip(pb, 4); goto start_sync; } n = get_stream_idx(d); if (!((i - avi->last_pkt_pos) & 1) && get_stream_idx(d + 1) < s->nb_streams) continue; // detect ##ix chunk and skip if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) { avio_skip(pb, size); goto start_sync; } if (avi->dv_demux && n != 0) continue; // parse ##dc/##wb if (n < s->nb_streams) { AVStream *st; AVIStream *ast; st = s->streams[n]; ast = st->priv_data; if (!ast) { av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n); continue; } if (s->nb_streams >= 2) { AVStream *st1 = s->streams[1]; AVIStream *ast1 = st1->priv_data; // workaround for broken small-file-bug402.avi if ( d[2] == 'w' && d[3] == 'b' && n == 0 && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st1->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && ast->prefix == 'd'*256+'c' && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count) ) { n = 1; st = st1; ast = ast1; av_log(s, AV_LOG_WARNING, "Invalid stream + prefix combination, assuming audio.\n"); } } if (!avi->dv_demux && ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* || // FIXME: needs a little reordering (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY)) */ || st->discard >= AVDISCARD_ALL)) { if (!exit_early) { ast->frame_offset += get_duration(ast, size); avio_skip(pb, size); goto start_sync; } } if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) { int k = avio_r8(pb); int last = (k + avio_r8(pb) - 1) & 0xFF; avio_rl16(pb); // flags // b + (g << 8) + (r << 16); for (; k <= last; k++) ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8; ast->has_pal = 1; goto start_sync; } else if (((ast->prefix_count < 5 || sync + 9 > i) && d[2] < 128 && d[3] < 128) || d[2] * 256 + d[3] == ast->prefix /* || (d[2] == 'd' && d[3] == 'c') || (d[2] == 'w' && d[3] == 'b') */) { if (exit_early) return 0; if (d[2] * 256 + d[3] == ast->prefix) ast->prefix_count++; else { ast->prefix = d[2] * 256 + d[3]; ast->prefix_count = 0; } avi->stream_index = n; ast->packet_size = size + 8; ast->remaining = size; if (size) { uint64_t pos = avio_tell(pb) - 8; if (!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos) { av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); } } return 0; } } } if (pb->error) return pb->error; return AVERROR_EOF; }
false
FFmpeg
511e10f673a69c05744be0355cc9ce5705407bc2
6,707
static int roq_probe(AVProbeData *p) { if (p->buf_size < 6) return 0; if ((AV_RL16(&p->buf[0]) != RoQ_MAGIC_NUMBER) || (AV_RL32(&p->buf[2]) != 0xFFFFFFFF)) return 0; return AVPROBE_SCORE_MAX; }
false
FFmpeg
87e8788680e16c51f6048af26f3f7830c35207a5
6,709
inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc, const int16_t *hChrFilter, const int16_t *hChrFilterPos, int hChrFilterSize, uint8_t *formatConvBuffer, uint32_t *pal) { src1 += c->chrSrcOffset; src2 += c->chrSrcOffset; if (c->chrToYV12) { c->chrToYV12(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); src1= formatConvBuffer; src2= formatConvBuffer+VOFW; } if (c->hScale16) { c->hScale16(dst , dstWidth, (uint16_t*)src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize, av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1); c->hScale16(dst+VOFW, dstWidth, (uint16_t*)src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize, av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1); } else if (!c->hcscale_fast) { c->hScale(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); c->hScale(dst+VOFW, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); } else { // fast bilinear upscale / crap downscale c->hcscale_fast(c, dst, dstWidth, src1, src2, srcW, xInc); } if (c->chrConvertRange) c->chrConvertRange(dst, dstWidth); }
false
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
6,711
static int net_init_nic(QemuOpts *opts, const char *name, VLANState *vlan) { int idx; NICInfo *nd; const char *netdev; idx = nic_get_free_idx(); if (idx == -1 || nb_nics >= MAX_NICS) { error_report("Too Many NICs"); return -1; } nd = &nd_table[idx]; memset(nd, 0, sizeof(*nd)); if ((netdev = qemu_opt_get(opts, "netdev"))) { nd->netdev = qemu_find_netdev(netdev); if (!nd->netdev) { error_report("netdev '%s' not found", netdev); return -1; } } else { assert(vlan); nd->vlan = vlan; } if (name) { nd->name = g_strdup(name); } if (qemu_opt_get(opts, "model")) { nd->model = g_strdup(qemu_opt_get(opts, "model")); } if (qemu_opt_get(opts, "addr")) { nd->devaddr = g_strdup(qemu_opt_get(opts, "addr")); } if (qemu_opt_get(opts, "macaddr") && net_parse_macaddr(nd->macaddr.a, qemu_opt_get(opts, "macaddr")) < 0) { error_report("invalid syntax for ethernet address"); return -1; } qemu_macaddr_default_if_unset(&nd->macaddr); nd->nvectors = qemu_opt_get_number(opts, "vectors", DEV_NVECTORS_UNSPECIFIED); if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED && (nd->nvectors < 0 || nd->nvectors > 0x7ffffff)) { error_report("invalid # of vectors: %d", nd->nvectors); return -1; } nd->used = 1; nb_nics++; return idx; }
true
qemu
6687b79d636cd60ed9adb1177d0d946b58fa7717
6,712
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int *duration) { int64_t out_pts = AV_NOPTS_VALUE; int removed_samples = 0; int i; if (afq->frame_count || afq->frame_alloc) { if (afq->frames->pts != AV_NOPTS_VALUE) out_pts = afq->frames->pts; } if(!afq->frame_count) av_log(afq->avctx, AV_LOG_WARNING, "Trying to remove %d samples, but que empty\n", nb_samples); if (pts) *pts = ff_samples_to_time_base(afq->avctx, out_pts); for(i=0; nb_samples && i<afq->frame_count; i++){ int n= FFMIN(afq->frames[i].duration, nb_samples); afq->frames[i].duration -= n; nb_samples -= n; removed_samples += n; if(afq->frames[i].pts != AV_NOPTS_VALUE) afq->frames[i].pts += n; } i -= i && afq->frames[i-1].duration; memmove(afq->frames, afq->frames + i, sizeof(*afq->frames) * (afq->frame_count - i)); afq->frame_count -= i; if(nb_samples){ av_assert0(!afq->frame_count); if(afq->frames[0].pts != AV_NOPTS_VALUE) afq->frames[0].pts += nb_samples; av_log(afq->avctx, AV_LOG_DEBUG, "Trying to remove %d more samples than are in the que\n", nb_samples); } if (duration) *duration = ff_samples_to_time_base(afq->avctx, removed_samples); }
true
FFmpeg
3938a0eeae24a335b181d753c464cf5bab33ff01
6,713
static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; uint32_t data; if (dev->pdev->msix_enabled) { g_assert_cmpint(dev->config_msix_entry, !=, -1); if (qpci_msix_masked(dev->pdev, dev->config_msix_entry)) { /* No ISR checking should be done if masked, but read anyway */ return qpci_msix_pending(dev->pdev, dev->config_msix_entry); } else { data = readl(dev->config_msix_addr); writel(dev->config_msix_addr, 0); return data == dev->config_msix_data; } } else { return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_ISR_STATUS) & 2; } }
true
qemu
1e34cf9681ec549e26f30daaabc1ce58d60446f7