project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
qemu
338c858c946017cd3ec8c2be06d817e001d94bc3
0
long do_sigreturn(CPUAlphaState *env) { struct target_sigcontext *sc; abi_ulong sc_addr = env->ir[IR_A0]; target_sigset_t target_set; sigset_t set; if (!lock_user_struct(VERIFY_READ, sc, sc_addr, 1)) { goto badframe; } target_sigemptyset(&target_set); __get_user(target_set.sig[0], &sc->sc_mask); target_to_host_sigset_internal(&set, &target_set); do_sigprocmask(SIG_SETMASK, &set, NULL); restore_sigcontext(env, sc); unlock_user_struct(sc, sc_addr, 0); return env->ir[IR_V0]; badframe: force_sig(TARGET_SIGSEGV); }
26,253
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
0
static bool ide_sect_range_ok(IDEState *s, uint64_t sector, uint64_t nb_sectors) { uint64_t total_sectors; bdrv_get_geometry(s->bs, &total_sectors); if (sector > total_sectors || nb_sectors > total_sectors - sector) { return false; } return true; }
26,254
qemu
384acbf46b70edf0d2c1648aa1a92a90bcf7057d
0
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int n) { int ret = -EINPROGRESS; async_context_push(); qed_write_l1_table(s, index, n, qed_sync_cb, &ret); while (ret == -EINPROGRESS) { qemu_aio_wait(); } async_context_pop(); return ret; }
26,255
qemu
ec05ec26f940564b1e07bf88857035ec27e21dd8
0
bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size, unsigned client) { assert(mr->terminates); return cpu_physical_memory_get_dirty(mr->ram_addr + addr, size, client); }
26,256
qemu
52cfcb464255b4da5115408e2a6ce3327bbcb9df
0
static void filter_mirror_setup(NetFilterState *nf, Error **errp) { MirrorState *s = FILTER_MIRROR(nf); if (!s->outdev) { error_setg(errp, "filter filter mirror needs 'outdev' " "property set"); return; } s->chr_out = qemu_chr_find(s->outdev); if (s->chr_out == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", s->outdev); return; } if (qemu_chr_fe_claim(s->chr_out) != 0) { error_setg(errp, QERR_DEVICE_IN_USE, s->outdev); return; } }
26,258
qemu
8297be80f7cf71e09617669a8bd8b2836dcfd4c3
0
static void generate_eeprom_spd(uint8_t *eeprom, ram_addr_t ram_size) { enum { SDR = 0x4, DDR2 = 0x8 } type; uint8_t *spd = spd_eeprom.contents; uint8_t nbanks = 0; uint16_t density = 0; int i; /* work in terms of MB */ ram_size >>= 20; while ((ram_size >= 4) && (nbanks <= 2)) { int sz_log2 = MIN(31 - clz32(ram_size), 14); nbanks++; density |= 1 << (sz_log2 - 2); ram_size -= 1 << sz_log2; } /* split to 2 banks if possible */ if ((nbanks == 1) && (density > 1)) { nbanks++; density >>= 1; } if (density & 0xff00) { density = (density & 0xe0) | ((density >> 8) & 0x1f); type = DDR2; } else if (!(density & 0x1f)) { type = DDR2; } else { type = SDR; } if (ram_size) { fprintf(stderr, "Warning: SPD cannot represent final %dMB" " of SDRAM\n", (int)ram_size); } /* fill in SPD memory information */ spd[2] = type; spd[5] = nbanks; spd[31] = density; /* checksum */ spd[63] = 0; for (i = 0; i < 63; i++) { spd[63] += spd[i]; } /* copy for SMBUS */ memcpy(eeprom, spd, sizeof(spd_eeprom.contents)); }
26,260
qemu
a0efbf16604770b9d805bcf210ec29942321134f
0
static GenericList *next_list(Visitor *v, GenericList *tail, size_t size) { StringInputVisitor *siv = to_siv(v); Range *r; if (!siv->ranges || !siv->cur_range) { return NULL; } r = siv->cur_range->data; if (!r) { return NULL; } if (siv->cur < r->begin || siv->cur >= r->end) { siv->cur_range = g_list_next(siv->cur_range); if (!siv->cur_range) { return NULL; } r = siv->cur_range->data; if (!r) { return NULL; } siv->cur = r->begin; } tail->next = g_malloc0(size); return tail->next; }
26,261
FFmpeg
aff01de6415f1ba022f1a58e354ad6e4d0796e97
0
static int link_filter_inouts(AVFilterContext *filt_ctx, AVFilterInOut **curr_inputs, AVFilterInOut **open_inputs, void *log_ctx) { int pad, ret; for (pad = 0; pad < filt_ctx->input_count; pad++) { AVFilterInOut *p = *curr_inputs; if (p) *curr_inputs = (*curr_inputs)->next; else if (!(p = av_mallocz(sizeof(*p)))) return AVERROR(ENOMEM); if (p->filter_ctx) { if ((ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx)) < 0) return ret; av_free(p->name); av_free(p); } else { p->filter_ctx = filt_ctx; p->pad_idx = pad; append_inout(open_inputs, &p); } } if (*curr_inputs) { av_log(log_ctx, AV_LOG_ERROR, "Too many inputs specified for the \"%s\" filter.\n", filt_ctx->filter->name); return AVERROR(EINVAL); } pad = filt_ctx->output_count; while (pad--) { AVFilterInOut *currlinkn = av_mallocz(sizeof(AVFilterInOut)); if (!currlinkn) return AVERROR(ENOMEM); currlinkn->filter_ctx = filt_ctx; currlinkn->pad_idx = pad; insert_inout(curr_inputs, currlinkn); } return 0; }
26,262
qemu
49dfcec40349245ad365964468b67e132c3cedc7
0
static void invalidate_and_set_dirty(hwaddr addr, hwaddr length) { if (cpu_physical_memory_range_includes_clean(addr, length)) { tb_invalidate_phys_range(addr, addr + length, 0); cpu_physical_memory_set_dirty_range_nocode(addr, length); } xen_modified_memory(addr, length); }
26,263
qemu
494a8ebe713055d3946183f4b395f85a18b43e9e
0
static int proxy_unlinkat(FsContext *ctx, V9fsPath *dir, const char *name, int flags) { int ret; V9fsString fullname; v9fs_string_init(&fullname); v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name); ret = proxy_remove(ctx, fullname.data); v9fs_string_free(&fullname); return ret; }
26,264
qemu
ad07cd69ecaffbaa015459a46975ab32e50df805
0
void virtio_scsi_common_realize(DeviceState *dev, Error **errp, VirtIOHandleOutput ctrl, VirtIOHandleOutput evt, VirtIOHandleOutput cmd) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev); int i; virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, sizeof(VirtIOSCSIConfig)); if (s->conf.num_queues == 0 || s->conf.num_queues > VIRTIO_QUEUE_MAX - 2) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), " "must be a positive integer less than %d.", s->conf.num_queues, VIRTIO_QUEUE_MAX - 2); virtio_cleanup(vdev); return; } s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues); s->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE; s->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE; s->ctrl_vq = virtio_add_queue_aio(vdev, VIRTIO_SCSI_VQ_SIZE, ctrl); s->event_vq = virtio_add_queue_aio(vdev, VIRTIO_SCSI_VQ_SIZE, evt); for (i = 0; i < s->conf.num_queues; i++) { s->cmd_vqs[i] = virtio_add_queue_aio(vdev, VIRTIO_SCSI_VQ_SIZE, cmd); } if (s->conf.iothread) { virtio_scsi_set_iothread(VIRTIO_SCSI(s), s->conf.iothread); } }
26,265
qemu
cd42d5b23691ad73edfd6dbcfc935a960a9c5a65
0
static inline void gen_intermediate_code_internal(SPARCCPU *cpu, TranslationBlock *tb, bool spc) { CPUState *cs = CPU(cpu); CPUSPARCState *env = &cpu->env; target_ulong pc_start, last_pc; uint16_t *gen_opc_end; DisasContext dc1, *dc = &dc1; CPUBreakpoint *bp; int j, lj = -1; int num_insns; int max_insns; unsigned int insn; memset(dc, 0, sizeof(DisasContext)); dc->tb = tb; pc_start = tb->pc; dc->pc = pc_start; last_pc = dc->pc; dc->npc = (target_ulong) tb->cs_base; dc->cc_op = CC_OP_DYNAMIC; dc->mem_idx = cpu_mmu_index(env); dc->def = env->def; dc->fpu_enabled = tb_fpu_enabled(tb->flags); dc->address_mask_32bit = tb_am_enabled(tb->flags); dc->singlestep = (cs->singlestep_enabled || singlestep); gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) max_insns = CF_COUNT_MASK; gen_tb_start(); do { if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { if (bp->pc == dc->pc) { if (dc->pc != pc_start) save_state(dc); gen_helper_debug(cpu_env); tcg_gen_exit_tb(0); dc->is_br = 1; goto exit_gen_loop; } } } if (spc) { qemu_log("Search PC...\n"); j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; if (lj < j) { lj++; while (lj < j) tcg_ctx.gen_opc_instr_start[lj++] = 0; tcg_ctx.gen_opc_pc[lj] = dc->pc; gen_opc_npc[lj] = dc->npc; tcg_ctx.gen_opc_instr_start[lj] = 1; tcg_ctx.gen_opc_icount[lj] = num_insns; } } if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) gen_io_start(); last_pc = dc->pc; insn = cpu_ldl_code(env, dc->pc); disas_sparc_insn(dc, insn); num_insns++; if (dc->is_br) break; /* if the next PC is different, we abort now */ if (dc->pc != (last_pc + 4)) break; /* if we reach a page boundary, we stop generation so that the PC of a TT_TFAULT exception is always in the right page */ if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0) break; /* if single step mode, we generate only one instruction and generate an exception */ if (dc->singlestep) { break; } } while ((tcg_ctx.gen_opc_ptr < gen_opc_end) && (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) && num_insns < max_insns); exit_gen_loop: if (tb->cflags & CF_LAST_IO) { gen_io_end(); } if (!dc->is_br) { if (dc->pc != DYNAMIC_PC && (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) { /* static PC and NPC: we can use direct chaining */ gen_goto_tb(dc, 0, dc->pc, dc->npc); } else { if (dc->pc != DYNAMIC_PC) { tcg_gen_movi_tl(cpu_pc, dc->pc); } save_npc(dc); tcg_gen_exit_tb(0); } } gen_tb_end(tb, num_insns); *tcg_ctx.gen_opc_ptr = INDEX_op_end; if (spc) { j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; lj++; while (lj <= j) tcg_ctx.gen_opc_instr_start[lj++] = 0; #if 0 log_page_dump(); #endif gen_opc_jump_pc[0] = dc->jump_pc[0]; gen_opc_jump_pc[1] = dc->jump_pc[1]; } else { tb->size = last_pc + 4 - pc_start; tb->icount = num_insns; } #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("--------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); log_target_disas(env, pc_start, last_pc + 4 - pc_start, 0); qemu_log("\n"); } #endif }
26,266
qemu
ef1e1e0782e99c9dcf2b35e5310cdd8ca9211374
0
static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, int *is_linux, uint8_t image_type, uint64_t (*translate_fn)(void *, uint64_t), void *translate_opaque) { int fd; int size; hwaddr address; uboot_image_header_t h; uboot_image_header_t *hdr = &h; uint8_t *data = NULL; int ret = -1; int do_uncompress = 0; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) return -1; size = read(fd, hdr, sizeof(uboot_image_header_t)); if (size < 0) goto out; bswap_uboot_header(hdr); if (hdr->ih_magic != IH_MAGIC) goto out; if (hdr->ih_type != image_type) { fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, image_type); goto out; } /* TODO: Implement other image types. */ switch (hdr->ih_type) { case IH_TYPE_KERNEL: address = hdr->ih_load; if (translate_fn) { address = translate_fn(translate_opaque, address); } if (loadaddr) { *loadaddr = hdr->ih_load; } switch (hdr->ih_comp) { case IH_COMP_NONE: break; case IH_COMP_GZIP: do_uncompress = 1; break; default: fprintf(stderr, "Unable to load u-boot images with compression type %d\n", hdr->ih_comp); goto out; } if (ep) { *ep = hdr->ih_ep; } /* TODO: Check CPU type. */ if (is_linux) { if (hdr->ih_os == IH_OS_LINUX) { *is_linux = 1; } else { *is_linux = 0; } } break; case IH_TYPE_RAMDISK: address = *loadaddr; break; default: fprintf(stderr, "Unsupported u-boot image type %d\n", hdr->ih_type); goto out; } data = g_malloc(hdr->ih_size); if (read(fd, data, hdr->ih_size) != hdr->ih_size) { fprintf(stderr, "Error reading file\n"); goto out; } if (do_uncompress) { uint8_t *compressed_data; size_t max_bytes; ssize_t bytes; compressed_data = data; max_bytes = UBOOT_MAX_GUNZIP_BYTES; data = g_malloc(max_bytes); bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size); g_free(compressed_data); if (bytes < 0) { fprintf(stderr, "Unable to decompress gzipped image!\n"); goto out; } hdr->ih_size = bytes; } rom_add_blob_fixed(filename, data, hdr->ih_size, address); ret = hdr->ih_size; out: if (data) g_free(data); close(fd); return ret; }
26,267
qemu
0ae18ceeaaa2c1749e742c4b112f6c3bf0896408
0
static void stellaris_init(const char *kernel_filename, const char *cpu_model, DisplayState *ds, stellaris_board_info *board) { static const int uart_irq[] = {5, 6, 33, 34}; static const int timer_irq[] = {19, 21, 23, 35}; static const uint32_t gpio_addr[7] = { 0x40004000, 0x40005000, 0x40006000, 0x40007000, 0x40024000, 0x40025000, 0x40026000}; static const int gpio_irq[7] = {0, 1, 2, 3, 4, 30, 31}; qemu_irq *pic; qemu_irq *gpio_in[7]; qemu_irq *gpio_out[7]; qemu_irq adc; int sram_size; int flash_size; i2c_bus *i2c; int i; flash_size = ((board->dc0 & 0xffff) + 1) << 1; sram_size = (board->dc0 >> 18) + 1; pic = armv7m_init(flash_size, sram_size, kernel_filename, cpu_model); if (board->dc1 & (1 << 16)) { adc = stellaris_adc_init(0x40038000, pic[14]); } else { adc = NULL; } for (i = 0; i < 4; i++) { if (board->dc2 & (0x10000 << i)) { stellaris_gptm_init(0x40030000 + i * 0x1000, pic[timer_irq[i]], adc); } } stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr); for (i = 0; i < 7; i++) { if (board->dc4 & (1 << i)) { gpio_in[i] = pl061_init(gpio_addr[i], pic[gpio_irq[i]], &gpio_out[i]); } } if (board->dc2 & (1 << 12)) { i2c = i2c_init_bus(); stellaris_i2c_init(0x40020000, pic[8], i2c); if (board->peripherals & BP_OLED_I2C) { ssd0303_init(ds, i2c, 0x3d); } } for (i = 0; i < 4; i++) { if (board->dc2 & (1 << i)) { pl011_init(0x4000c000 + i * 0x1000, pic[uart_irq[i]], serial_hds[i], PL011_LUMINARY); } } if (board->dc2 & (1 << 4)) { if (board->peripherals & BP_OLED_SSI) { void * oled; void * sd; void *ssi_bus; int index; oled = ssd0323_init(ds, &gpio_out[GPIO_C][7]); index = drive_get_index(IF_SD, 0, 0); sd = ssi_sd_init(drives_table[index].bdrv); ssi_bus = stellaris_ssi_bus_init(&gpio_out[GPIO_D][0], ssi_sd_xfer, sd, ssd0323_xfer_ssi, oled); pl022_init(0x40008000, pic[7], stellaris_ssi_bus_xfer, ssi_bus); /* Make sure the select pin is high. */ qemu_irq_raise(gpio_out[GPIO_D][0]); } else { pl022_init(0x40008000, pic[7], NULL, NULL); } } if (board->dc4 & (1 << 28)) { /* FIXME: Obey network model. */ stellaris_enet_init(&nd_table[0], 0x40048000, pic[42]); } if (board->peripherals & BP_GAMEPAD) { qemu_irq gpad_irq[5]; static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d }; gpad_irq[0] = qemu_irq_invert(gpio_in[GPIO_E][0]); /* up */ gpad_irq[1] = qemu_irq_invert(gpio_in[GPIO_E][1]); /* down */ gpad_irq[2] = qemu_irq_invert(gpio_in[GPIO_E][2]); /* left */ gpad_irq[3] = qemu_irq_invert(gpio_in[GPIO_E][3]); /* right */ gpad_irq[4] = qemu_irq_invert(gpio_in[GPIO_F][1]); /* select */ stellaris_gamepad_init(5, gpad_irq, gpad_keycode); } }
26,268
qemu
e3f5ec2b5e92706e3b807059f79b1fb5d936e567
0
static int pcnet_can_receive(void *opaque) { PCNetState *s = opaque; if (CSR_STOP(s) || CSR_SPND(s)) return 0; if (s->recv_pos > 0) return 0; return sizeof(s->buffer)-16; }
26,269
qemu
0e7106d8b5f7ef4f9df10baf1dfb3db482bcd046
0
static int write_object(int fd, char *buf, uint64_t oid, int copies, unsigned int datalen, uint64_t offset, bool create, bool cache) { return read_write_object(fd, buf, oid, copies, datalen, offset, true, create, cache); }
26,270
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static uint32_t cuda_readw (void *opaque, target_phys_addr_t addr) { return 0; }
26,271
qemu
4a1418e07bdcfaa3177739e04707ecaec75d89e1
0
void helper_iret_protected(int shift, int next_eip) { int tss_selector, type; uint32_t e1, e2; /* specific case for TSS */ if (env->eflags & NT_MASK) { #ifdef TARGET_X86_64 if (env->hflags & HF_LMA_MASK) raise_exception_err(EXCP0D_GPF, 0); #endif tss_selector = lduw_kernel(env->tr.base + 0); if (tss_selector & 4) raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc); if (load_segment(&e1, &e2, tss_selector) != 0) raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc); type = (e2 >> DESC_TYPE_SHIFT) & 0x17; /* NOTE: we check both segment and busy TSS */ if (type != 3) raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc); switch_tss(tss_selector, e1, e2, SWITCH_TSS_IRET, next_eip); } else { helper_ret_protected(shift, 1, 0); } env->hflags2 &= ~HF2_NMI_MASK; #ifdef CONFIG_KQEMU if (kqemu_is_ok(env)) { CC_OP = CC_OP_EFLAGS; env->exception_index = -1; cpu_loop_exit(); } #endif }
26,272
FFmpeg
6260ab60a80fd8baebf79f9ce9299b0db72333b5
0
static void blend_image_rgba(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y) { blend_image_packed_rgb(ctx, dst, src, 1, x, y, 0); }
26,273
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) { PCIBonitoState *s = opaque; PCIDevice *d = PCI_DEVICE(s); PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); uint32_t pciaddr; uint16_t status; DPRINTF("bonito_spciconf_writeb "TARGET_FMT_plx" val %x\n", addr, val); pciaddr = bonito_sbridge_pciaddr(s, addr); if (pciaddr == 0xffffffff) { return; } /* set the pci address in s->config_reg */ phb->config_reg = (pciaddr) | (1u << 31); pci_data_write(phb->bus, phb->config_reg, val & 0xff, 1); /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ status = pci_get_word(d->config + PCI_STATUS); status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); pci_set_word(d->config + PCI_STATUS, status); }
26,274
qemu
b0f49d138777fb6609aa2ea96d2c59fb872d2c2d
0
pvscsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid) { PVSCSIRequest *pvscsi_req = req->hba_private; PVSCSIState *s = pvscsi_req->dev; if (!pvscsi_req) { trace_pvscsi_command_complete_not_found(req->tag); return; } if (resid) { /* Short transfer. */ trace_pvscsi_command_complete_data_run(); pvscsi_req->cmp.hostStatus = BTSTAT_DATARUN; } pvscsi_req->cmp.scsiStatus = status; if (pvscsi_req->cmp.scsiStatus == CHECK_CONDITION) { uint8_t sense[SCSI_SENSE_BUF_SIZE]; int sense_len = scsi_req_get_sense(pvscsi_req->sreq, sense, sizeof(sense)); trace_pvscsi_command_complete_sense_len(sense_len); pvscsi_write_sense(pvscsi_req, sense, sense_len); } qemu_sglist_destroy(&pvscsi_req->sgl); pvscsi_complete_request(s, pvscsi_req); }
26,276
qemu
494a8ebe713055d3946183f4b395f85a18b43e9e
0
static int proxy_open(FsContext *ctx, V9fsPath *fs_path, int flags, V9fsFidOpenState *fs) { fs->fd = v9fs_request(ctx->private, T_OPEN, NULL, "sd", fs_path, flags); if (fs->fd < 0) { errno = -fs->fd; fs->fd = -1; } return fs->fd; }
26,277
qemu
0ae18ceeaaa2c1749e742c4b112f6c3bf0896408
0
void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { char buf[1024]; unsigned long bios_offset; int bios_size; CPUState *env; RTCState *rtc_state; int i; qemu_irq *i8259; int index; BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; /* init CPUs */ if (cpu_model == NULL) { #ifdef TARGET_MIPS64 cpu_model = "R4000"; #else cpu_model = "24Kf"; #endif } env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } qemu_register_reset(main_cpu_reset, env); /* allocate RAM */ cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); if (!mips_qemu_iomemtype) { mips_qemu_iomemtype = cpu_register_io_memory(0, mips_qemu_read, mips_qemu_write, NULL); } cpu_register_physical_memory(0x1fbf0000, 0x10000, mips_qemu_iomemtype); /* Try to load a BIOS image. If this fails, we continue regardless, but initialize the hardware ourselves. When a kernel gets preloaded we also initialize the hardware, since the BIOS wasn't run. */ bios_offset = ram_size + vga_ram_size; if (bios_name == NULL) bios_name = BIOS_FILENAME; snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); bios_size = load_image(buf, phys_ram_base + bios_offset); if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) { cpu_register_physical_memory(0x1fc00000, BIOS_SIZE, bios_offset | IO_MEM_ROM); } else if ((index = drive_get_index(IF_PFLASH, 0, 0)) > -1) { uint32_t mips_rom = 0x00400000; cpu_register_physical_memory(0x1fc00000, mips_rom, qemu_ram_alloc(mips_rom) | IO_MEM_ROM); if (!pflash_cfi01_register(0x1fc00000, qemu_ram_alloc(mips_rom), drives_table[index].bdrv, sector_len, mips_rom / sector_len, 4, 0, 0, 0, 0)) { fprintf(stderr, "qemu: Error registering flash memory.\n"); } } else { /* not fatal */ fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n", buf); } if (kernel_filename) { loaderparams.ram_size = ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename; load_kernel (env); } /* Init CPU internal devices */ cpu_mips_irq_init_cpu(env); cpu_mips_clock_init(env); /* The PIC is attached to the MIPS CPU INT0 pin */ i8259 = i8259_init(env->irq[2]); rtc_state = rtc_init(0x70, i8259[8]); /* Register 64 KB of ISA IO space at 0x14000000 */ isa_mmio_init(0x14000000, 0x00010000); isa_mem_base = 0x10000000; pit = pit_init(0x40, i8259[0]); for(i = 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_init(serial_io[i], i8259[serial_irq[i]], 115200, serial_hds[i]); } } isa_vga_init(ds, phys_ram_base + ram_size, ram_size, vga_ram_size); if (nd_table[0].vlan) { if (nd_table[i].model == NULL) { nd_table[i].model = "ne2k_isa"; } if (strcmp(nd_table[0].model, "ne2k_isa") == 0) { isa_ne2000_init(0x300, i8259[9], &nd_table[0]); } else if (strcmp(nd_table[0].model, "?") == 0) { fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n"); exit (1); } else { fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model); exit (1); } } if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { fprintf(stderr, "qemu: too many IDE bus\n"); exit(1); } for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS); if (index != -1) hd[i] = drives_table[index].bdrv; else hd[i] = NULL; } for(i = 0; i < MAX_IDE_BUS; i++) isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); i8042_init(i8259[1], i8259[12], 0x60); }
26,278
qemu
f1c52354e5bdab6983d13a4c174759c585e834b3
0
static bool spapr_drc_needed(void *opaque) { sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque; sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); bool rc = false; sPAPRDREntitySense value = drck->dr_entity_sense(drc); /* If no dev is plugged in there is no need to migrate the DRC state */ if (value != SPAPR_DR_ENTITY_SENSE_PRESENT) { return false; } /* * If there is dev plugged in, we need to migrate the DRC state when * it is different from cold-plugged state */ switch (spapr_drc_type(drc)) { case SPAPR_DR_CONNECTOR_TYPE_PCI: case SPAPR_DR_CONNECTOR_TYPE_CPU: case SPAPR_DR_CONNECTOR_TYPE_LMB: rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) && (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) && drc->configured && !drc->awaiting_release); break; case SPAPR_DR_CONNECTOR_TYPE_PHB: case SPAPR_DR_CONNECTOR_TYPE_VIO: default: g_assert_not_reached(); } return rc; }
26,279
FFmpeg
9bcbb250e23959075765edd3cb4c1fcb46736d7d
0
static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrUSrc, const int16_t *chrVSrc, const int16_t *alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) { int p= 4; const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW }; uint8_t *dst[4]= { aDest, dest, uDest, vDest }; x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW }; while (p--) { if (dst[p]) { __asm__ volatile( "mov %2, %%"REG_a" \n\t" ".p2align 4 \n\t" /* FIXME Unroll? */ "1: \n\t" "movq (%0, %%"REG_a", 2), %%mm0 \n\t" "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t" "psraw $7, %%mm0 \n\t" "psraw $7, %%mm1 \n\t" "packuswb %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%1, %%REGa)) "add $8, %%"REG_a" \n\t" "jnc 1b \n\t" :: "r" (src[p]), "r" (dst[p] + counter[p]), "g" (-counter[p]) : "%"REG_a ); } } }
26,280
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
0
static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size) { register const uint8_t* s=src; register uint8_t* d=dst; register const uint8_t *end; const uint8_t *mm_end; end = s + src_size; #if COMPILE_TEMPLATE_MMX __asm__ volatile(PREFETCH" %0"::"m"(*s)); __asm__ volatile("movq %0, %%mm4"::"m"(mask15s)); mm_end = end - 15; while (s<mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movq %1, %%mm0 \n\t" "movq 8%1, %%mm2 \n\t" "movq %%mm0, %%mm1 \n\t" "movq %%mm2, %%mm3 \n\t" "pand %%mm4, %%mm0 \n\t" "pand %%mm4, %%mm2 \n\t" "paddw %%mm1, %%mm0 \n\t" "paddw %%mm3, %%mm2 \n\t" MOVNTQ" %%mm0, %0 \n\t" MOVNTQ" %%mm2, 8%0" :"=m"(*d) :"m"(*s) ); d+=16; s+=16; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); #endif mm_end = end - 3; while (s < mm_end) { register unsigned x= *((const uint32_t *)s); *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0); d+=4; s+=4; } if (s < end) { register unsigned short x= *((const uint16_t *)s); *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0); } }
26,281
qemu
4482e05cbbb7e50e476f6a9500cf0b38913bd939
1
PowerPCCPU *ppc4xx_init(const char *cpu_model, clk_setup_t *cpu_clk, clk_setup_t *tb_clk, uint32_t sysclk) { PowerPCCPU *cpu; CPUPPCState *env; /* init CPUs */ cpu = POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model)); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC %s CPU definition\n", cpu_model); exit(1); } env = &cpu->env; cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */ cpu_clk->opaque = env; /* Set time-base frequency to sysclk */ tb_clk->cb = ppc_40x_timers_init(env, sysclk, PPC_INTERRUPT_PIT); tb_clk->opaque = env; ppc_dcr_init(env, NULL, NULL); /* Register qemu callbacks */ qemu_register_reset(ppc4xx_reset, cpu); return cpu; }
26,282
FFmpeg
9bbf1a5c232cffb64e5f8cf071d1626cc0d033e1
1
void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, int buf_size, int slice_count) { struct vdpau_render_state *render, *last, *next; int i; render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; assert(render); /* fill VdpPictureInfoMPEG1Or2 struct */ render->info.mpeg.picture_structure = s->picture_structure; render->info.mpeg.picture_coding_type = s->pict_type; render->info.mpeg.intra_dc_precision = s->intra_dc_precision; render->info.mpeg.frame_pred_frame_dct = s->frame_pred_frame_dct; render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors; render->info.mpeg.intra_vlc_format = s->intra_vlc_format; render->info.mpeg.alternate_scan = s->alternate_scan; render->info.mpeg.q_scale_type = s->q_scale_type; render->info.mpeg.top_field_first = s->top_field_first; render->info.mpeg.full_pel_forward_vector = s->full_pel[0]; // MPEG-1 only. Set 0 for MPEG-2 render->info.mpeg.full_pel_backward_vector = s->full_pel[1]; // MPEG-1 only. Set 0 for MPEG-2 render->info.mpeg.f_code[0][0] = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert. render->info.mpeg.f_code[0][1] = s->mpeg_f_code[0][1]; render->info.mpeg.f_code[1][0] = s->mpeg_f_code[1][0]; render->info.mpeg.f_code[1][1] = s->mpeg_f_code[1][1]; for (i = 0; i < 64; ++i) { render->info.mpeg.intra_quantizer_matrix[i] = s->intra_matrix[i]; render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i]; } render->info.mpeg.forward_reference = VDP_INVALID_HANDLE; render->info.mpeg.backward_reference = VDP_INVALID_HANDLE; switch(s->pict_type){ case FF_B_TYPE: next = (struct vdpau_render_state *)s->next_picture.data[0]; assert(next); render->info.mpeg.backward_reference = next->surface; // no return here, going to set forward prediction case FF_P_TYPE: last = (struct vdpau_render_state *)s->last_picture.data[0]; if (!last) // FIXME: Does this test make sense? last = render; // predict second field from the first render->info.mpeg.forward_reference = last->surface; } ff_vdpau_add_data_chunk(s, buf, buf_size); render->info.mpeg.slice_count = slice_count; if (slice_count) ff_draw_horiz_band(s, 0, s->avctx->height); render->bitstream_buffers_used = 0; }
26,283
FFmpeg
bc9eb0467a52828d6be48de5e60f042bf3b62d1f
1
static int open_input_stream(HTTPContext *c, const char *info) { char buf[128]; char input_filename[1024]; AVFormatContext *s = NULL; int buf_size, i, ret; int64_t stream_pos; /* find file name */ if (c->stream->feed) { strcpy(input_filename, c->stream->feed->feed_filename); buf_size = FFM_PACKET_SIZE; /* compute position (absolute time) */ if (av_find_info_tag(buf, sizeof(buf), "date", info)) { if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0) { http_log("Invalid date specification '%s' for stream\n", buf); return ret; } } else if (av_find_info_tag(buf, sizeof(buf), "buffer", info)) { int prebuffer = strtol(buf, 0, 10); stream_pos = av_gettime() - prebuffer * (int64_t)1000000; } else stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000; } else { strcpy(input_filename, c->stream->feed_filename); buf_size = 0; /* compute position (relative time) */ if (av_find_info_tag(buf, sizeof(buf), "date", info)) { if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0) { http_log("Invalid date specification '%s' for stream\n", buf); return ret; } } else stream_pos = 0; } if (!input_filename[0]) { http_log("No filename was specified for stream\n"); return AVERROR(EINVAL); } /* open stream */ ret = avformat_open_input(&s, input_filename, c->stream->ifmt, &c->stream->in_opts); if (ret < 0) { http_log("Could not open input '%s': %s\n", input_filename, av_err2str(ret)); return ret; } /* set buffer size */ if (buf_size > 0) { ret = ffio_set_buf_size(s->pb, buf_size); if (ret < 0) { http_log("Failed to set buffer size\n"); return ret; } } s->flags |= AVFMT_FLAG_GENPTS; c->fmt_in = s; if (strcmp(s->iformat->name, "ffm") && (ret = avformat_find_stream_info(c->fmt_in, NULL)) < 0) { http_log("Could not find stream info for input '%s'\n", input_filename); avformat_close_input(&s); return ret; } /* choose stream as clock source (we favor the video stream if * present) for packet sending */ c->pts_stream_index = 0; for(i=0;i<c->stream->nb_streams;i++) { if (c->pts_stream_index == 0 && c->stream->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { c->pts_stream_index = i; } } if (c->fmt_in->iformat->read_seek) av_seek_frame(c->fmt_in, -1, stream_pos, 0); /* set the start time (needed for maxtime and RTP packet timing) */ c->start_time = cur_time; c->first_pts = AV_NOPTS_VALUE; return 0; }
26,284
qemu
b46578555c4bce64e3daba4591334aba2d12c156
1
static int close_f(int argc, char **argv) { bdrv_close(bs); bs = NULL; return 0; }
26,285
qemu
3a3567d337d3ee6fb2e2fcc1d27cd045ed97ae9b
1
static void pty_chr_state(CharDriverState *chr, int connected) { PtyCharDriver *s = chr->opaque; if (!connected) { if (s->fd_tag) { io_remove_watch_poll(s->fd_tag); s->fd_tag = 0; } s->connected = 0; /* (re-)connect poll interval for idle guests: once per second. * We check more frequently in case the guests sends data to * the virtual device linked to our pty. */ pty_chr_rearm_timer(chr, 1000); } else { if (s->timer_tag) { g_source_remove(s->timer_tag); s->timer_tag = 0; } if (!s->connected) { qemu_chr_be_generic_open(chr); s->connected = 1; s->fd_tag = io_add_watch_poll(s->fd, pty_chr_read_poll, pty_chr_read, chr); } } }
26,286
qemu
4a94fc9bf2dac5965acb8e264d55a356737a2aa6
1
static void zynq_xadc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) { ZynqXADCState *s = (ZynqXADCState *)opaque; int reg = offset / 4; int xadc_reg; int xadc_cmd; int xadc_data; if (!zynq_xadc_check_offset(reg, false)) { qemu_log_mask(LOG_GUEST_ERROR, "zynq_xadc: Invalid write access " "to addr %" HWADDR_PRIx "\n", offset); return; } switch (reg) { case CFG: s->regs[CFG] = val; break; case INT_STS: s->regs[INT_STS] &= ~val; break; case INT_MASK: s->regs[INT_MASK] = val & INT_ALL; break; case CMDFIFO: xadc_cmd = extract32(val, 26, 4); xadc_reg = extract32(val, 16, 10); xadc_data = extract32(val, 0, 16); if (s->regs[MCTL] & MCTL_RESET) { qemu_log_mask(LOG_GUEST_ERROR, "zynq_xadc: Sending command " "while comm channel held in reset: %" PRIx32 "\n", (uint32_t) val); break; } if (xadc_reg > ZYNQ_XADC_NUM_ADC_REGS && xadc_cmd != CMD_NOP) { qemu_log_mask(LOG_GUEST_ERROR, "read/write op to invalid xadc " "reg 0x%x\n", xadc_reg); break; } switch (xadc_cmd) { case CMD_READ: xadc_push_dfifo(s, s->xadc_regs[xadc_reg]); break; case CMD_WRITE: s->xadc_regs[xadc_reg] = xadc_data; /* fallthrough */ case CMD_NOP: xadc_push_dfifo(s, 0); break; } break; case MCTL: s->regs[MCTL] = val & 0x00fffeff; break; } zynq_xadc_update_ints(s); }
26,287
qemu
d9bce9d99f4656ae0b0127f7472db9067b8f84ab
1
static inline void gen_set_Rc0 (DisasContext *ctx) { gen_op_cmpi(0); gen_op_set_Rc0(); }
26,288
qemu
a01672d3968cf91208666d371784110bfde9d4f8
1
static int kvm_log_start(CPUPhysMemoryClient *client, target_phys_addr_t phys_addr, ram_addr_t size) { return kvm_dirty_pages_log_change(phys_addr, size, true); }
26,289
qemu
fa617181839741727d0067ea68807133f498f29b
1
static int megasas_scsi_init(PCIDevice *dev) { DeviceState *d = DEVICE(dev); MegasasState *s = MEGASAS(dev); MegasasBaseClass *b = MEGASAS_DEVICE_GET_CLASS(s); uint8_t *pci_conf; int i, bar_type; Error *err = NULL; pci_conf = dev->config; /* PCI latency timer = 0 */ pci_conf[PCI_LATENCY_TIMER] = 0; /* Interrupt pin 1 */ pci_conf[PCI_INTERRUPT_PIN] = 0x01; memory_region_init_io(&s->mmio_io, OBJECT(s), &megasas_mmio_ops, s, "megasas-mmio", 0x4000); memory_region_init_io(&s->port_io, OBJECT(s), &megasas_port_ops, s, "megasas-io", 256); memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s, "megasas-queue", 0x40000); if (megasas_use_msi(s) && msi_init(dev, 0x50, 1, true, false)) { s->flags &= ~MEGASAS_MASK_USE_MSI; } if (megasas_use_msix(s) && msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000, &s->mmio_io, b->mmio_bar, 0x3800, 0x68)) { s->flags &= ~MEGASAS_MASK_USE_MSIX; } if (pci_is_express(dev)) { pcie_endpoint_cap_init(dev, 0xa0); } bar_type = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64; pci_register_bar(dev, b->ioport_bar, PCI_BASE_ADDRESS_SPACE_IO, &s->port_io); pci_register_bar(dev, b->mmio_bar, bar_type, &s->mmio_io); pci_register_bar(dev, 3, bar_type, &s->queue_io); if (megasas_use_msix(s)) { msix_vector_use(dev, 0); } s->fw_state = MFI_FWSTATE_READY; if (!s->sas_addr) { s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) | IEEE_COMPANY_LOCALLY_ASSIGNED) << 36; s->sas_addr |= (pci_bus_num(dev->bus) << 16); s->sas_addr |= (PCI_SLOT(dev->devfn) << 8); s->sas_addr |= PCI_FUNC(dev->devfn); } if (!s->hba_serial) { s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL); } if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) { s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE; } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) { s->fw_sge = 128 - MFI_PASS_FRAME_SIZE; } else { s->fw_sge = 64 - MFI_PASS_FRAME_SIZE; } if (s->fw_cmds > MEGASAS_MAX_FRAMES) { s->fw_cmds = MEGASAS_MAX_FRAMES; } trace_megasas_init(s->fw_sge, s->fw_cmds, megasas_is_jbod(s) ? "jbod" : "raid"); if (megasas_is_jbod(s)) { s->fw_luns = MFI_MAX_SYS_PDS; } else { s->fw_luns = MFI_MAX_LD; } s->producer_pa = 0; s->consumer_pa = 0; for (i = 0; i < s->fw_cmds; i++) { s->frames[i].index = i; s->frames[i].context = -1; s->frames[i].pa = 0; s->frames[i].state = s; } scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev), &megasas_scsi_info, NULL); if (!d->hotplugged) { scsi_bus_legacy_handle_cmdline(&s->bus, &err); if (err != NULL) { error_free(err); return -1; } } return 0; }
26,290
qemu
98f28ad7a7d26e5e77c5cb37b262d76d6ccd963d
1
VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf) { VirtIOBlock *s; int cylinders, heads, secs; static int virtio_blk_id; DriveInfo *dinfo; if (!conf->bs) { error_report("virtio-blk-pci: drive property not set"); s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config), sizeof(VirtIOBlock)); s->vdev.get_config = virtio_blk_update_config; s->vdev.get_features = virtio_blk_get_features; s->vdev.reset = virtio_blk_reset; s->bs = conf->bs; s->conf = conf; s->rq = NULL; s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); /* NB: per existing s/n string convention the string is terminated * by '\0' only when less than sizeof (s->sn) */ dinfo = drive_get_by_blockdev(s->bs); strncpy(s->sn, dinfo->serial, sizeof (s->sn)); s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); register_savevm(dev, "virtio-blk", virtio_blk_id++, 2, virtio_blk_save, virtio_blk_load, s); bdrv_set_removable(s->bs, 0); return &s->vdev;
26,292
qemu
5839e53bbc0fec56021d758aab7610df421ed8c8
1
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) { BDRVQcowState *s = bs->opaque; QEMUSnapshotInfo *sn_tab, *sn_info; QCowSnapshot *sn; int i; if (!s->nb_snapshots) { *psn_tab = NULL; return s->nb_snapshots; } sn_tab = g_malloc0(s->nb_snapshots * sizeof(QEMUSnapshotInfo)); for(i = 0; i < s->nb_snapshots; i++) { sn_info = sn_tab + i; sn = s->snapshots + i; pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), sn->id_str); pstrcpy(sn_info->name, sizeof(sn_info->name), sn->name); sn_info->vm_state_size = sn->vm_state_size; sn_info->date_sec = sn->date_sec; sn_info->date_nsec = sn->date_nsec; sn_info->vm_clock_nsec = sn->vm_clock_nsec; } *psn_tab = sn_tab; return s->nb_snapshots; }
26,293
FFmpeg
c23acbaed40101c677dfcfbbfe0d2c230a8e8f44
1
static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; DCTELEM *src, *dst; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; src = block; dst = block; for(i = 0; i < 8; i++){ t1 = 17 * (src[0] + src[2]) + 4; t2 = 17 * (src[0] - src[2]) + 4; t3 = 22 * src[1] + 10 * src[3]; t4 = 22 * src[3] - 10 * src[1]; dst[0] = (t1 + t3) >> 3; dst[1] = (t2 - t4) >> 3; dst[2] = (t2 + t4) >> 3; dst[3] = (t1 - t3) >> 3; src += 8; dst += 8; } src = block; for(i = 0; i < 4; i++){ t1 = 12 * (src[ 0] + src[32]) + 64; t2 = 12 * (src[ 0] - src[32]) + 64; t3 = 16 * src[16] + 6 * src[48]; t4 = 6 * src[16] - 16 * src[48]; t5 = t1 + t3; t6 = t2 + t4; t7 = t2 - t4; t8 = t1 - t3; t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56]; t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56]; t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; dest[0*linesize] = cm[dest[0*linesize] + ((t5 + t1) >> 7)]; dest[1*linesize] = cm[dest[1*linesize] + ((t6 + t2) >> 7)]; dest[2*linesize] = cm[dest[2*linesize] + ((t7 + t3) >> 7)]; dest[3*linesize] = cm[dest[3*linesize] + ((t8 + t4) >> 7)]; dest[4*linesize] = cm[dest[4*linesize] + ((t8 - t4 + 1) >> 7)]; dest[5*linesize] = cm[dest[5*linesize] + ((t7 - t3 + 1) >> 7)]; dest[6*linesize] = cm[dest[6*linesize] + ((t6 - t2 + 1) >> 7)]; dest[7*linesize] = cm[dest[7*linesize] + ((t5 - t1 + 1) >> 7)]; src ++; dest++; } }
26,295
qemu
367790cce8e14131426f5190dfd7d1bdbf656e4d
1
DISAS_INSN(shift_reg) { TCGv reg; TCGv shift; reg = DREG(insn, 0); shift = DREG(insn, 9); if (insn & 0x100) { gen_helper_shl_cc(reg, cpu_env, reg, shift); } else { if (insn & 8) { gen_helper_shr_cc(reg, cpu_env, reg, shift); } else { gen_helper_sar_cc(reg, cpu_env, reg, shift); } } set_cc_op(s, CC_OP_FLAGS); }
26,297
FFmpeg
9ccc6cecd2d0645f5073382360509eb278b239b1
1
static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx) { uint8_t *edata_ptr = avctx->extradata; unsigned int channel_mask; int i, bits; int log2_max_num_subframes; int num_possible_block_sizes; if (avctx->codec_id == AV_CODEC_ID_XMA1 || avctx->codec_id == AV_CODEC_ID_XMA2) avctx->block_align = 2048; if (!avctx->block_align) { av_log(avctx, AV_LOG_ERROR, "block_align is not set\n"); return AVERROR(EINVAL); } s->avctx = avctx; s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); if (!s->fdsp) return AVERROR(ENOMEM); init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; /** dump the extradata */ av_log(avctx, AV_LOG_DEBUG, "extradata:\n"); for (i = 0; i < avctx->extradata_size; i++) av_log(avctx, AV_LOG_DEBUG, "[%x] ", avctx->extradata[i]); av_log(avctx, AV_LOG_DEBUG, "\n"); if (avctx->codec_id == AV_CODEC_ID_XMA2 && (!avctx->extradata || avctx->extradata_size >= 6)) { s->decode_flags = 0x10d6; channel_mask = avctx->extradata ? AV_RL32(edata_ptr+2) : 0; s->bits_per_sample = 16; } else if (avctx->codec_id == AV_CODEC_ID_XMA1) { s->decode_flags = 0x10d6; s->bits_per_sample = 16; channel_mask = 0; } else if (avctx->codec_id == AV_CODEC_ID_WMAPRO && avctx->extradata_size >= 18) { s->decode_flags = AV_RL16(edata_ptr+14); channel_mask = AV_RL32(edata_ptr+2); s->bits_per_sample = AV_RL16(edata_ptr); if (s->bits_per_sample > 32 || s->bits_per_sample < 1) { avpriv_request_sample(avctx, "bits per sample is %d", s->bits_per_sample); return AVERROR_PATCHWELCOME; } } else { avpriv_request_sample(avctx, "Unknown extradata size"); return AVERROR_PATCHWELCOME; } if (avctx->codec_id != AV_CODEC_ID_WMAPRO && avctx->channels > 2) { s->nb_channels = 2; } else { s->nb_channels = avctx->channels; } /** generic init */ s->log2_frame_size = av_log2(avctx->block_align) + 4; if (s->log2_frame_size > 25) { avpriv_request_sample(avctx, "Large block align"); return AVERROR_PATCHWELCOME; } /** frame info */ if (avctx->codec_id != AV_CODEC_ID_WMAPRO) s->skip_frame = 0; else s->skip_frame = 1; /* skip first frame */ s->packet_loss = 1; s->len_prefix = (s->decode_flags & 0x40); /** get frame len */ if (avctx->codec_id == AV_CODEC_ID_WMAPRO) { bits = ff_wma_get_frame_len_bits(avctx->sample_rate, 3, s->decode_flags); if (bits > WMAPRO_BLOCK_MAX_BITS) { avpriv_request_sample(avctx, "14-bit block sizes"); return AVERROR_PATCHWELCOME; } s->samples_per_frame = 1 << bits; } else { s->samples_per_frame = 512; } /** subframe info */ log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3); s->max_num_subframes = 1 << log2_max_num_subframes; if (s->max_num_subframes == 16 || s->max_num_subframes == 4) s->max_subframe_len_bit = 1; s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1; num_possible_block_sizes = log2_max_num_subframes + 1; s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; s->dynamic_range_compression = (s->decode_flags & 0x80); if (s->max_num_subframes > MAX_SUBFRAMES) { av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %"PRId8"\n", s->max_num_subframes); return AVERROR_INVALIDDATA; } if (s->min_samples_per_subframe < WMAPRO_BLOCK_MIN_SIZE) { av_log(avctx, AV_LOG_ERROR, "min_samples_per_subframe of %d too small\n", s->min_samples_per_subframe); return AVERROR_INVALIDDATA; } if (s->avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); return AVERROR_INVALIDDATA; } if (s->nb_channels <= 0) { av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->nb_channels); return AVERROR_INVALIDDATA; } else if (s->nb_channels > WMAPRO_MAX_CHANNELS) { avpriv_request_sample(avctx, "More than %d channels", WMAPRO_MAX_CHANNELS); return AVERROR_PATCHWELCOME; } /** init previous block len */ for (i = 0; i < s->nb_channels; i++) s->channel[i].prev_block_len = s->samples_per_frame; /** extract lfe channel position */ s->lfe_channel = -1; if (channel_mask & 8) { unsigned int mask; for (mask = 1; mask < 16; mask <<= 1) { if (channel_mask & mask) ++s->lfe_channel; } } INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE, scale_huffbits, 1, 1, scale_huffcodes, 2, 2, 616); INIT_VLC_STATIC(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE, scale_rl_huffbits, 1, 1, scale_rl_huffcodes, 4, 4, 1406); INIT_VLC_STATIC(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE, coef0_huffbits, 1, 1, coef0_huffcodes, 4, 4, 2108); INIT_VLC_STATIC(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE, coef1_huffbits, 1, 1, coef1_huffcodes, 4, 4, 3912); INIT_VLC_STATIC(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE, vec4_huffbits, 1, 1, vec4_huffcodes, 2, 2, 604); INIT_VLC_STATIC(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE, vec2_huffbits, 1, 1, vec2_huffcodes, 2, 2, 562); INIT_VLC_STATIC(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE, vec1_huffbits, 1, 1, vec1_huffcodes, 2, 2, 562); /** calculate number of scale factor bands and their offsets for every possible block size */ for (i = 0; i < num_possible_block_sizes; i++) { int subframe_len = s->samples_per_frame >> i; int x; int band = 1; int rate = get_rate(avctx); s->sfb_offsets[i][0] = 0; for (x = 0; x < MAX_BANDS-1 && s->sfb_offsets[i][band - 1] < subframe_len; x++) { int offset = (subframe_len * 2 * critical_freq[x]) / rate + 2; offset &= ~3; if (offset > s->sfb_offsets[i][band - 1]) s->sfb_offsets[i][band++] = offset; if (offset >= subframe_len) break; } s->sfb_offsets[i][band - 1] = subframe_len; s->num_sfb[i] = band - 1; if (s->num_sfb[i] <= 0) { av_log(avctx, AV_LOG_ERROR, "num_sfb invalid\n"); return AVERROR_INVALIDDATA; } } /** Scale factors can be shared between blocks of different size as every block has a different scale factor band layout. The matrix sf_offsets is needed to find the correct scale factor. */ for (i = 0; i < num_possible_block_sizes; i++) { int b; for (b = 0; b < s->num_sfb[i]; b++) { int x; int offset = ((s->sfb_offsets[i][b] + s->sfb_offsets[i][b + 1] - 1) << i) >> 1; for (x = 0; x < num_possible_block_sizes; x++) { int v = 0; while (s->sfb_offsets[x][v + 1] << x < offset) { v++; av_assert0(v < MAX_BANDS); } s->sf_offsets[i][x][b] = v; } } } /** init MDCT, FIXME: only init needed sizes */ for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) ff_mdct_init(&s->mdct_ctx[i], WMAPRO_BLOCK_MIN_BITS+1+i, 1, 1.0 / (1 << (WMAPRO_BLOCK_MIN_BITS + i - 1)) / (1 << (s->bits_per_sample - 1))); /** init MDCT windows: simple sine window */ for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) { const int win_idx = WMAPRO_BLOCK_MAX_BITS - i; ff_init_ff_sine_windows(win_idx); s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx]; } /** calculate subwoofer cutoff values */ for (i = 0; i < num_possible_block_sizes; i++) { int block_size = s->samples_per_frame >> i; int cutoff = (440*block_size + 3LL * (s->avctx->sample_rate >> 1) - 1) / s->avctx->sample_rate; s->subwoofer_cutoffs[i] = av_clip(cutoff, 4, block_size); } /** calculate sine values for the decorrelation matrix */ for (i = 0; i < 33; i++) sin64[i] = sin(i*M_PI / 64.0); if (avctx->debug & FF_DEBUG_BITSTREAM) dump_context(s); avctx->channel_layout = channel_mask; return 0; }
26,298
qemu
b4ba67d9a702507793c2724e56f98e9b0f7be02b
1
static uint16_t qvirtio_pci_get_queue_size(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; return qpci_io_readw(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_NUM); }
26,299
qemu
92196b2f5664d5defa778b1b24df56e2239b5e93
1
int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count) { int ret; ret = bdrv_pwrite(bs, offset, buf, count); if (ret < 0) { return ret; } /* No flush needed for cache=writethrough, it uses O_DSYNC */ if ((bs->open_flags & BDRV_O_CACHE_MASK) != 0) { bdrv_flush(bs); } return 0; }
26,301
FFmpeg
b8b8e82ea14016b2cb04b49ecea57f836e6ee7f8
1
static void dnxhd_decode_dct_block_8(const DNXHDContext *ctx, RowContext *row, int n) { dnxhd_decode_dct_block(ctx, row, n, 4, 32, 6); }
26,302
FFmpeg
386601286fed2dff5e1955bc21a0256f6f35ab19
1
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) { unsigned int first_mb_in_slice; unsigned int pps_id; int ret; unsigned int slice_type, tmp, i, j; int last_pic_structure, last_pic_droppable; int must_reinit; int needs_reinit = 0; int field_pic_flag, bottom_field_flag; int first_slice = sl == h->slice_ctx && !h->current_slice; int frame_num, picture_structure, droppable; PPS *pps; h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab; h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab; first_mb_in_slice = get_ue_golomb_long(&sl->gb); if (first_mb_in_slice == 0) { // FIXME better field boundary detection if (h->current_slice) { if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) { ff_h264_field_end(h, sl, 1); h->current_slice = 0; } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == NAL_IDR_SLICE) { av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n"); ff_h264_field_end(h, sl, 1); h->current_slice = 0; ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); h->cur_pic_ptr = NULL; } else return AVERROR_INVALIDDATA; } if (!h->first_field) { if (h->cur_pic_ptr && !h->droppable) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, h->picture_structure == PICT_BOTTOM_FIELD); } h->cur_pic_ptr = NULL; } } slice_type = get_ue_golomb_31(&sl->gb); if (slice_type > 9) { av_log(h->avctx, AV_LOG_ERROR, "slice type %d too large at %d\n", slice_type, first_mb_in_slice); return AVERROR_INVALIDDATA; } if (slice_type > 4) { slice_type -= 5; sl->slice_type_fixed = 1; } else sl->slice_type_fixed = 0; slice_type = golomb_to_pict_type[slice_type]; sl->slice_type = slice_type; sl->slice_type_nos = slice_type & 3; if (h->nal_unit_type == NAL_IDR_SLICE && sl->slice_type_nos != AV_PICTURE_TYPE_I) { av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); return AVERROR_INVALIDDATA; } if ( (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE) || h->avctx->skip_frame >= AVDISCARD_ALL) { return SLICE_SKIPED; } // to make a few old functions happy, it's wrong though h->pict_type = sl->slice_type; pps_id = get_ue_golomb(&sl->gb); if (pps_id >= MAX_PPS_COUNT) { av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); return AVERROR_INVALIDDATA; } if (!h->pps_buffers[pps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id); return AVERROR_INVALIDDATA; } if (h->au_pps_id >= 0 && pps_id != h->au_pps_id) { av_log(h->avctx, AV_LOG_ERROR, "PPS change from %d to %d forbidden\n", h->au_pps_id, pps_id); return AVERROR_INVALIDDATA; } pps = h->pps_buffers[pps_id]; if (!h->sps_buffers[pps->sps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id); return AVERROR_INVALIDDATA; } if (first_slice) h->pps = *h->pps_buffers[pps_id]; if (pps->sps_id != h->sps.sps_id || pps->sps_id != h->current_sps_id || h->sps_buffers[pps->sps_id]->new) { if (!first_slice) { av_log(h->avctx, AV_LOG_ERROR, "SPS changed in the middle of the frame\n"); return AVERROR_INVALIDDATA; } h->sps = *h->sps_buffers[h->pps.sps_id]; if (h->mb_width != h->sps.mb_width || h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) || h->cur_bit_depth_luma != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc ) needs_reinit = 1; if (h->bit_depth_luma != h->sps.bit_depth_luma || h->chroma_format_idc != h->sps.chroma_format_idc) { h->bit_depth_luma = h->sps.bit_depth_luma; h->chroma_format_idc = h->sps.chroma_format_idc; needs_reinit = 1; } if ((ret = ff_h264_set_parameter_from_sps(h)) < 0) return ret; } h->avctx->profile = ff_h264_get_profile(&h->sps); h->avctx->level = h->sps.level_idc; h->avctx->refs = h->sps.ref_frame_count; must_reinit = (h->context_initialized && ( 16*h->sps.mb_width != h->avctx->coded_width || 16*h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) != h->avctx->coded_height || h->cur_bit_depth_luma != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc || h->mb_width != h->sps.mb_width || h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) )); if (h->avctx->pix_fmt == AV_PIX_FMT_NONE || (non_j_pixfmt(h->avctx->pix_fmt) != non_j_pixfmt(get_pixel_format(h, 0)))) must_reinit = 1; if (first_slice && av_cmp_q(h->sps.sar, h->avctx->sample_aspect_ratio)) must_reinit = 1; h->mb_width = h->sps.mb_width; h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->mb_num = h->mb_width * h->mb_height; h->mb_stride = h->mb_width + 1; h->b_stride = h->mb_width * 4; h->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p h->width = 16 * h->mb_width; h->height = 16 * h->mb_height; ret = init_dimensions(h); if (ret < 0) return ret; if (h->sps.video_signal_type_present_flag) { h->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if (h->sps.colour_description_present_flag) { if (h->avctx->colorspace != h->sps.colorspace) needs_reinit = 1; h->avctx->color_primaries = h->sps.color_primaries; h->avctx->color_trc = h->sps.color_trc; h->avctx->colorspace = h->sps.colorspace; } } if (h->context_initialized && (must_reinit || needs_reinit)) { if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "changing width %d -> %d / height %d -> %d on " "slice %d\n", h->width, h->avctx->coded_width, h->height, h->avctx->coded_height, h->current_slice + 1); return AVERROR_INVALIDDATA; } av_assert1(first_slice); ff_h264_flush_change(h); if ((ret = get_pixel_format(h, 1)) < 0) return ret; h->avctx->pix_fmt = ret; av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, " "pix_fmt: %s\n", h->width, h->height, av_get_pix_fmt_name(h->avctx->pix_fmt)); if ((ret = h264_slice_header_init(h, 1)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (!h->context_initialized) { if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); return AVERROR_PATCHWELCOME; } if ((ret = get_pixel_format(h, 1)) < 0) return ret; h->avctx->pix_fmt = ret; if ((ret = h264_slice_header_init(h, 0)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (first_slice && h->dequant_coeff_pps != pps_id) { h->dequant_coeff_pps = pps_id; ff_h264_init_dequant_tables(h); } frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num); if (!first_slice) { if (h->frame_num != frame_num) { av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n", h->frame_num, frame_num); return AVERROR_INVALIDDATA; } } sl->mb_mbaff = 0; h->mb_aff_frame = 0; last_pic_structure = h->picture_structure; last_pic_droppable = h->droppable; droppable = h->nal_ref_idc == 0; if (h->sps.frame_mbs_only_flag) { picture_structure = PICT_FRAME; } else { if (!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) { av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); return -1; } field_pic_flag = get_bits1(&sl->gb); if (field_pic_flag) { bottom_field_flag = get_bits1(&sl->gb); picture_structure = PICT_TOP_FIELD + bottom_field_flag; } else { picture_structure = PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } if (h->current_slice) { if (last_pic_structure != picture_structure || last_pic_droppable != droppable) { av_log(h->avctx, AV_LOG_ERROR, "Changing field mode (%d -> %d) between slices is not allowed\n", last_pic_structure, h->picture_structure); return AVERROR_INVALIDDATA; } else if (!h->cur_pic_ptr) { av_log(h->avctx, AV_LOG_ERROR, "unset cur_pic_ptr on slice %d\n", h->current_slice + 1); return AVERROR_INVALIDDATA; } } h->picture_structure = picture_structure; h->droppable = droppable; h->frame_num = frame_num; sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; if (h->current_slice == 0) { /* Shorten frame num gaps so we don't have to allocate reference * frames just to throw them away */ if (h->frame_num != h->prev_frame_num) { int unwrap_prev_frame_num = h->prev_frame_num; int max_frame_num = 1 << h->sps.log2_max_frame_num; if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num; if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) { unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1; if (unwrap_prev_frame_num < 0) unwrap_prev_frame_num += max_frame_num; h->prev_frame_num = unwrap_prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * Here, we're using that to see if we should mark previously * decode frames as "finished". * We have to do that before the "dummy" in-between frame allocation, * since that can modify h->cur_pic_ptr. */ if (h->first_field) { assert(h->cur_pic_ptr); assert(h->cur_pic_ptr->f.buf[0]); assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); /* Mark old field/frame as completed */ if (h->cur_pic_ptr->tf.owner == h->avctx) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_BOTTOM_FIELD); } /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ if (last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { if (h->cur_pic_ptr->frame_num != h->frame_num) { /* This and previous field were reference, but had * different frame_nums. Consider this field first in * pair. Throw away previous field except for reference * purposes. */ if (last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { /* Second field in complementary pair */ if (!((last_pic_structure == PICT_TOP_FIELD && h->picture_structure == PICT_BOTTOM_FIELD) || (last_pic_structure == PICT_BOTTOM_FIELD && h->picture_structure == PICT_TOP_FIELD))) { av_log(h->avctx, AV_LOG_ERROR, "Invalid field mode combination %d/%d\n", last_pic_structure, h->picture_structure); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; } else if (last_pic_droppable != h->droppable) { avpriv_request_sample(h->avctx, "Found reference and non-reference fields in the same frame, which"); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_PATCHWELCOME; } } } } while (h->frame_num != h->prev_frame_num && !h->first_field && h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) { H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); if (!h->sps.gaps_in_frame_num_allowed_flag) for(i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++) h->last_pocs[i] = INT_MIN; ret = h264_frame_start(h); if (ret < 0) { h->first_field = 0; return ret; } h->prev_frame_num++; h->prev_frame_num %= 1 << h->sps.log2_max_frame_num; h->cur_pic_ptr->frame_num = h->prev_frame_num; h->cur_pic_ptr->invalid_gap = !h->sps.gaps_in_frame_num_allowed_flag; ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); ret = ff_generate_sliding_window_mmcos(h, 1); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; /* Error concealment: If a ref is missing, copy the previous ref * in its place. * FIXME: Avoiding a memcpy would be nice, but ref handling makes * many assumptions about there being no actual duplicates. * FIXME: This does not copy padding for out-of-frame motion * vectors. Given we are concealing a lost frame, this probably * is not noticeable by comparison, but it should be fixed. */ if (h->short_ref_count) { if (prev) { av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, (const uint8_t **)prev->f.data, prev->f.linesize, h->avctx->pix_fmt, h->mb_width * 16, h->mb_height * 16); h->short_ref[0]->poc = prev->poc + 2; } h->short_ref[0]->frame_num = h->prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * We're using that to see whether to continue decoding in that * frame, or to allocate a new one. */ if (h->first_field) { assert(h->cur_pic_ptr); assert(h->cur_pic_ptr->f.buf[0]); assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ h->missing_fields ++; h->cur_pic_ptr = NULL; h->first_field = FIELD_PICTURE(h); } else { h->missing_fields = 0; if (h->cur_pic_ptr->frame_num != h->frame_num) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, h->picture_structure==PICT_BOTTOM_FIELD); /* This and the previous field had different frame_nums. * Consider this field first in pair. Throw away previous * one except for reference purposes. */ h->first_field = 1; h->cur_pic_ptr = NULL; } else { /* Second field in complementary pair */ h->first_field = 0; } } } else { /* Frame or first field in a potentially complementary pair */ h->first_field = FIELD_PICTURE(h); } if (!FIELD_PICTURE(h) || h->first_field) { if (h264_frame_start(h) < 0) { h->first_field = 0; return AVERROR_INVALIDDATA; } } else { release_unused_pictures(h, 0); } /* Some macroblocks can be accessed before they're available in case * of lost slices, MBAFF or threading. */ if (FIELD_PICTURE(h)) { for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++) memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table)); } else { memset(h->slice_table, -1, (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); } h->last_slice_type = -1; } h->cur_pic_ptr->frame_num = h->frame_num; // FIXME frame_num cleanup av_assert1(h->mb_num == h->mb_width * h->mb_height); if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || first_mb_in_slice >= h->mb_num) { av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return AVERROR_INVALIDDATA; } sl->resync_mb_x = sl->mb_x = first_mb_in_slice % h->mb_width; sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) << FIELD_OR_MBAFF_PICTURE(h); if (h->picture_structure == PICT_BOTTOM_FIELD) sl->resync_mb_y = sl->mb_y = sl->mb_y + 1; av_assert1(sl->mb_y < h->mb_height); if (h->picture_structure == PICT_FRAME) { h->curr_pic_num = h->frame_num; h->max_pic_num = 1 << h->sps.log2_max_frame_num; } else { h->curr_pic_num = 2 * h->frame_num + 1; h->max_pic_num = 1 << (h->sps.log2_max_frame_num + 1); } if (h->nal_unit_type == NAL_IDR_SLICE) get_ue_golomb(&sl->gb); /* idr_pic_id */ if (h->sps.poc_type == 0) { h->poc_lsb = get_bits(&sl->gb, h->sps.log2_max_poc_lsb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc_bottom = get_se_golomb(&sl->gb); } if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) { h->delta_poc[0] = get_se_golomb(&sl->gb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc[1] = get_se_golomb(&sl->gb); } ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc); if (h->pps.redundant_pic_cnt_present) sl->redundant_pic_count = get_ue_golomb(&sl->gb); ret = ff_set_ref_count(h, sl); if (ret < 0) return ret; if (slice_type != AV_PICTURE_TYPE_I && (h->current_slice == 0 || slice_type != h->last_slice_type || memcmp(h->last_ref_count, sl->ref_count, sizeof(sl->ref_count)))) { ff_h264_fill_default_ref_list(h, sl); } if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { ret = ff_h264_decode_ref_pic_list_reordering(h, sl); if (ret < 0) { sl->ref_count[1] = sl->ref_count[0] = 0; return ret; } } if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B)) ff_pred_weight_table(h, sl); else if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, -1); } else { sl->use_weight = 0; for (i = 0; i < 2; i++) { sl->luma_weight_flag[i] = 0; sl->chroma_weight_flag[i] = 0; } } // If frame-mt is enabled, only update mmco tables for the first slice // in a field. Subsequent slices can temporarily clobber h->mmco_index // or h->mmco, which will cause ref list mix-ups and decoding errors // further down the line. This may break decoding if the first slice is // corrupt, thus we only do this if frame-mt is enabled. if (h->nal_ref_idc) { ret = ff_h264_decode_ref_pic_marking(h, &sl->gb, !(h->avctx->active_thread_type & FF_THREAD_FRAME) || h->current_slice == 0); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return AVERROR_INVALIDDATA; } if (FRAME_MBAFF(h)) { ff_h264_fill_mbaff_ref_list(h, sl); if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, 0); implicit_weight_table(h, sl, 1); } } if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) ff_h264_direct_dist_scale_factor(h, sl); ff_h264_direct_ref_list_init(h, sl); if (sl->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) { tmp = get_ue_golomb_31(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); return AVERROR_INVALIDDATA; } sl->cabac_init_idc = tmp; } sl->last_qscale_diff = 0; tmp = h->pps.init_qp + get_se_golomb(&sl->gb); if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) { av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return AVERROR_INVALIDDATA; } sl->qscale = tmp; sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale); sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale); // FIXME qscale / qp ... stuff if (sl->slice_type == AV_PICTURE_TYPE_SP) get_bits1(&sl->gb); /* sp_for_switch_flag */ if (sl->slice_type == AV_PICTURE_TYPE_SP || sl->slice_type == AV_PICTURE_TYPE_SI) get_se_golomb(&sl->gb); /* slice_qs_delta */ sl->deblocking_filter = 1; sl->slice_alpha_c0_offset = 0; sl->slice_beta_offset = 0; if (h->pps.deblocking_filter_parameters_present) { tmp = get_ue_golomb_31(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return AVERROR_INVALIDDATA; } sl->deblocking_filter = tmp; if (sl->deblocking_filter < 2) sl->deblocking_filter ^= 1; // 1<->0 if (sl->deblocking_filter) { sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2; sl->slice_beta_offset = get_se_golomb(&sl->gb) * 2; if (sl->slice_alpha_c0_offset > 12 || sl->slice_alpha_c0_offset < -12 || sl->slice_beta_offset > 12 || sl->slice_beta_offset < -12) { av_log(h->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", sl->slice_alpha_c0_offset, sl->slice_beta_offset); return AVERROR_INVALIDDATA; } } } if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE) || (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) sl->deblocking_filter = 0; if (sl->deblocking_filter == 1 && h->max_contexts > 1) { if (h->avctx->flags2 & CODEC_FLAG2_FAST) { /* Cheat slightly for speed: * Do not bother to deblock across slices. */ sl->deblocking_filter = 2; } else { h->max_contexts = 1; if (!h->single_decode_warning) { av_log(h->avctx, AV_LOG_INFO, "Cannot parallelize slice decoding with deblocking filter type 1, decoding such frames in sequential order\n" "To parallelize slice decoding you need video encoded with disable_deblocking_filter_idc set to 2 (deblock only edges that do not cross slices).\n" "Setting the flags2 libavcodec option to +fast (-flags2 +fast) will disable deblocking across slices and enable parallel slice decoding " "but will generate non-standard-compliant output.\n"); h->single_decode_warning = 1; } if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); return SLICE_SINGLETHREAD; } } } sl->qp_thresh = 15 - FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]) + 6 * (h->sps.bit_depth_luma - 8); h->last_slice_type = slice_type; memcpy(h->last_ref_count, sl->ref_count, sizeof(h->last_ref_count)); sl->slice_num = ++h->current_slice; if (sl->slice_num) h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y; if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y && sl->slice_num >= MAX_SLICES) { //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES); } for (j = 0; j < 2; j++) { int id_list[16]; int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; for (i = 0; i < 16; i++) { id_list[i] = 60; if (j < sl->list_count && i < sl->ref_count[j] && sl->ref_list[j][i].parent->f.buf[0]) { int k; AVBuffer *buf = sl->ref_list[j][i].parent->f.buf[0]->buffer; for (k = 0; k < h->short_ref_count; k++) if (h->short_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = k; break; } for (k = 0; k < h->long_ref_count; k++) if (h->long_ref[k] && h->long_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = h->short_ref_count + k; break; } } } ref2frm[0] = ref2frm[1] = -1; for (i = 0; i < 16; i++) ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); ref2frm[18 + 0] = ref2frm[18 + 1] = -1; for (i = 16; i < 48; i++) ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + (sl->ref_list[j][i].reference & 3); } h->au_pps_id = pps_id; h->sps.new = h->sps_buffers[h->pps.sps_id]->new = 0; h->current_sps_id = h->pps.sps_id; if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", sl->slice_num, (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_picture_type_char(sl->slice_type), sl->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", pps_id, h->frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], sl->ref_count[0], sl->ref_count[1], sl->qscale, sl->deblocking_filter, sl->slice_alpha_c0_offset, sl->slice_beta_offset, sl->use_weight, sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "", sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); } return 0; }
26,303
FFmpeg
c6831e2a70f734c71f483d69d46d0635963530c7
1
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last) { int t, t2; int sign, base, add, ret; WvChannel *c = &ctx->ch[channel]; *last = 0; if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one) { if (ctx->zeroes) { ctx->zeroes--; if (ctx->zeroes) { c->slow_level -= LEVEL_DECAY(c->slow_level); return 0; } else { t = get_unary_0_33(gb); if (t >= 2) { if (get_bits_left(gb) < t - 1) t = get_bits(gb, t - 1) | (1 << (t-1)); } else { if (get_bits_left(gb) < 0) ctx->zeroes = t; if (ctx->zeroes) { memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median)); memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median)); c->slow_level -= LEVEL_DECAY(c->slow_level); return 0; if (ctx->zero) { t = 0; ctx->zero = 0; } else { t = get_unary_0_33(gb); if (get_bits_left(gb) < 0) if (t == 16) { t2 = get_unary_0_33(gb); if (t2 < 2) { if (get_bits_left(gb) < 0) t += t2; } else { if (get_bits_left(gb) < t2 - 1) t += get_bits(gb, t2 - 1) | (1 << (t2 - 1)); if (ctx->one) { ctx->one = t & 1; t = (t >> 1) + 1; } else { ctx->one = t & 1; t >>= 1; ctx->zero = !ctx->one; if (ctx->hybrid && !channel) update_error_limit(ctx); if (!t) { base = 0; add = GET_MED(0) - 1; DEC_MED(0); } else if (t == 1) { base = GET_MED(0); add = GET_MED(1) - 1; INC_MED(0); DEC_MED(1); } else if (t == 2) { base = GET_MED(0) + GET_MED(1); add = GET_MED(2) - 1; INC_MED(0); INC_MED(1); DEC_MED(2); } else { base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2); add = GET_MED(2) - 1; INC_MED(0); INC_MED(1); INC_MED(2); if (!c->error_limit) { ret = base + get_tail(gb, add); if (get_bits_left(gb) <= 0) } else { int mid = (base * 2 + add + 1) >> 1; while (add > c->error_limit) { if (get_bits_left(gb) <= 0) if (get_bits1(gb)) { add -= (mid - base); base = mid; } else add = mid - base - 1; mid = (base * 2 + add + 1) >> 1; ret = mid; sign = get_bits1(gb); if (ctx->hybrid_bitrate) c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level); return sign ? ~ret : ret; error: *last = 1; return 0;
26,304
qemu
187337f8b0ec0813dd3876d1efe37d415fb81c2e
1
static pxa2xx_timer_info *pxa2xx_timer_init(target_phys_addr_t base, qemu_irq *irqs) { int i; int iomemtype; pxa2xx_timer_info *s; s = (pxa2xx_timer_info *) qemu_mallocz(sizeof(pxa2xx_timer_info)); s->base = base; s->irq_enabled = 0; s->oldclock = 0; s->clock = 0; s->lastload = qemu_get_clock(vm_clock); s->reset3 = 0; for (i = 0; i < 4; i ++) { s->timer[i].value = 0; s->timer[i].irq = irqs[i]; s->timer[i].info = s; s->timer[i].num = i; s->timer[i].level = 0; s->timer[i].qtimer = qemu_new_timer(vm_clock, pxa2xx_timer_tick, &s->timer[i]); } iomemtype = cpu_register_io_memory(0, pxa2xx_timer_readfn, pxa2xx_timer_writefn, s); cpu_register_physical_memory(base, 0x00000fff, iomemtype); register_savevm("pxa2xx_timer", 0, 0, pxa2xx_timer_save, pxa2xx_timer_load, s); return s; }
26,305
FFmpeg
ec3b22326dc07fb8300a577bd6b17c19a0f1bcf7
1
static void http_write_packet(void *opaque, unsigned char *buf, int size) { HTTPContext *c = opaque; if (c->buffer_ptr == c->buffer_end || !c->buffer_ptr) c->buffer_ptr = c->buffer_end = c->buffer; if (c->buffer_end - c->buffer + size > IOBUFFER_MAX_SIZE) abort(); memcpy(c->buffer_end, buf, size); c->buffer_end += size; }
26,307
qemu
df8bf7a7fe75eb5d5caffa55f5cd4292b757aea6
1
void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt, const struct iovec *iov, int iovcnt, size_t iovoff, bool strip_vlan, uint16_t vet) { uint16_t tci = 0; uint16_t ploff = iovoff; assert(pkt); pkt->vlan_stripped = false; if (strip_vlan) { pkt->vlan_stripped = eth_strip_vlan_ex(iov, iovcnt, iovoff, vet, pkt->ehdr_buf, &ploff, &tci); } pkt->tci = tci; net_rx_pkt_pull_data(pkt, iov, iovcnt, ploff); }
26,308
FFmpeg
131644677970a3c4a0096270ea2a5b5d437c2e63
1
static int http_read_stream(URLContext *h, uint8_t *buf, int size) { HTTPContext *s = h->priv_data; int err, new_location; if (!s->hd) return AVERROR_EOF; if (s->end_chunked_post && !s->end_header) { err = http_read_header(h, &new_location); if (err < 0) return err; } if (s->chunksize >= 0) { if (!s->chunksize) { char line[32]; for (;;) { do { if ((err = http_get_line(s, line, sizeof(line))) < 0) return err; } while (!*line); /* skip CR LF from last chunk */ s->chunksize = strtoll(line, NULL, 16); av_log(NULL, AV_LOG_TRACE, "Chunked encoding data size: %"PRId64"'\n", s->chunksize); if (!s->chunksize) return 0; break; } } size = FFMIN(size, s->chunksize); } #if CONFIG_ZLIB if (s->compressed) return http_buf_read_compressed(h, buf, size); #endif /* CONFIG_ZLIB */ return http_buf_read(h, buf, size); }
26,309
FFmpeg
ed3c9b5b0dd5abb545c48e930e1c32c187b0776a
1
static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) { int i, j, scale_factor; unsigned prob, cumulative_target; unsigned cumul_prob = 0; unsigned scaled_cumul_prob = 0; rac->prob[0] = 0; rac->prob[257] = UINT_MAX; /* Read probabilities from bitstream */ for (i = 1; i < 257; i++) { if (lag_decode_prob(gb, &rac->prob[i]) < 0) { av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability encountered.\n"); return -1; } if ((uint64_t)cumul_prob + rac->prob[i] > UINT_MAX) { av_log(rac->avctx, AV_LOG_ERROR, "Integer overflow encountered in cumulative probability calculation.\n"); return -1; } cumul_prob += rac->prob[i]; if (!rac->prob[i]) { if (lag_decode_prob(gb, &prob)) { av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability run encountered.\n"); return -1; } if (prob > 256 - i) prob = 256 - i; for (j = 0; j < prob; j++) rac->prob[++i] = 0; } } if (!cumul_prob) { av_log(rac->avctx, AV_LOG_ERROR, "All probabilities are 0!\n"); return -1; } /* Scale probabilities so cumulative probability is an even power of 2. */ scale_factor = av_log2(cumul_prob); if (cumul_prob & (cumul_prob - 1)) { uint64_t mul = softfloat_reciprocal(cumul_prob); for (i = 1; i <= 128; i++) { rac->prob[i] = softfloat_mul(rac->prob[i], mul); scaled_cumul_prob += rac->prob[i]; } if (scaled_cumul_prob <= 0) { av_log(rac->avctx, AV_LOG_ERROR, "Scaled probabilities invalid\n"); return AVERROR_INVALIDDATA; } for (; i < 257; i++) { rac->prob[i] = softfloat_mul(rac->prob[i], mul); scaled_cumul_prob += rac->prob[i]; } scale_factor++; cumulative_target = 1 << scale_factor; if (scaled_cumul_prob > cumulative_target) { av_log(rac->avctx, AV_LOG_ERROR, "Scaled probabilities are larger than target!\n"); return -1; } scaled_cumul_prob = cumulative_target - scaled_cumul_prob; for (i = 1; scaled_cumul_prob; i = (i & 0x7f) + 1) { if (rac->prob[i]) { rac->prob[i]++; scaled_cumul_prob--; } /* Comment from reference source: * if (b & 0x80 == 0) { // order of operations is 'wrong'; it has been left this way * // since the compression change is negligible and fixing it * // breaks backwards compatibility * b =- (signed int)b; * b &= 0xFF; * } else { * b++; * b &= 0x7f; * } */ } } rac->scale = scale_factor; /* Fill probability array with cumulative probability for each symbol. */ for (i = 1; i < 257; i++) rac->prob[i] += rac->prob[i - 1]; return 0; }
26,310
qemu
d83c951cce14dd3c7600c386d3791c4993744622
1
static int ata_passthrough_12_xfer_size(SCSIDevice *dev, uint8_t *buf) { int length = buf[2] & 0x3; int xfer; int unit = ata_passthrough_xfer_unit(dev, buf); switch (length) { case 0: case 3: /* USB-specific. */ xfer = 0; break; case 1: xfer = buf[3]; break; case 2: xfer = buf[4]; break; } return xfer * unit; }
26,311
FFmpeg
0058584580b87feb47898e60e4b80c7f425882ad
0
static inline void downmix_2f_2r_to_stereo(float *samples) { int i; for (i = 0; i < 256; i++) { samples[i] += samples[i + 512]; samples[i + 256] = samples[i + 768]; samples[i + 512] = samples[i + 768] = 0; } }
26,312
FFmpeg
c04c3282b4334ff64cfd69d40fea010602e830fd
0
static int video_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st; st = av_new_stream(s, 0); if (!st) return AVERROR_NOMEM; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = s->iformat->value; st->need_parsing = 1; /* for mjpeg, specify frame rate */ /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ if (ap && ap->time_base.num) { av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); } else if ( st->codec->codec_id == CODEC_ID_MJPEG || st->codec->codec_id == CODEC_ID_MPEG4 || st->codec->codec_id == CODEC_ID_H264) { av_set_pts_info(st, 64, 1, 25); } return 0; }
26,313
FFmpeg
e278056fbad7405fc47901faea7de98db003a0fa
0
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; static int counter = 0; int i; init_get_bits(&gb, buf, buf_size * 8); if (s->theora && get_bits1(&gb)) { #if 1 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; #else int ptype = get_bits(&gb, 7); skip_bits(&gb, 6*8); /* "theora" */ switch(ptype) { case 1: theora_decode_comments(avctx, gb); break; case 2: theora_decode_tables(avctx, gb); init_dequantizer(s); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); } return buf_size; #endif } s->keyframe = !get_bits1(&gb); if (!s->theora) skip_bits(&gb, 1); s->last_quality_index = s->quality_index; s->quality_index = get_bits(&gb, 6); if (s->theora >= 0x030200) skip_bits1(&gb); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", s->keyframe?"key":"", counter, s->quality_index); counter++; if (s->quality_index != s->last_quality_index) { init_dequantizer(s); init_loop_filter(s); } if (s->keyframe) { if (!s->theora) { skip_bits(&gb, 4); /* width code */ skip_bits(&gb, 4); /* height code */ if (s->version) { s->version = get_bits(&gb, 5); if (counter == 1) av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora) { if (get_bits1(&gb)) av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); /* reserved? */ } if (s->last_frame.data[0] == s->golden_frame.data[0]) { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ } else { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); if (s->last_frame.data[0]) avctx->release_buffer(avctx, &s->last_frame); } s->golden_frame.reference = 3; if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } /* golden frame is also the current frame */ memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame)); /* time to figure out pixel addresses? */ if (!s->pixel_addresses_inited) { if (!s->flipped_image) vp3_calculate_pixel_addresses(s); else theora_calculate_pixel_addresses(s); } } else { /* allocate a new current frame */ s->current_frame.reference = 3; if(avctx->get_buffer(avctx, &s->current_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame s->current_frame.qstride= 0; {START_TIMER init_frame(s, &gb); STOP_TIMER("init_frame")} #if KEYFRAMES_ONLY if (!s->keyframe) { memcpy(s->current_frame.data[0], s->golden_frame.data[0], s->current_frame.linesize[0] * s->height); memcpy(s->current_frame.data[1], s->golden_frame.data[1], s->current_frame.linesize[1] * s->height / 2); memcpy(s->current_frame.data[2], s->golden_frame.data[2], s->current_frame.linesize[2] * s->height / 2); } else { #endif {START_TIMER if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } STOP_TIMER("unpack_superblocks")} {START_TIMER if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } STOP_TIMER("unpack_modes")} {START_TIMER if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } STOP_TIMER("unpack_vectors")} {START_TIMER if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } STOP_TIMER("unpack_dct_coeffs")} {START_TIMER reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { reverse_dc_prediction(s, s->u_fragment_start, s->fragment_width / 2, s->fragment_height / 2); reverse_dc_prediction(s, s->v_fragment_start, s->fragment_width / 2, s->fragment_height / 2); } STOP_TIMER("reverse_dc_prediction")} {START_TIMER for (i = 0; i < s->macroblock_height; i++) render_slice(s, i); STOP_TIMER("render_fragments")} {START_TIMER apply_loop_filter(s); STOP_TIMER("apply_loop_filter")} #if KEYFRAMES_ONLY } #endif *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; /* release the last frame, if it is allocated and if it is not the * golden frame */ if ((s->last_frame.data[0]) && (s->last_frame.data[0] != s->golden_frame.data[0])) avctx->release_buffer(avctx, &s->last_frame); /* shuffle frames (last = current) */ memcpy(&s->last_frame, &s->current_frame, sizeof(AVFrame)); s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ return buf_size; }
26,314
qemu
2466119c9551d606a0f92f9832e0c865bc04b488
1
static inline int host_to_target_errno(int err) { if(host_to_target_errno_table[err]) return host_to_target_errno_table[err]; return err; }
26,316
qemu
e8a40bf71d606f9f87866fb2461eaed52814b38e
1
void backup_start(const char *job_id, BlockDriverState *bs, BlockDriverState *target, int64_t speed, MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap, bool compress, BlockdevOnError on_source_error, BlockdevOnError on_target_error, int creation_flags, BlockCompletionFunc *cb, void *opaque, BlockJobTxn *txn, Error **errp) { int64_t len; BlockDriverInfo bdi; BackupBlockJob *job = NULL; int ret; assert(bs); assert(target); if (bs == target) { error_setg(errp, "Source and target cannot be the same"); return; } if (!bdrv_is_inserted(bs)) { error_setg(errp, "Device is not inserted: %s", bdrv_get_device_name(bs)); return; } if (!bdrv_is_inserted(target)) { error_setg(errp, "Device is not inserted: %s", bdrv_get_device_name(target)); return; } if (compress && target->drv->bdrv_co_pwritev_compressed == NULL) { error_setg(errp, "Compression is not supported for this drive %s", bdrv_get_device_name(target)); return; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { return; } if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) { return; } if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { if (!sync_bitmap) { error_setg(errp, "must provide a valid bitmap name for " "\"incremental\" sync mode"); return; } /* Create a new bitmap, and freeze/disable this one. */ if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) { return; } } else if (sync_bitmap) { error_setg(errp, "a sync_bitmap was provided to backup_run, " "but received an incompatible sync_mode (%s)", MirrorSyncMode_lookup[sync_mode]); return; } len = bdrv_getlength(bs); if (len < 0) { error_setg_errno(errp, -len, "unable to get length for '%s'", bdrv_get_device_name(bs)); goto error; } job = block_job_create(job_id, &backup_job_driver, bs, speed, creation_flags, cb, opaque, errp); if (!job) { goto error; } job->target = blk_new(); blk_insert_bs(job->target, target); job->on_source_error = on_source_error; job->on_target_error = on_target_error; job->sync_mode = sync_mode; job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ? sync_bitmap : NULL; job->compress = compress; /* If there is no backing file on the target, we cannot rely on COW if our * backup cluster size is smaller than the target cluster size. Even for * targets with a backing file, try to avoid COW if possible. */ ret = bdrv_get_info(target, &bdi); if (ret < 0 && !target->backing) { error_setg_errno(errp, -ret, "Couldn't determine the cluster size of the target image, " "which has no backing file"); error_append_hint(errp, "Aborting, since this may create an unusable destination image\n"); goto error; } else if (ret < 0 && target->backing) { /* Not fatal; just trudge on ahead. */ job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; } else { job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size); } block_job_add_bdrv(&job->common, target); job->common.len = len; job->common.co = qemu_coroutine_create(backup_run, job); block_job_txn_add_job(txn, &job->common); qemu_coroutine_enter(job->common.co); return; error: if (sync_bitmap) { bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL); } if (job) { blk_unref(job->target); block_job_unref(&job->common); } }
26,317
qemu
0b8b8753e4d94901627b3e86431230f2319215c4
1
static void restart_co_req(void *opaque) { Coroutine *co = opaque; qemu_coroutine_enter(co, NULL); }
26,318
qemu
6bdcc018a6ed760b9dfe43539124e420aed83092
1
static void nbd_coroutine_start(NBDClientSession *s, NBDRequest *request) { /* Poor man semaphore. The free_sema is locked when no other request * can be accepted, and unlocked after receiving one reply. */ if (s->in_flight == MAX_NBD_REQUESTS) { qemu_co_queue_wait(&s->free_sema, NULL); assert(s->in_flight < MAX_NBD_REQUESTS); } s->in_flight++; /* s->recv_coroutine[i] is set as soon as we get the send_lock. */ }
26,319
FFmpeg
c39059bea3adebcd888571d1181db215eee54495
0
void ff_h264_direct_dist_scale_factor(H264Context *const h) { const int poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; const int poc1 = h->ref_list[1][0].poc; int i, field; if (FRAME_MBAFF(h)) for (field = 0; field < 2; field++) { const int poc = h->cur_pic_ptr->field_poc[field]; const int poc1 = h->ref_list[1][0].field_poc[field]; for (i = 0; i < 2 * h->ref_count[0]; i++) h->dist_scale_factor_field[field][i ^ field] = get_scale_factor(h, poc, poc1, i + 16); } for (i = 0; i < h->ref_count[0]; i++) h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i); }
26,322
qemu
456736710df19c2275192269fe67a3f0b2583835
1
static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, QDict *options, int flags, BlockDriver *drv) { int ret, open_flags; const char *filename; assert(drv != NULL); assert(bs->file == NULL); assert(options != NULL && bs->options != options); trace_bdrv_open_common(bs, filename, flags, drv->format_name); if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) { return -ENOTSUP; } /* bdrv_open() with directly using a protocol as drv. This layer is already * opened, so assign it to bs (while file becomes a closed BlockDriverState) * and return immediately. */ if (file != NULL && drv->bdrv_file_open) { bdrv_swap(file, bs); return 0; } bs->open_flags = flags; bs->buffer_alignment = 512; assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */ if ((flags & BDRV_O_RDWR) && (flags & BDRV_O_COPY_ON_READ)) { bdrv_enable_copy_on_read(bs); } if (file != NULL) { filename = file->filename; } else { filename = qdict_get_try_str(options, "filename"); } if (filename != NULL) { pstrcpy(bs->filename, sizeof(bs->filename), filename); } else { bs->filename[0] = '\0'; } bs->drv = drv; bs->opaque = g_malloc0(drv->instance_size); bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB); open_flags = bdrv_open_flags(bs, flags); bs->read_only = !(open_flags & BDRV_O_RDWR); /* Open the image, either directly or using a protocol */ if (drv->bdrv_file_open) { assert(file == NULL); assert(drv->bdrv_parse_filename || filename != NULL); ret = drv->bdrv_file_open(bs, options, open_flags); } else { if (file == NULL) { qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a " "block driver for the protocol level", drv->format_name); ret = -EINVAL; goto free_and_fail; } assert(file != NULL); bs->file = file; ret = drv->bdrv_open(bs, options, open_flags); } if (ret < 0) { goto free_and_fail; } ret = refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { goto free_and_fail; } #ifndef _WIN32 if (bs->is_temporary) { assert(filename != NULL); unlink(filename); } #endif return 0; free_and_fail: bs->file = NULL; g_free(bs->opaque); bs->opaque = NULL; bs->drv = NULL; return ret; }
26,323
qemu
b35278f75450e57c134a153e6da9744c1db8382f
1
static int qcow2_open(BlockDriverState *bs, int flags) { BDRVQcowState *s = bs->opaque; int len, i, ret = 0; QCowHeader header; uint64_t ext_end; ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; } be32_to_cpus(&header.magic); be32_to_cpus(&header.version); be64_to_cpus(&header.backing_file_offset); be32_to_cpus(&header.backing_file_size); be64_to_cpus(&header.size); be32_to_cpus(&header.cluster_bits); be32_to_cpus(&header.crypt_method); be64_to_cpus(&header.l1_table_offset); be32_to_cpus(&header.l1_size); be64_to_cpus(&header.refcount_table_offset); be32_to_cpus(&header.refcount_table_clusters); be64_to_cpus(&header.snapshots_offset); be32_to_cpus(&header.nb_snapshots); if (header.magic != QCOW_MAGIC) { ret = -EINVAL; goto fail; } if (header.version < 2 || header.version > 3) { report_unsupported(bs, "QCOW version %d", header.version); ret = -ENOTSUP; goto fail; } s->qcow_version = header.version; /* Initialise version 3 header fields */ if (header.version == 2) { header.incompatible_features = 0; header.compatible_features = 0; header.autoclear_features = 0; header.refcount_order = 4; header.header_length = 72; } else { be64_to_cpus(&header.incompatible_features); be64_to_cpus(&header.compatible_features); be64_to_cpus(&header.autoclear_features); be32_to_cpus(&header.refcount_order); be32_to_cpus(&header.header_length); } if (header.header_length > sizeof(header)) { s->unknown_header_fields_size = header.header_length - sizeof(header); s->unknown_header_fields = g_malloc(s->unknown_header_fields_size); ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields, s->unknown_header_fields_size); if (ret < 0) { goto fail; } } if (header.backing_file_offset) { ext_end = header.backing_file_offset; } else { ext_end = 1 << header.cluster_bits; } /* Handle feature bits */ s->incompatible_features = header.incompatible_features; s->compatible_features = header.compatible_features; s->autoclear_features = header.autoclear_features; if (s->incompatible_features != 0) { void *feature_table = NULL; qcow2_read_extensions(bs, header.header_length, ext_end, &feature_table); report_unsupported_feature(bs, feature_table, s->incompatible_features); ret = -ENOTSUP; goto fail; } /* Check support for various header values */ if (header.refcount_order != 4) { report_unsupported(bs, "%d bit reference counts", 1 << header.refcount_order); ret = -ENOTSUP; goto fail; } if (header.cluster_bits < MIN_CLUSTER_BITS || header.cluster_bits > MAX_CLUSTER_BITS) { ret = -EINVAL; goto fail; } if (header.crypt_method > QCOW_CRYPT_AES) { ret = -EINVAL; goto fail; } s->crypt_method_header = header.crypt_method; if (s->crypt_method_header) { bs->encrypted = 1; } s->cluster_bits = header.cluster_bits; s->cluster_size = 1 << s->cluster_bits; s->cluster_sectors = 1 << (s->cluster_bits - 9); s->l2_bits = s->cluster_bits - 3; /* L2 is always one cluster */ s->l2_size = 1 << s->l2_bits; bs->total_sectors = header.size / 512; s->csize_shift = (62 - (s->cluster_bits - 8)); s->csize_mask = (1 << (s->cluster_bits - 8)) - 1; s->cluster_offset_mask = (1LL << s->csize_shift) - 1; s->refcount_table_offset = header.refcount_table_offset; s->refcount_table_size = header.refcount_table_clusters << (s->cluster_bits - 3); s->snapshots_offset = header.snapshots_offset; s->nb_snapshots = header.nb_snapshots; /* read the level 1 table */ s->l1_size = header.l1_size; s->l1_vm_state_index = size_to_l1(s, header.size); /* the L1 table must contain at least enough entries to put header.size bytes */ if (s->l1_size < s->l1_vm_state_index) { ret = -EINVAL; goto fail; } s->l1_table_offset = header.l1_table_offset; if (s->l1_size > 0) { s->l1_table = g_malloc0( align_offset(s->l1_size * sizeof(uint64_t), 512)); ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { goto fail; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } } /* alloc L2 table/refcount block cache */ s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE); s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE); s->cluster_cache = g_malloc(s->cluster_size); /* one more sector for decompressed data alignment */ s->cluster_data = qemu_blockalign(bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); s->cluster_cache_offset = -1; s->flags = flags; ret = qcow2_refcount_init(bs); if (ret != 0) { goto fail; } QLIST_INIT(&s->cluster_allocs); /* read qcow2 extensions */ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL)) { ret = -EINVAL; goto fail; } /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; if (len > 1023) { len = 1023; } ret = bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len); if (ret < 0) { goto fail; } bs->backing_file[len] = '\0'; } ret = qcow2_read_snapshots(bs); if (ret < 0) { goto fail; } /* Clear unknown autoclear feature bits */ if (!bs->read_only && s->autoclear_features != 0) { s->autoclear_features = 0; ret = qcow2_update_header(bs); if (ret < 0) { goto fail; } } /* Initialise locks */ qemu_co_mutex_init(&s->lock); #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0}; qcow2_check_refcounts(bs, &result); } #endif return ret; fail: g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); qcow2_free_snapshots(bs); qcow2_refcount_close(bs); g_free(s->l1_table); if (s->l2_table_cache) { qcow2_cache_destroy(bs, s->l2_table_cache); } g_free(s->cluster_cache); qemu_vfree(s->cluster_data); return ret; }
26,324
FFmpeg
f58cd2867a8af2eed13acdd21d067b48249b14a1
1
static int read_packet(AVFormatContext *s, AVPacket *pkt) { PAFDemuxContext *p = s->priv_data; AVIOContext *pb = s->pb; uint32_t count, offset; int size, i; if (p->current_frame >= p->nb_frames) return AVERROR_EOF; if (url_feof(pb)) return AVERROR_EOF; if (p->got_audio) { if (av_new_packet(pkt, p->audio_size) < 0) return AVERROR(ENOMEM); memcpy(pkt->data, p->temp_audio_frame, p->audio_size); pkt->duration = PAF_SOUND_SAMPLES * (p->audio_size / PAF_SOUND_FRAME_SIZE); pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = 1; p->got_audio = 0; return pkt->size; } count = (p->current_frame == 0) ? p->preload_count : p->blocks_count_table[p->current_frame - 1]; for (i = 0; i < count; i++) { if (p->current_frame_block >= p->frame_blks) return AVERROR_INVALIDDATA; offset = p->blocks_offset_table[p->current_frame_block] & ~(1U << 31); if (p->blocks_offset_table[p->current_frame_block] & (1U << 31)) { if (offset > p->audio_size - p->buffer_size) return AVERROR_INVALIDDATA; avio_read(pb, p->audio_frame + offset, p->buffer_size); if (offset == (p->max_audio_blks - 2) * p->buffer_size) { memcpy(p->temp_audio_frame, p->audio_frame, p->audio_size); p->got_audio = 1; } } else { if (offset > p->video_size - p->buffer_size) return AVERROR_INVALIDDATA; avio_read(pb, p->video_frame + offset, p->buffer_size); } p->current_frame_block++; } size = p->video_size - p->frames_offset_table[p->current_frame]; if (size < 1) return AVERROR_INVALIDDATA; if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM); pkt->stream_index = 0; pkt->duration = 1; memcpy(pkt->data, p->video_frame + p->frames_offset_table[p->current_frame], size); if (pkt->data[0] & 0x20) pkt->flags |= AV_PKT_FLAG_KEY; p->current_frame++; return pkt->size; }
26,325
qemu
962b289ef35087fcd8764e4e29808d8ac90157f7
1
char *target_strerror(int err) { return strerror(target_to_host_errno(err));
26,326
FFmpeg
ce41c51b0c71c87f623914ba0786aef325d818fe
1
AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle, int packet_size) { AVFormatContext *rtpctx; int ret; AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); if (!rtp_format) return NULL; /* Allocate an AVFormatContext for each output stream */ rtpctx = avformat_alloc_context(); if (!rtpctx) return NULL; rtpctx->oformat = rtp_format; if (!av_new_stream(rtpctx, 0)) { av_free(rtpctx); return NULL; } /* Copy the max delay setting; the rtp muxer reads this. */ rtpctx->max_delay = s->max_delay; /* Copy other stream parameters. */ rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; /* Set the synchronized start time. */ rtpctx->start_time_realtime = s->start_time_realtime; /* Remove the local codec, link to the original codec * context instead, to give the rtp muxer access to * codec parameters. */ av_free(rtpctx->streams[0]->codec); rtpctx->streams[0]->codec = st->codec; if (handle) { url_fdopen(&rtpctx->pb, handle); } else url_open_dyn_packet_buf(&rtpctx->pb, packet_size); ret = av_write_header(rtpctx); if (ret) { if (handle) { url_fclose(rtpctx->pb); } else { uint8_t *ptr; url_close_dyn_buf(rtpctx->pb, &ptr); av_free(ptr); } av_free(rtpctx->streams[0]); av_free(rtpctx); return NULL; } /* Copy the RTP AVStream timebase back to the original AVStream */ st->time_base = rtpctx->streams[0]->time_base; return rtpctx; }
26,327
qemu
f61d82c2dfe02a60642a76e8f0034a0244eef2bf
1
static int pci_cirrus_vga_initfn(PCIDevice *dev) { PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev); CirrusVGAState *s = &d->cirrus_vga; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); int16_t device_id = pc->device_id; /* setup VGA */ vga_common_init(&s->vga, OBJECT(dev), true); cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev), pci_address_space_io(dev)); s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga); /* setup PCI */ memory_region_init(&s->pci_bar, OBJECT(dev), "cirrus-pci-bar0", 0x2000000); /* XXX: add byte swapping apertures */ memory_region_add_subregion(&s->pci_bar, 0, &s->cirrus_linear_io); memory_region_add_subregion(&s->pci_bar, 0x1000000, &s->cirrus_linear_bitblt_io); /* setup memory space */ /* memory #0 LFB */ /* memory #1 memory-mapped I/O */ /* XXX: s->vga.vram_size must be a power of two */ pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->pci_bar); if (device_id == CIRRUS_ID_CLGD5446) { pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io); return 0;
26,328
FFmpeg
a443a2530d00b7019269202ac0f5ca8ba0a021c7
1
static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st, int read_all) { RMContext *rm = s->priv_data; ByteIOContext *pb = &s->pb; char buf[256]; uint32_t version; int i; /* ra type header */ version = get_be32(pb); /* version */ if (((version >> 16) & 0xff) == 3) { int64_t startpos = url_ftell(pb); /* very old version */ for(i = 0; i < 14; i++) get_byte(pb); get_str8(pb, s->title, sizeof(s->title)); get_str8(pb, s->author, sizeof(s->author)); get_str8(pb, s->copyright, sizeof(s->copyright)); get_str8(pb, s->comment, sizeof(s->comment)); if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) { // fourcc (should always be "lpcJ") get_byte(pb); get_str8(pb, buf, sizeof(buf)); // Skip extra header crap (this should never happen) if ((startpos + (version & 0xffff)) > url_ftell(pb)) url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb)); st->codec->sample_rate = 8000; st->codec->channels = 1; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_RA_144; } else { int flavor, sub_packet_h, coded_framesize, sub_packet_size; /* old version (4) */ get_be32(pb); /* .ra4 */ get_be32(pb); /* data size */ get_be16(pb); /* version2 */ get_be32(pb); /* header size */ flavor= get_be16(pb); /* add codec info / flavor */ rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */ get_be32(pb); /* ??? */ get_be32(pb); /* ??? */ get_be32(pb); /* ??? */ rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */ st->codec->block_align= get_be16(pb); /* frame size */ rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */ get_be16(pb); /* ??? */ if (((version >> 16) & 0xff) == 5) { get_be16(pb); get_be16(pb); get_be16(pb); } st->codec->sample_rate = get_be16(pb); get_be32(pb); st->codec->channels = get_be16(pb); if (((version >> 16) & 0xff) == 5) { get_be32(pb); buf[0] = get_byte(pb); buf[1] = get_byte(pb); buf[2] = get_byte(pb); buf[3] = get_byte(pb); buf[4] = 0; } else { get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* desc */ st->codec->codec_type = CODEC_TYPE_AUDIO; if (!strcmp(buf, "dnet")) { st->codec->codec_id = CODEC_ID_AC3; } else if (!strcmp(buf, "28_8")) { st->codec->codec_id = CODEC_ID_RA_288; st->codec->extradata_size= 0; rm->audio_framesize = st->codec->block_align; st->codec->block_align = coded_framesize; rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); } else if (!strcmp(buf, "cook")) { int codecdata_length, i; get_be16(pb); get_byte(pb); if (((version >> 16) & 0xff) == 5) get_byte(pb); codecdata_length = get_be32(pb); if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); st->codec->codec_id = CODEC_ID_COOK; st->codec->extradata_size= codecdata_length; st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); for(i = 0; i < codecdata_length; i++) ((uint8_t*)st->codec->extradata)[i] = get_byte(pb); rm->audio_framesize = st->codec->block_align; st->codec->block_align = rm->sub_packet_size; rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); } else { st->codec->codec_id = CODEC_ID_NONE; pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name), buf); if (read_all) { get_byte(pb); get_byte(pb); get_byte(pb); get_str8(pb, s->title, sizeof(s->title)); get_str8(pb, s->author, sizeof(s->author)); get_str8(pb, s->copyright, sizeof(s->copyright)); get_str8(pb, s->comment, sizeof(s->comment));
26,329
FFmpeg
aba232cfa9b193604ed98f3fa505378d006b1b3b
1
static int vc1test_write_header(AVFormatContext *s) { AVCodecContext *avc = s->streams[0]->codec; AVIOContext *pb = s->pb; if (avc->codec_id != CODEC_ID_WMV3) { av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n"); return -1; } avio_wl24(pb, 0); //frames count will be here avio_w8(pb, 0xC5); avio_wl32(pb, 4); avio_write(pb, avc->extradata, 4); avio_wl32(pb, avc->height); avio_wl32(pb, avc->width); avio_wl32(pb, 0xC); avio_wl24(pb, 0); // hrd_buffer avio_w8(pb, 0x80); // level|cbr|res1 avio_wl32(pb, 0); // hrd_rate if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1) avio_wl32(pb, s->streams[0]->r_frame_rate.den); else avio_wl32(pb, 0xFFFFFFFF); //variable framerate avpriv_set_pts_info(s->streams[0], 32, 1, 1000); return 0; }
26,332
FFmpeg
c0b91348fe4aec7d2245d95ccabb460a6971e361
1
static int caca_write_trailer(AVFormatContext *s) { CACAContext *c = s->priv_data; av_freep(&c->window_title); caca_free_dither(c->dither); caca_free_display(c->display); caca_free_canvas(c->canvas); return 0; }
26,334
qemu
02b33596d09bafed5d58366403a2d369f0d1047e
1
static void dec_null(DisasContext *dc) { qemu_log ("unknown insn pc=%x opc=%x\n", dc->pc, dc->opcode); dc->abort_at_next_insn = 1;
26,335
FFmpeg
e2710e790c09e49e86baa58c6063af0097cc8cb0
1
int av_parse_cpu_flags(const char *s) { #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV) #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX) #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW) #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT) #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE) #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2) #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2) #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3) #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3) #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3) #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4) #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42) #define CPUFLAG_AVXSLOW (AV_CPU_FLAG_AVXSLOW | CPUFLAG_AVX) #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX) #define CPUFLAG_FMA3 (AV_CPU_FLAG_FMA3 | CPUFLAG_AVX) #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX) #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX) #define CPUFLAG_BMI2 (AV_CPU_FLAG_BMI2 | AV_CPU_FLAG_BMI1) static const AVOption cpuflags_opts[] = { { "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" }, #if ARCH_PPC { "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ALTIVEC }, .unit = "flags" }, #elif ARCH_X86 { "mmx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX }, .unit = "flags" }, { "mmxext" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_MMXEXT }, .unit = "flags" }, { "sse" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE }, .unit = "flags" }, { "sse2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2 }, .unit = "flags" }, { "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2SLOW }, .unit = "flags" }, { "sse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3 }, .unit = "flags" }, { "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3SLOW }, .unit = "flags" }, { "ssse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSSE3 }, .unit = "flags" }, { "atom" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ATOM }, .unit = "flags" }, { "sse4.1" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE4 }, .unit = "flags" }, { "sse4.2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE42 }, .unit = "flags" }, { "avx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX }, .unit = "flags" }, { "avxslow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVXSLOW }, .unit = "flags" }, { "xop" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_XOP }, .unit = "flags" }, { "fma3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA3 }, .unit = "flags" }, { "fma4" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA4 }, .unit = "flags" }, { "avx2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX2 }, .unit = "flags" }, { "bmi1" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_BMI1 }, .unit = "flags" }, { "bmi2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_BMI2 }, .unit = "flags" }, { "3dnow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOW }, .unit = "flags" }, { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOWEXT }, .unit = "flags" }, { "cmov", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV }, .unit = "flags" }, #elif ARCH_ARM { "armv5te", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV5TE }, .unit = "flags" }, { "armv6", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6 }, .unit = "flags" }, { "armv6t2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6T2 }, .unit = "flags" }, { "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" }, { "vfpv3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3 }, .unit = "flags" }, { "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" }, #elif ARCH_AARCH64 { "armv8", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8 }, .unit = "flags" }, { "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" }, { "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" }, #endif { NULL }, }; static const AVClass class = { .class_name = "cpuflags", .item_name = av_default_item_name, .option = cpuflags_opts, .version = LIBAVUTIL_VERSION_INT, }; int flags = 0, ret; const AVClass *pclass = &class; if ((ret = av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, &flags)) < 0) return ret; return flags & INT_MAX; }
26,336
FFmpeg
915bbac6815eddd911fb5cb8a23517b3cac3a84b
1
void mpeg1_init_vlc(MpegEncContext *s) { static int done = 0; if (!done) { init_vlc(&dc_lum_vlc, 9, 12, vlc_dc_lum_bits, 1, 1, vlc_dc_lum_code, 2, 2); init_vlc(&dc_chroma_vlc, 9, 12, vlc_dc_chroma_bits, 1, 1, vlc_dc_chroma_code, 2, 2); init_vlc(&mv_vlc, 9, 17, &mbMotionVectorTable[0][1], 2, 1, &mbMotionVectorTable[0][0], 2, 1); init_vlc(&mbincr_vlc, 9, 35, &mbAddrIncrTable[0][1], 2, 1, &mbAddrIncrTable[0][0], 2, 1); init_vlc(&mb_pat_vlc, 9, 63, &mbPatTable[0][1], 2, 1, &mbPatTable[0][0], 2, 1); init_vlc(&mb_ptype_vlc, 6, 32, &table_mb_ptype[0][1], 2, 1, &table_mb_ptype[0][0], 2, 1); init_vlc(&mb_btype_vlc, 6, 32, &table_mb_btype[0][1], 2, 1, &table_mb_btype[0][0], 2, 1); init_rl(&rl_mpeg1); init_rl(&rl_mpeg2); /* cannot use generic init because we must add the EOB code */ init_vlc(&rl_mpeg1.vlc, 9, rl_mpeg1.n + 2, &rl_mpeg1.table_vlc[0][1], 4, 2, &rl_mpeg1.table_vlc[0][0], 4, 2); init_vlc(&rl_mpeg2.vlc, 9, rl_mpeg2.n + 2, &rl_mpeg2.table_vlc[0][1], 4, 2, &rl_mpeg2.table_vlc[0][0], 4, 2); } }
26,337
FFmpeg
50833c9f7b4e1922197a8955669f8ab3589c8cef
1
static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf, int buf_size, int block_width, int block_height, uint8_t *previous_frame, int *I_frame) { PutBitContext pb; int h_blocks, v_blocks, h_part, v_part, i, j; int buf_pos, res; int pred_blocks = 0; init_put_bits(&pb, buf, buf_size * 8); put_bits(&pb, 4, block_width / 16 - 1); put_bits(&pb, 12, s->image_width); put_bits(&pb, 4, block_height / 16 - 1); put_bits(&pb, 12, s->image_height); flush_put_bits(&pb); buf_pos = 4; h_blocks = s->image_width / block_width; h_part = s->image_width % block_width; v_blocks = s->image_height / block_height; v_part = s->image_height % block_height; /* loop over all block columns */ for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) { int y_pos = j * block_height; // vertical position in frame int cur_blk_height = (j < v_blocks) ? block_height : v_part; /* loop over all block rows */ for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) { int x_pos = i * block_width; // horizontal position in frame int cur_blk_width = (i < h_blocks) ? block_width : h_part; int ret = Z_OK; uint8_t *ptr = buf + buf_pos; /* copy the block to the temp buffer before compression * (if it differs from the previous frame's block) */ res = copy_region_enc(p->data[0], s->tmpblock, s->image_height - (y_pos + cur_blk_height + 1), x_pos, cur_blk_height, cur_blk_width, p->linesize[0], previous_frame); if (res || *I_frame) { unsigned long zsize = 3 * block_width * block_height; ret = compress2(ptr + 2, &zsize, s->tmpblock, 3 * cur_blk_width * cur_blk_height, 9); //ret = deflateReset(&s->zstream); if (ret != Z_OK) av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j); bytestream_put_be16(&ptr, zsize); buf_pos += zsize + 2; av_dlog(s->avctx, "buf_pos = %d\n", buf_pos); } else { pred_blocks++; bytestream_put_be16(&ptr, 0); buf_pos += 2; } } } if (pred_blocks) *I_frame = 0; else *I_frame = 1; return buf_pos; }
26,338
qemu
3453f9a0dfa58578e6dadf0905ff4528b428ec73
1
static void usb_uas_task(UASDevice *uas, uas_ui *ui) { uint16_t tag = be16_to_cpu(ui->hdr.tag); uint64_t lun64 = be64_to_cpu(ui->task.lun); SCSIDevice *dev = usb_uas_get_dev(uas, lun64); int lun = usb_uas_get_lun(lun64); UASRequest *req; uint16_t task_tag; req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag)); if (req) { goto overlapped_tag; if (dev == NULL) { goto incorrect_lun; switch (ui->task.function) { case UAS_TMF_ABORT_TASK: task_tag = be16_to_cpu(ui->task.task_tag); trace_usb_uas_tmf_abort_task(uas->dev.addr, tag, task_tag); req = usb_uas_find_request(uas, task_tag); if (req && req->dev == dev) { scsi_req_cancel(req->req); usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0); break; case UAS_TMF_LOGICAL_UNIT_RESET: trace_usb_uas_tmf_logical_unit_reset(uas->dev.addr, tag, lun); qdev_reset_all(&dev->qdev); usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0); break; default: trace_usb_uas_tmf_unsupported(uas->dev.addr, tag, ui->task.function); usb_uas_queue_response(uas, tag, UAS_RC_TMF_NOT_SUPPORTED, 0); break; return; invalid_tag: usb_uas_queue_response(uas, tag, UAS_RC_INVALID_INFO_UNIT, 0); return; overlapped_tag: usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0); return; incorrect_lun: usb_uas_queue_response(uas, tag, UAS_RC_INCORRECT_LUN, 0);
26,339
qemu
66dc50f7057b9a0191f54e55764412202306858d
1
static int sch_handle_start_func_passthrough(SubchDev *sch) { PMCW *p = &sch->curr_status.pmcw; SCSW *s = &sch->curr_status.scsw; int ret; ORB *orb = &sch->orb; if (!(s->ctrl & SCSW_ACTL_SUSP)) { assert(orb != NULL); p->intparm = orb->intparm; } /* * Only support prefetch enable mode. * Only support 64bit addressing idal. */ if (!(orb->ctrl0 & ORB_CTRL0_MASK_PFCH) || !(orb->ctrl0 & ORB_CTRL0_MASK_C64)) { return -EINVAL; } ret = s390_ccw_cmd_request(orb, s, sch->driver_data); switch (ret) { /* Currently we don't update control block and just return the cc code. */ case 0: break; case -EBUSY: break; case -ENODEV: break; case -EACCES: /* Let's reflect an inaccessible host device by cc 3. */ ret = -ENODEV; break; default: /* * All other return codes will trigger a program check, * or set cc to 1. */ break; }; return ret; }
26,340
qemu
1d06cb7ab93f879ac25c9f5ef1d1ac8d97a42dfc
1
static int cmd_valid_while_locked(SDState *sd, SDRequest *req) { /* Valid commands in locked state: * basic class (0) * lock card class (7) * CMD16 * implicitly, the ACMD prefix CMD55 * ACMD41 and ACMD42 * Anything else provokes an "illegal command" response. */ if (sd->card_status & APP_CMD) { return req->cmd == 41 || req->cmd == 42; } if (req->cmd == 16 || req->cmd == 55) { return 1; } return sd_cmd_class[req->cmd] == 0 || sd_cmd_class[req->cmd] == 7; }
26,341
FFmpeg
32c3047cac9294bb56d23c89a40a22409db5cc70
0
static int smc_decode_init(AVCodecContext *avctx) { SmcContext *s = avctx->priv_data; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; return 0; }
26,342
FFmpeg
403ee835e7913eb9536b22c2b22edfdd700166a9
0
int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, int track_index, int sample) { MOVMuxContext *mov = s->priv_data; MOVTrack *trk = &mov->tracks[track_index]; AVFormatContext *rtp_ctx = trk->rtp_ctx; uint8_t *buf = NULL; int size; AVIOContext *hintbuf = NULL; AVPacket hint_pkt; int ret = 0, count; if (!rtp_ctx) return AVERROR(ENOENT); if (!rtp_ctx->pb) return AVERROR(ENOMEM); sample_queue_push(&trk->sample_queue, pkt, sample); /* Feed the packet to the RTP muxer */ ff_write_chained(rtp_ctx, 0, pkt, s); /* Fetch the output from the RTP muxer, open a new output buffer * for next time. */ size = avio_close_dyn_buf(rtp_ctx->pb, &buf); if ((ret = url_open_dyn_packet_buf(&rtp_ctx->pb, RTP_MAX_PACKET_SIZE)) < 0) goto done; if (size <= 0) goto done; /* Open a buffer for writing the hint */ if ((ret = avio_open_dyn_buf(&hintbuf)) < 0) goto done; av_init_packet(&hint_pkt); count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt.dts); av_freep(&buf); /* Write the hint data into the hint track */ hint_pkt.size = size = avio_close_dyn_buf(hintbuf, &buf); hint_pkt.data = buf; hint_pkt.pts = hint_pkt.dts; hint_pkt.stream_index = track_index; if (pkt->flags & AV_PKT_FLAG_KEY) hint_pkt.flags |= AV_PKT_FLAG_KEY; if (count > 0) ff_mov_write_packet(s, &hint_pkt); done: av_free(buf); sample_queue_retain(&trk->sample_queue); return ret; }
26,343
FFmpeg
a4d3cf10b2ece441ae25849a66b1c11d838f9381
0
static void decode_lowdelay(DiracContext *s) { AVCodecContext *avctx = s->avctx; int slice_x, slice_y, bytes, bufsize; const uint8_t *buf; struct lowdelay_slice *slices; int slice_num = 0; slices = av_mallocz_array(s->lowdelay.num_x, s->lowdelay.num_y * sizeof(struct lowdelay_slice)); align_get_bits(&s->gb); /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */ buf = s->gb.buffer + get_bits_count(&s->gb)/8; bufsize = get_bits_left(&s->gb); for (slice_y = 0; bufsize > 0 && slice_y < s->lowdelay.num_y; slice_y++) for (slice_x = 0; bufsize > 0 && slice_x < s->lowdelay.num_x; slice_x++) { bytes = (slice_num+1) * s->lowdelay.bytes.num / s->lowdelay.bytes.den - slice_num * s->lowdelay.bytes.num / s->lowdelay.bytes.den; slices[slice_num].bytes = bytes; slices[slice_num].slice_x = slice_x; slices[slice_num].slice_y = slice_y; init_get_bits(&slices[slice_num].gb, buf, bufsize); slice_num++; buf += bytes; bufsize -= bytes*8; } avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num, sizeof(struct lowdelay_slice)); /* [DIRAC_STD] 13.5.2 Slices */ intra_dc_prediction(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ av_free(slices); }
26,344
FFmpeg
b7e7ee6231bc1f3608ed4005c3e7550ec4815296
1
static void copy_video_props(AVFilterBufferRefVideoProps *dst, AVFilterBufferRefVideoProps *src) { *dst = *src; if (src->qp_table) { int qsize = src->qp_table_size; dst->qp_table = av_malloc(qsize); memcpy(dst->qp_table, src->qp_table, qsize); } }
26,345
qemu
111049a4ecefc9cf1ac75c773f4c5c165f27fe63
1
void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) { do_blockdev_backup(arg, NULL, errp); }
26,347
FFmpeg
3c6607eb6f946ed3e108db3f0694cab7e5a5df7e
1
int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { int ret; int user_packet = !!avpkt->data; int nb_samples; *got_packet_ptr = 0; if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { av_free_packet(avpkt); av_init_packet(avpkt); avpkt->size = 0; return 0; } /* check for valid frame size */ if (frame) { nb_samples = frame->nb_samples; if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { if (nb_samples > avctx->frame_size) return AVERROR(EINVAL); } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) { if (nb_samples != avctx->frame_size) return AVERROR(EINVAL); } } else { nb_samples = avctx->frame_size; } if (avctx->codec->encode2) { ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); if (!ret && *got_packet_ptr) { if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { if (avpkt->pts == AV_NOPTS_VALUE) avpkt->pts = frame->pts; if (!avpkt->duration) avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); } avpkt->dts = avpkt->pts; } else { avpkt->size = 0; } } else { /* for compatibility with encoders not supporting encode2(), we need to allocate a packet buffer if the user has not provided one or check the size otherwise */ int fs_tmp = 0; int buf_size = avpkt->size; if (!user_packet) { if (avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) { av_assert0(av_get_bits_per_sample(avctx->codec_id) != 0); buf_size = nb_samples * avctx->channels * av_get_bits_per_sample(avctx->codec_id) / 8; } else { /* this is a guess as to the required size. if an encoder needs more than this, it should probably implement encode2() */ buf_size = 2 * avctx->frame_size * avctx->channels * av_get_bytes_per_sample(avctx->sample_fmt); buf_size += FF_MIN_BUFFER_SIZE; } } if ((ret = ff_alloc_packet(avpkt, buf_size))) return ret; /* Encoders using AVCodec.encode() that support CODEC_CAP_SMALL_LAST_FRAME require avctx->frame_size to be set to the smaller size when encoding the last frame. This code can be removed once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use encode2() */ if ((avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) && nb_samples < avctx->frame_size) { fs_tmp = avctx->frame_size; avctx->frame_size = nb_samples; } /* encode the frame */ ret = avctx->codec->encode(avctx, avpkt->data, avpkt->size, frame ? frame->data[0] : NULL); if (ret >= 0) { if (!ret) { /* no output. if the packet data was allocated by libavcodec, free it */ if (!user_packet) av_freep(&avpkt->data); } else { if (avctx->coded_frame) avpkt->pts = avpkt->dts = avctx->coded_frame->pts; /* Set duration for final small packet. This can be removed once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use encode2() */ if (fs_tmp) { avpkt->duration = ff_samples_to_time_base(avctx, avctx->frame_size); } } avpkt->size = ret; *got_packet_ptr = (ret > 0); ret = 0; } if (fs_tmp) avctx->frame_size = fs_tmp; } if (!ret) { if (!user_packet && avpkt->data) { uint8_t *new_data = av_realloc(avpkt->data, avpkt->size); if (new_data) avpkt->data = new_data; } avctx->frame_number++; } if (ret < 0 || !*got_packet_ptr) av_free_packet(avpkt); /* NOTE: if we add any audio encoders which output non-keyframe packets, this needs to be moved to the encoders, but for now we can do it here to simplify things */ avpkt->flags |= AV_PKT_FLAG_KEY; return ret; }
26,348
qemu
70fbd3c4bf9850fce733eea2c910c397905fb9a3
1
static void fsl_imx6_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); dc->realize = fsl_imx6_realize; dc->desc = "i.MX6 SOC"; }
26,349
qemu
2ad645d2854746b55ddfd1d8e951f689cca5d78f
1
static void test_endianness_split(gconstpointer data) { const TestCase *test = data; char *args; args = g_strdup_printf("-display none -M %s%s%s -device pc-testdev", test->machine, test->superio ? " -device " : "", test->superio ?: ""); qtest_start(args); isa_outl(test, 0xe8, 0x87654321); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321); isa_outw(test, 0xea, 0x8866); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664321); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321); isa_outw(test, 0xe8, 0x4422); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664422); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422); isa_outb(test, 0xeb, 0x87); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87664422); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8766); isa_outb(test, 0xea, 0x65); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654422); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422); isa_outb(test, 0xe9, 0x43); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654322); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4322); isa_outb(test, 0xe8, 0x21); g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321); g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765); g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321); qtest_quit(global_qtest); g_free(args); }
26,350
qemu
47d4be12c3997343e436c6cca89aefbbbeb70863
1
static void test_qemu_strtoull_whitespace(void) { const char *str = " \t "; char f = 'X'; const char *endptr = &f; uint64_t res = 999; int err; err = qemu_strtoull(str, &endptr, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, 0); g_assert(endptr == str); }
26,351
FFmpeg
3c1199c3c4cbdb4ffff0de89f06d5a08acefe356
1
static int matroska_parse_frame(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int pkt_size, uint64_t timecode, uint64_t duration, int64_t pos, int is_keyframe) { MatroskaTrackEncoding *encodings = track->encodings.elem; uint8_t *pkt_data = data; int offset = 0, res; AVPacket *pkt; if (encodings && encodings->scope & 1) { res = matroska_decode_buffer(&pkt_data, &pkt_size, track); if (res < 0) return res; } if (st->codec->codec_id == AV_CODEC_ID_WAVPACK) { uint8_t *wv_data; res = matroska_parse_wavpack(track, pkt_data, &wv_data, &pkt_size); if (res < 0) { av_log(matroska->ctx, AV_LOG_ERROR, "Error parsing a wavpack block.\n"); goto fail; } if (pkt_data != data) pkt_data = wv_data; } if (st->codec->codec_id == AV_CODEC_ID_PRORES) offset = 8; pkt = av_mallocz(sizeof(AVPacket)); /* XXX: prevent data copy... */ if (av_new_packet(pkt, pkt_size + offset) < 0) { av_free(pkt); return AVERROR(ENOMEM); } if (st->codec->codec_id == AV_CODEC_ID_PRORES) { uint8_t *buf = pkt->data; bytestream_put_be32(&buf, pkt_size); bytestream_put_be32(&buf, MKBETAG('i', 'c', 'p', 'f')); } memcpy(pkt->data + offset, pkt_data, pkt_size); if (pkt_data != data) av_free(pkt_data); pkt->flags = is_keyframe; pkt->stream_index = st->index; if (track->ms_compat) pkt->dts = timecode; else pkt->pts = timecode; pkt->pos = pos; if (st->codec->codec_id == AV_CODEC_ID_TEXT) pkt->convergence_duration = duration; else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE) pkt->duration = duration; if (st->codec->codec_id == AV_CODEC_ID_SSA) matroska_fix_ass_packet(matroska, pkt, duration); if (matroska->prev_pkt && timecode != AV_NOPTS_VALUE && matroska->prev_pkt->pts == timecode && matroska->prev_pkt->stream_index == st->index && st->codec->codec_id == AV_CODEC_ID_SSA) matroska_merge_packets(matroska->prev_pkt, pkt); else { dynarray_add(&matroska->packets, &matroska->num_packets, pkt); matroska->prev_pkt = pkt; } return 0; fail: if (pkt_data != data) return res; }
26,352
FFmpeg
0ecca7a49f8e254c12a3a1de048d738bfbb614c6
1
void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) { if(min_size < *size) return ptr; *size= 17*min_size/16 + 32; return av_realloc(ptr, *size); }
26,353
FFmpeg
26c208cf0ff59efd7786528884a64d35fc42e9bf
0
static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial) { int got_picture; if (packet_queue_get(&is->videoq, pkt, 1, serial) < 0) return -1; if (pkt->data == flush_pkt.data) { avcodec_flush_buffers(is->video_st->codec); SDL_LockMutex(is->pictq_mutex); // Make sure there are no long delay timers (ideally we should just flush the queue but that's harder) while (is->pictq_size && !is->videoq.abort_request) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } is->video_current_pos = -1; is->frame_last_pts = AV_NOPTS_VALUE; is->frame_last_duration = 0; is->frame_timer = (double)av_gettime() / 1000000.0; is->frame_last_dropped_pts = AV_NOPTS_VALUE; SDL_UnlockMutex(is->pictq_mutex); return 0; } if(avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt) < 0) return 0; if (got_picture) { int ret = 1; if (decoder_reorder_pts == -1) { *pts = av_frame_get_best_effort_timestamp(frame); } else if (decoder_reorder_pts) { *pts = frame->pkt_pts; } else { *pts = frame->pkt_dts; } if (*pts == AV_NOPTS_VALUE) { *pts = 0; } if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) { SDL_LockMutex(is->pictq_mutex); if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) { double clockdiff = get_video_clock(is) - get_master_clock(is); double dpts = av_q2d(is->video_st->time_base) * *pts; double ptsdiff = dpts - is->frame_last_pts; if (fabs(clockdiff) < AV_NOSYNC_THRESHOLD && ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD && clockdiff + ptsdiff - is->frame_last_filter_delay < 0) { is->frame_last_dropped_pos = pkt->pos; is->frame_last_dropped_pts = dpts; is->frame_drops_early++; ret = 0; } } SDL_UnlockMutex(is->pictq_mutex); } return ret; } return 0; }
26,354
qemu
9a93b61730e3b46ef1c01ca522c6abe80ec13832
1
static void msix_mmio_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { PCIDevice *dev = opaque; unsigned int offset = addr & (MSIX_PAGE_SIZE - 1) & ~0x3; int vector = offset / PCI_MSIX_ENTRY_SIZE; pci_set_long(dev->msix_table_page + offset, val); msix_handle_mask_update(dev, vector);
26,355
qemu
bdd81addf4033ce26e6cd180b060f63095f3ded9
1
static void vfio_msix_enable(VFIOPCIDevice *vdev) { vfio_disable_interrupts(vdev); vdev->msi_vectors = g_malloc0(vdev->msix->entries * sizeof(VFIOMSIVector)); vdev->interrupt = VFIO_INT_MSIX; /* * Some communication channels between VF & PF or PF & fw rely on the * physical state of the device and expect that enabling MSI-X from the * guest enables the same on the host. When our guest is Linux, the * guest driver call to pci_enable_msix() sets the enabling bit in the * MSI-X capability, but leaves the vector table masked. We therefore * can't rely on a vector_use callback (from request_irq() in the guest) * to switch the physical device into MSI-X mode because that may come a * long time after pci_enable_msix(). This code enables vector 0 with * triggering to userspace, then immediately release the vector, leaving * the physical device with no vectors enabled, but MSI-X enabled, just * like the guest view. */ vfio_msix_vector_do_use(&vdev->pdev, 0, NULL, NULL); vfio_msix_vector_release(&vdev->pdev, 0); if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, vfio_msix_vector_release, NULL)) { error_report("vfio: msix_set_vector_notifiers failed"); } trace_vfio_msix_enable(vdev->vbasedev.name); }
26,356
qemu
cfd47a71df51047833d182e9e97244e7816b57da
1
static int check_bind(struct sockaddr *sa, socklen_t salen, bool *has_proto) { int fd; fd = socket(sa->sa_family, SOCK_STREAM, 0); if (fd < 0) { return -1; } if (bind(fd, sa, salen) < 0) { close(fd); if (errno == EADDRNOTAVAIL) { *has_proto = false; return 0; } return -1; } close(fd); *has_proto = true; return 0; }
26,357
FFmpeg
b9fa32082c71013e90eab9e9997967d2939cf4a6
1
int ff_fft_init(FFTContext *s, int nbits, int inverse) { int i, j, m, n; float alpha, c1, s1, s2; int shuffle = 0; int av_unused has_vectors; s->nbits = nbits; n = 1 << nbits; s->exptab = av_malloc((n / 2) * sizeof(FFTComplex)); if (!s->exptab) goto fail; s->revtab = av_malloc(n * sizeof(uint16_t)); if (!s->revtab) goto fail; s->inverse = inverse; s2 = inverse ? 1.0 : -1.0; for(i=0;i<(n/2);i++) { alpha = 2 * M_PI * (float)i / (float)n; c1 = cos(alpha); s1 = sin(alpha) * s2; s->exptab[i].re = c1; s->exptab[i].im = s1; } s->fft_calc = ff_fft_calc_c; s->imdct_calc = ff_imdct_calc; s->imdct_half = ff_imdct_half; s->exptab1 = NULL; #ifdef HAVE_MMX has_vectors = mm_support(); shuffle = 1; if (has_vectors & MM_3DNOWEXT) { /* 3DNowEx for K7/K8 */ s->imdct_calc = ff_imdct_calc_3dn2; s->fft_calc = ff_fft_calc_3dn2; } else if (has_vectors & MM_3DNOW) { /* 3DNow! for K6-2/3 */ s->fft_calc = ff_fft_calc_3dn; } else if (has_vectors & MM_SSE) { /* SSE for P3/P4 */ s->imdct_calc = ff_imdct_calc_sse; s->imdct_half = ff_imdct_half_sse; s->fft_calc = ff_fft_calc_sse; } else { shuffle = 0; } #elif defined HAVE_ALTIVEC && !defined ALTIVEC_USE_REFERENCE_C_CODE has_vectors = mm_support(); if (has_vectors & MM_ALTIVEC) { s->fft_calc = ff_fft_calc_altivec; shuffle = 1; } #endif /* compute constant table for HAVE_SSE version */ if (shuffle) { int np, nblocks, np2, l; FFTComplex *q; np = 1 << nbits; nblocks = np >> 3; np2 = np >> 1; s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex)); if (!s->exptab1) goto fail; q = s->exptab1; do { for(l = 0; l < np2; l += 2 * nblocks) { *q++ = s->exptab[l]; *q++ = s->exptab[l + nblocks]; q->re = -s->exptab[l].im; q->im = s->exptab[l].re; q++; q->re = -s->exptab[l + nblocks].im; q->im = s->exptab[l + nblocks].re; q++; } nblocks = nblocks >> 1; } while (nblocks != 0); av_freep(&s->exptab); } /* compute bit reverse table */ for(i=0;i<n;i++) { m=0; for(j=0;j<nbits;j++) { m |= ((i >> j) & 1) << (nbits-j-1); } s->revtab[i]=m; } return 0; fail: av_freep(&s->revtab); av_freep(&s->exptab); av_freep(&s->exptab1); return -1; }
26,358
FFmpeg
45daae06fd6f05baddb897686a6fa90cda3abb49
0
static void write_mainheader(NUTContext *nut, AVIOContext *bc) { int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx; int64_t tmp_match; ff_put_v(bc, nut->version); if (nut->version > 3) ff_put_v(bc, nut->minor_version); ff_put_v(bc, nut->avf->nb_streams); ff_put_v(bc, nut->max_distance); ff_put_v(bc, nut->time_base_count); for (i = 0; i < nut->time_base_count; i++) { ff_put_v(bc, nut->time_base[i].num); ff_put_v(bc, nut->time_base[i].den); } tmp_pts = 0; tmp_mul = 1; tmp_stream = 0; tmp_match = 1 - (1LL << 62); tmp_head_idx = 0; for (i = 0; i < 256; ) { tmp_fields = 0; tmp_size = 0; // tmp_res=0; if (tmp_pts != nut->frame_code[i].pts_delta ) tmp_fields = 1; if (tmp_mul != nut->frame_code[i].size_mul ) tmp_fields = 2; if (tmp_stream != nut->frame_code[i].stream_id ) tmp_fields = 3; if (tmp_size != nut->frame_code[i].size_lsb ) tmp_fields = 4; // if (tmp_res != nut->frame_code[i].res ) tmp_fields=5; if (tmp_head_idx != nut->frame_code[i].header_idx) tmp_fields = 8; tmp_pts = nut->frame_code[i].pts_delta; tmp_flags = nut->frame_code[i].flags; tmp_stream = nut->frame_code[i].stream_id; tmp_mul = nut->frame_code[i].size_mul; tmp_size = nut->frame_code[i].size_lsb; // tmp_res = nut->frame_code[i].res; tmp_head_idx = nut->frame_code[i].header_idx; for (j = 0; i < 256; j++, i++) { if (i == 'N') { j--; continue; } if (nut->frame_code[i].pts_delta != tmp_pts || nut->frame_code[i].flags != tmp_flags || nut->frame_code[i].stream_id != tmp_stream || nut->frame_code[i].size_mul != tmp_mul || nut->frame_code[i].size_lsb != tmp_size + j || // nut->frame_code[i].res != tmp_res || nut->frame_code[i].header_idx != tmp_head_idx) break; } if (j != tmp_mul - tmp_size) tmp_fields = 6; ff_put_v(bc, tmp_flags); ff_put_v(bc, tmp_fields); if (tmp_fields > 0) put_s(bc, tmp_pts); if (tmp_fields > 1) ff_put_v(bc, tmp_mul); if (tmp_fields > 2) ff_put_v(bc, tmp_stream); if (tmp_fields > 3) ff_put_v(bc, tmp_size); if (tmp_fields > 4) ff_put_v(bc, 0 /*tmp_res*/); if (tmp_fields > 5) ff_put_v(bc, j); if (tmp_fields > 6) ff_put_v(bc, tmp_match); if (tmp_fields > 7) ff_put_v(bc, tmp_head_idx); } ff_put_v(bc, nut->header_count - 1); for (i = 1; i < nut->header_count; i++) { ff_put_v(bc, nut->header_len[i]); avio_write(bc, nut->header[i], nut->header_len[i]); } // flags had been effectively introduced in version 4 if (nut->version > NUT_STABLE_VERSION) ff_put_v(bc, nut->flags); }
26,359
qemu
a1f7f97b950a46393b0e55a9a0082e70f540cbbd
1
static void mmubooke_create_initial_mapping(CPUPPCState *env, target_ulong va, hwaddr pa) { ppcemb_tlb_t *tlb = &env->tlb.tlbe[0]; tlb->attr = 0; tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); tlb->size = 1 << 31; /* up to 0x80000000 */ tlb->EPN = va & TARGET_PAGE_MASK; tlb->RPN = pa & TARGET_PAGE_MASK; tlb->PID = 0; tlb = &env->tlb.tlbe[1]; tlb->attr = 0; tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); tlb->size = 1 << 31; /* up to 0xffffffff */ tlb->EPN = 0x80000000 & TARGET_PAGE_MASK; tlb->RPN = 0x80000000 & TARGET_PAGE_MASK; tlb->PID = 0; }
26,361
qemu
187337f8b0ec0813dd3876d1efe37d415fb81c2e
1
struct pxa2xx_pcmcia_s *pxa2xx_pcmcia_init(target_phys_addr_t base) { int iomemtype; struct pxa2xx_pcmcia_s *s; s = (struct pxa2xx_pcmcia_s *) qemu_mallocz(sizeof(struct pxa2xx_pcmcia_s)); /* Socket I/O Memory Space */ s->io_base = base | 0x00000000; iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_io_readfn, pxa2xx_pcmcia_io_writefn, s); cpu_register_physical_memory(s->io_base, 0x03ffffff, iomemtype); /* Then next 64 MB is reserved */ /* Socket Attribute Memory Space */ s->attr_base = base | 0x08000000; iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_attr_readfn, pxa2xx_pcmcia_attr_writefn, s); cpu_register_physical_memory(s->attr_base, 0x03ffffff, iomemtype); /* Socket Common Memory Space */ s->common_base = base | 0x0c000000; iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_common_readfn, pxa2xx_pcmcia_common_writefn, s); cpu_register_physical_memory(s->common_base, 0x03ffffff, iomemtype); if (base == 0x30000000) s->slot.slot_string = "PXA PC Card Socket 1"; else s->slot.slot_string = "PXA PC Card Socket 0"; s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0]; pcmcia_socket_register(&s->slot); return s; }
26,362
FFmpeg
bac9c03ed9328c63aba46e280ba408431b53fcb4
1
static int mov_text_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt) { AVSubtitle *sub = data; MovTextContext *m = avctx->priv_data; int ret; AVBPrint buf; char *ptr = avpkt->data; char *end; int text_length, tsmb_type, ret_tsmb; uint64_t tsmb_size; const uint8_t *tsmb; if (!ptr || avpkt->size < 2) return AVERROR_INVALIDDATA; /* * A packet of size two with value zero is an empty subtitle * used to mark the end of the previous non-empty subtitle. * We can just drop them here as we have duration information * already. If the value is non-zero, then it's technically a * bad packet. */ if (avpkt->size == 2) return AV_RB16(ptr) == 0 ? 0 : AVERROR_INVALIDDATA; /* * The first two bytes of the packet are the length of the text string * In complex cases, there are style descriptors appended to the string * so we can't just assume the packet size is the string size. */ text_length = AV_RB16(ptr); end = ptr + FFMIN(2 + text_length, avpkt->size); ptr += 2; tsmb_size = 0; m->tracksize = 2 + text_length; m->style_entries = 0; m->box_flags = 0; m->count_s = 0; // Note that the spec recommends lines be no longer than 2048 characters. av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); if (text_length + 2 != avpkt->size) { while (m->tracksize + 8 <= avpkt->size) { // A box is a minimum of 8 bytes. tsmb = ptr + m->tracksize - 2; tsmb_size = AV_RB32(tsmb); tsmb += 4; tsmb_type = AV_RB32(tsmb); tsmb += 4; if (tsmb_size == 1) { if (m->tracksize + 16 > avpkt->size) break; tsmb_size = AV_RB64(tsmb); tsmb += 8; m->size_var = 16; } else m->size_var = 8; //size_var is equal to 8 or 16 depending on the size of box if (tsmb_size == 0) { av_log(avctx, AV_LOG_ERROR, "tsmb_size is 0\n"); return AVERROR_INVALIDDATA; } if (tsmb_size > avpkt->size - m->tracksize) break; for (size_t i = 0; i < box_count; i++) { if (tsmb_type == box_types[i].type) { if (m->tracksize + m->size_var + box_types[i].base_size > avpkt->size) break; ret_tsmb = box_types[i].decode(tsmb, m, avpkt); if (ret_tsmb == -1) break; } } m->tracksize = m->tracksize + tsmb_size; } text_to_ass(&buf, ptr, end, m); } else text_to_ass(&buf, ptr, end, m); ret = ff_ass_add_rect(sub, buf.str, m->readorder++, 0, NULL, NULL); av_bprint_finalize(&buf, NULL); if (ret < 0) return ret; *got_sub_ptr = sub->num_rects > 0; return avpkt->size; }
26,363
FFmpeg
53c0c637d36c1de9ea461a8d863e8703da090894
1
static int ra144_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; unsigned int refl_rms[NBLOCKS]; // RMS of the reflection coefficients int16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block unsigned int lpc_refl[LPC_ORDER]; // LPC reflection coefficients of the frame int i, j; int ret; int16_t *samples; unsigned int energy; RA144Context *ractx = avctx->priv_data; GetBitContext gb; if (buf_size < FRAME_SIZE) { av_log(avctx, AV_LOG_ERROR, "Frame too small (%d bytes). Truncated file?\n", buf_size); *got_frame_ptr = 0; return AVERROR_INVALIDDATA; } /* get output buffer */ frame->nb_samples = NBLOCKS * BLOCKSIZE; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; samples = (int16_t *)frame->data[0]; init_get_bits8(&gb, buf, FRAME_SIZE); for (i = 0; i < LPC_ORDER; i++) lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])]; ff_eval_coefs(ractx->lpc_coef[0], lpc_refl); ractx->lpc_refl_rms[0] = ff_rms(lpc_refl); energy = ff_energy_tab[get_bits(&gb, 5)]; refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy); refl_rms[1] = ff_interp(ractx, block_coefs[1], 2, energy <= ractx->old_energy, ff_t_sqrt(energy*ractx->old_energy) >> 12); refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy); refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy); ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]); for (i=0; i < NBLOCKS; i++) { do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb); for (j=0; j < BLOCKSIZE; j++) *samples++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2); } ractx->old_energy = energy; ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); *got_frame_ptr = 1; return FRAME_SIZE; }
26,364
qemu
5dd7a535b71a0f2f8e7af75c5d694174359ce323
1
static void iscsi_timed_set_events(void *opaque) { IscsiLun *iscsilun = opaque; iscsi_set_events(iscsilun); }
26,365
qemu
b307446e04232b3a87e9da04886895a8e5a4a407
1
void mips_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, int flags) { MIPSCPU *cpu = MIPS_CPU(cs); CPUMIPSState *env = &cpu->env; int i; cpu_fprintf(f, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " " TARGET_FMT_ld "\n", env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0], env->hflags, env->btarget, env->bcond); for (i = 0; i < 32; i++) { if ((i & 3) == 0) cpu_fprintf(f, "GPR%02d:", i); cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]); if ((i & 3) == 3) cpu_fprintf(f, "\n"); } cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n", env->CP0_Status, env->CP0_Cause, env->CP0_EPC); cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x%016" PRIx64 "\n", env->CP0_Config0, env->CP0_Config1, env->lladdr); cpu_fprintf(f, " Config2 0x%08x Config3 0x%08x\n", env->CP0_Config2, env->CP0_Config3); cpu_fprintf(f, " Config4 0x%08x Config5 0x%08x\n", env->CP0_Config4, env->CP0_Config5); if (env->hflags & MIPS_HFLAG_FPU) fpu_dump_state(env, f, cpu_fprintf, flags); #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS) cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags); #endif }
26,366
qemu
0d931d706266d6ada3bf22d3afca1afdc8d12fa9
1
static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) { SerialState *s = opaque; do { if (s->tsr_retry <= 0) { if (s->fcr & UART_FCR_FE) { if (fifo8_is_empty(&s->xmit_fifo)) { return FALSE; } s->tsr = fifo8_pop(&s->xmit_fifo); if (!s->xmit_fifo.num) { s->lsr |= UART_LSR_THRE; } } else if ((s->lsr & UART_LSR_THRE)) { return FALSE; } else { s->tsr = s->thr; s->lsr |= UART_LSR_THRE; s->lsr &= ~UART_LSR_TEMT; } } if (s->mcr & UART_MCR_LOOP) { /* in loopback mode, say that we just received a char */ serial_receive1(s, &s->tsr, 1); } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) { if (s->tsr_retry >= 0 && s->tsr_retry < MAX_XMIT_RETRY && qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, serial_xmit, s) > 0) { s->tsr_retry++; return FALSE; } s->tsr_retry = 0; } else { s->tsr_retry = 0; } /* Transmit another byte if it is already available. It is only possible when FIFO is enabled and not empty. */ } while ((s->fcr & UART_FCR_FE) && !fifo8_is_empty(&s->xmit_fifo)); s->last_xmit_ts = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); if (s->lsr & UART_LSR_THRE) { s->lsr |= UART_LSR_TEMT; s->thr_ipending = 1; serial_update_irq(s); } return FALSE; }
26,369
FFmpeg
95b192de5d05f3e1542e7b2378cdefbc195f5185
0
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) { v->res_rtm_flag = 1; v->level = get_bits(gb, 3); if (v->level >= 5) { av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level); } v->chromaformat = get_bits(gb, 2); if (v->chromaformat != 1) { av_log(v->s.avctx, AV_LOG_ERROR, "Only 4:2:0 chroma format supported\n"); return -1; } // (fps-2)/4 (->30) v->frmrtq_postproc = get_bits(gb, 3); //common // (bitrate-32kbps)/64kbps v->bitrtq_postproc = get_bits(gb, 5); //common v->postprocflag = get_bits1(gb); //common v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1; v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1; v->s.avctx->width = v->s.avctx->coded_width; v->s.avctx->height = v->s.avctx->coded_height; v->broadcast = get_bits1(gb); v->interlace = get_bits1(gb); v->tfcntrflag = get_bits1(gb); v->finterpflag = get_bits1(gb); skip_bits1(gb); // reserved av_log(v->s.avctx, AV_LOG_DEBUG, "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n" "TFCTRflag=%i, FINTERPflag=%i\n", v->level, v->frmrtq_postproc, v->bitrtq_postproc, v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace, v->tfcntrflag, v->finterpflag); v->psf = get_bits1(gb); if (v->psf) { //PsF, 6.1.13 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n"); return -1; } v->s.max_b_frames = v->s.avctx->max_b_frames = 7; if (get_bits1(gb)) { //Display Info - decoding is not affected by it int w, h, ar = 0; av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n"); w = get_bits(gb, 14) + 1; h = get_bits(gb, 14) + 1; av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h); if (get_bits1(gb)) ar = get_bits(gb, 4); if (ar && ar < 14) { v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar]; } else if (ar == 15) { w = get_bits(gb, 8) + 1; h = get_bits(gb, 8) + 1; v->s.avctx->sample_aspect_ratio = (AVRational){w, h}; } else { av_reduce(&v->s.avctx->sample_aspect_ratio.num, &v->s.avctx->sample_aspect_ratio.den, v->s.avctx->height * w, v->s.avctx->width * h, 1 << 30); } av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den); if (get_bits1(gb)) { //framerate stuff if (get_bits1(gb)) { v->s.avctx->time_base.num = 32; v->s.avctx->time_base.den = get_bits(gb, 16) + 1; } else { int nr, dr; nr = get_bits(gb, 8); dr = get_bits(gb, 4); if (nr && nr < 8 && dr && dr < 3) { v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1]; v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000; } } if (v->broadcast) { // Pulldown may be present v->s.avctx->time_base.den *= 2; v->s.avctx->ticks_per_frame = 2; } } if (get_bits1(gb)) { v->color_prim = get_bits(gb, 8); v->transfer_char = get_bits(gb, 8); v->matrix_coef = get_bits(gb, 8); } } v->hrd_param_flag = get_bits1(gb); if (v->hrd_param_flag) { int i; v->hrd_num_leaky_buckets = get_bits(gb, 5); skip_bits(gb, 4); //bitrate exponent skip_bits(gb, 4); //buffer size exponent for (i = 0; i < v->hrd_num_leaky_buckets; i++) { skip_bits(gb, 16); //hrd_rate[n] skip_bits(gb, 16); //hrd_buffer[n] } } return 0; }
26,370