target
int64
0
1
idx
int64
0
27.3k
func
stringlengths
23
97k
0
1,230
void qemu_set_fd_handler(int fd, IOHandler *fd_read, IOHandler *fd_write, void *opaque) { iohandler_init(); aio_set_fd_handler(iohandler_ctx, fd, false, fd_read, fd_write, NULL, opaque); }
0
1,231
static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr, uint64_t value, unsigned size, MemTxAttrs attrs) { NVICState *s = (NVICState *)opaque; uint32_t offset = addr; unsigned i, startvec, end; unsigned setval = 0; trace_nvic_sysreg_write(addr, value, size); if (attrs.user && !nvic_user_access_ok(s, addr)) { /* Generate BusFault for unprivileged accesses */ return MEMTX_ERROR; } switch (offset) { case 0x100 ... 0x13f: /* NVIC Set enable */ offset += 0x80; setval = 1; /* fall through */ case 0x180 ... 0x1bf: /* NVIC Clear enable */ startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ; for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { if (value & (1 << i)) { s->vectors[startvec + i].enabled = setval; } } nvic_irq_update(s); return MEMTX_OK; case 0x200 ... 0x23f: /* NVIC Set pend */ /* the special logic in armv7m_nvic_set_pending() * is not needed since IRQs are never escalated */ offset += 0x80; setval = 1; /* fall through */ case 0x280 ... 0x2bf: /* NVIC Clear pend */ startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { if (value & (1 << i)) { s->vectors[startvec + i].pending = setval; } } nvic_irq_update(s); return MEMTX_OK; case 0x300 ... 0x33f: /* NVIC Active */ return MEMTX_OK; /* R/O */ case 0x400 ... 0x5ef: /* NVIC Priority */ startvec = 8 * (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */ for (i = 0; i < size && startvec + i < s->num_irq; i++) { set_prio(s, startvec + i, (value >> (i * 8)) & 0xff); } nvic_irq_update(s); return MEMTX_OK; case 0xd18 ... 0xd23: /* System Handler Priority. */ for (i = 0; i < size; i++) { unsigned hdlidx = (offset - 0xd14) + i; set_prio(s, hdlidx, (value >> (i * 8)) & 0xff); } nvic_irq_update(s); return MEMTX_OK; } if (size == 4) { nvic_writel(s, offset, value); return MEMTX_OK; } qemu_log_mask(LOG_GUEST_ERROR, "NVIC: Bad write of size %d at offset 0x%x\n", size, offset); /* This is UNPREDICTABLE; treat as RAZ/WI */ return MEMTX_OK; }
0
1,232
static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index, hwaddr *nb, uint16_t leaf, int level) { PhysPageEntry *p; int i; hwaddr step = (hwaddr)1 << (level * P_L2_BITS); if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) { lp->ptr = phys_map_node_alloc(); p = next_map.nodes[lp->ptr]; if (level == 0) { for (i = 0; i < P_L2_SIZE; i++) { p[i].skip = 0; p[i].ptr = PHYS_SECTION_UNASSIGNED; } } } else { p = next_map.nodes[lp->ptr]; } lp = &p[(*index >> (level * P_L2_BITS)) & (P_L2_SIZE - 1)]; while (*nb && lp < &p[P_L2_SIZE]) { if ((*index & (step - 1)) == 0 && *nb >= step) { lp->skip = 0; lp->ptr = leaf; *index += step; *nb -= step; } else { phys_page_set_level(lp, index, nb, leaf, level - 1); } ++lp; } }
0
1,233
static void map_page(uint8_t **ptr, uint64_t addr, uint32_t wanted) { target_phys_addr_t len = wanted; if (*ptr) { cpu_physical_memory_unmap(*ptr, len, 1, len); } *ptr = cpu_physical_memory_map(addr, &len, 1); if (len < wanted) { cpu_physical_memory_unmap(*ptr, len, 1, len); *ptr = NULL; } }
0
1,234
static VmdkExtent *vmdk_add_extent(BlockDriverState *bs, BlockDriverState *file, bool flat, int64_t sectors, int64_t l1_offset, int64_t l1_backup_offset, uint32_t l1_size, int l2_size, unsigned int cluster_sectors) { VmdkExtent *extent; BDRVVmdkState *s = bs->opaque; s->extents = g_realloc(s->extents, (s->num_extents + 1) * sizeof(VmdkExtent)); extent = &s->extents[s->num_extents]; s->num_extents++; memset(extent, 0, sizeof(VmdkExtent)); extent->file = file; extent->flat = flat; extent->sectors = sectors; extent->l1_table_offset = l1_offset; extent->l1_backup_table_offset = l1_backup_offset; extent->l1_size = l1_size; extent->l1_entry_sectors = l2_size * cluster_sectors; extent->l2_size = l2_size; extent->cluster_sectors = cluster_sectors; if (s->num_extents > 1) { extent->end_sector = (*(extent - 1)).end_sector + extent->sectors; } else { extent->end_sector = extent->sectors; } bs->total_sectors = extent->end_sector; return extent; }
0
1,235
static void ppc_heathrow_init (int ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char **fd_filename, int snapshot, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { CPUState *env = NULL, *envs[MAX_CPUS]; char buf[1024]; qemu_irq *pic, **heathrow_irqs; nvram_t nvram; m48t59_t *m48t59; int linux_boot, i; unsigned long bios_offset, vga_bios_offset; uint32_t kernel_base, kernel_size, initrd_base, initrd_size; PCIBus *pci_bus; MacIONVRAMState *nvr; int vga_bios_size, bios_size; qemu_irq *dummy_irq; int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index; int ppc_boot_device = boot_device[0]; linux_boot = (kernel_filename != NULL); /* init CPUs */ if (cpu_model == NULL) cpu_model = "default"; for (i = 0; i < smp_cpus; i++) { env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } /* Set time-base frequency to 100 Mhz */ cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); env->osi_call = vga_osi_call; qemu_register_reset(&cpu_ppc_reset, env); register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); envs[i] = env; } if (env->nip < 0xFFF80000) { /* Special test for PowerPC 601: * the boot vector is at 0xFFF00100, then we need a 1MB BIOS. * But the NVRAM is located at 0xFFF04000... */ cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n"); } /* allocate RAM */ cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); /* allocate and load BIOS */ 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_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf); exit(1); } bios_size = (bios_size + 0xfff) & ~0xfff; if (bios_size > 0x00080000) { /* As the NVRAM is located at 0xFFF04000, we cannot use 1 MB BIOSes */ cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n"); } cpu_register_physical_memory((uint32_t)(-bios_size), bios_size, bios_offset | IO_MEM_ROM); /* allocate and load VGA BIOS */ vga_bios_offset = bios_offset + bios_size; snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8); if (vga_bios_size < 0) { /* if no bios is present, we can still work */ fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf); vga_bios_size = 0; } else { /* set a specific header (XXX: find real Apple format for NDRV drivers) */ phys_ram_base[vga_bios_offset] = 'N'; phys_ram_base[vga_bios_offset + 1] = 'D'; phys_ram_base[vga_bios_offset + 2] = 'R'; phys_ram_base[vga_bios_offset + 3] = 'V'; cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4), vga_bios_size); vga_bios_size += 8; } vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff; if (linux_boot) { kernel_base = KERNEL_LOAD_ADDR; /* now we can load the kernel */ kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); if (kernel_size < 0) { cpu_abort(env, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } /* load initrd */ if (initrd_filename) { initrd_base = INITRD_LOAD_ADDR; initrd_size = load_image(initrd_filename, phys_ram_base + initrd_base); if (initrd_size < 0) { cpu_abort(env, "qemu: could not load initial ram disk '%s'\n", initrd_filename); exit(1); } } else { initrd_base = 0; initrd_size = 0; } ppc_boot_device = 'm'; } else { kernel_base = 0; kernel_size = 0; initrd_base = 0; initrd_size = 0; } isa_mem_base = 0x80000000; /* Register 2 MB of ISA IO space */ isa_mmio_init(0xfe000000, 0x00200000); /* XXX: we register only 1 output pin for heathrow PIC */ heathrow_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *)); heathrow_irqs[0] = qemu_mallocz(smp_cpus * sizeof(qemu_irq) * 1); /* Connect the heathrow PIC outputs to the 6xx bus */ for (i = 0; i < smp_cpus; i++) { switch (PPC_INPUT(env)) { case PPC_FLAGS_INPUT_6xx: heathrow_irqs[i] = heathrow_irqs[0] + (i * 1); heathrow_irqs[i][0] = ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; break; default: cpu_abort(env, "Bus model not supported on OldWorld Mac machine\n"); exit(1); } } /* init basic PC hardware */ if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n"); exit(1); } pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs); pci_bus = pci_grackle_init(0xfec00000, pic); pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, ram_size, vga_ram_size, vga_bios_offset, vga_bios_size); /* XXX: suppress that */ dummy_irq = i8259_init(NULL); /* XXX: use Mac Serial port */ serial_init(0x3f8, dummy_irq[4], serial_hds[0]); for(i = 0; i < nb_nics; i++) { if (!nd_table[i].model) nd_table[i].model = "ne2k_pci"; pci_nic_init(pci_bus, &nd_table[i], -1); } pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); /* cuda also initialize ADB */ cuda_init(&cuda_mem_index, pic[0x12]); adb_kbd_init(&adb_bus); adb_mouse_init(&adb_bus); nvr = macio_nvram_init(&nvram_mem_index, 0x2000); pmac_format_nvram_partition(nvr, 0x2000); dbdma_init(&dbdma_mem_index); macio_init(pci_bus, 0x0017, 1, pic_mem_index, dbdma_mem_index, cuda_mem_index, nvr, 0, NULL); if (usb_enabled) { usb_ohci_init_pci(pci_bus, 3, -1); } if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) graphic_depth = 15; m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); nvram.opaque = m48t59; nvram.read_fn = &m48t59_read; nvram.write_fn = &m48t59_write; PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "HEATHROW", ram_size, ppc_boot_device, kernel_base, kernel_size, kernel_cmdline, initrd_base, initrd_size, /* XXX: need an option to load a NVRAM image */ 0, graphic_width, graphic_height, graphic_depth); /* No PCI init: the BIOS will do it */ /* Special port to get debug messages from Open-Firmware */ register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL); }
0
1,236
static void musicpal_gpio_write(void *opaque, target_phys_addr_t offset, uint64_t value, unsigned size) { musicpal_gpio_state *s = opaque; switch (offset) { case MP_GPIO_OE_HI: /* used for LCD brightness control */ s->lcd_brightness = (s->lcd_brightness & MP_GPIO_LCD_BRIGHTNESS) | (value & MP_OE_LCD_BRIGHTNESS); musicpal_gpio_brightness_update(s); break; case MP_GPIO_OUT_LO: s->out_state = (s->out_state & 0xFFFF0000) | (value & 0xFFFF); break; case MP_GPIO_OUT_HI: s->out_state = (s->out_state & 0xFFFF) | (value << 16); s->lcd_brightness = (s->lcd_brightness & 0xFFFF) | (s->out_state & MP_GPIO_LCD_BRIGHTNESS); musicpal_gpio_brightness_update(s); qemu_set_irq(s->out[3], (s->out_state >> MP_GPIO_I2C_DATA_BIT) & 1); qemu_set_irq(s->out[4], (s->out_state >> MP_GPIO_I2C_CLOCK_BIT) & 1); break; case MP_GPIO_IER_LO: s->ier = (s->ier & 0xFFFF0000) | (value & 0xFFFF); break; case MP_GPIO_IER_HI: s->ier = (s->ier & 0xFFFF) | (value << 16); break; case MP_GPIO_IMR_LO: s->imr = (s->imr & 0xFFFF0000) | (value & 0xFFFF); break; case MP_GPIO_IMR_HI: s->imr = (s->imr & 0xFFFF) | (value << 16); break; } }
0
1,237
static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, cavs_vector *src, int distp) { int den = h->scale_den[src->ref]; *d_x = (src->x * distp * den + 256 + (src->x >> 31)) >> 9; *d_y = (src->y * distp * den + 256 + (src->y >> 31)) >> 9; }
0
1,238
static int usb_wacom_handle_data(USBDevice *dev, USBPacket *p) { USBWacomState *s = (USBWacomState *) dev; uint8_t buf[p->iov.size]; int ret = 0; switch (p->pid) { case USB_TOKEN_IN: if (p->devep == 1) { if (!(s->changed || s->idle)) return USB_RET_NAK; s->changed = 0; if (s->mode == WACOM_MODE_HID) ret = usb_mouse_poll(s, buf, p->iov.size); else if (s->mode == WACOM_MODE_WACOM) ret = usb_wacom_poll(s, buf, p->iov.size); usb_packet_copy(p, buf, ret); break; } /* Fall through. */ case USB_TOKEN_OUT: default: ret = USB_RET_STALL; break; } return ret; }
0
1,239
RGB_FUNCTIONS(rgb565) #undef RGB_IN #undef RGB_OUT #undef BPP /* bgr24 handling */ #define RGB_IN(r, g, b, s)\ {\ b = (s)[0];\ g = (s)[1];\ r = (s)[2];\ } #define RGB_OUT(d, r, g, b)\ {\ (d)[0] = b;\ (d)[1] = g;\ (d)[2] = r;\ } #define BPP 3 RGB_FUNCTIONS(bgr24) #undef RGB_IN #undef RGB_OUT #undef BPP /* rgb24 handling */ #define RGB_IN(r, g, b, s)\ {\ r = (s)[0];\ g = (s)[1];\ b = (s)[2];\ } #define RGB_OUT(d, r, g, b)\ {\ (d)[0] = r;\ (d)[1] = g;\ (d)[2] = b;\ } #define BPP 3 RGB_FUNCTIONS(rgb24) static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src, int width, int height) { uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1; int w, y, cb, cr, r_add, g_add, b_add; uint8_t *cm = cropTbl + MAX_NEG_CROP; unsigned int r, g, b; d = dst->data[0]; y1_ptr = src->data[0]; cb_ptr = src->data[1]; cr_ptr = src->data[2]; for(;height > 0; height --) { d1 = d; for(w = width; w > 0; w--) { YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]); YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]); RGB_OUT(d1, r, g, b); d1 += BPP; y1_ptr++; cb_ptr++; cr_ptr++; } d += dst->linesize[0]; y1_ptr += src->linesize[0] - width; cb_ptr += src->linesize[1] - width; cr_ptr += src->linesize[2] - width; } }
0
1,240
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f) { AudioFrame *new_frame; AudioFrame *queue_end = afq->frame_queue; /* find the end of the queue */ while (queue_end && queue_end->next) queue_end = queue_end->next; /* allocate new frame queue entry */ if (!(new_frame = av_malloc(sizeof(*new_frame)))) return AVERROR(ENOMEM); /* get frame parameters */ new_frame->next = NULL; new_frame->duration = f->nb_samples; if (f->pts != AV_NOPTS_VALUE) { new_frame->pts = av_rescale_q(f->pts, afq->avctx->time_base, (AVRational){ 1, afq->avctx->sample_rate }); afq->next_pts = new_frame->pts + new_frame->duration; } else { new_frame->pts = AV_NOPTS_VALUE; afq->next_pts = AV_NOPTS_VALUE; } /* add new frame to the end of the queue */ if (!queue_end) afq->frame_queue = new_frame; else queue_end->next = new_frame; /* add frame sample count */ afq->remaining_samples += f->nb_samples; #ifdef DEBUG ff_af_queue_log_state(afq); #endif return 0; }
0
1,241
yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target) { const uint8_t * const d128 = dither_8x8_220[y & 7]; int i; if (c->flags & SWS_ERROR_DIFFUSION) { int err = 0; int acc = 0; for (i = 0; i < dstW; i +=2) { int Y; Y = ((buf0[i + 0] + 64) >> 7); Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4; c->dither_error[0][i] = err; acc = 2*acc + (Y >= 128); Y -= 220*(acc&1); err = ((buf0[i + 1] + 64) >> 7); err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4; c->dither_error[0][i+1] = Y; acc = 2*acc + (err >= 128); err -= 220*(acc&1); if ((i & 7) == 6) output_pixel(*dest++, acc); } c->dither_error[0][i] = err; } else { for (i = 0; i < dstW; i += 8) { int acc = 0; accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]); accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]); accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]); accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]); accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]); accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]); accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]); accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]); output_pixel(*dest++, acc); } } }
0
1,242
static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask, bool exception) { sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); sPAPREventLogEntry *entry = NULL; /* we only queue EPOW events atm. */ if ((event_mask & EVENT_MASK_EPOW) == 0) { return NULL; } QTAILQ_FOREACH(entry, &spapr->pending_events, next) { if (entry->exception != exception) { continue; } /* EPOW and hotplug events are surfaced in the same manner */ if (entry->log_type == RTAS_LOG_TYPE_EPOW || entry->log_type == RTAS_LOG_TYPE_HOTPLUG) { break; } } if (entry) { QTAILQ_REMOVE(&spapr->pending_events, entry, next); } return entry; }
0
1,243
static int spapr_check_htab_fd(sPAPRMachineState *spapr) { int rc = 0; if (spapr->htab_fd_stale) { close(spapr->htab_fd); spapr->htab_fd = kvmppc_get_htab_fd(false); if (spapr->htab_fd < 0) { error_report("Unable to open fd for reading hash table from KVM: " "%s", strerror(errno)); rc = -1; } spapr->htab_fd_stale = false; } return rc; }
0
1,244
static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BDRVRawState *s = bs->opaque; void *buf = NULL; BlockDriver *drv; QEMUIOVector local_qiov; int ret; if (s->has_size && (offset > s->size || bytes > (s->size - offset))) { /* There's not enough space for the data. Don't write anything and just * fail to prevent leaking out of the size specified in options. */ return -ENOSPC; } if (offset > UINT64_MAX - s->offset) { ret = -EINVAL; goto fail; } if (bs->probed && offset < BLOCK_PROBE_BUF_SIZE && bytes) { /* Handling partial writes would be a pain - so we just * require that guests have 512-byte request alignment if * probing occurred */ QEMU_BUILD_BUG_ON(BLOCK_PROBE_BUF_SIZE != 512); QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != 512); assert(offset == 0 && bytes >= BLOCK_PROBE_BUF_SIZE); buf = qemu_try_blockalign(bs->file->bs, 512); if (!buf) { ret = -ENOMEM; goto fail; } ret = qemu_iovec_to_buf(qiov, 0, buf, 512); if (ret != 512) { ret = -EINVAL; goto fail; } drv = bdrv_probe_all(buf, 512, NULL); if (drv != bs->drv) { ret = -EPERM; goto fail; } /* Use the checked buffer, a malicious guest might be overwriting its * original buffer in the background. */ qemu_iovec_init(&local_qiov, qiov->niov + 1); qemu_iovec_add(&local_qiov, buf, 512); qemu_iovec_concat(&local_qiov, qiov, 512, qiov->size - 512); qiov = &local_qiov; } offset += s->offset; BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); fail: if (qiov == &local_qiov) { qemu_iovec_destroy(&local_qiov); } qemu_vfree(buf); return ret; }
0
1,245
void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size) { if (xen_enabled()) { return xen_map_cache(addr, *size, 1); } else { RAMBlock *block; QLIST_FOREACH(block, &ram_list.blocks, next) { if (addr - block->offset < block->length) { if (addr - block->offset + *size > block->length) *size = block->length - addr + block->offset; return block->host + (addr - block->offset); } } fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr); abort(); *size = 0; return NULL; } }
0
1,246
static void *qemu_dummy_cpu_thread_fn(void *arg) { #ifdef _WIN32 fprintf(stderr, "qtest is not supported under Windows\n"); exit(1); #else CPUState *cpu = arg; sigset_t waitset; int r; qemu_mutex_lock_iothread(); qemu_thread_get_self(cpu->thread); cpu->thread_id = qemu_get_thread_id(); cpu->exception_index = -1; cpu->can_do_io = 1; sigemptyset(&waitset); sigaddset(&waitset, SIG_IPI); /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); current_cpu = cpu; while (1) { current_cpu = NULL; qemu_mutex_unlock_iothread(); do { int sig; r = sigwait(&waitset, &sig); } while (r == -1 && (errno == EAGAIN || errno == EINTR)); if (r == -1) { perror("sigwait"); exit(1); } qemu_mutex_lock_iothread(); current_cpu = cpu; qemu_wait_io_event_common(cpu); } return NULL; #endif }
0
1,247
static void acpi_get_hotplug_info(AcpiMiscInfo *misc) { int i; PCIBus *bus = find_i440fx(); if (!bus) { /* Only PIIX supports ACPI hotplug */ memset(misc->slot_hotplug_enable, 0, sizeof misc->slot_hotplug_enable); return; } memset(misc->slot_hotplug_enable, 0xff, DIV_ROUND_UP(PCI_SLOT_MAX, BITS_PER_BYTE)); for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) { PCIDeviceClass *pc; PCIDevice *pdev = bus->devices[i]; if (!pdev) { continue; } pc = PCI_DEVICE_GET_CLASS(pdev); if (pc->no_hotplug) { int slot = PCI_SLOT(i); clear_bit(slot, misc->slot_hotplug_enable); } } }
0
1,248
static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *spapr) { int ret = 0, offset, cpus_offset; CPUState *cs; char cpu_model[32]; int smt = kvmppc_smt_threads(); uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)}; CPU_FOREACH(cs) { PowerPCCPU *cpu = POWERPC_CPU(cs); DeviceClass *dc = DEVICE_GET_CLASS(cs); int index = spapr_vcpu_id(cpu); int compat_smt = MIN(smp_threads, ppc_compat_max_threads(cpu)); if ((index % smt) != 0) { continue; } snprintf(cpu_model, 32, "%s@%x", dc->fw_name, index); cpus_offset = fdt_path_offset(fdt, "/cpus"); if (cpus_offset < 0) { cpus_offset = fdt_add_subnode(fdt, 0, "cpus"); if (cpus_offset < 0) { return cpus_offset; } } offset = fdt_subnode_offset(fdt, cpus_offset, cpu_model); if (offset < 0) { offset = fdt_add_subnode(fdt, cpus_offset, cpu_model); if (offset < 0) { return offset; } } ret = fdt_setprop(fdt, offset, "ibm,pft-size", pft_size_prop, sizeof(pft_size_prop)); if (ret < 0) { return ret; } if (nb_numa_nodes > 1) { ret = spapr_fixup_cpu_numa_dt(fdt, offset, cpu); if (ret < 0) { return ret; } } ret = spapr_fixup_cpu_smt_dt(fdt, offset, cpu, compat_smt); if (ret < 0) { return ret; } spapr_populate_pa_features(cpu, fdt, offset, spapr->cas_legacy_guest_workaround); } return ret; }
0
1,250
void subch_device_save(SubchDev *s, QEMUFile *f) { int i; qemu_put_byte(f, s->cssid); qemu_put_byte(f, s->ssid); qemu_put_be16(f, s->schid); qemu_put_be16(f, s->devno); qemu_put_byte(f, s->thinint_active); /* SCHIB */ /* PMCW */ qemu_put_be32(f, s->curr_status.pmcw.intparm); qemu_put_be16(f, s->curr_status.pmcw.flags); qemu_put_be16(f, s->curr_status.pmcw.devno); qemu_put_byte(f, s->curr_status.pmcw.lpm); qemu_put_byte(f, s->curr_status.pmcw.pnom); qemu_put_byte(f, s->curr_status.pmcw.lpum); qemu_put_byte(f, s->curr_status.pmcw.pim); qemu_put_be16(f, s->curr_status.pmcw.mbi); qemu_put_byte(f, s->curr_status.pmcw.pom); qemu_put_byte(f, s->curr_status.pmcw.pam); qemu_put_buffer(f, s->curr_status.pmcw.chpid, 8); qemu_put_be32(f, s->curr_status.pmcw.chars); /* SCSW */ qemu_put_be16(f, s->curr_status.scsw.flags); qemu_put_be16(f, s->curr_status.scsw.ctrl); qemu_put_be32(f, s->curr_status.scsw.cpa); qemu_put_byte(f, s->curr_status.scsw.dstat); qemu_put_byte(f, s->curr_status.scsw.cstat); qemu_put_be16(f, s->curr_status.scsw.count); qemu_put_be64(f, s->curr_status.mba); qemu_put_buffer(f, s->curr_status.mda, 4); /* end SCHIB */ qemu_put_buffer(f, s->sense_data, 32); qemu_put_be64(f, s->channel_prog); /* last cmd */ qemu_put_byte(f, s->last_cmd.cmd_code); qemu_put_byte(f, s->last_cmd.flags); qemu_put_be16(f, s->last_cmd.count); qemu_put_be32(f, s->last_cmd.cda); qemu_put_byte(f, s->last_cmd_valid); qemu_put_byte(f, s->id.reserved); qemu_put_be16(f, s->id.cu_type); qemu_put_byte(f, s->id.cu_model); qemu_put_be16(f, s->id.dev_type); qemu_put_byte(f, s->id.dev_model); qemu_put_byte(f, s->id.unused); for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) { qemu_put_byte(f, s->id.ciw[i].type); qemu_put_byte(f, s->id.ciw[i].command); qemu_put_be16(f, s->id.ciw[i].count); } qemu_put_byte(f, s->ccw_fmt_1); qemu_put_byte(f, s->ccw_no_data_cnt); }
0
1,251
static VirtIOSCSIVring *virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, EventNotifierHandler *handler, int n) { BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s))); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); VirtIOSCSIVring *r; int rc; /* Set up virtqueue notify */ rc = k->set_host_notifier(qbus->parent, n, true); if (rc != 0) { fprintf(stderr, "virtio-scsi: Failed to set host notifier (%d)\n", rc); s->dataplane_fenced = true; return NULL; } r = g_new(VirtIOSCSIVring, 1); r->host_notifier = *virtio_queue_get_host_notifier(vq); r->guest_notifier = *virtio_queue_get_guest_notifier(vq); aio_set_event_notifier(s->ctx, &r->host_notifier, false, handler); r->parent = s; if (!vring_setup(&r->vring, VIRTIO_DEVICE(s), n)) { fprintf(stderr, "virtio-scsi: VRing setup failed\n"); goto fail_vring; } return r; fail_vring: aio_set_event_notifier(s->ctx, &r->host_notifier, false, NULL); k->set_host_notifier(qbus->parent, n, false); g_free(r); return NULL; }
0
1,252
static void do_change_block(const char *device, const char *filename, const char *fmt) { BlockDriverState *bs; BlockDriver *drv = NULL; bs = bdrv_find(device); if (!bs) { term_printf("device not found\n"); return; } if (fmt) { drv = bdrv_find_format(fmt); if (!drv) { term_printf("invalid format %s\n", fmt); return; } } if (eject_device(bs, 0) < 0) return; bdrv_open2(bs, filename, 0, drv); qemu_key_check(bs, filename); }
0
1,253
static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features, uint32_t *ext_features, uint32_t *ext2_features, uint32_t *ext3_features, uint32_t *kvm_features, uint32_t *svm_features) { if (!lookup_feature(features, flagname, NULL, feature_name) && !lookup_feature(ext_features, flagname, NULL, ext_feature_name) && !lookup_feature(ext2_features, flagname, NULL, ext2_feature_name) && !lookup_feature(ext3_features, flagname, NULL, ext3_feature_name) && !lookup_feature(kvm_features, flagname, NULL, kvm_feature_name) && !lookup_feature(svm_features, flagname, NULL, svm_feature_name)) fprintf(stderr, "CPU feature %s not found\n", flagname); }
0
1,254
static void test_machine(const void *data) { const testdef_t *test = data; char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX"; int fd; fd = mkstemp(tmpname); g_assert(fd != -1); /* * Make sure that this test uses tcg if available: It is used as a * fast-enough smoketest for that. */ global_qtest = qtest_startf("-M %s,accel=tcg:kvm " "-chardev file,id=serial0,path=%s " "-no-shutdown -serial chardev:serial0 %s", test->machine, tmpname, test->extra); unlink(tmpname); check_guest_output(test, fd); qtest_quit(global_qtest); close(fd); }
0
1,255
START_TEST(qstring_from_substr_test) { QString *qs; qs = qstring_from_substr("virtualization", 3, 9); fail_unless(qs != NULL); fail_unless(strcmp(qstring_get_str(qs), "tualiza") == 0); QDECREF(qs); }
0
1,256
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); }
0
1,257
static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size) { /* This always zero-extends and writes to a full 128 bit wide vector */ TCGv_i64 tmplo = tcg_temp_new_i64(); TCGv_i64 tmphi; if (size < 4) { TCGMemOp memop = MO_TE + size; tmphi = tcg_const_i64(0); tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), memop); } else { TCGv_i64 tcg_hiaddr; tmphi = tcg_temp_new_i64(); tcg_hiaddr = tcg_temp_new_i64(); tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), MO_TEQ); tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8); tcg_gen_qemu_ld_i64(tmphi, tcg_hiaddr, get_mem_index(s), MO_TEQ); tcg_temp_free_i64(tcg_hiaddr); } tcg_gen_st_i64(tmplo, cpu_env, fp_reg_offset(destidx, MO_64)); tcg_gen_st_i64(tmphi, cpu_env, fp_reg_hi_offset(destidx)); tcg_temp_free_i64(tmplo); tcg_temp_free_i64(tmphi); }
0
1,258
static inline void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset) { gen_mov_reg_FCC0(dst, src, fcc_offset); gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); tcg_gen_or_tl(dst, dst, cpu_tmp0); }
0
1,259
av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, unsigned int *sample_rate, int channels, enum CodecID *codec_id) { AlsaData *s = ctx->priv_data; const char *audio_device; int res, flags = 0; snd_pcm_format_t format; snd_pcm_t *h; snd_pcm_hw_params_t *hw_params; snd_pcm_uframes_t buffer_size, period_size; int64_t layout = ctx->streams[0]->codec->channel_layout; if (ctx->filename[0] == 0) audio_device = "default"; else audio_device = ctx->filename; if (*codec_id == CODEC_ID_NONE) *codec_id = DEFAULT_CODEC_ID; format = codec_id_to_pcm_format(*codec_id); if (format == SND_PCM_FORMAT_UNKNOWN) { av_log(ctx, AV_LOG_ERROR, "sample format 0x%04x is not supported\n", *codec_id); return AVERROR(ENOSYS); } s->frame_size = av_get_bits_per_sample(*codec_id) / 8 * channels; if (ctx->flags & AVFMT_FLAG_NONBLOCK) { flags = SND_PCM_NONBLOCK; } res = snd_pcm_open(&h, audio_device, mode, flags); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot open audio device %s (%s)\n", audio_device, snd_strerror(res)); return AVERROR(EIO); } res = snd_pcm_hw_params_malloc(&hw_params); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(res)); goto fail1; } res = snd_pcm_hw_params_any(h, hw_params); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(res)); goto fail; } res = snd_pcm_hw_params_set_access(h, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set access type (%s)\n", snd_strerror(res)); goto fail; } res = snd_pcm_hw_params_set_format(h, hw_params, format); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set sample format 0x%04x %d (%s)\n", *codec_id, format, snd_strerror(res)); goto fail; } res = snd_pcm_hw_params_set_rate_near(h, hw_params, sample_rate, 0); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(res)); goto fail; } res = snd_pcm_hw_params_set_channels(h, hw_params, channels); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set channel count to %d (%s)\n", channels, snd_strerror(res)); goto fail; } snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size); buffer_size = FFMIN(buffer_size, ALSA_BUFFER_SIZE_MAX); /* TODO: maybe use ctx->max_picture_buffer somehow */ res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set ALSA buffer size (%s)\n", snd_strerror(res)); goto fail; } snd_pcm_hw_params_get_period_size_min(hw_params, &period_size, NULL); if (!period_size) period_size = buffer_size / 4; res = snd_pcm_hw_params_set_period_size_near(h, hw_params, &period_size, NULL); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set ALSA period size (%s)\n", snd_strerror(res)); goto fail; } s->period_size = period_size; res = snd_pcm_hw_params(h, hw_params); if (res < 0) { av_log(ctx, AV_LOG_ERROR, "cannot set parameters (%s)\n", snd_strerror(res)); goto fail; } snd_pcm_hw_params_free(hw_params); if (channels > 2 && layout) { if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) { char name[128]; av_get_channel_layout_string(name, sizeof(name), channels, layout); av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n", name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); } if (s->reorder_func) { s->reorder_buf_size = buffer_size; s->reorder_buf = av_malloc(s->reorder_buf_size * s->frame_size); if (!s->reorder_buf) goto fail1; } } s->h = h; return 0; fail: snd_pcm_hw_params_free(hw_params); fail1: snd_pcm_close(h); return AVERROR(EIO); }
0
1,260
bool kvm_arch_stop_on_emulation_error(CPUState *env) { return !(env->cr[0] & CR0_PE_MASK) || ((env->segs[R_CS].selector & 3) != 3); }
0
1,261
static ssize_t block_crypto_write_func(QCryptoBlock *block, size_t offset, const uint8_t *buf, size_t buflen, Error **errp, void *opaque) { struct BlockCryptoCreateData *data = opaque; ssize_t ret; ret = blk_pwrite(data->blk, offset, buf, buflen, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not write encryption header"); return ret; } return ret; }
0
1,262
static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms, uint64_t cumulative_shared_perms, Error **errp) { BlockDriver *drv = bs->drv; BdrvChild *c; int ret; /* Write permissions never work with read-only images */ if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && bdrv_is_read_only(bs)) { error_setg(errp, "Block node is read-only"); return -EPERM; } /* Check this node */ if (!drv) { return 0; } if (drv->bdrv_check_perm) { return drv->bdrv_check_perm(bs, cumulative_perms, cumulative_shared_perms, errp); } /* Drivers that never have children can omit .bdrv_child_perm() */ if (!drv->bdrv_child_perm) { assert(QLIST_EMPTY(&bs->children)); return 0; } /* Check all children */ QLIST_FOREACH(c, &bs->children, next) { uint64_t cur_perm, cur_shared; drv->bdrv_child_perm(bs, c, c->role, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, cur_perm, cur_shared, errp); if (ret < 0) { return ret; } } return 0; }
0
1,263
static void test_qemu_strtosz_simple(void) { const char *str; char *endptr = NULL; int64_t res; str = "0"; res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0); g_assert(endptr == str + 1); str = "12345"; res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 12345); g_assert(endptr == str + 5); res = qemu_strtosz(str, NULL); g_assert_cmpint(res, ==, 12345); /* Note: precision is 53 bits since we're parsing with strtod() */ str = "9007199254740991"; /* 2^53-1 */ res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0x1fffffffffffff); g_assert(endptr == str + 16); str = "9007199254740992"; /* 2^53 */ res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0x20000000000000); g_assert(endptr == str + 16); str = "9007199254740993"; /* 2^53+1 */ res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0x20000000000000); /* rounded to 53 bits */ g_assert(endptr == str + 16); str = "9223372036854774784"; /* 0x7ffffffffffffc00 (53 msbs set) */ res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0x7ffffffffffffc00); g_assert(endptr == str + 19); str = "9223372036854775295"; /* 0x7ffffffffffffdff */ res = qemu_strtosz(str, &endptr); g_assert_cmpint(res, ==, 0x7ffffffffffffc00); /* rounded to 53 bits */ g_assert(endptr == str + 19); /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */ }
0
1,264
void vring_teardown(Vring *vring) { hostmem_finalize(&vring->hostmem); }
0
1,266
static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd, NvmeRequest *req) { NvmeRwCmd *rw = (NvmeRwCmd *)cmd; uint32_t nlb = le32_to_cpu(rw->nlb) + 1; uint64_t slba = le64_to_cpu(rw->slba); uint64_t prp1 = le64_to_cpu(rw->prp1); uint64_t prp2 = le64_to_cpu(rw->prp2); uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds; uint64_t data_size = nlb << data_shift; uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS); int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0; if ((slba + nlb) > ns->id_ns.nsze) { return NVME_LBA_RANGE | NVME_DNR; } if (nvme_map_prp(&req->qsg, prp1, prp2, data_size, n)) { return NVME_INVALID_FIELD | NVME_DNR; } assert((nlb << data_shift) == req->qsg.size); dma_acct_start(n->conf.bs, &req->acct, &req->qsg, is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ); req->aiocb = is_write ? dma_bdrv_write(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req) : dma_bdrv_read(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req); return NVME_NO_COMPLETE; }
0
1,267
static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz, int ac_index, int16_t *quant_matrix, int ss, int se, int Al, int *EOBRUN) { int code, i, j, level, val, run; if(*EOBRUN){ (*EOBRUN)--; return 0; } {OPEN_READER(re, &s->gb) for(i=ss;;i++) { UPDATE_CACHE(re, &s->gb); GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */ code -= 16; run = ((unsigned) code) >> 4; code &= 0xF; if(code) { i += run; if(code > MIN_CACHE_BITS - 16){ UPDATE_CACHE(re, &s->gb) } { int cache=GET_CACHE(re,&s->gb); int sign=(~cache)>>31; level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; } LAST_SKIP_BITS(re, &s->gb, code) if (i >= se) { if(i == se){ j = s->scantable.permutated[se]; block[j] = level * quant_matrix[j] << Al; break; } av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); return -1; } j = s->scantable.permutated[i]; block[j] = level * quant_matrix[j] << Al; }else{ if(run == 0xF){// ZRL - skip 15 coefficients i += 15; }else{ val = (1 << run); if(run){ UPDATE_CACHE(re, &s->gb); val += NEG_USR32(GET_CACHE(re, &s->gb), run); LAST_SKIP_BITS(re, &s->gb, run); } *EOBRUN = val - 1; break; } } } CLOSE_READER(re, &s->gb)} if(i > *last_nnz) *last_nnz = i; return 0; }
0
1,268
static int dca_subframe_header(DCAContext *s, int base_channel, int block_index) { /* Primary audio coding side information */ int j, k; if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; if (!base_channel) { s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1; s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3); } for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) s->prediction_mode[j][k] = get_bits(&s->gb, 1); } /* Get prediction codebook */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) { if (s->prediction_mode[j][k] > 0) { /* (Prediction coefficient VQ address) */ s->prediction_vq[j][k] = get_bits(&s->gb, 12); } } } /* Bit allocation index */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->vq_start_subband[j]; k++) { if (s->bitalloc_huffman[j] == 6) s->bitalloc[j][k] = get_bits(&s->gb, 5); else if (s->bitalloc_huffman[j] == 5) s->bitalloc[j][k] = get_bits(&s->gb, 4); else if (s->bitalloc_huffman[j] == 7) { av_log(s->avctx, AV_LOG_ERROR, "Invalid bit allocation index\n"); return AVERROR_INVALIDDATA; } else { s->bitalloc[j][k] = get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); } if (s->bitalloc[j][k] > 26) { // av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index [%i][%i] too big (%i)\n", // j, k, s->bitalloc[j][k]); return AVERROR_INVALIDDATA; } } } /* Transition mode */ for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) { s->transition_mode[j][k] = 0; if (s->subsubframes[s->current_subframe] > 1 && k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) { s->transition_mode[j][k] = get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]); } } } if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; for (j = base_channel; j < s->prim_channels; j++) { const uint32_t *scale_table; int scale_sum; memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); if (s->scalefactor_huffman[j] == 6) scale_table = scale_factor_quant7; else scale_table = scale_factor_quant6; /* When huffman coded, only the difference is encoded */ scale_sum = 0; for (k = 0; k < s->subband_activity[j]; k++) { if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); s->scale_factor[j][k][0] = scale_table[scale_sum]; } if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { /* Get second scale factor */ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); s->scale_factor[j][k][1] = scale_table[scale_sum]; } } } /* Joint subband scale factor codebook select */ for (j = base_channel; j < s->prim_channels; j++) { /* Transmitted only if joint subband coding enabled */ if (s->joint_intensity[j] > 0) s->joint_huff[j] = get_bits(&s->gb, 3); } if (get_bits_left(&s->gb) < 0) return AVERROR_INVALIDDATA; /* Scale factors for joint subband coding */ for (j = base_channel; j < s->prim_channels; j++) { int source_channel; /* Transmitted only if joint subband coding enabled */ if (s->joint_intensity[j] > 0) { int scale = 0; source_channel = s->joint_intensity[j] - 1; /* When huffman coded, only the difference is encoded * (is this valid as well for joint scales ???) */ for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { scale = get_scale(&s->gb, s->joint_huff[j], 0); scale += 64; /* bias */ s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ } if (!(s->debug_flag & 0x02)) { av_log(s->avctx, AV_LOG_DEBUG, "Joint stereo coding not supported\n"); s->debug_flag |= 0x02; } } } /* Stereo downmix coefficients */ if (!base_channel && s->prim_channels > 2) { if (s->downmix) { for (j = base_channel; j < s->prim_channels; j++) { s->downmix_coef[j][0] = get_bits(&s->gb, 7); s->downmix_coef[j][1] = get_bits(&s->gb, 7); } } else { int am = s->amode & DCA_CHANNEL_MASK; for (j = base_channel; j < s->prim_channels; j++) { s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; } } } /* Dynamic range coefficient */ if (!base_channel && s->dynrange) s->dynrange_coef = get_bits(&s->gb, 8); /* Side information CRC check word */ if (s->crc_present) { get_bits(&s->gb, 16); } /* * Primary audio data arrays */ /* VQ encoded high frequency subbands */ for (j = base_channel; j < s->prim_channels; j++) for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) /* 1 vector -> 32 samples */ s->high_freq_vq[j][k] = get_bits(&s->gb, 10); /* Low frequency effect data */ if (!base_channel && s->lfe) { /* LFE samples */ int lfe_samples = 2 * s->lfe * (4 + block_index); int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]); float lfe_scale; for (j = lfe_samples; j < lfe_end_sample; j++) { /* Signed 8 bits int */ s->lfe_data[j] = get_sbits(&s->gb, 8); } /* Scale factor index */ s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)]; /* Quantization step size * scale factor */ lfe_scale = 0.035 * s->lfe_scale_factor; for (j = lfe_samples; j < lfe_end_sample; j++) s->lfe_data[j] *= lfe_scale; } #ifdef TRACE av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes[s->current_subframe]); av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n", s->partial_samples[s->current_subframe]); for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:"); for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "prediction coefs: %f, %f, %f, %f\n", (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: "); for (k = 0; k < s->vq_start_subband[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:"); for (k = 0; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:"); for (k = 0; k < s->subband_activity[j]; k++) { if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]); if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]); } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) { if (s->joint_intensity[j] > 0) { int source_channel = s->joint_intensity[j] - 1; av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n"); for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } } if (!base_channel && s->prim_channels > 2 && s->downmix) { av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n"); for (j = 0; j < s->prim_channels; j++) { av_log(s->avctx, AV_LOG_DEBUG, "Channel 0, %d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]); av_log(s->avctx, AV_LOG_DEBUG, "Channel 1, %d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]); } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } for (j = base_channel; j < s->prim_channels; j++) for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]); if (!base_channel && s->lfe) { int lfe_samples = 2 * s->lfe * (4 + block_index); int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]); av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n"); for (j = lfe_samples; j < lfe_end_sample; j++) av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]); av_log(s->avctx, AV_LOG_DEBUG, "\n"); } #endif return 0; }
0
1,269
static int vc1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; AVFrame *pict = data; uint8_t *buf2 = NULL; const uint8_t *buf_start = buf; /* no supplementary picture */ if (buf_size == 0) { /* special case for last picture */ if (s->low_delay==0 && s->next_picture_ptr) { *pict= *(AVFrame*)s->next_picture_ptr; s->next_picture_ptr= NULL; *data_size = sizeof(AVFrame); } return 0; } /* We need to set current_picture_ptr before reading the header, * otherwise we cannot store anything in there. */ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ int i= ff_find_unused_picture(s, 0); s->current_picture_ptr= &s->picture[i]; } if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){ if (v->profile < PROFILE_ADVANCED) avctx->pix_fmt = PIX_FMT_VDPAU_WMV3; else avctx->pix_fmt = PIX_FMT_VDPAU_VC1; } //for advanced profile we may need to parse and unescape data if (avctx->codec_id == CODEC_ID_VC1) { int buf_size2 = 0; buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */ const uint8_t *start, *end, *next; int size; next = buf; for(start = buf, end = buf + buf_size; next < end; start = next){ next = find_next_marker(start + 4, end); size = next - start - 4; if(size <= 0) continue; switch(AV_RB32(start)){ case VC1_CODE_FRAME: if (avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) buf_start = start; buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); break; case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&s->gb, buf2, buf_size2*8); vc1_decode_entry_point(avctx, v, &s->gb); break; case VC1_CODE_SLICE: av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n"); av_free(buf2); return -1; } } }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */ const uint8_t *divider; divider = find_next_marker(buf, buf + buf_size); if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){ av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n"); av_free(buf2); return -1; } buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2); // TODO av_free(buf2);return -1; }else{ buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2); } init_get_bits(&s->gb, buf2, buf_size2*8); } else init_get_bits(&s->gb, buf, buf_size*8); // do parse frame header if(v->profile < PROFILE_ADVANCED) { if(vc1_parse_frame_header(v, &s->gb) == -1) { av_free(buf2); return -1; } } else { if(vc1_parse_frame_header_adv(v, &s->gb) == -1) { av_free(buf2); return -1; } } if(s->pict_type != FF_I_TYPE && !v->res_rtm_flag){ av_free(buf2); return -1; } // for hurry_up==5 s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == FF_I_TYPE; /* skip B-frames if we don't have reference frames */ if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)){ av_free(buf2); return -1;//buf_size; } /* skip b frames if we are in a hurry */ if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return -1;//buf_size; if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) { av_free(buf2); return buf_size; } /* skip everything if we are in a hurry>=5 */ if(avctx->hurry_up>=5) { av_free(buf2); return -1;//buf_size; } if(s->next_p_frame_damaged){ if(s->pict_type==FF_B_TYPE) return buf_size; else s->next_p_frame_damaged=0; } if(MPV_frame_start(s, avctx) < 0) { av_free(buf2); return -1; } s->me.qpel_put= s->dsp.put_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; if ((CONFIG_VC1_VDPAU_DECODER || CONFIG_WMV3_VDPAU_DECODER) &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start); else if (avctx->hwaccel) { if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) return -1; if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0) return -1; if (avctx->hwaccel->end_frame(avctx) < 0) return -1; } else { ff_er_frame_start(s); v->bits = buf_size * 8; vc1_decode_blocks(v); //av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), buf_size*8); // if(get_bits_count(&s->gb) > buf_size * 8) // return -1; ff_er_frame_end(s); } MPV_frame_end(s); assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); assert(s->current_picture.pict_type == s->pict_type); if (s->pict_type == FF_B_TYPE || s->low_delay) { *pict= *(AVFrame*)s->current_picture_ptr; } else if (s->last_picture_ptr != NULL) { *pict= *(AVFrame*)s->last_picture_ptr; } if(s->last_picture_ptr || s->low_delay){ *data_size = sizeof(AVFrame); ff_print_debug_info(s, pict); } av_free(buf2); return buf_size; }
0
1,270
static void ff_h264_idct_add8_mmx2(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ int i; for(i=16; i<16+8; i++){ if(nnzc[ scan8[i] ]) ff_h264_idct_add_mmx (dest[(i&4)>>2] + block_offset[i], block + i*16, stride); else if(block[i*16]) ff_h264_idct_dc_add_mmx2(dest[(i&4)>>2] + block_offset[i], block + i*16, stride); } }
0
1,271
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) { if (len > 6) { /* check for h264 start code */ if (AV_RB32(data) == 0x00000001 || AV_RB24(data) == 0x000001) { uint8_t *buf=NULL, *end, *start; uint32_t sps_size=0, pps_size=0; uint8_t *sps=0, *pps=0; int ret = ff_avc_parse_nal_units_buf(data, &buf, &len); if (ret < 0) return ret; start = buf; end = buf + len; /* look for sps and pps */ while (buf < end) { unsigned int size; uint8_t nal_type; size = AV_RB32(buf); nal_type = buf[4] & 0x1f; if (nal_type == 7) { /* SPS */ sps = buf + 4; sps_size = size; } else if (nal_type == 8) { /* PPS */ pps = buf + 4; pps_size = size; } buf += size + 4; } assert(sps); assert(pps); avio_w8(pb, 1); /* version */ avio_w8(pb, sps[1]); /* profile */ avio_w8(pb, sps[2]); /* profile compat */ avio_w8(pb, sps[3]); /* level */ avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ avio_w8(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ avio_wb16(pb, sps_size); avio_write(pb, sps, sps_size); avio_w8(pb, 1); /* number of pps */ avio_wb16(pb, pps_size); avio_write(pb, pps, pps_size); av_free(start); } else { avio_write(pb, data, len); } } return 0; }
0
1,272
static void uninit(struct vf_instance *vf) { free(vf->priv); }
1
1,273
static ExitStatus trans_fop_dew_0c(DisasContext *ctx, uint32_t insn, const DisasInsn *di) { unsigned rt = extract32(insn, 0, 5); unsigned ra = extract32(insn, 21, 5); return do_fop_dew(ctx, rt, ra, di->f_dew); }
1
1,276
static void test_dispatch_cmd_io(void) { QDict *req = qdict_new(); QDict *args = qdict_new(); QDict *args3 = qdict_new(); QDict *ud1a = qdict_new(); QDict *ud1b = qdict_new(); QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef; QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QInt *ret3; qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42))); qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello"))); qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422))); qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2"))); qdict_put_obj(args, "ud1a", QOBJECT(ud1a)); qdict_put_obj(args, "ud1b", QOBJECT(ud1b)); qdict_put_obj(req, "arguments", QOBJECT(args)); qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2"))); ret = qobject_to_qdict(test_qmp_dispatch(req)); assert(!strcmp(qdict_get_str(ret, "string"), "blah1")); ret_dict = qdict_get_qdict(ret, "dict"); assert(!strcmp(qdict_get_str(ret_dict, "string"), "blah2")); ret_dict_dict = qdict_get_qdict(ret_dict, "dict"); ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef"); assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42); assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello")); assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3")); ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict2"); ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef"); assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422); assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2")); assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4")); QDECREF(ret); qdict_put(args3, "a", qint_from_int(66)); qdict_put(req, "arguments", args3); qdict_put(req, "execute", qstring_from_str("user_def_cmd3")); ret3 = qobject_to_qint(test_qmp_dispatch(req)); assert(qint_get_int(ret3) == 66); QDECREF(ret); QDECREF(req); }
1
1,279
int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { BdrvTrackedRequest req; int max_discard, ret; if (!bs->drv) { return -ENOMEDIUM; } ret = bdrv_check_request(bs, sector_num, nb_sectors); if (ret < 0) { return ret; } else if (bs->read_only) { return -EPERM; } assert(!(bs->open_flags & BDRV_O_INACTIVE)); /* Do nothing if disabled. */ if (!(bs->open_flags & BDRV_O_UNMAP)) { return 0; } if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) { return 0; } tracked_request_begin(&req, bs, sector_num << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, BDRV_TRACKED_DISCARD); ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req); if (ret < 0) { goto out; } max_discard = MIN_NON_ZERO(bs->bl.max_pdiscard >> BDRV_SECTOR_BITS, BDRV_REQUEST_MAX_SECTORS); while (nb_sectors > 0) { int ret; int num = nb_sectors; int discard_alignment = bs->bl.pdiscard_alignment >> BDRV_SECTOR_BITS; /* align request */ if (discard_alignment && num >= discard_alignment && sector_num % discard_alignment) { if (num > discard_alignment) { num = discard_alignment; } num -= sector_num % discard_alignment; } /* limit request size */ if (num > max_discard) { num = max_discard; } if (bs->drv->bdrv_co_discard) { ret = bs->drv->bdrv_co_discard(bs, sector_num, num); } else { BlockAIOCB *acb; CoroutineIOCompletion co = { .coroutine = qemu_coroutine_self(), }; acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors, bdrv_co_io_em_complete, &co); if (acb == NULL) { ret = -EIO; goto out; } else { qemu_coroutine_yield(); ret = co.ret; } } if (ret && ret != -ENOTSUP) { goto out; } sector_num += num; nb_sectors -= num; } ret = 0; out: bdrv_set_dirty(bs, req.offset >> BDRV_SECTOR_BITS, req.bytes >> BDRV_SECTOR_BITS); tracked_request_end(&req); return ret; }
0
1,280
static CCW1 copy_ccw_from_guest(hwaddr addr, bool fmt1) { CCW0 tmp0; CCW1 tmp1; CCW1 ret; if (fmt1) { cpu_physical_memory_read(addr, &tmp1, sizeof(tmp1)); ret.cmd_code = tmp1.cmd_code; ret.flags = tmp1.flags; ret.count = be16_to_cpu(tmp1.count); ret.cda = be32_to_cpu(tmp1.cda); } else { cpu_physical_memory_read(addr, &tmp0, sizeof(tmp0)); ret.cmd_code = tmp0.cmd_code; ret.flags = tmp0.flags; ret.count = be16_to_cpu(tmp0.count); ret.cda = be16_to_cpu(tmp0.cda1) | (tmp0.cda0 << 16); if ((ret.cmd_code & 0x0f) == CCW_CMD_TIC) { ret.cmd_code &= 0x0f; } } return ret; }
0
1,281
static int tosa_dac_init(I2CSlave *i2c) { /* Nothing to do. */ return 0; }
0
1,282
CharDriverState *qemu_chr_open_eventfd(int eventfd) { CharDriverState *chr = qemu_chr_open_fd(eventfd, eventfd); if (chr) { chr->avail_connections = 1; } return chr; }
0
1,283
static CharDriverState *qmp_chardev_open_socket(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { CharDriverState *chr; TCPCharDriver *s; ChardevSocket *sock = backend->u.socket; SocketAddress *addr = sock->addr; bool do_nodelay = sock->has_nodelay ? sock->nodelay : false; bool is_listen = sock->has_server ? sock->server : true; bool is_telnet = sock->has_telnet ? sock->telnet : false; bool is_waitconnect = sock->has_wait ? sock->wait : false; int64_t reconnect = sock->has_reconnect ? sock->reconnect : 0; ChardevCommon *common = qapi_ChardevSocket_base(sock); QIOChannelSocket *sioc = NULL; chr = qemu_chr_alloc(common, errp); if (!chr) { return NULL; } s = g_new0(TCPCharDriver, 1); s->is_unix = addr->type == SOCKET_ADDRESS_KIND_UNIX; s->is_listen = is_listen; s->is_telnet = is_telnet; s->do_nodelay = do_nodelay; if (sock->tls_creds) { Object *creds; creds = object_resolve_path_component( object_get_objects_root(), sock->tls_creds); if (!creds) { error_setg(errp, "No TLS credentials with id '%s'", sock->tls_creds); goto error; } s->tls_creds = (QCryptoTLSCreds *) object_dynamic_cast(creds, TYPE_QCRYPTO_TLS_CREDS); if (!s->tls_creds) { error_setg(errp, "Object with id '%s' is not TLS credentials", sock->tls_creds); goto error; } object_ref(OBJECT(s->tls_creds)); if (is_listen) { if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { error_setg(errp, "%s", "Expected TLS credentials for server endpoint"); goto error; } } else { if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { error_setg(errp, "%s", "Expected TLS credentials for client endpoint"); goto error; } } } qapi_copy_SocketAddress(&s->addr, sock->addr); chr->opaque = s; chr->chr_write = tcp_chr_write; chr->chr_sync_read = tcp_chr_sync_read; chr->chr_close = tcp_chr_close; chr->get_msgfds = tcp_get_msgfds; chr->set_msgfds = tcp_set_msgfds; chr->chr_add_client = tcp_chr_add_client; chr->chr_add_watch = tcp_chr_add_watch; chr->chr_update_read_handler = tcp_chr_update_read_handler; /* be isn't opened until we get a connection */ chr->explicit_be_open = true; chr->filename = SocketAddress_to_str("disconnected:", addr, is_listen, is_telnet); if (is_listen) { if (is_telnet) { s->do_telnetopt = 1; } } else if (reconnect > 0) { s->reconnect_time = reconnect; } sioc = qio_channel_socket_new(); if (s->reconnect_time) { qio_channel_socket_connect_async(sioc, s->addr, qemu_chr_socket_connected, chr, NULL); } else if (s->is_listen) { if (qio_channel_socket_listen_sync(sioc, s->addr, errp) < 0) { goto error; } s->listen_ioc = sioc; if (is_waitconnect) { fprintf(stderr, "QEMU waiting for connection on: %s\n", chr->filename); tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr); } qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL); if (!s->ioc) { s->listen_tag = qio_channel_add_watch( QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL); } } else { if (qio_channel_socket_connect_sync(sioc, s->addr, errp) < 0) { goto error; } tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); } return chr; error: if (sioc) { object_unref(OBJECT(sioc)); } if (s->tls_creds) { object_unref(OBJECT(s->tls_creds)); } g_free(s); qemu_chr_free_common(chr); return NULL; }
0
1,284
uint64_t ldq_le_phys(target_phys_addr_t addr) { return ldq_phys_internal(addr, DEVICE_LITTLE_ENDIAN); }
0
1,285
static int rv10_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MpegEncContext *s = avctx->priv_data; AVFrame *pict = data; int i, ret; int slice_count; const uint8_t *slices_hdr = NULL; av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size); /* no supplementary picture */ if (buf_size == 0) { return 0; } if (!avctx->slice_count) { slice_count = (*buf++) + 1; buf_size--; if (!slice_count || buf_size <= 8 * slice_count) { av_log(avctx, AV_LOG_ERROR, "Invalid slice count: %d.\n", slice_count); return AVERROR_INVALIDDATA; } slices_hdr = buf + 4; buf += 8 * slice_count; buf_size -= 8 * slice_count; } else slice_count = avctx->slice_count; for (i = 0; i < slice_count; i++) { unsigned offset = get_slice_offset(avctx, slices_hdr, i); int size, size2; if (offset >= buf_size) return AVERROR_INVALIDDATA; if (i + 1 == slice_count) size = buf_size - offset; else size = get_slice_offset(avctx, slices_hdr, i + 1) - offset; if (i + 2 >= slice_count) size2 = buf_size - offset; else size2 = get_slice_offset(avctx, slices_hdr, i + 2) - offset; if (size <= 0 || size2 <= 0 || offset + FFMAX(size, size2) > buf_size) return AVERROR_INVALIDDATA; if ((ret = rv10_decode_packet(avctx, buf + offset, size, size2)) < 0) return ret; if (ret > 8 * size) i++; } if (s->current_picture_ptr != NULL && s->mb_y >= s->mb_height) { ff_er_frame_end(&s->er); ff_mpv_frame_end(s); if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0) return ret; ff_print_debug_info(s, s->current_picture_ptr); } else if (s->last_picture_ptr != NULL) { if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0) return ret; ff_print_debug_info(s, s->last_picture_ptr); } if (s->last_picture_ptr || s->low_delay) { *got_frame = 1; } // so we can detect if frame_end was not called (find some nicer solution...) s->current_picture_ptr = NULL; } return avpkt->size; }
0
1,286
void xen_config_cleanup(void) { struct xs_dirs *d; TAILQ_FOREACH(d, &xs_cleanup, list) { xs_rm(xenstore, 0, d->xs_dir); } }
0
1,287
uint64_t helper_frsqrte(CPUPPCState *env, uint64_t arg) { CPU_DoubleU farg; farg.ll = arg; if (unlikely(float64_is_neg(farg.d) && !float64_is_zero(farg.d))) { /* Reciprocal square root of a negative nonzero number */ farg.ll = fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, 1); } else { if (unlikely(float64_is_signaling_nan(farg.d))) { /* sNaN reciprocal square root */ fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); } farg.d = float64_sqrt(farg.d, &env->fp_status); farg.d = float64_div(float64_one, farg.d, &env->fp_status); } return farg.ll; }
0
1,288
static MemTxResult vtd_mem_ir_write(void *opaque, hwaddr addr, uint64_t value, unsigned size, MemTxAttrs attrs) { int ret = 0; MSIMessage from = {}, to = {}; from.address = (uint64_t) addr + VTD_INTERRUPT_ADDR_FIRST; from.data = (uint32_t) value; ret = vtd_interrupt_remap_msi(opaque, &from, &to); if (ret) { /* TODO: report error */ VTD_DPRINTF(GENERAL, "int remap fail for addr 0x%"PRIx64 " data 0x%"PRIx32, from.address, from.data); /* Drop this interrupt */ return MEMTX_ERROR; } VTD_DPRINTF(IR, "delivering MSI 0x%"PRIx64":0x%"PRIx32 " for device sid 0x%04x", to.address, to.data, sid); if (dma_memory_write(&address_space_memory, to.address, &to.data, size)) { VTD_DPRINTF(GENERAL, "error: fail to write 0x%"PRIx64 " value 0x%"PRIx32, to.address, to.data); } return MEMTX_OK; }
0
1,289
static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, int bytes) { int ret; int cluster_bytes, buf_bytes; uint8_t *cluster_buf, *compressed_data; uint8_t *uncomp_buf; uint32_t data_len; VmdkGrainMarker *marker; uLongf buf_len; if (!extent->compressed) { ret = bdrv_co_preadv(extent->file->bs, cluster_offset + offset_in_cluster, bytes, qiov, 0); if (ret < 0) { return ret; } return 0; } cluster_bytes = extent->cluster_sectors * 512; /* Read two clusters in case GrainMarker + compressed data > one cluster */ buf_bytes = cluster_bytes * 2; cluster_buf = g_malloc(buf_bytes); uncomp_buf = g_malloc(cluster_bytes); ret = bdrv_pread(extent->file, cluster_offset, cluster_buf, buf_bytes); if (ret < 0) { goto out; } compressed_data = cluster_buf; buf_len = cluster_bytes; data_len = cluster_bytes; if (extent->has_marker) { marker = (VmdkGrainMarker *)cluster_buf; compressed_data = marker->data; data_len = le32_to_cpu(marker->size); } if (!data_len || data_len > buf_bytes) { ret = -EINVAL; goto out; } ret = uncompress(uncomp_buf, &buf_len, compressed_data, data_len); if (ret != Z_OK) { ret = -EINVAL; goto out; } if (offset_in_cluster < 0 || offset_in_cluster + bytes > buf_len) { ret = -EINVAL; goto out; } qemu_iovec_from_buf(qiov, 0, uncomp_buf + offset_in_cluster, bytes); ret = 0; out: g_free(uncomp_buf); g_free(cluster_buf); return ret; }
0
1,291
static void parser_context_free(JSONParserContext *ctxt) { if (ctxt) { while (!g_queue_is_empty(ctxt->buf)) { parser_context_pop_token(ctxt); } qobject_decref(ctxt->current); g_queue_free(ctxt->buf); g_free(ctxt); } }
0
1,293
int page_check_range(target_ulong start, target_ulong len, int flags) { PageDesc *p; target_ulong end; target_ulong addr; if (start + len < start) /* we've wrapped around */ return -1; end = TARGET_PAGE_ALIGN(start+len); /* must do before we loose bits in the next step */ start = start & TARGET_PAGE_MASK; for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) { p = page_find(addr >> TARGET_PAGE_BITS); if( !p ) return -1; if( !(p->flags & PAGE_VALID) ) return -1; if ((flags & PAGE_READ) && !(p->flags & PAGE_READ)) return -1; if (flags & PAGE_WRITE) { if (!(p->flags & PAGE_WRITE_ORG)) return -1; /* unprotect the page if it was put read-only because it contains translated code */ if (!(p->flags & PAGE_WRITE)) { if (!page_unprotect(addr, 0, NULL)) return -1; } return 0; } } return 0; }
0
1,294
processed(OptsVisitor *ov, const char *name) { if (ov->repeated_opts == NULL) { g_hash_table_remove(ov->unprocessed_opts, name); } }
0
1,295
minimac2_read(void *opaque, target_phys_addr_t addr, unsigned size) { MilkymistMinimac2State *s = opaque; uint32_t r = 0; addr >>= 2; switch (addr) { case R_SETUP: case R_MDIO: case R_STATE0: case R_COUNT0: case R_STATE1: case R_COUNT1: case R_TXCOUNT: r = s->regs[addr]; break; default: error_report("milkymist_minimac2: read access to unknown register 0x" TARGET_FMT_plx, addr << 2); break; } trace_milkymist_minimac2_memory_read(addr << 2, r); return r; }
0
1,296
static inline void float_to_int (float * _f, int16_t * s16, int samples) { int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format int i; for (i = 0; i < samples; i++) { s16[i] = blah (f[i]); } }
0
1,297
void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid) { KVMDevice *kd; if (!kvm_irqchip_in_kernel()) { return; } if (QSLIST_EMPTY(&kvm_devices_head)) { memory_listener_register(&devlistener, NULL); qemu_add_machine_init_done_notifier(&notify); } kd = g_new0(KVMDevice, 1); kd->mr = mr; kd->kda.id = devid; kd->kda.addr = -1; QSLIST_INSERT_HEAD(&kvm_devices_head, kd, entries); memory_region_ref(kd->mr); }
0
1,298
X86CPU *cpu_x86_init(const char *cpu_model) { X86CPU *cpu; CPUX86State *env; static int inited; cpu = X86_CPU(object_new(TYPE_X86_CPU)); env = &cpu->env; env->cpu_model_str = cpu_model; /* init various static tables used in TCG mode */ if (tcg_enabled() && !inited) { inited = 1; optimize_flags_init(); #ifndef CONFIG_USER_ONLY prev_debug_excp_handler = cpu_set_debug_excp_handler(breakpoint_handler); #endif } if (cpu_x86_register(cpu, cpu_model) < 0) { object_delete(OBJECT(cpu)); return NULL; } x86_cpu_realize(OBJECT(cpu), NULL); return cpu; }
0
1,299
int raw_get_aio_fd(BlockDriverState *bs) { BDRVRawState *s; if (!bs->drv) { return -ENOMEDIUM; } if (bs->drv == bdrv_find_format("raw")) { bs = bs->file; } /* raw-posix has several protocols so just check for raw_aio_readv */ if (bs->drv->bdrv_aio_readv != raw_aio_readv) { return -ENOTSUP; } s = bs->opaque; if (!s->use_aio) { return -ENOTSUP; } return s->fd; }
0
1,300
static SocketAddressLegacy *unix_build_address(const char *path) { SocketAddressLegacy *saddr; saddr = g_new0(SocketAddressLegacy, 1); saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1); saddr->u.q_unix.data->path = g_strdup(path); return saddr; }
0
1,301
e1000_mmio_read(void *opaque, hwaddr addr, unsigned size) { E1000State *s = opaque; unsigned int index = (addr & 0x1ffff) >> 2; if (index < NREADOPS && macreg_readops[index]) { return macreg_readops[index](s, index); } DBGOUT(UNKNOWN, "MMIO unknown read addr=0x%08x\n", index<<2); return 0; }
0
1,302
void bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, char *options, uint64_t img_size, int flags, Error **errp, bool quiet) { QEMUOptionParameter *param = NULL, *create_options = NULL; QEMUOptionParameter *backing_fmt, *backing_file, *size; BlockDriverState *bs = NULL; BlockDriver *drv, *proto_drv; BlockDriver *backing_drv = NULL; int ret = 0; /* Find driver and parse its options */ drv = bdrv_find_format(fmt); if (!drv) { error_setg(errp, "Unknown file format '%s'", fmt); return; } proto_drv = bdrv_find_protocol(filename); if (!proto_drv) { error_setg(errp, "Unknown protocol '%s'", filename); return; } create_options = append_option_parameters(create_options, drv->create_options); create_options = append_option_parameters(create_options, proto_drv->create_options); /* Create parameter list with default values */ param = parse_option_parameters("", create_options, param); set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size); /* Parse -o options */ if (options) { param = parse_option_parameters(options, create_options, param); if (param == NULL) { error_setg(errp, "Invalid options for file format '%s'.", fmt); goto out; } } if (base_filename) { if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE, base_filename)) { error_setg(errp, "Backing file not supported for file format '%s'", fmt); goto out; } } if (base_fmt) { if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) { error_setg(errp, "Backing file format not supported for file " "format '%s'", fmt); goto out; } } backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); if (backing_file && backing_file->value.s) { if (!strcmp(filename, backing_file->value.s)) { error_setg(errp, "Error: Trying to create an image with the " "same filename as the backing file"); goto out; } } backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT); if (backing_fmt && backing_fmt->value.s) { backing_drv = bdrv_find_format(backing_fmt->value.s); if (!backing_drv) { error_setg(errp, "Unknown backing file format '%s'", backing_fmt->value.s); goto out; } } // The size for the image must always be specified, with one exception: // If we are using a backing file, we can obtain the size from there size = get_option_parameter(param, BLOCK_OPT_SIZE); if (size && size->value.n == -1) { if (backing_file && backing_file->value.s) { uint64_t size; char buf[32]; int back_flags; /* backing files always opened read-only */ back_flags = flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); bs = bdrv_new(""); ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags, backing_drv); if (ret < 0) { error_setg_errno(errp, -ret, "Could not open '%s'", backing_file->value.s); goto out; } bdrv_get_geometry(bs, &size); size *= 512; snprintf(buf, sizeof(buf), "%" PRId64, size); set_option_parameter(param, BLOCK_OPT_SIZE, buf); } else { error_setg(errp, "Image creation needs a size parameter"); goto out; } } if (!quiet) { printf("Formatting '%s', fmt=%s ", filename, fmt); print_option_parameters(param); puts(""); } ret = bdrv_create(drv, filename, param); if (ret < 0) { if (ret == -ENOTSUP) { error_setg(errp,"Formatting or formatting option not supported for " "file format '%s'", fmt); } else if (ret == -EFBIG) { error_setg(errp, "The image size is too large for file format '%s'", fmt); } else { error_setg(errp, "%s: error while creating %s: %s", filename, fmt, strerror(-ret)); } } out: free_option_parameters(create_options); free_option_parameters(param); if (bs) { bdrv_delete(bs); } }
0
1,303
int nbd_client(int fd) { int ret; int serrno; TRACE("Doing NBD loop"); ret = ioctl(fd, NBD_DO_IT); if (ret == -1 && errno == EPIPE) { /* NBD_DO_IT normally returns EPIPE when someone has disconnected * the socket via NBD_DISCONNECT. We do not want to return 1 in * that case. */ ret = 0; } serrno = errno; TRACE("NBD loop returned %d: %s", ret, strerror(serrno)); TRACE("Clearing NBD queue"); ioctl(fd, NBD_CLEAR_QUE); TRACE("Clearing NBD socket"); ioctl(fd, NBD_CLEAR_SOCK); errno = serrno; return ret; }
0
1,304
static void slirp_init_once(void) { static int initialized; struct hostent *he; char our_name[256]; #ifdef _WIN32 WSADATA Data; #endif if (initialized) { return; } initialized = 1; #ifdef _WIN32 WSAStartup(MAKEWORD(2,0), &Data); atexit(winsock_cleanup); #endif loopback_addr.s_addr = htonl(INADDR_LOOPBACK); /* FIXME: This address may change during runtime */ if (gethostname(our_name, sizeof(our_name)) == 0) { he = gethostbyname(our_name); if (he) { our_addr = *(struct in_addr *)he->h_addr; } } if (our_addr.s_addr == 0) { our_addr = loopback_addr; } /* FIXME: This address may change during runtime */ if (get_dns_addr(&dns_addr) < 0) { dns_addr = loopback_addr; } }
1
1,305
BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) { return bdrv_named_nodes_list(); }
1
1,306
void backup_start(BlockDriverState *bs, BlockDriverState *target, int64_t speed, MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap, BlockdevOnError on_source_error, BlockdevOnError on_target_error, BlockCompletionFunc *cb, void *opaque, BlockJobTxn *txn, Error **errp) { int64_t len; BlockDriverInfo bdi; int ret; assert(bs); assert(target); assert(cb); 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 (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; } BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed, cb, opaque, errp); if (!job) { goto error; } job->on_source_error = on_source_error; job->on_target_error = on_target_error; job->target = target; job->sync_mode = sync_mode; job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ? sync_bitmap : NULL; /* 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(job->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); } bdrv_op_block_all(target, job->common.blocker); job->common.len = len; job->common.co = qemu_coroutine_create(backup_run); block_job_txn_add_job(txn, &job->common); qemu_coroutine_enter(job->common.co, job); return; error: if (sync_bitmap) { bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL); } }
1
1,309
void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, int flags) { #define RGPL 4 #define RFPL 4 PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; int i; cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n", env->nip, env->lr, env->ctr, cpu_read_xer(env), cs->cpu_index); cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " TARGET_FMT_lx " iidx %d didx %d\n", env->msr, env->spr[SPR_HID0], env->hflags, env->immu_idx, env->dmmu_idx); #if !defined(NO_TIMER_DUMP) cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 #if !defined(CONFIG_USER_ONLY) " DECR %08" PRIu32 "\n", cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) #if !defined(CONFIG_USER_ONLY) , cpu_ppc_load_decr(env) ); for (i = 0; i < 32; i++) { if ((i & (RGPL - 1)) == 0) cpu_fprintf(f, "GPR%02d", i); cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); if ((i & (RGPL - 1)) == (RGPL - 1)) cpu_fprintf(f, "\n"); cpu_fprintf(f, "CR "); for (i = 0; i < 8; i++) cpu_fprintf(f, "%01x", env->crf[i]); cpu_fprintf(f, " ["); for (i = 0; i < 8; i++) { char a = '-'; if (env->crf[i] & 0x08) a = 'L'; else if (env->crf[i] & 0x04) a = 'G'; else if (env->crf[i] & 0x02) a = 'E'; cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", env->reserve_addr); for (i = 0; i < 32; i++) { if ((i & (RFPL - 1)) == 0) cpu_fprintf(f, "FPR%02d", i); cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); if ((i & (RFPL - 1)) == (RFPL - 1)) cpu_fprintf(f, "\n"); cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); #if !defined(CONFIG_USER_ONLY) cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); if (env->excp_model == POWERPC_EXCP_BOOKE) { cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx " EPR " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], env->spr[SPR_BOOKE_EPR]); /* FSL-specific */ cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); /* * IVORs are left out as they are large and do not change often -- * they can be read with "p $ivor0", "p $ivor1", etc. */ if (env->flags & POWERPC_FLAG_CFAR) { cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); switch (env->mmu_model) { case POWERPC_MMU_32B: case POWERPC_MMU_601: case POWERPC_MMU_SOFT_6xx: case POWERPC_MMU_SOFT_74xx: case POWERPC_MMU_64B: case POWERPC_MMU_2_03: case POWERPC_MMU_2_06: case POWERPC_MMU_2_06a: case POWERPC_MMU_2_07: case POWERPC_MMU_2_07a: cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1], env->spr[SPR_DAR], env->spr[SPR_DSISR]); break; case POWERPC_MMU_BOOKE206: cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx " TLB1CFG " TARGET_FMT_lx "\n", env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], env->spr[SPR_BOOKE_TLB1CFG]); break; default: break; #undef RGPL #undef RFPL
1
1,310
void uninit_opts(void) { int i; for (i = 0; i < AVMEDIA_TYPE_NB; i++) av_freep(&avcodec_opts[i]); av_freep(&avformat_opts->key); av_freep(&avformat_opts); #if CONFIG_SWSCALE av_freep(&sws_opts); #endif }
1
1,311
static USBDevice *usb_braille_init(USBBus *bus, const char *unused) { USBDevice *dev; CharDriverState *cdrv; cdrv = qemu_chr_new("braille", "braille", NULL); if (!cdrv) return NULL; dev = usb_create(bus, "usb-braille"); qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); qdev_init_nofail(&dev->qdev); return dev; }
1
1,312
void qdev_free(DeviceState *dev) { BusState *bus; if (dev->state == DEV_STATE_INITIALIZED) { while (dev->num_child_bus) { bus = QLIST_FIRST(&dev->child_bus); qbus_free(bus); } if (dev->info->vmsd) vmstate_unregister(dev->info->vmsd, dev); if (dev->info->exit) dev->info->exit(dev); if (dev->opts) qemu_opts_del(dev->opts); } qemu_unregister_reset(qdev_reset, dev); QLIST_REMOVE(dev, sibling); for (prop = dev->info->props; prop && prop->name; prop++) { if (prop->info->free) { prop->info->free(dev, prop); } } qemu_free(dev); }
1
1,313
static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) { const uint8_t *s = src; const uint8_t *end; #ifdef HAVE_MMX const uint8_t *mm_end; #endif uint16_t *d = (uint16_t *)dst; end = s + src_size; #ifdef HAVE_MMX __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm __volatile( "movq %0, %%mm7\n\t" "movq %1, %%mm6\n\t" ::"m"(red_16mask),"m"(green_16mask)); mm_end = end - 15; while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movd %1, %%mm0\n\t" "movd 3%1, %%mm3\n\t" "punpckldq 6%1, %%mm0\n\t" "punpckldq 9%1, %%mm3\n\t" "movq %%mm0, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm3, %%mm4\n\t" "movq %%mm3, %%mm5\n\t" "psllq $8, %%mm0\n\t" "psllq $8, %%mm3\n\t" "pand %%mm7, %%mm0\n\t" "pand %%mm7, %%mm3\n\t" "psrlq $5, %%mm1\n\t" "psrlq $5, %%mm4\n\t" "pand %%mm6, %%mm1\n\t" "pand %%mm6, %%mm4\n\t" "psrlq $19, %%mm2\n\t" "psrlq $19, %%mm5\n\t" "pand %2, %%mm2\n\t" "pand %2, %%mm5\n\t" "por %%mm1, %%mm0\n\t" "por %%mm4, %%mm3\n\t" "por %%mm2, %%mm0\n\t" "por %%mm5, %%mm3\n\t" "psllq $16, %%mm3\n\t" "por %%mm3, %%mm0\n\t" MOVNTQ" %%mm0, %0\n\t" :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); d += 4; s += 12; } __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { const int r= *s++; const int g= *s++; const int b= *s++; *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); } }
0
1,314
static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) { const uint16_t *end; #if COMPILE_TEMPLATE_MMX const uint16_t *mm_end; #endif uint8_t *d = (uint8_t *)dst; const uint16_t *s = (const uint16_t *)src; end = s + src_size/2; #if COMPILE_TEMPLATE_MMX __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); mm_end = end - 7; while (s < mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movq %1, %%mm0 \n\t" "movq %1, %%mm1 \n\t" "movq %1, %%mm2 \n\t" "pand %2, %%mm0 \n\t" "pand %3, %%mm1 \n\t" "pand %4, %%mm2 \n\t" "psllq $3, %%mm0 \n\t" "psrlq $3, %%mm1 \n\t" "psrlq $8, %%mm2 \n\t" "movq %%mm0, %%mm3 \n\t" "movq %%mm1, %%mm4 \n\t" "movq %%mm2, %%mm5 \n\t" "punpcklwd %5, %%mm0 \n\t" "punpcklwd %5, %%mm1 \n\t" "punpcklwd %5, %%mm2 \n\t" "punpckhwd %5, %%mm3 \n\t" "punpckhwd %5, %%mm4 \n\t" "punpckhwd %5, %%mm5 \n\t" "psllq $8, %%mm1 \n\t" "psllq $16, %%mm2 \n\t" "por %%mm1, %%mm0 \n\t" "por %%mm2, %%mm0 \n\t" "psllq $8, %%mm4 \n\t" "psllq $16, %%mm5 \n\t" "por %%mm4, %%mm3 \n\t" "por %%mm5, %%mm3 \n\t" "movq %%mm0, %%mm6 \n\t" "movq %%mm3, %%mm7 \n\t" "movq 8%1, %%mm0 \n\t" "movq 8%1, %%mm1 \n\t" "movq 8%1, %%mm2 \n\t" "pand %2, %%mm0 \n\t" "pand %3, %%mm1 \n\t" "pand %4, %%mm2 \n\t" "psllq $3, %%mm0 \n\t" "psrlq $3, %%mm1 \n\t" "psrlq $8, %%mm2 \n\t" "movq %%mm0, %%mm3 \n\t" "movq %%mm1, %%mm4 \n\t" "movq %%mm2, %%mm5 \n\t" "punpcklwd %5, %%mm0 \n\t" "punpcklwd %5, %%mm1 \n\t" "punpcklwd %5, %%mm2 \n\t" "punpckhwd %5, %%mm3 \n\t" "punpckhwd %5, %%mm4 \n\t" "punpckhwd %5, %%mm5 \n\t" "psllq $8, %%mm1 \n\t" "psllq $16, %%mm2 \n\t" "por %%mm1, %%mm0 \n\t" "por %%mm2, %%mm0 \n\t" "psllq $8, %%mm4 \n\t" "psllq $16, %%mm5 \n\t" "por %%mm4, %%mm3 \n\t" "por %%mm5, %%mm3 \n\t" :"=m"(*d) :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null) :"memory"); /* borrowed 32 to 24 */ __asm__ volatile( "movq %%mm0, %%mm4 \n\t" "movq %%mm3, %%mm5 \n\t" "movq %%mm6, %%mm0 \n\t" "movq %%mm7, %%mm1 \n\t" "movq %%mm4, %%mm6 \n\t" "movq %%mm5, %%mm7 \n\t" "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm3 \n\t" STORE_BGR24_MMX :"=m"(*d) :"m"(*s) :"memory"); d += 24; s += 8; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); #endif while (s < end) { register uint16_t bgr; bgr = *s++; *d++ = (bgr&0x1F)<<3; *d++ = (bgr&0x7E0)>>3; *d++ = (bgr&0xF800)>>8; } }
1
1,315
static int teletext_close_decoder(AVCodecContext *avctx) { TeletextContext *ctx = avctx->priv_data; av_dlog(avctx, "lines_total=%u\n", ctx->lines_processed); while (ctx->nb_pages) subtitle_rect_free(&ctx->pages[--ctx->nb_pages].sub_rect); av_freep(&ctx->pages); vbi_dvb_demux_delete(ctx->dx); vbi_decoder_delete(ctx->vbi); ctx->dx = NULL; ctx->vbi = NULL; ctx->pts = AV_NOPTS_VALUE; return 0; }
1
1,316
static av_always_inline void predict(PredictorState *ps, int *coef, int output_enable) { const SoftFloat a = { 1023410176, 0 }; // 61.0 / 64 const SoftFloat alpha = { 973078528, 0 }; // 29.0 / 32 SoftFloat e0, e1; SoftFloat pv; SoftFloat k1, k2; SoftFloat r0 = ps->r0, r1 = ps->r1; SoftFloat cor0 = ps->cor0, cor1 = ps->cor1; SoftFloat var0 = ps->var0, var1 = ps->var1; SoftFloat tmp; if (var0.exp > 1 || (var0.exp == 1 && var0.mant > 0x20000000)) { k1 = av_mul_sf(cor0, flt16_even(av_div_sf(a, var0))); } else { k1.mant = 0; k1.exp = 0; } if (var1.exp > 1 || (var1.exp == 1 && var1.mant > 0x20000000)) { k2 = av_mul_sf(cor1, flt16_even(av_div_sf(a, var1))); } else { k2.mant = 0; k2.exp = 0; } tmp = av_mul_sf(k1, r0); pv = flt16_round(av_add_sf(tmp, av_mul_sf(k2, r1))); if (output_enable) { int shift = 28 - pv.exp; if (shift < 31) *coef += (pv.mant + (1 << (shift - 1))) >> shift; } e0 = av_int2sf(*coef, 2); e1 = av_sub_sf(e0, tmp); ps->cor1 = flt16_trunc(av_add_sf(av_mul_sf(alpha, cor1), av_mul_sf(r1, e1))); tmp = av_add_sf(av_mul_sf(r1, r1), av_mul_sf(e1, e1)); tmp.exp--; ps->var1 = flt16_trunc(av_add_sf(av_mul_sf(alpha, var1), tmp)); ps->cor0 = flt16_trunc(av_add_sf(av_mul_sf(alpha, cor0), av_mul_sf(r0, e0))); tmp = av_add_sf(av_mul_sf(r0, r0), av_mul_sf(e0, e0)); tmp.exp--; ps->var0 = flt16_trunc(av_add_sf(av_mul_sf(alpha, var0), tmp)); ps->r1 = flt16_trunc(av_mul_sf(a, av_sub_sf(r0, av_mul_sf(k1, e0)))); ps->r0 = flt16_trunc(av_mul_sf(a, e0)); }
1
1,317
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx) { AVCodecContext *avctx = inctx; ATDecodeContext *at = avctx->priv_data; if (at->eof) { *nb_packets = 0; if (packets) { *packets = &at->pkt_desc; at->pkt_desc.mDataByteSize = 0; } return 0; } av_packet_move_ref(&at->in_pkt, &at->new_in_pkt); at->new_in_pkt.data = 0; at->new_in_pkt.size = 0; if (!at->in_pkt.data) { *nb_packets = 0; return 1; } data->mNumberBuffers = 1; data->mBuffers[0].mNumberChannels = 0; data->mBuffers[0].mDataByteSize = at->in_pkt.size; data->mBuffers[0].mData = at->in_pkt.data; *nb_packets = 1; if (packets) { *packets = &at->pkt_desc; at->pkt_desc.mDataByteSize = at->in_pkt.size; } return 0; }
1
1,319
static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); const vector unsigned char permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0}; vector unsigned char perm1 = vec_lvsl(0, pix1); vector unsigned char perm2 = vec_lvsl(0, pix2); vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sum; vector signed int sumsqr; sum = (vector unsigned int)vec_splat_u32(0); for (i = 0; i < h; i++) { /* Read potentially unaligned pixels into t1 and t2 Since we're reading 16 pixels, and actually only want 8, mask out the last 8 pixels. The 0s don't change the sum. */ vector unsigned char pix1l = vec_ld( 0, pix1); vector unsigned char pix1r = vec_ld(15, pix1); vector unsigned char pix2l = vec_ld( 0, pix2); vector unsigned char pix2r = vec_ld(15, pix2); t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear); t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); /* Since we want to use unsigned chars, we can take advantage of the fact that abs(a-b)^2 = (a-b)^2. */ /* Calculate abs differences vector */ t3 = vec_max(t1, t2); t4 = vec_min(t1, t2); t5 = vec_sub(t3, t4); /* Square the values and add them to our sum */ sum = vec_msum(t5, t5, sum); pix1 += line_size; pix2 += line_size; } /* Sum up the four partial sums, and put the result into s */ sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); sumsqr = vec_splat(sumsqr, 3); vec_ste(sumsqr, 0, &s); return s; }
1
1,320
av_cold void ff_vp8dsp_init_ppc(VP8DSPContext *c) { #if HAVE_ALTIVEC if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; c->put_vp8_epel_pixels_tab[0][0][0] = put_vp8_pixels16_altivec; c->put_vp8_epel_pixels_tab[0][0][2] = put_vp8_epel16_h6_altivec; c->put_vp8_epel_pixels_tab[0][2][0] = put_vp8_epel16_v6_altivec; c->put_vp8_epel_pixels_tab[0][2][2] = put_vp8_epel16_h6v6_altivec; c->put_vp8_epel_pixels_tab[1][0][2] = put_vp8_epel8_h6_altivec; c->put_vp8_epel_pixels_tab[1][2][0] = put_vp8_epel8_v6_altivec; c->put_vp8_epel_pixels_tab[1][0][1] = put_vp8_epel8_h4_altivec; c->put_vp8_epel_pixels_tab[1][1][0] = put_vp8_epel8_v4_altivec; c->put_vp8_epel_pixels_tab[1][2][2] = put_vp8_epel8_h6v6_altivec; c->put_vp8_epel_pixels_tab[1][1][1] = put_vp8_epel8_h4v4_altivec; c->put_vp8_epel_pixels_tab[1][1][2] = put_vp8_epel8_h6v4_altivec; c->put_vp8_epel_pixels_tab[1][2][1] = put_vp8_epel8_h4v6_altivec; c->put_vp8_epel_pixels_tab[2][0][2] = put_vp8_epel4_h6_altivec; c->put_vp8_epel_pixels_tab[2][2][0] = put_vp8_epel4_v6_altivec; c->put_vp8_epel_pixels_tab[2][0][1] = put_vp8_epel4_h4_altivec; c->put_vp8_epel_pixels_tab[2][1][0] = put_vp8_epel4_v4_altivec; c->put_vp8_epel_pixels_tab[2][2][2] = put_vp8_epel4_h6v6_altivec; c->put_vp8_epel_pixels_tab[2][1][1] = put_vp8_epel4_h4v4_altivec; c->put_vp8_epel_pixels_tab[2][1][2] = put_vp8_epel4_h6v4_altivec; c->put_vp8_epel_pixels_tab[2][2][1] = put_vp8_epel4_h4v6_altivec; #endif /* HAVE_ALTIVEC */ }
1
1,321
static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { Error *local_err = NULL; BDRVSheepdogState *s = bs->opaque; int ret, fd; uint32_t new_vid; SheepdogInode *inode; unsigned int datalen; DPRINTF("sn_info: name %s id_str %s s: name %s vm_state_size %" PRId64 " " "is_snapshot %d\n", sn_info->name, sn_info->id_str, s->name, sn_info->vm_state_size, s->is_snapshot); if (s->is_snapshot) { error_report("You can't create a snapshot of a snapshot VDI, " "%s (%" PRIu32 ").", s->name, s->inode.vdi_id); return -EINVAL; } DPRINTF("%s %s\n", sn_info->name, sn_info->id_str); s->inode.vm_state_size = sn_info->vm_state_size; s->inode.vm_clock_nsec = sn_info->vm_clock_nsec; /* It appears that inode.tag does not require a NUL terminator, * which means this use of strncpy is ok. */ strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag)); /* we don't need to update entire object */ datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id); /* refresh inode. */ fd = connect_to_sdog(s, &local_err); if (fd < 0) { error_report("%s", error_get_pretty(local_err));; error_free(local_err); ret = fd; goto cleanup; } ret = write_object(fd, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id), s->inode.nr_copies, datalen, 0, false, s->cache_flags); if (ret < 0) { error_report("failed to write snapshot's inode."); goto cleanup; } ret = do_sd_create(s, &new_vid, 1, &local_err); if (ret < 0) { error_report("%s", error_get_pretty(local_err));; error_free(local_err); error_report("failed to create inode for snapshot. %s", strerror(errno)); goto cleanup; } inode = (SheepdogInode *)g_malloc(datalen); ret = read_object(fd, (char *)inode, vid_to_vdi_oid(new_vid), s->inode.nr_copies, datalen, 0, s->cache_flags); if (ret < 0) { error_report("failed to read new inode info. %s", strerror(errno)); goto cleanup; } memcpy(&s->inode, inode, datalen); DPRINTF("s->inode: name %s snap_id %x oid %x\n", s->inode.name, s->inode.snap_id, s->inode.vdi_id); cleanup: closesocket(fd); return ret; }
1
1,322
static int probe(AVProbeData *p) { unsigned i, frames, checked = 0; if (p->buf_size < 22 || AV_RL16(p->buf) || AV_RL16(p->buf + 2) != 1) return 0; frames = AV_RL16(p->buf + 4); if (!frames) return 0; for (i = 0; i < frames && i * 16 + 22 <= p->buf_size; i++) { unsigned offset; if (AV_RL16(p->buf + 10 + i * 16) & ~1) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (p->buf[13 + i * 16]) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (AV_RL32(p->buf + 14 + i * 16) < 40) return FFMIN(i, AVPROBE_SCORE_MAX / 4); offset = AV_RL32(p->buf + 18 + i * 16); if (offset < 22) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (offset + 8 > p->buf_size) continue; if (p->buf[offset] != 40 && AV_RB64(p->buf + offset) != PNGSIG) return FFMIN(i, AVPROBE_SCORE_MAX / 4); checked++; } if (checked < frames) return AVPROBE_SCORE_MAX / 4 + FFMIN(checked, 1); return AVPROBE_SCORE_MAX / 2 + 1; }
0
1,323
int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc) { inc_tb = av_mul_q(inc_tb, (AVRational) {inc, 1}); if (av_cmp_q(inc_tb, ts_tb) < 0) { //increase step is too small for even 1 step to be representable return ts; } else { int64_t old = av_rescale_q(ts, ts_tb, inc_tb); int64_t old_ts = av_rescale_q(old, inc_tb, ts_tb); return av_rescale_q(old + 1, inc_tb, ts_tb) + (ts - old_ts); } }
0
1,325
void ff_put_h264_qpel8_mc11_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_hv_qrt_8w_msa(src - 2, src - (stride * 2), stride, dst, stride, 8); }
0
1,326
static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceContext *sl) { const int mb_x = sl->mb_x; const int mb_y = sl->mb_y; const int mb_xy = sl->mb_xy; const int mb_type = h->cur_pic.mb_type[mb_xy]; uint8_t *dest[3]; int linesize; int i, j, p; const int *block_offset = &h->block_offset[0]; const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->sps.transform_bypass); const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) ? 3 : 1; for (p = 0; p < plane_count; p++) { dest[p] = h->cur_pic.f->data[p] + ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16; h->vdsp.prefetch(dest[p] + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT), sl->linesize, 4); } h->list_counts[mb_xy] = sl->list_count; if (!SIMPLE && MB_FIELD(sl)) { linesize = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize * 2; block_offset = &h->block_offset[48]; if (mb_y & 1) // FIXME move out of this function? for (p = 0; p < 3; p++) dest[p] -= sl->linesize * 15; if (FRAME_MBAFF(h)) { int list; for (list = 0; list < sl->list_count; list++) { if (!USES_LIST(mb_type, list)) continue; if (IS_16X16(mb_type)) { int8_t *ref = &sl->ref_cache[list][scan8[0]]; fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (sl->mb_y & 1), 1); } else { for (i = 0; i < 16; i += 4) { int ref = sl->ref_cache[list][scan8[i]]; if (ref >= 0) fill_rectangle(&sl->ref_cache[list][scan8[i]], 2, 2, 8, (16 + ref) ^ (sl->mb_y & 1), 1); } } } } } else { linesize = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize; } if (!SIMPLE && IS_INTRA_PCM(mb_type)) { if (PIXEL_SHIFT) { const int bit_depth = h->sps.bit_depth_luma; GetBitContext gb; init_get_bits(&gb, sl->intra_pcm_ptr, 768 * bit_depth); for (p = 0; p < plane_count; p++) for (i = 0; i < 16; i++) { uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize); for (j = 0; j < 16; j++) tmp[j] = get_bits(&gb, bit_depth); } } else { for (p = 0; p < plane_count; p++) for (i = 0; i < 16; i++) memcpy(dest[p] + i * linesize, sl->intra_pcm_ptr + p * 256 + i * 16, 16); } } else { if (IS_INTRA(mb_type)) { if (sl->deblocking_filter) xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, SIMPLE, PIXEL_SHIFT); for (p = 0; p < plane_count; p++) hl_decode_mb_predict_luma(h, sl, mb_type, SIMPLE, transform_bypass, PIXEL_SHIFT, block_offset, linesize, dest[p], p); if (sl->deblocking_filter) xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, SIMPLE, PIXEL_SHIFT); } else { FUNC(hl_motion_444)(h, sl, dest[0], dest[1], dest[2], h->qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, h->qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); } for (p = 0; p < plane_count; p++) hl_decode_mb_idct_luma(h, sl, mb_type, SIMPLE, transform_bypass, PIXEL_SHIFT, block_offset, linesize, dest[p], p); } }
1
1,327
static int parse_times(void *log_ctx, int64_t **times, int *nb_times, const char *times_str) { char *p; int i, ret = 0; char *times_str1 = av_strdup(times_str); char *saveptr = NULL; if (!times_str1) return AVERROR(ENOMEM); #define FAIL(err) ret = err; goto end *nb_times = 1; for (p = times_str1; *p; p++) if (*p == ',') (*nb_times)++; *times = av_malloc(sizeof(**times) * *nb_times); if (!*times) { av_log(log_ctx, AV_LOG_ERROR, "Could not allocate forced times array\n"); FAIL(AVERROR(ENOMEM)); } p = times_str1; for (i = 0; i < *nb_times; i++) { int64_t t; char *tstr = av_strtok(p, ",", &saveptr); av_assert0(tstr); p = NULL; ret = av_parse_time(&t, tstr, 1); if (ret < 0) { av_log(log_ctx, AV_LOG_ERROR, "Invalid time duration specification in %s\n", p); FAIL(AVERROR(EINVAL)); } (*times)[i] = t; /* check on monotonicity */ if (i && (*times)[i-1] > (*times)[i]) { av_log(log_ctx, AV_LOG_ERROR, "Specified time %f is greater than the following time %f\n", (float)((*times)[i])/1000000, (float)((*times)[i-1])/1000000); FAIL(AVERROR(EINVAL)); } } end: av_free(times_str1); return ret; }
1
1,328
static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, int * posts, int samples) { int range = 255 / fc->multiplier + 1; int i; for (i = 0; i < fc->values; i++) { int position = fc->list[fc->list[i].sort].x; int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; int j; float average = 0; begin = (position + begin) / 2; end = (position + end ) / 2; assert(end <= samples); for (j = begin; j < end; j++) average += fabs(coeffs[j]); average /= end - begin; average /= 32; // MAGIC! for (j = 0; j < range; j++) if (floor1_inverse_db_table[j * fc->multiplier] > average) break; posts[fc->list[i].sort] = j; } }
1
1,329
static void gen_spr_power8_fscr(CPUPPCState *env) { spr_register_kvm(env, SPR_FSCR, "FSCR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, KVM_REG_PPC_FSCR, 0x00000000); }
1
1,330
static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; PCMDecode *s = avctx->priv_data; int sample_size, c, n, i; short *samples; const uint8_t *src, *src8, *src2[MAX_CHANNELS]; uint8_t *dstu8; int16_t *dst_int16_t; int32_t *dst_int32_t; int64_t *dst_int64_t; uint16_t *dst_uint16_t; uint32_t *dst_uint32_t; samples = data; src = buf; if (avctx->sample_fmt!=avctx->codec->sample_fmts[0]) { av_log(avctx, AV_LOG_ERROR, "invalid sample_fmt\n"); return -1; } if(avctx->channels <= 0 || avctx->channels > MAX_CHANNELS){ av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n"); return -1; } sample_size = av_get_bits_per_sample(avctx->codec_id)/8; /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */ if (CODEC_ID_PCM_DVD == avctx->codec_id) /* 2 samples are interleaved per block in PCM_DVD */ sample_size = avctx->bits_per_coded_sample * 2 / 8; else if (avctx->codec_id == CODEC_ID_PCM_LXF) /* we process 40-bit blocks per channel for LXF */ sample_size = 5; if (sample_size == 0) { av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n"); return AVERROR(EINVAL); } n = avctx->channels * sample_size; if(n && buf_size % n){ if (buf_size < n) { av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n"); return -1; }else buf_size -= buf_size % n; } buf_size= FFMIN(buf_size, *data_size/2); *data_size=0; n = buf_size/sample_size; switch(avctx->codec->id) { case CODEC_ID_PCM_U32LE: DECODE(uint32_t, le32, src, samples, n, 0, 0x80000000) break; case CODEC_ID_PCM_U32BE: DECODE(uint32_t, be32, src, samples, n, 0, 0x80000000) break; case CODEC_ID_PCM_S24LE: DECODE(int32_t, le24, src, samples, n, 8, 0) break; case CODEC_ID_PCM_S24BE: DECODE(int32_t, be24, src, samples, n, 8, 0) break; case CODEC_ID_PCM_U24LE: DECODE(uint32_t, le24, src, samples, n, 8, 0x800000) break; case CODEC_ID_PCM_U24BE: DECODE(uint32_t, be24, src, samples, n, 8, 0x800000) break; case CODEC_ID_PCM_S24DAUD: for(;n>0;n--) { uint32_t v = bytestream_get_be24(&src); v >>= 4; // sync flags are here *samples++ = av_reverse[(v >> 8) & 0xff] + (av_reverse[v & 0xff] << 8); } break; case CODEC_ID_PCM_S16LE_PLANAR: n /= avctx->channels; for(c=0;c<avctx->channels;c++) src2[c] = &src[c*n*2]; for(;n>0;n--) for(c=0;c<avctx->channels;c++) *samples++ = bytestream_get_le16(&src2[c]); src = src2[avctx->channels-1]; break; case CODEC_ID_PCM_U16LE: DECODE(uint16_t, le16, src, samples, n, 0, 0x8000) break; case CODEC_ID_PCM_U16BE: DECODE(uint16_t, be16, src, samples, n, 0, 0x8000) break; case CODEC_ID_PCM_S8: dstu8= (uint8_t*)samples; for(;n>0;n--) { *dstu8++ = *src++ + 128; } samples= (short*)dstu8; break; #if HAVE_BIGENDIAN case CODEC_ID_PCM_F64LE: DECODE(int64_t, le64, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S32LE: case CODEC_ID_PCM_F32LE: DECODE(int32_t, le32, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S16LE: DECODE(int16_t, le16, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F64BE: case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_S32BE: case CODEC_ID_PCM_S16BE: #else case CODEC_ID_PCM_F64BE: DECODE(int64_t, be64, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_S32BE: DECODE(int32_t, be32, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S16BE: DECODE(int16_t, be16, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F64LE: case CODEC_ID_PCM_F32LE: case CODEC_ID_PCM_S32LE: case CODEC_ID_PCM_S16LE: #endif /* HAVE_BIGENDIAN */ case CODEC_ID_PCM_U8: memcpy(samples, src, n*sample_size); src += n*sample_size; samples = (short*)((uint8_t*)data + n*sample_size); break; case CODEC_ID_PCM_ZORK: for(;n>0;n--) { int x= *src++; if(x&128) x-= 128; else x = -x; *samples++ = x << 8; } break; case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: for(;n>0;n--) { *samples++ = s->table[*src++]; } break; case CODEC_ID_PCM_DVD: dst_int32_t = data; n /= avctx->channels; switch (avctx->bits_per_coded_sample) { case 20: while (n--) { c = avctx->channels; src8 = src + 4*c; while (c--) { *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 &0xf0) << 8); *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ &0x0f) << 12); } src = src8; } break; case 24: while (n--) { c = avctx->channels; src8 = src + 4*c; while (c--) { *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8); *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8); } src = src8; } break; default: av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n"); return -1; } samples = (short *) dst_int32_t; break; case CODEC_ID_PCM_LXF: dst_int32_t = data; n /= avctx->channels; //unpack and de-planerize for (i = 0; i < n; i++) { for (c = 0, src8 = src + i*5; c < avctx->channels; c++, src8 += n*5) { //extract low 20 bits and expand to 32 bits *dst_int32_t++ = (src8[2] << 28) | (src8[1] << 20) | (src8[0] << 12) | ((src8[2] & 0xF) << 8) | src8[1]; } for (c = 0, src8 = src + i*5; c < avctx->channels; c++, src8 += n*5) { //extract high 20 bits and expand to 32 bits *dst_int32_t++ = (src8[4] << 24) | (src8[3] << 16) | ((src8[2] & 0xF0) << 8) | (src8[4] << 4) | (src8[3] >> 4); } } src += n * avctx->channels * 5; samples = (short *) dst_int32_t; break; default: return -1; } *data_size = (uint8_t *)samples - (uint8_t *)data; return src - buf; }
1
1,331
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { int i, ret = 0; if (!avpkt->data && avpkt->size) { av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); return AVERROR(EINVAL); } if (!avctx->codec) return AVERROR(EINVAL); if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) { av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n"); return AVERROR(EINVAL); } *got_sub_ptr = 0; get_subtitle_defaults(sub); if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) { AVPacket pkt_recoded; AVPacket tmp = *avpkt; int did_split = av_packet_split_side_data(&tmp); //apply_param_change(avctx, &tmp); if (did_split) { /* FFMIN() prevents overflow in case the packet wasn't allocated with * proper padding. * If the side data is smaller than the buffer padding size, the * remaining bytes should have already been filled with zeros by the * original packet allocation anyway. */ memset(tmp.data + tmp.size, 0, FFMIN(avpkt->size - tmp.size, AV_INPUT_BUFFER_PADDING_SIZE)); } pkt_recoded = tmp; ret = recode_subtitle(avctx, &pkt_recoded, &tmp); if (ret < 0) { *got_sub_ptr = 0; } else { avctx->internal->pkt = &pkt_recoded; if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded); av_assert1((ret >= 0) >= !!*got_sub_ptr && !!*got_sub_ptr >= !!sub->num_rects); if (sub->num_rects && !sub->end_display_time && avpkt->duration && avctx->pkt_timebase.num) { AVRational ms = { 1, 1000 }; sub->end_display_time = av_rescale_q(avpkt->duration, avctx->pkt_timebase, ms); } for (i = 0; i < sub->num_rects; i++) { if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) { av_log(avctx, AV_LOG_ERROR, "Invalid UTF-8 in decoded subtitles text; " "maybe missing -sub_charenc option\n"); avsubtitle_free(sub); return AVERROR_INVALIDDATA; } } if (tmp.data != pkt_recoded.data) { // did we recode? /* prevent from destroying side data from original packet */ pkt_recoded.side_data = NULL; pkt_recoded.side_data_elems = 0; av_packet_unref(&pkt_recoded); } if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) sub->format = 0; else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) sub->format = 1; avctx->internal->pkt = NULL; } if (did_split) { av_packet_free_side_data(&tmp); if(ret == tmp.size) ret = avpkt->size; } if (*got_sub_ptr) avctx->frame_number++; } return ret; }
1
1,332
static int flv_write_packet(AVFormatContext *s, int stream_index, const uint8_t *buf, int size, int64_t timestamp) { ByteIOContext *pb = &s->pb; AVCodecContext *enc = &s->streams[stream_index]->codec; FLVContext *flv = s->priv_data; if (enc->codec_type == CODEC_TYPE_VIDEO) { FLVFrame *frame = av_malloc(sizeof(FLVFrame)); frame->next = 0; frame->type = 9; frame->flags = 2; // choose h263 frame->flags |= enc->coded_frame->key_frame ? 0x10 : 0x20; // add keyframe indicator frame->timestamp = timestamp; //frame->timestamp = ( ( flv->frameCount * (int64_t)FRAME_RATE_BASE * (int64_t)1000 ) / (int64_t)enc->frame_rate ); //printf("%08x %f %f\n",frame->timestamp,(double)enc->frame_rate/(double)FRAME_RATE_BASE,1000*(double)FRAME_RATE_BASE/(double)enc->frame_rate); frame->size = size; frame->data = av_malloc(size); memcpy(frame->data,buf,size); flv->hasVideo = 1; InsertSorted(flv,frame); flv->frameCount ++; } else if (enc->codec_type == CODEC_TYPE_AUDIO) { #ifdef CONFIG_MP3LAME if (enc->codec_id == CODEC_ID_MP3 ) { int c=0; for (;c<size;c++) { flv->audioFifo[(flv->audioOutPos+c)%AUDIO_FIFO_SIZE] = buf[c]; } flv->audioSize += size; flv->audioOutPos += size; flv->audioOutPos %= AUDIO_FIFO_SIZE; if ( flv->initDelay == -1 ) { flv->initDelay = timestamp; } if ( flv->audioTime == -1 ) { flv->audioTime = timestamp; // flv->audioTime = ( ( ( flv->sampleCount - enc->delay ) * 8000 ) / flv->audioRate ) - flv->initDelay - 250; // if ( flv->audioTime < 0 ) { // flv->audioTime = 0; // } } } for ( ; flv->audioSize >= 4 ; ) { int mp3FrameSize = 0; int mp3SampleRate = 0; int mp3IsMono = 0; int mp3SamplesPerFrame = 0; if ( mp3info(&flv->audioFifo[flv->audioInPos],&mp3FrameSize,&mp3SamplesPerFrame,&mp3SampleRate,&mp3IsMono) ) { if ( flv->audioSize >= mp3FrameSize ) { int soundFormat = 0x22; int c=0; FLVFrame *frame = av_malloc(sizeof(FLVFrame)); flv->audioRate = mp3SampleRate; switch (mp3SampleRate) { case 44100: soundFormat |= 0x0C; break; case 22050: soundFormat |= 0x08; break; case 11025: soundFormat |= 0x04; break; } if ( !mp3IsMono ) { soundFormat |= 0x01; } frame->next = 0; frame->type = 8; frame->flags = soundFormat; frame->timestamp = flv->audioTime; frame->size = mp3FrameSize; frame->data = av_malloc(mp3FrameSize); for (;c<mp3FrameSize;c++) { frame->data[c] = flv->audioFifo[(flv->audioInPos+c)%AUDIO_FIFO_SIZE]; } flv->audioInPos += mp3FrameSize; flv->audioSize -= mp3FrameSize; flv->audioInPos %= AUDIO_FIFO_SIZE; flv->sampleCount += mp3SamplesPerFrame; // Reset audio for next round flv->audioTime = -1; // We got audio! Make sure we set this to the global flags on closure flv->hasAudio = 1; InsertSorted(flv,frame); } break; } flv->audioInPos ++; flv->audioSize --; flv->audioInPos %= AUDIO_FIFO_SIZE; // no audio in here! flv->audioTime = -1; } #endif } Dump(flv,pb,128); put_flush_packet(pb); return 0; }
1
1,333
void ahci_init(AHCIState *s, DeviceState *qdev, DMAContext *dma, int ports) { qemu_irq *irqs; int i; s->dma = dma; s->ports = ports; s->dev = g_malloc0(sizeof(AHCIDevice) * ports); ahci_reg_init(s); /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ memory_region_init_io(&s->mem, &ahci_mem_ops, s, "ahci", AHCI_MEM_BAR_SIZE); memory_region_init_io(&s->idp, &ahci_idp_ops, s, "ahci-idp", 32); irqs = qemu_allocate_irqs(ahci_irq_set, s, s->ports); for (i = 0; i < s->ports; i++) { AHCIDevice *ad = &s->dev[i]; ide_bus_new(&ad->port, qdev, i); ide_init2(&ad->port, irqs[i]); ad->hba = s; ad->port_no = i; ad->port.dma = &ad->dma; ad->port.dma->ops = &ahci_dma_ops; ad->port_regs.cmd = PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON; } }
1
1,334
static void put_psr(target_ulong val) { env->psr = val & PSR_ICC; env->psref = (val & PSR_EF)? 1 : 0; env->psrpil = (val & PSR_PIL) >> 8; #if ((!defined (TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY)) cpu_check_irqs(env); #endif env->psrs = (val & PSR_S)? 1 : 0; env->psrps = (val & PSR_PS)? 1 : 0; #if !defined (TARGET_SPARC64) env->psret = (val & PSR_ET)? 1 : 0; #endif set_cwp(val & PSR_CWP); env->cc_op = CC_OP_FLAGS; }
0
1,336
void dsputil_init_ppc(void) { // Common optimisations whether Altivec or not // ... pending ... #if HAVE_ALTIVEC if (has_altivec()) { // Altivec specific optimisations pix_abs16x16 = pix_abs16x16_altivec; pix_abs8x8 = pix_abs8x8_altivec; pix_sum = pix_sum_altivec; diff_pixels = diff_pixels_altivec; get_pixels = get_pixels_altivec; } else #endif { // Non-AltiVec PPC optimisations // ... pending ... } }
1
1,339
int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, int64_t size) { BDRVQcowState *s = bs->opaque; int chk = s->overlap_check & ~ign; int i, j; if (!size) { return 0; } if (chk & QCOW2_OL_MAIN_HEADER) { if (offset < s->cluster_size) { return QCOW2_OL_MAIN_HEADER; } } /* align range to test to cluster boundaries */ size = align_offset(offset_into_cluster(s, offset) + size, s->cluster_size); offset = start_of_cluster(s, offset); if ((chk & QCOW2_OL_ACTIVE_L1) && s->l1_size) { if (overlaps_with(s->l1_table_offset, s->l1_size * sizeof(uint64_t))) { return QCOW2_OL_ACTIVE_L1; } } if ((chk & QCOW2_OL_REFCOUNT_TABLE) && s->refcount_table_size) { if (overlaps_with(s->refcount_table_offset, s->refcount_table_size * sizeof(uint64_t))) { return QCOW2_OL_REFCOUNT_TABLE; } } if ((chk & QCOW2_OL_SNAPSHOT_TABLE) && s->snapshots_size) { if (overlaps_with(s->snapshots_offset, s->snapshots_size)) { return QCOW2_OL_SNAPSHOT_TABLE; } } if ((chk & QCOW2_OL_INACTIVE_L1) && s->snapshots) { for (i = 0; i < s->nb_snapshots; i++) { if (s->snapshots[i].l1_size && overlaps_with(s->snapshots[i].l1_table_offset, s->snapshots[i].l1_size * sizeof(uint64_t))) { return QCOW2_OL_INACTIVE_L1; } } } if ((chk & QCOW2_OL_ACTIVE_L2) && s->l1_table) { for (i = 0; i < s->l1_size; i++) { if ((s->l1_table[i] & L1E_OFFSET_MASK) && overlaps_with(s->l1_table[i] & L1E_OFFSET_MASK, s->cluster_size)) { return QCOW2_OL_ACTIVE_L2; } } } if ((chk & QCOW2_OL_REFCOUNT_BLOCK) && s->refcount_table) { for (i = 0; i < s->refcount_table_size; i++) { if ((s->refcount_table[i] & REFT_OFFSET_MASK) && overlaps_with(s->refcount_table[i] & REFT_OFFSET_MASK, s->cluster_size)) { return QCOW2_OL_REFCOUNT_BLOCK; } } } if ((chk & QCOW2_OL_INACTIVE_L2) && s->snapshots) { for (i = 0; i < s->nb_snapshots; i++) { uint64_t l1_ofs = s->snapshots[i].l1_table_offset; uint32_t l1_sz = s->snapshots[i].l1_size; uint64_t l1_sz2 = l1_sz * sizeof(uint64_t); uint64_t *l1 = g_malloc(l1_sz2); int ret; ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2); if (ret < 0) { g_free(l1); return ret; } for (j = 0; j < l1_sz; j++) { uint64_t l2_ofs = be64_to_cpu(l1[j]) & L1E_OFFSET_MASK; if (l2_ofs && overlaps_with(l2_ofs, s->cluster_size)) { g_free(l1); return QCOW2_OL_INACTIVE_L2; } } g_free(l1); } } return 0; }
1
1,340
static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type, AVFormatContext *fmt) { char *config = NULL; switch (c->codec_id) { case AV_CODEC_ID_H264: { int mode = 1; if (fmt && fmt->oformat && fmt->oformat->priv_class && av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0")) mode = 0; if (c->extradata_size) { config = extradata2psets(c); } av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" "a=fmtp:%d packetization-mode=%d%s\r\n", payload_type, payload_type, mode, config ? config : ""); break; } case AV_CODEC_ID_H263: case AV_CODEC_ID_H263P: /* a=framesize is required by 3GPP TS 26.234 (PSS). It * actually specifies the maximum video size, but we only know * the current size. This is required for playback on Android * stagefright and on Samsung bada. */ if (!fmt || !fmt->oformat->priv_class || !av_opt_flag_is_set(fmt->priv_data, "rtpflags", "rfc2190") || c->codec_id == AV_CODEC_ID_H263P) av_strlcatf(buff, size, "a=rtpmap:%d H263-2000/90000\r\n" "a=framesize:%d %d-%d\r\n", payload_type, payload_type, c->width, c->height); break; case AV_CODEC_ID_HEVC: if (c->extradata_size) av_log(NULL, AV_LOG_WARNING, "HEVC extradata not currently " "passed properly through SDP\n"); av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type); break; case AV_CODEC_ID_MPEG4: if (c->extradata_size) { config = extradata2config(c); } av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" "a=fmtp:%d profile-level-id=1%s\r\n", payload_type, payload_type, config ? config : ""); break; case AV_CODEC_ID_AAC: if (fmt && fmt->oformat->priv_class && av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { config = latm_context2config(c); if (!config) return NULL; av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", payload_type, c->sample_rate, c->channels, payload_type, latm_context2profilelevel(c), config); } else { if (c->extradata_size) { config = extradata2config(c); } else { /* FIXME: maybe we can forge config information based on the * codec parameters... */ av_log(c, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); return NULL; } if (!config) { return NULL; } av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" "a=fmtp:%d profile-level-id=1;" "mode=AAC-hbr;sizelength=13;indexlength=3;" "indexdeltalength=3%s\r\n", payload_type, c->sample_rate, c->channels, payload_type, config); } break; case AV_CODEC_ID_PCM_S16BE: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", payload_type, c->sample_rate, c->channels); break; case AV_CODEC_ID_PCM_MULAW: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", payload_type, c->sample_rate, c->channels); break; case AV_CODEC_ID_PCM_ALAW: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", payload_type, c->sample_rate, c->channels); break; case AV_CODEC_ID_AMR_NB: av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n" "a=fmtp:%d octet-align=1\r\n", payload_type, c->sample_rate, c->channels, payload_type); break; case AV_CODEC_ID_AMR_WB: av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n" "a=fmtp:%d octet-align=1\r\n", payload_type, c->sample_rate, c->channels, payload_type); break; case AV_CODEC_ID_VORBIS: if (c->extradata_size) config = xiph_extradata2config(c); else av_log(c, AV_LOG_ERROR, "Vorbis configuration info missing\n"); if (!config) return NULL; av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n" "a=fmtp:%d configuration=%s\r\n", payload_type, c->sample_rate, c->channels, payload_type, config); break; case AV_CODEC_ID_THEORA: { const char *pix_fmt; switch (c->pix_fmt) { case AV_PIX_FMT_YUV420P: pix_fmt = "YCbCr-4:2:0"; break; case AV_PIX_FMT_YUV422P: pix_fmt = "YCbCr-4:2:2"; break; case AV_PIX_FMT_YUV444P: pix_fmt = "YCbCr-4:4:4"; break; default: av_log(c, AV_LOG_ERROR, "Unsupported pixel format.\n"); return NULL; } if (c->extradata_size) config = xiph_extradata2config(c); else av_log(c, AV_LOG_ERROR, "Theora configuation info missing\n"); if (!config) return NULL; av_strlcatf(buff, size, "a=rtpmap:%d theora/90000\r\n" "a=fmtp:%d delivery-method=inline; " "width=%d; height=%d; sampling=%s; " "configuration=%s\r\n", payload_type, payload_type, c->width, c->height, pix_fmt, config); break; } case AV_CODEC_ID_VP8: av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n", payload_type); break; case AV_CODEC_ID_MJPEG: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d JPEG/90000\r\n", payload_type); break; case AV_CODEC_ID_ADPCM_G722: if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n", payload_type, 8000, c->channels); break; case AV_CODEC_ID_ADPCM_G726: { if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", payload_type, c->bits_per_coded_sample*8, c->sample_rate); break; } case AV_CODEC_ID_ILBC: av_strlcatf(buff, size, "a=rtpmap:%d iLBC/%d\r\n" "a=fmtp:%d mode=%d\r\n", payload_type, c->sample_rate, payload_type, c->block_align == 38 ? 20 : 30); break; case AV_CODEC_ID_SPEEX: av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n", payload_type, c->sample_rate); break; case AV_CODEC_ID_OPUS: /* The opus RTP draft says that all opus streams MUST be declared as stereo, to avoid negotiation failures. The actual number of channels can change on a packet-by-packet basis. The number of channels a receiver prefers to receive or a sender plans to send can be declared via fmtp parameters (both default to mono), but receivers MUST be able to receive and process stereo packets. */ av_strlcatf(buff, size, "a=rtpmap:%d opus/48000/2\r\n", payload_type); if (c->channels == 2) { av_strlcatf(buff, size, "a=fmtp:%d sprop-stereo:1\r\n", payload_type); } break; default: /* Nothing special to do here... */ break; } av_free(config); return buff; }
1
1,342
static void compute_status(HTTPContext *c) { HTTPContext *c1; FFStream *stream; char *p; time_t ti; int i, len; AVIOContext *pb; if (avio_open_dyn_buf(&pb) < 0) { /* XXX: return an error ? */ c->buffer_ptr = c->buffer; c->buffer_end = c->buffer; return; } avio_printf(pb, "HTTP/1.0 200 OK\r\n"); avio_printf(pb, "Content-type: %s\r\n", "text/html"); avio_printf(pb, "Pragma: no-cache\r\n"); avio_printf(pb, "\r\n"); avio_printf(pb, "<html><head><title>%s Status</title>\n", program_name); if (c->stream->feed_filename[0]) avio_printf(pb, "<link rel=\"shortcut icon\" href=\"%s\">\n", c->stream->feed_filename); avio_printf(pb, "</head>\n<body>"); avio_printf(pb, "<h1>%s Status</h1>\n", program_name); /* format status */ avio_printf(pb, "<h2>Available Streams</h2>\n"); avio_printf(pb, "<table cellspacing=0 cellpadding=4>\n"); avio_printf(pb, "<tr><th valign=top>Path<th align=left>Served<br>Conns<th><br>bytes<th valign=top>Format<th>Bit rate<br>kbits/s<th align=left>Video<br>kbits/s<th><br>Codec<th align=left>Audio<br>kbits/s<th><br>Codec<th align=left valign=top>Feed\n"); stream = first_stream; while (stream != NULL) { char sfilename[1024]; char *eosf; if (stream->feed != stream) { av_strlcpy(sfilename, stream->filename, sizeof(sfilename) - 10); eosf = sfilename + strlen(sfilename); if (eosf - sfilename >= 4) { if (strcmp(eosf - 4, ".asf") == 0) strcpy(eosf - 4, ".asx"); else if (strcmp(eosf - 3, ".rm") == 0) strcpy(eosf - 3, ".ram"); else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) { /* generate a sample RTSP director if unicast. Generate an SDP redirector if multicast */ eosf = strrchr(sfilename, '.'); if (!eosf) eosf = sfilename + strlen(sfilename); if (stream->is_multicast) strcpy(eosf, ".sdp"); else strcpy(eosf, ".rtsp"); } } avio_printf(pb, "<tr><td><a href=\"/%s\">%s</a> ", sfilename, stream->filename); avio_printf(pb, "<td align=right> %d <td align=right> ", stream->conns_served); fmt_bytecount(pb, stream->bytes_served); switch(stream->stream_type) { case STREAM_TYPE_LIVE: { int audio_bit_rate = 0; int video_bit_rate = 0; const char *audio_codec_name = ""; const char *video_codec_name = ""; const char *audio_codec_name_extra = ""; const char *video_codec_name_extra = ""; for(i=0;i<stream->nb_streams;i++) { AVStream *st = stream->streams[i]; AVCodec *codec = avcodec_find_encoder(st->codec->codec_id); switch(st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: audio_bit_rate += st->codec->bit_rate; if (codec) { if (*audio_codec_name) audio_codec_name_extra = "..."; audio_codec_name = codec->name; } break; case AVMEDIA_TYPE_VIDEO: video_bit_rate += st->codec->bit_rate; if (codec) { if (*video_codec_name) video_codec_name_extra = "..."; video_codec_name = codec->name; } break; case AVMEDIA_TYPE_DATA: video_bit_rate += st->codec->bit_rate; break; default: abort(); } } avio_printf(pb, "<td align=center> %s <td align=right> %d <td align=right> %d <td> %s %s <td align=right> %d <td> %s %s", stream->fmt->name, stream->bandwidth, video_bit_rate / 1000, video_codec_name, video_codec_name_extra, audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra); if (stream->feed) avio_printf(pb, "<td>%s", stream->feed->filename); else avio_printf(pb, "<td>%s", stream->feed_filename); avio_printf(pb, "\n"); } break; default: avio_printf(pb, "<td align=center> - <td align=right> - <td align=right> - <td><td align=right> - <td>\n"); break; } } stream = stream->next; } avio_printf(pb, "</table>\n"); stream = first_stream; while (stream != NULL) { if (stream->feed == stream) { avio_printf(pb, "<h2>Feed %s</h2>", stream->filename); if (stream->pid) { avio_printf(pb, "Running as pid %d.\n", stream->pid); #if defined(linux) && !defined(CONFIG_NOCUTILS) { FILE *pid_stat; char ps_cmd[64]; /* This is somewhat linux specific I guess */ snprintf(ps_cmd, sizeof(ps_cmd), "ps -o \"%%cpu,cputime\" --no-headers %d", stream->pid); pid_stat = popen(ps_cmd, "r"); if (pid_stat) { char cpuperc[10]; char cpuused[64]; if (fscanf(pid_stat, "%10s %64s", cpuperc, cpuused) == 2) { avio_printf(pb, "Currently using %s%% of the cpu. Total time used %s.\n", cpuperc, cpuused); } fclose(pid_stat); } } #endif avio_printf(pb, "<p>"); } avio_printf(pb, "<table cellspacing=0 cellpadding=4><tr><th>Stream<th>type<th>kbits/s<th align=left>codec<th align=left>Parameters\n"); for (i = 0; i < stream->nb_streams; i++) { AVStream *st = stream->streams[i]; AVCodec *codec = avcodec_find_encoder(st->codec->codec_id); const char *type = "unknown"; char parameters[64]; parameters[0] = 0; switch(st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO: type = "audio"; snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz", st->codec->channels, st->codec->sample_rate); break; case AVMEDIA_TYPE_VIDEO: type = "video"; snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec->width, st->codec->height, st->codec->qmin, st->codec->qmax, st->codec->time_base.den / st->codec->time_base.num); break; default: abort(); } avio_printf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d<td>%s<td>%s\n", i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters); } avio_printf(pb, "</table>\n"); } stream = stream->next; } /* connection status */ avio_printf(pb, "<h2>Connection Status</h2>\n"); avio_printf(pb, "Number of connections: %d / %d<br>\n", nb_connections, nb_max_connections); avio_printf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k<br>\n", current_bandwidth, max_bandwidth); avio_printf(pb, "<table>\n"); avio_printf(pb, "<tr><th>#<th>File<th>IP<th>Proto<th>State<th>Target bits/sec<th>Actual bits/sec<th>Bytes transferred\n"); c1 = first_http_ctx; i = 0; while (c1 != NULL) { int bitrate; int j; bitrate = 0; if (c1->stream) { for (j = 0; j < c1->stream->nb_streams; j++) { if (!c1->stream->feed) bitrate += c1->stream->streams[j]->codec->bit_rate; else if (c1->feed_streams[j] >= 0) bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec->bit_rate; } } i++; p = inet_ntoa(c1->from_addr.sin_addr); avio_printf(pb, "<tr><td><b>%d</b><td>%s%s<td>%s<td>%s<td>%s<td align=right>", i, c1->stream ? c1->stream->filename : "", c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "", p, c1->protocol, http_state[c1->state]); fmt_bytecount(pb, bitrate); avio_printf(pb, "<td align=right>"); fmt_bytecount(pb, compute_datarate(&c1->datarate, c1->data_count) * 8); avio_printf(pb, "<td align=right>"); fmt_bytecount(pb, c1->data_count); avio_printf(pb, "\n"); c1 = c1->next; } avio_printf(pb, "</table>\n"); /* date */ ti = time(NULL); p = ctime(&ti); avio_printf(pb, "<hr size=1 noshade>Generated at %s", p); avio_printf(pb, "</body>\n</html>\n"); len = avio_close_dyn_buf(pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; }
1
1,343
static void esp_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) { ESPState *s = opaque; uint32_t saddr; saddr = (addr >> s->it_shift) & (ESP_REGS - 1); DPRINTF("write reg[%d]: 0x%2.2x -> 0x%2.2x\n", saddr, s->wregs[saddr], val); switch (saddr) { case ESP_TCLO: case ESP_TCMID: s->rregs[ESP_RSTAT] &= ~STAT_TC; break; case ESP_FIFO: if (s->do_cmd) { s->cmdbuf[s->cmdlen++] = val & 0xff; } else if ((s->rregs[ESP_RSTAT] & STAT_PIO_MASK) == 0) { uint8_t buf; buf = val & 0xff; s->ti_size--; fprintf(stderr, "esp: PIO data write not implemented\n"); } else { s->ti_size++; s->ti_buf[s->ti_wptr++] = val & 0xff; } break; case ESP_CMD: s->rregs[saddr] = val; if (val & CMD_DMA) { s->dma = 1; /* Reload DMA counter. */ s->rregs[ESP_TCLO] = s->wregs[ESP_TCLO]; s->rregs[ESP_TCMID] = s->wregs[ESP_TCMID]; } else { s->dma = 0; } switch(val & CMD_CMD) { case CMD_NOP: DPRINTF("NOP (%2.2x)\n", val); break; case CMD_FLUSH: DPRINTF("Flush FIFO (%2.2x)\n", val); //s->ti_size = 0; s->rregs[ESP_RINTR] = INTR_FC; s->rregs[ESP_RSEQ] = 0; s->rregs[ESP_RFLAGS] = 0; break; case CMD_RESET: DPRINTF("Chip reset (%2.2x)\n", val); esp_reset(s); break; case CMD_BUSRESET: DPRINTF("Bus reset (%2.2x)\n", val); s->rregs[ESP_RINTR] = INTR_RST; if (!(s->wregs[ESP_CFG1] & CFG1_RESREPT)) { esp_raise_irq(s); } break; case CMD_TI: handle_ti(s); break; case CMD_ICCS: DPRINTF("Initiator Command Complete Sequence (%2.2x)\n", val); write_response(s); break; case CMD_MSGACC: DPRINTF("Message Accepted (%2.2x)\n", val); write_response(s); s->rregs[ESP_RINTR] = INTR_DC; s->rregs[ESP_RSEQ] = 0; break; case CMD_SATN: DPRINTF("Set ATN (%2.2x)\n", val); break; case CMD_SELATN: DPRINTF("Set ATN (%2.2x)\n", val); handle_satn(s); break; case CMD_SELATNS: DPRINTF("Set ATN & stop (%2.2x)\n", val); handle_satn_stop(s); break; case CMD_ENSEL: DPRINTF("Enable selection (%2.2x)\n", val); break; default: DPRINTF("Unhandled ESP command (%2.2x)\n", val); break; } break; case ESP_WBUSID ... ESP_WSYNO: break; case ESP_CFG1: s->rregs[saddr] = val; break; case ESP_WCCF ... ESP_WTEST: break; case ESP_CFG2: s->rregs[saddr] = val & CFG2_MASK; break; case ESP_CFG3 ... ESP_RES4: s->rregs[saddr] = val; break; default: break; } s->wregs[saddr] = val; }
0
1,344
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, FLACFrameInfo *fi) { int bs_code, sr_code, bps_code; /* frame sync code */ skip_bits(gb, 16); /* block size and sample rate codes */ bs_code = get_bits(gb, 4); sr_code = get_bits(gb, 4); /* channels and decorrelation */ fi->ch_mode = get_bits(gb, 4); if (fi->ch_mode < FLAC_MAX_CHANNELS) { fi->channels = fi->ch_mode + 1; fi->ch_mode = FLAC_CHMODE_INDEPENDENT; } else if (fi->ch_mode <= FLAC_CHMODE_MID_SIDE) { fi->channels = 2; } else { av_log(avctx, AV_LOG_ERROR, "invalid channel mode: %d\n", fi->ch_mode); return -1; } /* bits per sample */ bps_code = get_bits(gb, 3); if (bps_code == 3 || bps_code == 7) { av_log(avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", bps_code); return -1; } fi->bps = sample_size_table[bps_code]; /* reserved bit */ if (get_bits1(gb)) { av_log(avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); return -1; } /* sample or frame count */ if (get_utf8(gb) < 0) { av_log(avctx, AV_LOG_ERROR, "utf8 fscked\n"); return -1; } /* blocksize */ if (bs_code == 0) { av_log(avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n"); return -1; } else if (bs_code == 6) { fi->blocksize = get_bits(gb, 8) + 1; } else if (bs_code == 7) { fi->blocksize = get_bits(gb, 16) + 1; } else { fi->blocksize = ff_flac_blocksize_table[bs_code]; } /* sample rate */ if (sr_code < 12) { fi->samplerate = ff_flac_sample_rate_table[sr_code]; } else if (sr_code == 12) { fi->samplerate = get_bits(gb, 8) * 1000; } else if (sr_code == 13) { fi->samplerate = get_bits(gb, 16); } else if (sr_code == 14) { fi->samplerate = get_bits(gb, 16) * 10; } else { av_log(avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", sr_code); return -1; } /* header CRC-8 check */ skip_bits(gb, 8); if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer, get_bits_count(gb)/8)) { av_log(avctx, AV_LOG_ERROR, "header crc mismatch\n"); return -1; } return 0; }
0
1,345
static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) { AVIOContext *dyn_cp; mkv_seekhead *seekhead = mkv->main_seekhead; ebml_master metaseek, seekentry; int64_t currentpos; int i; currentpos = avio_tell(pb); if (seekhead->reserved_size > 0) { if (avio_seek(pb, seekhead->filepos, SEEK_SET) < 0) { currentpos = -1; goto fail; } } if (start_ebml_master_crc32(pb, &dyn_cp, &metaseek, MATROSKA_ID_SEEKHEAD, seekhead->reserved_size) < 0) { currentpos = -1; goto fail; } for (i = 0; i < seekhead->num_entries; i++) { mkv_seekhead_entry *entry = &seekhead->entries[i]; seekentry = start_ebml_master(dyn_cp, MATROSKA_ID_SEEKENTRY, MAX_SEEKENTRY_SIZE); put_ebml_id(dyn_cp, MATROSKA_ID_SEEKID); put_ebml_num(dyn_cp, ebml_id_size(entry->elementid), 0); put_ebml_id(dyn_cp, entry->elementid); put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); end_ebml_master(dyn_cp, seekentry); } end_ebml_master_crc32(pb, &dyn_cp, mkv, metaseek); if (seekhead->reserved_size > 0) { uint64_t remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); put_ebml_void(pb, remaining); avio_seek(pb, currentpos, SEEK_SET); currentpos = seekhead->filepos; } fail: av_freep(&mkv->main_seekhead->entries); av_freep(&mkv->main_seekhead); return currentpos; }