project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
qemu
548f52ea06951c20f0b91cae6cde0512ec073c83
1
static void qemu_fill_buffer(QEMUFile *f) { int len; int pending; assert(!qemu_file_is_writable(f)); pending = f->buf_size - f->buf_index; if (pending > 0) { memmove(f->buf, f->buf + f->buf_index, pending); } f->buf_index = 0; f->buf_size = pending; len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, IO_BUF_SIZE - pending); if (len > 0) { f->buf_size += len; f->pos += len; } else if (len == 0) { qemu_file_set_error(f, -EIO); } else if (len != -EAGAIN) { qemu_file_set_error(f, len); } }
11,702
FFmpeg
6e42e6c4b410dbef8b593c2d796a5dad95f89ee4
1
static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size) { long idx = 15 - src_size; uint8_t *s = (uint8_t *) src-idx, *d = dst-idx; #ifdef HAVE_MMX __asm __volatile( "test %0, %0 \n\t" "jns 2f \n\t" PREFETCH" (%1, %0) \n\t" "movq %3, %%mm7 \n\t" "pxor %4, %%mm7 \n\t" "movq %%mm7, %%mm6 \n\t" "pxor %5, %%mm7 \n\t" ASMALIGN(4) "1: \n\t" PREFETCH" 32(%1, %0) \n\t" "movq (%1, %0), %%mm0 \n\t" "movq 8(%1, %0), %%mm1 \n\t" # ifdef HAVE_MMX2 "pshufw $177, %%mm0, %%mm3 \n\t" "pshufw $177, %%mm1, %%mm5 \n\t" "pand %%mm7, %%mm0 \n\t" "pand %%mm6, %%mm3 \n\t" "pand %%mm7, %%mm1 \n\t" "pand %%mm6, %%mm5 \n\t" "por %%mm3, %%mm0 \n\t" "por %%mm5, %%mm1 \n\t" # else "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm4 \n\t" "pand %%mm7, %%mm0 \n\t" "pand %%mm6, %%mm2 \n\t" "pand %%mm7, %%mm1 \n\t" "pand %%mm6, %%mm4 \n\t" "movq %%mm2, %%mm3 \n\t" "movq %%mm4, %%mm5 \n\t" "pslld $16, %%mm2 \n\t" "psrld $16, %%mm3 \n\t" "pslld $16, %%mm4 \n\t" "psrld $16, %%mm5 \n\t" "por %%mm2, %%mm0 \n\t" "por %%mm4, %%mm1 \n\t" "por %%mm3, %%mm0 \n\t" "por %%mm5, %%mm1 \n\t" # endif MOVNTQ" %%mm0, (%2, %0) \n\t" MOVNTQ" %%mm1, 8(%2, %0) \n\t" "add $16, %0 \n\t" "js 1b \n\t" SFENCE" \n\t" EMMS" \n\t" "2: \n\t" : "+&r"(idx) : "r" (s), "r" (d), "m" (mask32b), "m" (mask32r), "m" (mmx_one) : "memory"); #endif for (; idx<15; idx+=4) { register int v = *(uint32_t *)&s[idx], g = v & 0xff00ff00; v &= 0xff00ff; *(uint32_t *)&d[idx] = (v>>16) + g + (v<<16); } }
11,703
qemu
3d3697f2576424a2c0830a7b2e7c94c79dea9b50
1
static int xen_pt_initfn(PCIDevice *d) { XenPCIPassthroughState *s = XEN_PT_DEVICE(d); int rc = 0; uint8_t machine_irq = 0, scratch; uint16_t cmd = 0; int pirq = XEN_PT_UNASSIGNED_PIRQ; /* register real device */ XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d" " to devfn %#x\n", s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function, s->dev.devfn); rc = xen_host_pci_device_get(&s->real_device, s->hostaddr.domain, s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function); if (rc) { XEN_PT_ERR(d, "Failed to \"open\" the real pci device. rc: %i\n", rc); return -1; } s->is_virtfn = s->real_device.is_virtfn; if (s->is_virtfn) { XEN_PT_LOG(d, "%04x:%02x:%02x.%d is a SR-IOV Virtual Function\n", s->real_device.domain, s->real_device.bus, s->real_device.dev, s->real_device.func); } /* Initialize virtualized PCI configuration (Extended 256 Bytes) */ if (xen_host_pci_get_block(&s->real_device, 0, d->config, PCI_CONFIG_SPACE_SIZE) < 0) { xen_host_pci_device_put(&s->real_device); return -1; } s->memory_listener = xen_pt_memory_listener; s->io_listener = xen_pt_io_listener; /* Setup VGA bios for passthrough GFX */ if ((s->real_device.domain == 0) && (s->real_device.bus == 0) && (s->real_device.dev == 2) && (s->real_device.func == 0)) { if (!is_igd_vga_passthrough(&s->real_device)) { XEN_PT_ERR(d, "Need to enable igd-passthru if you're trying" " to passthrough IGD GFX.\n"); xen_host_pci_device_put(&s->real_device); return -1; } if (xen_pt_setup_vga(s, &s->real_device) < 0) { XEN_PT_ERR(d, "Setup VGA BIOS of passthrough GFX failed!\n"); xen_host_pci_device_put(&s->real_device); return -1; } /* Register ISA bridge for passthrough GFX. */ xen_igd_passthrough_isa_bridge_create(s, &s->real_device); } /* Handle real device's MMIO/PIO BARs */ xen_pt_register_regions(s, &cmd); /* reinitialize each config register to be emulated */ if (xen_pt_config_init(s)) { XEN_PT_ERR(d, "PCI Config space initialisation failed.\n"); xen_host_pci_device_put(&s->real_device); return -1; } /* Bind interrupt */ rc = xen_host_pci_get_byte(&s->real_device, PCI_INTERRUPT_PIN, &scratch); if (rc) { XEN_PT_ERR(d, "Failed to read PCI_INTERRUPT_PIN! (rc:%d)\n", rc); scratch = 0; } if (!scratch) { XEN_PT_LOG(d, "no pin interrupt\n"); goto out; } machine_irq = s->real_device.irq; rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq); if (rc < 0) { XEN_PT_ERR(d, "Mapping machine irq %u to pirq %i failed, (err: %d)\n", machine_irq, pirq, errno); /* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |= PCI_COMMAND_INTX_DISABLE; machine_irq = 0; s->machine_irq = 0; } else { machine_irq = pirq; s->machine_irq = pirq; xen_pt_mapped_machine_irq[machine_irq]++; } /* bind machine_irq to device */ if (machine_irq != 0) { uint8_t e_intx = xen_pt_pci_intx(s); rc = xc_domain_bind_pt_pci_irq(xen_xc, xen_domid, machine_irq, pci_bus_num(d->bus), PCI_SLOT(d->devfn), e_intx); if (rc < 0) { XEN_PT_ERR(d, "Binding of interrupt %i failed! (err: %d)\n", e_intx, errno); /* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |= PCI_COMMAND_INTX_DISABLE; xen_pt_mapped_machine_irq[machine_irq]--; if (xen_pt_mapped_machine_irq[machine_irq] == 0) { if (xc_physdev_unmap_pirq(xen_xc, xen_domid, machine_irq)) { XEN_PT_ERR(d, "Unmapping of machine interrupt %i failed!" " (err: %d)\n", machine_irq, errno); } } s->machine_irq = 0; } } out: if (cmd) { uint16_t val; rc = xen_host_pci_get_word(&s->real_device, PCI_COMMAND, &val); if (rc) { XEN_PT_ERR(d, "Failed to read PCI_COMMAND! (rc: %d)\n", rc); } else { val |= cmd; rc = xen_host_pci_set_word(&s->real_device, PCI_COMMAND, val); if (rc) { XEN_PT_ERR(d, "Failed to write PCI_COMMAND val=0x%x!(rc: %d)\n", val, rc); } } } memory_listener_register(&s->memory_listener, &s->dev.bus_master_as); memory_listener_register(&s->io_listener, &address_space_io); s->listener_set = true; XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered successfully!\n", s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function); return 0; }
11,704
FFmpeg
6e42e6c4b410dbef8b593c2d796a5dad95f89ee4
1
static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) { const uint8_t *s = src; const uint8_t *end; #ifdef HAVE_MMX const uint8_t *mm_end; #endif uint16_t *d = (uint16_t *)dst; end = s + src_size; #ifdef HAVE_MMX __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm __volatile( "movq %0, %%mm7\n\t" "movq %1, %%mm6\n\t" ::"m"(red_15mask),"m"(green_15mask)); mm_end = end - 15; while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movd %1, %%mm0\n\t" "movd 3%1, %%mm3\n\t" "punpckldq 6%1, %%mm0\n\t" "punpckldq 9%1, %%mm3\n\t" "movq %%mm0, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm3, %%mm4\n\t" "movq %%mm3, %%mm5\n\t" "psllq $7, %%mm0\n\t" "psllq $7, %%mm3\n\t" "pand %%mm7, %%mm0\n\t" "pand %%mm7, %%mm3\n\t" "psrlq $6, %%mm1\n\t" "psrlq $6, %%mm4\n\t" "pand %%mm6, %%mm1\n\t" "pand %%mm6, %%mm4\n\t" "psrlq $19, %%mm2\n\t" "psrlq $19, %%mm5\n\t" "pand %2, %%mm2\n\t" "pand %2, %%mm5\n\t" "por %%mm1, %%mm0\n\t" "por %%mm4, %%mm3\n\t" "por %%mm2, %%mm0\n\t" "por %%mm5, %%mm3\n\t" "psllq $16, %%mm3\n\t" "por %%mm3, %%mm0\n\t" MOVNTQ" %%mm0, %0\n\t" :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); d += 4; s += 12; } __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { const int r= *s++; const int g= *s++; const int b= *s++; *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); } }
11,705
FFmpeg
0041cdba98d5b636a8d912352dd3d8ca72bba4ce
0
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) { if(min_ts > ts || max_ts < ts) return -1; ff_read_frame_flush(s); if (s->iformat->read_seek2) return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); if(s->iformat->read_timestamp){ //try to seek via read_timestamp() } //Fallback to old API if new is not implemented but old is //Note the old has somewat different sematics if(s->iformat->read_seek || 1) return av_seek_frame(s, stream_index, ts, flags | (ts - min_ts > (uint64_t)(max_ts - ts) ? AVSEEK_FLAG_BACKWARD : 0)); // try some generic seek like seek_frame_generic() but with new ts semantics }
11,706
FFmpeg
6a63ff19b6a7fe3bc32c7fb4a62fca8f65786432
0
static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; MOVStreamContext *sc = st->priv_data; unsigned int i, entries, sample_size, field_size, num_bytes; GetBitContext gb; unsigned char* buf; get_byte(pb); /* version */ get_be24(pb); /* flags */ if (atom.type == MKTAG('s','t','s','z')) { sample_size = get_be32(pb); if (!sc->sample_size) /* do not overwrite value computed in stsd */ sc->sample_size = sample_size; field_size = 32; } else { sample_size = 0; get_be24(pb); /* reserved */ field_size = get_byte(pb); } entries = get_be32(pb); dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries); sc->sample_count = entries; if (sample_size) return 0; if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) { av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size); return -1; } if(entries >= UINT_MAX / sizeof(int)) return -1; sc->sample_sizes = av_malloc(entries * sizeof(int)); if (!sc->sample_sizes) return AVERROR(ENOMEM); num_bytes = (entries*field_size+4)>>3; buf = av_malloc(num_bytes+FF_INPUT_BUFFER_PADDING_SIZE); if (!buf) { av_freep(&sc->sample_sizes); return AVERROR(ENOMEM); } if (get_buffer(pb, buf, num_bytes) < num_bytes) { av_freep(&sc->sample_sizes); av_free(buf); return -1; } init_get_bits(&gb, buf, 8*num_bytes); for(i=0; i<entries; i++) sc->sample_sizes[i] = get_bits_long(&gb, field_size); av_free(buf); return 0; }
11,707
FFmpeg
e2b416b68e85f3495d1a55f202dd405824c044c8
0
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output) { AVFrame *decoded_frame, *f; AVCodecContext *avctx = ist->dec_ctx; int i, ret, err = 0, resample_changed; AVRational decoded_frame_tb; if (!ist->decoded_frame && !(ist->decoded_frame = av_frame_alloc())) return AVERROR(ENOMEM); if (!ist->filter_frame && !(ist->filter_frame = av_frame_alloc())) return AVERROR(ENOMEM); decoded_frame = ist->decoded_frame; update_benchmark(NULL); ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt); update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index); if (ret >= 0 && avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "Sample rate %d invalid\n", avctx->sample_rate); ret = AVERROR_INVALIDDATA; } if (*got_output || ret<0) decode_error_stat[ret<0] ++; if (ret < 0 && exit_on_error) exit_program(1); if (!*got_output || ret < 0) return ret; ist->samples_decoded += decoded_frame->nb_samples; ist->frames_decoded++; #if 1 /* increment next_dts to use for the case where the input stream does not have timestamps or there are multiple frames in the packet */ ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) / avctx->sample_rate; ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) / avctx->sample_rate; #endif resample_changed = ist->resample_sample_fmt != decoded_frame->format || ist->resample_channels != avctx->channels || ist->resample_channel_layout != decoded_frame->channel_layout || ist->resample_sample_rate != decoded_frame->sample_rate; if (resample_changed) { char layout1[64], layout2[64]; if (!guess_input_channel_layout(ist)) { av_log(NULL, AV_LOG_FATAL, "Unable to find default channel " "layout for Input Stream #%d.%d\n", ist->file_index, ist->st->index); exit_program(1); } decoded_frame->channel_layout = avctx->channel_layout; av_get_channel_layout_string(layout1, sizeof(layout1), ist->resample_channels, ist->resample_channel_layout); av_get_channel_layout_string(layout2, sizeof(layout2), avctx->channels, decoded_frame->channel_layout); av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d chl:%s to rate:%d fmt:%s ch:%d chl:%s\n", ist->file_index, ist->st->index, ist->resample_sample_rate, av_get_sample_fmt_name(ist->resample_sample_fmt), ist->resample_channels, layout1, decoded_frame->sample_rate, av_get_sample_fmt_name(decoded_frame->format), avctx->channels, layout2); ist->resample_sample_fmt = decoded_frame->format; ist->resample_sample_rate = decoded_frame->sample_rate; ist->resample_channel_layout = decoded_frame->channel_layout; ist->resample_channels = avctx->channels; for (i = 0; i < nb_filtergraphs; i++) if (ist_in_filtergraph(filtergraphs[i], ist)) { FilterGraph *fg = filtergraphs[i]; if (configure_filtergraph(fg) < 0) { av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n"); exit_program(1); } } } /* if the decoder provides a pts, use it instead of the last packet pts. the decoder could be delaying output by a packet or more. */ if (decoded_frame->pts != AV_NOPTS_VALUE) { ist->dts = ist->next_dts = ist->pts = ist->next_pts = av_rescale_q(decoded_frame->pts, avctx->time_base, AV_TIME_BASE_Q); decoded_frame_tb = avctx->time_base; } else if (decoded_frame->pkt_pts != AV_NOPTS_VALUE) { decoded_frame->pts = decoded_frame->pkt_pts; decoded_frame_tb = ist->st->time_base; } else if (pkt->pts != AV_NOPTS_VALUE) { decoded_frame->pts = pkt->pts; decoded_frame_tb = ist->st->time_base; }else { decoded_frame->pts = ist->dts; decoded_frame_tb = AV_TIME_BASE_Q; } pkt->pts = AV_NOPTS_VALUE; if (decoded_frame->pts != AV_NOPTS_VALUE) decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts, (AVRational){1, avctx->sample_rate}, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last, (AVRational){1, avctx->sample_rate}); ist->nb_samples = decoded_frame->nb_samples; for (i = 0; i < ist->nb_filters; i++) { if (i < ist->nb_filters - 1) { f = ist->filter_frame; err = av_frame_ref(f, decoded_frame); if (err < 0) break; } else f = decoded_frame; err = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f, AV_BUFFERSRC_FLAG_PUSH); if (err == AVERROR_EOF) err = 0; /* ignore */ if (err < 0) break; } decoded_frame->pts = AV_NOPTS_VALUE; av_frame_unref(ist->filter_frame); av_frame_unref(decoded_frame); return err < 0 ? err : ret; }
11,708
FFmpeg
da66b6313e61a861321b7d62a3d12a38877784bb
1
static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){ const int level= b->level; const int w= b->width; const int h= b->height; const int qlog= clip(s->qlog + b->qlog, 0, 128); const int qmul= qexp[qlog&7]<<(qlog>>3); int x,y; assert(QROOT==8); bias= bias ? 0 : (3*qmul)>>3; if(!bias){ for(y=0; y<h; y++){ for(x=0; x<w; x++){ int i= src[x + y*stride]; //FIXME use threshold //FIXME optimize //FIXME bias if(i>=0){ i<<= QEXPSHIFT; i/= qmul; src[x + y*stride]= i; }else{ i= -i; i<<= QEXPSHIFT; i/= qmul; src[x + y*stride]= -i; } } } }else{ for(y=0; y<h; y++){ for(x=0; x<w; x++){ int i= src[x + y*stride]; //FIXME use threshold //FIXME optimize //FIXME bias if(i>=0){ i<<= QEXPSHIFT; i= (i + bias) / qmul; src[x + y*stride]= i; }else{ i= -i; i<<= QEXPSHIFT; i= (i + bias) / qmul; src[x + y*stride]= -i; } } } } }
11,709
qemu
ee640c625e190a0c0e6b8966adc0e4720fb75200
1
static void virtio_pci_device_plugged(DeviceState *d, Error **errp) { VirtIOPCIProxy *proxy = VIRTIO_PCI(d); VirtioBusState *bus = &proxy->bus; bool legacy = virtio_pci_legacy(proxy); bool modern; bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; uint8_t *config; uint32_t size; VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); /* * Virtio capabilities present without * VIRTIO_F_VERSION_1 confuses guests */ if (!proxy->ignore_backend_features && !virtio_has_feature(vdev->host_features, VIRTIO_F_VERSION_1)) { virtio_pci_disable_modern(proxy); if (!legacy) { error_setg(errp, "Device doesn't support modern mode, and legacy" " mode is disabled"); error_append_hint(errp, "Set disable-legacy to off\n"); return; } } modern = virtio_pci_modern(proxy); config = proxy->pci_dev.config; if (proxy->class_code) { pci_config_set_class(config, proxy->class_code); } if (legacy) { if (virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) { error_setg(errp, "VIRTIO_F_IOMMU_PLATFORM was supported by" "neither legacy nor transitional device."); return ; } /* legacy and transitional */ pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID, pci_get_word(config + PCI_VENDOR_ID)); pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus)); } else { /* pure virtio-1.0 */ pci_set_word(config + PCI_VENDOR_ID, PCI_VENDOR_ID_REDHAT_QUMRANET); pci_set_word(config + PCI_DEVICE_ID, 0x1040 + virtio_bus_get_vdev_id(bus)); pci_config_set_revision(config, 1); } config[PCI_INTERRUPT_PIN] = 1; if (modern) { struct virtio_pci_cap cap = { .cap_len = sizeof cap, }; struct virtio_pci_notify_cap notify = { .cap.cap_len = sizeof notify, .notify_off_multiplier = cpu_to_le32(virtio_pci_queue_mem_mult(proxy)), }; struct virtio_pci_cfg_cap cfg = { .cap.cap_len = sizeof cfg, .cap.cfg_type = VIRTIO_PCI_CAP_PCI_CFG, }; struct virtio_pci_notify_cap notify_pio = { .cap.cap_len = sizeof notify, .notify_off_multiplier = cpu_to_le32(0x0), }; struct virtio_pci_cfg_cap *cfg_mask; virtio_pci_modern_regions_init(proxy); virtio_pci_modern_mem_region_map(proxy, &proxy->common, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->device, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->notify, &notify.cap); if (modern_pio) { memory_region_init(&proxy->io_bar, OBJECT(proxy), "virtio-pci-io", 0x4); pci_register_bar(&proxy->pci_dev, proxy->modern_io_bar_idx, PCI_BASE_ADDRESS_SPACE_IO, &proxy->io_bar); virtio_pci_modern_io_region_map(proxy, &proxy->notify_pio, &notify_pio.cap); } pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar_idx, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH | PCI_BASE_ADDRESS_MEM_TYPE_64, &proxy->modern_bar); proxy->config_cap = virtio_pci_add_mem_cap(proxy, &cfg.cap); cfg_mask = (void *)(proxy->pci_dev.wmask + proxy->config_cap); pci_set_byte(&cfg_mask->cap.bar, ~0x0); pci_set_long((uint8_t *)&cfg_mask->cap.offset, ~0x0); pci_set_long((uint8_t *)&cfg_mask->cap.length, ~0x0); pci_set_long(cfg_mask->pci_cfg_data, ~0x0); } if (proxy->nvectors) { int err = msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, proxy->msix_bar_idx); if (err) { /* Notice when a system that supports MSIx can't initialize it. */ if (err != -ENOTSUP) { error_report("unable to init msix vectors to %" PRIu32, proxy->nvectors); } proxy->nvectors = 0; } } proxy->pci_dev.config_write = virtio_write_config; proxy->pci_dev.config_read = virtio_read_config; if (legacy) { size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + virtio_bus_get_vdev_config_len(bus); size = pow2ceil(size); memory_region_init_io(&proxy->bar, OBJECT(proxy), &virtio_pci_config_ops, proxy, "virtio-pci", size); pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx, PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); } }
11,710
qemu
2d1cd6c7a91a4beb99a0c3a21be529222a708545
1
static void update_cursor_data_virgl(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id) { uint32_t width, height; uint32_t pixels, *data; data = virgl_renderer_get_cursor_data(resource_id, &width, &height); if (!data) { return; } if (width != s->current_cursor->width || height != s->current_cursor->height) { return; } pixels = s->current_cursor->width * s->current_cursor->height; memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t)); }
11,711
qemu
9745807191a81c45970f780166f44a7f93b18653
1
static void gen_addc(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) { TCGv t0 = tcg_const_tl(0); TCGv res = tcg_temp_new(); TCGv sr_cy = tcg_temp_new(); TCGv sr_ov = tcg_temp_new(); tcg_gen_shri_tl(sr_cy, cpu_sr, ctz32(SR_CY)); tcg_gen_andi_tl(sr_cy, sr_cy, 1); tcg_gen_add2_tl(res, sr_cy, srca, t0, sr_cy, t0); tcg_gen_add2_tl(res, sr_cy, res, sr_cy, srcb, t0); tcg_gen_xor_tl(sr_ov, srca, srcb); tcg_gen_xor_tl(t0, res, srcb); tcg_gen_andc_tl(sr_ov, t0, sr_ov); tcg_temp_free(t0); tcg_gen_mov_tl(dest, res); tcg_temp_free(res); tcg_gen_shri_tl(sr_ov, sr_ov, TARGET_LONG_BITS - 1); tcg_gen_deposit_tl(cpu_sr, cpu_sr, sr_cy, ctz32(SR_CY), 1); tcg_gen_deposit_tl(cpu_sr, cpu_sr, sr_ov, ctz32(SR_OV), 1); gen_ove_cyov(dc, sr_ov, sr_cy); tcg_temp_free(sr_ov); tcg_temp_free(sr_cy); }
11,713
FFmpeg
ecefce41d9f9fd10a8f564b011cd565cff2eb3ef
1
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options) { TLSContext *c = h->priv_data; TLSShared *s = &c->tls_shared; int ret; if ((ret = ff_tls_open_underlying(s, h, uri, options)) < 0) goto fail; c->ssl_context = SSLCreateContext(NULL, s->listen ? kSSLServerSide : kSSLClientSide, kSSLStreamType); if (!c->ssl_context) { av_log(h, AV_LOG_ERROR, "Unable to create SSL context\n"); ret = AVERROR(ENOMEM); goto fail; } if (s->ca_file) { if ((ret = load_ca(h)) < 0) goto fail; CHECK_ERROR(SSLSetSessionOption, c->ssl_context, kSSLSessionOptionBreakOnServerAuth, true); } if (s->cert_file) if ((ret = load_cert(h)) < 0) goto fail; if (s->verify) CHECK_ERROR(SSLSetPeerDomainName, c->ssl_context, s->host, strlen(s->host)); CHECK_ERROR(SSLSetIOFuncs, c->ssl_context, tls_read_cb, tls_write_cb); CHECK_ERROR(SSLSetConnection, c->ssl_context, h); while (1) { OSStatus status = SSLHandshake(c->ssl_context); if (status == errSSLServerAuthCompleted) { SecTrustRef peerTrust; SecTrustResultType trustResult; if (!s->verify) continue; if (SSLCopyPeerTrust(c->ssl_context, &peerTrust) != noErr) { ret = AVERROR(ENOMEM); goto fail; } if (SecTrustSetAnchorCertificates(peerTrust, c->ca_array) != noErr) { ret = AVERROR_UNKNOWN; goto fail; } if (SecTrustEvaluate(peerTrust, &trustResult) != noErr) { ret = AVERROR_UNKNOWN; goto fail; } if (trustResult == kSecTrustResultProceed || trustResult == kSecTrustResultUnspecified) { // certificate is trusted status = errSSLWouldBlock; // so we call SSLHandshake again } else if (trustResult == kSecTrustResultRecoverableTrustFailure) { // not trusted, for some reason other than being expired status = errSSLXCertChainInvalid; } else { // cannot use this certificate (fatal) status = errSSLBadCert; } if (peerTrust) CFRelease(peerTrust); } if (status == noErr) break; av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session: %i\n", (int)status); ret = AVERROR(EIO); goto fail; } return 0; fail: tls_close(h); return ret; }
11,715
qemu
4d1de87c75007ee7e29dd271ebb4afdcf01ad7aa
1
abi_long do_brk(abi_ulong new_brk) { abi_ulong brk_page; abi_long mapped_addr; int new_alloc_size; if (!new_brk) return target_brk; if (new_brk < target_original_brk) return target_brk; brk_page = HOST_PAGE_ALIGN(target_brk); /* If the new brk is less than this, set it and we're done... */ if (new_brk < brk_page) { target_brk = new_brk; return target_brk; } /* We need to allocate more memory after the brk... Note that * we don't use MAP_FIXED because that will map over the top of * any existing mapping (like the one with the host libc or qemu * itself); instead we treat "mapped but at wrong address" as * a failure and unmap again. */ new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1); mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0)); if (mapped_addr == brk_page) { target_brk = new_brk; return target_brk; } else if (mapped_addr != -1) { /* Mapped but at wrong address, meaning there wasn't actually * enough space for this brk. */ target_munmap(mapped_addr, new_alloc_size); mapped_addr = -1; } #if defined(TARGET_ALPHA) /* We (partially) emulate OSF/1 on Alpha, which requires we return a proper errno, not an unchanged brk value. */ return -TARGET_ENOMEM; #endif /* For everything else, return the previous break. */ return target_brk; }
11,716
FFmpeg
2dbc84b1a8d39e7fa0c7d66a120838fced35f5b4
1
static int mkv_write_tracks(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb = s->pb; ebml_master tracks; int i, j, ret; ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb)); if (ret < 0) return ret; tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0); for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVCodecContext *codec = st->codec; ebml_master subinfo, track; int native_id = 0; int qt_id = 0; int bit_depth = av_get_bits_per_sample(codec->codec_id); int sample_rate = codec->sample_rate; int output_sample_rate = 0; AVDictionaryEntry *tag; if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { mkv->have_attachments = 1; continue; } if (!bit_depth) bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3; if (codec->codec_id == AV_CODEC_ID_AAC) get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0); put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER , i + 1); put_ebml_uint (pb, MATROSKA_ID_TRACKUID , i + 1); put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0); // no lacing (yet) if ((tag = av_dict_get(st->metadata, "title", NULL, 0))) put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value); tag = av_dict_get(st->metadata, "language", NULL, 0); put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und"); if (st->disposition) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT)); // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { if (ff_mkv_codec_tags[j].id == codec->codec_id) { put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str); native_id = 1; break; } } if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 || codec->codec_id == AV_CODEC_ID_VORBIS)) { av_log(s, AV_LOG_ERROR, "Only VP8 video and Vorbis audio are supported for WebM.\n"); return AVERROR(EINVAL); } switch (codec->codec_type) { case AVMEDIA_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); if(st->avg_frame_rate.num && st->avg_frame_rate.den && 1.0/av_q2d(st->avg_frame_rate) > av_q2d(codec->time_base)) put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1E9/av_q2d(st->avg_frame_rate)); else put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, av_q2d(codec->time_base)*1E9); if (!native_id && ff_codec_get_tag(ff_codec_movvideo_tags, codec->codec_id) && (!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id) || codec->codec_id == AV_CODEC_ID_SVQ1 || codec->codec_id == AV_CODEC_ID_SVQ3 || codec->codec_id == AV_CODEC_ID_CINEPAK)) qt_id = 1; if (qt_id) put_ebml_string(pb, MATROSKA_ID_CODECID, "V_QUICKTIME"); else if (!native_id) { // if there is no mkv-specific codec ID, use VFW mode put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC"); mkv->tracks[i].write_dts = 1; } subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) || (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) { // save stereo mode flag uint64_t st_mode = MATROSKA_VIDEO_STEREO_MODE_COUNT; for (j=0; j<MATROSKA_VIDEO_STEREO_MODE_COUNT; j++) if (!strcmp(tag->value, ff_matroska_video_stereo_mode[j])){ st_mode = j; break; } if ((mkv->mode == MODE_WEBM && st_mode > 3 && st_mode != 11) || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) { av_log(s, AV_LOG_ERROR, "The specified stereo mode is not valid.\n"); return AVERROR(EINVAL); } else put_ebml_uint(pb, MATROSKA_ID_VIDEOSTEREOMODE, st_mode); } if (st->sample_aspect_ratio.num) { int d_width = av_rescale(codec->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width); put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height); } if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) { uint32_t color_space = av_le2ne32(codec->codec_tag); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); } end_ebml_master(pb, subinfo); break; case AVMEDIA_TYPE_AUDIO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO); if (!native_id) // no mkv-specific ID, use ACM mode put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM"); subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate); if (output_sample_rate) put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); if (bit_depth) put_ebml_uint(pb, MATROSKA_ID_AUDIOBITDEPTH, bit_depth); end_ebml_master(pb, subinfo); break; case AVMEDIA_TYPE_SUBTITLE: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_SUBTITLE); if (!native_id) { av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", codec->codec_id); return AVERROR(ENOSYS); } break; default: av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n"); break; } ret = mkv_write_codecprivate(s, pb, codec, native_id, qt_id); if (ret < 0) return ret; end_ebml_master(pb, track); // ms precision is the de-facto standard timescale for mkv files avpriv_set_pts_info(st, 64, 1, 1000); } end_ebml_master(pb, tracks); return 0; }
11,717
qemu
ea375f9ab8c76686dca0af8cb4f87a4eb569cad3
1
int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f) { SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) { if (se->save_live_state == NULL) continue; /* Section type */ qemu_put_byte(f, QEMU_VM_SECTION_END); qemu_put_be32(f, se->section_id); se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque); } QTAILQ_FOREACH(se, &savevm_handlers, entry) { int len; if (se->save_state == NULL && se->vmsd == NULL) continue; /* Section type */ qemu_put_byte(f, QEMU_VM_SECTION_FULL); qemu_put_be32(f, se->section_id); /* ID string */ len = strlen(se->idstr); qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)se->idstr, len); qemu_put_be32(f, se->instance_id); qemu_put_be32(f, se->version_id); vmstate_save(f, se); } qemu_put_byte(f, QEMU_VM_EOF); if (qemu_file_has_error(f)) return -EIO; return 0; }
11,718
qemu
fa66b909f382619da15f8c7e323145adfa94fdac
1
static int scsi_hot_add(Monitor *mon, DeviceState *adapter, DriveInfo *dinfo, int printinfo) { SCSIBus *scsibus; SCSIDevice *scsidev; scsibus = DO_UPCAST(SCSIBus, qbus, QLIST_FIRST(&adapter->child_bus)); if (!scsibus || strcmp(scsibus->qbus.info->name, "SCSI") != 0) { error_report("Device is not a SCSI adapter"); /* * drive_init() tries to find a default for dinfo->unit. Doesn't * work at all for hotplug though as we assign the device to a * specific bus instead of the first bus with spare scsi ids. * * Ditch the calculated value and reload from option string (if * specified). */ dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1); scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo->unit); dinfo->unit = scsidev->id; if (printinfo) monitor_printf(mon, "OK bus %d, unit %d\n", scsibus->busnr, scsidev->id); return 0;
11,719
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static void blk_mig_cleanup(void) { BlkMigDevState *bmds; BlkMigBlock *blk; bdrv_drain_all(); unset_dirty_tracking(); blk_mig_lock(); while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) { QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry); bdrv_op_unblock_all(bmds->bs, bmds->blocker); error_free(bmds->blocker); bdrv_unref(bmds->bs); g_free(bmds->aio_bitmap); g_free(bmds); } while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) { QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry); g_free(blk->buf); g_free(blk); } blk_mig_unlock(); }
11,720
qemu
111049a4ecefc9cf1ac75c773f4c5c165f27fe63
1
static void do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, Error **errp) { BlockDriverState *bs; BlockDriverState *target_bs; BlockDriverState *source = NULL; BdrvDirtyBitmap *bmap = NULL; AioContext *aio_context; QDict *options = NULL; Error *local_err = NULL; int flags; int64_t size; if (!backup->has_speed) { backup->speed = 0; } if (!backup->has_on_source_error) { backup->on_source_error = BLOCKDEV_ON_ERROR_REPORT; } if (!backup->has_on_target_error) { backup->on_target_error = BLOCKDEV_ON_ERROR_REPORT; } if (!backup->has_mode) { backup->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; } if (!backup->has_job_id) { backup->job_id = NULL; } if (!backup->has_compress) { backup->compress = false; } bs = qmp_get_root_bs(backup->device, errp); if (!bs) { return; } aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); if (!backup->has_format) { backup->format = backup->mode == NEW_IMAGE_MODE_EXISTING ? NULL : (char*) bs->drv->format_name; } /* Early check to avoid creating target */ if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { goto out; } flags = bs->open_flags | BDRV_O_RDWR; /* See if we have a backing HD we can use to create our new image * on top of. */ if (backup->sync == MIRROR_SYNC_MODE_TOP) { source = backing_bs(bs); if (!source) { backup->sync = MIRROR_SYNC_MODE_FULL; } } if (backup->sync == MIRROR_SYNC_MODE_NONE) { source = bs; } size = bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); goto out; } if (backup->mode != NEW_IMAGE_MODE_EXISTING) { assert(backup->format); if (source) { bdrv_img_create(backup->target, backup->format, source->filename, source->drv->format_name, NULL, size, flags, &local_err, false); } else { bdrv_img_create(backup->target, backup->format, NULL, NULL, NULL, size, flags, &local_err, false); } } if (local_err) { error_propagate(errp, local_err); goto out; } if (backup->format) { options = qdict_new(); qdict_put(options, "driver", qstring_from_str(backup->format)); } target_bs = bdrv_open(backup->target, NULL, options, flags, errp); if (!target_bs) { goto out; } bdrv_set_aio_context(target_bs, aio_context); if (backup->has_bitmap) { bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap); if (!bmap) { error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap); bdrv_unref(target_bs); goto out; } } backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync, bmap, backup->compress, backup->on_source_error, backup->on_target_error, BLOCK_JOB_DEFAULT, NULL, NULL, txn, &local_err); bdrv_unref(target_bs); if (local_err != NULL) { error_propagate(errp, local_err); goto out; } out: aio_context_release(aio_context); }
11,721
FFmpeg
1b3b018aa4e43d7bf87df5cdf28c69a9ad5a6cbc
1
static inline int get16(const uint8_t **pp, const uint8_t *p_end) { const uint8_t *p; int c; p = *pp; if ((p + 1) >= p_end) return AVERROR_INVALIDDATA; c = AV_RB16(p); p += 2; *pp = p; return c; }
11,722
qemu
15c2f669e3fb2bc97f7b42d1871f595c0ac24af8
1
static void test_visitor_out_null(TestOutputVisitorData *data, const void *unused) { QObject *arg; QDict *qdict; QObject *nil; visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); visit_type_null(data->ov, "a", &error_abort); visit_end_struct(data->ov, &error_abort); arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QDICT); qdict = qobject_to_qdict(arg); g_assert_cmpint(qdict_size(qdict), ==, 1); nil = qdict_get(qdict, "a"); g_assert(nil); g_assert(qobject_type(nil) == QTYPE_QNULL); qobject_decref(arg); }
11,724
qemu
198a0039c5fca224a77e9761e2350dd9cc102ad0
1
void vnc_client_error(VncState *vs) { vnc_client_io_error(vs, -1, EINVAL); }
11,725
qemu
0b8b8753e4d94901627b3e86431230f2319215c4
1
static void test_yield(void) { Coroutine *coroutine; bool done = false; int i = -1; /* one extra time to return from coroutine */ coroutine = qemu_coroutine_create(yield_5_times); while (!done) { qemu_coroutine_enter(coroutine, &done); i++; } g_assert_cmpint(i, ==, 5); /* coroutine must yield 5 times */ }
11,726
FFmpeg
29d1df66adb3723d1e7f2d363984b50792fb7c11
0
static inline int l3_unscale(int value, int exponent) { unsigned int m; int e; e = table_4_3_exp [4 * value + (exponent & 3)]; m = table_4_3_value[4 * value + (exponent & 3)]; e -= exponent >> 2; assert(e >= 1); if (e > 31) return 0; m = (m + (1 << (e - 1))) >> e; return m; }
11,727
FFmpeg
172865931951d73f1ac60f4b56cdb4da77f37f1d
0
static int wsaud_read_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; unsigned int chunk_size; int ret = 0; AVStream *st = s->streams[0]; if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != AUD_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); /* validate the chunk */ if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) return AVERROR_INVALIDDATA; chunk_size = AV_RL16(&preamble[0]); if (st->codec->codec_id == AV_CODEC_ID_WESTWOOD_SND1) { /* For Westwood SND1 audio we need to add the output size and input size to the start of the packet to match what is in VQA. Specifically, this is needed to signal when a packet should be decoding as raw 8-bit pcm or variable-size ADPCM. */ int out_size = AV_RL16(&preamble[2]); if ((ret = av_new_packet(pkt, chunk_size + 4))) return ret; if ((ret = avio_read(pb, &pkt->data[4], chunk_size)) != chunk_size) return ret < 0 ? ret : AVERROR(EIO); AV_WL16(&pkt->data[0], out_size); AV_WL16(&pkt->data[2], chunk_size); pkt->duration = out_size; } else { ret = av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) return AVERROR(EIO); /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ pkt->duration = (chunk_size * 2) / st->codec->channels; } pkt->stream_index = st->index; return ret; }
11,728
FFmpeg
1bbeb06a36ec36ce03e1c882c8e97efdc13c9a9b
0
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts) { ContextInfo *ci = (ContextInfo *) ctx; uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; int rowsize = picture->linesize[0]; #if 0 av_log(NULL, AV_LOG_DEBUG, "pix_fmt = %d, width = %d, pts = %lld, ci->next_pts = %lld\n", pix_fmt, width, pts, ci->next_pts); #endif if (pts < ci->next_pts) return; if (width < ci->min_width) return; ci->next_pts = pts + 1000000; if (pix_fmt == PIX_FMT_YUV420P) { uint8_t *y, *u, *v; int width2 = width >> 1; int inrange = 0; int pixcnt; int h; int h_start, h_end; int w_start, w_end; h_end = 2 * ((ci->inset * height) / 200); h_start = height - h_end; w_end = (ci->inset * width2) / 100; w_start = width2 - w_end; pixcnt = ((h_start - h_end) >> 1) * (w_start - w_end); y = picture->data[0] + h_end * picture->linesize[0] + w_end * 2; u = picture->data[1] + h_end * picture->linesize[1] / 2 + w_end; v = picture->data[2] + h_end * picture->linesize[2] / 2 + w_end; for (h = h_start; h > h_end; h -= 2) { int w; for (w = w_start; w > w_end; w--) { unsigned int r,g,b; HSV hsv; int cb, cr, yt, r_add, g_add, b_add; YUV_TO_RGB1_CCIR(u[0], v[0]); YUV_TO_RGB2_CCIR(r, g, b, y[0]); get_hsv(&hsv, r, g, b); if (ci->debug > 1) av_log(NULL, AV_LOG_DEBUG, "(%d,%d,%d) -> (%d,%d,%d)\n", r,g,b,hsv.h,hsv.s,hsv.v); if (hsv.h >= ci->dark.h && hsv.h <= ci->bright.h && hsv.s >= ci->dark.s && hsv.s <= ci->bright.s && hsv.v >= ci->dark.v && hsv.v <= ci->bright.v) { inrange++; } else if (ci->zapping) { y[0] = y[1] = y[rowsize] = y[rowsize + 1] = 16; u[0] = 128; v[0] = 128; } y+= 2; u++; v++; } y += picture->linesize[0] * 2 - (w_start - w_end) * 2; u += picture->linesize[1] - (w_start - w_end); v += picture->linesize[2] - (w_start - w_end); } if (ci->debug) av_log(NULL, AV_LOG_INFO, "Fish: Inrange=%d of %d = %d threshold\n", inrange, pixcnt, 1000 * inrange / pixcnt); if (inrange * 1000 / pixcnt >= ci->threshold) { /* Save to file */ int size; char *buf; AVPicture picture1; static int frame_counter; static int foundfile; if ((frame_counter++ % 20) == 0) { /* Check how many files we have */ DIR *d; foundfile = 0; d = opendir(ci->dir); if (d) { struct dirent *dent; while ((dent = readdir(d))) { if (strncmp("fishimg", dent->d_name, 7) == 0) { if (strcmp(".ppm", dent->d_name + strlen(dent->d_name) - 4) == 0) { foundfile++; } } } closedir(d); } } if (foundfile < ci->file_limit) { FILE *f; char fname[256]; size = avpicture_get_size(PIX_FMT_RGB24, width, height); buf = av_malloc(size); avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height); // if we already got a SWS context, let's realloc if is not re-useable ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx, width, height, pix_fmt, width, height, PIX_FMT_RGB24, sws_flags, NULL, NULL, NULL); if (ci->toRGB_convert_ctx == NULL) { av_log(NULL, AV_LOG_ERROR, "Cannot initialize the toRGB conversion context\n"); return; } // img_convert parameters are 2 first destination, then 4 source // sws_scale parameters are context, 4 first source, then 2 destination sws_scale(ci->toRGB_convert_ctx, picture->data, picture->linesize, 0, height, picture1.data, picture1.linesize); /* Write out the PPM file */ snprintf(fname, sizeof(fname), "%s/fishimg%ld_%"PRId64".ppm", ci->dir, (long)(av_gettime() / 1000000), pts); f = fopen(fname, "w"); if (f) { fprintf(f, "P6 %d %d 255\n", width, height); fwrite(buf, width * height * 3, 1, f); fclose(f); } av_free(buf); ci->next_pts = pts + ci->min_interval; } } } }
11,729
FFmpeg
229843aa359ae0c9519977d7fa952688db63f559
0
static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts) { AVIStream *avist = s->streams[stream_index]->priv_data; AVCodecContext *enc = s->streams[stream_index]->codec; av_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index); while (enc->block_align == 0 && dts != AV_NOPTS_VALUE && dts > avist->packet_count && enc->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) { AVPacket empty_packet; if (dts - avist->packet_count > 60000) { av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count); return AVERROR(EINVAL); } av_init_packet(&empty_packet); empty_packet.size = 0; empty_packet.data = NULL; empty_packet.stream_index = stream_index; avi_write_packet(s, &empty_packet); av_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count); } return 0; }
11,730
FFmpeg
46f67f4a34cab5f5686baf1605dd77d3c70740b5
1
MKSCALE16(scale16be, AV_RB16, AV_WB16) MKSCALE16(scale16le, AV_RL16, AV_WL16) static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); RawVideoContext *context = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int avpkt_stride = avpkt->size / avctx->height; int linesize_align = 4; int res, len; int need_copy; AVFrame *frame = data; if ((avctx->bits_per_coded_sample == 8 || avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2 || avctx->bits_per_coded_sample == 1) && avctx->pix_fmt == AV_PIX_FMT_PAL8 && (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) { context->is_1_2_4_8_bpp = 1; context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width, 16), avctx->height, 1); } else { context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16; context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); } if (context->frame_size < 0) return context->frame_size; need_copy = !avpkt->buf || context->is_1_2_4_8_bpp || context->is_yuv2 || context->is_lt_16bpp; frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; res = ff_decode_frame_props(avctx, frame); if (res < 0) return res; av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos); av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration); if (context->tff >= 0) { frame->interlaced_frame = 1; frame->top_field_first = context->tff; } if ((res = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) return res; if (need_copy) frame->buf[0] = av_buffer_alloc(FFMAX(context->frame_size, buf_size)); else frame->buf[0] = av_buffer_ref(avpkt->buf); if (!frame->buf[0]) return AVERROR(ENOMEM); // 1 bpp in mov, and 2, 4 and 8 bpp in avi/mov if (context->is_1_2_4_8_bpp) { int i, j, row_pix = 0; uint8_t *dst = frame->buf[0]->data; buf_size = context->frame_size - AVPALETTE_SIZE; if (avctx->bits_per_coded_sample == 8) { for (i = 0, j = 0; j < buf_size && i<avpkt->size; i++, j++) { dst[j] = buf[i]; row_pix++; if (row_pix == avctx->width) { i += avpkt_stride - (i % avpkt_stride) - 1; j += 16 - (j % 16) - 1; row_pix = 0; } } } else if (avctx->bits_per_coded_sample == 4) { for (i = 0, j = 0; 2 * j + 1 < buf_size && i<avpkt->size; i++, j++) { dst[2 * j + 0] = buf[i] >> 4; dst[2 * j + 1] = buf[i] & 15; row_pix += 2; if (row_pix >= avctx->width) { i += avpkt_stride - (i % avpkt_stride) - 1; j += 8 - (j % 8) - 1; row_pix = 0; } } } else if (avctx->bits_per_coded_sample == 2) { for (i = 0, j = 0; 4 * j + 3 < buf_size && i<avpkt->size; i++, j++) { dst[4 * j + 0] = buf[i] >> 6; dst[4 * j + 1] = buf[i] >> 4 & 3; dst[4 * j + 2] = buf[i] >> 2 & 3; dst[4 * j + 3] = buf[i] & 3; row_pix += 4; if (row_pix >= avctx->width) { i += avpkt_stride - (i % avpkt_stride) - 1; j += 4 - (j % 4) - 1; row_pix = 0; } } } else { av_assert0(avctx->bits_per_coded_sample == 1); for (i = 0, j = 0; 8 * j + 7 < buf_size && i<avpkt->size; i++, j++) { dst[8 * j + 0] = buf[i] >> 7; dst[8 * j + 1] = buf[i] >> 6 & 1; dst[8 * j + 2] = buf[i] >> 5 & 1; dst[8 * j + 3] = buf[i] >> 4 & 1; dst[8 * j + 4] = buf[i] >> 3 & 1; dst[8 * j + 5] = buf[i] >> 2 & 1; dst[8 * j + 6] = buf[i] >> 1 & 1; dst[8 * j + 7] = buf[i] & 1; row_pix += 8; if (row_pix >= avctx->width) { i += avpkt_stride - (i % avpkt_stride) - 1; j += 2 - (j % 2) - 1; row_pix = 0; } } } linesize_align = 16; buf = dst; } else if (context->is_lt_16bpp) { uint8_t *dst = frame->buf[0]->data; int packed = (avctx->codec_tag & 0xFFFFFF) == MKTAG('B','I','T', 0); int swap = avctx->codec_tag >> 24; if (packed && swap) { av_fast_padded_malloc(&context->bitstream_buf, &context->bitstream_buf_size, buf_size); if (!context->bitstream_buf) return AVERROR(ENOMEM); if (swap == 16) context->bbdsp.bswap16_buf(context->bitstream_buf, (const uint16_t*)buf, buf_size / 2); else if (swap == 32) context->bbdsp.bswap_buf(context->bitstream_buf, (const uint32_t*)buf, buf_size / 4); else return AVERROR_INVALIDDATA; buf = context->bitstream_buf; } if (desc->flags & AV_PIX_FMT_FLAG_BE) scale16be(avctx, dst, buf, buf_size, packed); else scale16le(avctx, dst, buf, buf_size, packed); buf = dst; } else if (need_copy) { memcpy(frame->buf[0]->data, buf, buf_size); buf = frame->buf[0]->data; } if (avctx->codec_tag == MKTAG('A', 'V', '1', 'x') || avctx->codec_tag == MKTAG('A', 'V', 'u', 'p')) buf += buf_size - context->frame_size; len = context->frame_size - (avctx->pix_fmt==AV_PIX_FMT_PAL8 ? AVPALETTE_SIZE : 0); if (buf_size < len && ((avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0) || !need_copy)) { av_log(avctx, AV_LOG_ERROR, "Invalid buffer size, packet size %d < expected frame_size %d\n", buf_size, len); av_buffer_unref(&frame->buf[0]); return AVERROR(EINVAL); } if ((res = av_image_fill_arrays(frame->data, frame->linesize, buf, avctx->pix_fmt, avctx->width, avctx->height, 1)) < 0) { av_buffer_unref(&frame->buf[0]); return res; } if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { av_buffer_unref(&context->palette); context->palette = av_buffer_alloc(AVPALETTE_SIZE); if (!context->palette) { av_buffer_unref(&frame->buf[0]); return AVERROR(ENOMEM); } memcpy(context->palette->data, pal, AVPALETTE_SIZE); frame->palette_has_changed = 1; } } if ((avctx->pix_fmt==AV_PIX_FMT_BGR24 || avctx->pix_fmt==AV_PIX_FMT_GRAY8 || avctx->pix_fmt==AV_PIX_FMT_RGB555LE || avctx->pix_fmt==AV_PIX_FMT_RGB555BE || avctx->pix_fmt==AV_PIX_FMT_RGB565LE || avctx->pix_fmt==AV_PIX_FMT_MONOWHITE || avctx->pix_fmt==AV_PIX_FMT_PAL8) && FFALIGN(frame->linesize[0], linesize_align) * avctx->height <= buf_size) frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align); if (avctx->pix_fmt == AV_PIX_FMT_NV12 && avctx->codec_tag == MKTAG('N', 'V', '1', '2') && FFALIGN(frame->linesize[0], linesize_align) * avctx->height + FFALIGN(frame->linesize[1], linesize_align) * ((avctx->height + 1) / 2) <= buf_size) { int la0 = FFALIGN(frame->linesize[0], linesize_align); frame->data[1] += (la0 - frame->linesize[0]) * avctx->height; frame->linesize[0] = la0; frame->linesize[1] = FFALIGN(frame->linesize[1], linesize_align); } if ((avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->frame_size) || (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)) { frame->buf[1] = av_buffer_ref(context->palette); if (!frame->buf[1]) { av_buffer_unref(&frame->buf[0]); return AVERROR(ENOMEM); } frame->data[1] = frame->buf[1]->data; } if (avctx->pix_fmt == AV_PIX_FMT_BGR24 && ((frame->linesize[0] + 3) & ~3) * avctx->height <= buf_size) frame->linesize[0] = (frame->linesize[0] + 3) & ~3; if (context->flip) flip(avctx, frame); if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2') || avctx->codec_tag == MKTAG('Y', 'V', '1', '6') || avctx->codec_tag == MKTAG('Y', 'V', '2', '4') || avctx->codec_tag == MKTAG('Y', 'V', 'U', '9')) FFSWAP(uint8_t *, frame->data[1], frame->data[2]); if (avctx->codec_tag == AV_RL32("I420") && (avctx->width+1)*(avctx->height+1) * 3/2 == buf_size) { frame->data[1] = frame->data[1] + (avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height; frame->data[2] = frame->data[2] + ((avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height)*5/4; } if (avctx->codec_tag == AV_RL32("yuv2") && avctx->pix_fmt == AV_PIX_FMT_YUYV422) { int x, y; uint8_t *line = frame->data[0]; for (y = 0; y < avctx->height; y++) { for (x = 0; x < avctx->width; x++) line[2 * x + 1] ^= 0x80; line += frame->linesize[0]; } } if (avctx->field_order > AV_FIELD_PROGRESSIVE) { /* we have interlaced material flagged in container */ frame->interlaced_frame = 1; if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB) frame->top_field_first = 1; } *got_frame = 1; return buf_size; }
11,733
FFmpeg
d7e9533aa06f4073a27812349b35ba5fede11ca1
1
static void convert_matrix(int *qmat, UINT16 *qmat16, const UINT16 *quant_matrix, int qscale) { int i; if (av_fdct == jpeg_fdct_ifast) { for(i=0;i<64;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[block_permute_op(i)] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / (aanscales[i] * qscale * quant_matrix[block_permute_op(i)])); } } else { for(i=0;i<64;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[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); qmat16[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]); } } }
11,734
qemu
21d58b575e79c5d0739b695b272ea89bb052a7bf
1
static void virtio_console_init_pci(PCIDevice *pci_dev) { VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIODevice *vdev; vdev = virtio_console_init(&pci_dev->qdev); virtio_init_pci(proxy, vdev, PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_CONSOLE, PCI_CLASS_DISPLAY_OTHER, 0x00); }
11,736
FFmpeg
e07ac727c1cc9eed39e7f9117c97006f719864bd
1
static int g2m_init_buffers(G2MContext *c) { int aligned_height; if (!c->framebuf || c->old_width < c->width || c->old_height < c->height) { c->framebuf_stride = FFALIGN(c->width * 3, 16); aligned_height = FFALIGN(c->height, 16); av_free(c->framebuf); c->framebuf = av_mallocz(c->framebuf_stride * aligned_height); if (!c->framebuf) return AVERROR(ENOMEM); } if (!c->synth_tile || !c->jpeg_tile || c->old_tile_w < c->tile_width || c->old_tile_h < c->tile_height) { c->tile_stride = FFALIGN(c->tile_width, 16) * 3; aligned_height = FFALIGN(c->tile_height, 16); av_free(c->synth_tile); av_free(c->jpeg_tile); av_free(c->kempf_buf); av_free(c->kempf_flags); c->synth_tile = av_mallocz(c->tile_stride * aligned_height); c->jpeg_tile = av_mallocz(c->tile_stride * aligned_height); c->kempf_buf = av_mallocz((c->tile_width + 1) * aligned_height + FF_INPUT_BUFFER_PADDING_SIZE); c->kempf_flags = av_mallocz( c->tile_width * aligned_height); if (!c->synth_tile || !c->jpeg_tile || !c->kempf_buf || !c->kempf_flags) return AVERROR(ENOMEM); } return 0; }
11,737
qemu
a7278b36fcab9af469563bd7b9dadebe2ae25e48
1
static bool vmxnet_tx_pkt_parse_headers(struct VmxnetTxPkt *pkt) { struct iovec *l2_hdr, *l3_hdr; size_t bytes_read; size_t full_ip6hdr_len; uint16_t l3_proto; assert(pkt); l2_hdr = &pkt->vec[VMXNET_TX_PKT_L2HDR_FRAG]; l3_hdr = &pkt->vec[VMXNET_TX_PKT_L3HDR_FRAG]; bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, 0, l2_hdr->iov_base, ETH_MAX_L2_HDR_LEN); if (bytes_read < ETH_MAX_L2_HDR_LEN) { l2_hdr->iov_len = 0; return false; } else { l2_hdr->iov_len = eth_get_l2_hdr_length(l2_hdr->iov_base); } l3_proto = eth_get_l3_proto(l2_hdr->iov_base, l2_hdr->iov_len); switch (l3_proto) { case ETH_P_IP: l3_hdr->iov_base = g_malloc(ETH_MAX_IP4_HDR_LEN); bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, l2_hdr->iov_len, l3_hdr->iov_base, sizeof(struct ip_header)); if (bytes_read < sizeof(struct ip_header)) { l3_hdr->iov_len = 0; return false; } l3_hdr->iov_len = IP_HDR_GET_LEN(l3_hdr->iov_base); pkt->l4proto = ((struct ip_header *) l3_hdr->iov_base)->ip_p; /* copy optional IPv4 header data */ bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, l2_hdr->iov_len + sizeof(struct ip_header), l3_hdr->iov_base + sizeof(struct ip_header), l3_hdr->iov_len - sizeof(struct ip_header)); if (bytes_read < l3_hdr->iov_len - sizeof(struct ip_header)) { l3_hdr->iov_len = 0; return false; } break; case ETH_P_IPV6: if (!eth_parse_ipv6_hdr(pkt->raw, pkt->raw_frags, l2_hdr->iov_len, &pkt->l4proto, &full_ip6hdr_len)) { l3_hdr->iov_len = 0; return false; } l3_hdr->iov_base = g_malloc(full_ip6hdr_len); bytes_read = iov_to_buf(pkt->raw, pkt->raw_frags, l2_hdr->iov_len, l3_hdr->iov_base, full_ip6hdr_len); if (bytes_read < full_ip6hdr_len) { l3_hdr->iov_len = 0; return false; } else { l3_hdr->iov_len = full_ip6hdr_len; } break; default: l3_hdr->iov_len = 0; break; } vmxnet_tx_pkt_calculate_hdr_len(pkt); pkt->packet_type = get_eth_packet_type(l2_hdr->iov_base); return true; }
11,738
qemu
8cdd2e0abbf593a38a146d8dfc998754cefbc27a
1
int tpm_register_model(enum TpmModel model) { int i; for (i = 0; i < TPM_MAX_MODELS; i++) { if (tpm_models[i] == -1) { tpm_models[i] = model; return 0; } } error_report("Could not register TPM model"); return 1; }
11,739
qemu
7d1b0095bff7157e856d1d0e6c4295641ced2752
1
static inline TCGv load_cpu_offset(int offset) { TCGv tmp = new_tmp(); tcg_gen_ld_i32(tmp, cpu_env, offset); return tmp; }
11,740
qemu
905f26f2221e139ac0e7317ddac158c50f5cf876
1
static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) { int ret, rc = 0; unsigned int xh_len; int xh_flags; if (!XBZRLE.decoded_buf) { XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE); } /* extract RLE header */ xh_flags = qemu_get_byte(f); xh_len = qemu_get_be16(f); if (xh_flags != ENCODING_FLAG_XBZRLE) { fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n"); return -1; } if (xh_len > TARGET_PAGE_SIZE) { fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n"); return -1; } /* load data and decode */ qemu_get_buffer(f, XBZRLE.decoded_buf, xh_len); /* decode RLE */ ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host, TARGET_PAGE_SIZE); if (ret == -1) { fprintf(stderr, "Failed to load XBZRLE page - decode error!\n"); rc = -1; } else if (ret > TARGET_PAGE_SIZE) { fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n", ret, TARGET_PAGE_SIZE); abort(); } return rc; }
11,741
FFmpeg
f04fe23a5256cc82c383f2949ead78cb7cc9228d
1
static int xv_write_header(AVFormatContext *s) { XVContext *xv = s->priv_data; unsigned int num_adaptors; XvAdaptorInfo *ai; XvImageFormatValues *fv; int num_formats = 0, j; AVCodecContext *encctx = s->streams[0]->codec; if ( s->nb_streams > 1 || encctx->codec_type != AVMEDIA_TYPE_VIDEO || encctx->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); return AVERROR(EINVAL); } xv->display = XOpenDisplay(xv->display_name); if (!xv->display) { av_log(s, AV_LOG_ERROR, "Could not open the X11 display '%s'\n", xv->display_name); return AVERROR(EINVAL); } xv->image_width = encctx->width; xv->image_height = encctx->height; if (!xv->window_width && !xv->window_height) { xv->window_width = encctx->width; xv->window_height = encctx->height; } xv->window = XCreateSimpleWindow(xv->display, DefaultRootWindow(xv->display), xv->window_x, xv->window_y, xv->window_width, xv->window_height, 0, 0, 0); if (!xv->window_title) { if (!(xv->window_title = av_strdup(s->filename))) return AVERROR(ENOMEM); } XStoreName(xv->display, xv->window, xv->window_title); XMapWindow(xv->display, xv->window); if (XvQueryAdaptors(xv->display, DefaultRootWindow(xv->display), &num_adaptors, &ai) != Success) return AVERROR_EXTERNAL; xv->xv_port = ai[0].base_id; if (encctx->pix_fmt != AV_PIX_FMT_YUV420P) { av_log(s, AV_LOG_ERROR, "Unsupported pixel format '%s', only yuv420p is currently supported\n", av_get_pix_fmt_name(encctx->pix_fmt)); return AVERROR_PATCHWELCOME; } fv = XvListImageFormats(xv->display, xv->xv_port, &num_formats); if (!fv) return AVERROR_EXTERNAL; for (j = 0; j < num_formats; j++) { if (fv[j].id == MKTAG('I','4','2','0')) { break; } } XFree(fv); if (j >= num_formats) { av_log(s, AV_LOG_ERROR, "Device does not support pixel format yuv420p, aborting\n"); return AVERROR(EINVAL); } xv->gc = XCreateGC(xv->display, xv->window, 0, 0); xv->image_width = encctx->width; xv->image_height = encctx->height; xv->yuv_image = XvShmCreateImage(xv->display, xv->xv_port, MKTAG('I','4','2','0'), 0, xv->image_width, xv->image_height, &xv->yuv_shminfo); xv->yuv_shminfo.shmid = shmget(IPC_PRIVATE, xv->yuv_image->data_size, IPC_CREAT | 0777); xv->yuv_shminfo.shmaddr = (char *)shmat(xv->yuv_shminfo.shmid, 0, 0); xv->yuv_image->data = xv->yuv_shminfo.shmaddr; xv->yuv_shminfo.readOnly = False; XShmAttach(xv->display, &xv->yuv_shminfo); XSync(xv->display, False); shmctl(xv->yuv_shminfo.shmid, IPC_RMID, 0); return 0; }
11,743
qemu
f81e551229070f01bf747eda3f05960182db9d2a
1
static void xscom_write(void *opaque, hwaddr addr, uint64_t val, unsigned width) { PnvChip *chip = opaque; uint32_t pcba = pnv_xscom_pcba(chip, addr); MemTxResult result; /* Handle some SCOMs here before dispatch */ if (xscom_write_default(chip, pcba, val)) { goto complete; } address_space_stq(&chip->xscom_as, pcba << 3, val, MEMTXATTRS_UNSPECIFIED, &result); if (result != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "XSCOM write failed at @0x%" HWADDR_PRIx " pcba=0x%08x data=0x%" PRIx64 "\n", addr, pcba, val); xscom_complete(current_cpu, HMER_XSCOM_FAIL | HMER_XSCOM_DONE); return; } complete: xscom_complete(current_cpu, HMER_XSCOM_DONE); }
11,744
qemu
212df029754caabba45f941fbd22ec219b934ef9
1
void cpu_alpha_store_fpcr (CPUState *env, uint64_t val) { int round_mode, mask; set_float_exception_flags((val >> 52) & 0x3F, &env->fp_status); mask = 0; if (val & FPCR_INVD) mask |= float_flag_invalid; if (val & FPCR_DZED) mask |= float_flag_divbyzero; if (val & FPCR_OVFD) mask |= float_flag_overflow; if (val & FPCR_UNFD) mask |= float_flag_underflow; if (val & FPCR_INED) mask |= float_flag_inexact; env->fp_status.float_exception_mask = mask; switch ((val >> FPCR_DYN_SHIFT) & 3) { case 0: round_mode = float_round_to_zero; break; case 1: round_mode = float_round_down; break; case 2: round_mode = float_round_nearest_even; break; case 3: round_mode = float_round_up; break; } set_float_rounding_mode(round_mode, &env->fp_status); }
11,746
FFmpeg
42364fcbcac99c42a9859c3662a2956e5554b68c
1
int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr) { uint8_t iv[16] = { 0 }, hmac[20]; int len = *lenptr; int ext, seq_largest; uint32_t ssrc, roc; uint64_t index; int rtcp; // TODO: Missing replay protection if (len < s->hmac_size) return AVERROR_INVALIDDATA; rtcp = RTP_PT_IS_RTCP(buf[1]); // Authentication HMAC av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth)); // If MKI is used, this should exclude the MKI as well av_hmac_update(s->hmac, buf, len - s->hmac_size); if (!rtcp) { int seq = AV_RB16(buf + 2); uint32_t v; uint8_t rocbuf[4]; // RFC 3711 section 3.3.1, appendix A seq_largest = s->seq_initialized ? s->seq_largest : seq; v = roc = s->roc; if (seq_largest < 32768) { if (seq - seq_largest > 32768) v = roc - 1; } else { if (seq_largest - 32768 > seq) v = roc + 1; } if (v == roc) { seq_largest = FFMAX(seq_largest, seq); } else if (v == roc + 1) { seq_largest = seq; roc = v; } index = seq + (((uint64_t)v) << 16); AV_WB32(rocbuf, roc); av_hmac_update(s->hmac, rocbuf, 4); } av_hmac_final(s->hmac, hmac, sizeof(hmac)); if (memcmp(hmac, buf + len - s->hmac_size, s->hmac_size)) { av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\n"); return AVERROR_INVALIDDATA; } len -= s->hmac_size; *lenptr = len; if (len < 12) return AVERROR_INVALIDDATA; if (rtcp) { uint32_t srtcp_index = AV_RB32(buf + len - 4); len -= 4; *lenptr = len; ssrc = AV_RB32(buf + 4); index = srtcp_index & 0x7fffffff; buf += 8; len -= 8; if (!(srtcp_index & 0x80000000)) return 0; } else { s->seq_initialized = 1; s->seq_largest = seq_largest; s->roc = roc; ext = buf[0] & 0x10; ssrc = AV_RB32(buf + 8); buf += 12; len -= 12; if (ext) { if (len < 4) return AVERROR_INVALIDDATA; ext = (AV_RB16(buf + 2) + 1) * 4; if (len < ext) return AVERROR_INVALIDDATA; len -= ext; buf += ext; } } create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc); av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0); encrypt_counter(s->aes, iv, buf, len); return 0; }
11,747
FFmpeg
70259737cbad1136d942fa0cca5d55be1ca37e0a
1
static void celt_pvq_search(float *X, int *y, int K, int N) { int i; float res = 0.0f, y_norm = 0.0f, xy_norm = 0.0f; for (i = 0; i < N; i++) res += FFABS(X[i]); res = K/res; for (i = 0; i < N; i++) { y[i] = lrintf(res*X[i]); y_norm += y[i]*y[i]; xy_norm += y[i]*X[i]; K -= FFABS(y[i]); } while (K) { int max_idx = 0, phase = FFSIGN(K); float max_den = 1.0f, max_num = 0.0f; y_norm += 1.0f; for (i = 0; i < N; i++) { /* If the sum has been overshot and the best place has 0 pulses allocated * to it, attempting to decrease it further will actually increase the * sum. Prevent this by disregarding any 0 positions when decrementing. */ const int ca = 1 ^ ((y[i] == 0) & (phase < 0)); float xy_new = xy_norm + 1*phase*FFABS(X[i]); float y_new = y_norm + 2*phase*FFABS(y[i]); xy_new = xy_new * xy_new; if (ca && (max_den*xy_new) > (y_new*max_num)) { max_den = y_new; max_num = xy_new; max_idx = i; } } K -= phase; phase *= FFSIGN(X[max_idx]); xy_norm += 1*phase*X[max_idx]; y_norm += 2*phase*y[max_idx]; y[max_idx] += phase; } }
11,750
qemu
19ebd13ed45ad5d5f277f5914d55b83f13eb09eb
1
static void commit_complete(BlockJob *job, void *opaque) { CommitBlockJob *s = container_of(job, CommitBlockJob, common); CommitCompleteData *data = opaque; BlockDriverState *active = s->active; BlockDriverState *top = blk_bs(s->top); BlockDriverState *base = blk_bs(s->base); BlockDriverState *overlay_bs = bdrv_find_overlay(active, s->commit_top_bs); int ret = data->ret; bool remove_commit_top_bs = false; /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */ bdrv_ref(top); bdrv_ref(overlay_bs); /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before * the normal backing chain can be restored. */ blk_unref(s->base); if (!block_job_is_cancelled(&s->common) && ret == 0) { /* success */ ret = bdrv_drop_intermediate(active, s->commit_top_bs, base, s->backing_file_str); } else if (overlay_bs) { /* XXX Can (or should) we somehow keep 'consistent read' blocked even * after the failed/cancelled commit job is gone? If we already wrote * something to base, the intermediate images aren't valid any more. */ remove_commit_top_bs = true; } /* restore base open flags here if appropriate (e.g., change the base back * to r/o). These reopens do not need to be atomic, since we won't abort * even on failure here */ if (s->base_flags != bdrv_get_flags(base)) { bdrv_reopen(base, s->base_flags, NULL); } if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) { bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL); } g_free(s->backing_file_str); blk_unref(s->top); block_job_completed(&s->common, ret); g_free(data); /* If bdrv_drop_intermediate() didn't already do that, remove the commit * filter driver from the backing chain. Do this as the final step so that * the 'consistent read' permission can be granted. */ if (remove_commit_top_bs) { bdrv_set_backing_hd(overlay_bs, top, &error_abort); } }
11,751
FFmpeg
5edea431d0616737e5a5f58cefc07ba5b2e0875f
1
static void compute_pkt_fields2(AVStream *st, AVPacket *pkt){ int b_frames = FFMAX(st->codec.has_b_frames, st->codec.max_b_frames); int num, den, frame_size; // av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, b_frames, pkt->size, pkt->stream_index); /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE) return -1;*/ if(pkt->pts != AV_NOPTS_VALUE) pkt->pts = av_rescale(pkt->pts, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); if(pkt->dts != AV_NOPTS_VALUE) pkt->dts = av_rescale(pkt->dts, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); /* duration field */ pkt->duration = av_rescale(pkt->duration, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); if (pkt->duration == 0) { compute_frame_duration(&num, &den, st, NULL, pkt); if (den && num) { pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); } } //XXX/FIXME this is a temporary hack until all encoders output pts if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !b_frames){ pkt->dts= // pkt->pts= st->cur_dts; pkt->pts= st->pts.val; } //calculate dts from pts if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){ if(b_frames){ if(st->last_IP_pts == AV_NOPTS_VALUE){ st->last_IP_pts= -pkt->duration; } if(st->last_IP_pts < pkt->pts){ pkt->dts= st->last_IP_pts; st->last_IP_pts= pkt->pts; }else pkt->dts= pkt->pts; }else pkt->dts= pkt->pts; } // av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%lld dts2:%lld\n", pkt->pts, pkt->dts); st->cur_dts= pkt->dts; st->pts.val= pkt->dts; /* update pts */ switch (st->codec.codec_type) { case CODEC_TYPE_AUDIO: frame_size = get_audio_frame_size(&st->codec, pkt->size); /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay, but it would be better if we had the real timestamps from the encoder */ if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) { av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); } break; case CODEC_TYPE_VIDEO: av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec.frame_rate_base); break; default: break; } }
11,752
qemu
731d5856cbb9c160fe02b90cd3cf354ea4f52f34
1
static void net_dump_cleanup(VLANClientState *vc) { DumpState *s = vc->opaque; close(s->fd); qemu_free(s); }
11,753
qemu
874adf45dbfbae2810423527d777ba37bc5ca974
1
int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) { int i, ret; int32_t config_len; uint32_t num; uint32_t features; BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); /* * We poison the endianness to ensure it does not get used before * subsections have been loaded. */ vdev->device_endian = VIRTIO_DEVICE_ENDIAN_UNKNOWN; 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_QUEUE_MAX) { return -1; } qemu_get_be32s(f, &features); /* * Temporarily set guest_features low bits - needed by * virtio net load code testing for VIRTIO_NET_F_CTRL_GUEST_OFFLOADS * VIRTIO_NET_F_GUEST_ANNOUNCE and VIRTIO_NET_F_CTRL_VQ. * * Note: devices should always test host features in future - don't create * new dependencies like this. */ vdev->guest_features = features; config_len = qemu_get_be32(f); /* * There are cases where the incoming config can be bigger or smaller * than what we have; so load what we have space for, and skip * any excess that's in the stream. */ qemu_get_buffer(f, vdev->config, MIN(config_len, vdev->config_len)); while (config_len > vdev->config_len) { qemu_get_byte(f); config_len--; } num = qemu_get_be32(f); if (num > VIRTIO_QUEUE_MAX) { error_report("Invalid number of virtqueues: 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].vring.desc = 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].vring.desc) { /* XXX virtio-1 devices */ virtio_queue_update_rings(vdev, i); } 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); if (vdc->load != NULL) { ret = vdc->load(vdev, f, version_id); if (ret) { return ret; } } if (vdc->vmsd) { ret = vmstate_load_state(f, vdc->vmsd, vdev, version_id); if (ret) { return ret; } } /* Subsections */ ret = vmstate_load_state(f, &vmstate_virtio, vdev, 1); if (ret) { return ret; } if (vdev->device_endian == VIRTIO_DEVICE_ENDIAN_UNKNOWN) { vdev->device_endian = virtio_default_endian(); } if (virtio_64bit_features_needed(vdev)) { /* * Subsection load filled vdev->guest_features. Run them * through virtio_set_features to sanity-check them against * host_features. */ uint64_t features64 = vdev->guest_features; if (virtio_set_features_nocheck(vdev, features64) < 0) { error_report("Features 0x%" PRIx64 " unsupported. " "Allowed features: 0x%" PRIx64, features64, vdev->host_features); return -1; } } else { if (virtio_set_features_nocheck(vdev, features) < 0) { error_report("Features 0x%x unsupported. " "Allowed features: 0x%" PRIx64, features, vdev->host_features); return -1; } } rcu_read_lock(); for (i = 0; i < num; i++) { if (vdev->vq[i].vring.desc) { uint16_t nheads; nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx; /* Check it isn't doing 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; } vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]); vdev->vq[i].shadow_avail_idx = vring_avail_idx(&vdev->vq[i]); /* * Some devices migrate VirtQueueElements that have been popped * from the avail ring but not yet returned to the used ring. * Since max ring size < UINT16_MAX it's safe to use modulo * UINT16_MAX + 1 subtraction. */ vdev->vq[i].inuse = (uint16_t)(vdev->vq[i].last_avail_idx - vdev->vq[i].used_idx); if (vdev->vq[i].inuse > vdev->vq[i].vring.num) { error_report("VQ %d size 0x%x < last_avail_idx 0x%x - " "used_idx 0x%x", i, vdev->vq[i].vring.num, vdev->vq[i].last_avail_idx, vdev->vq[i].used_idx); return -1; } } } rcu_read_unlock(); return 0; }
11,754
FFmpeg
dae7ff04160901a30a35af05f2f149b289c4f0b1
1
static int my_log2(unsigned int i) { unsigned int iLog2 = 0; while ((i >> iLog2) > 1) iLog2++; return iLog2; }
11,755
qemu
b2d1fe67d09d2b6c7da647fbcea6ca0148c206d3
1
static void usbredir_iso_packet(void *priv, uint64_t id, struct usb_redir_iso_packet_header *iso_packet, uint8_t *data, int data_len) { USBRedirDevice *dev = priv; uint8_t ep = iso_packet->endpoint; DPRINTF2("iso-in status %d ep %02X len %d id %"PRIu64"\n", iso_packet->status, ep, data_len, id); if (dev->endpoint[EP2I(ep)].type != USB_ENDPOINT_XFER_ISOC) { ERROR("received iso packet for non iso endpoint %02X\n", ep); free(data); return; } if (dev->endpoint[EP2I(ep)].iso_started == 0) { DPRINTF("received iso packet for non started stream ep %02X\n", ep); free(data); return; } /* bufp_alloc also adds the packet to the ep queue */ bufp_alloc(dev, data, data_len, iso_packet->status, ep); }
11,756
FFmpeg
32c3047cac9294bb56d23c89a40a22409db5cc70
0
static int vqa_decode_init(AVCodecContext *avctx) { VqaContext *s = avctx->priv_data; unsigned char *vqa_header; int i, j, codebook_index; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; dsputil_init(&s->dsp, avctx); /* make sure the extradata made it */ if (s->avctx->extradata_size != VQA_HEADER_SIZE) { av_log(s->avctx, AV_LOG_ERROR, " VQA video: expected extradata size of %d\n", VQA_HEADER_SIZE); return -1; } /* load up the VQA parameters from the header */ vqa_header = (unsigned char *)s->avctx->extradata; s->vqa_version = vqa_header[0]; s->width = AV_RL16(&vqa_header[6]); s->height = AV_RL16(&vqa_header[8]); if(avcodec_check_dimensions(avctx, s->width, s->height)){ s->width= s->height= 0; return -1; } s->vector_width = vqa_header[10]; s->vector_height = vqa_header[11]; s->partial_count = s->partial_countdown = vqa_header[13]; /* the vector dimensions have to meet very stringent requirements */ if ((s->vector_width != 4) || ((s->vector_height != 2) && (s->vector_height != 4))) { /* return without further initialization */ return -1; } /* allocate codebooks */ s->codebook_size = MAX_CODEBOOK_SIZE; s->codebook = av_malloc(s->codebook_size); s->next_codebook_buffer = av_malloc(s->codebook_size); /* initialize the solid-color vectors */ if (s->vector_height == 4) { codebook_index = 0xFF00 * 16; for (i = 0; i < 256; i++) for (j = 0; j < 16; j++) s->codebook[codebook_index++] = i; } else { codebook_index = 0xF00 * 8; for (i = 0; i < 256; i++) for (j = 0; j < 8; j++) s->codebook[codebook_index++] = i; } s->next_codebook_buffer_index = 0; /* allocate decode buffer */ s->decode_buffer_size = (s->width / s->vector_width) * (s->height / s->vector_height) * 2; s->decode_buffer = av_malloc(s->decode_buffer_size); s->frame.data[0] = NULL; return 0; }
11,757
FFmpeg
ba80b8d29b2adc7fd74324c9bd50cd0be7ab2c21
0
static void decode_hrd(HEVCContext *s, int common_inf_present, int max_sublayers) { GetBitContext *gb = &s->HEVClc->gb; int nal_params_present = 0, vcl_params_present = 0; int subpic_params_present = 0; int i; if (common_inf_present) { nal_params_present = get_bits1(gb); vcl_params_present = get_bits1(gb); if (nal_params_present || vcl_params_present) { subpic_params_present = get_bits1(gb); if (subpic_params_present) { skip_bits(gb, 8); // tick_divisor_minus2 skip_bits(gb, 5); // du_cpb_removal_delay_increment_length_minus1 skip_bits(gb, 1); // sub_pic_cpb_params_in_pic_timing_sei_flag skip_bits(gb, 5); // dpb_output_delay_du_length_minus1 } skip_bits(gb, 4); // bit_rate_scale skip_bits(gb, 4); // cpb_size_scale if (subpic_params_present) skip_bits(gb, 4); // cpb_size_du_scale skip_bits(gb, 5); // initial_cpb_removal_delay_length_minus1 skip_bits(gb, 5); // au_cpb_removal_delay_length_minus1 skip_bits(gb, 5); // dpb_output_delay_length_minus1 } } for (i = 0; i < max_sublayers; i++) { int low_delay = 0; unsigned int nb_cpb = 1; int fixed_rate = get_bits1(gb); if (!fixed_rate) fixed_rate = get_bits1(gb); if (fixed_rate) get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1 else low_delay = get_bits1(gb); if (!low_delay) nb_cpb = get_ue_golomb_long(gb) + 1; if (nal_params_present) decode_sublayer_hrd(s, nb_cpb, subpic_params_present); if (vcl_params_present) decode_sublayer_hrd(s, nb_cpb, subpic_params_present); } }
11,758
qemu
b3ceef24f4fee8d5ed96b8c4a5d3e80c0a651f0b
0
static void slavio_serial_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) { SerialState *ser = opaque; ChannelState *s; uint32_t saddr; int newreg, channel; val &= 0xff; saddr = (addr & 3) >> 1; channel = (addr & SERIAL_MAXADDR) >> 2; s = &ser->chn[channel]; switch (saddr) { case 0: SER_DPRINTF("Write channel %c, reg[%d] = %2.2x\n", CHN_C(s), s->reg, val & 0xff); newreg = 0; switch (s->reg) { case 0: newreg = val & 7; val &= 0x38; switch (val) { case 8: newreg |= 0x8; break; case 0x28: clr_txint(s); break; case 0x38: if (s->rxint_under_svc) clr_rxint(s); else if (s->txint_under_svc) clr_txint(s); break; default: break; } break; case 1 ... 3: case 6 ... 8: case 10 ... 11: case 14 ... 15: s->wregs[s->reg] = val; break; case 4: case 5: case 12: case 13: s->wregs[s->reg] = val; slavio_serial_update_parameters(s); break; case 9: switch (val & 0xc0) { case 0: default: break; case 0x40: slavio_serial_reset_chn(&ser->chn[1]); return; case 0x80: slavio_serial_reset_chn(&ser->chn[0]); return; case 0xc0: slavio_serial_reset(ser); return; } break; default: break; } if (s->reg == 0) s->reg = newreg; else s->reg = 0; break; case 1: SER_DPRINTF("Write channel %c, ch %d\n", CHN_C(s), val); if (s->wregs[5] & 8) { // tx enabled s->tx = val; if (s->chr) qemu_chr_write(s->chr, &s->tx, 1); else if (s->type == kbd) { handle_kbd_command(s, val); } s->rregs[0] |= 4; // Tx buffer empty s->rregs[1] |= 1; // All sent set_txint(s); } break; default: break; } }
11,759
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
mst_fpga_writeb(void *opaque, target_phys_addr_t addr, uint64_t value, unsigned size) { mst_irq_state *s = (mst_irq_state *) opaque; value &= 0xffffffff; switch (addr) { case MST_LEDDAT1: s->leddat1 = value; break; case MST_LEDDAT2: s->leddat2 = value; break; case MST_LEDCTRL: s->ledctrl = value; break; case MST_GPSWR: s->gpswr = value; break; case MST_MSCWR1: s->mscwr1 = value; break; case MST_MSCWR2: s->mscwr2 = value; break; case MST_MSCWR3: s->mscwr3 = value; break; case MST_MSCRD: s->mscrd = value; break; case MST_INTMSKENA: /* Mask interrupt */ s->intmskena = (value & 0xFEEFF); qemu_set_irq(s->parent, s->intsetclr & s->intmskena); break; case MST_INTSETCLR: /* clear or set interrupt */ s->intsetclr = (value & 0xFEEFF); qemu_set_irq(s->parent, s->intsetclr & s->intmskena); break; /* For PCMCIAx allow the to change only power and reset */ case MST_PCMCIA0: s->pcmcia0 = (value & 0x1f) | (s->pcmcia0 & ~0x1f); break; case MST_PCMCIA1: s->pcmcia1 = (value & 0x1f) | (s->pcmcia1 & ~0x1f); break; default: printf("Mainstone - mst_fpga_writeb: Bad register offset " "0x" TARGET_FMT_plx "\n", addr); } }
11,760
qemu
e6a3ee5f7981e7df40aa581ebc245fd0a7d3bed0
0
static int sysctl_oldcvt(void *holdp, size_t holdlen, uint32_t kind) { switch (kind & CTLTYPE) { case CTLTYPE_INT: case CTLTYPE_UINT: *(uint32_t *)holdp = tswap32(*(uint32_t *)holdp); break; #ifdef TARGET_ABI32 case CTLTYPE_LONG: case CTLTYPE_ULONG: *(uint32_t *)holdp = tswap32(*(long *)holdp); break; #else case CTLTYPE_LONG: *(uint64_t *)holdp = tswap64(*(long *)holdp); case CTLTYPE_ULONG: *(uint64_t *)holdp = tswap64(*(unsigned long *)holdp); break; #endif #if !defined(__FreeBSD_version) || __FreeBSD_version < 900031 case CTLTYPE_QUAD: #else case CTLTYPE_U64: #endif *(uint64_t *)holdp = tswap64(*(uint64_t *)holdp); break; case CTLTYPE_STRING: break; default: /* XXX unhandled */ return -1; } return 0; }
11,761
qemu
72cf2d4f0e181d0d3a3122e04129c58a95da713e
0
static void vma_delete(struct mm_struct *mm) { struct vm_area_struct *vma; while ((vma = vma_first(mm)) != NULL) { TAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); qemu_free(vma); } qemu_free(mm); }
11,762
qemu
6e0d8677cb443e7408c0b7a25a93c6596d7fa380
0
void OPPROTO op_addl_ESI_T0(void) { ESI = (uint32_t)(ESI + T0); }
11,763
FFmpeg
68f593b48433842f3407586679fe07f3e5199ab9
0
static int rv10_decode_packet(AVCodecContext *avctx, UINT8 *buf, int buf_size) { MpegEncContext *s = avctx->priv_data; int i, mb_count, mb_pos, left; init_get_bits(&s->gb, buf, buf_size); mb_count = rv10_decode_picture_header(s); if (mb_count < 0) { fprintf(stderr, "HEADER ERROR\n"); return -1; } if (s->mb_x >= s->mb_width || s->mb_y >= s->mb_height) { fprintf(stderr, "POS ERROR %d %d\n", s->mb_x, s->mb_y); return -1; } mb_pos = s->mb_y * s->mb_width + s->mb_x; left = s->mb_width * s->mb_height - mb_pos; if (mb_count > left) { fprintf(stderr, "COUNT ERROR\n"); return -1; } if (s->mb_x == 0 && s->mb_y == 0) { if(MPV_frame_start(s, avctx) < 0) return -1; } #ifdef DEBUG printf("qscale=%d\n", s->qscale); #endif /* default quantization values */ s->y_dc_scale = 8; s->c_dc_scale = 8; s->rv10_first_dc_coded[0] = 0; s->rv10_first_dc_coded[1] = 0; s->rv10_first_dc_coded[2] = 0; if(s->mb_y==0) s->first_slice_line=1; s->block_wrap[0]= s->block_wrap[1]= s->block_wrap[2]= s->block_wrap[3]= s->mb_width*2 + 2; s->block_wrap[4]= s->block_wrap[5]= s->mb_width + 2; ff_init_block_index(s); /* decode each macroblock */ for(i=0;i<mb_count;i++) { ff_update_block_index(s); #ifdef DEBUG printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); #endif s->dsp.clear_blocks(s->block[0]); s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; if (ff_h263_decode_mb(s, s->block) == SLICE_ERROR) { fprintf(stderr, "ERROR at MB %d %d\n", s->mb_x, s->mb_y); return -1; } MPV_decode_mb(s, s->block); if (++s->mb_x == s->mb_width) { s->mb_x = 0; s->mb_y++; ff_init_block_index(s); s->first_slice_line=0; } } return buf_size; }
11,764
qemu
758e8e38eb582e3dc87fd55a1d234c25108a7b7f
0
static int local_setuid(FsContext *ctx, uid_t uid) { struct passwd *pw; gid_t groups[33]; int ngroups; static uid_t cur_uid = -1; if (cur_uid == uid) { return 0; } if (setreuid(0, 0)) { return -1; } pw = getpwuid(uid); if (pw == NULL) { return -1; } ngroups = 33; if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups) == -1) { return -1; } if (setgroups(ngroups, groups)) { return -1; } if (setregid(-1, pw->pw_gid)) { return -1; } if (setreuid(-1, uid)) { return -1; } cur_uid = uid; return 0; }
11,765
qemu
568c73a4783cd981e9aa6de4f15dcda7829643ad
0
static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, InputEvent *evt) { PS2KbdState *s = (PS2KbdState *)dev; int scancodes[3], i, count; qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); count = qemu_input_key_value_to_scancode(evt->key->key, evt->key->down, scancodes); for (i = 0; i < count; i++) { ps2_put_keycode(s, scancodes[i]); } }
11,766
qemu
801f70445293ec8ed2d78fd92313c2f71fa48ac9
0
static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, uint16_t *refcount_table, int refcount_table_size, int64_t l2_offset, int check_copied) { BDRVQcowState *s = bs->opaque; uint64_t *l2_table, l2_entry; int i, l2_size, nb_csectors, refcount; /* Read L2 table from disk */ l2_size = s->l2_size * sizeof(uint64_t); l2_table = g_malloc(l2_size); if (bdrv_pread(bs->file, l2_offset, l2_table, l2_size) != l2_size) goto fail; /* Do the actual checks */ for(i = 0; i < s->l2_size; i++) { l2_entry = be64_to_cpu(l2_table[i]); switch (qcow2_get_cluster_type(l2_entry)) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters don't have QCOW_OFLAG_COPIED */ if (l2_entry & QCOW_OFLAG_COPIED) { fprintf(stderr, "ERROR: cluster %" PRId64 ": " "copied flag must never be set for compressed " "clusters\n", l2_entry >> s->cluster_bits); l2_entry &= ~QCOW_OFLAG_COPIED; res->corruptions++; } /* Mark cluster as used */ nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; l2_entry &= s->cluster_offset_mask; inc_refcounts(bs, res, refcount_table, refcount_table_size, l2_entry & ~511, nb_csectors * 512); break; case QCOW2_CLUSTER_ZERO: if ((l2_entry & L2E_OFFSET_MASK) == 0) { break; } /* fall through */ case QCOW2_CLUSTER_NORMAL: { /* QCOW_OFLAG_COPIED must be set iff refcount == 1 */ uint64_t offset = l2_entry & L2E_OFFSET_MASK; if (check_copied) { refcount = get_refcount(bs, offset >> s->cluster_bits); if (refcount < 0) { fprintf(stderr, "Can't get refcount for offset %" PRIx64 ": %s\n", l2_entry, strerror(-refcount)); goto fail; } if ((refcount == 1) != ((l2_entry & QCOW_OFLAG_COPIED) != 0)) { fprintf(stderr, "ERROR OFLAG_COPIED: offset=%" PRIx64 " refcount=%d\n", l2_entry, refcount); res->corruptions++; } } /* Mark cluster as used */ inc_refcounts(bs, res, refcount_table,refcount_table_size, offset, s->cluster_size); /* Correct offsets are cluster aligned */ if (offset & (s->cluster_size - 1)) { fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not " "properly aligned; L2 entry corrupted.\n", offset); res->corruptions++; } break; } case QCOW2_CLUSTER_UNALLOCATED: break; default: abort(); } } g_free(l2_table); return 0; fail: fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); g_free(l2_table); return -EIO; }
11,767
qemu
4b1b1c896fb38d435f3d350c44b1bdc8b56600a4
0
uint32_t qemu_devtree_alloc_phandle(void *fdt) { static int phandle = 0x8000; return phandle++; }
11,768
qemu
d0cc2fbfa607678866475383c508be84818ceb64
0
int event_notifier_init(EventNotifier *e, int active) { #ifdef CONFIG_EVENTFD int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) return -errno; e->fd = fd; return 0; #else return -ENOSYS; #endif }
11,769
qemu
30fd3e27907dfd1c0c66cc1339657af1a2ce1d4b
0
static ssize_t qio_channel_socket_readv(QIOChannel *ioc, const struct iovec *iov, size_t niov, int **fds, size_t *nfds, Error **errp) { QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); ssize_t ret; struct msghdr msg = { NULL, }; char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; int sflags = 0; memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); #ifdef MSG_CMSG_CLOEXEC sflags |= MSG_CMSG_CLOEXEC; #endif msg.msg_iov = (struct iovec *)iov; msg.msg_iovlen = niov; if (fds && nfds) { msg.msg_control = control; msg.msg_controllen = sizeof(control); } retry: ret = recvmsg(sioc->fd, &msg, sflags); if (ret < 0) { if (socket_error() == EAGAIN || socket_error() == EWOULDBLOCK) { return QIO_CHANNEL_ERR_BLOCK; } if (socket_error() == EINTR) { goto retry; } error_setg_errno(errp, socket_error(), "Unable to read from socket"); return -1; } if (fds && nfds) { qio_channel_socket_copy_fds(&msg, fds, nfds); } return ret; }
11,770
qemu
f090c9d4ad5812fb92843d6470a1111c15190c4c
0
float32 float32_sqrt( float32 a STATUS_PARAM ) { flag aSign; int16 aExp, zExp; bits32 aSig, zSig; bits64 rem, term; aSig = extractFloat32Frac( a ); aExp = extractFloat32Exp( a ); aSign = extractFloat32Sign( a ); if ( aExp == 0xFF ) { if ( aSig ) return propagateFloat32NaN( a, 0 STATUS_VAR ); if ( ! aSign ) return a; float_raise( float_flag_invalid STATUS_VAR); return float32_default_nan; } if ( aSign ) { if ( ( aExp | aSig ) == 0 ) return a; float_raise( float_flag_invalid STATUS_VAR); return float32_default_nan; } if ( aExp == 0 ) { if ( aSig == 0 ) return 0; normalizeFloat32Subnormal( aSig, &aExp, &aSig ); } zExp = ( ( aExp - 0x7F )>>1 ) + 0x7E; aSig = ( aSig | 0x00800000 )<<8; zSig = estimateSqrt32( aExp, aSig ) + 2; if ( ( zSig & 0x7F ) <= 5 ) { if ( zSig < 2 ) { zSig = 0x7FFFFFFF; goto roundAndPack; } aSig >>= aExp & 1; term = ( (bits64) zSig ) * zSig; rem = ( ( (bits64) aSig )<<32 ) - term; while ( (sbits64) rem < 0 ) { --zSig; rem += ( ( (bits64) zSig )<<1 ) | 1; } zSig |= ( rem != 0 ); } shift32RightJamming( zSig, 1, &zSig ); roundAndPack: return roundAndPackFloat32( 0, zExp, zSig STATUS_VAR ); }
11,771
qemu
6a32f80f056b577d275268e4f6f3477ba721c94f
0
static void xhci_port_update(XHCIPort *port, int is_detach) { port->portsc = PORTSC_PP; if (port->uport->dev && port->uport->dev->attached && !is_detach && (1 << port->uport->dev->speed) & port->speedmask) { port->portsc |= PORTSC_CCS; switch (port->uport->dev->speed) { case USB_SPEED_LOW: port->portsc |= PORTSC_SPEED_LOW; break; case USB_SPEED_FULL: port->portsc |= PORTSC_SPEED_FULL; break; case USB_SPEED_HIGH: port->portsc |= PORTSC_SPEED_HIGH; break; case USB_SPEED_SUPER: port->portsc |= PORTSC_SPEED_SUPER; break; } } if (xhci_running(port->xhci)) { port->portsc |= PORTSC_CSC; XHCIEvent ev = { ER_PORT_STATUS_CHANGE, CC_SUCCESS, port->portnr << 24}; xhci_event(port->xhci, &ev, 0); DPRINTF("xhci: port change event for port %d\n", port->portnr); } }
11,772
qemu
41a2b9596c9ed2a827e16e749632752dd2686647
0
static void ide_atapi_cmd_ok(IDEState *s) { s->error = 0; s->status = READY_STAT; s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD; ide_set_irq(s); }
11,773
qemu
6886867e9880830d735d8ae6f6cc63ed9eb2be0c
0
static void notdirty_mem_write(void *opaque, hwaddr ram_addr, uint64_t val, unsigned size) { if (!cpu_physical_memory_get_dirty_flag(ram_addr, DIRTY_MEMORY_CODE)) { tb_invalidate_phys_page_fast(ram_addr, size); } switch (size) { case 1: stb_p(qemu_get_ram_ptr(ram_addr), val); break; case 2: stw_p(qemu_get_ram_ptr(ram_addr), val); break; case 4: stl_p(qemu_get_ram_ptr(ram_addr), val); break; default: abort(); } cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_MIGRATION); cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_VGA); /* we remove the notdirty callback only if the code has been flushed */ if (!cpu_physical_memory_is_clean(ram_addr)) { CPUArchState *env = current_cpu->env_ptr; tlb_set_dirty(env, current_cpu->mem_io_vaddr); } }
11,774
FFmpeg
2aab7c2dfaca4386c38e5d565cd2bf73096bcc86
0
void ff_put_h264_qpel16_mc13_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_hv_qrt_16w_msa(src + stride - 2, src - (stride * 2), stride, dst, stride, 16); }
11,775
qemu
245f7b51c0ea04fb2224b1127430a096c91aee70
0
static void tight_palette_rgb2buf(uint32_t rgb, int bpp, uint8_t buf[6]) { memset(buf, 0, 6); if (bpp == 32) { buf[0] = ((rgb >> 24) & 0xFF); buf[1] = ((rgb >> 16) & 0xFF); buf[2] = ((rgb >> 8) & 0xFF); buf[3] = ((rgb >> 0) & 0xFF); buf[4] = ((buf[0] & 1) == 0) << 3 | ((buf[1] & 1) == 0) << 2; buf[4]|= ((buf[2] & 1) == 0) << 1 | ((buf[3] & 1) == 0) << 0; buf[0] |= 1; buf[1] |= 1; buf[2] |= 1; buf[3] |= 1; } if (bpp == 16) { buf[0] = ((rgb >> 8) & 0xFF); buf[1] = ((rgb >> 0) & 0xFF); buf[2] = ((buf[0] & 1) == 0) << 1 | ((buf[1] & 1) == 0) << 0; buf[0] |= 1; buf[1] |= 1; } }
11,776
qemu
3d575329a53ad3b72b07cea0d8f97ccc000df6ff
0
void vmexit(uint64_t exit_code, uint64_t exit_info_1) { uint32_t int_ctl; if (loglevel & CPU_LOG_TB_IN_ASM) fprintf(logfile,"vmexit(%016" PRIx64 ", %016" PRIx64 ", %016" PRIx64 ", " TARGET_FMT_lx ")!\n", exit_code, exit_info_1, ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2)), EIP); if(env->hflags & HF_INHIBIT_IRQ_MASK) { stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_state), SVM_INTERRUPT_SHADOW_MASK); env->hflags &= ~HF_INHIBIT_IRQ_MASK; } else { stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_state), 0); } /* Save the VM state in the vmcb */ SVM_SAVE_SEG(env->vm_vmcb, segs[R_ES], es); SVM_SAVE_SEG(env->vm_vmcb, segs[R_CS], cs); SVM_SAVE_SEG(env->vm_vmcb, segs[R_SS], ss); SVM_SAVE_SEG(env->vm_vmcb, segs[R_DS], ds); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.base), env->gdt.base); stl_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.limit), env->gdt.limit); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.base), env->idt.base); stl_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.limit), env->idt.limit); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.efer), env->efer); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr0), env->cr[0]); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr2), env->cr[2]); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr3), env->cr[3]); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr4), env->cr[4]); if ((int_ctl = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl))) & V_INTR_MASKING_MASK) { int_ctl &= ~V_TPR_MASK; int_ctl |= env->cr[8] & V_TPR_MASK; stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), int_ctl); } stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rflags), compute_eflags()); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rip), env->eip); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rsp), ESP); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rax), EAX); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr7), env->dr[7]); stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr6), env->dr[6]); stb_phys(env->vm_vmcb + offsetof(struct vmcb, save.cpl), env->hflags & HF_CPL_MASK); /* Reload the host state from vm_hsave */ env->hflags &= ~HF_HIF_MASK; env->intercept = 0; env->intercept_exceptions = 0; env->interrupt_request &= ~CPU_INTERRUPT_VIRQ; env->gdt.base = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.base)); env->gdt.limit = ldl_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.limit)); env->idt.base = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.base)); env->idt.limit = ldl_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.limit)); cpu_x86_update_cr0(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr0)) | CR0_PE_MASK); cpu_x86_update_cr4(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr4))); cpu_x86_update_cr3(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr3))); if (int_ctl & V_INTR_MASKING_MASK) env->cr[8] = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr8)); /* we need to set the efer after the crs so the hidden flags get set properly */ #ifdef TARGET_X86_64 env->efer = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.efer)); env->hflags &= ~HF_LMA_MASK; if (env->efer & MSR_EFER_LMA) env->hflags |= HF_LMA_MASK; #endif env->eflags = 0; load_eflags(ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rflags)), ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK)); CC_OP = CC_OP_EFLAGS; SVM_LOAD_SEG(env->vm_hsave, ES, es); SVM_LOAD_SEG(env->vm_hsave, CS, cs); SVM_LOAD_SEG(env->vm_hsave, SS, ss); SVM_LOAD_SEG(env->vm_hsave, DS, ds); EIP = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rip)); ESP = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rsp)); EAX = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rax)); env->dr[6] = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr6)); env->dr[7] = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr7)); /* other setups */ cpu_x86_set_cpl(env, 0); stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_code_hi), (uint32_t)(exit_code >> 32)); stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_code), exit_code); stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_1), exit_info_1); helper_clgi(); /* FIXME: Resets the current ASID register to zero (host ASID). */ /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ /* Clears the TSC_OFFSET inside the processor. */ /* If the host is in PAE mode, the processor reloads the host's PDPEs from the page table indicated the host's CR3. If the PDPEs contain illegal state, the processor causes a shutdown. */ /* Forces CR0.PE = 1, RFLAGS.VM = 0. */ env->cr[0] |= CR0_PE_MASK; env->eflags &= ~VM_MASK; /* Disables all breakpoints in the host DR7 register. */ /* Checks the reloaded host state for consistency. */ /* If the host's rIP reloaded by #VMEXIT is outside the limit of the host's code segment or non-canonical (in the case of long mode), a #GP fault is delivered inside the host.) */ /* remove any pending exception */ env->exception_index = -1; env->error_code = 0; env->old_exception = -1; regs_to_env(); cpu_loop_exit(); }
11,777
qemu
24ac07dec7f23c58dc48aa7754f872781b386d46
0
static void slirp_smb_cleanup(SlirpState *s) { char cmd[128]; int ret; if (s->smb_dir[0] != '\0') { snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir); ret = system(cmd); if (!WIFEXITED(ret)) { qemu_error("'%s' failed.\n", cmd); } else if (WEXITSTATUS(ret)) { qemu_error("'%s' failed. Error code: %d\n", cmd, WEXITSTATUS(ret)); } s->smb_dir[0] = '\0'; } }
11,778
qemu
5fb6c7a8b26eab1a22207d24b4784bd2b39ab54b
0
static uint8_t read_u8(uint8_t *data, size_t offset) { return data[offset]; }
11,779
qemu
fc22118d9bb56ec71655b936a29513c140e6c289
0
static ssize_t local_lgetxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size) { if ((ctx->fs_sm == SM_MAPPED) && (strncmp(name, "user.virtfs.", 12) == 0)) { /* * Don't allow fetch of user.virtfs namesapce * in case of mapped security */ errno = ENOATTR; return -1; } return lgetxattr(rpath(ctx, path), name, value, size); }
11,780
qemu
40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4
1
static int rtc_start_timer(struct qemu_alarm_timer *t) { int rtc_fd; unsigned long current_rtc_freq = 0; TFR(rtc_fd = open("/dev/rtc", O_RDONLY)); if (rtc_fd < 0) return -1; ioctl(rtc_fd, RTC_IRQP_READ, &current_rtc_freq); if (current_rtc_freq != RTC_FREQ && ioctl(rtc_fd, RTC_IRQP_SET, RTC_FREQ) < 0) { fprintf(stderr, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n" "error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n" "type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n"); goto fail; } if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) { fail: close(rtc_fd); return -1; } enable_sigio_timer(rtc_fd); t->priv = (void *)(long)rtc_fd; return 0; }
11,782
FFmpeg
ccff9da62a833238db7a22eb39be0814f522c2c5
0
static void h261_encode_motion(H261Context * h, int val){ MpegEncContext * const s = &h->s; int sign, code; if(val==0){ code = 0; put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); } else{ if(val > 16) val -=32; if(val < -16) val+=32; sign = val < 0; code = sign ? -val : val; put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); put_bits(&s->pb,1,sign); } }
11,783
FFmpeg
c27328e749ff3be648411765cd17362fee017341
1
static inline int parse_command_line(AVFormatContext *s, const char *line, int linelen, char *uri, int urisize, char *method, int methodsize, enum RTSPMethod *methodcode) { RTSPState *rt = s->priv_data; const char *linept, *searchlinept; linept = strchr(line, ' '); if (linept - line > methodsize - 1) { av_log(s, AV_LOG_ERROR, "Method string too long\n"); return AVERROR(EIO); } memcpy(method, line, linept - line); method[linept - line] = '\0'; linept++; if (!strcmp(method, "ANNOUNCE")) *methodcode = ANNOUNCE; else if (!strcmp(method, "OPTIONS")) *methodcode = OPTIONS; else if (!strcmp(method, "RECORD")) *methodcode = RECORD; else if (!strcmp(method, "SETUP")) *methodcode = SETUP; else if (!strcmp(method, "PAUSE")) *methodcode = PAUSE; else if (!strcmp(method, "TEARDOWN")) *methodcode = TEARDOWN; else *methodcode = UNKNOWN; /* Check method with the state */ if (rt->state == RTSP_STATE_IDLE) { if ((*methodcode != ANNOUNCE) && (*methodcode != OPTIONS)) { av_log(s, AV_LOG_ERROR, "Unexpected command in Idle State %s\n", line); return AVERROR_PROTOCOL_NOT_FOUND; } } else if (rt->state == RTSP_STATE_PAUSED) { if ((*methodcode != OPTIONS) && (*methodcode != RECORD) && (*methodcode != SETUP)) { av_log(s, AV_LOG_ERROR, "Unexpected command in Paused State %s\n", line); return AVERROR_PROTOCOL_NOT_FOUND; } } else if (rt->state == RTSP_STATE_STREAMING) { if ((*methodcode != PAUSE) && (*methodcode != OPTIONS) && (*methodcode != TEARDOWN)) { av_log(s, AV_LOG_ERROR, "Unexpected command in Streaming State" " %s\n", line); return AVERROR_PROTOCOL_NOT_FOUND; } } else { av_log(s, AV_LOG_ERROR, "Unexpected State [%d]\n", rt->state); return AVERROR_BUG; } searchlinept = strchr(linept, ' '); if (!searchlinept) { av_log(s, AV_LOG_ERROR, "Error parsing message URI\n"); } if (searchlinept - linept > urisize - 1) { av_log(s, AV_LOG_ERROR, "uri string length exceeded buffer size\n"); return AVERROR(EIO); } memcpy(uri, linept, searchlinept - linept); uri[searchlinept - linept] = '\0'; if (strcmp(rt->control_uri, uri)) { char host[128], path[512], auth[128]; int port; char ctl_host[128], ctl_path[512], ctl_auth[128]; int ctl_port; av_url_split(NULL, 0, auth, sizeof(auth), host, sizeof(host), &port, path, sizeof(path), uri); av_url_split(NULL, 0, ctl_auth, sizeof(ctl_auth), ctl_host, sizeof(ctl_host), &ctl_port, ctl_path, sizeof(ctl_path), rt->control_uri); if (strcmp(host, ctl_host)) av_log(s, AV_LOG_INFO, "Host %s differs from expected %s\n", host, ctl_host); if (strcmp(path, ctl_path) && *methodcode != SETUP) av_log(s, AV_LOG_WARNING, "WARNING: Path %s differs from expected" " %s\n", path, ctl_path); if (*methodcode == ANNOUNCE) { av_log(s, AV_LOG_INFO, "Updating control URI to %s\n", uri); av_strlcpy(rt->control_uri, uri, sizeof(rt->control_uri)); } } linept = searchlinept + 1; if (!av_strstart(linept, "RTSP/1.0", NULL)) { av_log(s, AV_LOG_ERROR, "Error parsing protocol or version\n"); return AVERROR_PROTOCOL_NOT_FOUND; } return 0; }
11,784
qemu
ef397e88e96d4a798bd190bcd0c43865c3725ae2
1
void ppc40x_core_reset (CPUState *env) { target_ulong dbsr; printf("Reset PowerPC core\n"); cpu_ppc_reset(env); dbsr = env->spr[SPR_40x_DBSR]; dbsr &= ~0x00000300; dbsr |= 0x00000100; env->spr[SPR_40x_DBSR] = dbsr; cpu_loop_exit(); }
11,785
qemu
e58d695e6c3a5cfa0aa2fc91b87ade017ef28b05
1
void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { v->type_any(v, name, obj, errp); }
11,786
qemu
536eeea86905237953a7c05c2fa2a3d1f3cba328
1
void error_vprepend(Error **errp, const char *fmt, va_list ap) { GString *newmsg; if (!errp) { return; } newmsg = g_string_new(NULL); g_string_vprintf(newmsg, fmt, ap); g_string_append(newmsg, (*errp)->msg); (*errp)->msg = g_string_free(newmsg, 0); }
11,787
FFmpeg
aac46e088d67a390489af686b846dea4987d8ffb
0
static void autocorrelate(const float x[40][2], float phi[3][2][2], int lag) { int i; float real_sum = 0.0f; float imag_sum = 0.0f; if (lag) { for (i = 1; i < 38; i++) { real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1]; imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0]; } phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1]; phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0]; if (lag == 1) { phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1]; phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0]; } } else { for (i = 1; i < 38; i++) { real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1]; } phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1]; phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1]; } }
11,788
FFmpeg
2aab7c2dfaca4386c38e5d565cd2bf73096bcc86
0
void ff_put_h264_qpel4_mc11_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_hv_qrt_4w_msa(src - 2, src - (stride * 2), stride, dst, stride, 4); }
11,789
FFmpeg
a7f6bfdc185a04a703bedd712ee306435372af12
0
static void lowpass_line_complex_c(uint8_t *dstp, ptrdiff_t linesize, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref) { const uint8_t *srcp_above = srcp + mref; const uint8_t *srcp_below = srcp + pref; const uint8_t *srcp_above2 = srcp + mref * 2; const uint8_t *srcp_below2 = srcp + pref * 2; int i; for (i = 0; i < linesize; i++) { // this calculation is an integer representation of // '0.75 * current + 0.25 * above + 0.25 * below - 0.125 * above2 - 0.125 * below2' // '4 +' is for rounding. dstp[i] = av_clip_uint8((4 + (srcp[i] << 2) + ((srcp[i] + srcp_above[i] + srcp_below[i]) << 1) - srcp_above2[i] - srcp_below2[i]) >> 3); } }
11,790
FFmpeg
662234a9a22f1cd0f0ac83b8bb1ffadedca90c0a
0
static void avc_luma_midv_qrt_and_aver_dst_4w_msa(const uint8_t *src, int32_t src_stride, uint8_t *dst, int32_t dst_stride, int32_t height, uint8_t ver_offset) { int32_t loop_cnt; int32_t out0, out1; v16i8 src0, src1, src2, src3, src4; v16u8 dst0, dst1; v16i8 mask0, mask1, mask2; v8i16 hz_out0, hz_out1, hz_out2, hz_out3; v8i16 hz_out4, hz_out5, hz_out6; v8i16 res0, res1, res2, res3; v16u8 vec0, vec1; LD_SB3(&luma_mask_arr[48], 16, mask0, mask1, mask2); LD_SB5(src, src_stride, src0, src1, src2, src3, src4); src += (5 * src_stride); XORI_B5_128_SB(src0, src1, src2, src3, src4); hz_out0 = AVC_XOR_VSHF_B_AND_APPLY_6TAP_HORIZ_FILT_SH(src0, src1, mask0, mask1, mask2); hz_out2 = AVC_XOR_VSHF_B_AND_APPLY_6TAP_HORIZ_FILT_SH(src2, src3, mask0, mask1, mask2); PCKOD_D2_SH(hz_out0, hz_out0, hz_out2, hz_out2, hz_out1, hz_out3); hz_out4 = AVC_HORZ_FILTER_SH(src4, mask0, mask1, mask2); for (loop_cnt = (height >> 1); loop_cnt--;) { LD_SB2(src, src_stride, src0, src1); src += (2 * src_stride); XORI_B2_128_SB(src0, src1); LD_UB2(dst, dst_stride, dst0, dst1); hz_out5 = AVC_XOR_VSHF_B_AND_APPLY_6TAP_HORIZ_FILT_SH(src0, src1, mask0, mask1, mask2); hz_out6 = (v8i16) __msa_pckod_d((v2i64) hz_out5, (v2i64) hz_out5); res0 = AVC_CALC_DPADD_H_6PIX_2COEFF_R_SH(hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5); res2 = AVC_CALC_DPADD_H_6PIX_2COEFF_R_SH(hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6); if (ver_offset) { res1 = __msa_srari_h(hz_out3, 5); res3 = __msa_srari_h(hz_out4, 5); } else { res1 = __msa_srari_h(hz_out2, 5); res3 = __msa_srari_h(hz_out3, 5); } SAT_SH2_SH(res1, res3, 7); res0 = __msa_aver_s_h(res0, res1); res1 = __msa_aver_s_h(res2, res3); vec0 = PCKEV_XORI128_UB(res0, res0); vec1 = PCKEV_XORI128_UB(res1, res1); AVER_UB2_UB(vec0, dst0, vec1, dst1, dst0, dst1); out0 = __msa_copy_u_w((v4i32) dst0, 0); out1 = __msa_copy_u_w((v4i32) dst1, 0); SW(out0, dst); dst += dst_stride; SW(out1, dst); dst += dst_stride; hz_out0 = hz_out2; hz_out1 = hz_out3; hz_out2 = hz_out4; hz_out3 = hz_out5; hz_out4 = hz_out6; } }
11,791
FFmpeg
05db409c280acc22362c2e79ea67abe3873043a5
0
static int vc1t_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = s->pb; AVStream *st; int fps, frames; frames = get_le24(pb); if(get_byte(pb) != 0xC5 || get_le32(pb) != 4) return -1; /* init video codec */ st = av_new_stream(s, 0); if (!st) return -1; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_WMV3; st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); st->codec->extradata_size = VC1_EXTRADATA_SIZE; get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); st->codec->height = get_le32(pb); st->codec->width = get_le32(pb); if(get_le32(pb) != 0xC) return -1; url_fskip(pb, 8); fps = get_le32(pb); if(fps == -1) av_set_pts_info(st, 32, 1, 1000); else{ av_set_pts_info(st, 24, 1, fps); st->duration = frames; } return 0; }
11,792
FFmpeg
49e617f9565b6528fe707bae7ea4b62b10c771a5
0
static void filter_line_c(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode) { int x; uint8_t *prev2 = parity ? prev : cur ; uint8_t *next2 = parity ? cur : next; for (x = 0; x < w; x++) { int c = cur[mrefs]; int d = (prev2[0] + next2[0])>>1; int e = cur[prefs]; int temporal_diff0 = FFABS(prev2[0] - next2[0]); int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); int spatial_pred = (c+e)>>1; int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; #define CHECK(j)\ { int score = FFABS(cur[mrefs-1+j] - cur[prefs-1-j])\ + FFABS(cur[mrefs +j] - cur[prefs -j])\ + FFABS(cur[mrefs+1+j] - cur[prefs+1-j]);\ if (score < spatial_score) {\ spatial_score= score;\ spatial_pred= (cur[mrefs +j] + cur[prefs -j])>>1;\ CHECK(-1) CHECK(-2) }} }}
11,794
FFmpeg
03cef34aa66662e2ab3681d290e7c5a6634f4058
0
static void qsv_uninit(AVCodecContext *s) { InputStream *ist = s->opaque; QSVContext *qsv = ist->hwaccel_ctx; av_freep(&qsv->ost->enc_ctx->hwaccel_context); av_freep(&s->hwaccel_context); av_buffer_unref(&qsv->opaque_surfaces_buf); av_freep(&qsv->surface_used); av_freep(&qsv->surface_ptrs); av_freep(&qsv); }
11,796
FFmpeg
1e46c63eb72be752e044ba32257d77f35cbd9dac
1
int avformat_write_header(AVFormatContext *s, AVDictionary **options) { int ret = 0, i; AVStream *st; AVDictionary *tmp = NULL; AVCodecContext *codec = NULL; AVOutputFormat *of = s->oformat; if (options) av_dict_copy(&tmp, *options, 0); if ((ret = av_opt_set_dict(s, &tmp)) < 0) goto fail; // some sanity checks if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) { av_log(s, AV_LOG_ERROR, "no streams\n"); ret = AVERROR(EINVAL); goto fail; } for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; codec = st->codec; switch (codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if (codec->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "sample rate not set\n"); ret = AVERROR(EINVAL); goto fail; } if (!codec->block_align) codec->block_align = codec->channels * av_get_bits_per_sample(codec->codec_id) >> 3; break; case AVMEDIA_TYPE_VIDEO: if (codec->time_base.num <= 0 || codec->time_base.den <= 0) { //FIXME audio too? av_log(s, AV_LOG_ERROR, "time base not set\n"); ret = AVERROR(EINVAL); goto fail; } if ((codec->width <= 0 || codec->height <= 0) && !(of->flags & AVFMT_NODIMENSIONS)) { av_log(s, AV_LOG_ERROR, "dimensions not set\n"); ret = AVERROR(EINVAL); goto fail; } if (av_cmp_q(st->sample_aspect_ratio, codec->sample_aspect_ratio)) { av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer " "(%d/%d) and encoder layer (%d/%d)\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den); ret = AVERROR(EINVAL); goto fail; } break; } if (of->codec_tag) { if (codec->codec_tag && codec->codec_id == AV_CODEC_ID_RAWVIDEO && !av_codec_get_tag(of->codec_tag, codec->codec_id) && !validate_codec_tag(s, st)) { // the current rawvideo encoding system ends up setting // the wrong codec_tag for avi, we override it here codec->codec_tag = 0; } if (codec->codec_tag) { if (!validate_codec_tag(s, st)) { char tagbuf[32]; av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag); av_log(s, AV_LOG_ERROR, "Tag %s/0x%08x incompatible with output codec id '%d'\n", tagbuf, codec->codec_tag, codec->codec_id); ret = AVERROR_INVALIDDATA; goto fail; } } else codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id); } if (of->flags & AVFMT_GLOBALHEADER && !(codec->flags & CODEC_FLAG_GLOBAL_HEADER)) av_log(s, AV_LOG_WARNING, "Codec for stream %d does not use global headers " "but container format requires global headers\n", i); } if (!s->priv_data && of->priv_data_size > 0) { s->priv_data = av_mallocz(of->priv_data_size); if (!s->priv_data) { ret = AVERROR(ENOMEM); goto fail; } if (of->priv_class) { *(const AVClass **)s->priv_data = of->priv_class; av_opt_set_defaults(s->priv_data); if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) goto fail; } } /* set muxer identification string */ if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0); } if (s->oformat->write_header) { ret = s->oformat->write_header(s); if (ret < 0) goto fail; } /* init PTS generation */ for (i = 0; i < s->nb_streams; i++) { int64_t den = AV_NOPTS_VALUE; st = s->streams[i]; switch (st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: den = (int64_t)st->time_base.num * st->codec->sample_rate; break; case AVMEDIA_TYPE_VIDEO: den = (int64_t)st->time_base.num * st->codec->time_base.den; break; default: break; } if (den != AV_NOPTS_VALUE) { if (den <= 0) { ret = AVERROR_INVALIDDATA; goto fail; } frac_init(&st->pts, 0, 0, den); } } if (options) { av_dict_free(options); *options = tmp; } return 0; fail: av_dict_free(&tmp); return ret; }
11,797
FFmpeg
c8cfbc6629c1fe5755b59a3bcfd95ad08b843a07
1
static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length) { int ret, i; ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->sei, &s->is_nalff, &s->nal_length_size, s->avctx->err_recognition, s->apply_defdispwin, s->avctx); if (ret < 0) return ret; /* export stream parameters from the first SPS */ for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { if (s->ps.sps_list[i]) { const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; export_stream_params(s->avctx, &s->ps, sps); break; } } return 0; }
11,798
FFmpeg
7f526efd17973ec6d2204f7a47b6923e2be31363
1
void palette8torgb15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette) { unsigned i; for(i=0; i<num_pixels; i++) ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ]; }
11,799
qemu
0479097859372a760843ad1b9c6ed3705c6423ca
1
static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) { return host_memory_backend_get_memory(dimm->hostmem, &error_abort); }
11,800
qemu
d9bce9d99f4656ae0b0127f7472db9067b8f84ab
1
PPC_OP(subfic) { T0 = PARAM(1) + ~T0 + 1; if (T0 <= PARAM(1)) { xer_ca = 1; } else { xer_ca = 0; } RETURN(); }
11,801
FFmpeg
6e42e6c4b410dbef8b593c2d796a5dad95f89ee4
1
static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, uint8_t *dst, long width, long height, long srcStride1, long srcStride2, long srcStride3, long dstStride) { long y,x,w,h; w=width/2; h=height; for(y=0;y<h;y++){ const uint8_t* yp=src1+srcStride1*y; const uint8_t* up=src2+srcStride2*(y>>2); const uint8_t* vp=src3+srcStride3*(y>>2); uint8_t* d=dst+dstStride*y; x=0; #ifdef HAVE_MMX for(;x<w-7;x+=8) { asm volatile( PREFETCH" 32(%1, %0)\n\t" PREFETCH" 32(%2, %0)\n\t" PREFETCH" 32(%3, %0)\n\t" "movq (%1, %0, 4), %%mm0\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */ "movq (%2, %0), %%mm1\n\t" /* U0U1U2U3U4U5U6U7 */ "movq (%3, %0), %%mm2\n\t" /* V0V1V2V3V4V5V6V7 */ "movq %%mm0, %%mm3\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */ "movq %%mm1, %%mm4\n\t" /* U0U1U2U3U4U5U6U7 */ "movq %%mm2, %%mm5\n\t" /* V0V1V2V3V4V5V6V7 */ "punpcklbw %%mm1, %%mm1\n\t" /* U0U0 U1U1 U2U2 U3U3 */ "punpcklbw %%mm2, %%mm2\n\t" /* V0V0 V1V1 V2V2 V3V3 */ "punpckhbw %%mm4, %%mm4\n\t" /* U4U4 U5U5 U6U6 U7U7 */ "punpckhbw %%mm5, %%mm5\n\t" /* V4V4 V5V5 V6V6 V7V7 */ "movq %%mm1, %%mm6\n\t" "punpcklbw %%mm2, %%mm1\n\t" /* U0V0 U0V0 U1V1 U1V1*/ "punpcklbw %%mm1, %%mm0\n\t" /* Y0U0 Y1V0 Y2U0 Y3V0*/ "punpckhbw %%mm1, %%mm3\n\t" /* Y4U1 Y5V1 Y6U1 Y7V1*/ MOVNTQ" %%mm0, (%4, %0, 8)\n\t" MOVNTQ" %%mm3, 8(%4, %0, 8)\n\t" "punpckhbw %%mm2, %%mm6\n\t" /* U2V2 U2V2 U3V3 U3V3*/ "movq 8(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm6, %%mm0\n\t" /* Y U2 Y V2 Y U2 Y V2*/ "punpckhbw %%mm6, %%mm3\n\t" /* Y U3 Y V3 Y U3 Y V3*/ MOVNTQ" %%mm0, 16(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 24(%4, %0, 8)\n\t" "movq %%mm4, %%mm6\n\t" "movq 16(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm5, %%mm4\n\t" "punpcklbw %%mm4, %%mm0\n\t" /* Y U4 Y V4 Y U4 Y V4*/ "punpckhbw %%mm4, %%mm3\n\t" /* Y U5 Y V5 Y U5 Y V5*/ MOVNTQ" %%mm0, 32(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 40(%4, %0, 8)\n\t" "punpckhbw %%mm5, %%mm6\n\t" "movq 24(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm6, %%mm0\n\t" /* Y U6 Y V6 Y U6 Y V6*/ "punpckhbw %%mm6, %%mm3\n\t" /* Y U7 Y V7 Y U7 Y V7*/ MOVNTQ" %%mm0, 48(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 56(%4, %0, 8)\n\t" : "+r" (x) : "r"(yp), "r" (up), "r"(vp), "r"(d) :"memory"); } #endif for(; x<w; x++) { const long x2= x<<2; d[8*x+0]=yp[x2]; d[8*x+1]=up[x]; d[8*x+2]=yp[x2+1]; d[8*x+3]=vp[x]; d[8*x+4]=yp[x2+2]; d[8*x+5]=up[x]; d[8*x+6]=yp[x2+3]; d[8*x+7]=vp[x]; } } #ifdef HAVE_MMX asm( EMMS" \n\t" SFENCE" \n\t" ::: "memory" ); #endif }
11,802
qemu
02c4f26b1517d9e403ec10d6f6ca3c0276d19e43
1
static int nvme_init(PCIDevice *pci_dev) { NvmeCtrl *n = NVME(pci_dev); NvmeIdCtrl *id = &n->id_ctrl; int i; int64_t bs_size; uint8_t *pci_conf; if (!(n->conf.bs)) { return -1; } bs_size = bdrv_getlength(n->conf.bs); if (bs_size < 0) { return -1; } blkconf_serial(&n->conf, &n->serial); if (!n->serial) { return -1; } pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] = 1; pci_config_set_prog_interface(pci_dev->config, 0x2); pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS); pcie_endpoint_cap_init(&n->parent_obj, 0x80); n->num_namespaces = 1; n->num_queues = 64; n->reg_size = 1 << qemu_fls(0x1004 + 2 * (n->num_queues + 1) * 4); n->ns_size = bs_size / (uint64_t)n->num_namespaces; n->namespaces = g_malloc0(sizeof(*n->namespaces)*n->num_namespaces); n->sq = g_malloc0(sizeof(*n->sq)*n->num_queues); n->cq = g_malloc0(sizeof(*n->cq)*n->num_queues); memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", n->reg_size); pci_register_bar(&n->parent_obj, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, &n->iomem); msix_init_exclusive_bar(&n->parent_obj, n->num_queues, 4); id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID)); id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID)); strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' '); strpadcpy((char *)id->fr, sizeof(id->fr), "1.0", ' '); strpadcpy((char *)id->sn, sizeof(id->sn), n->serial, ' '); id->rab = 6; id->ieee[0] = 0x00; id->ieee[1] = 0x02; id->ieee[2] = 0xb3; id->oacs = cpu_to_le16(0); id->frmw = 7 << 1; id->lpa = 1 << 0; id->sqes = (0x6 << 4) | 0x6; id->cqes = (0x4 << 4) | 0x4; id->nn = cpu_to_le32(n->num_namespaces); id->psd[0].mp = cpu_to_le16(0x9c4); id->psd[0].enlat = cpu_to_le32(0x10); id->psd[0].exlat = cpu_to_le32(0x4); n->bar.cap = 0; NVME_CAP_SET_MQES(n->bar.cap, 0x7ff); NVME_CAP_SET_CQR(n->bar.cap, 1); NVME_CAP_SET_AMS(n->bar.cap, 1); NVME_CAP_SET_TO(n->bar.cap, 0xf); NVME_CAP_SET_CSS(n->bar.cap, 1); n->bar.vs = 0x00010001; n->bar.intmc = n->bar.intms = 0; for (i = 0; i < n->num_namespaces; i++) { NvmeNamespace *ns = &n->namespaces[i]; NvmeIdNs *id_ns = &ns->id_ns; id_ns->nsfeat = 0; id_ns->nlbaf = 0; id_ns->flbas = 0; id_ns->mc = 0; id_ns->dpc = 0; id_ns->dps = 0; id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; id_ns->ncap = id_ns->nuse = id_ns->nsze = cpu_to_le64(n->ns_size >> id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); } return 0; }
11,803
qemu
bea60dd7679364493a0d7f5b54316c767cf894ef
1
static void send_ext_audio_ack(VncState *vs) { vnc_lock_output(vs); vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE); vnc_write_u8(vs, 0); vnc_write_u16(vs, 1); vnc_framebuffer_update(vs, 0, 0, surface_width(vs->vd->ds), surface_height(vs->vd->ds), VNC_ENCODING_AUDIO); vnc_unlock_output(vs); vnc_flush(vs); }
11,804
qemu
39ac8455106af1ed669b8e10223420cf1ac5b190
1
target_ulong spapr_hypercall(CPUState *env, target_ulong opcode, target_ulong *args) { if (msr_pr) { hcall_dprintf("Hypercall made with MSR[PR]=1\n"); return H_PRIVILEGE; } if ((opcode <= MAX_HCALL_OPCODE) && ((opcode & 0x3) == 0)) { spapr_hcall_fn fn = hypercall_table[opcode / 4]; if (fn) { return fn(env, spapr, opcode, args); } } hcall_dprintf("Unimplemented hcall 0x" TARGET_FMT_lx "\n", opcode); return H_FUNCTION; }
11,805
qemu
9ed5726c043958359b0f1fa44ab3e4f25f9d9a47
1
target_ulong helper_emt(target_ulong arg1) { // TODO arg1 = 0; // rt = arg1 return arg1; }
11,807
FFmpeg
c780b543e72141393ae3c0b0cb2654f9a5e35f73
1
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) { ID3v2ExtraMeta *current = *extra_meta, *next; void (*free_func)(ID3v2ExtraMeta*); while (current) { if ((free_func = get_extra_meta_func(current->tag, 1)->free)) free_func(current->data); next = current->next; av_freep(&current); current = next; } }
11,808
qemu
77cb0f5aafc8e6d0c6d3c339f381c9b7921648e0
1
static int adb_mouse_request(ADBDevice *d, uint8_t *obuf, const uint8_t *buf, int len) { MouseState *s = ADB_MOUSE(d); int cmd, reg, olen; if ((buf[0] & 0x0f) == ADB_FLUSH) { /* flush mouse fifo */ s->buttons_state = s->last_buttons_state; s->dx = 0; s->dy = 0; s->dz = 0; return 0; } cmd = buf[0] & 0xc; reg = buf[0] & 0x3; olen = 0; switch(cmd) { case ADB_WRITEREG: ADB_DPRINTF("write reg %d val 0x%2.2x\n", reg, buf[1]); switch(reg) { case 2: break; case 3: switch(buf[2]) { case ADB_CMD_SELF_TEST: break; case ADB_CMD_CHANGE_ID: case ADB_CMD_CHANGE_ID_AND_ACT: case ADB_CMD_CHANGE_ID_AND_ENABLE: d->devaddr = buf[1] & 0xf; break; default: d->devaddr = buf[1] & 0xf; /* we support handlers: * 0x01: Classic Apple Mouse Protocol / 100 cpi operations * 0x02: Classic Apple Mouse Protocol / 200 cpi operations * we don't support handlers (at least): * 0x03: Mouse systems A3 trackball * 0x04: Extended Apple Mouse Protocol * 0x2f: Microspeed mouse * 0x42: Macally * 0x5f: Microspeed mouse * 0x66: Microspeed mouse */ if (buf[2] == 1 || buf[2] == 2) { d->handler = buf[2]; } break; } } break; case ADB_READREG: switch(reg) { case 0: olen = adb_mouse_poll(d, obuf); break; case 1: break; case 3: obuf[0] = d->handler; obuf[1] = d->devaddr; olen = 2; break; } ADB_DPRINTF("read reg %d obuf[0] 0x%2.2x obuf[1] 0x%2.2x\n", reg, obuf[0], obuf[1]); break; } return olen; }
11,809
qemu
6630886863d4a9b3b7bcb3b0e2895d83eb269c75
1
static int net_init_nic(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ int idx; NICInfo *nd; const NetLegacyNicOptions *nic; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_NIC); nic = opts->nic; 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 (nic->has_netdev) { nd->netdev = qemu_find_netdev(nic->netdev); if (!nd->netdev) { error_report("netdev '%s' not found", nic->netdev); return -1; } } else { assert(peer); nd->netdev = peer; } nd->name = g_strdup(name); if (nic->has_model) { nd->model = g_strdup(nic->model); } if (nic->has_addr) { nd->devaddr = g_strdup(nic->addr); } if (nic->has_macaddr && net_parse_macaddr(nd->macaddr.a, nic->macaddr) < 0) { error_report("invalid syntax for ethernet address"); return -1; } if (nic->has_macaddr && is_multicast_ether_addr(nd->macaddr.a)) { error_report("NIC cannot have multicast MAC address (odd 1st byte)"); return -1; } qemu_macaddr_default_if_unset(&nd->macaddr); if (nic->has_vectors) { if (nic->vectors > 0x7ffffff) { error_report("invalid # of vectors: %"PRIu32, nic->vectors); return -1; } nd->nvectors = nic->vectors; } else { nd->nvectors = DEV_NVECTORS_UNSPECIFIED; } nd->used = 1; nb_nics++; return idx; }
11,811
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
void migrate_del_blocker(Error *reason) { migration_blockers = g_slist_remove(migration_blockers, reason); }
11,812
qemu
107e4b352cc309f9bd7588ef1a44549200620078
1
char *desc_get_buf(DescInfo *info, bool read_only) { PCIDevice *dev = PCI_DEVICE(info->ring->r); size_t size = read_only ? le16_to_cpu(info->desc.tlv_size) : le16_to_cpu(info->desc.buf_size); if (size > info->buf_size) { info->buf = g_realloc(info->buf, size); info->buf_size = size; } if (!info->buf) { return NULL; } pci_dma_read(dev, le64_to_cpu(info->desc.buf_addr), info->buf, size); return info->buf; }
11,814
qemu
e0d9c6f93729c9bfc98fcafcd73098bb8e131aeb
1
int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, int64_t sector_num, int nb_sectors) { int n1; if ((sector_num + nb_sectors) <= bs->total_sectors) return nb_sectors; if (sector_num >= bs->total_sectors) n1 = 0; else n1 = bs->total_sectors - sector_num; qemu_iovec_memset(qiov, 0, 512 * (nb_sectors - n1)); return n1; }
11,815
qemu
eb513f82f04fab442cdef9db698dafc852275f7f
1
void helper_stqf(CPUSPARCState *env, target_ulong addr, int mem_idx) { /* XXX add 128 bit store */ CPU_QuadU u; helper_check_align(env, addr, 7); #if !defined(CONFIG_USER_ONLY) switch (mem_idx) { case MMU_USER_IDX: u.q = QT0; cpu_stq_user(env, addr, u.ll.upper); cpu_stq_user(env, addr + 8, u.ll.lower); break; case MMU_KERNEL_IDX: u.q = QT0; cpu_stq_kernel(env, addr, u.ll.upper); cpu_stq_kernel(env, addr + 8, u.ll.lower); break; #ifdef TARGET_SPARC64 case MMU_HYPV_IDX: u.q = QT0; cpu_stq_hypv(env, addr, u.ll.upper); cpu_stq_hypv(env, addr + 8, u.ll.lower); break; #endif default: DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx); break; } #else u.q = QT0; stq_raw(address_mask(env, addr), u.ll.upper); stq_raw(address_mask(env, addr + 8), u.ll.lower); #endif }
11,816
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int get_uint64(QEMUFile *f, void *pv, size_t size) { uint64_t *v = pv; qemu_get_be64s(f, v); return 0; }
11,817