project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
FFmpeg
9e5381a21b2106a012b92c1878886c5af4e1a932
0
void parse_options(int argc, char **argv, const OptionDef *options, void (* parse_arg_function)(const char*)) { const char *opt, *arg; int optindex, handleoptions=1; const OptionDef *po; /* parse options */ optindex = 1; while (optindex < argc) { opt = argv[optindex++]; if (handleoptions && opt[0] == '-' && opt[1] != '\0') { int bool_val = 1; if (opt[1] == '-' && opt[2] == '\0') { handleoptions = 0; continue; } opt++; po= find_option(options, opt); if (!po->name && opt[0] == 'n' && opt[1] == 'o') { /* handle 'no' bool option */ po = find_option(options, opt + 2); if (!(po->name && (po->flags & OPT_BOOL))) goto unknown_opt; bool_val = 0; } if (!po->name) po= find_option(options, "default"); if (!po->name) { unknown_opt: fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt); exit(1); } arg = NULL; if (po->flags & HAS_ARG) { arg = argv[optindex++]; if (!arg) { fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt); exit(1); } } if (po->flags & OPT_STRING) { char *str; str = av_strdup(arg); *po->u.str_arg = str; } else if (po->flags & OPT_BOOL) { *po->u.int_arg = bool_val; } else if (po->flags & OPT_INT) { *po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); } else if (po->flags & OPT_INT64) { *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); } else if (po->flags & OPT_FLOAT) { *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -1.0/0.0, 1.0/0.0); } else if (po->flags & OPT_FUNC2) { if(po->u.func2_arg(opt, arg)<0) goto unknown_opt; } else { po->u.func_arg(arg); } if(po->flags & OPT_EXIT) exit(0); } else { if (parse_arg_function) parse_arg_function(opt); } } }
13,954
qemu
f7736b91c40a617e93505e32dcbd2cb56aad8a23
0
static int dma_buf_rw(BMDMAState *bm, int is_write) { IDEState *s = bmdma_active_if(bm); struct { uint32_t addr; uint32_t size; } prd; int l, len; for(;;) { l = s->io_buffer_size - s->io_buffer_index; if (l <= 0) break; if (bm->cur_prd_len == 0) { /* end of table (with a fail safe of one page) */ if (bm->cur_prd_last || (bm->cur_addr - bm->addr) >= 4096) return 0; cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8); bm->cur_addr += 8; prd.addr = le32_to_cpu(prd.addr); prd.size = le32_to_cpu(prd.size); len = prd.size & 0xfffe; if (len == 0) len = 0x10000; bm->cur_prd_len = len; bm->cur_prd_addr = prd.addr; bm->cur_prd_last = (prd.size & 0x80000000); } if (l > bm->cur_prd_len) l = bm->cur_prd_len; if (l > 0) { if (is_write) { cpu_physical_memory_write(bm->cur_prd_addr, s->io_buffer + s->io_buffer_index, l); } else { cpu_physical_memory_read(bm->cur_prd_addr, s->io_buffer + s->io_buffer_index, l); } bm->cur_prd_addr += l; bm->cur_prd_len -= l; s->io_buffer_index += l; } } return 1; }
13,955
qemu
5fa9a0ae49a01536a403f38e39222c3e8cc964c5
0
static void eepro100_cu_command(EEPRO100State * s, uint8_t val) { eepro100_tx_t tx; uint32_t cb_address; switch (val) { case CU_NOP: /* No operation. */ break; case CU_START: if (get_cu_state(s) != cu_idle) { /* Intel documentation says that CU must be idle for the CU * start command. Intel driver for Linux also starts the CU * from suspended state. */ logout("CU state is %u, should be %u\n", get_cu_state(s), cu_idle); //~ assert(!"wrong CU state"); } set_cu_state(s, cu_active); s->cu_offset = s->pointer; next_command: cb_address = s->cu_base + s->cu_offset; cpu_physical_memory_read(cb_address, (uint8_t *) & tx, sizeof(tx)); uint16_t status = le16_to_cpu(tx.status); uint16_t command = le16_to_cpu(tx.command); logout ("val=0x%02x (cu start), status=0x%04x, command=0x%04x, link=0x%08x\n", val, status, command, tx.link); bool bit_el = ((command & 0x8000) != 0); bool bit_s = ((command & 0x4000) != 0); bool bit_i = ((command & 0x2000) != 0); bool bit_nc = ((command & 0x0010) != 0); bool success = true; //~ bool bit_sf = ((command & 0x0008) != 0); uint16_t cmd = command & 0x0007; s->cu_offset = le32_to_cpu(tx.link); switch (cmd) { case CmdNOp: /* Do nothing. */ break; case CmdIASetup: cpu_physical_memory_read(cb_address + 8, &s->macaddr[0], 6); TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6))); break; case CmdConfigure: cpu_physical_memory_read(cb_address + 8, &s->configuration[0], sizeof(s->configuration)); TRACE(OTHER, logout("configuration: %s\n", nic_dump(&s->configuration[0], 16))); break; case CmdMulticastList: //~ missing("multicast list"); break; case CmdTx: (void)0; uint32_t tbd_array = le32_to_cpu(tx.tx_desc_addr); uint16_t tcb_bytes = (le16_to_cpu(tx.tcb_bytes) & 0x3fff); TRACE(RXTX, logout ("transmit, TBD array address 0x%08x, TCB byte count 0x%04x, TBD count %u\n", tbd_array, tcb_bytes, tx.tbd_count)); if (bit_nc) { missing("CmdTx: NC = 0"); success = false; break; } //~ assert(!bit_sf); if (tcb_bytes > 2600) { logout("TCB byte count too large, using 2600\n"); tcb_bytes = 2600; } /* Next assertion fails for local configuration. */ //~ assert((tcb_bytes > 0) || (tbd_array != 0xffffffff)); if (!((tcb_bytes > 0) || (tbd_array != 0xffffffff))) { logout ("illegal values of TBD array address and TCB byte count!\n"); } // sends larger than MAX_ETH_FRAME_SIZE are allowed, up to 2600 bytes uint8_t buf[2600]; uint16_t size = 0; uint32_t tbd_address = cb_address + 0x10; assert(tcb_bytes <= sizeof(buf)); while (size < tcb_bytes) { uint32_t tx_buffer_address = ldl_phys(tbd_address); uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); tbd_address += 8; TRACE(RXTX, logout ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n", tx_buffer_address, tx_buffer_size)); tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); cpu_physical_memory_read(tx_buffer_address, &buf[size], tx_buffer_size); size += tx_buffer_size; } if (tbd_array == 0xffffffff) { /* Simplified mode. Was already handled by code above. */ } else { /* Flexible mode. */ uint8_t tbd_count = 0; if (device_supports_eTxCB(s) && !(s->configuration[6] & BIT(4))) { /* Extended Flexible TCB. */ for (; tbd_count < 2; tbd_count++) { uint32_t tx_buffer_address = ldl_phys(tbd_address); uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); tbd_address += 8; TRACE(RXTX, logout ("TBD (extended flexible mode): buffer address 0x%08x, size 0x%04x\n", tx_buffer_address, tx_buffer_size)); tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); cpu_physical_memory_read(tx_buffer_address, &buf[size], tx_buffer_size); size += tx_buffer_size; if (tx_buffer_el & 1) { break; } } } tbd_address = tbd_array; for (; tbd_count < tx.tbd_count; tbd_count++) { uint32_t tx_buffer_address = ldl_phys(tbd_address); uint16_t tx_buffer_size = lduw_phys(tbd_address + 4); uint16_t tx_buffer_el = lduw_phys(tbd_address + 6); tbd_address += 8; TRACE(RXTX, logout ("TBD (flexible mode): buffer address 0x%08x, size 0x%04x\n", tx_buffer_address, tx_buffer_size)); tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size); cpu_physical_memory_read(tx_buffer_address, &buf[size], tx_buffer_size); size += tx_buffer_size; if (tx_buffer_el & 1) { break; } } } TRACE(RXTX, logout("%p sending frame, len=%d,%s\n", s, size, nic_dump(buf, size))); qemu_send_packet(s->vc, buf, size); s->statistics.tx_good_frames++; /* Transmit with bad status would raise an CX/TNO interrupt. * (82557 only). Emulation never has bad status. */ //~ eepro100_cx_interrupt(s); break; case CmdTDR: TRACE(OTHER, logout("load microcode\n")); /* Starting with offset 8, the command contains * 64 dwords microcode which we just ignore here. */ break; default: missing("undefined command"); success = false; break; } /* Write new status. */ stw_phys(cb_address, status | 0x8000 | (success ? 0x2000 : 0)); if (bit_i) { /* CU completed action. */ eepro100_cx_interrupt(s); } if (bit_el) { /* CU becomes idle. Terminate command loop. */ set_cu_state(s, cu_idle); eepro100_cna_interrupt(s); } else if (bit_s) { /* CU becomes suspended. */ set_cu_state(s, cu_suspended); eepro100_cna_interrupt(s); } else { /* More entries in list. */ TRACE(OTHER, logout("CU list with at least one more entry\n")); goto next_command; } TRACE(OTHER, logout("CU list empty\n")); /* List is empty. Now CU is idle or suspended. */ break; case CU_RESUME: if (get_cu_state(s) != cu_suspended) { logout("bad CU resume from CU state %u\n", get_cu_state(s)); /* Workaround for bad Linux eepro100 driver which resumes * from idle state. */ //~ missing("cu resume"); set_cu_state(s, cu_suspended); } if (get_cu_state(s) == cu_suspended) { TRACE(OTHER, logout("CU resuming\n")); set_cu_state(s, cu_active); goto next_command; } break; case CU_STATSADDR: /* Load dump counters address. */ s->statsaddr = s->pointer; TRACE(OTHER, logout("val=0x%02x (status address)\n", val)); break; case CU_SHOWSTATS: /* Dump statistical counters. */ TRACE(OTHER, logout("val=0x%02x (dump stats)\n", val)); dump_statistics(s); break; case CU_CMD_BASE: /* Load CU base. */ TRACE(OTHER, logout("val=0x%02x (CU base address)\n", val)); s->cu_base = s->pointer; break; case CU_DUMPSTATS: /* Dump and reset statistical counters. */ TRACE(OTHER, logout("val=0x%02x (dump stats and reset)\n", val)); dump_statistics(s); memset(&s->statistics, 0, sizeof(s->statistics)); break; case CU_SRESUME: /* CU static resume. */ missing("CU static resume"); break; default: missing("Undefined CU command"); } }
13,956
qemu
f101cd885ec148761738638ae42f7c5162b6d445
0
void HELPER(set_cp15)(CPUState *env, uint32_t insn, uint32_t val) { int op1; int op2; int crm; op1 = (insn >> 21) & 7; op2 = (insn >> 5) & 7; crm = insn & 0xf; switch ((insn >> 16) & 0xf) { case 0: /* ID codes. */ if (arm_feature(env, ARM_FEATURE_XSCALE)) break; if (arm_feature(env, ARM_FEATURE_OMAPCP)) break; if (arm_feature(env, ARM_FEATURE_V7) && op1 == 2 && crm == 0 && op2 == 0) { env->cp15.c0_cssel = val & 0xf; break; } goto bad_reg; case 1: /* System configuration. */ if (arm_feature(env, ARM_FEATURE_OMAPCP)) op2 = 0; switch (op2) { case 0: if (!arm_feature(env, ARM_FEATURE_XSCALE) || crm == 0) env->cp15.c1_sys = val; /* ??? Lots of these bits are not implemented. */ /* This may enable/disable the MMU, so do a TLB flush. */ tlb_flush(env, 1); break; case 1: /* Auxiliary cotrol register. */ if (arm_feature(env, ARM_FEATURE_XSCALE)) { env->cp15.c1_xscaleauxcr = val; break; } /* Not implemented. */ break; case 2: if (arm_feature(env, ARM_FEATURE_XSCALE)) goto bad_reg; if (env->cp15.c1_coproc != val) { env->cp15.c1_coproc = val; /* ??? Is this safe when called from within a TB? */ tb_flush(env); } break; default: goto bad_reg; } break; case 2: /* MMU Page table control / MPU cache control. */ if (arm_feature(env, ARM_FEATURE_MPU)) { switch (op2) { case 0: env->cp15.c2_data = val; break; case 1: env->cp15.c2_insn = val; break; default: goto bad_reg; } } else { switch (op2) { case 0: env->cp15.c2_base0 = val; break; case 1: env->cp15.c2_base1 = val; break; case 2: val &= 7; env->cp15.c2_control = val; env->cp15.c2_mask = ~(((uint32_t)0xffffffffu) >> val); env->cp15.c2_base_mask = ~((uint32_t)0x3fffu >> val); break; default: goto bad_reg; } } break; case 3: /* MMU Domain access control / MPU write buffer control. */ env->cp15.c3 = val; tlb_flush(env, 1); /* Flush TLB as domain not tracked in TLB */ break; case 4: /* Reserved. */ goto bad_reg; case 5: /* MMU Fault status / MPU access permission. */ if (arm_feature(env, ARM_FEATURE_OMAPCP)) op2 = 0; switch (op2) { case 0: if (arm_feature(env, ARM_FEATURE_MPU)) val = extended_mpu_ap_bits(val); env->cp15.c5_data = val; break; case 1: if (arm_feature(env, ARM_FEATURE_MPU)) val = extended_mpu_ap_bits(val); env->cp15.c5_insn = val; break; case 2: if (!arm_feature(env, ARM_FEATURE_MPU)) goto bad_reg; env->cp15.c5_data = val; break; case 3: if (!arm_feature(env, ARM_FEATURE_MPU)) goto bad_reg; env->cp15.c5_insn = val; break; default: goto bad_reg; } break; case 6: /* MMU Fault address / MPU base/size. */ if (arm_feature(env, ARM_FEATURE_MPU)) { if (crm >= 8) goto bad_reg; env->cp15.c6_region[crm] = val; } else { if (arm_feature(env, ARM_FEATURE_OMAPCP)) op2 = 0; switch (op2) { case 0: env->cp15.c6_data = val; break; case 1: /* ??? This is WFAR on armv6 */ case 2: env->cp15.c6_insn = val; break; default: goto bad_reg; } } break; case 7: /* Cache control. */ env->cp15.c15_i_max = 0x000; env->cp15.c15_i_min = 0xff0; /* No cache, so nothing to do. */ /* ??? MPCore has VA to PA translation functions. */ break; case 8: /* MMU TLB control. */ switch (op2) { case 0: /* Invalidate all. */ tlb_flush(env, 0); break; case 1: /* Invalidate single TLB entry. */ #if 0 /* ??? This is wrong for large pages and sections. */ /* As an ugly hack to make linux work we always flush a 4K pages. */ val &= 0xfffff000; tlb_flush_page(env, val); tlb_flush_page(env, val + 0x400); tlb_flush_page(env, val + 0x800); tlb_flush_page(env, val + 0xc00); #else tlb_flush(env, 1); #endif break; case 2: /* Invalidate on ASID. */ tlb_flush(env, val == 0); break; case 3: /* Invalidate single entry on MVA. */ /* ??? This is like case 1, but ignores ASID. */ tlb_flush(env, 1); break; default: goto bad_reg; } break; case 9: if (arm_feature(env, ARM_FEATURE_OMAPCP)) break; switch (crm) { case 0: /* Cache lockdown. */ switch (op1) { case 0: /* L1 cache. */ switch (op2) { case 0: env->cp15.c9_data = val; break; case 1: env->cp15.c9_insn = val; break; default: goto bad_reg; } break; case 1: /* L2 cache. */ /* Ignore writes to L2 lockdown/auxiliary registers. */ break; default: goto bad_reg; } break; case 1: /* TCM memory region registers. */ /* Not implemented. */ goto bad_reg; default: goto bad_reg; } break; case 10: /* MMU TLB lockdown. */ /* ??? TLB lockdown not implemented. */ break; case 12: /* Reserved. */ goto bad_reg; case 13: /* Process ID. */ switch (op2) { case 0: /* Unlike real hardware the qemu TLB uses virtual addresses, not modified virtual addresses, so this causes a TLB flush. */ if (env->cp15.c13_fcse != val) tlb_flush(env, 1); env->cp15.c13_fcse = val; break; case 1: /* This changes the ASID, so do a TLB flush. */ if (env->cp15.c13_context != val && !arm_feature(env, ARM_FEATURE_MPU)) tlb_flush(env, 0); env->cp15.c13_context = val; break; case 2: env->cp15.c13_tls1 = val; break; case 3: env->cp15.c13_tls2 = val; break; case 4: env->cp15.c13_tls3 = val; break; default: goto bad_reg; } break; case 14: /* Reserved. */ goto bad_reg; case 15: /* Implementation specific. */ if (arm_feature(env, ARM_FEATURE_XSCALE)) { if (op2 == 0 && crm == 1) { if (env->cp15.c15_cpar != (val & 0x3fff)) { /* Changes cp0 to cp13 behavior, so needs a TB flush. */ tb_flush(env); env->cp15.c15_cpar = val & 0x3fff; } break; } goto bad_reg; } if (arm_feature(env, ARM_FEATURE_OMAPCP)) { switch (crm) { case 0: break; case 1: /* Set TI925T configuration. */ env->cp15.c15_ticonfig = val & 0xe7; env->cp15.c0_cpuid = (val & (1 << 5)) ? /* OS_TYPE bit */ ARM_CPUID_TI915T : ARM_CPUID_TI925T; break; case 2: /* Set I_max. */ env->cp15.c15_i_max = val; break; case 3: /* Set I_min. */ env->cp15.c15_i_min = val; break; case 4: /* Set thread-ID. */ env->cp15.c15_threadid = val & 0xffff; break; case 8: /* Wait-for-interrupt (deprecated). */ cpu_interrupt(env, CPU_INTERRUPT_HALT); break; default: goto bad_reg; } } break; } return; bad_reg: /* ??? For debugging only. Should raise illegal instruction exception. */ cpu_abort(env, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n", (insn >> 16) & 0xf, crm, op1, op2); }
13,957
qemu
57407ea44cc0a3d630b9b89a2be011f1955ce5c1
0
static void pci_pcnet_cleanup(NetClientState *nc) { PCNetState *d = qemu_get_nic_opaque(nc); pcnet_common_cleanup(d); }
13,958
qemu
42a268c241183877192c376d03bd9b6d527407c7
0
static void gen_mulo(DisasContext *ctx) { int l1 = gen_new_label(); TCGv_i64 t0 = tcg_temp_new_i64(); TCGv_i64 t1 = tcg_temp_new_i64(); TCGv t2 = tcg_temp_new(); /* Start with XER OV disabled, the most likely case */ tcg_gen_movi_tl(cpu_ov, 0); tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); tcg_gen_mul_i64(t0, t0, t1); tcg_gen_trunc_i64_tl(t2, t0); gen_store_spr(SPR_MQ, t2); tcg_gen_shri_i64(t1, t0, 32); tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); tcg_gen_ext32s_i64(t1, t0); tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); tcg_gen_movi_tl(cpu_ov, 1); tcg_gen_movi_tl(cpu_so, 1); gen_set_label(l1); tcg_temp_free_i64(t0); tcg_temp_free_i64(t1); tcg_temp_free(t2); if (unlikely(Rc(ctx->opcode) != 0)) gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); }
13,959
qemu
12d69ac03b45156356b240424623719f15d8143e
0
static void test_source_flush_event_notifier(void) { EventNotifierTestData data = { .n = 0, .active = 10, .auto_set = true }; event_notifier_init(&data.e, false); aio_set_event_notifier(ctx, &data.e, event_ready_cb); g_assert(g_main_context_iteration(NULL, false)); g_assert_cmpint(data.n, ==, 0); g_assert_cmpint(data.active, ==, 10); event_notifier_set(&data.e); g_assert(g_main_context_iteration(NULL, false)); g_assert_cmpint(data.n, ==, 1); g_assert_cmpint(data.active, ==, 9); g_assert(g_main_context_iteration(NULL, false)); while (g_main_context_iteration(NULL, false)); g_assert_cmpint(data.n, ==, 10); g_assert_cmpint(data.active, ==, 0); g_assert(!g_main_context_iteration(NULL, false)); aio_set_event_notifier(ctx, &data.e, NULL); while (g_main_context_iteration(NULL, false)); event_notifier_cleanup(&data.e); }
13,960
qemu
8bfc26ea302ec03585d7258a7cf8938f76512730
0
uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) { uint32_t mask; unsigned el = arm_current_el(env); /* First handle registers which unprivileged can read */ switch (reg) { case 0 ... 7: /* xPSR sub-fields */ mask = 0; if ((reg & 1) && el) { mask |= XPSR_EXCP; /* IPSR (unpriv. reads as zero) */ } if (!(reg & 4)) { mask |= XPSR_NZCV | XPSR_Q; /* APSR */ } /* EPSR reads as zero */ return xpsr_read(env) & mask; break; case 20: /* CONTROL */ return env->v7m.control; } if (el == 0) { return 0; /* unprivileged reads others as zero */ } switch (reg) { case 8: /* MSP */ return (env->v7m.control & R_V7M_CONTROL_SPSEL_MASK) ? env->v7m.other_sp : env->regs[13]; case 9: /* PSP */ return (env->v7m.control & R_V7M_CONTROL_SPSEL_MASK) ? env->regs[13] : env->v7m.other_sp; case 16: /* PRIMASK */ return env->v7m.primask[env->v7m.secure]; case 17: /* BASEPRI */ case 18: /* BASEPRI_MAX */ return env->v7m.basepri[env->v7m.secure]; case 19: /* FAULTMASK */ return env->v7m.faultmask[env->v7m.secure]; default: qemu_log_mask(LOG_GUEST_ERROR, "Attempt to read unknown special" " register %d\n", reg); return 0; } }
13,961
qemu
104981d52b63dc3d68f39d4442881c667f44bbb9
0
static void usbredir_control_packet(void *priv, uint32_t id, struct usb_redir_control_packet_header *control_packet, uint8_t *data, int data_len) { USBRedirDevice *dev = priv; int len = control_packet->length; AsyncURB *aurb; DPRINTF("ctrl-in status %d len %d id %u\n", control_packet->status, len, id); aurb = async_find(dev, id); if (!aurb) { free(data); return; } aurb->control_packet.status = control_packet->status; aurb->control_packet.length = control_packet->length; if (memcmp(&aurb->control_packet, control_packet, sizeof(*control_packet))) { ERROR("return control packet mismatch, please report this!\n"); len = USB_RET_NAK; } if (aurb->packet) { len = usbredir_handle_status(dev, control_packet->status, len); if (len > 0) { usbredir_log_data(dev, "ctrl data in:", data, data_len); if (data_len <= sizeof(dev->dev.data_buf)) { memcpy(dev->dev.data_buf, data, data_len); } else { ERROR("ctrl buffer too small (%d > %zu)\n", data_len, sizeof(dev->dev.data_buf)); len = USB_RET_STALL; } } aurb->packet->result = len; usb_generic_async_ctrl_complete(&dev->dev, aurb->packet); } async_free(dev, aurb); free(data); }
13,962
qemu
5d47e3728bbd589701f74bb494c9c9825ba23c88
0
static int qemu_paio_submit(struct qemu_paiocb *aiocb, int is_write) { aiocb->is_write = is_write; aiocb->ret = -EINPROGRESS; aiocb->active = 0; mutex_lock(&lock); if (idle_threads == 0 && cur_threads < max_threads) spawn_thread(); TAILQ_INSERT_TAIL(&request_list, aiocb, node); mutex_unlock(&lock); cond_broadcast(&cond); return 0; }
13,963
qemu
2e6a64cb8d7506ad27d3b6c8000bc8d773936932
0
static void input_linux_event_keyboard(void *opaque) { InputLinux *il = opaque; struct input_event event; int rc; for (;;) { rc = read(il->fd, &event, sizeof(event)); if (rc != sizeof(event)) { if (rc < 0 && errno != EAGAIN) { fprintf(stderr, "%s: read: %s\n", __func__, strerror(errno)); qemu_set_fd_handler(il->fd, NULL, NULL, NULL); close(il->fd); } break; } input_linux_handle_keyboard(il, &event); } }
13,964
qemu
c572f23a3e7180dbeab5e86583e43ea2afed6271
1
static void v9fs_create(void *opaque) { int32_t fid; int err = 0; size_t offset = 7; V9fsFidState *fidp; V9fsQID qid; int32_t perm; int8_t mode; V9fsPath path; struct stat stbuf; V9fsString name; V9fsString extension; int iounit; V9fsPDU *pdu = opaque; v9fs_path_init(&path); pdu_unmarshal(pdu, offset, "dsdbs", &fid, &name, &perm, &mode, &extension); trace_v9fs_create(pdu->tag, pdu->id, fid, name.data, perm, mode); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (perm & P9_STAT_MODE_DIR) { err = v9fs_co_mkdir(pdu, fidp, &name, perm & 0777, fidp->uid, -1, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_opendir(pdu, fidp); if (err < 0) { goto out; } fidp->fid_type = P9_FID_DIR; } else if (perm & P9_STAT_MODE_SYMLINK) { err = v9fs_co_symlink(pdu, fidp, &name, extension.data, -1 , &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_LINK) { int32_t ofid = atoi(extension.data); V9fsFidState *ofidp = get_fid(pdu, ofid); if (ofidp == NULL) { err = -EINVAL; goto out; } err = v9fs_co_link(pdu, ofidp, fidp, &name); put_fid(pdu, ofidp); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } } else if (perm & P9_STAT_MODE_DEVICE) { char ctype; uint32_t major, minor; mode_t nmode = 0; if (sscanf(extension.data, "%c %u %u", &ctype, &major, &minor) != 3) { err = -errno; goto out; } switch (ctype) { case 'c': nmode = S_IFCHR; break; case 'b': nmode = S_IFBLK; break; default: err = -EIO; goto out; } nmode |= perm & 0777; err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, makedev(major, minor), nmode, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_NAMED_PIPE) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFIFO | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_SOCKET) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFSOCK | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else { err = v9fs_co_open2(pdu, fidp, &name, -1, omode_to_uflags(mode)|O_CREAT, perm, &stbuf); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = omode_to_uflags(mode); if (fidp->open_flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } } iounit = get_iounit(pdu, &fidp->path); stat_to_qid(&stbuf, &qid); offset += pdu_marshal(pdu, offset, "Qd", &qid, iounit); err = offset; out: put_fid(pdu, fidp); out_nofid: complete_pdu(pdu->s, pdu, err); v9fs_string_free(&name); v9fs_string_free(&extension); v9fs_path_free(&path); }
13,965
qemu
600b828c448f108b89e1f864f0420a49ccb70d43
1
static int gen_neon_unzip(int rd, int rm, int size, int q) { TCGv tmp, tmp2; if (size == 3 || (!q && size == 2)) { return 1; } tmp = tcg_const_i32(rd); tmp2 = tcg_const_i32(rm); if (q) { switch (size) { case 0: gen_helper_neon_qunzip8(tmp, tmp2); break; case 1: gen_helper_neon_qunzip16(tmp, tmp2); break; case 2: gen_helper_neon_qunzip32(tmp, tmp2); break; default: abort(); } } else { switch (size) { case 0: gen_helper_neon_unzip8(tmp, tmp2); break; case 1: gen_helper_neon_unzip16(tmp, tmp2); break; default: abort(); } } tcg_temp_free_i32(tmp); tcg_temp_free_i32(tmp2); return 0; }
13,966
qemu
35b5066ea7c2c3051fbc5a24b3d463b9800063e2
1
static void gen_wait(DisasContext *ctx) { TCGv_i32 t0 = tcg_temp_new_i32(); tcg_gen_st_i32(t0, cpu_env, -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted)); tcg_temp_free_i32(t0); /* Stop translation, as the CPU is supposed to sleep from now */ gen_exception_err(ctx, EXCP_HLT, 1); }
13,967
qemu
3005c2c2fa2875a3413af97e9db368856d3330fd
1
GuestExec *qmp_guest_exec(const char *path, bool has_arg, strList *arg, bool has_env, strList *env, bool has_input_data, const char *input_data, bool has_capture_output, bool capture_output, Error **err) { GPid pid; GuestExec *ge = NULL; GuestExecInfo *gei; char **argv, **envp; strList arglist; gboolean ret; GError *gerr = NULL; gint in_fd, out_fd, err_fd; GIOChannel *in_ch, *out_ch, *err_ch; GSpawnFlags flags; bool has_output = (has_capture_output && capture_output); uint8_t *input = NULL; size_t ninput = 0; arglist.value = (char *)path; arglist.next = has_arg ? arg : NULL; if (has_input_data) { input = qbase64_decode(input_data, -1, &ninput, err); if (!input) { return NULL; } } argv = guest_exec_get_args(&arglist, true); envp = has_env ? guest_exec_get_args(env, false) : NULL; flags = G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD; #if GLIB_CHECK_VERSION(2, 33, 2) flags |= G_SPAWN_SEARCH_PATH_FROM_ENVP; #endif if (!has_output) { flags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL; } ret = g_spawn_async_with_pipes(NULL, argv, envp, flags, guest_exec_task_setup, NULL, &pid, has_input_data ? &in_fd : NULL, has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr); if (!ret) { error_setg(err, QERR_QGA_COMMAND_FAILED, gerr->message); g_error_free(gerr); goto done; } ge = g_new0(GuestExec, 1); ge->pid = gpid_to_int64(pid); gei = guest_exec_info_add(pid); gei->has_output = has_output; g_child_watch_add(pid, guest_exec_child_watch, gei); if (has_input_data) { gei->in.data = input; gei->in.size = ninput; #ifdef G_OS_WIN32 in_ch = g_io_channel_win32_new_fd(in_fd); #else in_ch = g_io_channel_unix_new(in_fd); #endif g_io_channel_set_encoding(in_ch, NULL, NULL); g_io_channel_set_buffered(in_ch, false); g_io_channel_set_flags(in_ch, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch(in_ch, G_IO_OUT, guest_exec_input_watch, &gei->in); } if (has_output) { #ifdef G_OS_WIN32 out_ch = g_io_channel_win32_new_fd(out_fd); err_ch = g_io_channel_win32_new_fd(err_fd); #else out_ch = g_io_channel_unix_new(out_fd); err_ch = g_io_channel_unix_new(err_fd); #endif g_io_channel_set_encoding(out_ch, NULL, NULL); g_io_channel_set_encoding(err_ch, NULL, NULL); g_io_channel_set_buffered(out_ch, false); g_io_channel_set_buffered(err_ch, false); g_io_channel_set_close_on_unref(out_ch, true); g_io_channel_set_close_on_unref(err_ch, true); g_io_add_watch(out_ch, G_IO_IN | G_IO_HUP, guest_exec_output_watch, &gei->out); g_io_add_watch(err_ch, G_IO_IN | G_IO_HUP, guest_exec_output_watch, &gei->err); } done: g_free(argv); g_free(envp); return ge; }
13,968
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
0
static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat) { __asm__ volatile( "movq 24(%4), %%mm6 \n\t" "mov %3, %%"REG_a" \n\t" "pxor %%mm7, %%mm7 \n\t" "1: \n\t" PREFETCH" 64(%0) \n\t" "movd (%0), %%mm0 \n\t" "movd 2(%0), %%mm1 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm3 \n\t" "pmaddwd (%4), %%mm0 \n\t" "pmaddwd 8(%4), %%mm1 \n\t" "pmaddwd 16(%4), %%mm2 \n\t" "pmaddwd %%mm6, %%mm3 \n\t" "paddd %%mm1, %%mm0 \n\t" "paddd %%mm3, %%mm2 \n\t" "movd 6(%0), %%mm1 \n\t" "movd 8(%0), %%mm3 \n\t" "add $12, %0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "punpcklbw %%mm7, %%mm3 \n\t" "movq %%mm1, %%mm4 \n\t" "movq %%mm3, %%mm5 \n\t" "pmaddwd (%4), %%mm1 \n\t" "pmaddwd 8(%4), %%mm3 \n\t" "pmaddwd 16(%4), %%mm4 \n\t" "pmaddwd %%mm6, %%mm5 \n\t" "paddd %%mm3, %%mm1 \n\t" "paddd %%mm5, %%mm4 \n\t" "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3 \n\t" "paddd %%mm3, %%mm0 \n\t" "paddd %%mm3, %%mm2 \n\t" "paddd %%mm3, %%mm1 \n\t" "paddd %%mm3, %%mm4 \n\t" "psrad $15, %%mm0 \n\t" "psrad $15, %%mm2 \n\t" "psrad $15, %%mm1 \n\t" "psrad $15, %%mm4 \n\t" "packssdw %%mm1, %%mm0 \n\t" "packssdw %%mm4, %%mm2 \n\t" "packuswb %%mm0, %%mm0 \n\t" "packuswb %%mm2, %%mm2 \n\t" "movd %%mm0, (%1, %%"REG_a") \n\t" "movd %%mm2, (%2, %%"REG_a") \n\t" "add $4, %%"REG_a" \n\t" " js 1b \n\t" : "+r" (src) : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24]) : "%"REG_a ); }
13,970
FFmpeg
ac4b32df71bd932838043a4838b86d11e169707f
1
void intra_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3], VP8Macroblock *mb, int mb_x, int mb_y) { int x, y, mode, nnz; uint32_t tr; /* for the first row, we need to run xchg_mb_border to init the top edge * to 127 otherwise, skip it if we aren't going to deblock */ if (mb_y && (s->deblock_filter || !mb_y) && td->thread_nr == 0) xchg_mb_border(s->top_border[mb_x + 1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width, s->filter.simple, 1); if (mb->mode < MODE_I4x4) { mode = check_intra_pred8x8_mode_emuedge(mb->mode, mb_x, mb_y); s->hpc.pred16x16[mode](dst[0], s->linesize); } else { uint8_t *ptr = dst[0]; uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb; uint8_t tr_top[4] = { 127, 127, 127, 127 }; // all blocks on the right edge of the macroblock use bottom edge // the top macroblock for their topright edge uint8_t *tr_right = ptr - s->linesize + 16; // if we're on the right edge of the frame, said edge is extended // from the top macroblock if (mb_y && mb_x == s->mb_width - 1) { tr = tr_right[-1] * 0x01010101u; tr_right = (uint8_t *) &tr; } if (mb->skip) AV_ZERO128(td->non_zero_count_cache); for (y = 0; y < 4; y++) { uint8_t *topright = ptr + 4 - s->linesize; for (x = 0; x < 4; x++) { int copy = 0, linesize = s->linesize; uint8_t *dst = ptr + 4 * x; DECLARE_ALIGNED(4, uint8_t, copy_dst)[5 * 8]; if ((y == 0 || x == 3) && mb_y == 0) { topright = tr_top; } else if (x == 3) topright = tr_right; mode = check_intra_pred4x4_mode_emuedge(intra4x4[x], mb_x + x, mb_y + y, &copy); if (copy) { dst = copy_dst + 12; linesize = 8; if (!(mb_y + y)) { copy_dst[3] = 127U; AV_WN32A(copy_dst + 4, 127U * 0x01010101U); } else { AV_COPY32(copy_dst + 4, ptr + 4 * x - s->linesize); if (!(mb_x + x)) { copy_dst[3] = 129U; } else { copy_dst[3] = ptr[4 * x - s->linesize - 1]; } } if (!(mb_x + x)) { copy_dst[11] = copy_dst[19] = copy_dst[27] = copy_dst[35] = 129U; } else { copy_dst[11] = ptr[4 * x - 1]; copy_dst[19] = ptr[4 * x + s->linesize - 1]; copy_dst[27] = ptr[4 * x + s->linesize * 2 - 1]; copy_dst[35] = ptr[4 * x + s->linesize * 3 - 1]; } } s->hpc.pred4x4[mode](dst, topright, linesize); if (copy) { AV_COPY32(ptr + 4 * x, copy_dst + 12); AV_COPY32(ptr + 4 * x + s->linesize, copy_dst + 20); AV_COPY32(ptr + 4 * x + s->linesize * 2, copy_dst + 28); AV_COPY32(ptr + 4 * x + s->linesize * 3, copy_dst + 36); } nnz = td->non_zero_count_cache[y][x]; if (nnz) { if (nnz == 1) s->vp8dsp.vp8_idct_dc_add(ptr + 4 * x, td->block[y][x], s->linesize); else s->vp8dsp.vp8_idct_add(ptr + 4 * x, td->block[y][x], s->linesize); } topright += 4; } ptr += 4 * s->linesize; intra4x4 += 4; } } mode = check_intra_pred8x8_mode_emuedge(mb->chroma_pred_mode, mb_x, mb_y); s->hpc.pred8x8[mode](dst[1], s->uvlinesize); s->hpc.pred8x8[mode](dst[2], s->uvlinesize); if (mb_y && (s->deblock_filter || !mb_y) && td->thread_nr == 0) xchg_mb_border(s->top_border[mb_x + 1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width, s->filter.simple, 0); }
13,971
FFmpeg
526886e6069636a918c8c04db17e864e3d8151c1
1
static av_always_inline void decode_subband_internal(DiracContext *s, SubBand *b, int is_arith) { int cb_x, cb_y, left, right, top, bottom; DiracArith c; GetBitContext gb; int cb_width = s->codeblock[b->level + (b->orientation != subband_ll)].width; int cb_height = s->codeblock[b->level + (b->orientation != subband_ll)].height; int blockcnt_one = (cb_width + cb_height) == 2; if (!b->length) return; init_get_bits8(&gb, b->coeff_data, b->length); if (is_arith) ff_dirac_init_arith_decoder(&c, &gb, b->length); top = 0; for (cb_y = 0; cb_y < cb_height; cb_y++) { bottom = (b->height * (cb_y+1)) / cb_height; left = 0; for (cb_x = 0; cb_x < cb_width; cb_x++) { right = (b->width * (cb_x+1)) / cb_width; codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith); left = right; } top = bottom; } if (b->orientation == subband_ll && s->num_refs == 0) intra_dc_prediction(b); }
13,972
FFmpeg
28bf81c90d36a55cf76e2be913c5215ebebf61f2
1
static inline void RENAME(yuv2rgb2)(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int dstbpp) { int yalpha1=yalpha^4095; int uvalpha1=uvalpha^4095; if(fullUVIpol) { #ifdef HAVE_MMX if(dstbpp == 32) { asm volatile( FULL_YSCALEYUV2RGB "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 MOVNTQ(%%mm3, (%4, %%eax, 4)) MOVNTQ(%%mm1, 8(%4, %%eax, 4)) "addl $4, %%eax \n\t" "cmpl %5, %%eax \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } else if(dstbpp==24) { asm volatile( FULL_YSCALEYUV2RGB // lsb ... msb "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 "movq %%mm3, %%mm2 \n\t" // BGR0BGR0 "psrlq $8, %%mm3 \n\t" // GR0BGR00 "pand "MANGLE(bm00000111)", %%mm2\n\t" // BGR00000 "pand "MANGLE(bm11111000)", %%mm3\n\t" // 000BGR00 "por %%mm2, %%mm3 \n\t" // BGRBGR00 "movq %%mm1, %%mm2 \n\t" "psllq $48, %%mm1 \n\t" // 000000BG "por %%mm1, %%mm3 \n\t" // BGRBGRBG "movq %%mm2, %%mm1 \n\t" // BGR0BGR0 "psrld $16, %%mm2 \n\t" // R000R000 "psrlq $24, %%mm1 \n\t" // 0BGR0000 "por %%mm2, %%mm1 \n\t" // RBGRR000 "movl %4, %%ebx \n\t" "addl %%eax, %%ebx \n\t" #ifdef HAVE_MMX2 //FIXME Alignment "movntq %%mm3, (%%ebx, %%eax, 2)\n\t" "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t" #else "movd %%mm3, (%%ebx, %%eax, 2) \n\t" "psrlq $32, %%mm3 \n\t" "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t" "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t" #endif "addl $4, %%eax \n\t" "cmpl %5, %%eax \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax", "%ebx" ); } else if(dstbpp==15) { asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g5Dither)", %%mm1\n\t" "paddusb "MANGLE(r5Dither)", %%mm0\n\t" "paddusb "MANGLE(b5Dither)", %%mm3\n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $2, %%mm1 \n\t" "psllw $7, %%mm0 \n\t" "pand "MANGLE(g15Mask)", %%mm1 \n\t" "pand "MANGLE(r15Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%eax, 2)) "addl $4, %%eax \n\t" "cmpl %5, %%eax \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } else if(dstbpp==16) { asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g6Dither)", %%mm1\n\t" "paddusb "MANGLE(r5Dither)", %%mm0\n\t" "paddusb "MANGLE(b5Dither)", %%mm3\n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $3, %%mm1 \n\t" "psllw $8, %%mm0 \n\t" "pand "MANGLE(g16Mask)", %%mm1 \n\t" "pand "MANGLE(r16Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%eax, 2)) "addl $4, %%eax \n\t" "cmpl %5, %%eax \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } #else if(dstbpp==32 || dstbpp==24) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; dest+=dstbpp>>3; } } else if(dstbpp==16) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table16b[(Y + yuvtab_40cf[U]) >>13] | clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table16r[(Y + yuvtab_3343[V]) >>13]; } } else if(dstbpp==15) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table15b[(Y + yuvtab_40cf[U]) >>13] | clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table15r[(Y + yuvtab_3343[V]) >>13]; } } #endif }//FULL_UV_IPOL else { #ifdef HAVE_MMX if(dstbpp == 32) { asm volatile( YSCALEYUV2RGB WRITEBGR32 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } else if(dstbpp==24) { asm volatile( "movl %4, %%ebx \n\t" YSCALEYUV2RGB WRITEBGR24 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax", "%ebx" ); } else if(dstbpp==15) { asm volatile( YSCALEYUV2RGB /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g5Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR15 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } else if(dstbpp==16) { asm volatile( YSCALEYUV2RGB /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g6Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR16 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%eax" ); } #else if(dstbpp==32) { int i; for(i=0; i<dstW-1; i+=2){ // vertical linear interpolation && yuv2rgb in a single step: int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)]; int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19); int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19); int Cb= yuvtab_40cf[U]; int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U]; int Cr= yuvtab_3343[V]; dest[4*i+0]=clip_table[((Y1 + Cb) >>13)]; dest[4*i+1]=clip_table[((Y1 + Cg) >>13)]; dest[4*i+2]=clip_table[((Y1 + Cr) >>13)]; dest[4*i+4]=clip_table[((Y2 + Cb) >>13)]; dest[4*i+5]=clip_table[((Y2 + Cg) >>13)]; dest[4*i+6]=clip_table[((Y2 + Cr) >>13)]; } } else if(dstbpp==24) { int i; for(i=0; i<dstW-1; i+=2){ // vertical linear interpolation && yuv2rgb in a single step: int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)]; int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19); int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19); int Cb= yuvtab_40cf[U]; int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U]; int Cr= yuvtab_3343[V]; dest[0]=clip_table[((Y1 + Cb) >>13)]; dest[1]=clip_table[((Y1 + Cg) >>13)]; dest[2]=clip_table[((Y1 + Cr) >>13)]; dest[3]=clip_table[((Y2 + Cb) >>13)]; dest[4]=clip_table[((Y2 + Cg) >>13)]; dest[5]=clip_table[((Y2 + Cr) >>13)]; dest+=6; } } else if(dstbpp==16) { int i; for(i=0; i<dstW-1; i+=2){ // vertical linear interpolation && yuv2rgb in a single step: int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)]; int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19); int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19); int Cb= yuvtab_40cf[U]; int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U]; int Cr= yuvtab_3343[V]; ((uint16_t*)dest)[i] = clip_table16b[(Y1 + Cb) >>13] | clip_table16g[(Y1 + Cg) >>13] | clip_table16r[(Y1 + Cr) >>13]; ((uint16_t*)dest)[i+1] = clip_table16b[(Y2 + Cb) >>13] | clip_table16g[(Y2 + Cg) >>13] | clip_table16r[(Y2 + Cr) >>13]; } } else if(dstbpp==15) { int i; for(i=0; i<dstW-1; i+=2){ // vertical linear interpolation && yuv2rgb in a single step: int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)]; int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19); int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19); int Cb= yuvtab_40cf[U]; int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U]; int Cr= yuvtab_3343[V]; ((uint16_t*)dest)[i] = clip_table15b[(Y1 + Cb) >>13] | clip_table15g[(Y1 + Cg) >>13] | clip_table15r[(Y1 + Cr) >>13]; ((uint16_t*)dest)[i+1] = clip_table15b[(Y2 + Cb) >>13] | clip_table15g[(Y2 + Cg) >>13] | clip_table15r[(Y2 + Cr) >>13]; } } #endif } //!FULL_UV_IPOL }
13,973
FFmpeg
2e9b79fc003f19c65f4fd6ef30748c1916ed4fa7
1
static int wavpack_encode_block(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, uint8_t *out, int out_size) { int block_size, start, end, data_size, tcount, temp, m = 0; int i, j, ret, got_extra = 0, nb_samples = s->block_samples; uint32_t crc = 0xffffffffu; struct Decorr *dpp; PutByteContext pb; if (!(s->flags & WV_MONO) && s->optimize_mono) { int32_t lor = 0, diff = 0; for (i = 0; i < nb_samples; i++) { lor |= samples_l[i] | samples_r[i]; diff |= samples_l[i] - samples_r[i]; if (lor && diff) break; } if (i == nb_samples && lor && !diff) { s->flags &= ~(WV_JOINT_STEREO | WV_CROSS_DECORR); s->flags |= WV_FALSE_STEREO; if (!s->false_stereo) { s->false_stereo = 1; s->num_terms = 0; CLEAR(s->w); } } else if (s->false_stereo) { s->false_stereo = 0; s->num_terms = 0; CLEAR(s->w); } } if (s->flags & SHIFT_MASK) { int shift = (s->flags & SHIFT_MASK) >> SHIFT_LSB; int mag = (s->flags & MAG_MASK) >> MAG_LSB; if (s->flags & WV_MONO_DATA) shift_mono(samples_l, nb_samples, shift); else shift_stereo(samples_l, samples_r, nb_samples, shift); if ((mag -= shift) < 0) s->flags &= ~MAG_MASK; else s->flags -= (1 << MAG_LSB) * shift; } if ((s->flags & WV_FLOAT_DATA) || (s->flags & MAG_MASK) >> MAG_LSB >= 24) { av_fast_padded_malloc(&s->orig_l, &s->orig_l_size, sizeof(int32_t) * nb_samples); memcpy(s->orig_l, samples_l, sizeof(int32_t) * nb_samples); if (!(s->flags & WV_MONO_DATA)) { av_fast_padded_malloc(&s->orig_r, &s->orig_r_size, sizeof(int32_t) * nb_samples); memcpy(s->orig_r, samples_r, sizeof(int32_t) * nb_samples); } if (s->flags & WV_FLOAT_DATA) got_extra = scan_float(s, samples_l, samples_r, nb_samples); else got_extra = scan_int32(s, samples_l, samples_r, nb_samples); s->num_terms = 0; } else { scan_int23(s, samples_l, samples_r, nb_samples); if (s->shift != s->int32_zeros + s->int32_ones + s->int32_dups) { s->shift = s->int32_zeros + s->int32_ones + s->int32_dups; s->num_terms = 0; } } if (!s->num_passes && !s->num_terms) { s->num_passes = 1; if (s->flags & WV_MONO_DATA) ret = wv_mono(s, samples_l, 1, 0); else ret = wv_stereo(s, samples_l, samples_r, 1, 0); s->num_passes = 0; } if (s->flags & WV_MONO_DATA) { for (i = 0; i < nb_samples; i++) crc += (crc << 1) + samples_l[i]; if (s->num_passes) ret = wv_mono(s, samples_l, !s->num_terms, 1); } else { for (i = 0; i < nb_samples; i++) crc += (crc << 3) + (samples_l[i] << 1) + samples_l[i] + samples_r[i]; if (s->num_passes) ret = wv_stereo(s, samples_l, samples_r, !s->num_terms, 1); } if (ret < 0) return ret; if (!s->ch_offset) s->flags |= WV_INITIAL_BLOCK; s->ch_offset += 1 + !(s->flags & WV_MONO); if (s->ch_offset == s->avctx->channels) s->flags |= WV_FINAL_BLOCK; bytestream2_init_writer(&pb, out, out_size); bytestream2_put_le32(&pb, MKTAG('w', 'v', 'p', 'k')); bytestream2_put_le32(&pb, 0); bytestream2_put_le16(&pb, 0x410); bytestream2_put_le16(&pb, 0); bytestream2_put_le32(&pb, 0); bytestream2_put_le32(&pb, s->sample_index); bytestream2_put_le32(&pb, nb_samples); bytestream2_put_le32(&pb, s->flags); bytestream2_put_le32(&pb, crc); if (s->flags & WV_INITIAL_BLOCK && s->avctx->channel_layout != AV_CH_LAYOUT_MONO && s->avctx->channel_layout != AV_CH_LAYOUT_STEREO) { put_metadata_block(&pb, WP_ID_CHANINFO, 5); bytestream2_put_byte(&pb, s->avctx->channels); bytestream2_put_le32(&pb, s->avctx->channel_layout); bytestream2_put_byte(&pb, 0); } if ((s->flags & SRATE_MASK) == SRATE_MASK) { put_metadata_block(&pb, WP_ID_SAMPLE_RATE, 3); bytestream2_put_le24(&pb, s->avctx->sample_rate); bytestream2_put_byte(&pb, 0); } put_metadata_block(&pb, WP_ID_DECTERMS, s->num_terms); for (i = 0; i < s->num_terms; i++) { struct Decorr *dpp = &s->decorr_passes[i]; bytestream2_put_byte(&pb, ((dpp->value + 5) & 0x1f) | ((dpp->delta << 5) & 0xe0)); } if (s->num_terms & 1) bytestream2_put_byte(&pb, 0); #define WRITE_DECWEIGHT(type) do { \ temp = store_weight(type); \ bytestream2_put_byte(&pb, temp); \ type = restore_weight(temp); \ } while (0) bytestream2_put_byte(&pb, WP_ID_DECWEIGHTS); bytestream2_put_byte(&pb, 0); start = bytestream2_tell_p(&pb); for (i = s->num_terms - 1; i >= 0; --i) { struct Decorr *dpp = &s->decorr_passes[i]; if (store_weight(dpp->weightA) || (!(s->flags & WV_MONO_DATA) && store_weight(dpp->weightB))) break; } tcount = i + 1; for (i = 0; i < s->num_terms; i++) { struct Decorr *dpp = &s->decorr_passes[i]; if (i < tcount) { WRITE_DECWEIGHT(dpp->weightA); if (!(s->flags & WV_MONO_DATA)) WRITE_DECWEIGHT(dpp->weightB); } else { dpp->weightA = dpp->weightB = 0; } } end = bytestream2_tell_p(&pb); out[start - 2] = WP_ID_DECWEIGHTS | (((end - start) & 1) ? WP_IDF_ODD: 0); out[start - 1] = (end - start + 1) >> 1; if ((end - start) & 1) bytestream2_put_byte(&pb, 0); #define WRITE_DECSAMPLE(type) do { \ temp = log2s(type); \ type = wp_exp2(temp); \ bytestream2_put_le16(&pb, temp); \ } while (0) bytestream2_put_byte(&pb, WP_ID_DECSAMPLES); bytestream2_put_byte(&pb, 0); start = bytestream2_tell_p(&pb); for (i = 0; i < s->num_terms; i++) { struct Decorr *dpp = &s->decorr_passes[i]; if (i == 0) { if (dpp->value > MAX_TERM) { WRITE_DECSAMPLE(dpp->samplesA[0]); WRITE_DECSAMPLE(dpp->samplesA[1]); if (!(s->flags & WV_MONO_DATA)) { WRITE_DECSAMPLE(dpp->samplesB[0]); WRITE_DECSAMPLE(dpp->samplesB[1]); } } else if (dpp->value < 0) { WRITE_DECSAMPLE(dpp->samplesA[0]); WRITE_DECSAMPLE(dpp->samplesB[0]); } else { for (j = 0; j < dpp->value; j++) { WRITE_DECSAMPLE(dpp->samplesA[j]); if (!(s->flags & WV_MONO_DATA)) WRITE_DECSAMPLE(dpp->samplesB[j]); } } } else { CLEAR(dpp->samplesA); CLEAR(dpp->samplesB); } } end = bytestream2_tell_p(&pb); out[start - 1] = (end - start) >> 1; #define WRITE_CHAN_ENTROPY(chan) do { \ for (i = 0; i < 3; i++) { \ temp = wp_log2(s->w.c[chan].median[i]); \ bytestream2_put_le16(&pb, temp); \ s->w.c[chan].median[i] = wp_exp2(temp); \ } \ } while (0) put_metadata_block(&pb, WP_ID_ENTROPY, 6 * (1 + (!(s->flags & WV_MONO_DATA)))); WRITE_CHAN_ENTROPY(0); if (!(s->flags & WV_MONO_DATA)) WRITE_CHAN_ENTROPY(1); if (s->flags & WV_FLOAT_DATA) { put_metadata_block(&pb, WP_ID_FLOATINFO, 4); bytestream2_put_byte(&pb, s->float_flags); bytestream2_put_byte(&pb, s->float_shift); bytestream2_put_byte(&pb, s->float_max_exp); bytestream2_put_byte(&pb, 127); } if (s->flags & WV_INT32_DATA) { put_metadata_block(&pb, WP_ID_INT32INFO, 4); bytestream2_put_byte(&pb, s->int32_sent_bits); bytestream2_put_byte(&pb, s->int32_zeros); bytestream2_put_byte(&pb, s->int32_ones); bytestream2_put_byte(&pb, s->int32_dups); } if (s->flags & WV_MONO_DATA && !s->num_passes) { for (i = 0; i < nb_samples; i++) { int32_t code = samples_l[i]; for (tcount = s->num_terms, dpp = s->decorr_passes; tcount--; dpp++) { int32_t sam; if (dpp->value > MAX_TERM) { if (dpp->value & 1) sam = 2 * dpp->samplesA[0] - dpp->samplesA[1]; else sam = (3 * dpp->samplesA[0] - dpp->samplesA[1]) >> 1; dpp->samplesA[1] = dpp->samplesA[0]; dpp->samplesA[0] = code; } else { sam = dpp->samplesA[m]; dpp->samplesA[(m + dpp->value) & (MAX_TERM - 1)] = code; } code -= APPLY_WEIGHT(dpp->weightA, sam); UPDATE_WEIGHT(dpp->weightA, dpp->delta, sam, code); } m = (m + 1) & (MAX_TERM - 1); samples_l[i] = code; } if (m) { for (tcount = s->num_terms, dpp = s->decorr_passes; tcount--; dpp++) if (dpp->value > 0 && dpp->value <= MAX_TERM) { int32_t temp_A[MAX_TERM], temp_B[MAX_TERM]; int k; memcpy(temp_A, dpp->samplesA, sizeof(dpp->samplesA)); memcpy(temp_B, dpp->samplesB, sizeof(dpp->samplesB)); for (k = 0; k < MAX_TERM; k++) { dpp->samplesA[k] = temp_A[m]; dpp->samplesB[k] = temp_B[m]; m = (m + 1) & (MAX_TERM - 1); } } } } else if (!s->num_passes) { if (s->flags & WV_JOINT_STEREO) { for (i = 0; i < nb_samples; i++) samples_r[i] += ((samples_l[i] -= samples_r[i]) >> 1); } for (i = 0; i < s->num_terms; i++) { struct Decorr *dpp = &s->decorr_passes[i]; if (((s->flags & MAG_MASK) >> MAG_LSB) >= 16 || dpp->delta != 2) decorr_stereo_pass2(dpp, samples_l, samples_r, nb_samples); else decorr_stereo_pass_id2(dpp, samples_l, samples_r, nb_samples); } } bytestream2_put_byte(&pb, WP_ID_DATA | WP_IDF_LONG); init_put_bits(&s->pb, pb.buffer + 3, bytestream2_get_bytes_left_p(&pb)); if (s->flags & WV_MONO_DATA) { for (i = 0; i < nb_samples; i++) wavpack_encode_sample(s, &s->w.c[0], s->samples[0][i]); } else { for (i = 0; i < nb_samples; i++) { wavpack_encode_sample(s, &s->w.c[0], s->samples[0][i]); wavpack_encode_sample(s, &s->w.c[1], s->samples[1][i]); } } encode_flush(s); flush_put_bits(&s->pb); data_size = put_bits_count(&s->pb) >> 3; bytestream2_put_le24(&pb, (data_size + 1) >> 1); bytestream2_skip_p(&pb, data_size); if (data_size & 1) bytestream2_put_byte(&pb, 0); if (got_extra) { bytestream2_put_byte(&pb, WP_ID_EXTRABITS | WP_IDF_LONG); init_put_bits(&s->pb, pb.buffer + 7, bytestream2_get_bytes_left_p(&pb)); if (s->flags & WV_FLOAT_DATA) pack_float(s, s->orig_l, s->orig_r, nb_samples); else pack_int32(s, s->orig_l, s->orig_r, nb_samples); flush_put_bits(&s->pb); data_size = put_bits_count(&s->pb) >> 3; bytestream2_put_le24(&pb, (data_size + 5) >> 1); bytestream2_put_le32(&pb, s->crc_x); bytestream2_skip_p(&pb, data_size); if (data_size & 1) bytestream2_put_byte(&pb, 0); } block_size = bytestream2_tell_p(&pb); AV_WL32(out + 4, block_size - 8); return block_size; }
13,974
qemu
b161e2e4b32ac8fb9e6a891eba3da0b825b5d046
1
static void qemu_laio_process_completion(struct qemu_laio_state *s, struct qemu_laiocb *laiocb) { int ret; s->count--; ret = laiocb->ret; if (ret != -ECANCELED) { if (ret == laiocb->nbytes) ret = 0; else if (ret >= 0) ret = -EINVAL; laiocb->common.cb(laiocb->common.opaque, ret); } qemu_aio_release(laiocb); }
13,975
qemu
d72915c60bff51495529449750e051d01b03c62f
1
void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg) { *cfg = ts->cfg;
13,976
qemu
fa5912a17b51b807c4ec78a4aa914891c7770781
1
vreader_xfr_bytes(VReader *reader, unsigned char *send_buf, int send_buf_len, unsigned char *receive_buf, int *receive_buf_len) { VCardAPDU *apdu; VCardResponse *response = NULL; VCardStatus card_status; unsigned short status; VCard *card = vreader_get_card(reader); if (card == NULL) { return VREADER_NO_CARD; } apdu = vcard_apdu_new(send_buf, send_buf_len, &status); if (apdu == NULL) { response = vcard_make_response(status); card_status = VCARD_DONE; } else { g_debug("%s: CLS=0x%x,INS=0x%x,P1=0x%x,P2=0x%x,Lc=%d,Le=%d %s", __func__, apdu->a_cla, apdu->a_ins, apdu->a_p1, apdu->a_p2, apdu->a_Lc, apdu->a_Le, apdu_ins_to_string(apdu->a_ins)); card_status = vcard_process_apdu(card, apdu, &response); if (response) { g_debug("%s: status=%d sw1=0x%x sw2=0x%x len=%d (total=%d)", __func__, response->b_status, response->b_sw1, response->b_sw2, response->b_len, response->b_total_len); } } assert(card_status == VCARD_DONE); if (card_status == VCARD_DONE) { int size = MIN(*receive_buf_len, response->b_total_len); memcpy(receive_buf, response->b_data, size); *receive_buf_len = size; } vcard_response_delete(response); vcard_apdu_delete(apdu); vcard_free(card); /* free our reference */ return VREADER_OK; }
13,977
qemu
5193be3be35f29a35bc465036cd64ad60d43385f
1
static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) { TSC210xState *s = (TSC210xState *) opaque; int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int i; s->x = qemu_get_be16(f); s->y = qemu_get_be16(f); s->pressure = qemu_get_byte(f); s->state = qemu_get_byte(f); s->page = qemu_get_byte(f); s->offset = qemu_get_byte(f); s->command = qemu_get_byte(f); s->irq = qemu_get_byte(f); qemu_get_be16s(f, &s->dav); timer_get(f, s->timer); s->enabled = qemu_get_byte(f); s->host_mode = qemu_get_byte(f); s->function = qemu_get_byte(f); s->nextfunction = qemu_get_byte(f); s->precision = qemu_get_byte(f); s->nextprecision = qemu_get_byte(f); s->filter = qemu_get_byte(f); s->pin_func = qemu_get_byte(f); s->ref = qemu_get_byte(f); s->timing = qemu_get_byte(f); s->noise = qemu_get_be32(f); qemu_get_be16s(f, &s->audio_ctrl1); qemu_get_be16s(f, &s->audio_ctrl2); qemu_get_be16s(f, &s->audio_ctrl3); qemu_get_be16s(f, &s->pll[0]); qemu_get_be16s(f, &s->pll[1]); qemu_get_be16s(f, &s->volume); s->volume_change = qemu_get_sbe64(f) + now; s->powerdown = qemu_get_sbe64(f) + now; s->softstep = qemu_get_byte(f); qemu_get_be16s(f, &s->dac_power); for (i = 0; i < 0x14; i ++) qemu_get_be16s(f, &s->filter_data[i]); s->busy = timer_pending(s->timer); qemu_set_irq(s->pint, !s->irq); qemu_set_irq(s->davint, !s->dav); return 0;
13,978
qemu
ef4760626e88bc3e7a1b46c7370378cbd12d379f
1
static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr) { uint16_t val; if (addr <= sizeof(s->mem) - sizeof(val)) { memcpy(&val, &s->mem[addr], sizeof(val)); } switch (addr) { case SCBStatus: case SCBCmd: TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val)); break; case SCBeeprom: val = eepro100_read_eeprom(s); TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val)); break; default: logout("addr=%s val=0x%04x\n", regname(addr), val); missing("unknown word read"); } return val; }
13,979
qemu
7d1b0095bff7157e856d1d0e6c4295641ced2752
1
static int disas_cp15_insn(CPUState *env, DisasContext *s, uint32_t insn) { uint32_t rd; TCGv tmp, tmp2; /* M profile cores use memory mapped registers instead of cp15. */ if (arm_feature(env, ARM_FEATURE_M)) return 1; if ((insn & (1 << 25)) == 0) { if (insn & (1 << 20)) { /* mrrc */ return 1; } /* mcrr. Used for block cache operations, so implement as no-op. */ return 0; } if ((insn & (1 << 4)) == 0) { /* cdp */ return 1; } if (IS_USER(s) && !cp15_user_ok(insn)) { return 1; } /* Pre-v7 versions of the architecture implemented WFI via coprocessor * instructions rather than a separate instruction. */ if ((insn & 0x0fff0fff) == 0x0e070f90) { /* 0,c7,c0,4: Standard v6 WFI (also used in some pre-v6 cores). * In v7, this must NOP. */ if (!arm_feature(env, ARM_FEATURE_V7)) { /* Wait for interrupt. */ gen_set_pc_im(s->pc); s->is_jmp = DISAS_WFI; } return 0; } if ((insn & 0x0fff0fff) == 0x0e070f58) { /* 0,c7,c8,2: Not all pre-v6 cores implemented this WFI, * so this is slightly over-broad. */ if (!arm_feature(env, ARM_FEATURE_V6)) { /* Wait for interrupt. */ gen_set_pc_im(s->pc); s->is_jmp = DISAS_WFI; return 0; } /* Otherwise fall through to handle via helper function. * In particular, on v7 and some v6 cores this is one of * the VA-PA registers. */ } rd = (insn >> 12) & 0xf; if (cp15_tls_load_store(env, s, insn, rd)) return 0; tmp2 = tcg_const_i32(insn); if (insn & ARM_CP_RW_BIT) { tmp = new_tmp(); gen_helper_get_cp15(tmp, cpu_env, tmp2); /* If the destination register is r15 then sets condition codes. */ if (rd != 15) store_reg(s, rd, tmp); else dead_tmp(tmp); } else { tmp = load_reg(s, rd); gen_helper_set_cp15(cpu_env, tmp2, tmp); dead_tmp(tmp); /* Normally we would always end the TB here, but Linux * arch/arm/mach-pxa/sleep.S expects two instructions following * an MMU enable to execute from cache. Imitate this behaviour. */ if (!arm_feature(env, ARM_FEATURE_XSCALE) || (insn & 0x0fff0fff) != 0x0e010f10) gen_lookup_tb(s); } tcg_temp_free_i32(tmp2); return 0; }
13,980
FFmpeg
7c0b84d89911b2035161f5ef51aafbfcc84aa9e2
1
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) { ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; ASFStream *stream; AVCodecContext *codec; uint32_t packet_number; int64_t pts; int start_sec; int flags = pkt->flags; int ret; uint64_t offset = avio_tell(pb); codec = s->streams[pkt->stream_index]->codec; stream = &asf->streams[pkt->stream_index]; if (codec->codec_type == AVMEDIA_TYPE_AUDIO) flags &= ~AV_PKT_FLAG_KEY; pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts; av_assert0(pts != AV_NOPTS_VALUE); pts *= 10000; asf->duration = FFMAX(asf->duration, pts + pkt->duration * 10000); packet_number = asf->nb_packets; put_frame(s, stream, s->streams[pkt->stream_index], pkt->dts, pkt->data, pkt->size, flags); start_sec = (int)((PREROLL_TIME * 10000 + pts + ASF_INDEXED_INTERVAL - 1) / ASF_INDEXED_INTERVAL); /* check index */ if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) { uint16_t packet_count = asf->nb_packets - packet_number; ret = update_index(s, start_sec, packet_number, packet_count, offset); if (ret < 0) return ret; asf->end_sec = start_sec; return 0;
13,981
qemu
efec3dd631d94160288392721a5f9c39e50fb2bc
1
static void pl181_class_init(ObjectClass *klass, void *data) { SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); DeviceClass *k = DEVICE_CLASS(klass); sdc->init = pl181_init; k->vmsd = &vmstate_pl181; k->reset = pl181_reset; k->no_user = 1; }
13,982
qemu
a718978ed58abc1ad92567a9c17525136be02a71
1
static void ahci_start_transfer(IDEDMA *dma) { AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma); IDEState *s = &ad->port.ifs[0]; uint32_t size = (uint32_t)(s->data_end - s->data_ptr); /* write == ram -> device */ uint16_t opts = le16_to_cpu(ad->cur_cmd->opts); int is_write = opts & AHCI_CMD_WRITE; int is_atapi = opts & AHCI_CMD_ATAPI; int has_sglist = 0; if (is_atapi && !ad->done_atapi_packet) { /* already prepopulated iobuffer */ ad->done_atapi_packet = true; size = 0; goto out; } if (ahci_dma_prepare_buf(dma, is_write)) { has_sglist = 1; } DPRINTF(ad->port_no, "%sing %d bytes on %s w/%s sglist\n", is_write ? "writ" : "read", size, is_atapi ? "atapi" : "ata", has_sglist ? "" : "o"); if (has_sglist && size) { if (is_write) { dma_buf_write(s->data_ptr, size, &s->sg); } else { dma_buf_read(s->data_ptr, size, &s->sg); } } out: /* declare that we processed everything */ s->data_ptr = s->data_end; /* Update number of transferred bytes, destroy sglist */ ahci_commit_buf(dma, size); s->end_transfer_func(s); if (!(s->status & DRQ_STAT)) { /* done with PIO send/receive */ ahci_write_fis_pio(ad, le32_to_cpu(ad->cur_cmd->status)); } }
13,983
qemu
6e38a4ba7889083b65729db2144cdbcefbaa303a
1
void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d) { qemu_irq *irq; if (bus->dma == &bm->dma) { return; } bm->dma.ops = &bmdma_ops; bus->dma = &bm->dma; bm->irq = bus->irq; irq = qemu_allocate_irqs(bmdma_irq, bm, 1); bus->irq = *irq; bm->pci_dev = d; }
13,984
qemu
46daff13c854769bfa8c51e77719325ea0f47b1b
1
static void qemu_tcg_wait_io_event(void) { CPUState *env; while (all_cpu_threads_idle()) { /* Start accounting real time to the virtual clock if the CPUs are idle. */ qemu_clock_warp(vm_clock); qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex); } qemu_mutex_unlock(&qemu_global_mutex); /* * Users of qemu_global_mutex can be starved, having no chance * to acquire it since this path will get to it first. * So use another lock to provide fairness. */ qemu_mutex_lock(&qemu_fair_mutex); qemu_mutex_unlock(&qemu_fair_mutex); qemu_mutex_lock(&qemu_global_mutex); for (env = first_cpu; env != NULL; env = env->next_cpu) { qemu_wait_io_event_common(env); } }
13,985
FFmpeg
770c934fa1635f4fadf5db4fc5cc5ad15d82455a
1
void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) { int i, j, n, n8, n4, n2, n3; FFTDouble re, im; const uint16_t *revtab = s->revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; FFTComplex *x = (FFTComplex *)out; n = 1 << s->mdct_bits; n2 = n >> 1; n4 = n >> 2; n8 = n >> 3; n3 = 3 * n4; /* pre rotation */ for(i=0;i<n8;i++) { re = RSCALE(-input[2*i+n3] - input[n3-1-2*i]); im = RSCALE(-input[n4+2*i] + input[n4-1-2*i]); j = revtab[i]; CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]); re = RSCALE( input[2*i] - input[n2-1-2*i]); im = RSCALE(-input[n2+2*i] - input[ n-1-2*i]); j = revtab[n8 + i]; CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]); } s->fft_calc(s, x); /* post rotation */ for(i=0;i<n8;i++) { FFTSample r0, i0, r1, i1; CMUL(i1, r0, x[n8-i-1].re, x[n8-i-1].im, -tsin[n8-i-1], -tcos[n8-i-1]); CMUL(i0, r1, x[n8+i ].re, x[n8+i ].im, -tsin[n8+i ], -tcos[n8+i ]); x[n8-i-1].re = r0; x[n8-i-1].im = i0; x[n8+i ].re = r1; x[n8+i ].im = i1; } }
13,986
qemu
71d0770c4cec9f1dc04f4dadcbf7fd6c335030a9
1
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) { BlockDriverState *bs; int ret; bs = bdrv_new(""); if (!bs) return -ENOMEM; ret = bdrv_open2(bs, filename, flags | BDRV_O_FILE, NULL); if (ret < 0) { bdrv_delete(bs); return ret; } *pbs = bs; return 0; }
13,987
FFmpeg
dc6cf61e331557eb275a44d7a31df8e781bbb22b
1
static int sdp_parse_fmtp_config_h264(AVStream * stream, PayloadContext * h264_data, char *attr, char *value) { AVCodecContext *codec = stream->codec; assert(codec->codec_id == CODEC_ID_H264); assert(h264_data != NULL); if (!strcmp(attr, "packetization-mode")) { av_log(codec, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value)); h264_data->packetization_mode = atoi(value); /* Packetization Mode: 0 or not present: Single NAL mode (Only nals from 1-23 are allowed) 1: Non-interleaved Mode: 1-23, 24 (STAP-A), 28 (FU-A) are allowed. 2: Interleaved Mode: 25 (STAP-B), 26 (MTAP16), 27 (MTAP24), 28 (FU-A), and 29 (FU-B) are allowed. */ if (h264_data->packetization_mode > 1) av_log(codec, AV_LOG_ERROR, "Interleaved RTP mode is not supported yet."); } else if (!strcmp(attr, "profile-level-id")) { if (strlen(value) == 6) { char buffer[3]; // 6 characters=3 bytes, in hex. uint8_t profile_idc; uint8_t profile_iop; uint8_t level_idc; buffer[0] = value[0]; buffer[1] = value[1]; buffer[2] = '\0'; profile_idc = strtol(buffer, NULL, 16); buffer[0] = value[2]; buffer[1] = value[3]; profile_iop = strtol(buffer, NULL, 16); buffer[0] = value[4]; buffer[1] = value[5]; level_idc = strtol(buffer, NULL, 16); // set the parameters... av_log(codec, AV_LOG_DEBUG, "RTP Profile IDC: %x Profile IOP: %x Level: %x\n", profile_idc, profile_iop, level_idc); h264_data->profile_idc = profile_idc; h264_data->profile_iop = profile_iop; h264_data->level_idc = level_idc; } } else if (!strcmp(attr, "sprop-parameter-sets")) { uint8_t start_sequence[]= { 0, 0, 1 }; codec->extradata_size= 0; codec->extradata= NULL; while (*value) { char base64packet[1024]; uint8_t decoded_packet[1024]; uint32_t packet_size; char *dst = base64packet; while (*value && *value != ',' && (dst - base64packet) < sizeof(base64packet) - 1) { *dst++ = *value++; } *dst++ = '\0'; if (*value == ',') value++; packet_size= av_base64_decode(decoded_packet, base64packet, sizeof(decoded_packet)); if (packet_size) { uint8_t *dest = av_malloc(packet_size + sizeof(start_sequence) + codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if(dest) { if(codec->extradata_size) { // av_realloc? memcpy(dest, codec->extradata, codec->extradata_size); av_free(codec->extradata); } memcpy(dest+codec->extradata_size, start_sequence, sizeof(start_sequence)); memcpy(dest+codec->extradata_size+sizeof(start_sequence), decoded_packet, packet_size); memset(dest+codec->extradata_size+sizeof(start_sequence)+ packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); codec->extradata= dest; codec->extradata_size+= sizeof(start_sequence)+packet_size; } else { av_log(codec, AV_LOG_ERROR, "Unable to allocate memory for extradata!"); return AVERROR(ENOMEM); } } } av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size); } return 0; }
13,989
qemu
b4ba67d9a702507793c2724e56f98e9b0f7be02b
1
void qpci_io_writeq(QPCIDevice *dev, void *data, uint64_t value) { uintptr_t addr = (uintptr_t)data; if (addr < QPCI_PIO_LIMIT) { dev->bus->pio_writeq(dev->bus, addr, value); } else { value = cpu_to_le64(value); dev->bus->memwrite(dev->bus, addr, &value, sizeof(value)); } }
13,990
qemu
7d61d892327d803ae43d14500601e48031b4632c
1
static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, abi_ulong target_addr, socklen_t addrlen) { void *addr; void *host_msg; abi_long ret; if ((int)addrlen < 0) { return -TARGET_EINVAL; } host_msg = lock_user(VERIFY_READ, msg, len, 1); if (!host_msg) return -TARGET_EFAULT; if (fd_trans_target_to_host_data(fd)) { ret = fd_trans_target_to_host_data(fd)(host_msg, len); if (ret < 0) { unlock_user(host_msg, msg, 0); return ret; } } if (target_addr) { addr = alloca(addrlen+1); ret = target_to_host_sockaddr(fd, addr, target_addr, addrlen); if (ret) { unlock_user(host_msg, msg, 0); return ret; } ret = get_errno(safe_sendto(fd, host_msg, len, flags, addr, addrlen)); } else { ret = get_errno(safe_sendto(fd, host_msg, len, flags, NULL, 0)); } unlock_user(host_msg, msg, 0); return ret; }
13,991
qemu
8804f57b531e4887ad9521c9abb9e0bbbcb1dd4e
1
static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req, uint8_t *buf, uint32_t len) { struct srp_direct_buf *md = req->cur_desc; uint32_t llen; int rc; dprintf("VSCSI: direct segment 0x%x bytes, va=0x%llx desc len=0x%x\n", len, (unsigned long long)md->va, md->len); llen = MIN(len, md->len); if (llen) { if (req->writing) { /* writing = to device = reading from memory */ rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen); } else { rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen); } } md->len -= llen; md->va += llen; if (rc) { return -1; } return llen; }
13,992
qemu
eef9f19eea26cd8b4553459118f87d7150b53c5a
1
static inline void flash_sync_area(Flash *s, int64_t off, int64_t len) { QEMUIOVector *iov = g_new(QEMUIOVector, 1); if (!s->blk || blk_is_read_only(s->blk)) { return; } assert(!(len % BDRV_SECTOR_SIZE)); qemu_iovec_init(iov, 1); qemu_iovec_add(iov, s->storage + off, len); blk_aio_pwritev(s->blk, off, iov, 0, blk_sync_complete, iov); }
13,993
qemu
6658ffb81ee56a510d7d77025872a508a9adce3a
1
static void gdb_vm_stopped(void *opaque, int reason) { GDBState *s = opaque; char buf[256]; int ret; if (s->state == RS_SYSCALL) /* disable single step if it was enable */ cpu_single_step(s->env, 0); if (reason == EXCP_DEBUG) { tb_flush(s->env); ret = SIGTRAP; } else if (reason == EXCP_INTERRUPT) { ret = SIGINT; } else { ret = 0; snprintf(buf, sizeof(buf), "S%02x", ret);
13,994
qemu
baf35cb90204d75404892aa4e52628ae7a00669b
1
void main_loop_wait(int timeout) { IOHandlerRecord *ioh; fd_set rfds, wfds, xfds; int ret, nfds; #ifdef _WIN32 int ret2, i; #endif struct timeval tv; PollingEntry *pe; /* XXX: need to suppress polling by better using win32 events */ ret = 0; for(pe = first_polling_entry; pe != NULL; pe = pe->next) { ret |= pe->func(pe->opaque); } #ifdef _WIN32 if (ret == 0) { int err; WaitObjects *w = &wait_objects; ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout); if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) { if (w->func[ret - WAIT_OBJECT_0]) w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); /* Check for additional signaled events */ for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) { /* Check if event is signaled */ ret2 = WaitForSingleObject(w->events[i], 0); if(ret2 == WAIT_OBJECT_0) { if (w->func[i]) w->func[i](w->opaque[i]); } else if (ret2 == WAIT_TIMEOUT) { } else { err = GetLastError(); fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err); } } } else if (ret == WAIT_TIMEOUT) { } else { err = GetLastError(); fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err); } } #endif /* poll any events */ /* XXX: separate device handlers from system ones */ nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { if (ioh->deleted) continue; if (ioh->fd_read && (!ioh->fd_read_poll || ioh->fd_read_poll(ioh->opaque) != 0)) { FD_SET(ioh->fd, &rfds); if (ioh->fd > nfds) nfds = ioh->fd; } if (ioh->fd_write) { FD_SET(ioh->fd, &wfds); if (ioh->fd > nfds) nfds = ioh->fd; } } tv.tv_sec = 0; #ifdef _WIN32 tv.tv_usec = 0; #else tv.tv_usec = timeout * 1000; #endif #if defined(CONFIG_SLIRP) if (slirp_inited) { slirp_select_fill(&nfds, &rfds, &wfds, &xfds); } #endif ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); if (ret > 0) { IOHandlerRecord **pioh; for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { ioh->fd_read(ioh->opaque); } if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { ioh->fd_write(ioh->opaque); } } /* remove deleted IO handlers */ pioh = &first_io_handler; while (*pioh) { ioh = *pioh; if (ioh->deleted) { *pioh = ioh->next; qemu_free(ioh); } else pioh = &ioh->next; } } #if defined(CONFIG_SLIRP) if (slirp_inited) { if (ret < 0) { FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); } slirp_select_poll(&rfds, &wfds, &xfds); } #endif qemu_aio_poll(); if (vm_running) { if (likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER))) qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], qemu_get_clock(vm_clock)); /* run dma transfers, if any */ DMA_run(); } /* real time timers */ qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], qemu_get_clock(rt_clock)); if (alarm_timer->flags & ALARM_FLAG_EXPIRED) { alarm_timer->flags &= ~(ALARM_FLAG_EXPIRED); qemu_rearm_alarm_timer(alarm_timer); } /* Check bottom-halves last in case any of the earlier events triggered them. */ qemu_bh_poll(); }
13,995
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int buf_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) { QEMUBuffer *s = opaque; return qsb_write_at(s->qsb, buf, pos, size); }
13,996
qemu
cf143ad35018c5fc1da6365b45acda2b34aba90a
1
static void mv88w8618_eth_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { mv88w8618_eth_state *s = opaque; switch (offset) { case MP_ETH_SMIR: s->smir = value; break; case MP_ETH_PCXR: s->vlan_header = ((value >> MP_ETH_PCXR_2BSM_BIT) & 1) * 2; break; case MP_ETH_SDCMR: if (value & MP_ETH_CMD_TXHI) { eth_send(s, 1); } if (value & MP_ETH_CMD_TXLO) { eth_send(s, 0); } if (value & (MP_ETH_CMD_TXHI | MP_ETH_CMD_TXLO) && s->icr & s->imr) { qemu_irq_raise(s->irq); } break; case MP_ETH_ICR: s->icr &= value; break; case MP_ETH_IMR: s->imr = value; if (s->icr & s->imr) { qemu_irq_raise(s->irq); } break; case MP_ETH_FRDP0 ... MP_ETH_FRDP3: s->frx_queue[(offset - MP_ETH_FRDP0)/4] = value; break; case MP_ETH_CRDP0 ... MP_ETH_CRDP3: s->rx_queue[(offset - MP_ETH_CRDP0)/4] = s->cur_rx[(offset - MP_ETH_CRDP0)/4] = value; break; case MP_ETH_CTDP0 ... MP_ETH_CTDP3: s->tx_queue[(offset - MP_ETH_CTDP0)/4] = value; break; } }
13,997
FFmpeg
ab3ff19f08b7a83e320c39ab066f289c242b8030
1
static int config_props(AVFilterLink *inlink) { FadeContext *s = inlink->dst->priv; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format); s->hsub = pixdesc->log2_chroma_w; s->vsub = pixdesc->log2_chroma_h; s->bpp = av_get_bits_per_pixel(pixdesc) >> 3; s->alpha &= !!(pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA); s->is_packed_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0; /* use CCIR601/709 black level for studio-level pixel non-alpha components */ s->black_level = ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !s->alpha ? 16 : 0; /* 32768 = 1 << 15, it is an integer representation * of 0.5 and is for rounding. */ s->black_level_scaled = (s->black_level << 16) + 32768; return 0; }
13,998
qemu
0af7a37054310384e00209e0a43efe95b7c19ef0
1
static void gen_msa(CPUMIPSState *env, DisasContext *ctx) { uint32_t opcode = ctx->opcode; check_insn(ctx, ASE_MSA); check_msa_access(ctx); switch (MASK_MSA_MINOR(opcode)) { case OPC_MSA_I8_00: case OPC_MSA_I8_01: case OPC_MSA_I8_02: gen_msa_i8(env, ctx); break; case OPC_MSA_I5_06: case OPC_MSA_I5_07: gen_msa_i5(env, ctx); break; case OPC_MSA_BIT_09: case OPC_MSA_BIT_0A: gen_msa_bit(env, ctx); break; case OPC_MSA_3R_0D: case OPC_MSA_3R_0E: case OPC_MSA_3R_0F: case OPC_MSA_3R_10: case OPC_MSA_3R_11: case OPC_MSA_3R_12: case OPC_MSA_3R_13: case OPC_MSA_3R_14: case OPC_MSA_3R_15: gen_msa_3r(env, ctx); break; case OPC_MSA_ELM: gen_msa_elm(env, ctx); break; case OPC_MSA_3RF_1A: case OPC_MSA_3RF_1B: case OPC_MSA_3RF_1C: gen_msa_3rf(env, ctx); break; case OPC_MSA_VEC: gen_msa_vec(env, ctx); break; case OPC_LD_B: case OPC_LD_H: case OPC_LD_W: case OPC_LD_D: case OPC_ST_B: case OPC_ST_H: case OPC_ST_W: case OPC_ST_D: { int32_t s10 = sextract32(ctx->opcode, 16, 10); uint8_t rs = (ctx->opcode >> 11) & 0x1f; uint8_t wd = (ctx->opcode >> 6) & 0x1f; uint8_t df = (ctx->opcode >> 0) & 0x3; TCGv_i32 tdf = tcg_const_i32(df); TCGv_i32 twd = tcg_const_i32(wd); TCGv_i32 trs = tcg_const_i32(rs); TCGv_i32 ts10 = tcg_const_i32(s10); switch (MASK_MSA_MINOR(opcode)) { case OPC_LD_B: case OPC_LD_H: case OPC_LD_W: case OPC_LD_D: gen_helper_msa_ld_df(cpu_env, tdf, twd, trs, ts10); break; case OPC_ST_B: case OPC_ST_H: case OPC_ST_W: case OPC_ST_D: gen_helper_msa_st_df(cpu_env, tdf, twd, trs, ts10); break; } tcg_temp_free_i32(twd); tcg_temp_free_i32(tdf); tcg_temp_free_i32(trs); tcg_temp_free_i32(ts10); } break; default: MIPS_INVAL("MSA instruction"); generate_exception(ctx, EXCP_RI); break; } }
13,999
qemu
b9c600d20716b3d942cb07188ff998fb236a8365
1
static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb) { BDRVQuorumState *s = acb->common.bs->opaque; acb->qcrs[acb->child_iter].buf = qemu_blockalign(s->children[acb->child_iter]->bs, acb->qiov->size); qemu_iovec_init(&acb->qcrs[acb->child_iter].qiov, acb->qiov->niov); qemu_iovec_clone(&acb->qcrs[acb->child_iter].qiov, acb->qiov, acb->qcrs[acb->child_iter].buf); bdrv_aio_readv(s->children[acb->child_iter]->bs, acb->sector_num, &acb->qcrs[acb->child_iter].qiov, acb->nb_sectors, quorum_aio_cb, &acb->qcrs[acb->child_iter]); return &acb->common; }
14,000
qemu
65207c59d99f2260c5f1d3b9c491146616a522aa
1
static void qmp_monitor_complete(void *opaque, QObject *ret_data) { monitor_protocol_emitter(opaque, ret_data); }
14,002
FFmpeg
5260edee7e5bd975837696c8c8c1a80eb2fbd7c1
1
static int old_codec37(SANMVideoContext *ctx, int top, int left, int width, int height) { int stride = ctx->pitch; int i, j, k, t; int skip_run = 0; int compr, mvoff, seq, flags; uint32_t decoded_size; uint8_t *dst, *prev; compr = bytestream2_get_byte(&ctx->gb); mvoff = bytestream2_get_byte(&ctx->gb); seq = bytestream2_get_le16(&ctx->gb); decoded_size = bytestream2_get_le32(&ctx->gb); bytestream2_skip(&ctx->gb, 4); flags = bytestream2_get_byte(&ctx->gb); bytestream2_skip(&ctx->gb, 3); if (decoded_size > height * stride - left - top * stride) { decoded_size = height * stride - left - top * stride; av_log(ctx->avctx, AV_LOG_WARNING, "decoded size is too large\n"); } ctx->rotate_code = 0; if (((seq & 1) || !(flags & 1)) && (compr && compr != 2)) rotate_bufs(ctx, 1); dst = ((uint8_t*)ctx->frm0) + left + top * stride; prev = ((uint8_t*)ctx->frm2) + left + top * stride; if (mvoff > 2) { av_log(ctx->avctx, AV_LOG_ERROR, "invalid motion base value %d\n", mvoff); return AVERROR_INVALIDDATA; } av_dlog(ctx->avctx, "compression %d\n", compr); switch (compr) { case 0: for (i = 0; i < height; i++) { bytestream2_get_buffer(&ctx->gb, dst, width); dst += stride; } memset(ctx->frm1, 0, ctx->height * stride); memset(ctx->frm2, 0, ctx->height * stride); break; case 2: if (rle_decode(ctx, dst, decoded_size)) return AVERROR_INVALIDDATA; memset(ctx->frm1, 0, ctx->frm1_size); memset(ctx->frm2, 0, ctx->frm2_size); break; case 3: case 4: if (flags & 4) { for (j = 0; j < height; j += 4) { for (i = 0; i < width; i += 4) { int code; if (skip_run) { skip_run--; copy_block4(dst + i, prev + i, stride, stride, 4); continue; } if (bytestream2_get_bytes_left(&ctx->gb) < 1) return AVERROR_INVALIDDATA; code = bytestream2_get_byteu(&ctx->gb); switch (code) { case 0xFF: if (bytestream2_get_bytes_left(&ctx->gb) < 16) return AVERROR_INVALIDDATA; for (k = 0; k < 4; k++) bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4); break; case 0xFE: if (bytestream2_get_bytes_left(&ctx->gb) < 4) return AVERROR_INVALIDDATA; for (k = 0; k < 4; k++) memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->gb), 4); break; case 0xFD: if (bytestream2_get_bytes_left(&ctx->gb) < 1) return AVERROR_INVALIDDATA; t = bytestream2_get_byteu(&ctx->gb); for (k = 0; k < 4; k++) memset(dst + i + k * stride, t, 4); break; default: if (compr == 4 && !code) { if (bytestream2_get_bytes_left(&ctx->gb) < 1) return AVERROR_INVALIDDATA; skip_run = bytestream2_get_byteu(&ctx->gb) + 1; i -= 4; } else { int mx, my; mx = c37_mv[(mvoff * 255 + code) * 2 ]; my = c37_mv[(mvoff * 255 + code) * 2 + 1]; codec37_mv(dst + i, prev + i + mx + my * stride, ctx->height, stride, i + mx, j + my); } } } dst += stride * 4; prev += stride * 4; } } else { for (j = 0; j < height; j += 4) { for (i = 0; i < width; i += 4) { int code; if (skip_run) { skip_run--; copy_block4(dst + i, prev + i, stride, stride, 4); continue; } code = bytestream2_get_byte(&ctx->gb); if (code == 0xFF) { if (bytestream2_get_bytes_left(&ctx->gb) < 16) return AVERROR_INVALIDDATA; for (k = 0; k < 4; k++) bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4); } else if (compr == 4 && !code) { if (bytestream2_get_bytes_left(&ctx->gb) < 1) return AVERROR_INVALIDDATA; skip_run = bytestream2_get_byteu(&ctx->gb) + 1; i -= 4; } else { int mx, my; mx = c37_mv[(mvoff * 255 + code) * 2]; my = c37_mv[(mvoff * 255 + code) * 2 + 1]; codec37_mv(dst + i, prev + i + mx + my * stride, ctx->height, stride, i + mx, j + my); } } dst += stride * 4; prev += stride * 4; } } break; default: av_log(ctx->avctx, AV_LOG_ERROR, "subcodec 37 compression %d not implemented\n", compr); return AVERROR_PATCHWELCOME; } return 0; }
14,003
qemu
4652b8f3e1ec91bb9d6f00e40df7f96d1f1aafee
1
static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix, bool *rebuild, void **refcount_table, int64_t *nb_clusters) { BDRVQcow2State *s = bs->opaque; int64_t i; QCowSnapshot *sn; int ret; if (!*refcount_table) { int64_t old_size = 0; ret = realloc_refcount_array(s, refcount_table, &old_size, *nb_clusters); res->check_errors++; /* header */ 0, s->cluster_size); /* current L1 table */ ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO); /* snapshots */ for (i = 0; i < s->nb_snapshots; i++) { sn = s->snapshots + i; ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, sn->l1_table_offset, sn->l1_size, 0); s->snapshots_offset, s->snapshots_size); /* refcount data */ s->refcount_table_offset, s->refcount_table_size * sizeof(uint64_t)); return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clusters);
14,004
FFmpeg
2469ed32c81ebf2347e6883091c566724b286167
1
static uint64_t calc_rice_params(RiceContext *rc, uint32_t udata[FLAC_MAX_BLOCKSIZE], uint64_t sums[32][MAX_PARTITIONS], int pmin, int pmax, const int32_t *data, int n, int pred_order, int exact) { int i; uint64_t bits[MAX_PARTITION_ORDER+1]; int opt_porder; RiceContext tmp_rc; int kmax = (1 << rc->coding_mode) - 2; av_assert1(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); av_assert1(pmax >= 0 && pmax <= MAX_PARTITION_ORDER); av_assert1(pmin <= pmax); tmp_rc.coding_mode = rc->coding_mode; for (i = 0; i < n; i++) udata[i] = (2 * data[i]) ^ (data[i] >> 31); calc_sum_top(pmax, exact ? kmax : 0, udata, n, pred_order, sums); opt_porder = pmin; bits[pmin] = UINT32_MAX; for (i = pmax; ; ) { bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums, n, pred_order, kmax, exact); if (bits[i] < bits[opt_porder]) { opt_porder = i; *rc = tmp_rc; } if (i == pmin) break; calc_sum_next(--i, sums, exact ? kmax : 0); } return bits[opt_porder]; }
14,005
qemu
cdcab9d94101a6dd9ac8136c6f2cd15b6a997896
1
static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp) { MemoryRegion *mr = host_memory_backend_get_memory(dimm->hostmem, errp); NVDIMMDevice *nvdimm = NVDIMM(dimm); uint64_t align, pmem_size, size = memory_region_size(mr); align = memory_region_get_alignment(mr); pmem_size = size - nvdimm->label_size; nvdimm->label_data = memory_region_get_ram_ptr(mr) + pmem_size; pmem_size = QEMU_ALIGN_DOWN(pmem_size, align); if (size <= nvdimm->label_size || !pmem_size) { HostMemoryBackend *hostmem = dimm->hostmem; char *path = object_get_canonical_path_component(OBJECT(hostmem)); error_setg(errp, "the size of memdev %s (0x%" PRIx64 ") is too " "small to contain nvdimm label (0x%" PRIx64 ") and " "aligned PMEM (0x%" PRIx64 ")", path, memory_region_size(mr), nvdimm->label_size, align); return; } memory_region_init_alias(&nvdimm->nvdimm_mr, OBJECT(dimm), "nvdimm-memory", mr, 0, pmem_size); nvdimm->nvdimm_mr.align = align; }
14,006
FFmpeg
e8876902a9021ec185ca785653067dd34f24c5ce
1
ReSampleContext *av_audio_resample_init(int output_channels, int input_channels, int output_rate, int input_rate, enum AVSampleFormat sample_fmt_out, enum AVSampleFormat sample_fmt_in, int filter_length, int log2_phase_count, int linear, double cutoff) { ReSampleContext *s; if (input_channels > MAX_CHANNELS) { av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than %d is unsupported.\n", MAX_CHANNELS); return NULL; } if (output_channels > 2 && !(output_channels == 6 && input_channels == 2) && output_channels != input_channels) { av_log(NULL, AV_LOG_ERROR, "Resampling output channel count must be 1 or 2 for mono input; 1, 2 or 6 for stereo input; or N for N channel input.\n"); return NULL; } s = av_mallocz(sizeof(ReSampleContext)); if (!s) { av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context.\n"); return NULL; } s->ratio = (float)output_rate / (float)input_rate; s->input_channels = input_channels; s->output_channels = output_channels; s->filter_channels = s->input_channels; if (s->output_channels < s->filter_channels) s->filter_channels = s->output_channels; s->sample_fmt[0] = sample_fmt_in; s->sample_fmt[1] = sample_fmt_out; s->sample_size[0] = av_get_bits_per_sample_fmt(s->sample_fmt[0]) >> 3; s->sample_size[1] = av_get_bits_per_sample_fmt(s->sample_fmt[1]) >> 3; if (s->sample_fmt[0] != AV_SAMPLE_FMT_S16) { if (!(s->convert_ctx[0] = av_audio_convert_alloc(AV_SAMPLE_FMT_S16, 1, s->sample_fmt[0], 1, NULL, 0))) { av_log(s, AV_LOG_ERROR, "Cannot convert %s sample format to s16 sample format\n", av_get_sample_fmt_name(s->sample_fmt[0])); av_free(s); return NULL; } } if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) { if (!(s->convert_ctx[1] = av_audio_convert_alloc(s->sample_fmt[1], 1, AV_SAMPLE_FMT_S16, 1, NULL, 0))) { av_log(s, AV_LOG_ERROR, "Cannot convert s16 sample format to %s sample format\n", av_get_sample_fmt_name(s->sample_fmt[1])); av_audio_convert_free(s->convert_ctx[0]); av_free(s); return NULL; } } #define TAPS 16 s->resample_context = av_resample_init(output_rate, input_rate, filter_length, log2_phase_count, linear, cutoff); *(const AVClass**)s->resample_context = &audioresample_context_class; return s; }
14,007
qemu
e3cffe6fad29e07d401eabb913a6d88501d5c143
1
static void gen_sync(DisasContext *ctx) { uint32_t l = (ctx->opcode >> 21) & 3; /* * We may need to check for a pending TLB flush. * * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32. * * Additionally, this can only happen in kernel mode however so * check MSR_PR as well. */ if (((l == 2) || !(ctx->insns_flags & PPC_64B)) && !ctx->pr) { gen_check_tlb_flush(ctx); } }
14,008
qemu
83e33300a2342c5d0bf48474fdf8da22c22b4973
1
static int qcrypto_ivgen_essiv_calculate(QCryptoIVGen *ivgen, uint64_t sector, uint8_t *iv, size_t niv, Error **errp) { QCryptoIVGenESSIV *essiv = ivgen->private; size_t ndata = qcrypto_cipher_get_block_len(ivgen->cipher); uint8_t *data = g_new(uint8_t, ndata); sector = cpu_to_le64(sector); memcpy(data, (uint8_t *)&sector, ndata); if (sizeof(sector) < ndata) { memset(data + sizeof(sector), 0, ndata - sizeof(sector)); } if (qcrypto_cipher_encrypt(essiv->cipher, data, data, ndata, errp) < 0) { g_free(data); return -1; } if (ndata > niv) { ndata = niv; } memcpy(iv, data, ndata); if (ndata < niv) { memset(iv + ndata, 0, niv - ndata); } g_free(data); return 0; }
14,009
FFmpeg
56c182c4d716b8b72156ff57a0c8d72087db8549
1
void ff_nut_free_sp(NUTContext *nut) { av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free); av_tree_destroy(nut->syncpoints); }
14,010
qemu
cc05c43ad942165ecc6ffd39e41991bee43af044
1
static void memory_region_oldmmio_write_accessor(MemoryRegion *mr, hwaddr addr, uint64_t *value, unsigned size, unsigned shift, uint64_t mask) { uint64_t tmp; tmp = (*value >> shift) & mask; trace_memory_region_ops_write(mr, addr, tmp, size); mr->ops->old_mmio.write[ctz32(size)](mr->opaque, addr, tmp); }
14,011
qemu
381b634c275ca1a2806e97392527bbfc01bcb333
1
static void scsi_cmd_xfer_mode(SCSICommand *cmd) { if (!cmd->xfer) { cmd->mode = SCSI_XFER_NONE; return; } switch (cmd->buf[0]) { case WRITE_6: case WRITE_10: case WRITE_VERIFY_10: case WRITE_12: case WRITE_VERIFY_12: case WRITE_16: case WRITE_VERIFY_16: case COPY: case COPY_VERIFY: case COMPARE: case CHANGE_DEFINITION: case LOG_SELECT: case MODE_SELECT: case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER: case FORMAT_UNIT: case REASSIGN_BLOCKS: case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW: case UPDATE_BLOCK: case WRITE_LONG_10: case WRITE_SAME_10: case WRITE_SAME_16: case UNMAP: case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12: case MEDIUM_SCAN: case SEND_VOLUME_TAG: case SEND_CUE_SHEET: case SEND_DVD_STRUCTURE: case PERSISTENT_RESERVE_OUT: case MAINTENANCE_OUT: cmd->mode = SCSI_XFER_TO_DEV; break; default: cmd->mode = SCSI_XFER_FROM_DEV; break; } }
14,012
qemu
544a3731591f5d53e15f22de00ce5ac758d490b3
1
static void test_visitor_in_union_flat(TestInputVisitorData *data, const void *unused) { Visitor *v; UserDefFlatUnion *tmp; UserDefUnionBase *base; v = visitor_input_test_init(data, "{ 'enum1': 'value1', " "'integer': 41, " "'string': 'str', " "'boolean': true }"); visit_type_UserDefFlatUnion(v, NULL, &tmp, &error_abort); g_assert_cmpint(tmp->enum1, ==, ENUM_ONE_VALUE1); g_assert_cmpstr(tmp->string, ==, "str"); g_assert_cmpint(tmp->integer, ==, 41); g_assert_cmpint(tmp->u.value1->boolean, ==, true); base = qapi_UserDefFlatUnion_base(tmp); g_assert(&base->enum1 == &tmp->enum1); qapi_free_UserDefFlatUnion(tmp); }
14,013
FFmpeg
1c31b26bdf66879a46a7a3e340da815c1b2125a8
1
static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) { AVIOContext *pb = s->pb; APEContext *ape = s->priv_data; AVStream *st; uint32_t tag; int i; int total_blocks; int64_t pts; /* TODO: Skip any leading junk such as id3v2 tags */ ape->junklength = 0; tag = avio_rl32(pb); if (tag != MKTAG('M', 'A', 'C', ' ')) return -1; ape->fileversion = avio_rl16(pb); if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) { av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10); return -1; if (ape->fileversion >= 3980) { ape->padding1 = avio_rl16(pb); ape->descriptorlength = avio_rl32(pb); ape->headerlength = avio_rl32(pb); ape->seektablelength = avio_rl32(pb); ape->wavheaderlength = avio_rl32(pb); ape->audiodatalength = avio_rl32(pb); ape->audiodatalength_high = avio_rl32(pb); ape->wavtaillength = avio_rl32(pb); avio_read(pb, ape->md5, 16); /* Skip any unknown bytes at the end of the descriptor. This is for future compatibility */ if (ape->descriptorlength > 52) avio_seek(pb, ape->descriptorlength - 52, SEEK_CUR); /* Read header data */ ape->compressiontype = avio_rl16(pb); ape->formatflags = avio_rl16(pb); ape->blocksperframe = avio_rl32(pb); ape->finalframeblocks = avio_rl32(pb); ape->totalframes = avio_rl32(pb); ape->bps = avio_rl16(pb); ape->channels = avio_rl16(pb); ape->samplerate = avio_rl32(pb); } else { ape->descriptorlength = 0; ape->headerlength = 32; ape->compressiontype = avio_rl16(pb); ape->formatflags = avio_rl16(pb); ape->channels = avio_rl16(pb); ape->samplerate = avio_rl32(pb); ape->wavheaderlength = avio_rl32(pb); ape->wavtaillength = avio_rl32(pb); ape->totalframes = avio_rl32(pb); ape->finalframeblocks = avio_rl32(pb); if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) { avio_seek(pb, 4, SEEK_CUR); /* Skip the peak level */ ape->headerlength += 4; if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) { ape->seektablelength = avio_rl32(pb); ape->headerlength += 4; ape->seektablelength *= sizeof(int32_t); } else ape->seektablelength = ape->totalframes * sizeof(int32_t); if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT) ape->bps = 8; else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT) ape->bps = 24; else ape->bps = 16; if (ape->fileversion >= 3950) ape->blocksperframe = 73728 * 4; else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800 && ape->compressiontype >= 4000)) ape->blocksperframe = 73728; else ape->blocksperframe = 9216; /* Skip any stored wav header */ if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER)) avio_seek(pb, ape->wavheaderlength, SEEK_CUR); if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){ av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes); return -1; ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame)); if(!ape->frames) return AVERROR(ENOMEM); ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength; ape->currentframe = 0; ape->totalsamples = ape->finalframeblocks; if (ape->totalframes > 1) ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1); if (ape->seektablelength > 0) { ape->seektable = av_malloc(ape->seektablelength); for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++) ape->seektable[i] = avio_rl32(pb); ape->frames[0].pos = ape->firstframe; ape->frames[0].nblocks = ape->blocksperframe; ape->frames[0].skip = 0; for (i = 1; i < ape->totalframes; i++) { ape->frames[i].pos = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe; ape->frames[i].nblocks = ape->blocksperframe; ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; ape->frames[ape->totalframes - 1].size = ape->finalframeblocks * 4; ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks; for (i = 0; i < ape->totalframes; i++) { if(ape->frames[i].skip){ ape->frames[i].pos -= ape->frames[i].skip; ape->frames[i].size += ape->frames[i].skip; ape->frames[i].size = (ape->frames[i].size + 3) & ~3; ape_dumpinfo(s, ape); /* try to read APE tags */ if (!url_is_streamed(pb)) { ff_ape_parse_tag(s); avio_seek(pb, 0, SEEK_SET); av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ape->compressiontype); /* now we are ready: build format streams */ st = av_new_stream(s, 0); if (!st) return -1; total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_APE; st->codec->codec_tag = MKTAG('A', 'P', 'E', ' '); st->codec->channels = ape->channels; st->codec->sample_rate = ape->samplerate; st->codec->bits_per_coded_sample = ape->bps; st->codec->frame_size = MAC_SUBFRAME_SIZE; st->nb_frames = ape->totalframes; st->start_time = 0; st->duration = total_blocks / MAC_SUBFRAME_SIZE; av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); st->codec->extradata_size = APE_EXTRADATA_SIZE; AV_WL16(st->codec->extradata + 0, ape->fileversion); AV_WL16(st->codec->extradata + 2, ape->compressiontype); AV_WL16(st->codec->extradata + 4, ape->formatflags); pts = 0; for (i = 0; i < ape->totalframes; i++) { ape->frames[i].pts = pts; av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME); pts += ape->blocksperframe / MAC_SUBFRAME_SIZE; return 0;
14,015
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int buf_close(void *opaque) { QEMUBuffer *s = opaque; qsb_free(s->qsb); g_free(s); return 0; }
14,016
FFmpeg
936751b6527cff789ef077a4e43a04ae9e658232
1
static const struct URLProtocol *url_find_protocol(const char *filename) { const URLProtocol **protocols; char proto_str[128], proto_nested[128], *ptr; size_t proto_len = strspn(filename, URL_SCHEME_CHARS); int i; if (filename[proto_len] != ':' && (strncmp(filename, "subfile,", 8) || !strchr(filename + proto_len + 1, ':')) || is_dos_path(filename)) strcpy(proto_str, "file"); else av_strlcpy(proto_str, filename, FFMIN(proto_len + 1, sizeof(proto_str))); if ((ptr = strchr(proto_str, ','))) *ptr = '\0'; av_strlcpy(proto_nested, proto_str, sizeof(proto_nested)); if ((ptr = strchr(proto_nested, '+'))) *ptr = '\0'; protocols = ffurl_get_protocols(NULL, NULL); for (i = 0; protocols[i]; i++) { const URLProtocol *up = protocols[i]; if (!strcmp(proto_str, up->name)) { av_freep(&protocols); return up; } if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME && !strcmp(proto_nested, up->name)) { av_freep(&protocols); return up; } } av_freep(&protocols); }
14,017
qemu
fc6467eaf22f974620b5dd046afca04e619f9be9
1
void qmp_nbd_server_stop(Error **errp) { while (!QTAILQ_EMPTY(&close_notifiers)) { NBDCloseNotifier *cn = QTAILQ_FIRST(&close_notifiers); nbd_close_notifier(&cn->n, nbd_export_get_blockdev(cn->exp)); } qemu_set_fd_handler2(server_fd, NULL, NULL, NULL, NULL); close(server_fd); server_fd = -1; }
14,018
qemu
062ba099e01ff1474be98c0a4f3da351efab5d9d
1
int arm_reset_cpu(uint64_t cpuid) { CPUState *target_cpu_state; ARMCPU *target_cpu; DPRINTF("cpu %" PRId64 "\n", cpuid); /* change to the cpu we are resetting */ target_cpu_state = arm_get_cpu_by_id(cpuid); if (!target_cpu_state) { return QEMU_ARM_POWERCTL_INVALID_PARAM; } target_cpu = ARM_CPU(target_cpu_state); if (target_cpu->powered_off) { qemu_log_mask(LOG_GUEST_ERROR, "[ARM]%s: CPU %" PRId64 " is off\n", __func__, cpuid); return QEMU_ARM_POWERCTL_IS_OFF; } /* Reset the cpu */ cpu_reset(target_cpu_state); return QEMU_ARM_POWERCTL_RET_SUCCESS; }
14,019
FFmpeg
43cd33be16b21b9a217025e208f4ffbf0bf81da4
1
static void postprocess_chroma(AVFrame *frame, int w, int h, int depth) { uint16_t *dstu = (uint16_t *)frame->data[1]; uint16_t *dstv = (uint16_t *)frame->data[2]; int16_t *srcu = (int16_t *)frame->data[1]; int16_t *srcv = (int16_t *)frame->data[2]; ptrdiff_t strideu = frame->linesize[1] / 2; ptrdiff_t stridev = frame->linesize[2] / 2; const int add = 1 << (depth - 1); const int shift = 16 - depth; int i, j; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { dstu[i] = (add + srcu[i]) << shift; dstv[i] = (add + srcv[i]) << shift; } dstu += strideu; dstv += stridev; srcu += strideu; srcv += stridev; } }
14,020
FFmpeg
af4cc2605c7a56ecfd84c264aa2b325020418472
0
static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta) { int isv34, tlen, unsync; char tag[5]; int64_t next, end = avio_tell(s->pb) + len; int taghdrlen; const char *reason = NULL; AVIOContext pb; AVIOContext *pbx; unsigned char *buffer = NULL; int buffer_size = 0; const ID3v2EMFunc *extra_func; switch (version) { case 2: if (flags & 0x40) { reason = "compression"; goto error; } isv34 = 0; taghdrlen = 6; break; case 3: case 4: isv34 = 1; taghdrlen = 10; break; default: reason = "version"; goto error; } unsync = flags & 0x80; if (isv34 && flags & 0x40) { /* Extended header present, just skip over it */ int extlen = get_size(s->pb, 4); if (version == 4) /* In v2.4 the length includes the length field we just read. */ extlen -= 4; if (extlen < 0) { reason = "invalid extended header length"; goto error; } avio_skip(s->pb, extlen); } while (len >= taghdrlen) { unsigned int tflags = 0; int tunsync = 0; if (isv34) { avio_read(s->pb, tag, 4); tag[4] = 0; if (version == 3) { tlen = avio_rb32(s->pb); } else tlen = get_size(s->pb, 4); tflags = avio_rb16(s->pb); tunsync = tflags & ID3v2_FLAG_UNSYNCH; } else { avio_read(s->pb, tag, 3); tag[3] = 0; tlen = avio_rb24(s->pb); } if (tlen < 0 || tlen > len - taghdrlen) { av_log(s, AV_LOG_WARNING, "Invalid size in frame %s, skipping the rest of tag.\n", tag); break; } len -= taghdrlen + tlen; next = avio_tell(s->pb) + tlen; if (!tlen) { if (tag[0]) av_log(s, AV_LOG_DEBUG, "Invalid empty frame %s, skipping.\n", tag); continue; } if (tflags & ID3v2_FLAG_DATALEN) { avio_rb32(s->pb); tlen -= 4; } if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) { av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag); avio_skip(s->pb, tlen); /* check for text tag or supported special meta tag */ } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) { if (unsync || tunsync) { int64_t end = avio_tell(s->pb) + tlen; uint8_t *b; av_fast_malloc(&buffer, &buffer_size, tlen); if (!buffer) { av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen); goto seek; } b = buffer; while (avio_tell(s->pb) < end) { *b++ = avio_r8(s->pb); if (*(b - 1) == 0xff && avio_tell(s->pb) < end - 1) { uint8_t val = avio_r8(s->pb); *b++ = val ? val : avio_r8(s->pb); } } ffio_init_context(&pb, buffer, b - buffer, 0, NULL, NULL, NULL, NULL); tlen = b - buffer; pbx = &pb; // read from sync buffer } else { pbx = s->pb; // read straight from input } if (tag[0] == 'T') /* parse text tag */ read_ttag(s, pbx, tlen, tag); else /* parse special meta tag */ extra_func->read(s, pbx, tlen, tag, extra_meta); } else if (!tag[0]) { if (tag[1]) av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding"); avio_skip(s->pb, tlen); break; } /* Skip to end of tag */ seek: avio_seek(s->pb, next, SEEK_SET); } /* Footer preset, always 10 bytes, skip over it */ if (version == 4 && flags & 0x10) end += 10; error: if (reason) av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); avio_seek(s->pb, end, SEEK_SET); av_free(buffer); return; }
14,021
qemu
ef5b234477df80700b128f561f5877a0688a70c8
1
static int ehci_state_fetchqtd(EHCIQueue *q) { EHCIqtd qtd; EHCIPacket *p; int again = 0; get_dwords(q->ehci, NLPTR_GET(q->qtdaddr), (uint32_t *) &qtd, sizeof(EHCIqtd) >> 2); ehci_trace_qtd(q, NLPTR_GET(q->qtdaddr), &qtd); p = QTAILQ_FIRST(&q->packets); if (p != NULL) { if (p->qtdaddr != q->qtdaddr || (!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) || (!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) || p->qtd.bufptr[0] != qtd.bufptr[0]) { ehci_cancel_queue(q); ehci_trace_guest_bug(q->ehci, "guest updated active QH or qTD"); p = NULL; } else { p->qtd = qtd; ehci_qh_do_overlay(q); } } if (!(qtd.token & QTD_TOKEN_ACTIVE)) { if (p != NULL) { /* transfer canceled by guest (clear active) */ ehci_cancel_queue(q); p = NULL; } ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH); again = 1; } else if (p != NULL) { switch (p->async) { case EHCI_ASYNC_NONE: /* Previously nacked packet (likely interrupt ep) */ ehci_set_state(q->ehci, q->async, EST_EXECUTE); break; case EHCI_ASYNC_INFLIGHT: /* Unfinyshed async handled packet, go horizontal */ ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH); break; case EHCI_ASYNC_FINISHED: /* Should never happen, as this case is caught by fetchqh */ ehci_set_state(q->ehci, q->async, EST_EXECUTING); break; } again = 1; } else { p = ehci_alloc_packet(q); p->qtdaddr = q->qtdaddr; p->qtd = qtd; ehci_set_state(q->ehci, q->async, EST_EXECUTE); again = 1; } return again; }
14,026
FFmpeg
3728603f1854b5c79d1a64dd3b41b80640ef1e7f
0
static av_always_inline int encode_line(FFV1Context *s, int w, int16_t *sample[3], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; int x; int run_index = s->run_index; int run_count = 0; int run_mode = 0; if (s->ac) { if (c->bytestream_end - c->bytestream < w * 20) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } else { if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } for (x = 0; x < w; x++) { int diff, context; context = get_context(p, sample[0] + x, sample[1] + x, sample[2] + x); diff = sample[0][x] - predict(sample[0] + x, sample[1] + x); if (context < 0) { context = -context; diff = -diff; } diff = fold(diff, bits); if (s->ac) { if (s->flags & CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat, s->rc_stat2[p->quant_table_index][context]); } else { put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL); } } else { if (context == 0) run_mode = 1; if (run_mode) { if (diff) { while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; put_bits(&s->pb, 1, 1); } put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count); if (run_index) run_index--; run_count = 0; run_mode = 0; if (diff > 0) diff--; } else { run_count++; } } av_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, (int)put_bits_count(&s->pb)); if (run_mode == 0) put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits); } } if (run_mode) { while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; put_bits(&s->pb, 1, 1); } if (run_count) put_bits(&s->pb, 1, 1); } s->run_index = run_index; return 0; }
14,028
FFmpeg
37ec7d291eacedfacdce21332f4c719f2be79d12
1
static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { struct Mp4vParseContext *pc = s1->priv_data; Mpeg4DecContext *dec_ctx = &pc->dec_ctx; MpegEncContext *s = &dec_ctx->m; GetBitContext gb1, *gb = &gb1; int ret; s->avctx = avctx; s->current_picture_ptr = &s->current_picture; if (avctx->extradata_size && pc->first_picture) { init_get_bits(gb, avctx->extradata, avctx->extradata_size * 8); ret = ff_mpeg4_decode_picture_header(dec_ctx, gb); } init_get_bits(gb, buf, 8 * buf_size); ret = ff_mpeg4_decode_picture_header(dec_ctx, gb); if (s->width && (!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height)) { ret = ff_set_dimensions(avctx, s->width, s->height); return ret; } if((s1->flags & PARSER_FLAG_USE_CODEC_TS) && s->avctx->time_base.den>0 && ret>=0){ av_assert1(s1->pts == AV_NOPTS_VALUE); av_assert1(s1->dts == AV_NOPTS_VALUE); s1->pts = av_rescale_q(s->time, (AVRational){1, s->avctx->time_base.den}, (AVRational){1, 1200000}); } s1->pict_type = s->pict_type; pc->first_picture = 0; return ret; }
14,029
qemu
3e305e4a4752f70c0b5c3cf5b43ec957881714f7
1
void vnc_tls_client_cleanup(VncState *vs) { if (vs->tls.session) { gnutls_deinit(vs->tls.session); vs->tls.session = NULL; } g_free(vs->tls.dname); }
14,032
qemu
9d2db3760be9e32414e22889e3e2bffdf4898f32
1
void colo_do_failover(MigrationState *s) { /* Make sure VM stopped while failover happened. */ if (!colo_runstate_is_stopped()) { vm_stop_force_state(RUN_STATE_COLO); } if (get_colo_mode() == COLO_MODE_PRIMARY) { primary_vm_do_failover(); } }
14,033
qemu
441cbac0c7e641780decbc674a9a68c6a5200f71
1
static void test_validate_union_flat(TestInputVisitorData *data, const void *unused) { UserDefFlatUnion *tmp = NULL; Visitor *v; Error *err = NULL; v = validate_test_init(data, "{ 'enum1': 'value1', " "'string': 'str', " "'boolean': true }"); /* TODO when generator bug is fixed, add 'integer': 41 */ visit_type_UserDefFlatUnion(v, &tmp, NULL, &err); g_assert(!err); qapi_free_UserDefFlatUnion(tmp); }
14,035
FFmpeg
6e42e6c4b410dbef8b593c2d796a5dad95f89ee4
1
static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, long width, long height, long lumStride, long chromStride, long dstStride, long vertLumPerChroma) { long y; const long chromWidth= width>>1; for(y=0; y<height; y++) { #ifdef HAVE_MMX //FIXME handle 2 lines a once (fewer prefetch, reuse some chrom, but very likely limited by mem anyway) asm volatile( "xor %%"REG_a", %%"REG_a" \n\t" ASMALIGN(4) "1: \n\t" PREFETCH" 32(%1, %%"REG_a", 2) \n\t" PREFETCH" 32(%2, %%"REG_a") \n\t" PREFETCH" 32(%3, %%"REG_a") \n\t" "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0) "movq %%mm0, %%mm2 \n\t" // U(0) "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0) "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0) "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8) "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0) "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8) "movq %%mm0, %%mm4 \n\t" // Y(0) "movq %%mm2, %%mm6 \n\t" // Y(8) "punpcklbw %%mm3, %%mm0 \n\t" // YUYV YUYV(0) "punpckhbw %%mm3, %%mm4 \n\t" // YUYV YUYV(4) "punpcklbw %%mm5, %%mm2 \n\t" // YUYV YUYV(8) "punpckhbw %%mm5, %%mm6 \n\t" // YUYV YUYV(12) MOVNTQ" %%mm0, (%0, %%"REG_a", 4)\n\t" MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4)\n\t" MOVNTQ" %%mm2, 16(%0, %%"REG_a", 4)\n\t" MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4)\n\t" "add $8, %%"REG_a" \n\t" "cmp %4, %%"REG_a" \n\t" " jb 1b \n\t" ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth) : "%"REG_a ); #else //FIXME adapt the alpha asm code from yv12->yuy2 #if __WORDSIZE >= 64 int i; uint64_t *ldst = (uint64_t *) dst; const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; for(i = 0; i < chromWidth; i += 2){ uint64_t k, l; k = uc[0] + (yc[0] << 8) + (vc[0] << 16) + (yc[1] << 24); l = uc[1] + (yc[2] << 8) + (vc[1] << 16) + (yc[3] << 24); *ldst++ = k + (l << 32); yc += 4; uc += 2; vc += 2; } #else int i, *idst = (int32_t *) dst; const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; for(i = 0; i < chromWidth; i++){ #ifdef WORDS_BIGENDIAN *idst++ = (uc[0] << 24)+ (yc[0] << 16) + (vc[0] << 8) + (yc[1] << 0); #else *idst++ = uc[0] + (yc[0] << 8) + (vc[0] << 16) + (yc[1] << 24); #endif yc += 2; uc++; vc++; } #endif #endif if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) { usrc += chromStride; vsrc += chromStride; } ysrc += lumStride; dst += dstStride; } #ifdef HAVE_MMX asm( EMMS" \n\t" SFENCE" \n\t" :::"memory"); #endif }
14,036
qemu
4118a97030aa9bd1d520d1d06bbe0655d829df04
1
int target_munmap(target_ulong start, target_ulong len) { target_ulong end, real_start, real_end, addr; int prot, ret; #ifdef DEBUG_MMAP printf("munmap: start=0x%lx len=0x%lx\n", start, len); #endif if (start & ~TARGET_PAGE_MASK) return -EINVAL; len = TARGET_PAGE_ALIGN(len); if (len == 0) return -EINVAL; end = start + len; real_start = start & qemu_host_page_mask; real_end = HOST_PAGE_ALIGN(end); if (start > real_start) { /* handle host page containing start */ prot = 0; for(addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } if (real_end == real_start + qemu_host_page_size) { for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } end = real_end; } if (prot != 0) real_start += qemu_host_page_size; } if (end < real_end) { prot = 0; for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } if (prot != 0) real_end -= qemu_host_page_size; } /* unmap what we can */ if (real_start < real_end) { ret = munmap((void *)real_start, real_end - real_start); if (ret != 0) return ret; } page_set_flags(start, start + len, 0); return 0; }
14,037
qemu
0d10193870b5a81c3bce13a602a5403c3a55cf6c
1
int cpu_exec(CPUState *env) { int ret, interrupt_request; TranslationBlock *tb; uint8_t *tc_ptr; unsigned long next_tb; if (env->halted) { if (!cpu_has_work(env)) { return EXCP_HALTED; } env->halted = 0; } cpu_single_env = env; if (unlikely(exit_request)) { env->exit_request = 1; } #if defined(TARGET_I386) /* put eflags in CPU temporary format */ CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); DF = 1 - (2 * ((env->eflags >> 10) & 1)); CC_OP = CC_OP_EFLAGS; env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); #elif defined(TARGET_SPARC) #elif defined(TARGET_M68K) env->cc_op = CC_OP_FLAGS; env->cc_dest = env->sr & 0xf; env->cc_x = (env->sr >> 4) & 1; #elif defined(TARGET_ALPHA) #elif defined(TARGET_ARM) #elif defined(TARGET_UNICORE32) #elif defined(TARGET_PPC) #elif defined(TARGET_LM32) #elif defined(TARGET_MICROBLAZE) #elif defined(TARGET_MIPS) #elif defined(TARGET_SH4) #elif defined(TARGET_CRIS) #elif defined(TARGET_S390X) /* XXXXX */ #else #error unsupported target CPU #endif env->exception_index = -1; /* prepare setjmp context for exception handling */ for(;;) { if (setjmp(env->jmp_env) == 0) { /* if an exception is pending, we execute it here */ if (env->exception_index >= 0) { if (env->exception_index >= EXCP_INTERRUPT) { /* exit request from the cpu execution loop */ ret = env->exception_index; if (ret == EXCP_DEBUG) { cpu_handle_debug_exception(env); } break; #if defined(CONFIG_USER_ONLY) /* if user mode only, we simulate a fake exception which will be handled outside the cpu execution loop */ #if defined(TARGET_I386) do_interrupt(env); #endif ret = env->exception_index; break; #else do_interrupt(env); env->exception_index = -1; #endif } } next_tb = 0; /* force lookup of first TB */ for(;;) { interrupt_request = env->interrupt_request; if (unlikely(interrupt_request)) { if (unlikely(env->singlestep_enabled & SSTEP_NOIRQ)) { /* Mask out external interrupts for this step. */ interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; } if (interrupt_request & CPU_INTERRUPT_DEBUG) { env->interrupt_request &= ~CPU_INTERRUPT_DEBUG; env->exception_index = EXCP_DEBUG; cpu_loop_exit(env); } #if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS) || \ defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) || \ defined(TARGET_MICROBLAZE) || defined(TARGET_LM32) || defined(TARGET_UNICORE32) if (interrupt_request & CPU_INTERRUPT_HALT) { env->interrupt_request &= ~CPU_INTERRUPT_HALT; env->halted = 1; env->exception_index = EXCP_HLT; cpu_loop_exit(env); } #endif #if defined(TARGET_I386) if (interrupt_request & CPU_INTERRUPT_INIT) { svm_check_intercept(env, SVM_EXIT_INIT); do_cpu_init(env); env->exception_index = EXCP_HALTED; cpu_loop_exit(env); } else if (interrupt_request & CPU_INTERRUPT_SIPI) { do_cpu_sipi(env); } else if (env->hflags2 & HF2_GIF_MASK) { if ((interrupt_request & CPU_INTERRUPT_SMI) && !(env->hflags & HF_SMM_MASK)) { svm_check_intercept(env, SVM_EXIT_SMI); env->interrupt_request &= ~CPU_INTERRUPT_SMI; do_smm_enter(env); next_tb = 0; } else if ((interrupt_request & CPU_INTERRUPT_NMI) && !(env->hflags2 & HF2_NMI_MASK)) { env->interrupt_request &= ~CPU_INTERRUPT_NMI; env->hflags2 |= HF2_NMI_MASK; do_interrupt_x86_hardirq(env, EXCP02_NMI, 1); next_tb = 0; } else if (interrupt_request & CPU_INTERRUPT_MCE) { env->interrupt_request &= ~CPU_INTERRUPT_MCE; do_interrupt_x86_hardirq(env, EXCP12_MCHK, 0); next_tb = 0; } else if ((interrupt_request & CPU_INTERRUPT_HARD) && (((env->hflags2 & HF2_VINTR_MASK) && (env->hflags2 & HF2_HIF_MASK)) || (!(env->hflags2 & HF2_VINTR_MASK) && (env->eflags & IF_MASK && !(env->hflags & HF_INHIBIT_IRQ_MASK))))) { int intno; svm_check_intercept(env, SVM_EXIT_INTR); env->interrupt_request &= ~(CPU_INTERRUPT_HARD | CPU_INTERRUPT_VIRQ); intno = cpu_get_pic_interrupt(env); qemu_log_mask(CPU_LOG_TB_IN_ASM, "Servicing hardware INT=0x%02x\n", intno); do_interrupt_x86_hardirq(env, intno, 1); /* ensure that no TB jump will be modified as the program flow was changed */ next_tb = 0; #if !defined(CONFIG_USER_ONLY) } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) && (env->eflags & IF_MASK) && !(env->hflags & HF_INHIBIT_IRQ_MASK)) { int intno; /* FIXME: this should respect TPR */ svm_check_intercept(env, SVM_EXIT_VINTR); intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector)); qemu_log_mask(CPU_LOG_TB_IN_ASM, "Servicing virtual hardware INT=0x%02x\n", intno); do_interrupt_x86_hardirq(env, intno, 1); env->interrupt_request &= ~CPU_INTERRUPT_VIRQ; next_tb = 0; #endif } } #elif defined(TARGET_PPC) #if 0 if ((interrupt_request & CPU_INTERRUPT_RESET)) { cpu_reset(env); } #endif if (interrupt_request & CPU_INTERRUPT_HARD) { ppc_hw_interrupt(env); if (env->pending_interrupts == 0) env->interrupt_request &= ~CPU_INTERRUPT_HARD; next_tb = 0; } #elif defined(TARGET_LM32) if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->ie & IE_IE)) { env->exception_index = EXCP_IRQ; do_interrupt(env); next_tb = 0; } #elif defined(TARGET_MICROBLAZE) if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->sregs[SR_MSR] & MSR_IE) && !(env->sregs[SR_MSR] & (MSR_EIP | MSR_BIP)) && !(env->iflags & (D_FLAG | IMM_FLAG))) { env->exception_index = EXCP_IRQ; do_interrupt(env); next_tb = 0; } #elif defined(TARGET_MIPS) if ((interrupt_request & CPU_INTERRUPT_HARD) && cpu_mips_hw_interrupts_pending(env)) { /* Raise it */ env->exception_index = EXCP_EXT_INTERRUPT; env->error_code = 0; do_interrupt(env); next_tb = 0; } #elif defined(TARGET_SPARC) if (interrupt_request & CPU_INTERRUPT_HARD) { if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) { int pil = env->interrupt_index & 0xf; int type = env->interrupt_index & 0xf0; if (((type == TT_EXTINT) && cpu_pil_allowed(env, pil)) || type != TT_EXTINT) { env->exception_index = env->interrupt_index; do_interrupt(env); next_tb = 0; } } } #elif defined(TARGET_ARM) if (interrupt_request & CPU_INTERRUPT_FIQ && !(env->uncached_cpsr & CPSR_F)) { env->exception_index = EXCP_FIQ; do_interrupt(env); next_tb = 0; } /* ARMv7-M interrupt return works by loading a magic value into the PC. On real hardware the load causes the return to occur. The qemu implementation performs the jump normally, then does the exception return when the CPU tries to execute code at the magic address. This will cause the magic PC value to be pushed to the stack if an interrupt occurred at the wrong time. We avoid this by disabling interrupts when pc contains a magic address. */ if (interrupt_request & CPU_INTERRUPT_HARD && ((IS_M(env) && env->regs[15] < 0xfffffff0) || !(env->uncached_cpsr & CPSR_I))) { env->exception_index = EXCP_IRQ; do_interrupt(env); next_tb = 0; } #elif defined(TARGET_UNICORE32) if (interrupt_request & CPU_INTERRUPT_HARD && !(env->uncached_asr & ASR_I)) { do_interrupt(env); next_tb = 0; } #elif defined(TARGET_SH4) if (interrupt_request & CPU_INTERRUPT_HARD) { do_interrupt(env); next_tb = 0; } #elif defined(TARGET_ALPHA) { int idx = -1; /* ??? This hard-codes the OSF/1 interrupt levels. */ switch (env->pal_mode ? 7 : env->ps & PS_INT_MASK) { case 0 ... 3: if (interrupt_request & CPU_INTERRUPT_HARD) { idx = EXCP_DEV_INTERRUPT; } /* FALLTHRU */ case 4: if (interrupt_request & CPU_INTERRUPT_TIMER) { idx = EXCP_CLK_INTERRUPT; } /* FALLTHRU */ case 5: if (interrupt_request & CPU_INTERRUPT_SMP) { idx = EXCP_SMP_INTERRUPT; } /* FALLTHRU */ case 6: if (interrupt_request & CPU_INTERRUPT_MCHK) { idx = EXCP_MCHK; } } if (idx >= 0) { env->exception_index = idx; env->error_code = 0; do_interrupt(env); next_tb = 0; } } #elif defined(TARGET_CRIS) if (interrupt_request & CPU_INTERRUPT_HARD && (env->pregs[PR_CCS] & I_FLAG) && !env->locked_irq) { env->exception_index = EXCP_IRQ; do_interrupt(env); next_tb = 0; } if (interrupt_request & CPU_INTERRUPT_NMI && (env->pregs[PR_CCS] & M_FLAG)) { env->exception_index = EXCP_NMI; do_interrupt(env); next_tb = 0; } #elif defined(TARGET_M68K) if (interrupt_request & CPU_INTERRUPT_HARD && ((env->sr & SR_I) >> SR_I_SHIFT) < env->pending_level) { /* Real hardware gets the interrupt vector via an IACK cycle at this point. Current emulated hardware doesn't rely on this, so we provide/save the vector when the interrupt is first signalled. */ env->exception_index = env->pending_vector; do_interrupt_m68k_hardirq(env); next_tb = 0; } #elif defined(TARGET_S390X) && !defined(CONFIG_USER_ONLY) if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->psw.mask & PSW_MASK_EXT)) { do_interrupt(env); next_tb = 0; } #endif /* Don't use the cached interrupt_request value, do_interrupt may have updated the EXITTB flag. */ if (env->interrupt_request & CPU_INTERRUPT_EXITTB) { env->interrupt_request &= ~CPU_INTERRUPT_EXITTB; /* ensure that no TB jump will be modified as the program flow was changed */ next_tb = 0; } } if (unlikely(env->exit_request)) { env->exit_request = 0; env->exception_index = EXCP_INTERRUPT; cpu_loop_exit(env); } #if defined(DEBUG_DISAS) || defined(CONFIG_DEBUG_EXEC) if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) { /* restore flags in standard format */ #if defined(TARGET_I386) env->eflags = env->eflags | cpu_cc_compute_all(env, CC_OP) | (DF & DF_MASK); log_cpu_state(env, X86_DUMP_CCOP); env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); #elif defined(TARGET_M68K) cpu_m68k_flush_flags(env, env->cc_op); env->cc_op = CC_OP_FLAGS; env->sr = (env->sr & 0xffe0) | env->cc_dest | (env->cc_x << 4); log_cpu_state(env, 0); #else log_cpu_state(env, 0); #endif } #endif /* DEBUG_DISAS || CONFIG_DEBUG_EXEC */ spin_lock(&tb_lock); tb = tb_find_fast(env); /* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */ if (tb_invalidated_flag) { /* as some TB could have been invalidated because of memory exceptions while generating the code, we must recompute the hash index here */ next_tb = 0; tb_invalidated_flag = 0; } #ifdef CONFIG_DEBUG_EXEC qemu_log_mask(CPU_LOG_EXEC, "Trace 0x%08lx [" TARGET_FMT_lx "] %s\n", (long)tb->tc_ptr, tb->pc, lookup_symbol(tb->pc)); #endif /* see if we can patch the calling TB. When the TB spans two pages, we cannot safely do a direct jump. */ if (next_tb != 0 && tb->page_addr[1] == -1) { tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb); } spin_unlock(&tb_lock); /* cpu_interrupt might be called while translating the TB, but before it is linked into a potentially infinite loop and becomes env->current_tb. Avoid starting execution if there is a pending interrupt. */ env->current_tb = tb; barrier(); if (likely(!env->exit_request)) { tc_ptr = tb->tc_ptr; /* execute the generated code */ next_tb = tcg_qemu_tb_exec(env, tc_ptr); if ((next_tb & 3) == 2) { /* Instruction counter expired. */ int insns_left; tb = (TranslationBlock *)(long)(next_tb & ~3); /* Restore PC. */ cpu_pc_from_tb(env, tb); insns_left = env->icount_decr.u32; if (env->icount_extra && insns_left >= 0) { /* Refill decrementer and continue execution. */ env->icount_extra += insns_left; if (env->icount_extra > 0xffff) { insns_left = 0xffff; insns_left = env->icount_extra; } env->icount_extra -= insns_left; env->icount_decr.u16.low = insns_left; if (insns_left > 0) { /* Execute remaining instructions. */ cpu_exec_nocache(env, insns_left, tb); } env->exception_index = EXCP_INTERRUPT; next_tb = 0; cpu_loop_exit(env); } } } env->current_tb = NULL; /* reset soft MMU for next block (it can currently only be set by a memory fault) */ } /* for(;;) */ } } /* for(;;) */ #if defined(TARGET_I386) /* restore flags in standard format */ env->eflags = env->eflags | cpu_cc_compute_all(env, CC_OP) | (DF & DF_MASK); #elif defined(TARGET_ARM) /* XXX: Save/restore host fpu exception state?. */ #elif defined(TARGET_UNICORE32) #elif defined(TARGET_SPARC) #elif defined(TARGET_PPC) #elif defined(TARGET_LM32) #elif defined(TARGET_M68K) cpu_m68k_flush_flags(env, env->cc_op); env->cc_op = CC_OP_FLAGS; env->sr = (env->sr & 0xffe0) | env->cc_dest | (env->cc_x << 4); #elif defined(TARGET_MICROBLAZE) #elif defined(TARGET_MIPS) #elif defined(TARGET_SH4) #elif defined(TARGET_ALPHA) #elif defined(TARGET_CRIS) #elif defined(TARGET_S390X) /* XXXXX */ #else #error unsupported target CPU #endif /* fail safe : never use cpu_single_env outside cpu_exec() */ cpu_single_env = NULL; return ret; }
14,038
FFmpeg
190f6135b48a97dadd7586f154640bec6468df1b
0
callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time) { AVFormatContext *s = priv_data; struct dshow_ctx *ctx = s->priv_data; AVPacketList **ppktl, *pktl_next; // dump_videohdr(s, vdhdr); WaitForSingleObject(ctx->mutex, INFINITE); if(shall_we_drop(s)) goto fail; pktl_next = av_mallocz(sizeof(AVPacketList)); if(!pktl_next) goto fail; if(av_new_packet(&pktl_next->pkt, buf_size) < 0) { av_free(pktl_next); goto fail; } pktl_next->pkt.stream_index = index; pktl_next->pkt.pts = time; memcpy(pktl_next->pkt.data, buf, buf_size); for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); *ppktl = pktl_next; ctx->curbufsize += buf_size; SetEvent(ctx->event); ReleaseMutex(ctx->mutex); return; fail: ReleaseMutex(ctx->mutex); return; }
14,039
FFmpeg
7f526efd17973ec6d2204f7a47b6923e2be31363
1
static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, uint8_t *dst, unsigned width, unsigned height, int srcStride1, int srcStride2, int srcStride3, int dstStride) { unsigned long y,x,w,h; w=width/2; h=height; for(y=0;y<h;y++){ const uint8_t* yp=src1+srcStride1*y; const uint8_t* up=src2+srcStride2*(y>>2); const uint8_t* vp=src3+srcStride3*(y>>2); uint8_t* d=dst+dstStride*y; x=0; #ifdef HAVE_MMX for(;x<w-7;x+=8) { asm volatile( PREFETCH" 32(%1, %0)\n\t" PREFETCH" 32(%2, %0)\n\t" PREFETCH" 32(%3, %0)\n\t" "movq (%1, %0, 4), %%mm0\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */ "movq (%2, %0), %%mm1\n\t" /* U0U1U2U3U4U5U6U7 */ "movq (%3, %0), %%mm2\n\t" /* V0V1V2V3V4V5V6V7 */ "movq %%mm0, %%mm3\n\t" /* Y0Y1Y2Y3Y4Y5Y6Y7 */ "movq %%mm1, %%mm4\n\t" /* U0U1U2U3U4U5U6U7 */ "movq %%mm2, %%mm5\n\t" /* V0V1V2V3V4V5V6V7 */ "punpcklbw %%mm1, %%mm1\n\t" /* U0U0 U1U1 U2U2 U3U3 */ "punpcklbw %%mm2, %%mm2\n\t" /* V0V0 V1V1 V2V2 V3V3 */ "punpckhbw %%mm4, %%mm4\n\t" /* U4U4 U5U5 U6U6 U7U7 */ "punpckhbw %%mm5, %%mm5\n\t" /* V4V4 V5V5 V6V6 V7V7 */ "movq %%mm1, %%mm6\n\t" "punpcklbw %%mm2, %%mm1\n\t" /* U0V0 U0V0 U1V1 U1V1*/ "punpcklbw %%mm1, %%mm0\n\t" /* Y0U0 Y1V0 Y2U0 Y3V0*/ "punpckhbw %%mm1, %%mm3\n\t" /* Y4U1 Y5V1 Y6U1 Y7V1*/ MOVNTQ" %%mm0, (%4, %0, 8)\n\t" MOVNTQ" %%mm3, 8(%4, %0, 8)\n\t" "punpckhbw %%mm2, %%mm6\n\t" /* U2V2 U2V2 U3V3 U3V3*/ "movq 8(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm6, %%mm0\n\t" /* Y U2 Y V2 Y U2 Y V2*/ "punpckhbw %%mm6, %%mm3\n\t" /* Y U3 Y V3 Y U3 Y V3*/ MOVNTQ" %%mm0, 16(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 24(%4, %0, 8)\n\t" "movq %%mm4, %%mm6\n\t" "movq 16(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm5, %%mm4\n\t" "punpcklbw %%mm4, %%mm0\n\t" /* Y U4 Y V4 Y U4 Y V4*/ "punpckhbw %%mm4, %%mm3\n\t" /* Y U5 Y V5 Y U5 Y V5*/ MOVNTQ" %%mm0, 32(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 40(%4, %0, 8)\n\t" "punpckhbw %%mm5, %%mm6\n\t" "movq 24(%1, %0, 4), %%mm0\n\t" "movq %%mm0, %%mm3\n\t" "punpcklbw %%mm6, %%mm0\n\t" /* Y U6 Y V6 Y U6 Y V6*/ "punpckhbw %%mm6, %%mm3\n\t" /* Y U7 Y V7 Y U7 Y V7*/ MOVNTQ" %%mm0, 48(%4, %0, 8)\n\t" MOVNTQ" %%mm3, 56(%4, %0, 8)\n\t" : "+r" (x) : "r"(yp), "r" (up), "r"(vp), "r"(d) :"memory"); } #endif for(; x<w; x++) { const int x2= x<<2; d[8*x+0]=yp[x2]; d[8*x+1]=up[x]; d[8*x+2]=yp[x2+1]; d[8*x+3]=vp[x]; d[8*x+4]=yp[x2+2]; d[8*x+5]=up[x]; d[8*x+6]=yp[x2+3]; d[8*x+7]=vp[x]; } } #ifdef HAVE_MMX asm( EMMS" \n\t" SFENCE" \n\t" ::: "memory" ); #endif }
14,040
qemu
07e95cd529af345fdeea230913f68eff5b925bb6
1
static int qio_channel_websock_handshake_process(QIOChannelWebsock *ioc, const char *line, size_t size, Error **errp) { int ret = -1; char *protocols = qio_channel_websock_handshake_entry( line, size, QIO_CHANNEL_WEBSOCK_HEADER_PROTOCOL); char *version = qio_channel_websock_handshake_entry( line, size, QIO_CHANNEL_WEBSOCK_HEADER_VERSION); char *key = qio_channel_websock_handshake_entry( line, size, QIO_CHANNEL_WEBSOCK_HEADER_KEY); if (!protocols) { error_setg(errp, "Missing websocket protocol header data"); goto cleanup; } if (!version) { error_setg(errp, "Missing websocket version header data"); goto cleanup; } if (!key) { error_setg(errp, "Missing websocket key header data"); goto cleanup; } if (!g_strrstr(protocols, QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY)) { error_setg(errp, "No '%s' protocol is supported by client '%s'", QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY, protocols); goto cleanup; } if (!g_str_equal(version, QIO_CHANNEL_WEBSOCK_SUPPORTED_VERSION)) { error_setg(errp, "Version '%s' is not supported by client '%s'", QIO_CHANNEL_WEBSOCK_SUPPORTED_VERSION, version); goto cleanup; } if (strlen(key) != QIO_CHANNEL_WEBSOCK_CLIENT_KEY_LEN) { error_setg(errp, "Key length '%zu' was not as expected '%d'", strlen(key), QIO_CHANNEL_WEBSOCK_CLIENT_KEY_LEN); goto cleanup; } ret = qio_channel_websock_handshake_send_response(ioc, key, errp); cleanup: g_free(protocols); g_free(version); g_free(key); return ret; }
14,041
FFmpeg
b9c8388710a06544812739eedc0a40d3451491dc
1
static void *av_mallocz_static(unsigned int size) { void *ptr = av_mallocz(size); if(ptr){ array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); if(!array_static) return NULL; array_static[last_static++] = ptr; } return ptr; }
14,042
qemu
64ffbe04eaafebf4045a3ace52a360c14959d196
1
int index_from_key(const char *key) { int i; for (i = 0; QKeyCode_lookup[i] != NULL; i++) { if (!strcmp(key, QKeyCode_lookup[i])) { break; } } /* Return Q_KEY_CODE__MAX if the key is invalid */ return i; }
14,043
FFmpeg
39bb30f6640fe1faf4bbc779a79786028febc95d
1
static int mxf_read_primer_pack(MXFContext *mxf) { ByteIOContext *pb = mxf->fc->pb; int item_num = get_be32(pb); int item_len = get_be32(pb); if (item_len != 18) { av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n"); return -1; } if (item_num > UINT_MAX / item_len) return -1; mxf->local_tags_count = item_num; mxf->local_tags = av_malloc(item_num*item_len); if (!mxf->local_tags) return -1; get_buffer(pb, mxf->local_tags, item_num*item_len); return 0; }
14,045
qemu
9a321e92343891e30f6fe8bfaad40454ae358bfb
1
static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { uint32_t config_addr = rtas_ld(args, 0); uint64_t buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2); unsigned int intr_src_num = -1, ioa_intr_num = rtas_ld(args, 3); int ndev; sPAPRPHBState *phb = NULL; /* Fins sPAPRPHBState */ phb = find_phb(spapr, buid); if (!phb) { rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); return; } /* Find device descriptor and start IRQ */ ndev = spapr_msicfg_find(phb, config_addr, false); if (ndev < 0) { trace_spapr_pci_msi("MSI has not been enabled", -1, config_addr); rtas_st(rets, 0, RTAS_OUT_HW_ERROR); return; } intr_src_num = phb->msi_table[ndev].irq + ioa_intr_num; trace_spapr_pci_rtas_ibm_query_interrupt_source_number(ioa_intr_num, intr_src_num); rtas_st(rets, 0, RTAS_OUT_SUCCESS); rtas_st(rets, 1, intr_src_num); rtas_st(rets, 2, 1);/* 0 == level; 1 == edge */ }
14,047
FFmpeg
d1f558b3628d3ab99fd93a98b5758ef1be45a5da
0
static int convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size) { switch (AV_RB32(src)) { case DCA_SYNCWORD_CORE_BE: case DCA_SYNCWORD_SUBSTREAM: memcpy(dst, src, src_size); return src_size; case DCA_SYNCWORD_CORE_LE: case DCA_SYNCWORD_CORE_14B_BE: case DCA_SYNCWORD_CORE_14B_LE: return avpriv_dca_convert_bitstream(src, src_size, dst, max_size); default: return AVERROR_INVALIDDATA; } }
14,048
FFmpeg
b8866783c6a855643a3869020ac5241b12f7d97a
0
int ff_scale_image(uint8_t *dst_data[4], int dst_linesize[4], int dst_w, int dst_h, enum AVPixelFormat dst_pix_fmt, uint8_t * const src_data[4], int src_linesize[4], int src_w, int src_h, enum AVPixelFormat src_pix_fmt, void *log_ctx) { int ret; struct SwsContext *sws_ctx = sws_getContext(src_w, src_h, src_pix_fmt, dst_w, dst_h, dst_pix_fmt, SWS_BILINEAR, NULL, NULL, NULL); if (!sws_ctx) { av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion " "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", av_get_pix_fmt_name(src_pix_fmt), src_w, src_h, av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h); ret = AVERROR(EINVAL); goto end; } if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0) goto end; ret = 0; sws_scale(sws_ctx, (const uint8_t * const*)src_data, src_linesize, 0, src_h, dst_data, dst_linesize); end: sws_freeContext(sws_ctx); return ret; }
14,049
FFmpeg
229843aa359ae0c9519977d7fa952688db63f559
0
static int ftp_read(URLContext *h, unsigned char *buf, int size) { FTPContext *s = h->priv_data; int read, err, retry_done = 0; av_dlog(h, "ftp protocol read %d bytes\n", size); retry: if (s->state == DISCONNECTED) { /* optimization */ if (s->position >= s->filesize) return 0; if ((err = ftp_connect_data_connection(h)) < 0) return err; } if (s->state == READY) { if (s->position >= s->filesize) return 0; if ((err = ftp_retrieve(s)) < 0) return err; } if (s->conn_data && s->state == DOWNLOADING) { read = ffurl_read(s->conn_data, buf, size); if (read >= 0) { s->position += read; if (s->position >= s->filesize) { /* server will terminate, but keep current position to avoid madness */ /* save position to restart from it */ int64_t pos = s->position; if (ftp_abort(h) < 0) { s->position = pos; return AVERROR(EIO); } s->position = pos; } } if (read <= 0 && s->position < s->filesize && !h->is_streamed) { /* Server closed connection. Probably due to inactivity */ int64_t pos = s->position; av_log(h, AV_LOG_INFO, "Reconnect to FTP server.\n"); if ((err = ftp_abort(h)) < 0) return err; if ((err = ftp_seek(h, pos, SEEK_SET)) < 0) { av_log(h, AV_LOG_ERROR, "Position cannot be restored.\n"); return err; } if (!retry_done) { retry_done = 1; goto retry; } } return read; } av_log(h, AV_LOG_DEBUG, "FTP read failed\n"); return AVERROR(EIO); }
14,050
qemu
62ef3760d4e400849fc663474227bb4668244455
1
sPAPROptionVector *spapr_ovec_new(void) { sPAPROptionVector *ov; ov = g_new0(sPAPROptionVector, 1); ov->bitmap = bitmap_new(OV_MAXBITS); return ov; }
14,051
qemu
bac8d7b45dd855759204117e5a05452ede01bbab
1
static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) { char desc[DESC_SIZE]; uint32_t cid; const char *p_name, *cid_str; size_t cid_str_size; BDRVVmdkState *s = bs->opaque; if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) { return 0; } if (parent) { cid_str = "parentCID"; cid_str_size = sizeof("parentCID"); } else { cid_str = "CID"; cid_str_size = sizeof("CID"); } p_name = strstr(desc, cid_str); if (p_name != NULL) { p_name += cid_str_size; sscanf(p_name, "%x", &cid); } return cid; }
14,052
qemu
96bc97ebf350ec480b69082819cedb8850f46a0f
1
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id) { QemuOpts *opts; QTAILQ_FOREACH(opts, &list->head, next) { if (!opts->id) { if (!id) { return opts; } continue; } if (strcmp(opts->id, id) != 0) { continue; } return opts; } return NULL; }
14,053
FFmpeg
df3a96c497c0db51c917e51e5e4a60986979db91
1
static void do_video_out(AVFormatContext *s, OutputStream *ost, AVFrame *in_picture, float quality) { int ret, format_video_sync; AVPacket pkt; AVCodecContext *enc = ost->st->codec; int nb_frames; double sync_ipts, delta; double duration = 0; int frame_size = 0; InputStream *ist = NULL; if (ost->source_index >= 0) ist = input_streams[ost->source_index]; if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num) duration = 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)); sync_ipts = in_picture->pts; delta = sync_ipts - ost->sync_opts + duration; /* by default, we output a single frame */ nb_frames = 1; format_video_sync = video_sync_method; if (format_video_sync == VSYNC_AUTO) format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? ((s->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : 1; switch (format_video_sync) { case VSYNC_CFR: // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c if (delta < -1.1) nb_frames = 0; else if (delta > 1.1) nb_frames = lrintf(delta); break; case VSYNC_VFR: if (delta <= -0.6) nb_frames = 0; else if (delta > 0.6) ost->sync_opts = lrint(sync_ipts); break; case VSYNC_DROP: case VSYNC_PASSTHROUGH: ost->sync_opts = lrint(sync_ipts); break; default: av_assert0(0); nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); if (nb_frames == 0) { av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n"); } else if (nb_frames > 1) { nb_frames_dup += nb_frames - 1; av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1); duplicate_frame: av_init_packet(&pkt); pkt.data = NULL; pkt.size = 0; in_picture->pts = ost->sync_opts; if (s->oformat->flags & AVFMT_RAWPICTURE && enc->codec->id == CODEC_ID_RAWVIDEO) { /* raw pictures are written as AVPicture structure to avoid any copies. We support temporarily the older method. */ enc->coded_frame->interlaced_frame = in_picture->interlaced_frame; enc->coded_frame->top_field_first = in_picture->top_field_first; pkt.data = (uint8_t *)in_picture; pkt.size = sizeof(AVPicture); pkt.pts = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base); pkt.flags |= AV_PKT_FLAG_KEY; write_frame(s, &pkt, ost); video_size += pkt.size; } else { int got_packet; AVFrame big_picture; big_picture = *in_picture; /* better than nothing: use input picture interlaced settings */ big_picture.interlaced_frame = in_picture->interlaced_frame; if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) { if (ost->top_field_first == -1) big_picture.top_field_first = in_picture->top_field_first; else big_picture.top_field_first = !!ost->top_field_first; /* handles same_quant here. This is not correct because it may not be a global option */ big_picture.quality = quality; if (!enc->me_threshold) big_picture.pict_type = 0; if (ost->forced_kf_index < ost->forced_kf_count && big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) { big_picture.pict_type = AV_PICTURE_TYPE_I; ost->forced_kf_index++; update_benchmark(NULL); ret = avcodec_encode_video2(enc, &pkt, &big_picture, &got_packet); update_benchmark("encode_video %d.%d", ost->file_index, ost->index); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); exit_program(1); if (got_packet) { if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & CODEC_CAP_DELAY)) pkt.pts = ost->sync_opts; if (pkt.pts != AV_NOPTS_VALUE) pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base); if (pkt.dts != AV_NOPTS_VALUE) pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:video " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base), av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base)); write_frame(s, &pkt, ost); frame_size = pkt.size; video_size += pkt.size; av_free_packet(&pkt); /* if two pass, output log */ if (ost->logfile && enc->stats_out) { fprintf(ost->logfile, "%s", enc->stats_out); ost->sync_opts++; /* * For video, number of frames in == number of packets out. * But there may be reordering, so we can't throw away frames on encoder * flush, we need to limit them here, before they go into encoder. */ ost->frame_number++; if(--nb_frames) goto duplicate_frame; if (vstats_filename && frame_size) do_video_stats(output_files[ost->file_index]->ctx, ost, frame_size);
14,054
FFmpeg
4484c722f68e6a54b8bd701d391897bc092b4404
1
static av_cold int read_specific_config(ALSDecContext *ctx) { GetBitContext gb; uint64_t ht_size; int i, config_offset; MPEG4AudioConfig m4ac; ALSSpecificConfig *sconf = &ctx->sconf; AVCodecContext *avctx = ctx->avctx; uint32_t als_id, header_size, trailer_size; init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata, avctx->extradata_size * 8, 1); if (config_offset < 0) return -1; skip_bits_long(&gb, config_offset); if (get_bits_left(&gb) < (30 << 3)) return -1; // read the fixed items als_id = get_bits_long(&gb, 32); avctx->sample_rate = m4ac.sample_rate; skip_bits_long(&gb, 32); // sample rate already known sconf->samples = get_bits_long(&gb, 32); avctx->channels = m4ac.channels; skip_bits(&gb, 16); // number of channels already known skip_bits(&gb, 3); // skip file_type sconf->resolution = get_bits(&gb, 3); sconf->floating = get_bits1(&gb); sconf->msb_first = get_bits1(&gb); sconf->frame_length = get_bits(&gb, 16) + 1; sconf->ra_distance = get_bits(&gb, 8); sconf->ra_flag = get_bits(&gb, 2); sconf->adapt_order = get_bits1(&gb); sconf->coef_table = get_bits(&gb, 2); sconf->long_term_prediction = get_bits1(&gb); sconf->max_order = get_bits(&gb, 10); sconf->block_switching = get_bits(&gb, 2); sconf->bgmc = get_bits1(&gb); sconf->sb_part = get_bits1(&gb); sconf->joint_stereo = get_bits1(&gb); sconf->mc_coding = get_bits1(&gb); sconf->chan_config = get_bits1(&gb); sconf->chan_sort = get_bits1(&gb); sconf->crc_enabled = get_bits1(&gb); sconf->rlslms = get_bits1(&gb); skip_bits(&gb, 5); // skip 5 reserved bits skip_bits1(&gb); // skip aux_data_enabled // check for ALSSpecificConfig struct if (als_id != MKBETAG('A','L','S','\0')) return -1; ctx->cur_frame_length = sconf->frame_length; // read channel config if (sconf->chan_config) sconf->chan_config_info = get_bits(&gb, 16); // TODO: use this to set avctx->channel_layout // read channel sorting if (sconf->chan_sort && avctx->channels > 1) { int chan_pos_bits = av_ceil_log2(avctx->channels); int bits_needed = avctx->channels * chan_pos_bits + 7; if (get_bits_left(&gb) < bits_needed) return -1; if (!(sconf->chan_pos = av_malloc(avctx->channels * sizeof(*sconf->chan_pos)))) return AVERROR(ENOMEM); ctx->cs_switch = 1; for (i = 0; i < avctx->channels; i++) { int idx; idx = get_bits(&gb, chan_pos_bits); if (idx >= avctx->channels) { av_log(avctx, AV_LOG_WARNING, "Invalid channel reordering.\n"); ctx->cs_switch = 0; break; } sconf->chan_pos[idx] = i; } align_get_bits(&gb); } // read fixed header and trailer sizes, // if size = 0xFFFFFFFF then there is no data field! if (get_bits_left(&gb) < 64) return -1; header_size = get_bits_long(&gb, 32); trailer_size = get_bits_long(&gb, 32); if (header_size == 0xFFFFFFFF) header_size = 0; if (trailer_size == 0xFFFFFFFF) trailer_size = 0; ht_size = ((int64_t)(header_size) + (int64_t)(trailer_size)) << 3; // skip the header and trailer data if (get_bits_left(&gb) < ht_size) return -1; if (ht_size > INT32_MAX) return -1; skip_bits_long(&gb, ht_size); // initialize CRC calculation if (sconf->crc_enabled) { if (get_bits_left(&gb) < 32) return -1; if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) { ctx->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE); ctx->crc = 0xFFFFFFFF; ctx->crc_org = ~get_bits_long(&gb, 32); } else skip_bits_long(&gb, 32); } // no need to read the rest of ALSSpecificConfig (ra_unit_size & aux data) dprint_specific_config(ctx); return 0; }
14,055
FFmpeg
a0c624e299730c8c5800375c2f5f3c6c200053ff
1
static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) { V4L2m2mContext *s = avctx->priv_data; V4L2Context *const capture = &s->capture; V4L2Context *const output = &s->output; AVPacket avpkt = {0}; int ret; ret = ff_decode_get_packet(avctx, &avpkt); if (ret < 0 && ret != AVERROR_EOF) return ret; if (s->draining) goto dequeue; ret = ff_v4l2_context_enqueue_packet(output, &avpkt); if (ret < 0) { if (ret != AVERROR(ENOMEM)) return ret; /* no input buffers available, continue dequeing */ } if (avpkt.size) { ret = v4l2_try_start(avctx); if (ret) return 0; } dequeue: return ff_v4l2_context_dequeue_frame(capture, frame); }
14,057
FFmpeg
95a57d26d8653d21f0dab1aff3558ee944853dbf
1
static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, AVFrame *picture) { int compno, reslevelno, bandno; int x, y; uint8_t *line; Jpeg2000T1Context t1; /* Loop on tile components */ for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; Jpeg2000CodingStyle *codsty = tile->codsty + compno; /* Loop on resolution levels */ for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) { Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno; /* Loop on bands */ for (bandno = 0; bandno < rlevel->nbands; bandno++) { uint16_t nb_precincts, precno; Jpeg2000Band *band = rlevel->band + bandno; int cblkno = 0, bandpos; bandpos = bandno + (reslevelno > 0); if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1]) continue; nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y; /* Loop on precincts */ for (precno = 0; precno < nb_precincts; precno++) { Jpeg2000Prec *prec = band->prec + precno; /* Loop on codeblocks */ for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) { int x, y; Jpeg2000Cblk *cblk = prec->cblk + cblkno; decode_cblk(s, codsty, &t1, cblk, cblk->coord[0][1] - cblk->coord[0][0], cblk->coord[1][1] - cblk->coord[1][0], bandpos); x = cblk->coord[0][0]; y = cblk->coord[1][0]; if (codsty->transform == FF_DWT97) dequantization_float(x, y, cblk, comp, &t1, band); else dequantization_int(x, y, cblk, comp, &t1, band); } /* end cblk */ } /*end prec */ } /* end band */ } /* end reslevel */ /* inverse DWT */ ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data); } /*end comp */ /* inverse MCT transformation */ if (tile->codsty[0].mct) mct_decode(s, tile); if (s->precision <= 8) { for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; float *datap = comp->f_data; int32_t *i_datap = comp->i_data; int cbps = s->cbps[compno]; int w = tile->comp[compno].coord[0][1] - s->image_offset_x; y = tile->comp[compno].coord[1][0] - s->image_offset_y; line = picture->data[0] + y * picture->linesize[0]; for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { uint8_t *dst; x = tile->comp[compno].coord[0][0] - s->image_offset_x; dst = line + x * s->ncomponents + compno; if (tile->codsty->transform == FF_DWT97) { for (; x < w; x += s->cdx[compno]) { int val = lrintf(*datap) + (1 << (cbps - 1)); /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ val = av_clip(val, 0, (1 << cbps) - 1); *dst = val << (8 - cbps); datap++; dst += s->ncomponents; } } else { for (; x < w; x += s->cdx[compno]) { int val = *i_datap + (1 << (cbps - 1)); /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ val = av_clip(val, 0, (1 << cbps) - 1); *dst = val << (8 - cbps); i_datap++; dst += s->ncomponents; } } line += picture->linesize[0]; } } } else { for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; float *datap = comp->f_data; int32_t *i_datap = comp->i_data; uint16_t *linel; int cbps = s->cbps[compno]; int w = tile->comp[compno].coord[0][1] - s->image_offset_x; y = tile->comp[compno].coord[1][0] - s->image_offset_y; linel = (uint16_t *)picture->data[0] + y * (picture->linesize[0] >> 1); for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { uint16_t *dst; x = tile->comp[compno].coord[0][0] - s->image_offset_x; dst = linel + (x * s->ncomponents + compno); if (tile->codsty->transform == FF_DWT97) { for (; x < w; x += s-> cdx[compno]) { int val = lrintf(*datap) + (1 << (cbps - 1)); /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ val = av_clip(val, 0, (1 << cbps) - 1); /* align 12 bit values in little-endian mode */ *dst = val << (16 - cbps); datap++; dst += s->ncomponents; } } else { for (; x < w; x += s-> cdx[compno]) { int val = *i_datap + (1 << (cbps - 1)); /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ val = av_clip(val, 0, (1 << cbps) - 1); /* align 12 bit values in little-endian mode */ *dst = val << (16 - cbps); i_datap++; dst += s->ncomponents; } } linel += picture->linesize[0] >> 1; } } } return 0; }
14,058
FFmpeg
08ccc474b73a3acef5e56060c8174d4e82ace20d
1
static int rtmp_open(URLContext *s, const char *uri, int flags) { RTMPContext *rt = s->priv_data; char proto[8], hostname[256], path[1024], auth[100], *fname; char *old_app, *qmark, fname_buffer[1024]; uint8_t buf[2048]; int port; AVDictionary *opts = NULL; int ret; if (rt->listen_timeout > 0) rt->listen = 1; rt->is_input = !(flags & AVIO_FLAG_WRITE); av_url_split(proto, sizeof(proto), auth, sizeof(auth), hostname, sizeof(hostname), &port, path, sizeof(path), s->filename); if (strchr(path, ' ')) { av_log(s, AV_LOG_WARNING, "Detected librtmp style URL parameters, these aren't supported " "by the libavformat internal RTMP handler currently enabled. " "See the documentation for the correct way to pass parameters.\n"); } if (auth[0]) { char *ptr = strchr(auth, ':'); if (ptr) { *ptr = '\0'; av_strlcpy(rt->username, auth, sizeof(rt->username)); av_strlcpy(rt->password, ptr + 1, sizeof(rt->password)); } } if (rt->listen && strcmp(proto, "rtmp")) { av_log(s, AV_LOG_ERROR, "rtmp_listen not available for %s\n", proto); return AVERROR(EINVAL); } if (!strcmp(proto, "rtmpt") || !strcmp(proto, "rtmpts")) { if (!strcmp(proto, "rtmpts")) av_dict_set(&opts, "ffrtmphttp_tls", "1", 1); /* open the http tunneling connection */ ff_url_join(buf, sizeof(buf), "ffrtmphttp", NULL, hostname, port, NULL); } else if (!strcmp(proto, "rtmps")) { /* open the tls connection */ if (port < 0) port = RTMPS_DEFAULT_PORT; ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port, NULL); } else if (!strcmp(proto, "rtmpe") || (!strcmp(proto, "rtmpte"))) { if (!strcmp(proto, "rtmpte")) av_dict_set(&opts, "ffrtmpcrypt_tunneling", "1", 1); /* open the encrypted connection */ ff_url_join(buf, sizeof(buf), "ffrtmpcrypt", NULL, hostname, port, NULL); rt->encrypted = 1; } else { /* open the tcp connection */ if (port < 0) port = RTMP_DEFAULT_PORT; if (rt->listen) ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, "?listen&listen_timeout=%d", rt->listen_timeout * 1000); else ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); } reconnect: if ((ret = ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, &opts)) < 0) { av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf); goto fail; } if (rt->swfverify) { if ((ret = rtmp_calc_swfhash(s)) < 0) goto fail; } rt->state = STATE_START; if (!rt->listen && (ret = rtmp_handshake(s, rt)) < 0) goto fail; if (rt->listen && (ret = rtmp_server_handshake(s, rt)) < 0) goto fail; rt->out_chunk_size = 128; rt->in_chunk_size = 128; // Probably overwritten later rt->state = STATE_HANDSHAKED; // Keep the application name when it has been defined by the user. old_app = rt->app; rt->app = av_malloc(APP_MAX_LENGTH); if (!rt->app) { ret = AVERROR(ENOMEM); goto fail; } //extract "app" part from path qmark = strchr(path, '?'); if (qmark && strstr(qmark, "slist=")) { char* amp; // After slist we have the playpath, before the params, the app av_strlcpy(rt->app, path + 1, FFMIN(qmark - path, APP_MAX_LENGTH)); fname = strstr(path, "slist=") + 6; // Strip any further query parameters from fname amp = strchr(fname, '&'); if (amp) { av_strlcpy(fname_buffer, fname, FFMIN(amp - fname + 1, sizeof(fname_buffer))); fname = fname_buffer; } } else if (!strncmp(path, "/ondemand/", 10)) { fname = path + 10; memcpy(rt->app, "ondemand", 9); } else { char *next = *path ? path + 1 : path; char *p = strchr(next, '/'); if (!p) { fname = next; rt->app[0] = '\0'; } else { // make sure we do not mismatch a playpath for an application instance char *c = strchr(p + 1, ':'); fname = strchr(p + 1, '/'); if (!fname || (c && c < fname)) { fname = p + 1; av_strlcpy(rt->app, path + 1, FFMIN(p - path, APP_MAX_LENGTH)); } else { fname++; av_strlcpy(rt->app, path + 1, FFMIN(fname - path - 1, APP_MAX_LENGTH)); } } } if (old_app) { // The name of application has been defined by the user, override it. if (strlen(old_app) >= APP_MAX_LENGTH) { ret = AVERROR(EINVAL); goto fail; } av_free(rt->app); rt->app = old_app; } if (!rt->playpath) { int len = strlen(fname); rt->playpath = av_malloc(PLAYPATH_MAX_LENGTH); if (!rt->playpath) { ret = AVERROR(ENOMEM); goto fail; } if (!strchr(fname, ':') && len >= 4 && (!strcmp(fname + len - 4, ".f4v") || !strcmp(fname + len - 4, ".mp4"))) { memcpy(rt->playpath, "mp4:", 5); } else { if (len >= 4 && !strcmp(fname + len - 4, ".flv")) fname[len - 4] = '\0'; rt->playpath[0] = 0; } av_strlcat(rt->playpath, fname, PLAYPATH_MAX_LENGTH); } if (!rt->tcurl) { rt->tcurl = av_malloc(TCURL_MAX_LENGTH); if (!rt->tcurl) { ret = AVERROR(ENOMEM); goto fail; } ff_url_join(rt->tcurl, TCURL_MAX_LENGTH, proto, NULL, hostname, port, "/%s", rt->app); } if (!rt->flashver) { rt->flashver = av_malloc(FLASHVER_MAX_LENGTH); if (!rt->flashver) { ret = AVERROR(ENOMEM); goto fail; } if (rt->is_input) { snprintf(rt->flashver, FLASHVER_MAX_LENGTH, "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4); } else { snprintf(rt->flashver, FLASHVER_MAX_LENGTH, "FMLE/3.0 (compatible; %s)", LIBAVFORMAT_IDENT); } } rt->client_report_size = 1048576; rt->bytes_read = 0; rt->has_audio = 0; rt->has_video = 0; rt->received_metadata = 0; rt->last_bytes_read = 0; rt->server_bw = 2500000; av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", proto, path, rt->app, rt->playpath); if (!rt->listen) { if ((ret = gen_connect(s, rt)) < 0) goto fail; } else { if ((ret = read_connect(s, s->priv_data)) < 0) goto fail; } do { ret = get_packet(s, 1); } while (ret == AVERROR(EAGAIN)); if (ret < 0) goto fail; if (rt->do_reconnect) { int i; ffurl_close(rt->stream); rt->stream = NULL; rt->do_reconnect = 0; rt->nb_invokes = 0; for (i = 0; i < 2; i++) memset(rt->prev_pkt[i], 0, sizeof(**rt->prev_pkt) * rt->nb_prev_pkt[i]); free_tracked_methods(rt); goto reconnect; } if (rt->is_input) { int err; // generate FLV header for demuxer rt->flv_size = 13; if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0) return err; rt->flv_off = 0; memcpy(rt->flv_data, "FLV\1\0\0\0\0\011\0\0\0\0", rt->flv_size); // Read packets until we reach the first A/V packet or read metadata. // If there was a metadata package in front of the A/V packets, we can // build the FLV header from this. If we do not receive any metadata, // the FLV decoder will allocate the needed streams when their first // audio or video packet arrives. while (!rt->has_audio && !rt->has_video && !rt->received_metadata) { if ((ret = get_packet(s, 0)) < 0) return ret; } // Either after we have read the metadata or (if there is none) the // first packet of an A/V stream, we have a better knowledge about the // streams, so set the FLV header accordingly. if (rt->has_audio) { rt->flv_data[4] |= FLV_HEADER_FLAG_HASAUDIO; } if (rt->has_video) { rt->flv_data[4] |= FLV_HEADER_FLAG_HASVIDEO; } } else { rt->flv_size = 0; rt->flv_data = NULL; rt->flv_off = 0; rt->skip_bytes = 13; } s->max_packet_size = rt->stream->max_packet_size; s->is_streamed = 1; return 0; fail: av_dict_free(&opts); rtmp_close(s); return ret; }
14,059
FFmpeg
b7fa5c5abb39f819fbb42253711bc13e5cac0e81
1
static int read_random(uint32_t *dst, const char *file) { int fd = open(file, O_RDONLY); int err = -1; if (fd == -1) return -1; #if HAVE_FCNTL && defined(O_NONBLOCK) if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) != -1) #endif err = read(fd, dst, sizeof(*dst)); close(fd); return err; }
14,060
qemu
7faa8075d898ae56d2c533c530569bb25ab86eaf
1
static void enable_device(PIIX4PMState *s, int slot) { s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS; s->pci0_status.up |= (1 << slot); }
14,061
qemu
3d5b3ec6d460a92245215aaf7b349b0b9e5ffa25
1
static QObject *parse_literal(JSONParserContext *ctxt) { QObject *token, *obj; JSONParserContext saved_ctxt = parser_context_save(ctxt); token = parser_context_pop_token(ctxt); if (token == NULL) { goto out; } switch (token_get_type(token)) { case JSON_STRING: obj = QOBJECT(qstring_from_escaped_str(ctxt, token)); break; case JSON_INTEGER: obj = QOBJECT(qint_from_int(strtoll(token_get_value(token), NULL, 10))); break; case JSON_FLOAT: /* FIXME dependent on locale */ obj = QOBJECT(qfloat_from_double(strtod(token_get_value(token), NULL))); break; default: goto out; } return obj; out: parser_context_restore(ctxt, saved_ctxt); return NULL; }
14,062
qemu
0ccb9c1d8128a020720d5c6abf99a470742a1b94
1
void cpu_loop(CPUM68KState *env) { CPUState *cs = CPU(m68k_env_get_cpu(env)); int trapnr; unsigned int n; target_siginfo_t info; TaskState *ts = cs->opaque; for(;;) { cpu_exec_start(cs); trapnr = cpu_exec(cs); cpu_exec_end(cs); process_queued_cpu_work(cs); switch(trapnr) { case EXCP_ILLEGAL: { if (ts->sim_syscalls) { uint16_t nr; get_user_u16(nr, env->pc + 2); env->pc += 4; do_m68k_simcall(env, nr); } else { goto do_sigill; } } case EXCP_HALT_INSN: /* Semihosing syscall. */ env->pc += 4; do_m68k_semihosting(env, env->dregs[0]); case EXCP_LINEA: case EXCP_LINEF: case EXCP_UNSUPPORTED: do_sigill: info.si_signo = TARGET_SIGILL; info.si_code = TARGET_ILL_ILLOPN; case EXCP_TRAP0: { abi_long ret; ts->sim_syscalls = 0; n = env->dregs[0]; env->pc += 2; ret = do_syscall(env, n, env->dregs[1], env->dregs[2], env->dregs[3], env->dregs[4], env->dregs[5], env->aregs[0], 0, 0); if (ret == -TARGET_ERESTARTSYS) { env->pc -= 2; } else if (ret != -TARGET_QEMU_ESIGRETURN) { env->dregs[0] = ret; } } case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ case EXCP_ACCESS: { info.si_signo = TARGET_SIGSEGV; /* XXX: check env->error_code */ info.si_code = TARGET_SEGV_MAPERR; info._sifields._sigfault._addr = env->mmu.ar; } case EXCP_DEBUG: { int sig; sig = gdb_handlesig(cs, TARGET_SIGTRAP); if (sig) { info.si_signo = sig; info.si_code = TARGET_TRAP_BRKPT; } } case EXCP_ATOMIC: cpu_exec_step_atomic(cs); default: EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); abort(); } process_pending_signals(env); } }
14,064
qemu
feeee5aca765606818e00f5a19d19f141f4ae365
1
void do_savevm(Monitor *mon, const QDict *qdict) { DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; int ret; QEMUFile *f; int saved_vm_running; uint32_t vm_state_size; #ifdef _WIN32 struct _timeb tb; #else struct timeval tv; #endif const char *name = qdict_get_try_str(qdict, "name"); bs = get_bs_snapshots(); if (!bs) { monitor_printf(mon, "No block device can accept snapshots\n"); return; } /* ??? Should this occur after vm_stop? */ qemu_aio_flush(); saved_vm_running = vm_running; vm_stop(0); memset(sn, 0, sizeof(*sn)); if (name) { ret = bdrv_snapshot_find(bs, old_sn, name); if (ret >= 0) { pstrcpy(sn->name, sizeof(sn->name), old_sn->name); pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str); } else { pstrcpy(sn->name, sizeof(sn->name), name); } } /* fill auxiliary fields */ #ifdef _WIN32 _ftime(&tb); sn->date_sec = tb.time; sn->date_nsec = tb.millitm * 1000000; #else gettimeofday(&tv, NULL); sn->date_sec = tv.tv_sec; sn->date_nsec = tv.tv_usec * 1000; #endif sn->vm_clock_nsec = qemu_get_clock(vm_clock); /* Delete old snapshots of the same name */ if (name && del_existing_snapshots(mon, name) < 0) { goto the_end; } /* save the VM state */ f = qemu_fopen_bdrv(bs, 1); if (!f) { monitor_printf(mon, "Could not open VM state file\n"); goto the_end; } ret = qemu_savevm_state(mon, f); vm_state_size = qemu_ftell(f); qemu_fclose(f); if (ret < 0) { monitor_printf(mon, "Error %d while writing VM\n", ret); goto the_end; } /* create the snapshots */ QTAILQ_FOREACH(dinfo, &drives, next) { bs1 = dinfo->bdrv; if (bdrv_has_snapshot(bs1)) { /* Write VM state size only to the image that contains the state */ sn->vm_state_size = (bs == bs1 ? vm_state_size : 0); ret = bdrv_snapshot_create(bs1, sn); if (ret < 0) { monitor_printf(mon, "Error while creating snapshot on '%s'\n", bdrv_get_device_name(bs1)); } } } the_end: if (saved_vm_running) vm_start(); }
14,065
qemu
40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4
1
int paio_init(void) { struct sigaction act; PosixAioState *s; int fds[2]; int ret; if (posix_aio_state) return 0; s = qemu_malloc(sizeof(PosixAioState)); sigfillset(&act.sa_mask); act.sa_flags = 0; /* do not restart syscalls to interrupt select() */ act.sa_handler = aio_signal_handler; sigaction(SIGUSR2, &act, NULL); s->first_aio = NULL; if (pipe(fds) == -1) { fprintf(stderr, "failed to create pipe\n"); return -1; } s->rfd = fds[0]; s->wfd = fds[1]; fcntl(s->rfd, F_SETFL, O_NONBLOCK); fcntl(s->wfd, F_SETFL, O_NONBLOCK); qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, posix_aio_process_queue, s); ret = pthread_attr_init(&attr); if (ret) die2(ret, "pthread_attr_init"); ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ret) die2(ret, "pthread_attr_setdetachstate"); QTAILQ_INIT(&request_list); posix_aio_state = s; return 0; }
14,066
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int set_dirty_tracking(void) { BlkMigDevState *bmds; int ret; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { bmds->dirty_bitmap = bdrv_create_dirty_bitmap(bmds->bs, BLOCK_SIZE, NULL); if (!bmds->dirty_bitmap) { ret = -errno; goto fail; } } return 0; fail: QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { if (bmds->dirty_bitmap) { bdrv_release_dirty_bitmap(bmds->bs, bmds->dirty_bitmap); } } return ret; }
14,067
FFmpeg
bb6c67bb36b136de10256f0999128df4a42f9ffc
1
static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { SliceContext *slice = link->dst->priv; int y2, ret = 0; if (slice_dir == 1) { for (y2 = y; y2 + slice->h <= y + h; y2 += slice->h) { ret = ff_draw_slice(link->dst->outputs[0], y2, slice->h, slice_dir); if (ret < 0) return ret; } if (y2 < y + h) return ff_draw_slice(link->dst->outputs[0], y2, y + h - y2, slice_dir); } else if (slice_dir == -1) { for (y2 = y + h; y2 - slice->h >= y; y2 -= slice->h) { ret = ff_draw_slice(link->dst->outputs[0], y2 - slice->h, slice->h, slice_dir); if (ret < 0) return ret; } if (y2 > y) return ff_draw_slice(link->dst->outputs[0], y, y2 - y, slice_dir); } return 0; }
14,068
qemu
5ee5993001cf32addb86a92e2ae8cb090fbc1462
1
void cpu_check_irqs(CPUSPARCState *env) { CPUState *cs; if (env->pil_in && (env->interrupt_index == 0 || (env->interrupt_index & ~15) == TT_EXTINT)) { unsigned int i; for (i = 15; i > 0; i--) { if (env->pil_in & (1 << i)) { int old_interrupt = env->interrupt_index; env->interrupt_index = TT_EXTINT | i; if (old_interrupt != env->interrupt_index) { cs = CPU(sparc_env_get_cpu(env)); trace_sun4m_cpu_interrupt(i); cpu_interrupt(cs, CPU_INTERRUPT_HARD); } break; } } } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) { cs = CPU(sparc_env_get_cpu(env)); trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15); env->interrupt_index = 0; cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); } }
14,069