uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; int max; uint32_t ret = 0; uint32_t cpuid_1_edx; bool found = false; max = 1; while ((cpuid = try_get_cpuid(s, max)) == NULL) { max *= 2; } struct kvm_cpuid_entry2 *entry = cpuid_find_entry(cpuid, function, index); if (entry) { found = true; ret = cpuid_entry_get_reg(entry, reg); } /* Fixups for the data returned by KVM, below */ if (reg == R_EDX) { switch (function) { case 1: /* KVM before 2.6.30 misreports the following features */ ret |= CPUID_MTRR | CPUID_PAT | CPUID_MCE | CPUID_MCA; break; case 0x80000001: /* On Intel, kvm returns cpuid according to the Intel spec, * so add missing bits according to the AMD spec: */ cpuid_1_edx = kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX); ret |= cpuid_1_edx & CPUID_EXT2_AMD_ALIASES; break; } } g_free(cpuid); /* fallback for older kernels */ if ((function == KVM_CPUID_FEATURES) && !found) { ret = get_para_features(s); } return ret; }


static abi_long do_socketcall(int num, abi_ulong vptr) { abi_long ret; const int n = sizeof(abi_ulong); switch(num) { case SOCKOP_socket: { abi_ulong domain, type, protocol; if (get_user_ual(domain, vptr) || get_user_ual(type, vptr + n) || get_user_ual(protocol, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_socket(domain, type, protocol); } break; case SOCKOP_bind: { abi_ulong sockfd; abi_ulong target_addr; socklen_t addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(addrlen, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_bind(sockfd, target_addr, addrlen); } break; case SOCKOP_connect: { abi_ulong sockfd; abi_ulong target_addr; socklen_t addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(addrlen, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_connect(sockfd, target_addr, addrlen); } break; case SOCKOP_listen: { abi_ulong sockfd, backlog; if (get_user_ual(sockfd, vptr) || get_user_ual(backlog, vptr + n)) return -TARGET_EFAULT; ret = get_errno(listen(sockfd, backlog)); } break; case SOCKOP_accept: { abi_ulong sockfd; abi_ulong target_addr, target_addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(target_addrlen, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_accept4(sockfd, target_addr, target_addrlen, 0); } break; case SOCKOP_accept4: { abi_ulong sockfd; abi_ulong target_addr, target_addrlen; abi_ulong flags; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(target_addrlen, vptr + 2 * n) || get_user_ual(flags, vptr + 3 * n)) { return -TARGET_EFAULT; } ret = do_accept4(sockfd, target_addr, target_addrlen, flags); } break; case SOCKOP_getsockname: { abi_ulong sockfd; abi_ulong target_addr, target_addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(target_addrlen, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_getsockname(sockfd, target_addr, target_addrlen); } break; case SOCKOP_getpeername: { abi_ulong sockfd; abi_ulong target_addr, target_addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(target_addr, vptr + n) || get_user_ual(target_addrlen, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_getpeername(sockfd, target_addr, target_addrlen); } break; case SOCKOP_socketpair: { abi_ulong domain, type, protocol; abi_ulong tab; if (get_user_ual(domain, vptr) || get_user_ual(type, vptr + n) || get_user_ual(protocol, vptr + 2 * n) || get_user_ual(tab, vptr + 3 * n)) return -TARGET_EFAULT; ret = do_socketpair(domain, type, protocol, tab); } break; case SOCKOP_send: { abi_ulong sockfd; abi_ulong msg; size_t len; abi_ulong flags; if (get_user_ual(sockfd, vptr) || get_user_ual(msg, vptr + n) || get_user_ual(len, vptr + 2 * n) || get_user_ual(flags, vptr + 3 * n)) return -TARGET_EFAULT; ret = do_sendto(sockfd, msg, len, flags, 0, 0); } break; case SOCKOP_recv: { abi_ulong sockfd; abi_ulong msg; size_t len; abi_ulong flags; if (get_user_ual(sockfd, vptr) || get_user_ual(msg, vptr + n) || get_user_ual(len, vptr + 2 * n) || get_user_ual(flags, vptr + 3 * n)) return -TARGET_EFAULT; ret = do_recvfrom(sockfd, msg, len, flags, 0, 0); } break; case SOCKOP_sendto: { abi_ulong sockfd; abi_ulong msg; size_t len; abi_ulong flags; abi_ulong addr; abi_ulong addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(msg, vptr + n) || get_user_ual(len, vptr + 2 * n) || get_user_ual(flags, vptr + 3 * n) || get_user_ual(addr, vptr + 4 * n) || get_user_ual(addrlen, vptr + 5 * n)) return -TARGET_EFAULT; ret = do_sendto(sockfd, msg, len, flags, addr, addrlen); } break; case SOCKOP_recvfrom: { abi_ulong sockfd; abi_ulong msg; size_t len; abi_ulong flags; abi_ulong addr; socklen_t addrlen; if (get_user_ual(sockfd, vptr) || get_user_ual(msg, vptr + n) || get_user_ual(len, vptr + 2 * n) || get_user_ual(flags, vptr + 3 * n) || get_user_ual(addr, vptr + 4 * n) || get_user_ual(addrlen, vptr + 5 * n)) return -TARGET_EFAULT; ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen); } break; case SOCKOP_shutdown: { abi_ulong sockfd, how; if (get_user_ual(sockfd, vptr) || get_user_ual(how, vptr + n)) return -TARGET_EFAULT; ret = get_errno(shutdown(sockfd, how)); } break; case SOCKOP_sendmsg: case SOCKOP_recvmsg: { abi_ulong fd; abi_ulong target_msg; abi_ulong flags; if (get_user_ual(fd, vptr) || get_user_ual(target_msg, vptr + n) || get_user_ual(flags, vptr + 2 * n)) return -TARGET_EFAULT; ret = do_sendrecvmsg(fd, target_msg, flags, (num == SOCKOP_sendmsg)); } break; case SOCKOP_setsockopt: { abi_ulong sockfd; abi_ulong level; abi_ulong optname; abi_ulong optval; abi_ulong optlen; if (get_user_ual(sockfd, vptr) || get_user_ual(level, vptr + n) || get_user_ual(optname, vptr + 2 * n) || get_user_ual(optval, vptr + 3 * n) || get_user_ual(optlen, vptr + 4 * n)) return -TARGET_EFAULT; ret = do_setsockopt(sockfd, level, optname, optval, optlen); } break; case SOCKOP_getsockopt: { abi_ulong sockfd; abi_ulong level; abi_ulong optname; abi_ulong optval; socklen_t optlen; if (get_user_ual(sockfd, vptr) || get_user_ual(level, vptr + n) || get_user_ual(optname, vptr + 2 * n) || get_user_ual(optval, vptr + 3 * n) || get_user_ual(optlen, vptr + 4 * n)) return -TARGET_EFAULT; ret = do_getsockopt(sockfd, level, optname, optval, optlen); } break; default: gemu_log("Unsupported socketcall: %d\n", num); ret = -TARGET_ENOSYS; break; } return ret; }


static int nbd_send_rep_list(int csock, NBDExport *exp) { uint64_t magic, name_len; uint32_t opt, type, len; name_len = strlen(exp->name); magic = cpu_to_be64(NBD_REP_MAGIC); if (write_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) { LOG("write failed (magic)"); return -EINVAL; } opt = cpu_to_be32(NBD_OPT_LIST); if (write_sync(csock, &opt, sizeof(opt)) != sizeof(opt)) { LOG("write failed (opt)"); return -EINVAL; } type = cpu_to_be32(NBD_REP_SERVER); if (write_sync(csock, &type, sizeof(type)) != sizeof(type)) { LOG("write failed (reply type)"); return -EINVAL; } len = cpu_to_be32(name_len + sizeof(len)); if (write_sync(csock, &len, sizeof(len)) != sizeof(len)) { LOG("write failed (length)"); return -EINVAL; } len = cpu_to_be32(name_len); if (write_sync(csock, &len, sizeof(len)) != sizeof(len)) { LOG("write failed (length)"); return -EINVAL; } if (write_sync(csock, exp->name, name_len) != name_len) { LOG("write failed (buffer)"); return -EINVAL; } return 0; }


static int nic_init(PCIDevice *pci_dev, uint32_t device) { PCIEEPRO100State *d = DO_UPCAST(PCIEEPRO100State, dev, pci_dev); EEPRO100State *s; logout("\n"); d->dev.unregister = pci_nic_uninit; s = &d->eepro100; s->device = device; s->pci_dev = &d->dev; pci_reset(s); /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */ s->eeprom = eeprom93xx_new(EEPROM_SIZE); /* Handler for memory-mapped I/O */ d->eepro100.mmio_index = cpu_register_io_memory(pci_mmio_read, pci_mmio_write, s); pci_register_bar(&d->dev, 0, PCI_MEM_SIZE, PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_MEM_PREFETCH, pci_mmio_map); pci_register_bar(&d->dev, 1, PCI_IO_SIZE, PCI_ADDRESS_SPACE_IO, pci_map); pci_register_bar(&d->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM, pci_mmio_map); qdev_get_macaddr(&d->dev.qdev, s->macaddr); logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)); assert(s->region[1] == 0); nic_reset(s); s->vc = qdev_get_vlan_client(&d->dev.qdev, nic_can_receive, nic_receive, NULL, nic_cleanup, s); qemu_format_nic_info_str(s->vc, s->macaddr); qemu_register_reset(nic_reset, s); register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s); return 0; }


static uint64_t pchip_read(void *opaque, target_phys_addr_t addr, unsigned size) { TyphoonState *s = opaque; uint64_t ret = 0; if (addr & 4) { return s->latch_tmp; } switch (addr) { case 0x0000: /* WSBA0: Window Space Base Address Register. */ ret = s->pchip.win[0].base_addr; break; case 0x0040: /* WSBA1 */ ret = s->pchip.win[1].base_addr; break; case 0x0080: /* WSBA2 */ ret = s->pchip.win[2].base_addr; break; case 0x00c0: /* WSBA3 */ ret = s->pchip.win[3].base_addr; break; case 0x0100: /* WSM0: Window Space Mask Register. */ ret = s->pchip.win[0].mask; break; case 0x0140: /* WSM1 */ ret = s->pchip.win[1].mask; break; case 0x0180: /* WSM2 */ ret = s->pchip.win[2].mask; break; case 0x01c0: /* WSM3 */ ret = s->pchip.win[3].mask; break; case 0x0200: /* TBA0: Translated Base Address Register. */ ret = (uint64_t)s->pchip.win[0].translated_base_pfn << 10; break; case 0x0240: /* TBA1 */ ret = (uint64_t)s->pchip.win[1].translated_base_pfn << 10; break; case 0x0280: /* TBA2 */ ret = (uint64_t)s->pchip.win[2].translated_base_pfn << 10; break; case 0x02c0: /* TBA3 */ ret = (uint64_t)s->pchip.win[3].translated_base_pfn << 10; break; case 0x0300: /* PCTL: Pchip Control Register. */ ret = s->pchip.ctl; break; case 0x0340: /* PLAT: Pchip Master Latency Register. */ break; case 0x03c0: /* PERROR: Pchip Error Register. */ break; case 0x0400: /* PERRMASK: Pchip Error Mask Register. */ break; case 0x0440: /* PERRSET: Pchip Error Set Register. */ break; case 0x0480: /* TLBIV: Translation Buffer Invalidate Virtual Register (WO). */ break; case 0x04c0: /* TLBIA: Translation Buffer Invalidate All Register (WO). */ break; case 0x0500: /* PMONCTL */ case 0x0540: /* PMONCNT */ case 0x0800: /* SPRST */ break; default: cpu_unassigned_access(cpu_single_env, addr, 0, 0, 0, size); return -1; } s->latch_tmp = ret >> 32; return ret; }


static void curl_close(BlockDriverState *bs) { BDRVCURLState *s = bs->opaque; DPRINTF("CURL: Close\n"); curl_detach_aio_context(bs); qemu_mutex_destroy(&s->mutex); g_free(s->cookie); g_free(s->url); }


int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size) { int len; len = s->buf_end - s->buf_ptr; if (len == 0) { fill_buffer(s); len = s->buf_end - s->buf_ptr; } if (len > size) len = size; memcpy(buf, s->buf_ptr, len); s->buf_ptr += len; return len; }


static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) { int num_gain = 0; int c, g, sfb, ret; int sign; INTFLOAT scale; SingleChannelElement *sce = &che->ch[0]; ChannelCoupling *coup = &che->coup; coup->coupling_point = 2 * get_bits1(gb); coup->num_coupled = get_bits(gb, 3); for (c = 0; c <= coup->num_coupled; c++) { num_gain++; coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE; coup->id_select[c] = get_bits(gb, 4); if (coup->type[c] == TYPE_CPE) { coup->ch_select[c] = get_bits(gb, 2); if (coup->ch_select[c] == 3) num_gain++; } else coup->ch_select[c] = 2; } coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1); sign = get_bits(gb, 1); scale = AAC_RENAME(cce_scale)[get_bits(gb, 2)]; if ((ret = decode_ics(ac, sce, gb, 0, 0))) return ret; for (c = 0; c < num_gain; c++) { int idx = 0; int cge = 1; int gain = 0; INTFLOAT gain_cache = FIXR10(1.); if (c) { cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; gain_cache = GET_GAIN(scale, gain); } if (coup->coupling_point == AFTER_IMDCT) { coup->gain[c][0] = gain_cache; } else { for (g = 0; g < sce->ics.num_window_groups; g++) { for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { if (sce->band_type[idx] != ZERO_BT) { if (!cge) { int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; if (t) { int s = 1; t = gain += t; if (sign) { s -= 2 * (t & 0x1); t >>= 1; } gain_cache = GET_GAIN(scale, t) * s; } } coup->gain[c][idx] = gain_cache; } } } } } return 0; }


static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) { VirtualConsole *vc = opaque; GtkDisplayState *s = vc->s; int gdk_keycode = key->hardware_keycode; int qemu_keycode; int i; if (key->keyval == GDK_KEY_Pause) { qemu_input_event_send_key_qcode(vc->gfx.dcl.con, Q_KEY_CODE_PAUSE, key->type == GDK_KEY_PRESS); qemu_keycode = gd_map_keycode(s, gtk_widget_get_display(widget), gdk_keycode); trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode, (key->type == GDK_KEY_PRESS) ? "down" : "up"); for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) { if (qemu_keycode == modifier_keycode[i]) { s->modifier_pressed[i] = (key->type == GDK_KEY_PRESS); qemu_input_event_send_key_number(vc->gfx.dcl.con, qemu_keycode, key->type == GDK_KEY_PRESS);


void *pl110_init(DisplayState *ds, uint32_t base, qemu_irq irq, int versatile) { pl110_state *s; int iomemtype; s = (pl110_state *)qemu_mallocz(sizeof(pl110_state)); iomemtype = cpu_register_io_memory(0, pl110_readfn, pl110_writefn, s); cpu_register_physical_memory(base, 0x00000fff, iomemtype); s->base = base; s->ds = ds; s->versatile = versatile; s->irq = irq; graphic_console_init(ds, pl110_update_display, pl110_invalidate_display, NULL, s); /* ??? Save/restore. */ return s; }


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


static void replication_start(ReplicationState *rs, ReplicationMode mode, Error **errp) { BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; BlockDriverState *top_bs; int64_t active_length, hidden_length, disk_length; AioContext *aio_context; Error *local_err = NULL; aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); s = bs->opaque; if (s->replication_state != BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); aio_context_release(aio_context); return; } if (s->mode != mode) { error_setg(errp, "The parameter mode's value is invalid, needs %d," " but got %d", s->mode, mode); aio_context_release(aio_context); return; } switch (s->mode) { case REPLICATION_MODE_PRIMARY: break; case REPLICATION_MODE_SECONDARY: s->active_disk = bs->file; if (!s->active_disk || !s->active_disk->bs || !s->active_disk->bs->backing) { error_setg(errp, "Active disk doesn't have backing file"); aio_context_release(aio_context); return; } s->hidden_disk = s->active_disk->bs->backing; if (!s->hidden_disk->bs || !s->hidden_disk->bs->backing) { error_setg(errp, "Hidden disk doesn't have backing file"); aio_context_release(aio_context); return; } s->secondary_disk = s->hidden_disk->bs->backing; if (!s->secondary_disk->bs || !bdrv_has_blk(s->secondary_disk->bs)) { error_setg(errp, "The secondary disk doesn't have block backend"); aio_context_release(aio_context); return; } /* verify the length */ active_length = bdrv_getlength(s->active_disk->bs); hidden_length = bdrv_getlength(s->hidden_disk->bs); disk_length = bdrv_getlength(s->secondary_disk->bs); if (active_length < 0 || hidden_length < 0 || disk_length < 0 || active_length != hidden_length || hidden_length != disk_length) { error_setg(errp, "Active disk, hidden disk, secondary disk's length" " are not the same"); aio_context_release(aio_context); return; } if (!s->active_disk->bs->drv->bdrv_make_empty || !s->hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_empty"); aio_context_release(aio_context); return; } /* reopen the backing file in r/w mode */ reopen_backing_file(bs, true, &local_err); if (local_err) { error_propagate(errp, local_err); aio_context_release(aio_context); return; } /* start backup job now */ error_setg(&s->blocker, "Block device is in use by internal backup job"); top_bs = bdrv_lookup_bs(s->top_id, s->top_id, NULL); if (!top_bs || !bdrv_is_root_node(top_bs) || !check_top_bs(top_bs, bs)) { error_setg(errp, "No top_bs or it is invalid"); reopen_backing_file(bs, false, NULL); aio_context_release(aio_context); return; } bdrv_op_block_all(top_bs, s->blocker); bdrv_op_unblock(top_bs, BLOCK_OP_TYPE_DATAPLANE, s->blocker); backup_start(NULL, s->secondary_disk->bs, s->hidden_disk->bs, 0, MIRROR_SYNC_MODE_NONE, NULL, false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, BLOCK_JOB_INTERNAL, backup_job_completed, bs, NULL, &local_err); if (local_err) { error_propagate(errp, local_err); backup_job_cleanup(bs); aio_context_release(aio_context); return; } break; default: aio_context_release(aio_context); abort(); } s->replication_state = BLOCK_REPLICATION_RUNNING; if (s->mode == REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); } s->error = 0; aio_context_release(aio_context); }


static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { #if COMPILE_TEMPLATE_MMX __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm4 \n\t" "mov %0, %%"REG_a" \n\t" "1: \n\t" "movq (%1, %%"REG_a",4), %%mm0 \n\t" "movq 8(%1, %%"REG_a",4), %%mm1 \n\t" "pand %%mm4, %%mm0 \n\t" "pand %%mm4, %%mm1 \n\t" "packuswb %%mm1, %%mm0 \n\t" "movq %%mm0, %%mm1 \n\t" "psrlw $8, %%mm0 \n\t" "pand %%mm4, %%mm1 \n\t" "packuswb %%mm0, %%mm0 \n\t" "packuswb %%mm1, %%mm1 \n\t" "movd %%mm0, (%3, %%"REG_a") \n\t" "movd %%mm1, (%2, %%"REG_a") \n\t" "add $4, %%"REG_a" \n\t" " js 1b \n\t" : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width) : "%"REG_a ); #else int i; for (i=0; i<width; i++) { dstU[i]= src1[4*i + 0]; dstV[i]= src1[4*i + 2]; } #endif assert(src1 == src2); }


uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) { int memory_map_mode, plane; uint32_t ret; /* convert to VGA memory offset */ memory_map_mode = (s->gr[VGA_GFX_MISC] >> 2) & 3; addr &= 0x1ffff; switch(memory_map_mode) { case 0: break; case 1: if (addr >= 0x10000) return 0xff; addr += s->bank_offset; break; case 2: addr -= 0x10000; if (addr >= 0x8000) return 0xff; break; default: case 3: addr -= 0x18000; if (addr >= 0x8000) return 0xff; break; } if (s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) { /* chain 4 mode : simplest access */ ret = s->vram_ptr[addr]; } else if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane = (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); ret = s->vram_ptr[((addr & ~1) << 1) | plane]; } else { /* standard VGA latched access */ s->latch = ((uint32_t *)s->vram_ptr)[addr]; if (!(s->gr[VGA_GFX_MODE] & 0x08)) { /* read mode 0 */ plane = s->gr[VGA_GFX_PLANE_READ]; ret = GET_PLANE(s->latch, plane); } else { /* read mode 1 */ ret = (s->latch ^ mask16[s->gr[VGA_GFX_COMPARE_VALUE]]) & mask16[s->gr[VGA_GFX_COMPARE_MASK]]; ret |= ret >> 16; ret |= ret >> 8; ret = (~ret) & 0xff; } } return ret; }


static av_cold int libx265_encode_close(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; av_frame_free(&avctx->coded_frame); ctx->api->param_free(ctx->params); if (ctx->encoder) ctx->api->encoder_close(ctx->encoder); return 0; }


static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, const uint8_t *buf, int buf_size, int top_bottom, int non_mod) { DVBSubContext *ctx = avctx->priv_data; DVBSubRegion *region = get_region(ctx, display->region_id); const uint8_t *buf_end = buf + buf_size; uint8_t *pbuf; int x_pos, y_pos; int i; uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf}; uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; uint8_t *map_table; #if 0 av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size, top_bottom ? "bottom" : "top"); for (i = 0; i < buf_size; i++) { if (i % 16 == 0) av_dlog(avctx, "0x%8p: ", buf+i); av_dlog(avctx, "%02x ", buf[i]); if (i % 16 == 15) av_dlog(avctx, "\n"); } if (i % 16) av_dlog(avctx, "\n"); #endif if (region == 0) return; pbuf = region->pbuf; region->dirty = 1; x_pos = display->x_pos; y_pos = display->y_pos; if ((y_pos & 1) != top_bottom) y_pos++; while (buf < buf_end) { if (x_pos > region->width || y_pos > region->height) { av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n"); return; } switch (*buf++) { case 0x10: if (region->depth == 8) map_table = map2to8; else if (region->depth == 4) map_table = map2to4; else map_table = NULL; x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, region->width - x_pos, &buf, buf_end - buf, non_mod, map_table); break; case 0x11: if (region->depth < 4) { av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth); return; } if (region->depth == 8) map_table = map4to8; else map_table = NULL; x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, region->width - x_pos, &buf, buf_end - buf, non_mod, map_table); break; case 0x12: if (region->depth < 8) { av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth); return; } x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos, region->width - x_pos, &buf, buf_end - buf, non_mod, NULL); break; case 0x20: map2to4[0] = (*buf) >> 4; map2to4[1] = (*buf++) & 0xf; map2to4[2] = (*buf) >> 4; map2to4[3] = (*buf++) & 0xf; break; case 0x21: for (i = 0; i < 4; i++) map2to8[i] = *buf++; break; case 0x22: for (i = 0; i < 16; i++) map4to8[i] = *buf++; break; case 0xf0: x_pos = display->x_pos; y_pos += 2; break; default: av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1)); } } }


static void assert_file_overwrite(const char *filename) { if (file_overwrite && file_skip) { fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n"); exit_program(1); } if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (avio_check(filename, 0) == 0) { if (!using_stdin && !file_skip) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); exit_program(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); exit_program(1); } } } }


static void tlb_info(Monitor *mon) { CPUState *env; int l1, l2; uint32_t pgd, pde, pte; env = mon_get_cpu(); if (!(env->cr[0] & CR0_PG_MASK)) { monitor_printf(mon, "PG disabled\n"); return; } pgd = env->cr[3] & ~0xfff; for(l1 = 0; l1 < 1024; l1++) { cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); pde = le32_to_cpu(pde); if (pde & PG_PRESENT_MASK) { if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { print_pte(mon, (l1 << 22), pde, ~((1 << 20) - 1)); } else { for(l2 = 0; l2 < 1024; l2++) { cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, (uint8_t *)&pte, 4); pte = le32_to_cpu(pte); if (pte & PG_PRESENT_MASK) { print_pte(mon, (l1 << 22) + (l2 << 12), pte & ~PG_PSE_MASK, ~0xfff); } } } } } }


static void parse_option_number(const char *name, const char *value, uint64_t *ret, Error **errp) { char *postfix; uint64_t number; number = strtoull(value, &postfix, 0); if (*postfix != '\0') { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); return; } *ret = number; }


static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){ int width, height, vo_ver_id; /* vol header */ skip_bits(gb, 1); /* random access */ s->vo_type= get_bits(gb, 8); if (get_bits1(gb) != 0) { /* is_ol_id */ vo_ver_id = get_bits(gb, 4); /* vo_ver_id */ skip_bits(gb, 3); /* vo_priority */ } else { vo_ver_id = 1; //printf("vo type:%d\n",s->vo_type); s->aspect_ratio_info= get_bits(gb, 4); if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){ s->avctx->sample_aspect_ratio.num= get_bits(gb, 8); // par_width s->avctx->sample_aspect_ratio.den= get_bits(gb, 8); // par_height }else{ s->avctx->sample_aspect_ratio= pixel_aspect[s->aspect_ratio_info]; if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */ int chroma_format= get_bits(gb, 2); if(chroma_format!=1){ av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); s->low_delay= get_bits1(gb); if(get_bits1(gb)){ /* vbv parameters */ get_bits(gb, 15); /* first_half_bitrate */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* latter_half_bitrate */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* first_half_vbv_buffer_size */ skip_bits1(gb); /* marker */ get_bits(gb, 3); /* latter_half_vbv_buffer_size */ get_bits(gb, 11); /* first_half_vbv_occupancy */ skip_bits1(gb); /* marker */ get_bits(gb, 15); /* latter_half_vbv_occupancy */ skip_bits1(gb); /* marker */ }else{ // set low delay flag only once the smartest? low delay detection won't be overriden if(s->picture_number==0) s->low_delay=0; s->shape = get_bits(gb, 2); /* vol shape */ if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); skip_bits(gb, 4); //video_object_layer_shape_extension check_marker(gb, "before time_increment_resolution"); s->avctx->time_base.den = get_bits(gb, 16); if(!s->avctx->time_base.den){ av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n"); s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; if (s->time_increment_bits < 1) s->time_increment_bits = 1; check_marker(gb, "before fixed_vop_rate"); if (get_bits1(gb) != 0) { /* fixed_vop_rate */ s->avctx->time_base.num = get_bits(gb, s->time_increment_bits); }else s->avctx->time_base.num = 1; s->t_frame=0; if (s->shape != BIN_ONLY_SHAPE) { if (s->shape == RECT_SHAPE) { skip_bits1(gb); /* marker */ width = get_bits(gb, 13); skip_bits1(gb); /* marker */ height = get_bits(gb, 13); skip_bits1(gb); /* marker */ if(width && height && !(s->width && s->codec_tag == ff_get_fourcc("MP4S"))){ /* they should be non zero but who knows ... */ s->width = width; s->height = height; // printf("width/height: %d %d\n", width, height); s->progressive_sequence= s->progressive_frame= get_bits1(gb)^1; s->interlaced_dct=0; if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ if (vo_ver_id == 1) { s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ } else { s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ if(s->vol_sprite_usage==STATIC_SPRITE){ s->sprite_width = get_bits(gb, 13); skip_bits1(gb); /* marker */ s->sprite_height= get_bits(gb, 13); skip_bits1(gb); /* marker */ s->sprite_left = get_bits(gb, 13); skip_bits1(gb); /* marker */ s->sprite_top = get_bits(gb, 13); skip_bits1(gb); /* marker */ s->num_sprite_warping_points= get_bits(gb, 6); s->sprite_warping_accuracy = get_bits(gb, 2); s->sprite_brightness_change= get_bits1(gb); if(s->vol_sprite_usage==STATIC_SPRITE) s->low_latency_sprite= get_bits1(gb); // FIXME sadct disable bit if verid!=1 && shape not rect if (get_bits1(gb) == 1) { /* not_8_bit */ s->quant_precision = get_bits(gb, 4); /* quant_precision */ if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); /* bits_per_pixel */ if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision); } else { s->quant_precision = 5; // FIXME a bunch of grayscale shape things if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */ int i, v; /* load default matrixes */ for(i=0; i<64; i++){ int j= s->dsp.idct_permutation[i]; v= ff_mpeg4_default_intra_matrix[i]; s->intra_matrix[j]= v; s->chroma_intra_matrix[j]= v; v= ff_mpeg4_default_non_intra_matrix[i]; s->inter_matrix[j]= v; s->chroma_inter_matrix[j]= v; /* load custom intra matrix */ if(get_bits1(gb)){ int last=0; for(i=0; i<64; i++){ int j; v= get_bits(gb, 8); if(v==0) break; last= v; j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; s->intra_matrix[j]= v; s->chroma_intra_matrix[j]= v; /* replicate last value */ for(; i<64; i++){ int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; s->intra_matrix[j]= last; s->chroma_intra_matrix[j]= last; /* load custom non intra matrix */ if(get_bits1(gb)){ int last=0; for(i=0; i<64; i++){ int j; v= get_bits(gb, 8); if(v==0) break; last= v; j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; s->inter_matrix[j]= v; s->chroma_inter_matrix[j]= v; /* replicate last value */ for(; i<64; i++){ int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; s->inter_matrix[j]= last; s->chroma_inter_matrix[j]= last; // FIXME a bunch of grayscale shape things if(vo_ver_id != 1) s->quarter_sample= get_bits1(gb); else s->quarter_sample=0; if(!get_bits1(gb)) av_log(s->avctx, AV_LOG_ERROR, "Complexity estimation not supported\n"); s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */ s->data_partitioning= get_bits1(gb); if(s->data_partitioning){ s->rvlc= get_bits1(gb); if(vo_ver_id != 1) { s->new_pred= get_bits1(gb); if(s->new_pred){ av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); skip_bits(gb, 2); /* requested upstream message type */ skip_bits1(gb); /* newpred segment type */ s->reduced_res_vop= get_bits1(gb); if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n"); else{ s->new_pred=0; s->reduced_res_vop= 0; s->scalability= get_bits1(gb); if (s->scalability) { GetBitContext bak= *gb; int ref_layer_id; int ref_layer_sampling_dir; int h_sampling_factor_n; int h_sampling_factor_m; int v_sampling_factor_n; int v_sampling_factor_m; s->hierachy_type= get_bits1(gb); ref_layer_id= get_bits(gb, 4); ref_layer_sampling_dir= get_bits1(gb); h_sampling_factor_n= get_bits(gb, 5); h_sampling_factor_m= get_bits(gb, 5); v_sampling_factor_n= get_bits(gb, 5); v_sampling_factor_m= get_bits(gb, 5); s->enhancement_type= get_bits1(gb); if( h_sampling_factor_n==0 || h_sampling_factor_m==0 || v_sampling_factor_n==0 || v_sampling_factor_m==0){ // fprintf(stderr, "illegal scalability header (VERY broken encoder), trying to workaround\n"); s->scalability=0; *gb= bak; }else av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); // bin shape stuff FIXME return 0;


static int scsi_disk_initfn(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); int is_cd; DriveInfo *dinfo; if (!s->qdev.conf.bs) { error_report("scsi-disk: drive property not set"); s->bs = s->qdev.conf.bs; is_cd = bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM; if (bdrv_get_on_error(s->bs, 1) != BLOCK_ERR_REPORT) { error_report("Device doesn't support drive option rerror"); if (!s->serial) { /* try to fall back to value set with legacy -drive serial=... */ dinfo = drive_get_by_blockdev(s->bs); s->serial = qemu_strdup(*dinfo->serial ? dinfo->serial : "0"); if (!s->version) { s->version = qemu_strdup(QEMU_VERSION); if (bdrv_is_sg(s->bs)) { error_report("scsi-disk: unwanted /dev/sg*"); if (is_cd) { s->qdev.blocksize = 2048; } else { s->qdev.blocksize = s->qdev.conf.logical_block_size; s->cluster_size = s->qdev.blocksize / 512; s->qdev.type = TYPE_DISK; qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); bdrv_set_removable(s->bs, is_cd); return 0;


static av_cold int dvdsub_init(AVCodecContext *avctx) { DVDSubContext *ctx = avctx->priv_data; char *data, *cur; if (!avctx->extradata || !avctx->extradata_size) return 0; data = av_malloc(avctx->extradata_size + 1); if (!data) return AVERROR(ENOMEM); memcpy(data, avctx->extradata, avctx->extradata_size); data[avctx->extradata_size] = '\0'; cur = data; while (*cur) { if (strncmp("palette:", cur, 8) == 0) { int i; char *p = cur + 8; ctx->has_palette = 1; for (i = 0; i < 16; i++) { ctx->palette[i] = strtoul(p, &p, 16); while (*p == ',' || av_isspace(*p)) p++; } } else if (!strncmp("size:", cur, 5)) { int w, h; if (sscanf(cur + 5, "%dx%d", &w, &h) == 2) { int ret = ff_set_dimensions(avctx, w, h); if (ret < 0) return ret; } } cur += strcspn(cur, "\n\r"); cur += strspn(cur, "\n\r"); } av_free(data); return 0; }


static void mxf_write_random_index_pack(AVFormatContext *s) { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; uint64_t pos = avio_tell(pb); int i; avio_write(pb, random_index_pack_key, 16); klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count); if (mxf->edit_unit_byte_count) avio_wb32(pb, 1); // BodySID of header partition else avio_wb32(pb, 0); avio_wb64(pb, 0); // offset of header partition for (i = 0; i < mxf->body_partitions_count; i++) { avio_wb32(pb, 1); // BodySID avio_wb64(pb, mxf->body_partition_offset[i]); } avio_wb32(pb, 0); // BodySID of footer partition avio_wb64(pb, mxf->footer_partition_offset); avio_wb32(pb, avio_tell(pb) - pos + 4); }


static int qcow2_mark_clean(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { int ret = bdrv_flush(bs); if (ret < 0) { return ret; } s->incompatible_features &= ~QCOW2_INCOMPAT_DIRTY; return qcow2_update_header(bs); } return 0; }


static int config_props(AVFilterLink *link) { YADIFContext *yadif = link->src->priv; link->time_base.num = link->src->inputs[0]->time_base.num; link->time_base.den = link->src->inputs[0]->time_base.den * 2; link->w = link->src->inputs[0]->w; link->h = link->src->inputs[0]->h; if(yadif->mode&1) link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1}); return 0; }


void qemu_system_powerdown(void) { if(pm_state->pmen & PWRBTN_EN) { pm_state->pmsts |= PWRBTN_EN; pm_update_sci(pm_state); } }


static int alloc_table(VLC *vlc, int size) { int index; index = vlc->table_size; vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { vlc->table_allocated += (1 << vlc->bits); vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } return index; }


int net_slirp_smb(const char *exported_dir) { struct in_addr vserver_addr = { .s_addr = 0 }; if (legacy_smb_export) { fprintf(stderr, "-smb given twice\n"); return -1; } legacy_smb_export = exported_dir; if (!QTAILQ_EMPTY(&slirp_stacks)) { return slirp_smb(QTAILQ_FIRST(&slirp_stacks), exported_dir, vserver_addr); } return 0; }


static void set_int32(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; int32_t *ptr = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; int64_t value; if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } visit_type_int(v, &value, name, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (value > prop->info->min && value <= prop->info->max) { *ptr = value; } else { error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, dev->id?:"", name, value, prop->info->min, prop->info->max); } }


static av_cold int smvjpeg_decode_init(AVCodecContext *avctx) { SMVJpegDecodeContext *s = avctx->priv_data; AVCodec *codec; AVDictionary *thread_opt = NULL; int ret = 0; s->frames_per_jpeg = 0; s->picture[0] = av_frame_alloc(); if (!s->picture[0]) return AVERROR(ENOMEM); s->picture[1] = av_frame_alloc(); if (!s->picture[1]) return AVERROR(ENOMEM); s->jpg.picture_ptr = s->picture[0]; if (avctx->extradata_size >= 4) s->frames_per_jpeg = AV_RL32(avctx->extradata); if (s->frames_per_jpeg <= 0) { av_log(avctx, AV_LOG_ERROR, "Invalid number of frames per jpeg.\n"); ret = -1; } codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG); if (!codec) { av_log(avctx, AV_LOG_ERROR, "MJPEG codec not found\n"); ret = -1; } s->avctx = avcodec_alloc_context3(codec); av_dict_set(&thread_opt, "threads", "1", 0); s->avctx->refcounted_frames = 1; s->avctx->flags = avctx->flags; s->avctx->idct_algo = avctx->idct_algo; if (ff_codec_open2_recursive(s->avctx, codec, &thread_opt) < 0) { av_log(avctx, AV_LOG_ERROR, "MJPEG codec failed to open\n"); ret = -1; } av_dict_free(&thread_opt); return ret; }


static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters) { static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }; char sws_flags_str[128]; char buffersrc_args[256]; int ret; AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc(); AVFilterContext *filt_src = NULL, *filt_out = NULL, *filt_format, *filt_crop; AVCodecContext *codec = is->video_st->codec; snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags); graph->scale_sws_opts = av_strdup(sws_flags_str); snprintf(buffersrc_args, sizeof(buffersrc_args), "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", codec->width, codec->height, codec->pix_fmt, is->video_st->time_base.num, is->video_st->time_base.den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den); if ((ret = avfilter_graph_create_filter(&filt_src, avfilter_get_by_name("buffer"), "ffplay_buffer", buffersrc_args, NULL, graph)) < 0) return ret; buffersink_params->pixel_fmts = pix_fmts; ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("ffbuffersink"), "ffplay_buffersink", NULL, buffersink_params, graph); av_freep(&buffersink_params); if (ret < 0) return ret; /* SDL YUV code is not handling odd width/height for some driver * combinations, therefore we crop the picture to an even width/height. */ if ((ret = avfilter_graph_create_filter(&filt_crop, avfilter_get_by_name("crop"), "ffplay_crop", "floor(in_w/2)*2:floor(in_h/2)*2", NULL, graph)) < 0) return ret; if ((ret = avfilter_graph_create_filter(&filt_format, avfilter_get_by_name("format"), "format", "yuv420p", NULL, graph)) < 0) return ret; if ((ret = avfilter_link(filt_crop, 0, filt_format, 0)) < 0) return ret; if ((ret = avfilter_link(filt_format, 0, filt_out, 0)) < 0) return ret; if ((ret = configure_filtergraph(graph, vfilters, filt_src, filt_crop)) < 0) return ret; is->in_video_filter = filt_src; is->out_video_filter = filt_out; return ret; }


static void pxa2xx_pcmcia_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); dc->realize = pxa2xx_pcmcia_realize; }


static void cuvid_flush(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data; AVCUDADeviceContext *device_hwctx = device_ctx->hwctx; CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx; CUVIDSOURCEDATAPACKET seq_pkt = { 0 }; int ret; ctx->ever_flushed = 1; ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx)); if (ret < 0) goto error; av_fifo_freep(&ctx->frame_queue); ctx->frame_queue = av_fifo_alloc(MAX_FRAME_COUNT * sizeof(CuvidParsedFrame)); if (!ctx->frame_queue) { av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on flush\n"); return; } if (ctx->cudecoder) { cuvidDestroyDecoder(ctx->cudecoder); ctx->cudecoder = NULL; } if (ctx->cuparser) { cuvidDestroyVideoParser(ctx->cuparser); ctx->cuparser = NULL; } ret = CHECK_CU(cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo)); if (ret < 0) goto error; seq_pkt.payload = ctx->cuparse_ext.raw_seqhdr_data; seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length; if (seq_pkt.payload && seq_pkt.payload_size) { ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &seq_pkt)); if (ret < 0) goto error; } ret = CHECK_CU(cuCtxPopCurrent(&dummy)); if (ret < 0) goto error; ctx->prev_pts = INT64_MIN; ctx->decoder_flushing = 0; return; error: av_log(avctx, AV_LOG_ERROR, "CUDA reinit on flush failed\n"); }


void ff_avg_h264_qpel8_mc00_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avg_width8_msa(src, stride, dst, stride, 8); }


static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { TiffEncoderContext *s = avctx->priv_data; const AVFrame *const p = pict; int i; uint8_t *ptr; uint8_t *offset; uint32_t strips; uint32_t *strip_sizes = NULL; uint32_t *strip_offsets = NULL; int bytes_per_row; uint32_t res[2] = { 72, 1 }; // image resolution (72/1) uint16_t bpp_tab[] = { 8, 8, 8, 8 }; int ret; int is_yuv = 0; uint8_t *yuv_line = NULL; int shift_h, shift_v; int packet_size; const AVPixFmtDescriptor *pfd; s->avctx = avctx; s->width = avctx->width; s->height = avctx->height; s->subsampling[0] = 1; s->subsampling[1] = 1; switch (avctx->pix_fmt) { case AV_PIX_FMT_RGB48LE: case AV_PIX_FMT_GRAY16LE: case AV_PIX_FMT_RGBA: case AV_PIX_FMT_RGB24: case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_PAL8: pfd = av_pix_fmt_desc_get(avctx->pix_fmt); s->bpp = av_get_bits_per_pixel(pfd); if (pfd->flags & AV_PIX_FMT_FLAG_PAL) s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE; else if (pfd->flags & AV_PIX_FMT_FLAG_RGB) s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB; else s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO; s->bpp_tab_size = pfd->nb_components; for (i = 0; i < s->bpp_tab_size; i++) bpp_tab[i] = s->bpp / s->bpp_tab_size; break; case AV_PIX_FMT_MONOBLACK: s->bpp = 1; s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO; s->bpp_tab_size = 0; break; case AV_PIX_FMT_MONOWHITE: s->bpp = 1; s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO; s->bpp_tab_size = 0; break; case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV444P: case AV_PIX_FMT_YUV410P: case AV_PIX_FMT_YUV411P: av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v); s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR; s->bpp = 8 + (16 >> (shift_h + shift_v)); s->subsampling[0] = 1 << shift_h; s->subsampling[1] = 1 << shift_v; s->bpp_tab_size = 3; is_yuv = 1; break; default: av_log(s->avctx, AV_LOG_ERROR, "This colors format is not supported\n"); return -1; } if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) // best choice for DEFLATE s->rps = s->height; else // suggest size of strip s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); // round rps up s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; strips = (s->height - 1) / s->rps + 1; packet_size = avctx->height * ((avctx->width * s->bpp + 7) >> 3) * 2 + avctx->height * 4 + FF_MIN_BUFFER_SIZE; if (!pkt->data && (ret = av_new_packet(pkt, packet_size)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); return ret; } ptr = pkt->data; s->buf_start = pkt->data; s->buf = &ptr; s->buf_size = pkt->size; if (check_size(s, 8)) goto fail; // write header bytestream_put_le16(&ptr, 0x4949); bytestream_put_le16(&ptr, 42); offset = ptr; bytestream_put_le32(&ptr, 0); strip_sizes = av_mallocz_array(strips, sizeof(*strip_sizes)); strip_offsets = av_mallocz_array(strips, sizeof(*strip_offsets)); if (!strip_sizes || !strip_offsets) { ret = AVERROR(ENOMEM); goto fail; } bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp * s->subsampling[0] * s->subsampling[1] + 7) >> 3; if (is_yuv) { yuv_line = av_malloc(bytes_per_row); if (!yuv_line) { av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n"); ret = AVERROR(ENOMEM); goto fail; } } #if CONFIG_ZLIB if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) { uint8_t *zbuf; int zlen, zn; int j; zlen = bytes_per_row * s->rps; zbuf = av_malloc(zlen); if (!zbuf) { ret = AVERROR(ENOMEM); goto fail; } strip_offsets[0] = ptr - pkt->data; zn = 0; for (j = 0; j < s->rps; j++) { if (is_yuv) { pack_yuv(s, p, yuv_line, j); memcpy(zbuf + zn, yuv_line, bytes_per_row); j += s->subsampling[1] - 1; } else memcpy(zbuf + j * bytes_per_row, p->data[0] + j * p->linesize[0], bytes_per_row); zn += bytes_per_row; } ret = encode_strip(s, zbuf, ptr, zn, s->compr); av_free(zbuf); if (ret < 0) { av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); goto fail; } ptr += ret; strip_sizes[0] = ptr - pkt->data - strip_offsets[0]; } else #endif if (s->compr == TIFF_LZW) { s->lzws = av_malloc(ff_lzw_encode_state_size); if (!s->lzws) { ret = AVERROR(ENOMEM); goto fail; } } for (i = 0; i < s->height; i++) { if (strip_sizes[i / s->rps] == 0) { if (s->compr == TIFF_LZW) { ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), 12, FF_LZW_TIFF, put_bits); } strip_offsets[i / s->rps] = ptr - pkt->data; } if (is_yuv) { pack_yuv(s, p, yuv_line, i); ret = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); i += s->subsampling[1] - 1; } else ret = encode_strip(s, p->data[0] + i * p->linesize[0], ptr, bytes_per_row, s->compr); if (ret < 0) { av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); goto fail; } strip_sizes[i / s->rps] += ret; ptr += ret; if (s->compr == TIFF_LZW && (i == s->height - 1 || i % s->rps == s->rps - 1)) { ret = ff_lzw_encode_flush(s->lzws, flush_put_bits); strip_sizes[(i / s->rps)] += ret; ptr += ret; } } if (s->compr == TIFF_LZW) av_free(s->lzws); s->num_entries = 0; add_entry1(s, TIFF_SUBFILE, TIFF_LONG, 0); add_entry1(s, TIFF_WIDTH, TIFF_LONG, s->width); add_entry1(s, TIFF_HEIGHT, TIFF_LONG, s->height); if (s->bpp_tab_size) add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab); add_entry1(s, TIFF_COMPR, TIFF_SHORT, s->compr); add_entry1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation); add_entry(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, strip_offsets); if (s->bpp_tab_size) add_entry1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size); add_entry1(s, TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps); add_entry(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, strip_sizes); add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res); add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res); add_entry1(s, TIFF_RES_UNIT, TIFF_SHORT, 2); if (!(avctx->flags & CODEC_FLAG_BITEXACT)) add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING, strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT); if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { uint16_t pal[256 * 3]; for (i = 0; i < 256; i++) { uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4); pal[i] = ((rgb >> 16) & 0xff) * 257; pal[i + 256] = ((rgb >> 8) & 0xff) * 257; pal[i + 512] = (rgb & 0xff) * 257; } add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal); } if (is_yuv) { /** according to CCIR Recommendation 601.1 */ uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 }; add_entry(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling); add_entry(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw); } // write offset to dir bytestream_put_le32(&offset, ptr - pkt->data); if (check_size(s, 6 + s->num_entries * 12)) { ret = AVERROR(EINVAL); goto fail; } bytestream_put_le16(&ptr, s->num_entries); // write tag count bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12); bytestream_put_le32(&ptr, 0); pkt->size = ptr - pkt->data; pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; fail: av_free(strip_sizes); av_free(strip_offsets); av_free(yuv_line); return ret; }


static int parse_key(DBEContext *s) { int key = 0; if (s->key_present && s->input_size > 0) key = AV_RB24(s->input) >> 24 - s->word_bits; skip_input(s, s->key_present); return key; }


static int vaapi_encode_issue(AVCodecContext *avctx, VAAPIEncodePicture *pic) { VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeSlice *slice; VAStatus vas; int err, i; char data[MAX_PARAM_BUFFER_SIZE]; size_t bit_len; av_log(avctx, AV_LOG_DEBUG, "Issuing encode for pic %"PRId64"/%"PRId64" " "as type %s.\n", pic->display_order, pic->encode_order, picture_type_name[pic->type]); if (pic->nb_refs == 0) { av_log(avctx, AV_LOG_DEBUG, "No reference pictures.\n"); } else { av_log(avctx, AV_LOG_DEBUG, "Refers to:"); for (i = 0; i < pic->nb_refs; i++) { av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64, pic->refs[i]->display_order, pic->refs[i]->encode_order); } av_log(avctx, AV_LOG_DEBUG, ".\n"); } av_assert0(pic->input_available && !pic->encode_issued); for (i = 0; i < pic->nb_refs; i++) { av_assert0(pic->refs[i]); // If we are serialised then the references must have already // completed. If not, they must have been issued but need not // have completed yet. if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING) av_assert0(pic->refs[i]->encode_complete); else av_assert0(pic->refs[i]->encode_issued); } av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface); pic->recon_image = av_frame_alloc(); if (!pic->recon_image) { err = AVERROR(ENOMEM); goto fail; } err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0); if (err < 0) { err = AVERROR(ENOMEM); goto fail; } pic->recon_surface = (VASurfaceID)(uintptr_t)pic->recon_image->data[3]; av_log(avctx, AV_LOG_DEBUG, "Recon surface is %#x.\n", pic->recon_surface); pic->output_buffer_ref = av_buffer_pool_get(ctx->output_buffer_pool); if (!pic->output_buffer_ref) { err = AVERROR(ENOMEM); goto fail; } pic->output_buffer = (VABufferID)(uintptr_t)pic->output_buffer_ref->data; av_log(avctx, AV_LOG_DEBUG, "Output buffer is %#x.\n", pic->output_buffer); if (ctx->codec->picture_params_size > 0) { pic->codec_picture_params = av_malloc(ctx->codec->picture_params_size); if (!pic->codec_picture_params) goto fail; memcpy(pic->codec_picture_params, ctx->codec_picture_params, ctx->codec->picture_params_size); } else { av_assert0(!ctx->codec_picture_params); } pic->nb_param_buffers = 0; if (pic->encode_order == 0) { // Global parameter buffers are set on the first picture only. for (i = 0; i < ctx->nb_global_params; i++) { err = vaapi_encode_make_param_buffer(avctx, pic, VAEncMiscParameterBufferType, (char*)ctx->global_params[i], ctx->global_params_size[i]); if (err < 0) goto fail; } } if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) { err = vaapi_encode_make_param_buffer(avctx, pic, VAEncSequenceParameterBufferType, ctx->codec_sequence_params, ctx->codec->sequence_params_size); if (err < 0) goto fail; } if (ctx->codec->init_picture_params) { err = ctx->codec->init_picture_params(avctx, pic); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to initialise picture " "parameters: %d.\n", err); goto fail; } err = vaapi_encode_make_param_buffer(avctx, pic, VAEncPictureParameterBufferType, pic->codec_picture_params, ctx->codec->picture_params_size); if (err < 0) goto fail; } if (pic->type == PICTURE_TYPE_IDR) { if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE && ctx->codec->write_sequence_header) { bit_len = 8 * sizeof(data); err = ctx->codec->write_sequence_header(avctx, data, &bit_len); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to write per-sequence " "header: %d.\n", err); goto fail; } err = vaapi_encode_make_packed_header(avctx, pic, ctx->codec->sequence_header_type, data, bit_len); if (err < 0) goto fail; } } if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_PICTURE && ctx->codec->write_picture_header) { bit_len = 8 * sizeof(data); err = ctx->codec->write_picture_header(avctx, pic, data, &bit_len); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to write per-picture " "header: %d.\n", err); goto fail; } err = vaapi_encode_make_packed_header(avctx, pic, ctx->codec->picture_header_type, data, bit_len); if (err < 0) goto fail; } if (ctx->codec->write_extra_buffer) { for (i = 0;; i++) { size_t len = sizeof(data); int type; err = ctx->codec->write_extra_buffer(avctx, pic, i, &type, data, &len); if (err == AVERROR_EOF) break; if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to write extra " "buffer %d: %d.\n", i, err); goto fail; } err = vaapi_encode_make_param_buffer(avctx, pic, type, data, len); if (err < 0) goto fail; } } if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_MISC && ctx->codec->write_extra_header) { for (i = 0;; i++) { int type; bit_len = 8 * sizeof(data); err = ctx->codec->write_extra_header(avctx, pic, i, &type, data, &bit_len); if (err == AVERROR_EOF) break; if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to write extra " "header %d: %d.\n", i, err); goto fail; } err = vaapi_encode_make_packed_header(avctx, pic, type, data, bit_len); if (err < 0) goto fail; } } av_assert0(pic->nb_slices <= MAX_PICTURE_SLICES); for (i = 0; i < pic->nb_slices; i++) { slice = av_mallocz(sizeof(*slice)); if (!slice) { err = AVERROR(ENOMEM); goto fail; } slice->index = i; pic->slices[i] = slice; if (ctx->codec->slice_params_size > 0) { slice->codec_slice_params = av_mallocz(ctx->codec->slice_params_size); if (!slice->codec_slice_params) { err = AVERROR(ENOMEM); goto fail; } } if (ctx->codec->init_slice_params) { err = ctx->codec->init_slice_params(avctx, pic, slice); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to initalise slice " "parameters: %d.\n", err); goto fail; } } if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SLICE && ctx->codec->write_slice_header) { bit_len = 8 * sizeof(data); err = ctx->codec->write_slice_header(avctx, pic, slice, data, &bit_len); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to write per-slice " "header: %d.\n", err); goto fail; } err = vaapi_encode_make_packed_header(avctx, pic, ctx->codec->slice_header_type, data, bit_len); if (err < 0) goto fail; } if (ctx->codec->init_slice_params) { err = vaapi_encode_make_param_buffer(avctx, pic, VAEncSliceParameterBufferType, slice->codec_slice_params, ctx->codec->slice_params_size); if (err < 0) goto fail; } } vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context, pic->input_surface); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to begin picture encode issue: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail_with_picture; } vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, pic->param_buffers, pic->nb_param_buffers); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to upload encode parameters: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail_with_picture; } vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to end picture encode issue: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); // vaRenderPicture() has been called here, so we should not destroy // the parameter buffers unless separate destruction is required. if (ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) goto fail; else goto fail_at_end; } if (ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { for (i = 0; i < pic->nb_param_buffers; i++) { vas = vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to destroy " "param buffer %#x: %d (%s).\n", pic->param_buffers[i], vas, vaErrorStr(vas)); // And ignore. } } } pic->encode_issued = 1; if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING) return vaapi_encode_wait(avctx, pic); else return 0; fail_with_picture: vaEndPicture(ctx->hwctx->display, ctx->va_context); fail: for(i = 0; i < pic->nb_param_buffers; i++) vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]); fail_at_end: av_freep(&pic->codec_picture_params); av_frame_free(&pic->recon_image); return err; }


static void pc_q35_machine_options(MachineClass *m) { m->family = "pc_q35"; m->desc = "Standard PC (Q35 + ICH9, 2009)"; m->hot_add_cpu = pc_hot_add_cpu; m->units_per_default_bus = 1; m->default_machine_opts = "firmware=bios-256k.bin"; m->default_display = "std"; m->no_floppy = 1; }


static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) { struct sockaddr_in sin = { .sin_family = AF_INET, .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) }, }; struct sockaddr_in6 sin6 = { .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_LOOPBACK_INIT, }; if (check_bind((struct sockaddr *)&sin, sizeof(sin), has_ipv4) < 0) { return -1; } if (check_bind((struct sockaddr *)&sin6, sizeof(sin6), has_ipv6) < 0) { return -1; } return 0; }


static inline void RENAME(rgb24to32)(const uint8_t *src,uint8_t *dst,unsigned src_size) { uint8_t *dest = dst; const uint8_t *s = src; const uint8_t *end; #ifdef HAVE_MMX const uint8_t *mm_end; #endif end = s + src_size; #ifdef HAVE_MMX __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); mm_end = end - 23; __asm __volatile("movq %0, %%mm7"::"m"(mask32):"memory"); while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movd %1, %%mm0\n\t" "punpckldq 3%1, %%mm0\n\t" "movd 6%1, %%mm1\n\t" "punpckldq 9%1, %%mm1\n\t" "movd 12%1, %%mm2\n\t" "punpckldq 15%1, %%mm2\n\t" "movd 18%1, %%mm3\n\t" "punpckldq 21%1, %%mm3\n\t" "pand %%mm7, %%mm0\n\t" "pand %%mm7, %%mm1\n\t" "pand %%mm7, %%mm2\n\t" "pand %%mm7, %%mm3\n\t" MOVNTQ" %%mm0, %0\n\t" MOVNTQ" %%mm1, 8%0\n\t" MOVNTQ" %%mm2, 16%0\n\t" MOVNTQ" %%mm3, 24%0" :"=m"(*dest) :"m"(*s) :"memory"); dest += 32; s += 24; } __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { #ifdef WORDS_BIGENDIAN *dest++ = 0; *dest++ = *s++; *dest++ = *s++; *dest++ = *s++; #else *dest++ = *s++; *dest++ = *s++; *dest++ = *s++; *dest++ = 0; #endif } }


static int encode_picture(MpegEncContext *s, int picture_number) { int i, ret; int bits; int context_count = s->slice_context_count; s->picture_number = picture_number; /* Reset the average MB variance */ s->me.mb_var_sum_temp = s->me.mc_mb_var_sum_temp = 0; /* we need to initialize some time vars before we can encode b-frames */ // RAL: Condition added for MPEG1VIDEO if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->msmpeg4_version)) set_frame_distances(s); if(CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4) ff_set_mpeg4_time(s); s->me.scene_change_score=0; // s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME rate distortion if(s->pict_type==AV_PICTURE_TYPE_I){ if(s->msmpeg4_version >= 3) s->no_rounding=1; else s->no_rounding=0; }else if(s->pict_type!=AV_PICTURE_TYPE_B){ if(s->flipflop_rounding || s->codec_id == AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_MPEG4) s->no_rounding ^= 1; } if(s->flags & CODEC_FLAG_PASS2){ if (estimate_qp(s,1) < 0) return -1; ff_get_2pass_fcode(s); }else if(!(s->flags & CODEC_FLAG_QSCALE)){ if(s->pict_type==AV_PICTURE_TYPE_B) s->lambda= s->last_lambda_for[s->pict_type]; else s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; update_qscale(s); } if(s->codec_id != AV_CODEC_ID_AMV && s->codec_id != AV_CODEC_ID_MJPEG){ if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); s->q_chroma_intra_matrix = s->q_intra_matrix; s->q_chroma_intra_matrix16 = s->q_intra_matrix16; } s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; i<context_count; i++){ ret = ff_update_duplicate_context(s->thread_context[i], s); if (ret < 0) return ret; } if(ff_init_me(s)<0) return -1; /* Estimate motion for every MB */ if(s->pict_type != AV_PICTURE_TYPE_I){ s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8; s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; if (s->pict_type != AV_PICTURE_TYPE_B) { if((s->avctx->pre_me && s->last_non_b_pict_type==AV_PICTURE_TYPE_I) || s->avctx->pre_me==2){ s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } } s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); }else /* if(s->pict_type == AV_PICTURE_TYPE_I) */{ /* I-Frame */ for(i=0; i<s->mb_stride*s->mb_height; i++) s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; if(!s->fixed_qscale){ /* finding spatial complexity for I-frame rate control */ s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } } for(i=1; i<context_count; i++){ merge_context_after_me(s, s->thread_context[i]); } s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; emms_c(); if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == AV_PICTURE_TYPE_P){ s->pict_type= AV_PICTURE_TYPE_I; for(i=0; i<s->mb_stride*s->mb_height; i++) s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; if(s->msmpeg4_version >= 3) s->no_rounding=1; av_dlog(s, "Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); } if(!s->umvplus){ if(s->pict_type==AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) { s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); if(s->flags & CODEC_FLAG_INTERLACED_ME){ int a,b; a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); s->f_code= FFMAX3(s->f_code, a, b); } ff_fix_long_p_mvs(s); ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); if(s->flags & CODEC_FLAG_INTERLACED_ME){ int j; for(i=0; i<2; i++){ for(j=0; j<2; j++) ff_fix_long_mvs(s, s->p_field_select_table[i], j, s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); } } } if(s->pict_type==AV_PICTURE_TYPE_B){ int a, b; a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); s->f_code = FFMAX(a, b); a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); s->b_code = FFMAX(a, b); ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); if(s->flags & CODEC_FLAG_INTERLACED_ME){ int dir, j; for(dir=0; dir<2; dir++){ for(i=0; i<2; i++){ for(j=0; j<2; j++){ int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I) : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I); ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); } } } } } } if (estimate_qp(s, 0) < 0) return -1; if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==AV_PICTURE_TYPE_I && !(s->flags & CODEC_FLAG_QSCALE)) s->qscale= 3; //reduce clipping problems if (s->out_format == FMT_MJPEG) { const uint16_t * luma_matrix = ff_mpeg1_default_intra_matrix; const uint16_t *chroma_matrix = ff_mpeg1_default_intra_matrix; if (s->avctx->intra_matrix) { chroma_matrix = luma_matrix = s->avctx->intra_matrix; } if (s->avctx->chroma_intra_matrix) chroma_matrix = s->avctx->chroma_intra_matrix; /* for mjpeg, we do include qscale in the matrix */ for(i=1;i<64;i++){ int j= s->dsp.idct_permutation[i]; s->chroma_intra_matrix[j] = av_clip_uint8((chroma_matrix[i] * s->qscale) >> 3); s-> intra_matrix[j] = av_clip_uint8(( luma_matrix[i] * s->qscale) >> 3); } s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision]; s->chroma_intra_matrix[0] = s->intra_matrix[0] = ff_mpeg2_dc_scale_table[s->intra_dc_precision][8]; ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->intra_quant_bias, 8, 8, 1); ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16, s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1); s->qscale= 8; } if(s->codec_id == AV_CODEC_ID_AMV){ static const uint8_t y[32]={13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13}; static const uint8_t c[32]={14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14}; for(i=1;i<64;i++){ int j= s->dsp.idct_permutation[ff_zigzag_direct[i]]; s->intra_matrix[j] = sp5x_quant_table[5*2+0][i]; s->chroma_intra_matrix[j] = sp5x_quant_table[5*2+1][i]; } s->y_dc_scale_table= y; s->c_dc_scale_table= c; s->intra_matrix[0] = 13; s->chroma_intra_matrix[0] = 14; ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->intra_quant_bias, 8, 8, 1); ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16, s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1); s->qscale= 8; } //FIXME var duplication s->current_picture_ptr->f.key_frame = s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr s->current_picture_ptr->f.pict_type = s->current_picture.f.pict_type = s->pict_type; if (s->current_picture.f.key_frame) s->picture_in_gop_number=0; s->mb_x = s->mb_y = 0; s->last_bits= put_bits_count(&s->pb); switch(s->out_format) { case FMT_MJPEG: if (CONFIG_MJPEG_ENCODER) ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, s->intra_matrix, s->chroma_intra_matrix); break; case FMT_H261: if (CONFIG_H261_ENCODER) ff_h261_encode_picture_header(s, picture_number); break; case FMT_H263: if (CONFIG_WMV2_ENCODER && s->codec_id == AV_CODEC_ID_WMV2) ff_wmv2_encode_picture_header(s, picture_number); else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) ff_msmpeg4_encode_picture_header(s, picture_number); else if (CONFIG_MPEG4_ENCODER && s->h263_pred) ff_mpeg4_encode_picture_header(s, picture_number); else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) ff_rv10_encode_picture_header(s, picture_number); else if (CONFIG_RV20_ENCODER && s->codec_id == AV_CODEC_ID_RV20) ff_rv20_encode_picture_header(s, picture_number); else if (CONFIG_FLV_ENCODER && s->codec_id == AV_CODEC_ID_FLV1) ff_flv_encode_picture_header(s, picture_number); else if (CONFIG_H263_ENCODER) ff_h263_encode_picture_header(s, picture_number); break; case FMT_MPEG1: if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) ff_mpeg1_encode_picture_header(s, picture_number); break; default: av_assert0(0); } bits= put_bits_count(&s->pb); s->header_bits= bits - s->last_bits; for(i=1; i<context_count; i++){ update_duplicate_context_after_me(s->thread_context[i], s); } s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); for(i=1; i<context_count; i++){ merge_context_after_encode(s, s->thread_context[i]); } emms_c(); return 0; }


static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask) { return (x & mask) == (y & mask); }


static int asf_build_simple_index(AVFormatContext *s, int stream_index) { ff_asf_guid g; ASFContext *asf = s->priv_data; int64_t current_pos = avio_tell(s->pb); int64_t ret; if((ret = avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET)) < 0) { return ret; if ((ret = ff_get_guid(s->pb, &g)) < 0) /* the data object can be followed by other top-level objects, * skip them until the simple index object is reached */ while (ff_guidcmp(&g, &ff_asf_simple_index_header)) { int64_t gsize = avio_rl64(s->pb); if (gsize < 24 || avio_feof(s->pb)) { avio_skip(s->pb, gsize - 24); if ((ret = ff_get_guid(s->pb, &g)) < 0) { int64_t itime, last_pos = -1; int pct, ict; int i; int64_t av_unused gsize = avio_rl64(s->pb); if ((ret = ff_get_guid(s->pb, &g)) < 0) itime = avio_rl64(s->pb); pct = avio_rl32(s->pb); ict = avio_rl32(s->pb); av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict); for (i = 0; i < ict; i++) { int pktnum = avio_rl32(s->pb); int pktct = avio_rl16(s->pb); int64_t pos = s->internal->data_offset + s->packet_size * (int64_t)pktnum; int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0); if (pos != last_pos) { av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n", pktnum, pktct, index_pts); av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME); last_pos = pos; asf->index_read = ict > 1; end: // if (avio_feof(s->pb)) { // ret = 0; // } avio_seek(s->pb, current_pos, SEEK_SET); return ret;


static void ppc_cpu_initfn(Object *obj) { CPUState *cs = CPU(obj); PowerPCCPU *cpu = POWERPC_CPU(obj); PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); CPUPPCState *env = &cpu->env; cs->env_ptr = env; cpu_exec_init(env, &error_abort); cpu->cpu_dt_id = cs->cpu_index; env->msr_mask = pcc->msr_mask; env->mmu_model = pcc->mmu_model; env->excp_model = pcc->excp_model; env->bus_model = pcc->bus_model; env->insns_flags = pcc->insns_flags; env->insns_flags2 = pcc->insns_flags2; env->flags = pcc->flags; env->bfd_mach = pcc->bfd_mach; env->check_pow = pcc->check_pow; #if defined(TARGET_PPC64) if (pcc->sps) { env->sps = *pcc->sps; } else if (env->mmu_model & POWERPC_MMU_64) { /* Use default sets of page sizes */ static const struct ppc_segment_page_sizes defsps = { .sps = { { .page_shift = 12, /* 4K */ .slb_enc = 0, .enc = { { .page_shift = 12, .pte_enc = 0 } } }, { .page_shift = 24, /* 16M */ .slb_enc = 0x100, .enc = { { .page_shift = 24, .pte_enc = 0 } } }, }, }; env->sps = defsps; } #endif /* defined(TARGET_PPC64) */ if (tcg_enabled()) { ppc_translate_init(); } }


static void vhost_user_cleanup(NetClientState *nc) { VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc); if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); s->vhost_net = NULL; if (nc->queue_index == 0) { qemu_chr_fe_deinit(&s->chr, true); qemu_purge_queued_packets(nc);


int av_base64_decode(uint8_t *out, const char *in, int out_size) { int i, v; uint8_t *dst = out; v = 0; for (i = 0; in[i] && in[i] != '='; i++) { unsigned int index= in[i]-43; if (index>=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff) return -1; v = (v << 6) + map2[index]; if (i & 3) { if (dst - out < out_size) { *dst++ = v >> (6 - 2 * (i & 3)); } } } return dst - out; }


static int process_input(int file_index) { InputFile *ifile = input_files[file_index]; AVFormatContext *is; InputStream *ist; AVPacket pkt; int ret, i, j; is = ifile->ctx; ret = get_input_packet(ifile, &pkt); if (ret == AVERROR(EAGAIN)) { ifile->eagain = 1; return ret; } if (ret < 0) { if (ret != AVERROR_EOF) { print_error(is->filename, ret); if (exit_on_error) exit_program(1); } ifile->eof_reached = 1; for (i = 0; i < ifile->nb_streams; i++) { ist = input_streams[ifile->ist_index + i]; if (ist->decoding_needed) output_packet(ist, NULL); /* mark all outputs that don't go through lavfi as finished */ for (j = 0; j < nb_output_streams; j++) { OutputStream *ost = output_streams[j]; if (ost->source_index == ifile->ist_index + i && (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) close_output_stream(ost); } } return AVERROR(EAGAIN); } reset_eagain(); if (do_pkt_dump) { av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, is->streams[pkt.stream_index]); } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ if (pkt.stream_index >= ifile->nb_streams) { report_new_stream(file_index, &pkt); goto discard_packet; } ist = input_streams[ifile->ist_index + pkt.stream_index]; if (ist->discard) goto discard_packet; if(!ist->wrap_correction_done && input_files[file_index]->ctx->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){ uint64_t stime = av_rescale_q(input_files[file_index]->ctx->start_time, AV_TIME_BASE_Q, ist->st->time_base); uint64_t stime2= stime + (1LL<<ist->st->pts_wrap_bits); ist->wrap_correction_done = 1; if(pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime && pkt.dts - stime > stime2 - pkt.dts) { pkt.dts -= 1LL<<ist->st->pts_wrap_bits; ist->wrap_correction_done = 0; } if(pkt.pts != AV_NOPTS_VALUE && pkt.pts > stime && pkt.pts - stime > stime2 - pkt.pts) { pkt.pts -= 1LL<<ist->st->pts_wrap_bits; ist->wrap_correction_done = 0; } } if (pkt.dts != AV_NOPTS_VALUE) pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts *= ist->ts_scale; if (pkt.dts != AV_NOPTS_VALUE) pkt.dts *= ist->ts_scale; if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%"PRId64"\n", ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->st->codec->codec_type), av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), input_files[ist->file_index]->ts_offset); } if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE && !copy_ts) { int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); int64_t delta = pkt_dts - ist->next_dts; if (is->iformat->flags & AVFMT_TS_DISCONT) { if(delta < -1LL*dts_delta_threshold*AV_TIME_BASE || (delta > 1LL*dts_delta_threshold*AV_TIME_BASE && ist->st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) || pkt_dts+1<ist->pts){ ifile->ts_offset -= delta; av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, ifile->ts_offset); pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if (pkt.pts != AV_NOPTS_VALUE) pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } else { if ( delta < -1LL*dts_error_threshold*AV_TIME_BASE || (delta > 1LL*dts_error_threshold*AV_TIME_BASE && ist->st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) ) { av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt.dts, ist->next_dts, pkt.stream_index); pkt.dts = AV_NOPTS_VALUE; } if (pkt.pts != AV_NOPTS_VALUE){ int64_t pkt_pts = av_rescale_q(pkt.pts, ist->st->time_base, AV_TIME_BASE_Q); delta = pkt_pts - ist->next_dts; if ( delta < -1LL*dts_error_threshold*AV_TIME_BASE || (delta > 1LL*dts_error_threshold*AV_TIME_BASE && ist->st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) ) { av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt.pts, ist->next_dts, pkt.stream_index); pkt.pts = AV_NOPTS_VALUE; } } } } sub2video_heartbeat(ist, pkt.pts); ret = output_packet(ist, &pkt); if (ret < 0) { char buf[128]; av_strerror(ret, buf, sizeof(buf)); av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n", ist->file_index, ist->st->index, buf); if (exit_on_error) exit_program(1); } discard_packet: av_free_packet(&pkt); return 0; }


void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) { int64_t value; if (!error_is_set(errp)) { if (v->type_int8) { v->type_int8(v, obj, name, errp); } else { value = *obj; v->type_int(v, &value, name, errp); if (value < INT8_MIN || value > INT8_MAX) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "int8_t"); return; } *obj = value; } } }


static void roq_encode_video(RoqContext *enc) { RoqTempdata *tempData = enc->tmpData; int i; memset(tempData, 0, sizeof(*tempData)); create_cel_evals(enc, tempData); generate_new_codebooks(enc, tempData); if (enc->framesSinceKeyframe >= 1) { motion_search(enc, 8); motion_search(enc, 4); } retry_encode: for (i=0; i<enc->width*enc->height/64; i++) gather_data_for_cel(tempData->cel_evals + i, enc, tempData); /* Quake 3 can't handle chunks bigger than 65536 bytes */ if (tempData->mainChunkSize/8 > 65536) { enc->lambda *= .8; goto retry_encode; } remap_codebooks(enc, tempData); write_codebooks(enc, tempData); reconstruct_and_encode_image(enc, tempData, enc->width, enc->height, enc->width*enc->height/64); enc->avctx->coded_frame = enc->current_frame; /* Rotate frame history */ FFSWAP(AVFrame *, enc->current_frame, enc->last_frame); FFSWAP(motion_vect *, enc->last_motion4, enc->this_motion4); FFSWAP(motion_vect *, enc->last_motion8, enc->this_motion8); av_free(tempData->cel_evals); av_free(tempData->closest_cb2); enc->framesSinceKeyframe++; }


static int packet_alloc(AVBufferRef **buf, int size) { int ret; if ((unsigned)size >= (unsigned)size + AV_INPUT_BUFFER_PADDING_SIZE) return AVERROR(EINVAL); ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE); if (ret < 0) return ret; memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); return 0; }


static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h; const uint8_t *p, *p_end; AVIOContext pb; int mp4_descr_count = 0; Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } }; int i, pid; AVFormatContext *s = ts->stream; p_end = section + section_len - 4; p = section; if (parse_section_header(&h, &p, p_end) < 0) return; if (h.tid != M4OD_TID) return; if (h.version == tssf->last_ver) return; tssf->last_ver = h.version; mp4_read_od(s, p, (unsigned) (p_end - p), mp4_descr, &mp4_descr_count, MAX_MP4_DESCR_COUNT); for (pid = 0; pid < NB_PID_MAX; pid++) { if (!ts->pids[pid]) continue; for (i = 0; i < mp4_descr_count; i++) { PESContext *pes; AVStream *st; if (ts->pids[pid]->es_id != mp4_descr[i].es_id) continue; if (ts->pids[pid]->type != MPEGTS_PES) { av_log(s, AV_LOG_ERROR, "pid %x is not PES\n", pid); continue; } pes = ts->pids[pid]->u.pes_filter.opaque; st = pes->st; if (!st) continue; pes->sl = mp4_descr[i].sl; ffio_init_context(&pb, mp4_descr[i].dec_config_descr, mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(s, st, &pb); if (st->codec->codec_id == AV_CODEC_ID_AAC && st->codec->extradata_size > 0) st->need_parsing = 0; if (st->codec->codec_id == AV_CODEC_ID_H264 && st->codec->extradata_size > 0) st->need_parsing = 0; if (st->codec->codec_id <= AV_CODEC_ID_NONE) { // do nothing } else if (st->codec->codec_id < AV_CODEC_ID_FIRST_AUDIO) st->codec->codec_type = AVMEDIA_TYPE_VIDEO; else if (st->codec->codec_id < AV_CODEC_ID_FIRST_SUBTITLE) st->codec->codec_type = AVMEDIA_TYPE_AUDIO; else if (st->codec->codec_id < AV_CODEC_ID_FIRST_UNKNOWN) st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; } } for (i = 0; i < mp4_descr_count; i++) av_free(mp4_descr[i].dec_config_descr); }


static int ffat_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { ATDecodeContext *at = avctx->priv_data; OSStatus ret; AudioBufferList out_buffers = { .mNumberBuffers = 1, .mBuffers = { { .mNumberChannels = avctx->channels, .mDataByteSize = at->pkt_size, } } }; AudioStreamPacketDescription out_pkt_desc = {0}; if ((ret = ff_alloc_packet2(avctx, avpkt, at->pkt_size, 0)) < 0) return ret; av_frame_unref(&at->new_in_frame); if (frame) { if ((ret = ff_af_queue_add(&at->afq, frame)) < 0) return ret; if ((ret = av_frame_ref(&at->new_in_frame, frame)) < 0) return ret; } else { at->eof = 1; } out_buffers.mBuffers[0].mData = avpkt->data; *got_packet_ptr = avctx->frame_size / at->frame_size; ret = AudioConverterFillComplexBuffer(at->converter, ffat_encode_callback, avctx, got_packet_ptr, &out_buffers, (avctx->frame_size > at->frame_size) ? NULL : &out_pkt_desc); if ((!ret || ret == 1) && *got_packet_ptr) { avpkt->size = out_buffers.mBuffers[0].mDataByteSize; ff_af_queue_remove(&at->afq, out_pkt_desc.mVariableFramesInPacket ? out_pkt_desc.mVariableFramesInPacket : avctx->frame_size, &avpkt->pts, &avpkt->duration); } else if (ret && ret != 1) { av_log(avctx, AV_LOG_WARNING, "Encode error: %i\n", ret); } return 0; }


static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary *opts, AVDictionary *opts2) { HLSContext *c = s->priv_data; AVDictionary *tmp = NULL; const char *proto_name = avio_find_protocol_name(url); int ret; av_dict_copy(&tmp, opts, 0); av_dict_copy(&tmp, opts2, 0); if (!proto_name) return AVERROR_INVALIDDATA; // only http(s) & file are allowed if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL)) return AVERROR_INVALIDDATA; if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':') ; else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5)) return AVERROR_INVALIDDATA; ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp); if (ret >= 0) { // update cookies on http response with setcookies. void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb; update_options(&c->cookies, "cookies", u); av_dict_set(&opts, "cookies", c->cookies, 0); } av_dict_free(&tmp); return ret; }


static int nvdec_mpeg12_end_frame(AVCodecContext *avctx) { NVDECContext *ctx = avctx->internal->hwaccel_priv_data; int ret = ff_nvdec_end_frame(avctx); ctx->bitstream = NULL; return ret; }


static void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUX86State *env) { abi_ulong frame_addr, addr; struct rt_sigframe *frame; int i, err = 0; frame_addr = get_sigframe(ka, env, sizeof(*frame)); if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) goto give_sigsegv; __put_user(current_exec_domain_sig(sig), &frame->sig); addr = frame_addr + offsetof(struct rt_sigframe, info); __put_user(addr, &frame->pinfo); addr = frame_addr + offsetof(struct rt_sigframe, uc); __put_user(addr, &frame->puc); err |= copy_siginfo_to_user(&frame->info, info); if (err) goto give_sigsegv; /* Create the ucontext. */ __put_user(0, &frame->uc.tuc_flags); __put_user(0, &frame->uc.tuc_link); __put_user(target_sigaltstack_used.ss_sp, &frame->uc.tuc_stack.ss_sp); __put_user(sas_ss_flags(get_sp_from_cpustate(env)), &frame->uc.tuc_stack.ss_flags); __put_user(target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size); err |= setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env, set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate)); for(i = 0; i < TARGET_NSIG_WORDS; i++) { if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i])) goto give_sigsegv; } /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { uint16_t val16; addr = frame_addr + offsetof(struct rt_sigframe, retcode); __put_user(addr, &frame->pretcode); /* This is movl $,%eax ; int $0x80 */ __put_user(0xb8, (char *)(frame->retcode+0)); __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); val16 = 0x80cd; __put_user(val16, (uint16_t *)(frame->retcode+5)); } if (err) goto give_sigsegv; /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; env->eip = ka->_sa_handler; cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); cpu_x86_load_seg(env, R_SS, __USER_DS); cpu_x86_load_seg(env, R_CS, __USER_CS); env->eflags &= ~TF_MASK; unlock_user_struct(frame, frame_addr, 1); return; give_sigsegv: unlock_user_struct(frame, frame_addr, 1); if (sig == TARGET_SIGSEGV) ka->_sa_handler = TARGET_SIG_DFL; force_sig(TARGET_SIGSEGV /* , current */); }


static void pci_qdev_realize(DeviceState *qdev, Error **errp) { PCIDevice *pci_dev = (PCIDevice *)qdev; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev); Error *local_err = NULL; PCIBus *bus; bool is_default_rom; /* initialize cap_present for pci_is_express() and pci_config_size() */ if (pc->is_express) { pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; } bus = PCI_BUS(qdev_get_parent_bus(qdev)); pci_dev = do_pci_register_device(pci_dev, bus, object_get_typename(OBJECT(qdev)), pci_dev->devfn, errp); if (pci_dev == NULL) return; if (pc->realize) { pc->realize(pci_dev, &local_err); if (local_err) { error_propagate(errp, local_err); do_pci_unregister_device(pci_dev); return; } } /* rom loading */ is_default_rom = false; if (pci_dev->romfile == NULL && pc->romfile != NULL) { pci_dev->romfile = g_strdup(pc->romfile); is_default_rom = true; } pci_add_option_rom(pci_dev, is_default_rom, &local_err); if (local_err) { error_propagate(errp, local_err); pci_qdev_unrealize(DEVICE(pci_dev), NULL); return; } }


int check_migratable(Object *obj, Error **err) { return 0; }


static av_cold int vp8_free(AVCodecContext *avctx) { VP8Context *ctx = avctx->priv_data; vpx_codec_destroy(&ctx->encoder); av_freep(&ctx->twopass_stats.buf); av_freep(&avctx->coded_frame); av_freep(&avctx->stats_out); free_frame_list(ctx->coded_frame_list); return 0; }


static void exynos4210_fimd_write(void *opaque, target_phys_addr_t offset, uint64_t val, unsigned size) { Exynos4210fimdState *s = (Exynos4210fimdState *)opaque; unsigned w, i; uint32_t old_value; DPRINT_L2("write offset 0x%08x, value=%llu(0x%08llx)\n", offset, (long long unsigned int)val, (long long unsigned int)val); switch (offset) { case FIMD_VIDCON0: if ((val & FIMD_VIDCON0_ENVID_MASK) == FIMD_VIDCON0_ENVID_MASK) { exynos4210_fimd_enable(s, true); } else { if ((val & FIMD_VIDCON0_ENVID) == 0) { exynos4210_fimd_enable(s, false); } } s->vidcon[0] = val; break; case FIMD_VIDCON1: /* Leave read-only bits as is */ val = (val & (~FIMD_VIDCON1_ROMASK)) | (s->vidcon[1] & FIMD_VIDCON1_ROMASK); s->vidcon[1] = val; break; case FIMD_VIDCON2 ... FIMD_VIDCON3: s->vidcon[(offset) >> 2] = val; break; case FIMD_VIDTCON_START ... FIMD_VIDTCON_END: s->vidtcon[(offset - FIMD_VIDTCON_START) >> 2] = val; break; case FIMD_WINCON_START ... FIMD_WINCON_END: w = (offset - FIMD_WINCON_START) >> 2; /* Window's current buffer ID */ i = fimd_get_buffer_id(&s->window[w]); old_value = s->window[w].wincon; val = (val & ~FIMD_WINCON_ROMASK) | (s->window[w].wincon & FIMD_WINCON_ROMASK); if (w == 0) { /* Window 0 wincon ALPHA_MUL bit must always be 0 */ val &= ~FIMD_WINCON_ALPHA_MUL; } exynos4210_fimd_trace_bppmode(s, w, val); switch (val & FIMD_WINCON_BUFSELECT) { case FIMD_WINCON_BUF0_SEL: val &= ~FIMD_WINCON_BUFSTATUS; break; case FIMD_WINCON_BUF1_SEL: val = (val & ~FIMD_WINCON_BUFSTAT_H) | FIMD_WINCON_BUFSTAT_L; break; case FIMD_WINCON_BUF2_SEL: if (val & FIMD_WINCON_BUFMODE) { val = (val & ~FIMD_WINCON_BUFSTAT_L) | FIMD_WINCON_BUFSTAT_H; } break; default: break; } s->window[w].wincon = val; exynos4210_fimd_update_win_bppmode(s, w); fimd_update_get_alpha(s, w); if ((i != fimd_get_buffer_id(&s->window[w])) || (!(old_value & FIMD_WINCON_ENWIN) && (s->window[w].wincon & FIMD_WINCON_ENWIN))) { fimd_update_memory_section(s, w); } break; case FIMD_SHADOWCON: old_value = s->shadowcon; s->shadowcon = val; for (w = 0; w < NUM_OF_WINDOWS; w++) { if (FIMD_WINDOW_PROTECTED(old_value, w) && !FIMD_WINDOW_PROTECTED(s->shadowcon, w)) { fimd_update_memory_section(s, w); } } break; case FIMD_WINCHMAP: s->winchmap = val; break; case FIMD_VIDOSD_START ... FIMD_VIDOSD_END: w = (offset - FIMD_VIDOSD_START) >> 4; i = ((offset - FIMD_VIDOSD_START) & 0xF) >> 2; switch (i) { case 0: old_value = s->window[w].lefttop_y; s->window[w].lefttop_x = (val >> FIMD_VIDOSD_HOR_SHIFT) & FIMD_VIDOSD_COORD_MASK; s->window[w].lefttop_y = (val >> FIMD_VIDOSD_VER_SHIFT) & FIMD_VIDOSD_COORD_MASK; if (s->window[w].lefttop_y != old_value) { fimd_update_memory_section(s, w); } break; case 1: old_value = s->window[w].rightbot_y; s->window[w].rightbot_x = (val >> FIMD_VIDOSD_HOR_SHIFT) & FIMD_VIDOSD_COORD_MASK; s->window[w].rightbot_y = (val >> FIMD_VIDOSD_VER_SHIFT) & FIMD_VIDOSD_COORD_MASK; if (s->window[w].rightbot_y != old_value) { fimd_update_memory_section(s, w); } break; case 2: if (w == 0) { s->window[w].osdsize = val; } else { s->window[w].alpha_val[0] = unpack_upper_4((val & FIMD_VIDOSD_ALPHA_AEN0) >> FIMD_VIDOSD_AEN0_SHIFT) | (s->window[w].alpha_val[0] & FIMD_VIDALPHA_ALPHA_LOWER); s->window[w].alpha_val[1] = unpack_upper_4(val & FIMD_VIDOSD_ALPHA_AEN1) | (s->window[w].alpha_val[1] & FIMD_VIDALPHA_ALPHA_LOWER); } break; case 3: if (w != 1 && w != 2) { DPRINT_ERROR("Bad write offset 0x%08x\n", offset); return; } s->window[w].osdsize = val; break; } break; case FIMD_VIDWADD0_START ... FIMD_VIDWADD0_END: w = (offset - FIMD_VIDWADD0_START) >> 3; i = ((offset - FIMD_VIDWADD0_START) >> 2) & 1; if (i == fimd_get_buffer_id(&s->window[w]) && s->window[w].buf_start[i] != val) { s->window[w].buf_start[i] = val; fimd_update_memory_section(s, w); break; } s->window[w].buf_start[i] = val; break; case FIMD_VIDWADD1_START ... FIMD_VIDWADD1_END: w = (offset - FIMD_VIDWADD1_START) >> 3; i = ((offset - FIMD_VIDWADD1_START) >> 2) & 1; s->window[w].buf_end[i] = val; break; case FIMD_VIDWADD2_START ... FIMD_VIDWADD2_END: w = (offset - FIMD_VIDWADD2_START) >> 2; if (((val & FIMD_VIDWADD2_PAGEWIDTH) != s->window[w].virtpage_width) || (((val >> FIMD_VIDWADD2_OFFSIZE_SHIFT) & FIMD_VIDWADD2_OFFSIZE) != s->window[w].virtpage_offsize)) { s->window[w].virtpage_width = val & FIMD_VIDWADD2_PAGEWIDTH; s->window[w].virtpage_offsize = (val >> FIMD_VIDWADD2_OFFSIZE_SHIFT) & FIMD_VIDWADD2_OFFSIZE; fimd_update_memory_section(s, w); } break; case FIMD_VIDINTCON0: s->vidintcon[0] = val; break; case FIMD_VIDINTCON1: s->vidintcon[1] &= ~(val & 7); exynos4210_fimd_update_irq(s); break; case FIMD_WKEYCON_START ... FIMD_WKEYCON_END: w = ((offset - FIMD_WKEYCON_START) >> 3) + 1; i = ((offset - FIMD_WKEYCON_START) >> 2) & 1; s->window[w].keycon[i] = val; break; case FIMD_WKEYALPHA_START ... FIMD_WKEYALPHA_END: w = ((offset - FIMD_WKEYALPHA_START) >> 2) + 1; s->window[w].keyalpha = val; break; case FIMD_DITHMODE: s->dithmode = val; break; case FIMD_WINMAP_START ... FIMD_WINMAP_END: w = (offset - FIMD_WINMAP_START) >> 2; old_value = s->window[w].winmap; s->window[w].winmap = val; if ((val & FIMD_WINMAP_EN) ^ (old_value & FIMD_WINMAP_EN)) { exynos4210_fimd_invalidate(s); exynos4210_fimd_update_win_bppmode(s, w); exynos4210_fimd_trace_bppmode(s, w, 0xFFFFFFFF); exynos4210_fimd_update(s); } break; case FIMD_WPALCON_HIGH ... FIMD_WPALCON_LOW: i = (offset - FIMD_WPALCON_HIGH) >> 2; s->wpalcon[i] = val; if (s->wpalcon[1] & FIMD_WPALCON_UPDATEEN) { for (w = 0; w < NUM_OF_WINDOWS; w++) { exynos4210_fimd_update_win_bppmode(s, w); fimd_update_get_alpha(s, w); } } break; case FIMD_TRIGCON: val = (val & ~FIMD_TRIGCON_ROMASK) | (s->trigcon & FIMD_TRIGCON_ROMASK); s->trigcon = val; break; case FIMD_I80IFCON_START ... FIMD_I80IFCON_END: s->i80ifcon[(offset - FIMD_I80IFCON_START) >> 2] = val; break; case FIMD_COLORGAINCON: s->colorgaincon = val; break; case FIMD_LDI_CMDCON0 ... FIMD_LDI_CMDCON1: s->ldi_cmdcon[(offset - FIMD_LDI_CMDCON0) >> 2] = val; break; case FIMD_SIFCCON0 ... FIMD_SIFCCON2: i = (offset - FIMD_SIFCCON0) >> 2; if (i != 2) { s->sifccon[i] = val; } break; case FIMD_HUECOEFCR_START ... FIMD_HUECOEFCR_END: i = (offset - FIMD_HUECOEFCR_START) >> 2; s->huecoef_cr[i] = val; break; case FIMD_HUECOEFCB_START ... FIMD_HUECOEFCB_END: i = (offset - FIMD_HUECOEFCB_START) >> 2; s->huecoef_cb[i] = val; break; case FIMD_HUEOFFSET: s->hueoffset = val; break; case FIMD_VIDWALPHA_START ... FIMD_VIDWALPHA_END: w = ((offset - FIMD_VIDWALPHA_START) >> 3); i = ((offset - FIMD_VIDWALPHA_START) >> 2) & 1; if (w == 0) { s->window[w].alpha_val[i] = val; } else { s->window[w].alpha_val[i] = (val & FIMD_VIDALPHA_ALPHA_LOWER) | (s->window[w].alpha_val[i] & FIMD_VIDALPHA_ALPHA_UPPER); } break; case FIMD_BLENDEQ_START ... FIMD_BLENDEQ_END: s->window[(offset - FIMD_BLENDEQ_START) >> 2].blendeq = val; break; case FIMD_BLENDCON: old_value = s->blendcon; s->blendcon = val; if ((s->blendcon & FIMD_ALPHA_8BIT) != (old_value & FIMD_ALPHA_8BIT)) { for (w = 0; w < NUM_OF_WINDOWS; w++) { fimd_update_get_alpha(s, w); } } break; case FIMD_WRTQOSCON_START ... FIMD_WRTQOSCON_END: s->window[(offset - FIMD_WRTQOSCON_START) >> 2].rtqoscon = val; break; case FIMD_I80IFCMD_START ... FIMD_I80IFCMD_END: s->i80ifcmd[(offset - FIMD_I80IFCMD_START) >> 2] = val; break; case FIMD_VIDW0ADD0_B2 ... FIMD_VIDW4ADD0_B2: if (offset & 0x0004) { DPRINT_ERROR("bad write offset 0x%08x\n", offset); break; } w = (offset - FIMD_VIDW0ADD0_B2) >> 3; if (fimd_get_buffer_id(&s->window[w]) == 2 && s->window[w].buf_start[2] != val) { s->window[w].buf_start[2] = val; fimd_update_memory_section(s, w); break; } s->window[w].buf_start[2] = val; break; case FIMD_SHD_ADD0_START ... FIMD_SHD_ADD0_END: if (offset & 0x0004) { DPRINT_ERROR("bad write offset 0x%08x\n", offset); break; } s->window[(offset - FIMD_SHD_ADD0_START) >> 3].shadow_buf_start = val; break; case FIMD_SHD_ADD1_START ... FIMD_SHD_ADD1_END: if (offset & 0x0004) { DPRINT_ERROR("bad write offset 0x%08x\n", offset); break; } s->window[(offset - FIMD_SHD_ADD1_START) >> 3].shadow_buf_end = val; break; case FIMD_SHD_ADD2_START ... FIMD_SHD_ADD2_END: s->window[(offset - FIMD_SHD_ADD2_START) >> 2].shadow_buf_size = val; break; case FIMD_PAL_MEM_START ... FIMD_PAL_MEM_END: w = (offset - FIMD_PAL_MEM_START) >> 10; i = ((offset - FIMD_PAL_MEM_START) >> 2) & 0xFF; s->window[w].palette[i] = val; break; case FIMD_PALMEM_AL_START ... FIMD_PALMEM_AL_END: /* Palette memory aliases for windows 0 and 1 */ w = (offset - FIMD_PALMEM_AL_START) >> 10; i = ((offset - FIMD_PALMEM_AL_START) >> 2) & 0xFF; s->window[w].palette[i] = val; break; default: DPRINT_ERROR("bad write offset 0x%08x\n", offset); break; } }


static int usb_wacom_initfn(USBDevice *dev) { USBWacomState *s = DO_UPCAST(USBWacomState, dev, dev); s->dev.speed = USB_SPEED_FULL; s->changed = 1; return 0; }


void bdrv_register(BlockDriver *bdrv) { /* Block drivers without coroutine functions need emulation */ if (!bdrv->bdrv_co_readv) { bdrv->bdrv_co_readv = bdrv_co_readv_em; bdrv->bdrv_co_writev = bdrv_co_writev_em; if (!bdrv->bdrv_aio_readv) { /* add AIO emulation layer */ bdrv->bdrv_aio_readv = bdrv_aio_readv_em; bdrv->bdrv_aio_writev = bdrv_aio_writev_em; } else if (!bdrv->bdrv_read) { /* add synchronous IO emulation layer */ bdrv->bdrv_read = bdrv_read_em; bdrv->bdrv_write = bdrv_write_em; } } if (!bdrv->bdrv_aio_flush) bdrv->bdrv_aio_flush = bdrv_aio_flush_em; QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list); }


void socket_listen_cleanup(int fd, Error **errp) { SocketAddress *addr; addr = socket_local_address(fd, errp); if (addr->type == SOCKET_ADDRESS_KIND_UNIX && addr->u.q_unix.data->path) { if (unlink(addr->u.q_unix.data->path) < 0 && errno != ENOENT) { error_setg_errno(errp, errno, "Failed to unlink socket %s", addr->u.q_unix.data->path); } } qapi_free_SocketAddress(addr); }


static void test_nested_struct(gconstpointer opaque) { TestArgs *args = (TestArgs *) opaque; const SerializeOps *ops = args->ops; UserDefNested *udnp = nested_struct_create(); UserDefNested *udnp_copy = NULL; Error *err = NULL; void *serialize_data; ops->serialize(udnp, &serialize_data, visit_nested_struct, &err); ops->deserialize((void **)&udnp_copy, serialize_data, visit_nested_struct, &err); g_assert(err == NULL); nested_struct_compare(udnp, udnp_copy); nested_struct_cleanup(udnp); nested_struct_cleanup(udnp_copy); ops->cleanup(serialize_data); g_free(args); }


static int usb_net_initfn(USBDevice *dev) { USBNetState *s = DO_UPCAST(USBNetState, dev, dev); s->dev.speed = USB_SPEED_FULL; s->rndis = 1; s->rndis_state = RNDIS_UNINITIALIZED; QTAILQ_INIT(&s->rndis_resp); s->medium = 0; /* NDIS_MEDIUM_802_3 */ s->speed = 1000000; /* 100MBps, in 100Bps units */ s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */; s->filter = 0; s->vendorid = 0x1234; qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_usbnet_info, &s->conf, s->dev.qdev.info->name, s->dev.qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); snprintf(s->usbstring_mac, sizeof(s->usbstring_mac), "%02x%02x%02x%02x%02x%02x", 0x40, s->conf.macaddr.a[1], s->conf.macaddr.a[2], s->conf.macaddr.a[3], s->conf.macaddr.a[4], s->conf.macaddr.a[5]); usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac); add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0"); return 0; }


static void curses_setup(void) { int i, colour_default[8] = { COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, }; /* input as raw as possible, let everything be interpreted * by the guest system */ initscr(); noecho(); intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE); start_color(); raw(); scrollok(stdscr, FALSE); for (i = 0; i < 64; i++) { init_pair(i, colour_default[i & 7], colour_default[i >> 3]); } /* Set default color for more than 64. (monitor uses 0x74xx for example) */ for (i = 64; i < COLOR_PAIRS; i++) { init_pair(i, COLOR_WHITE, COLOR_BLACK); } /* * Setup mapping for vga to curses line graphics. * FIXME: for better font, have to use ncursesw and setlocale() */ #if 0 /* FIXME: map from where? */ ACS_S1; ACS_S3; ACS_S7; ACS_S9; #endif /* ACS_* is not constant. So, we can't initialize statically. */ vga_to_curses['\0'] = ' '; vga_to_curses[0x04] = ACS_DIAMOND; vga_to_curses[0x0a] = ACS_RARROW; vga_to_curses[0x0b] = ACS_LARROW; vga_to_curses[0x18] = ACS_UARROW; vga_to_curses[0x19] = ACS_DARROW; vga_to_curses[0x9c] = ACS_STERLING; vga_to_curses[0xb0] = ACS_BOARD; vga_to_curses[0xb1] = ACS_CKBOARD; vga_to_curses[0xb3] = ACS_VLINE; vga_to_curses[0xb4] = ACS_RTEE; vga_to_curses[0xbf] = ACS_URCORNER; vga_to_curses[0xc0] = ACS_LLCORNER; vga_to_curses[0xc1] = ACS_BTEE; vga_to_curses[0xc2] = ACS_TTEE; vga_to_curses[0xc3] = ACS_LTEE; vga_to_curses[0xc4] = ACS_HLINE; vga_to_curses[0xc5] = ACS_PLUS; vga_to_curses[0xce] = ACS_LANTERN; vga_to_curses[0xd8] = ACS_NEQUAL; vga_to_curses[0xd9] = ACS_LRCORNER; vga_to_curses[0xda] = ACS_ULCORNER; vga_to_curses[0xdb] = ACS_BLOCK; vga_to_curses[0xe3] = ACS_PI; vga_to_curses[0xf1] = ACS_PLMINUS; vga_to_curses[0xf2] = ACS_GEQUAL; vga_to_curses[0xf3] = ACS_LEQUAL; vga_to_curses[0xf8] = ACS_DEGREE; vga_to_curses[0xfe] = ACS_BULLET; }


static bool send_gradient_rect(VncState *vs, int w, int h) { int stream = 3; int level = tight_conf[vs->tight_compression].gradient_zlib_level; size_t bytes; if (vs->clientds.pf.bytes_per_pixel == 1) return send_full_color_rect(vs, w, h); vnc_write_u8(vs, (stream | VNC_TIGHT_EXPLICIT_FILTER) << 4); vnc_write_u8(vs, VNC_TIGHT_FILTER_GRADIENT); buffer_reserve(&vs->tight_gradient, w * 3 * sizeof (int)); if (vs->tight_pixel24) { tight_filter_gradient24(vs, vs->tight.buffer, w, h); bytes = 3; } else if (vs->clientds.pf.bytes_per_pixel == 4) { tight_filter_gradient32(vs, (uint32_t *)vs->tight.buffer, w, h); bytes = 4; } else { tight_filter_gradient16(vs, (uint16_t *)vs->tight.buffer, w, h); bytes = 2; } buffer_reset(&vs->tight_gradient); bytes = w * h * bytes; vs->tight.offset = bytes; bytes = tight_compress_data(vs, stream, bytes, level, Z_FILTERED); return (bytes >= 0); }


int bdrv_get_flags(BlockDriverState *bs) { return bs->open_flags; }


static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) { AVFilterContext *ctx = inlink->dst; ASNSContext *asns = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; int ret; int nb_samples = insamples->nb_samples; if (av_audio_fifo_space(asns->fifo) < nb_samples) { av_log(ctx, AV_LOG_DEBUG, "No space for %d samples, stretching audio fifo\n", nb_samples); ret = av_audio_fifo_realloc(asns->fifo, av_audio_fifo_size(asns->fifo) + nb_samples); if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Stretching audio fifo failed, discarded %d samples\n", nb_samples); return -1; } } av_audio_fifo_write(asns->fifo, (void **)insamples->extended_data, nb_samples); if (asns->next_out_pts == AV_NOPTS_VALUE) asns->next_out_pts = insamples->pts; av_frame_free(&insamples); while (av_audio_fifo_size(asns->fifo) >= asns->nb_out_samples) push_samples(outlink); return 0; }