project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
qemu | 9eaaf971683c99ed197fa1b7d1a3ca9baabfb3ee | 0 | static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
{
if (lhs->type != qobject_type(rhs)) {
return 0;
}
switch (lhs->type) {
case QTYPE_QINT:
return lhs->value.qint == qint_get_int(qobject_to_qint(rhs));
case QTYPE_QSTRING:
return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) == 0);
case QTYPE_QDICT: {
int i;
for (i = 0; lhs->value.qdict[i].key; i++) {
QObject *obj = qdict_get(qobject_to_qdict(rhs), lhs->value.qdict[i].key);
if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) {
return 0;
}
}
return 1;
}
case QTYPE_QLIST: {
QListCompareHelper helper;
helper.index = 0;
helper.objs = lhs->value.qlist;
helper.result = 1;
qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
return helper.result;
}
default:
break;
}
return 0;
}
| 15,068 |
qemu | becf8217deb2afc347d5172d9f30c8a8964b8b27 | 0 | static void trigger_prot_fault(CPUS390XState *env, target_ulong vaddr,
uint64_t asc, int rw, bool exc)
{
uint64_t tec;
tec = vaddr | (rw == MMU_DATA_STORE ? FS_WRITE : FS_READ) | 4 | asc >> 46;
DPRINTF("%s: trans_exc_code=%016" PRIx64 "\n", __func__, tec);
if (!exc) {
return;
}
trigger_access_exception(env, PGM_PROTECTION, ILEN_LATER_INC, tec);
}
| 15,070 |
qemu | e23e400ec62a03dea58ddb38479b4f1ef86f556d | 0 | static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res)
{
BDRVQcowState *s = bs->opaque;
uint64_t *l2_table = qemu_blockalign(bs, s->cluster_size);
int ret;
int refcount;
int i, j;
for (i = 0; i < s->l1_size; i++) {
uint64_t l1_entry = s->l1_table[i];
uint64_t l2_offset = l1_entry & L1E_OFFSET_MASK;
if (!l2_offset) {
continue;
}
refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
if (refcount < 0) {
/* don't print message nor increment check_errors */
continue;
}
if ((refcount == 1) != ((l1_entry & QCOW_OFLAG_COPIED) != 0)) {
fprintf(stderr, "ERROR OFLAG_COPIED L2 cluster: l1_index=%d "
"l1_entry=%" PRIx64 " refcount=%d\n",
i, l1_entry, refcount);
res->corruptions++;
}
ret = bdrv_pread(bs->file, l2_offset, l2_table,
s->l2_size * sizeof(uint64_t));
if (ret < 0) {
fprintf(stderr, "ERROR: Could not read L2 table: %s\n",
strerror(-ret));
res->check_errors++;
goto fail;
}
for (j = 0; j < s->l2_size; j++) {
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
int cluster_type = qcow2_get_cluster_type(l2_entry);
if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
refcount = get_refcount(bs, data_offset >> s->cluster_bits);
if (refcount < 0) {
/* don't print message nor increment check_errors */
continue;
}
if ((refcount == 1) != ((l2_entry & QCOW_OFLAG_COPIED) != 0)) {
fprintf(stderr, "ERROR OFLAG_COPIED data cluster: "
"l2_entry=%" PRIx64 " refcount=%d\n",
l2_entry, refcount);
res->corruptions++;
}
}
}
}
ret = 0;
fail:
qemu_vfree(l2_table);
return ret;
}
| 15,071 |
qemu | 6f3c90af3c50d4f839849c8ba9b6ba4e9a548c28 | 0 | static int map_f(BlockBackend *blk, int argc, char **argv)
{
int64_t offset;
int64_t nb_sectors, total_sectors;
char s1[64];
int64_t num;
int ret;
const char *retstr;
offset = 0;
total_sectors = blk_nb_sectors(blk);
if (total_sectors < 0) {
error_report("Failed to query image length: %s",
strerror(-total_sectors));
return 0;
}
nb_sectors = total_sectors;
do {
ret = map_is_allocated(blk_bs(blk), offset, nb_sectors, &num);
if (ret < 0) {
error_report("Failed to get allocation status: %s", strerror(-ret));
return 0;
} else if (!num) {
error_report("Unexpected end of image");
return 0;
}
retstr = ret ? " allocated" : "not allocated";
cvtstr(offset << 9ULL, s1, sizeof(s1));
printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
"at offset %s (%d)\n",
offset << 9ULL, num, nb_sectors, retstr, s1, ret);
offset += num;
nb_sectors -= num;
} while (offset < total_sectors);
return 0;
}
| 15,072 |
qemu | 7c560456707bfe53eb1728fcde759be7d9418b62 | 0 | fdctrl_t *fdctrl_init (qemu_irq irq, int dma_chann, int mem_mapped,
target_phys_addr_t io_base,
BlockDriverState **fds)
{
fdctrl_t *fdctrl;
int io_mem;
int i;
FLOPPY_DPRINTF("init controller\n");
fdctrl = qemu_mallocz(sizeof(fdctrl_t));
if (!fdctrl)
return NULL;
fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
if (fdctrl->fifo == NULL) {
qemu_free(fdctrl);
return NULL;
}
fdctrl->result_timer = qemu_new_timer(vm_clock,
fdctrl_result_timer, fdctrl);
fdctrl->version = 0x90; /* Intel 82078 controller */
fdctrl->irq = irq;
fdctrl->dma_chann = dma_chann;
fdctrl->io_base = io_base;
fdctrl->config = 0x60; /* Implicit seek, polling & FIFO enabled */
fdctrl->sun4m = 0;
if (fdctrl->dma_chann != -1) {
fdctrl->dma_en = 1;
DMA_register_channel(dma_chann, &fdctrl_transfer_handler, fdctrl);
} else {
fdctrl->dma_en = 0;
}
for (i = 0; i < 2; i++) {
fd_init(&fdctrl->drives[i], fds[i]);
}
fdctrl_reset(fdctrl, 0);
fdctrl->state = FD_CTRL_ACTIVE;
if (mem_mapped) {
io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write,
fdctrl);
cpu_register_physical_memory(io_base, 0x08, io_mem);
} else {
register_ioport_read((uint32_t)io_base + 0x01, 5, 1, &fdctrl_read,
fdctrl);
register_ioport_read((uint32_t)io_base + 0x07, 1, 1, &fdctrl_read,
fdctrl);
register_ioport_write((uint32_t)io_base + 0x01, 5, 1, &fdctrl_write,
fdctrl);
register_ioport_write((uint32_t)io_base + 0x07, 1, 1, &fdctrl_write,
fdctrl);
}
register_savevm("fdc", io_base, 1, fdc_save, fdc_load, fdctrl);
qemu_register_reset(fdctrl_external_reset, fdctrl);
for (i = 0; i < 2; i++) {
fd_revalidate(&fdctrl->drives[i]);
}
return fdctrl;
}
| 15,073 |
FFmpeg | 07bad27810cdd7d3171cbd542119aa051646377c | 0 | static void end_frame(AVFilterLink *inlink)
{
TransContext *trans = inlink->dst->priv;
AVFilterBufferRef *inpic = inlink->cur_buf;
AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
AVFilterLink *outlink = inlink->dst->outputs[0];
int plane;
for (plane = 0; outpic->data[plane]; plane++) {
int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;
int vsub = plane == 1 || plane == 2 ? trans->vsub : 0;
int pixstep = trans->pixsteps[plane];
int inh = inpic->video->h>>vsub;
int outw = outpic->video->w>>hsub;
int outh = outpic->video->h>>vsub;
uint8_t *out, *in;
int outlinesize, inlinesize;
int x, y;
out = outpic->data[plane]; outlinesize = outpic->linesize[plane];
in = inpic ->data[plane]; inlinesize = inpic ->linesize[plane];
if (trans->dir&1) {
in += inpic->linesize[plane] * (inh-1);
inlinesize *= -1;
}
if (trans->dir&2) {
out += outpic->linesize[plane] * (outh-1);
outlinesize *= -1;
}
for (y = 0; y < outh; y++) {
switch (pixstep) {
case 1:
for (x = 0; x < outw; x++)
out[x] = in[x*inlinesize + y];
break;
case 2:
for (x = 0; x < outw; x++)
*((uint16_t *)(out + 2*x)) = *((uint16_t *)(in + x*inlinesize + y*2));
break;
case 3:
for (x = 0; x < outw; x++) {
int32_t v = AV_RB24(in + x*inlinesize + y*3);
AV_WB24(out + 3*x, v);
}
break;
case 4:
for (x = 0; x < outw; x++)
*((uint32_t *)(out + 4*x)) = *((uint32_t *)(in + x*inlinesize + y*4));
break;
}
out += outlinesize;
}
}
avfilter_unref_buffer(inpic);
ff_draw_slice(outlink, 0, outpic->video->h, 1);
ff_end_frame(outlink);
avfilter_unref_buffer(outpic);
}
| 15,074 |
qemu | 3718d8ab65f68de2acccbe6a315907805f54e3cc | 0 | void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
void *opaque, Error **errp)
{
BlockJob *job;
if (bs->job || bdrv_in_use(bs)) {
error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
return NULL;
}
bdrv_ref(bs);
bdrv_set_in_use(bs, 1);
job = g_malloc0(driver->instance_size);
job->driver = driver;
job->bs = bs;
job->cb = cb;
job->opaque = opaque;
job->busy = true;
bs->job = job;
/* Only set speed when necessary to avoid NotSupported error */
if (speed != 0) {
Error *local_err = NULL;
block_job_set_speed(job, speed, &local_err);
if (local_err) {
bs->job = NULL;
g_free(job);
bdrv_set_in_use(bs, 0);
error_propagate(errp, local_err);
return NULL;
}
}
return job;
}
| 15,075 |
qemu | 92f9a4f13ea29de4644bd0b077643e1dff96ab29 | 0 | static int apb_pci_bridge_initfn(PCIDevice *dev)
{
int rc;
rc = pci_bridge_initfn(dev);
if (rc < 0) {
return rc;
}
pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_SUN);
pci_config_set_device_id(dev->config, PCI_DEVICE_ID_SUN_SIMBA);
/*
* command register:
* According to PCI bridge spec, after reset
* bus master bit is off
* memory space enable bit is off
* According to manual (805-1251.pdf).
* the reset value should be zero unless the boot pin is tied high
* (which is true) and thus it should be PCI_COMMAND_MEMORY.
*/
pci_set_word(dev->config + PCI_COMMAND,
PCI_COMMAND_MEMORY);
pci_set_word(dev->config + PCI_STATUS,
PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
PCI_STATUS_DEVSEL_MEDIUM);
pci_set_byte(dev->config + PCI_REVISION_ID, 0x11);
return 0;
}
| 15,076 |
qemu | 494a8ebe713055d3946183f4b395f85a18b43e9e | 0 | static int proxy_rename(FsContext *ctx, const char *oldpath,
const char *newpath)
{
int retval;
V9fsString oldname, newname;
v9fs_string_init(&oldname);
v9fs_string_init(&newname);
v9fs_string_sprintf(&oldname, "%s", oldpath);
v9fs_string_sprintf(&newname, "%s", newpath);
retval = v9fs_request(ctx->private, T_RENAME, NULL, "ss",
&oldname, &newname);
v9fs_string_free(&oldname);
v9fs_string_free(&newname);
if (retval < 0) {
errno = -retval;
}
return retval;
}
| 15,078 |
qemu | 97f90cbfe810bb153fc44bde732d9639610783bb | 0 | void helper_memalign(uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)
{
if (addr & mask) {
qemu_log("unaligned access addr=%x mask=%x, wr=%d\n",
addr, mask, wr);
if (!(env->sregs[SR_MSR] & MSR_EE)) {
return;
}
env->sregs[SR_ESR] = ESR_EC_UNALIGNED_DATA | (wr << 10) \
| (dr & 31) << 5;
if (mask == 3) {
env->sregs[SR_ESR] |= 1 << 11;
}
helper_raise_exception(EXCP_HW_EXCP);
}
}
| 15,079 |
qemu | 880a7578381d1c7ed4d41c7599ae3cc06567a824 | 0 | static void gdb_breakpoint_remove_all(CPUState *env)
{
cpu_breakpoint_remove_all(env, BP_GDB);
#ifndef CONFIG_USER_ONLY
cpu_watchpoint_remove_all(env, BP_GDB);
#endif
}
| 15,080 |
qemu | 655ed67c2a248cf0a887229d8492d6ddc0518545 | 0 | static void handle_pending_signal(CPUArchState *cpu_env, int sig)
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
abi_ulong handler;
sigset_t set;
target_sigset_t target_old_set;
struct target_sigaction *sa;
TaskState *ts = cpu->opaque;
struct emulated_sigtable *k = &ts->sigtab[sig - 1];
trace_user_handle_signal(cpu_env, sig);
/* dequeue signal */
k->pending = 0;
sig = gdb_handlesig(cpu, sig);
if (!sig) {
sa = NULL;
handler = TARGET_SIG_IGN;
} else {
sa = &sigact_table[sig - 1];
handler = sa->_sa_handler;
}
if (sig == TARGET_SIGSEGV && sigismember(&ts->signal_mask, SIGSEGV)) {
/* Guest has blocked SIGSEGV but we got one anyway. Assume this
* is a forced SIGSEGV (ie one the kernel handles via force_sig_info
* because it got a real MMU fault), and treat as if default handler.
*/
handler = TARGET_SIG_DFL;
}
if (handler == TARGET_SIG_DFL) {
/* default handler : ignore some signal. The other are job control or fatal */
if (sig == TARGET_SIGTSTP || sig == TARGET_SIGTTIN || sig == TARGET_SIGTTOU) {
kill(getpid(),SIGSTOP);
} else if (sig != TARGET_SIGCHLD &&
sig != TARGET_SIGURG &&
sig != TARGET_SIGWINCH &&
sig != TARGET_SIGCONT) {
force_sig(sig);
}
} else if (handler == TARGET_SIG_IGN) {
/* ignore sig */
} else if (handler == TARGET_SIG_ERR) {
force_sig(sig);
} else {
/* compute the blocked signals during the handler execution */
sigset_t *blocked_set;
target_to_host_sigset(&set, &sa->sa_mask);
/* SA_NODEFER indicates that the current signal should not be
blocked during the handler */
if (!(sa->sa_flags & TARGET_SA_NODEFER))
sigaddset(&set, target_to_host_signal(sig));
/* save the previous blocked signal state to restore it at the
end of the signal execution (see do_sigreturn) */
host_to_target_sigset_internal(&target_old_set, &ts->signal_mask);
/* block signals in the handler */
blocked_set = ts->in_sigsuspend ?
&ts->sigsuspend_mask : &ts->signal_mask;
sigorset(&ts->signal_mask, blocked_set, &set);
ts->in_sigsuspend = 0;
/* if the CPU is in VM86 mode, we restore the 32 bit values */
#if defined(TARGET_I386) && !defined(TARGET_X86_64)
{
CPUX86State *env = cpu_env;
if (env->eflags & VM_MASK)
save_v86_state(env);
}
#endif
/* prepare the stack frame of the virtual CPU */
#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64) \
|| defined(TARGET_OPENRISC) || defined(TARGET_TILEGX)
/* These targets do not have traditional signals. */
setup_rt_frame(sig, sa, &k->info, &target_old_set, cpu_env);
#else
if (sa->sa_flags & TARGET_SA_SIGINFO)
setup_rt_frame(sig, sa, &k->info, &target_old_set, cpu_env);
else
setup_frame(sig, sa, &target_old_set, cpu_env);
#endif
if (sa->sa_flags & TARGET_SA_RESETHAND) {
sa->_sa_handler = TARGET_SIG_DFL;
}
}
}
| 15,081 |
qemu | 786a4ea82ec9c87e3a895cf41081029b285a5fe5 | 0 | static void pxa2xx_gpio_handler_update(PXA2xxGPIOInfo *s) {
uint32_t level, diff;
int i, bit, line;
for (i = 0; i < PXA2XX_GPIO_BANKS; i ++) {
level = s->olevel[i] & s->dir[i];
for (diff = s->prev_level[i] ^ level; diff; diff ^= 1 << bit) {
bit = ffs(diff) - 1;
line = bit + 32 * i;
qemu_set_irq(s->handler[line], (level >> bit) & 1);
}
s->prev_level[i] = level;
}
}
| 15,083 |
qemu | 72cf2d4f0e181d0d3a3122e04129c58a95da713e | 0 | int kvm_init(int smp_cpus)
{
static const char upgrade_note[] =
"Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
"(see http://sourceforge.net/projects/kvm).\n";
KVMState *s;
int ret;
int i;
if (smp_cpus > 1) {
fprintf(stderr, "No SMP KVM support, use '-smp 1'\n");
return -EINVAL;
}
s = qemu_mallocz(sizeof(KVMState));
#ifdef KVM_CAP_SET_GUEST_DEBUG
TAILQ_INIT(&s->kvm_sw_breakpoints);
#endif
for (i = 0; i < ARRAY_SIZE(s->slots); i++)
s->slots[i].slot = i;
s->vmfd = -1;
s->fd = open("/dev/kvm", O_RDWR);
if (s->fd == -1) {
fprintf(stderr, "Could not access KVM kernel module: %m\n");
ret = -errno;
goto err;
}
ret = kvm_ioctl(s, KVM_GET_API_VERSION, 0);
if (ret < KVM_API_VERSION) {
if (ret > 0)
ret = -EINVAL;
fprintf(stderr, "kvm version too old\n");
goto err;
}
if (ret > KVM_API_VERSION) {
ret = -EINVAL;
fprintf(stderr, "kvm version not supported\n");
goto err;
}
s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
if (s->vmfd < 0)
goto err;
/* initially, KVM allocated its own memory and we had to jump through
* hooks to make phys_ram_base point to this. Modern versions of KVM
* just use a user allocated buffer so we can use regular pages
* unmodified. Make sure we have a sufficiently modern version of KVM.
*/
if (!kvm_check_extension(s, KVM_CAP_USER_MEMORY)) {
ret = -EINVAL;
fprintf(stderr, "kvm does not support KVM_CAP_USER_MEMORY\n%s",
upgrade_note);
goto err;
}
/* There was a nasty bug in < kvm-80 that prevents memory slots from being
* destroyed properly. Since we rely on this capability, refuse to work
* with any kernel without this capability. */
if (!kvm_check_extension(s, KVM_CAP_DESTROY_MEMORY_REGION_WORKS)) {
ret = -EINVAL;
fprintf(stderr,
"KVM kernel module broken (DESTROY_MEMORY_REGION).\n%s",
upgrade_note);
goto err;
}
#ifdef KVM_CAP_COALESCED_MMIO
s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO);
#else
s->coalesced_mmio = 0;
#endif
s->broken_set_mem_region = 1;
#ifdef KVM_CAP_JOIN_MEMORY_REGIONS_WORKS
ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_JOIN_MEMORY_REGIONS_WORKS);
if (ret > 0) {
s->broken_set_mem_region = 0;
}
#endif
ret = kvm_arch_init(s, smp_cpus);
if (ret < 0)
goto err;
kvm_state = s;
return 0;
err:
if (s) {
if (s->vmfd != -1)
close(s->vmfd);
if (s->fd != -1)
close(s->fd);
}
qemu_free(s);
return ret;
}
| 15,084 |
FFmpeg | 30df9789a9745d8e4b1afc10d1a983bfc8816eb9 | 0 | static void unpack_alpha(GetBitContext *gb, uint16_t *dst, int num_coeffs,
const int num_bits)
{
const int mask = (1 << num_bits) - 1;
int i, idx, val, alpha_val;
idx = 0;
alpha_val = mask;
do {
do {
if (get_bits1(gb))
val = get_bits(gb, num_bits);
else {
int sign;
val = get_bits(gb, num_bits == 16 ? 7 : 4);
sign = val & 1;
val = (val + 2) >> 1;
if (sign)
val = -val;
}
alpha_val = (alpha_val + val) & mask;
if (num_bits == 16)
dst[idx++] = alpha_val >> 6;
else
dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
if (idx == num_coeffs - 1)
break;
} while (get_bits1(gb));
val = get_bits(gb, 4);
if (!val)
val = get_bits(gb, 11);
if (idx + val > num_coeffs)
val = num_coeffs - idx;
if (num_bits == 16)
for (i = 0; i < val; i++)
dst[idx++] = alpha_val >> 6;
else
for (i = 0; i < val; i++)
dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
} while (idx < num_coeffs);
}
| 15,085 |
qemu | 05e7af694ce00dafdc464ca70306fa9dd6f78dcd | 0 | static int virtconsole_initfn(VirtIOSerialPort *port)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
vcon->port.dev.info);
if (port->id == 0 && !info->is_console) {
error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
return -1;
}
if (vcon->chr) {
qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
vcon);
info->have_data = flush_buf;
info->guest_open = guest_open;
info->guest_close = guest_close;
}
return 0;
}
| 15,087 |
qemu | 91cda45b69e45a089f9989979a65db3f710c9925 | 0 | static int ppc_hash32_get_physical_address(CPUPPCState *env, struct mmu_ctx_hash32 *ctx,
target_ulong eaddr, int rw,
int access_type)
{
bool real_mode = (access_type == ACCESS_CODE && msr_ir == 0)
|| (access_type != ACCESS_CODE && msr_dr == 0);
if (real_mode) {
ctx->raddr = eaddr;
ctx->prot = PAGE_READ | PAGE_EXEC | PAGE_WRITE;
return 0;
} else {
int ret = -1;
/* Try to find a BAT */
if (env->nb_BATs != 0) {
ret = ppc_hash32_get_bat(env, ctx, eaddr, rw, access_type);
}
if (ret < 0) {
/* We didn't match any BAT entry or don't have BATs */
ret = get_segment32(env, ctx, eaddr, rw, access_type);
}
return ret;
}
}
| 15,088 |
qemu | ae261c86aaed62e7acddafab8262a2bf286d40b7 | 0 | static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
BDRVVmdkState *s = bs->opaque;
int ret;
uint64_t n, index_in_cluster;
VmdkExtent *extent = NULL;
uint64_t cluster_offset;
while (nb_sectors > 0) {
extent = find_extent(s, sector_num, extent);
if (!extent) {
return -EIO;
}
ret = get_cluster_offset(
bs, extent, NULL,
sector_num << 9, 0, &cluster_offset);
index_in_cluster = sector_num % extent->cluster_sectors;
n = extent->cluster_sectors - index_in_cluster;
if (n > nb_sectors)
n = nb_sectors;
if (ret) {
/* if not allocated, try to read from parent image, if exist */
if (bs->backing_hd) {
if (!vmdk_is_cid_valid(bs))
return -EINVAL;
ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
if (ret < 0)
return ret;
} else {
memset(buf, 0, 512 * n);
}
} else {
ret = bdrv_pread(extent->file,
cluster_offset + index_in_cluster * 512,
buf, n * 512);
if (ret < 0) {
return ret;
}
}
nb_sectors -= n;
sector_num += n;
buf += n * 512;
}
return 0;
}
| 15,089 |
qemu | 741d4086c856320807a2575389d7c0505578270b | 0 | static bool migrate_params_check(MigrationParameters *params, Error **errp)
{
if (params->has_compress_level &&
(params->compress_level < 0 || params->compress_level > 9)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
"is invalid, it should be in the range of 0 to 9");
return false;
}
if (params->has_compress_threads &&
(params->compress_threads < 1 || params->compress_threads > 255)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"compress_threads",
"is invalid, it should be in the range of 1 to 255");
return false;
}
if (params->has_decompress_threads &&
(params->decompress_threads < 1 || params->decompress_threads > 255)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"decompress_threads",
"is invalid, it should be in the range of 1 to 255");
return false;
}
if (params->has_cpu_throttle_initial &&
(params->cpu_throttle_initial < 1 ||
params->cpu_throttle_initial > 99)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"cpu_throttle_initial",
"an integer in the range of 1 to 99");
return false;
}
if (params->has_cpu_throttle_increment &&
(params->cpu_throttle_increment < 1 ||
params->cpu_throttle_increment > 99)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"cpu_throttle_increment",
"an integer in the range of 1 to 99");
return false;
}
if (params->has_max_bandwidth &&
(params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) {
error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
" range of 0 to %zu bytes/second", SIZE_MAX);
return false;
}
if (params->has_downtime_limit &&
(params->downtime_limit < 0 ||
params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
"the range of 0 to %d milliseconds",
MAX_MIGRATE_DOWNTIME);
return false;
}
if (params->has_x_checkpoint_delay && (params->x_checkpoint_delay < 0)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"x_checkpoint_delay",
"is invalid, it should be positive");
return false;
}
if (params->has_x_multifd_channels &&
(params->x_multifd_channels < 1 || params->x_multifd_channels > 255)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"multifd_channels",
"is invalid, it should be in the range of 1 to 255");
return false;
}
if (params->has_x_multifd_page_count &&
(params->x_multifd_page_count < 1 ||
params->x_multifd_page_count > 10000)) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"multifd_page_count",
"is invalid, it should be in the range of 1 to 10000");
return false;
}
if (params->has_xbzrle_cache_size &&
(params->xbzrle_cache_size < qemu_target_page_size() ||
!is_power_of_2(params->xbzrle_cache_size))) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"xbzrle_cache_size",
"is invalid, it should be bigger than target page size"
" and a power of two");
return false;
}
return true;
}
| 15,090 |
qemu | 2fd5d864099dd38b43b595e9e3375dad2f76049b | 1 | int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
struct in_addr addr, int port)
{
struct ex_list *tmp_ptr;
/* First, check if the port is "bound" */
for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
if (port == tmp_ptr->ex_fport &&
addr.s_addr == tmp_ptr->ex_addr.s_addr)
return -1;
}
tmp_ptr = *ex_ptr;
*ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
(*ex_ptr)->ex_fport = port;
(*ex_ptr)->ex_addr = addr;
(*ex_ptr)->ex_pty = do_pty;
(*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
(*ex_ptr)->ex_next = tmp_ptr;
return 0;
}
| 15,091 |
qemu | 3604a76fea6ff37738d4a8f596be38407be74a83 | 1 | static void dec_sextb(DisasContext *dc)
{
LOG_DIS("sextb r%d, r%d\n", dc->r2, dc->r0);
if (!(dc->env->features & LM32_FEATURE_SIGN_EXTEND)) {
cpu_abort(dc->env, "hardware sign extender is not available\n");
}
tcg_gen_ext8s_tl(cpu_R[dc->r2], cpu_R[dc->r0]);
}
| 15,092 |
FFmpeg | 323e6fead07c75f418e4b60704a4f437bb3483b2 | 1 | static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in)
{
int i, re, im, n, n2, n4;
int16_t *rot = mdct->rot_tmp;
IComplex *x = mdct->cplx_tmp;
n = 1 << mdct->nbits;
n2 = n >> 1;
n4 = n >> 2;
/* shift to simplify computations */
for (i = 0; i <n4; i++)
rot[i] = -in[i + 3*n4];
memcpy(&rot[n4], &in[0], 3*n4*sizeof(*in));
/* pre rotation */
for (i = 0; i < n4; i++) {
re = ((int)rot[ 2*i] - (int)rot[ n-1-2*i]) >> 1;
im = -((int)rot[n2+2*i] - (int)rot[n2-1-2*i]) >> 1;
CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i]);
}
fft(mdct, x, mdct->nbits - 2);
/* post rotation */
for (i = 0; i < n4; i++) {
re = x[i].re;
im = x[i].im;
CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i]);
}
}
| 15,093 |
qemu | 2886be1b01c274570fa139748a402207482405bd | 1 | static uint32_t pm_ioport_readw(void *opaque, uint32_t addr)
{
VT686PMState *s = opaque;
uint32_t val;
addr &= 0x0f;
switch (addr) {
case 0x00:
val = acpi_pm1_evt_get_sts(&s->ar, s->ar.tmr.overflow_time);
break;
case 0x02:
val = s->ar.pm1.evt.en;
break;
case 0x04:
val = s->ar.pm1.cnt.cnt;
break;
default:
val = 0;
break;
}
DPRINTF("PM readw port=0x%04x val=0x%02x\n", addr, val);
return val;
}
| 15,095 |
FFmpeg | cf04af2086be105ff86088357b83d672d38417d9 | 1 | static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
uint8_t *properties)
{
Jpeg2000CodingStyle tmp;
int compno, ret;
if (bytestream2_get_bytes_left(&s->g) < 5)
tmp.csty = bytestream2_get_byteu(&s->g);
// get progression order
tmp.prog_order = bytestream2_get_byteu(&s->g);
tmp.nlayers = bytestream2_get_be16u(&s->g);
tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation
if ((ret = get_cox(s, &tmp)) < 0)
return ret;
for (compno = 0; compno < s->ncomponents; compno++)
if (!(properties[compno] & HAD_COC))
memcpy(c + compno, &tmp, sizeof(tmp));
return 0; | 15,096 |
FFmpeg | 4bf2e7c5f1c0ad3997fd7c9859c16db8e4e16df6 | 1 | static av_cold void construct_perm_table(TwinContext *tctx,enum FrameType ftype)
{
int block_size;
const ModeTab *mtab = tctx->mtab;
int size = tctx->avctx->channels*mtab->fmode[ftype].sub;
int16_t *tmp_perm = (int16_t *) tctx->tmp_buf;
if (ftype == FT_PPC) {
size = tctx->avctx->channels;
block_size = mtab->ppc_shape_len;
} else
block_size = mtab->size / mtab->fmode[ftype].sub;
permutate_in_line(tmp_perm, tctx->n_div[ftype], size,
block_size, tctx->length[ftype],
tctx->length_change[ftype], ftype);
transpose_perm(tctx->permut[ftype], tmp_perm, tctx->n_div[ftype],
tctx->length[ftype], tctx->length_change[ftype]);
linear_perm(tctx->permut[ftype], tctx->permut[ftype], size,
size*block_size);
}
| 15,097 |
FFmpeg | 4a9f466b997e0c44d1e304a7a9c5d5de0b0868c7 | 1 | yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
const int16_t *ubuf[2], const int16_t *vbuf[2],
const int16_t *abuf0, uint8_t *dest, int dstW,
int uvalpha, int y, enum PixelFormat target,
int hasAlpha)
{
const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
int i;
if (uvalpha < 2048) {
for (i = 0; i < (dstW >> 1); i++) {
int Y1 = (buf0[i * 2 ] + 64) >> 7;
int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
int U = (ubuf0[i] + 64) >> 7;
int V = (vbuf0[i] + 64) >> 7;
int A1, A2;
const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
*g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
*b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
if (hasAlpha) {
A1 = (abuf0[i * 2 ] + 64) >> 7;
A2 = (abuf0[i * 2 + 1] + 64) >> 7;
}
yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
r, g, b, y, target, hasAlpha);
}
} else {
const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
for (i = 0; i < (dstW >> 1); i++) {
int Y1 = (buf0[i * 2 ] + 64) >> 7;
int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
int A1, A2;
const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
*g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
*b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
if (hasAlpha) {
A1 = (abuf0[i * 2 ] + 64) >> 7;
A2 = (abuf0[i * 2 + 1] + 64) >> 7;
}
yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
r, g, b, y, target, hasAlpha);
}
}
}
| 15,098 |
qemu | cd245a19329edfcd968b00d05ad92de7a0e2daa1 | 1 | void *qemu_vmalloc(size_t size)
{
/* FIXME: this is not exactly optimal solution since VirtualAlloc
has 64Kb granularity, but at least it guarantees us that the
memory is page aligned. */
if (!size) {
abort();
}
return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
}
| 15,099 |
FFmpeg | d608a27d9e28d24ab56acc4ea6bfb13b2802035c | 0 | static int real_seek(AVFormatContext *avf, int stream,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
ConcatContext *cat = avf->priv_data;
int ret, left, right;
if (stream >= 0) {
if (stream >= avf->nb_streams)
return AVERROR(EINVAL);
rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
&min_ts, &ts, &max_ts);
}
left = 0;
right = cat->nb_files;
while (right - left > 1) {
int mid = (left + right) / 2;
if (ts < cat->files[mid].start_time)
right = mid;
else
left = mid;
}
if ((ret = open_file(avf, left)) < 0)
return ret;
ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
if (ret < 0 && !(flags & AVSEEK_FLAG_BACKWARD) &&
left < cat->nb_files - 1 &&
cat->files[left + 1].start_time < max_ts) {
if ((ret = open_file(avf, left + 1)) < 0)
return ret;
ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);
}
return ret;
}
| 15,100 |
FFmpeg | 0c9ab5ef9c1ee852c80c859c9e07efe8730b57ed | 1 | static void FUNC(dequant)(int16_t *coeffs, int16_t log2_size)
{
int shift = 15 - BIT_DEPTH - log2_size;
int x, y;
int size = 1 << log2_size;
if (shift > 0) {
int offset = 1 << (shift - 1);
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
*coeffs = (*coeffs + offset) >> shift;
coeffs++;
}
}
} else {
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
*coeffs = *coeffs << -shift;
coeffs++;
}
}
}
}
| 15,101 |
qemu | cfc87e00c22ab4ea0262c9771c803ed03d754001 | 1 | vpc_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
QEMUIOVector *qiov, int flags)
{
BDRVVPCState *s = bs->opaque;
int ret;
int64_t image_offset;
int64_t n_bytes;
int64_t bytes_done = 0;
VHDFooter *footer = (VHDFooter *) s->footer_buf;
QEMUIOVector local_qiov;
if (be32_to_cpu(footer->type) == VHD_FIXED) {
return bdrv_co_preadv(bs->file, offset, bytes, qiov, 0);
}
qemu_co_mutex_lock(&s->lock);
qemu_iovec_init(&local_qiov, qiov->niov);
while (bytes > 0) {
image_offset = get_image_offset(bs, offset, false);
n_bytes = MIN(bytes, s->block_size - (offset % s->block_size));
if (image_offset == -1) {
qemu_iovec_memset(qiov, bytes_done, 0, n_bytes);
} else {
qemu_iovec_reset(&local_qiov);
qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes);
ret = bdrv_co_preadv(bs->file, image_offset, n_bytes,
&local_qiov, 0);
if (ret < 0) {
goto fail;
}
}
bytes -= n_bytes;
offset += n_bytes;
bytes_done += n_bytes;
}
ret = 0;
fail:
qemu_iovec_destroy(&local_qiov);
qemu_co_mutex_unlock(&s->lock);
return ret;
}
| 15,102 |
qemu | c599d4d6d6e9bfdb64e54c33a22cb26e3496b96d | 1 | long do_rt_sigreturn(CPUMIPSState *env)
{
struct target_rt_sigframe *frame;
abi_ulong frame_addr;
sigset_t blocked;
frame_addr = env->active_tc.gpr[29];
trace_user_do_rt_sigreturn(env, frame_addr);
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) {
goto badframe;
}
target_to_host_sigset(&blocked, &frame->rs_uc.tuc_sigmask);
set_sigmask(&blocked);
restore_sigcontext(env, &frame->rs_uc.tuc_mcontext);
if (do_sigaltstack(frame_addr +
offsetof(struct target_rt_sigframe, rs_uc.tuc_stack),
0, get_sp_from_cpustate(env)) == -EFAULT)
goto badframe;
env->active_tc.PC = env->CP0_EPC;
mips_set_hflags_isa_mode_from_pc(env);
/* I am not sure this is right, but it seems to work
* maybe a problem with nested signals ? */
env->CP0_EPC = 0;
return -TARGET_QEMU_ESIGRETURN;
badframe:
force_sig(TARGET_SIGSEGV/*, current*/);
return 0;
}
| 15,103 |
qemu | 233aa5c2d1cf4655ffe335025a68cf5454f87dad | 1 | static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
{
CharDriverState *chr = NULL;
TCPCharDriver *s = NULL;
int fd = -1;
int is_listen;
int is_waitconnect;
int do_nodelay;
int is_unix;
int is_telnet;
is_listen = qemu_opt_get_bool(opts, "server", 0);
is_waitconnect = qemu_opt_get_bool(opts, "wait", 1);
is_telnet = qemu_opt_get_bool(opts, "telnet", 0);
do_nodelay = !qemu_opt_get_bool(opts, "delay", 1);
is_unix = qemu_opt_get(opts, "path") != NULL;
if (!is_listen)
is_waitconnect = 0;
chr = g_malloc0(sizeof(CharDriverState));
s = g_malloc0(sizeof(TCPCharDriver));
if (is_unix) {
if (is_listen) {
fd = unix_listen_opts(opts);
} else {
fd = unix_connect_opts(opts);
}
} else {
if (is_listen) {
fd = inet_listen_opts(opts, 0, NULL);
} else {
fd = inet_connect_opts(opts, true, NULL, NULL);
}
}
if (fd < 0) {
goto fail;
}
if (!is_waitconnect)
socket_set_nonblock(fd);
s->connected = 0;
s->fd = -1;
s->listen_fd = -1;
s->msgfd = -1;
s->is_unix = is_unix;
s->do_nodelay = do_nodelay && !is_unix;
chr->opaque = s;
chr->chr_write = tcp_chr_write;
chr->chr_close = tcp_chr_close;
chr->get_msgfd = tcp_get_msgfd;
chr->chr_add_client = tcp_chr_add_client;
if (is_listen) {
s->listen_fd = fd;
qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
if (is_telnet)
s->do_telnetopt = 1;
} else {
s->connected = 1;
s->fd = fd;
socket_set_nodelay(fd);
tcp_chr_connect(chr);
}
/* for "info chardev" monitor command */
chr->filename = g_malloc(256);
if (is_unix) {
snprintf(chr->filename, 256, "unix:%s%s",
qemu_opt_get(opts, "path"),
qemu_opt_get_bool(opts, "server", 0) ? ",server" : "");
} else if (is_telnet) {
snprintf(chr->filename, 256, "telnet:%s:%s%s",
qemu_opt_get(opts, "host"), qemu_opt_get(opts, "port"),
qemu_opt_get_bool(opts, "server", 0) ? ",server" : "");
} else {
snprintf(chr->filename, 256, "tcp:%s:%s%s",
qemu_opt_get(opts, "host"), qemu_opt_get(opts, "port"),
qemu_opt_get_bool(opts, "server", 0) ? ",server" : "");
}
if (is_listen && is_waitconnect) {
printf("QEMU waiting for connection on: %s\n",
chr->filename);
tcp_chr_accept(chr);
socket_set_nonblock(s->listen_fd);
}
return chr;
fail:
if (fd >= 0)
closesocket(fd);
g_free(s);
g_free(chr);
return NULL;
}
| 15,104 |
qemu | 0c460dac03e7919079525d8e24ef2c4c607c219d | 1 | void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap)
{
bool has_reply = false;
int nesting = 0;
/* Send QMP request */
socket_sendf(s->qmp_fd, fmt, ap);
/* Receive reply */
while (!has_reply || nesting > 0) {
ssize_t len;
char c;
len = read(s->qmp_fd, &c, 1);
if (len == -1 && errno == EINTR) {
continue;
}
if (len == -1 || len == 0) {
fprintf(stderr, "Broken pipe\n");
exit(1);
}
switch (c) {
case '{':
nesting++;
has_reply = true;
break;
case '}':
nesting--;
break;
}
}
}
| 15,105 |
FFmpeg | 1acd7d594c15aa491729c837ad3519d3469e620a | 0 | static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h)
{
const int mb_x = h->mb_x;
const int mb_y = h->mb_y;
const int mb_xy = h->mb_xy;
const int mb_type = h->cur_pic.f.mb_type[mb_xy];
uint8_t *dest[3];
int linesize;
int i, j, p;
int *block_offset = &h->block_offset[0];
const int transform_bypass = !SIMPLE && (h->qscale == 0 && h->sps.transform_bypass);
const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) ? 3 : 1;
for (p = 0; p < plane_count; p++) {
dest[p] = h->cur_pic.f.data[p] +
((mb_x << PIXEL_SHIFT) + mb_y * h->linesize) * 16;
h->vdsp.prefetch(dest[p] + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT),
h->linesize, 4);
}
h->list_counts[mb_xy] = h->list_count;
if (!SIMPLE && MB_FIELD) {
linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize * 2;
block_offset = &h->block_offset[48];
if (mb_y & 1) // FIXME move out of this function?
for (p = 0; p < 3; p++)
dest[p] -= h->linesize * 15;
if (FRAME_MBAFF) {
int list;
for (list = 0; list < h->list_count; list++) {
if (!USES_LIST(mb_type, list))
continue;
if (IS_16X16(mb_type)) {
int8_t *ref = &h->ref_cache[list][scan8[0]];
fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (h->mb_y & 1), 1);
} else {
for (i = 0; i < 16; i += 4) {
int ref = h->ref_cache[list][scan8[i]];
if (ref >= 0)
fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2,
8, (16 + ref) ^ (h->mb_y & 1), 1);
}
}
}
}
} else {
linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize;
}
if (!SIMPLE && IS_INTRA_PCM(mb_type)) {
if (PIXEL_SHIFT) {
const int bit_depth = h->sps.bit_depth_luma;
GetBitContext gb;
init_get_bits(&gb, (uint8_t *)h->intra_pcm_ptr, 768 * bit_depth);
for (p = 0; p < plane_count; p++)
for (i = 0; i < 16; i++) {
uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize);
for (j = 0; j < 16; j++)
tmp[j] = get_bits(&gb, bit_depth);
}
} else {
for (p = 0; p < plane_count; p++)
for (i = 0; i < 16; i++)
memcpy(dest[p] + i * linesize,
(uint8_t *)h->intra_pcm_ptr + p * 256 + i * 16, 16);
}
} else {
if (IS_INTRA(mb_type)) {
if (h->deblocking_filter)
xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,
linesize, 1, 1, SIMPLE, PIXEL_SHIFT);
for (p = 0; p < plane_count; p++)
hl_decode_mb_predict_luma(h, mb_type, 1, SIMPLE,
transform_bypass, PIXEL_SHIFT,
block_offset, linesize, dest[p], p);
if (h->deblocking_filter)
xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,
linesize, 0, 1, SIMPLE, PIXEL_SHIFT);
} else {
FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2],
h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,
h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,
h->h264dsp.weight_h264_pixels_tab,
h->h264dsp.biweight_h264_pixels_tab);
}
for (p = 0; p < plane_count; p++)
hl_decode_mb_idct_luma(h, mb_type, 1, SIMPLE, transform_bypass,
PIXEL_SHIFT, block_offset, linesize,
dest[p], p);
if (h->cbp || IS_INTRA(mb_type)) {
h->dsp.clear_blocks(h->mb);
h->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT));
}
}
}
| 15,107 |
FFmpeg | 875efafac8afe22971c87fc7dfee83d27364ab50 | 0 | static void msvideo1_decode_8bit(Msvideo1Context *s)
{
int block_ptr, pixel_ptr;
int total_blocks;
int pixel_x, pixel_y; /* pixel width and height iterators */
int block_x, block_y; /* block width and height iterators */
int blocks_wide, blocks_high; /* width and height in 4x4 blocks */
int block_inc;
int row_dec;
/* decoding parameters */
int stream_ptr;
unsigned char byte_a, byte_b;
unsigned short flags;
int skip_blocks;
unsigned char colors[8];
unsigned char *pixels = s->frame.data[0];
unsigned char *prev_pixels = s->prev_frame.data[0];
int stride = s->frame.linesize[0];
stream_ptr = 0;
skip_blocks = 0;
blocks_wide = s->avctx->width / 4;
blocks_high = s->avctx->height / 4;
total_blocks = blocks_wide * blocks_high;
block_inc = 4;
row_dec = stride + 4;
for (block_y = blocks_high; block_y > 0; block_y--) {
block_ptr = ((block_y * 4) - 1) * stride;
for (block_x = blocks_wide; block_x > 0; block_x--) {
/* check if this block should be skipped */
if (skip_blocks) {
COPY_PREV_BLOCK();
block_ptr += block_inc;
skip_blocks--;
total_blocks--;
continue;
}
pixel_ptr = block_ptr;
/* get the next two bytes in the encoded data stream */
CHECK_STREAM_PTR(2);
byte_a = s->buf[stream_ptr++];
byte_b = s->buf[stream_ptr++];
/* check if the decode is finished */
if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0))
return;
else if ((byte_b & 0xFC) == 0x84) {
/* skip code, but don't count the current block */
skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
COPY_PREV_BLOCK();
} else if (byte_b < 0x80) {
/* 2-color encoding */
flags = (byte_b << 8) | byte_a;
CHECK_STREAM_PTR(2);
colors[0] = s->buf[stream_ptr++];
colors[1] = s->buf[stream_ptr++];
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
pixels[pixel_ptr++] = colors[(flags & 0x1) ^ 1];
pixel_ptr -= row_dec;
}
} else if (byte_b >= 0x90) {
/* 8-color encoding */
flags = (byte_b << 8) | byte_a;
CHECK_STREAM_PTR(8);
memcpy(colors, &s->buf[stream_ptr], 8);
stream_ptr += 8;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1)
pixels[pixel_ptr++] =
colors[((pixel_y & 0x2) << 1) +
(pixel_x & 0x2) + ((flags & 0x1) ^ 1)];
pixel_ptr -= row_dec;
}
} else {
/* 1-color encoding */
colors[0] = byte_a;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++)
pixels[pixel_ptr++] = colors[0];
pixel_ptr -= row_dec;
}
}
block_ptr += block_inc;
total_blocks--;
}
}
/* make the palette available on the way out */
if (s->avctx->pix_fmt == PIX_FMT_PAL8)
memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
}
| 15,109 |
FFmpeg | ef5994e09d07ace62a672fcdc84761231288edad | 1 | static int lrc_read_header(AVFormatContext *s)
{
LRCContext *lrc = s->priv_data;
AVBPrint line;
AVStream *st;
st = avformat_new_stream(s, NULL);
if(!st) {
return AVERROR(ENOMEM);
}
avpriv_set_pts_info(st, 64, 1, 1000);
lrc->ts_offset = 0;
st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codecpar->codec_id = AV_CODEC_ID_TEXT;
av_bprint_init(&line, 0, AV_BPRINT_SIZE_UNLIMITED);
while(!avio_feof(s->pb)) {
int64_t pos = read_line(&line, s->pb);
int64_t header_offset = find_header(line.str);
if(header_offset >= 0) {
char *comma_offset = strchr(line.str, ':');
if(comma_offset) {
char *right_bracket_offset = strchr(line.str, ']');
if(!right_bracket_offset) {
continue;
}
*right_bracket_offset = *comma_offset = '\0';
if(strcmp(line.str + 1, "offset") ||
sscanf(comma_offset + 1, "%"SCNd64, &lrc->ts_offset) != 1) {
av_dict_set(&s->metadata, line.str + 1, comma_offset + 1, 0);
}
*comma_offset = ':';
*right_bracket_offset = ']';
}
} else {
AVPacket *sub;
int64_t ts_start = AV_NOPTS_VALUE;
int64_t ts_stroffset = 0;
int64_t ts_stroffset_incr = 0;
int64_t ts_strlength = count_ts(line.str);
while((ts_stroffset_incr = read_ts(line.str + ts_stroffset,
&ts_start)) != 0) {
ts_stroffset += ts_stroffset_incr;
sub = ff_subtitles_queue_insert(&lrc->q, line.str + ts_strlength,
line.len - ts_strlength, 0);
if(!sub) {
return AVERROR(ENOMEM);
}
sub->pos = pos;
sub->pts = ts_start - lrc->ts_offset;
sub->duration = -1;
}
}
}
ff_subtitles_queue_finalize(s, &lrc->q);
ff_metadata_conv_ctx(s, NULL, ff_lrc_metadata_conv);
return 0;
} | 15,110 |
FFmpeg | ff3db937ef3aa30046a3936146f86ad48ee2ff90 | 1 | static int asf_write_header1(AVFormatContext *s, int64_t file_size,
int64_t data_chunk_size)
{
ASFContext *asf = s->priv_data;
AVIOContext *pb = s->pb;
AVDictionaryEntry *tags[5];
int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
int has_title;
int metadata_count;
AVCodecParameters *par;
int64_t header_offset, cur_pos, hpos;
int bit_rate;
int64_t duration;
ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL);
tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
duration = asf->duration + PREROLL_TIME * 10000;
has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
metadata_count = av_dict_count(s->metadata);
bit_rate = 0;
for (n = 0; n < s->nb_streams; n++) {
par = s->streams[n]->codecpar;
avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
bit_rate += par->bit_rate;
}
if (asf->is_streamed) {
put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
}
put_guid(pb, &ff_asf_header);
avio_wl64(pb, -1); /* header length, will be patched after */
avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
avio_w8(pb, 1); /* ??? */
avio_w8(pb, 2); /* ??? */
/* file header */
header_offset = avio_tell(pb);
hpos = put_header(pb, &ff_asf_file_header);
put_guid(pb, &ff_asf_my_guid);
avio_wl64(pb, file_size);
file_time = 0;
avio_wl64(pb, unix_to_file_time(file_time));
avio_wl64(pb, asf->nb_packets); /* number of packets */
avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
avio_wl64(pb, PREROLL_TIME); /* start time stamp */
avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
avio_wl32(pb, s->packet_size); /* packet size */
avio_wl32(pb, s->packet_size); /* packet size */
avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
end_header(pb, hpos);
/* unknown headers */
hpos = put_header(pb, &ff_asf_head1_guid);
put_guid(pb, &ff_asf_head2_guid);
avio_wl32(pb, 6);
avio_wl16(pb, 0);
end_header(pb, hpos);
/* title and other infos */
if (has_title) {
int len;
uint8_t *buf;
AVIOContext *dyn_buf;
if (avio_open_dyn_buf(&dyn_buf) < 0)
return AVERROR(ENOMEM);
hpos = put_header(pb, &ff_asf_comment_header);
for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
avio_wl16(pb, len);
}
len = avio_close_dyn_buf(dyn_buf, &buf);
avio_write(pb, buf, len);
av_freep(&buf);
end_header(pb, hpos);
}
if (metadata_count) {
AVDictionaryEntry *tag = NULL;
hpos = put_header(pb, &ff_asf_extended_content_header);
avio_wl16(pb, metadata_count);
while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
put_str16(pb, tag->key);
avio_wl16(pb, 0);
put_str16(pb, tag->value);
}
end_header(pb, hpos);
}
/* chapters using ASF markers */
if (!asf->is_streamed && s->nb_chapters) {
int ret;
if (ret = asf_write_markers(s))
return ret;
}
/* stream headers */
for (n = 0; n < s->nb_streams; n++) {
int64_t es_pos;
// ASFStream *stream = &asf->streams[n];
par = s->streams[n]->codecpar;
asf->streams[n].num = n + 1;
asf->streams[n].seq = 0;
switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
wav_extra_size = 0;
extra_size = 18 + wav_extra_size;
extra_size2 = 8;
break;
default:
case AVMEDIA_TYPE_VIDEO:
wav_extra_size = par->extradata_size;
extra_size = 0x33 + wav_extra_size;
extra_size2 = 0;
break;
}
hpos = put_header(pb, &ff_asf_stream_header);
if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
put_guid(pb, &ff_asf_audio_stream);
put_guid(pb, &ff_asf_audio_conceal_spread);
} else {
put_guid(pb, &ff_asf_video_stream);
put_guid(pb, &ff_asf_video_conceal_none);
}
avio_wl64(pb, 0); /* ??? */
es_pos = avio_tell(pb);
avio_wl32(pb, extra_size); /* wav header len */
avio_wl32(pb, extra_size2); /* additional data len */
avio_wl16(pb, n + 1); /* stream number */
avio_wl32(pb, 0); /* ??? */
if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
/* WAVEFORMATEX header */
int wavsize = ff_put_wav_header(s, pb, par);
if (wavsize < 0)
return -1;
if (wavsize != extra_size) {
cur_pos = avio_tell(pb);
avio_seek(pb, es_pos, SEEK_SET);
avio_wl32(pb, wavsize); /* wav header len */
avio_seek(pb, cur_pos, SEEK_SET);
}
/* ERROR Correction */
avio_w8(pb, 0x01);
if (par->codec_id == AV_CODEC_ID_ADPCM_G726 || !par->block_align) {
avio_wl16(pb, 0x0190);
avio_wl16(pb, 0x0190);
} else {
avio_wl16(pb, par->block_align);
avio_wl16(pb, par->block_align);
}
avio_wl16(pb, 0x01);
avio_w8(pb, 0x00);
} else {
avio_wl32(pb, par->width);
avio_wl32(pb, par->height);
avio_w8(pb, 2); /* ??? */
avio_wl16(pb, 40 + par->extradata_size); /* size */
/* BITMAPINFOHEADER header */
ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 1);
}
end_header(pb, hpos);
}
/* media comments */
hpos = put_header(pb, &ff_asf_codec_comment_header);
put_guid(pb, &ff_asf_codec_comment1_header);
avio_wl32(pb, s->nb_streams);
for (n = 0; n < s->nb_streams; n++) {
const AVCodecDescriptor *codec_desc;
const char *desc;
par = s->streams[n]->codecpar;
codec_desc = avcodec_descriptor_get(par->codec_id);
if (par->codec_type == AVMEDIA_TYPE_AUDIO)
avio_wl16(pb, 2);
else if (par->codec_type == AVMEDIA_TYPE_VIDEO)
avio_wl16(pb, 1);
else
avio_wl16(pb, -1);
if (par->codec_id == AV_CODEC_ID_WMAV2)
desc = "Windows Media Audio V8";
else
desc = codec_desc ? codec_desc->name : NULL;
if (desc) {
AVIOContext *dyn_buf;
uint8_t *buf;
int len;
if (avio_open_dyn_buf(&dyn_buf) < 0)
return AVERROR(ENOMEM);
avio_put_str16le(dyn_buf, desc);
len = avio_close_dyn_buf(dyn_buf, &buf);
avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
avio_write(pb, buf, len);
av_freep(&buf);
} else
avio_wl16(pb, 0);
avio_wl16(pb, 0); /* no parameters */
/* id */
if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
avio_wl16(pb, 2);
avio_wl16(pb, par->codec_tag);
} else {
avio_wl16(pb, 4);
avio_wl32(pb, par->codec_tag);
}
if (!par->codec_tag)
return -1;
}
end_header(pb, hpos);
/* patch the header size fields */
cur_pos = avio_tell(pb);
header_size = cur_pos - header_offset;
if (asf->is_streamed) {
header_size += 8 + 30 + DATA_HEADER_SIZE;
avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
avio_wl16(pb, header_size);
avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
avio_wl16(pb, header_size);
header_size -= 8 + 30 + DATA_HEADER_SIZE;
}
header_size += 24 + 6;
avio_seek(pb, header_offset - 14, SEEK_SET);
avio_wl64(pb, header_size);
avio_seek(pb, cur_pos, SEEK_SET);
/* movie chunk, followed by packets of packet_size */
asf->data_offset = cur_pos;
put_guid(pb, &ff_asf_data_header);
avio_wl64(pb, data_chunk_size);
put_guid(pb, &ff_asf_my_guid);
avio_wl64(pb, asf->nb_packets); /* nb packets */
avio_w8(pb, 1); /* ??? */
avio_w8(pb, 1); /* ??? */
return 0;
}
| 15,111 |
qemu | baf35cb90204d75404892aa4e52628ae7a00669b | 1 | void qemu_aio_wait(void)
{
sigset_t set;
int nb_sigs;
#if !defined(QEMU_IMG) && !defined(QEMU_NBD)
if (qemu_bh_poll())
return;
#endif
sigemptyset(&set);
sigaddset(&set, aio_sig_num);
sigwait(&set, &nb_sigs);
qemu_aio_poll();
}
| 15,112 |
qemu | 0752706de257b38763006ff5bb6b39a97e669ba2 | 1 | static void config_error(Monitor *mon, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (mon) {
monitor_vprintf(mon, fmt, ap);
} else {
fprintf(stderr, "qemu: ");
vfprintf(stderr, fmt, ap);
exit(1);
}
va_end(ap);
}
| 15,113 |
qemu | 38f3ef574b48afc507c6f636ae4393fd36bda072 | 1 | static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov)
{
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
}
| 15,114 |
qemu | b7b5233ad7fdd9985bb6d05b7919f3a20723ff2c | 1 | void g_free(void *ptr)
{
/* FIXME: We should unmark the reserved pages here. However this gets
complicated when one target page spans multiple host pages, so we
don't bother. */
size_t *p;
p = (size_t *)((char *)ptr - 16);
munmap(p, *p);
}
| 15,117 |
qemu | 5c6c0e513600ba57c3e73b7151d3c0664438f7b5 | 1 | static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
{
SCSIRequest *req;
req = scsi_req_alloc(sizeof(SCSIGenericReq), d, tag, lun);
return DO_UPCAST(SCSIGenericReq, req, req);
}
| 15,118 |
qemu | 69179fe2fc0b91f68699012ba72d329e74ff629e | 1 | static void test_reconnect(void)
{
gchar *path = g_strdup_printf("/%s/vhost-user/reconnect/subprocess",
qtest_get_arch());
g_test_trap_subprocess(path, 0, 0);
g_test_trap_assert_passed();
} | 15,119 |
qemu | fcf73f66a67f5e58c18216f8c8651e38cf4d90af | 1 | int64_t qdict_get_try_int(const QDict *qdict, const char *key,
int64_t def_value)
{
QObject *obj;
obj = qdict_get(qdict, key);
if (!obj || qobject_type(obj) != QTYPE_QINT)
return def_value;
return qint_get_int(qobject_to_qint(obj));
}
| 15,120 |
FFmpeg | 7f526efd17973ec6d2204f7a47b6923e2be31363 | 1 | static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, int width)
{
#ifdef HAVE_MMX
asm volatile(
"mov %2, %%"REG_a" \n\t"
"movq "MANGLE(bgr2YCoeff)", %%mm6 \n\t"
"movq "MANGLE(w1111)", %%mm5 \n\t"
"pxor %%mm7, %%mm7 \n\t"
"lea (%%"REG_a", %%"REG_a", 2), %%"REG_b"\n\t"
".balign 16 \n\t"
"1: \n\t"
PREFETCH" 64(%0, %%"REG_b") \n\t"
"movd (%0, %%"REG_b"), %%mm0 \n\t"
"movd 3(%0, %%"REG_b"), %%mm1 \n\t"
"punpcklbw %%mm7, %%mm0 \n\t"
"punpcklbw %%mm7, %%mm1 \n\t"
"movd 6(%0, %%"REG_b"), %%mm2 \n\t"
"movd 9(%0, %%"REG_b"), %%mm3 \n\t"
"punpcklbw %%mm7, %%mm2 \n\t"
"punpcklbw %%mm7, %%mm3 \n\t"
"pmaddwd %%mm6, %%mm0 \n\t"
"pmaddwd %%mm6, %%mm1 \n\t"
"pmaddwd %%mm6, %%mm2 \n\t"
"pmaddwd %%mm6, %%mm3 \n\t"
#ifndef FAST_BGR2YV12
"psrad $8, %%mm0 \n\t"
"psrad $8, %%mm1 \n\t"
"psrad $8, %%mm2 \n\t"
"psrad $8, %%mm3 \n\t"
#endif
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"pmaddwd %%mm5, %%mm0 \n\t"
"pmaddwd %%mm5, %%mm2 \n\t"
"packssdw %%mm2, %%mm0 \n\t"
"psraw $7, %%mm0 \n\t"
"movd 12(%0, %%"REG_b"), %%mm4 \n\t"
"movd 15(%0, %%"REG_b"), %%mm1 \n\t"
"punpcklbw %%mm7, %%mm4 \n\t"
"punpcklbw %%mm7, %%mm1 \n\t"
"movd 18(%0, %%"REG_b"), %%mm2 \n\t"
"movd 21(%0, %%"REG_b"), %%mm3 \n\t"
"punpcklbw %%mm7, %%mm2 \n\t"
"punpcklbw %%mm7, %%mm3 \n\t"
"pmaddwd %%mm6, %%mm4 \n\t"
"pmaddwd %%mm6, %%mm1 \n\t"
"pmaddwd %%mm6, %%mm2 \n\t"
"pmaddwd %%mm6, %%mm3 \n\t"
#ifndef FAST_BGR2YV12
"psrad $8, %%mm4 \n\t"
"psrad $8, %%mm1 \n\t"
"psrad $8, %%mm2 \n\t"
"psrad $8, %%mm3 \n\t"
#endif
"packssdw %%mm1, %%mm4 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"pmaddwd %%mm5, %%mm4 \n\t"
"pmaddwd %%mm5, %%mm2 \n\t"
"add $24, %%"REG_b" \n\t"
"packssdw %%mm2, %%mm4 \n\t"
"psraw $7, %%mm4 \n\t"
"packuswb %%mm4, %%mm0 \n\t"
"paddusb "MANGLE(bgr2YOffset)", %%mm0 \n\t"
"movq %%mm0, (%1, %%"REG_a") \n\t"
"add $8, %%"REG_a" \n\t"
" js 1b \n\t"
: : "r" (src+width*3), "r" (dst+width), "g" ((long)-width)
: "%"REG_a, "%"REG_b
);
#else
int i;
for(i=0; i<width; i++)
{
int b= src[i*3+0];
int g= src[i*3+1];
int r= src[i*3+2];
dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
}
#endif
}
| 15,121 |
FFmpeg | 83f238cbf0c038245d2b2dffa5beb0916e7c36d2 | 0 | void dsputil_init_armv4l(void)
{
// ff_idct = j_rev_dct_ARM;
}
| 15,122 |
FFmpeg | 857cd1f33bcf86005529af2a77f861f884327be5 | 0 | static void RENAME(resample_one)(DELEM *dst, const DELEM *src,
int dst_size, int64_t index2, int64_t incr)
{
int dst_index;
for (dst_index = 0; dst_index < dst_size; dst_index++) {
dst[dst_index] = src[index2 >> 32];
index2 += incr;
}
}
| 15,123 |
qemu | 4557117d9eed8cadc360aec23b42fc39a7011864 | 1 | static int qemu_gluster_create(const char *filename,
QEMUOptionParameter *options, Error **errp)
{
struct glfs *glfs;
struct glfs_fd *fd;
int ret = 0;
int prealloc = 0;
int64_t total_size = 0;
GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
glfs = qemu_gluster_init(gconf, filename, errp);
if (!glfs) {
ret = -EINVAL;
goto out;
}
while (options && options->name) {
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
if (!options->value.s || !strcmp(options->value.s, "off")) {
prealloc = 0;
} else if (!strcmp(options->value.s, "full") &&
gluster_supports_zerofill()) {
prealloc = 1;
} else {
error_setg(errp, "Invalid preallocation mode: '%s'"
" or GlusterFS doesn't support zerofill API",
options->value.s);
ret = -EINVAL;
goto out;
}
}
options++;
}
fd = glfs_creat(glfs, gconf->image,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
if (!fd) {
ret = -errno;
} else {
if (!glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE)) {
if (prealloc && qemu_gluster_zerofill(fd, 0,
total_size * BDRV_SECTOR_SIZE)) {
ret = -errno;
}
} else {
ret = -errno;
}
if (glfs_close(fd) != 0) {
ret = -errno;
}
}
out:
qemu_gluster_gconf_free(gconf);
if (glfs) {
glfs_fini(glfs);
}
return ret;
}
| 15,126 |
qemu | c3e10c7b4377c1cbc0a4fbc12312c2cf41c0cda7 | 1 | void OPPROTO op_subfme (void)
{
T0 = ~T0 + xer_ca - 1;
if (likely((uint32_t)T0 != (uint32_t)-1))
xer_ca = 1;
RETURN();
}
| 15,127 |
qemu | 6bdcc018a6ed760b9dfe43539124e420aed83092 | 1 | int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags)
{
ssize_t ret;
NBDClientSession *client = nbd_get_client_session(bs);
NBDRequest request = {
.type = NBD_CMD_WRITE_ZEROES,
.from = offset,
.len = count,
};
NBDReply reply;
if (!(client->nbdflags & NBD_FLAG_SEND_WRITE_ZEROES)) {
return -ENOTSUP;
}
if (flags & BDRV_REQ_FUA) {
assert(client->nbdflags & NBD_FLAG_SEND_FUA);
request.flags |= NBD_CMD_FLAG_FUA;
}
if (!(flags & BDRV_REQ_MAY_UNMAP)) {
request.flags |= NBD_CMD_FLAG_NO_HOLE;
}
nbd_coroutine_start(client, &request);
ret = nbd_co_send_request(bs, &request, NULL);
if (ret < 0) {
reply.error = -ret;
} else {
nbd_co_receive_reply(client, &request, &reply, NULL);
}
nbd_coroutine_end(bs, &request);
return -reply.error;
}
| 15,128 |
qemu | 4f4321c11ff6e98583846bfd6f0e81954924b003 | 1 | 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->len = len;
usb_generic_async_ctrl_complete(&dev->dev, aurb->packet);
}
async_free(dev, aurb);
free(data);
}
| 15,129 |
FFmpeg | e5c7229999182ad1cef13b9eca050dba7a5a08da | 0 | int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
{
if (avctx->internal->pkt) {
frame->pkt_pts = avctx->internal->pkt->pts;
av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos);
av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration);
av_frame_set_pkt_size (frame, avctx->internal->pkt->size);
} else {
frame->pkt_pts = AV_NOPTS_VALUE;
av_frame_set_pkt_pos (frame, -1);
av_frame_set_pkt_duration(frame, 0);
av_frame_set_pkt_size (frame, -1);
}
frame->reordered_opaque = avctx->reordered_opaque;
switch (avctx->codec->type) {
case AVMEDIA_TYPE_VIDEO:
if (frame->format < 0)
frame->format = avctx->pix_fmt;
if (!frame->sample_aspect_ratio.num)
frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
if (av_frame_get_colorspace(frame) == AVCOL_SPC_UNSPECIFIED)
av_frame_set_colorspace(frame, avctx->colorspace);
if (av_frame_get_color_range(frame) == AVCOL_RANGE_UNSPECIFIED)
av_frame_set_color_range(frame, avctx->color_range);
break;
case AVMEDIA_TYPE_AUDIO:
if (!frame->sample_rate)
frame->sample_rate = avctx->sample_rate;
if (frame->format < 0)
frame->format = avctx->sample_fmt;
if (!frame->channel_layout) {
if (avctx->channel_layout) {
if (av_get_channel_layout_nb_channels(avctx->channel_layout) !=
avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
"configuration.\n");
return AVERROR(EINVAL);
}
frame->channel_layout = avctx->channel_layout;
} else {
if (avctx->channels > FF_SANE_NB_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
avctx->channels);
return AVERROR(ENOSYS);
}
}
}
av_frame_set_channels(frame, avctx->channels);
break;
}
return 0;
}
| 15,131 |
FFmpeg | 8f618f4c048e3579b62768665c255b89bd99b89f | 1 | AVFilterContext *avfilter_open(AVFilter *filter, char *inst_name)
{
AVFilterContext *ret = av_malloc(sizeof(AVFilterContext));
ret->av_class = av_mallocz(sizeof(AVClass));
ret->av_class->item_name = filter_name;
ret->filter = filter;
ret->name = inst_name ? av_strdup(inst_name) : NULL;
ret->priv = av_mallocz(filter->priv_size);
ret->input_count = pad_count(filter->inputs);
ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count);
memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count);
ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
ret->output_count = pad_count(filter->outputs);
ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count);
memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count);
ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
return ret;
}
| 15,135 |
qemu | 2caa9e9d2e0f356cc244bc41ce1d3e81663f6782 | 1 | static int vnc_zlib_stop(VncState *vs)
{
z_streamp zstream = &vs->zlib.stream;
int previous_out;
// switch back to normal output/zlib buffers
vs->zlib.zlib = vs->output;
vs->output = vs->zlib.tmp;
// compress the zlib buffer
// initialize the stream
// XXX need one stream per session
if (zstream->opaque != vs) {
int err;
VNC_DEBUG("VNC: initializing zlib stream\n");
VNC_DEBUG("VNC: opaque = %p | vs = %p\n", zstream->opaque, vs);
zstream->zalloc = vnc_zlib_zalloc;
zstream->zfree = vnc_zlib_zfree;
err = deflateInit2(zstream, vs->tight.compression, Z_DEFLATED, MAX_WBITS,
MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
fprintf(stderr, "VNC: error initializing zlib\n");
return -1;
}
vs->zlib.level = vs->tight.compression;
zstream->opaque = vs;
}
if (vs->tight.compression != vs->zlib.level) {
if (deflateParams(zstream, vs->tight.compression,
Z_DEFAULT_STRATEGY) != Z_OK) {
return -1;
}
vs->zlib.level = vs->tight.compression;
}
// reserve memory in output buffer
buffer_reserve(&vs->output, vs->zlib.zlib.offset + 64);
// set pointers
zstream->next_in = vs->zlib.zlib.buffer;
zstream->avail_in = vs->zlib.zlib.offset;
zstream->next_out = vs->output.buffer + vs->output.offset;
zstream->avail_out = vs->output.capacity - vs->output.offset;
zstream->data_type = Z_BINARY;
previous_out = zstream->total_out;
// start encoding
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
fprintf(stderr, "VNC: error during zlib compression\n");
return -1;
}
vs->output.offset = vs->output.capacity - zstream->avail_out;
return zstream->total_out - previous_out;
}
| 15,137 |
qemu | 45bbbb466cf4a6280076ea5a51f67ef5bedee345 | 1 | void OPPROTO op_divw_AX_T0(void)
{
unsigned int num, den, q, r;
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
den = (T0 & 0xffff);
if (den == 0) {
raise_exception(EXCP00_DIVZ);
}
q = (num / den) & 0xffff;
r = (num % den) & 0xffff;
EAX = (EAX & ~0xffff) | q;
EDX = (EDX & ~0xffff) | r;
}
| 15,138 |
FFmpeg | 7596fc3d4b616318ac42a6cc011fe20f3ff7aaa9 | 1 | static void fic_draw_cursor(AVCodecContext *avctx, int cur_x, int cur_y)
{
FICContext *ctx = avctx->priv_data;
uint8_t *ptr = ctx->cursor_buf;
uint8_t *dstptr[3];
uint8_t planes[4][1024];
uint8_t chroma[3][256];
int i, j, p;
/* Convert to YUVA444. */
for (i = 0; i < 1024; i++) {
planes[0][i] = av_clip_uint8((( 25 * ptr[0] + 129 * ptr[1] + 66 * ptr[2]) / 255) + 16);
planes[1][i] = av_clip_uint8(((-38 * ptr[0] + 112 * ptr[1] + -74 * ptr[2]) / 255) + 128);
planes[2][i] = av_clip_uint8(((-18 * ptr[0] + 112 * ptr[1] + -94 * ptr[2]) / 255) + 128);
planes[3][i] = ptr[3];
ptr += 4;
}
/* Subsample chroma. */
for (i = 0; i < 32; i += 2)
for (j = 0; j < 32; j += 2)
for (p = 0; p < 3; p++)
chroma[p][16 * (i / 2) + j / 2] = (planes[p + 1][32 * i + j ] +
planes[p + 1][32 * i + j + 1] +
planes[p + 1][32 * (i + 1) + j ] +
planes[p + 1][32 * (i + 1) + j + 1]) / 4;
/* Seek to x/y pos of cursor. */
for (i = 0; i < 3; i++)
dstptr[i] = ctx->final_frame->data[i] +
(ctx->final_frame->linesize[i] * (cur_y >> !!i)) +
(cur_x >> !!i) + !!i;
/* Copy. */
for (i = 0; i < FFMIN(32, avctx->height - cur_y) - 1; i += 2) {
int lsize = FFMIN(32, avctx->width - cur_x);
int csize = lsize / 2;
fic_alpha_blend(dstptr[0],
planes[0] + i * 32, lsize, planes[3] + i * 32);
fic_alpha_blend(dstptr[0] + ctx->final_frame->linesize[0],
planes[0] + (i + 1) * 32, lsize, planes[3] + (i + 1) * 32);
fic_alpha_blend(dstptr[1],
chroma[0] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);
fic_alpha_blend(dstptr[2],
chroma[1] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);
dstptr[0] += ctx->final_frame->linesize[0] * 2;
dstptr[1] += ctx->final_frame->linesize[1];
dstptr[2] += ctx->final_frame->linesize[2];
}
}
| 15,139 |
FFmpeg | 88e7a4d18c63799a21dff4a570ceb8008e310820 | 1 | static int decode_ref_pic_list_reordering(H264Context *h){
MpegEncContext * const s = &h->s;
int list, index;
print_short_term(h);
print_long_term(h);
if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func
for(list=0; list<2; list++){
memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);
if(get_bits1(&s->gb)){
int pred= h->curr_pic_num;
for(index=0; ; index++){
int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb);
int pic_id;
int i;
Picture *ref = NULL;
if(reordering_of_pic_nums_idc==3)
break;
if(index >= h->ref_count[list]){
av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n");
return -1;
}
if(reordering_of_pic_nums_idc<3){
if(reordering_of_pic_nums_idc<2){
const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1;
if(abs_diff_pic_num >= h->max_pic_num){
av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n");
return -1;
}
if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num;
else pred+= abs_diff_pic_num;
pred &= h->max_pic_num - 1;
for(i= h->short_ref_count-1; i>=0; i--){
ref = h->short_ref[i];
assert(ref->reference == 3);
assert(!ref->long_ref);
if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer
break;
}
if(i>=0)
ref->pic_id= ref->frame_num;
}else{
pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx
ref = h->long_ref[pic_id];
if(ref){
ref->pic_id= pic_id;
assert(ref->reference == 3);
assert(ref->long_ref);
i=0;
}else{
i=-1;
}
}
if (i < 0) {
av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n");
memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME
} else {
for(i=index; i+1<h->ref_count[list]; i++){
if(ref->long_ref == h->ref_list[list][i].long_ref && ref->pic_id == h->ref_list[list][i].pic_id)
break;
}
for(; i > index; i--){
h->ref_list[list][i]= h->ref_list[list][i-1];
}
h->ref_list[list][index]= *ref;
}
}else{
av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");
return -1;
}
}
}
if(h->slice_type!=B_TYPE) break;
}
for(list=0; list<2; list++){
for(index= 0; index < h->ref_count[list]; index++){
if(!h->ref_list[list][index].data[0])
h->ref_list[list][index]= s->current_picture;
}
if(h->slice_type!=B_TYPE) break;
}
if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred)
direct_dist_scale_factor(h);
direct_ref_list_init(h);
return 0;
}
| 15,140 |
qemu | 15fa08f8451babc88d733bd411d4c94976f9d0f8 | 1 | TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *old_op,
TCGOpcode opc, int nargs)
{
int oi = s->gen_next_op_idx;
int prev = old_op->prev;
int next = old_op - s->gen_op_buf;
TCGOp *new_op;
tcg_debug_assert(oi < OPC_BUF_SIZE);
s->gen_next_op_idx = oi + 1;
new_op = &s->gen_op_buf[oi];
*new_op = (TCGOp){
.opc = opc,
.prev = prev,
.next = next
};
s->gen_op_buf[prev].next = oi;
old_op->prev = oi;
return new_op;
}
| 15,141 |
FFmpeg | c23acbaed40101c677dfcfbbfe0d2c230a8e8f44 | 1 | void FUNCC(ff_h264_idct8_dc_add)(uint8_t *_dst, DCTELEM *block, int stride){
int i, j;
int dc = (((dctcoef*)block)[0] + 32) >> 6;
INIT_CLIP
pixel *dst = (pixel*)_dst;
stride /= sizeof(pixel);
for( j = 0; j < 8; j++ )
{
for( i = 0; i < 8; i++ )
dst[i] = CLIP( dst[i] + dc );
dst += stride;
}
}
| 15,142 |
FFmpeg | 9a2e79116d6235c53d8e9663a8d30d1950d7431a | 1 | static int svq3_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
SVQ3Context *svq3 = avctx->priv_data;
H264Context *h = &svq3->h;
MpegEncContext *s = &h->s;
int buf_size = avpkt->size;
int m, mb_type;
/* special case for last picture */
if (buf_size == 0) {
if (s->next_picture_ptr && !s->low_delay) {
*(AVFrame *) data = s->next_picture.f;
s->next_picture_ptr = NULL;
*got_frame = 1;
}
return 0;
}
init_get_bits(&s->gb, buf, 8 * buf_size);
s->mb_x = s->mb_y = h->mb_xy = 0;
if (svq3_decode_slice_header(avctx))
return -1;
s->pict_type = h->slice_type;
s->picture_number = h->slice_num;
if (avctx->debug & FF_DEBUG_PICT_INFO)
av_log(h->s.avctx, AV_LOG_DEBUG,
"%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
av_get_picture_type_char(s->pict_type),
svq3->halfpel_flag, svq3->thirdpel_flag,
s->adaptive_quant, s->qscale, h->slice_num);
/* for skipping the frame */
s->current_picture.f.pict_type = s->pict_type;
s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
/* Skip B-frames if we do not have reference frames. */
if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B)
return 0;
if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
avctx->skip_frame >= AVDISCARD_ALL)
return 0;
if (s->next_p_frame_damaged) {
if (s->pict_type == AV_PICTURE_TYPE_B)
return 0;
else
s->next_p_frame_damaged = 0;
}
if (ff_h264_frame_start(h) < 0)
return -1;
if (s->pict_type == AV_PICTURE_TYPE_B) {
h->frame_num_offset = h->slice_num - h->prev_frame_num;
if (h->frame_num_offset < 0)
h->frame_num_offset += 256;
if (h->frame_num_offset == 0 ||
h->frame_num_offset >= h->prev_frame_num_offset) {
av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
return -1;
}
} else {
h->prev_frame_num = h->frame_num;
h->frame_num = h->slice_num;
h->prev_frame_num_offset = h->frame_num - h->prev_frame_num;
if (h->prev_frame_num_offset < 0)
h->prev_frame_num_offset += 256;
}
for (m = 0; m < 2; m++) {
int i;
for (i = 0; i < 4; i++) {
int j;
for (j = -1; j < 4; j++)
h->ref_cache[m][scan8[0] + 8 * i + j] = 1;
if (i < 3)
h->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
}
}
for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
if ((get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
((get_bits_count(&s->gb) & 7) == 0 ||
show_bits(&s->gb, -get_bits_count(&s->gb) & 7) == 0)) {
skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb));
s->gb.size_in_bits = 8 * buf_size;
if (svq3_decode_slice_header(avctx))
return -1;
/* TODO: support s->mb_skip_run */
}
mb_type = svq3_get_ue_golomb(&s->gb);
if (s->pict_type == AV_PICTURE_TYPE_I)
mb_type += 8;
else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
mb_type += 4;
if ((unsigned)mb_type > 33 || svq3_decode_mb(svq3, mb_type)) {
av_log(h->s.avctx, AV_LOG_ERROR,
"error while decoding MB %d %d\n", s->mb_x, s->mb_y);
return -1;
}
if (mb_type != 0)
ff_h264_hl_decode_mb(h);
if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
(s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
}
ff_draw_horiz_band(s, 16 * s->mb_y, 16);
}
ff_MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
*(AVFrame *)data = s->current_picture.f;
else
*(AVFrame *)data = s->last_picture.f;
/* Do not output the last pic after seeking. */
if (s->last_picture_ptr || s->low_delay)
*got_frame = 1;
return buf_size;
}
| 15,143 |
FFmpeg | fc5c49ab3247533e0a5cb203cf7122143389eb5c | 1 | static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb)
{
int i;
int a= 2<<s->sprite_warping_accuracy;
int rho= 3-s->sprite_warping_accuracy;
int r=16/a;
const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes
int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
int sprite_ref[4][2];
int virtual_ref[2][2];
int w2, h2, w3, h3;
int alpha=0, beta=0;
int w= s->width;
int h= s->height;
int min_ab;
for(i=0; i<s->num_sprite_warping_points; i++){
int length;
int x=0, y=0;
length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
if(length){
x= get_xbits(gb, length);
}
if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */
length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
if(length){
y=get_xbits(gb, length);
}
skip_bits1(gb); /* marker bit */
s->sprite_traj[i][0]= d[i][0]= x;
s->sprite_traj[i][1]= d[i][1]= y;
}
for(; i<4; i++)
s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0;
while((1<<alpha)<w) alpha++;
while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'
w2= 1<<alpha;
h2= 1<<beta;
// Note, the 4th point isn't used for GMC
if(s->divx_version==500 && s->divx_build==413){
sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
} else {
sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
}
/* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]);
sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */
// this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...)
// perhaps it should be reordered to be more readable ...
// the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides
// so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form
virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
+ ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w);
virtual_ref[0][1]= 16*vop_ref[0][1]
+ ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w);
virtual_ref[1][0]= 16*vop_ref[0][0]
+ ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h);
virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
+ ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h);
switch(s->num_sprite_warping_points)
{
case 0:
s->sprite_offset[0][0]= 0;
s->sprite_offset[0][1]= 0;
s->sprite_offset[1][0]= 0;
s->sprite_offset[1][1]= 0;
s->sprite_delta[0][0]= a;
s->sprite_delta[0][1]= 0;
s->sprite_delta[1][0]= 0;
s->sprite_delta[1][1]= a;
s->sprite_shift[0]= 0;
s->sprite_shift[1]= 0;
break;
case 1: //GMC only
s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0];
s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1];
s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
s->sprite_delta[0][0]= a;
s->sprite_delta[0][1]= 0;
s->sprite_delta[1][0]= 0;
s->sprite_delta[1][1]= a;
s->sprite_shift[0]= 0;
s->sprite_shift[1]= 0;
break;
case 2:
s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho))
+ (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
+ ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
+ (1<<(alpha+rho-1));
s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho))
+ (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
+ (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
+ (1<<(alpha+rho-1));
s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
+( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
+2*w2*r*sprite_ref[0][0]
- 16*w2
+ (1<<(alpha+rho+1)));
s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
+(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
+2*w2*r*sprite_ref[0][1]
- 16*w2
+ (1<<(alpha+rho+1)));
s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
s->sprite_shift[0]= alpha+rho;
s->sprite_shift[1]= alpha+rho+2;
break;
case 3:
min_ab= FFMIN(alpha, beta);
w3= w2>>min_ab;
h3= h2>>min_ab;
s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
+ (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
+ (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
+ (1<<(alpha+beta+rho-min_ab-1));
s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
+ (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
+ (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
+ (1<<(alpha+beta+rho-min_ab-1));
s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
+ (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
+ 2*w2*h3*r*sprite_ref[0][0]
- 16*w2*h3
+ (1<<(alpha+beta+rho-min_ab+1));
s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
+ (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
+ 2*w2*h3*r*sprite_ref[0][1]
- 16*w2*h3
+ (1<<(alpha+beta+rho-min_ab+1));
s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
s->sprite_shift[0]= alpha + beta + rho - min_ab;
s->sprite_shift[1]= alpha + beta + rho - min_ab + 2;
break;
}
/* try to simplify the situation */
if( s->sprite_delta[0][0] == a<<s->sprite_shift[0]
&& s->sprite_delta[0][1] == 0
&& s->sprite_delta[1][0] == 0
&& s->sprite_delta[1][1] == a<<s->sprite_shift[0])
{
s->sprite_offset[0][0]>>=s->sprite_shift[0];
s->sprite_offset[0][1]>>=s->sprite_shift[0];
s->sprite_offset[1][0]>>=s->sprite_shift[1];
s->sprite_offset[1][1]>>=s->sprite_shift[1];
s->sprite_delta[0][0]= a;
s->sprite_delta[0][1]= 0;
s->sprite_delta[1][0]= 0;
s->sprite_delta[1][1]= a;
s->sprite_shift[0]= 0;
s->sprite_shift[1]= 0;
s->real_sprite_warping_points=1;
}
else{
int shift_y= 16 - s->sprite_shift[0];
int shift_c= 16 - s->sprite_shift[1];
for(i=0; i<2; i++){
s->sprite_offset[0][i]<<= shift_y;
s->sprite_offset[1][i]<<= shift_c;
s->sprite_delta[0][i]<<= shift_y;
s->sprite_delta[1][i]<<= shift_y;
s->sprite_shift[i]= 16;
}
s->real_sprite_warping_points= s->num_sprite_warping_points;
}
}
| 15,144 |
FFmpeg | 7b4367d93ea2a34baeab2c734630df5e0f11d4c1 | 1 | static int parse(AVCodecParserContext *ctx,
AVCodecContext *avctx,
const uint8_t **out_data, int *out_size,
const uint8_t *data, int size)
{
VP9ParseContext *s = ctx->priv_data;
int full_size = size;
int marker;
if (size <= 0) {
*out_size = 0;
*out_data = data;
return 0;
}
if (s->n_frames > 0) {
*out_data = data;
*out_size = s->size[--s->n_frames];
parse_frame(ctx, *out_data, *out_size);
return s->n_frames > 0 ? *out_size : size /* i.e. include idx tail */;
}
marker = data[size - 1];
if ((marker & 0xe0) == 0xc0) {
int nbytes = 1 + ((marker >> 3) & 0x3);
int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;
if (size >= idx_sz && data[size - idx_sz] == marker) {
const uint8_t *idx = data + size + 1 - idx_sz;
int first = 1;
switch (nbytes) {
#define case_n(a, rd) \
case a: \
while (n_frames--) { \
unsigned sz = rd; \
idx += a; \
if (sz > size) { \
s->n_frames = 0; \
*out_size = size; \
*out_data = data; \
av_log(avctx, AV_LOG_ERROR, \
"Superframe packet size too big: %u > %d\n", \
sz, size); \
return full_size; \
} \
if (first) { \
first = 0; \
*out_data = data; \
*out_size = sz; \
s->n_frames = n_frames; \
} else { \
s->size[n_frames] = sz; \
} \
data += sz; \
size -= sz; \
} \
parse_frame(ctx, *out_data, *out_size); \
return *out_size
case_n(1, *idx);
case_n(2, AV_RL16(idx));
case_n(3, AV_RL24(idx));
case_n(4, AV_RL32(idx));
}
}
}
*out_data = data;
*out_size = size;
parse_frame(ctx, data, size);
return size;
}
| 15,145 |
qemu | f8ed85ac992c48814d916d5df4d44f9a971c5de4 | 1 | void axisdev88_init(MachineState *machine)
{
ram_addr_t ram_size = machine->ram_size;
const char *cpu_model = machine->cpu_model;
const char *kernel_filename = machine->kernel_filename;
const char *kernel_cmdline = machine->kernel_cmdline;
CRISCPU *cpu;
CPUCRISState *env;
DeviceState *dev;
SysBusDevice *s;
DriveInfo *nand;
qemu_irq irq[30], nmi[2];
void *etraxfs_dmac;
struct etraxfs_dma_client *dma_eth;
int i;
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
MemoryRegion *phys_intmem = g_new(MemoryRegion, 1);
/* init CPUs */
if (cpu_model == NULL) {
cpu_model = "crisv32";
}
cpu = cpu_cris_init(cpu_model);
env = &cpu->env;
/* allocate RAM */
memory_region_allocate_system_memory(phys_ram, NULL, "axisdev88.ram",
ram_size);
memory_region_add_subregion(address_space_mem, 0x40000000, phys_ram);
/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the
internal memory. */
memory_region_init_ram(phys_intmem, NULL, "axisdev88.chipram", INTMEM_SIZE,
&error_abort);
vmstate_register_ram_global(phys_intmem);
memory_region_add_subregion(address_space_mem, 0x38000000, phys_intmem);
/* Attach a NAND flash to CS1. */
nand = drive_get(IF_MTD, 0, 0);
nand_state.nand = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL,
NAND_MFR_STMICRO, 0x39);
memory_region_init_io(&nand_state.iomem, NULL, &nand_ops, &nand_state,
"nand", 0x05000000);
memory_region_add_subregion(address_space_mem, 0x10000000,
&nand_state.iomem);
gpio_state.nand = &nand_state;
memory_region_init_io(&gpio_state.iomem, NULL, &gpio_ops, &gpio_state,
"gpio", 0x5c);
memory_region_add_subregion(address_space_mem, 0x3001a000,
&gpio_state.iomem);
dev = qdev_create(NULL, "etraxfs,pic");
/* FIXME: Is there a proper way to signal vectors to the CPU core? */
qdev_prop_set_ptr(dev, "interrupt_vector", &env->interrupt_vector);
qdev_init_nofail(dev);
s = SYS_BUS_DEVICE(dev);
sysbus_mmio_map(s, 0, 0x3001c000);
sysbus_connect_irq(s, 0, qdev_get_gpio_in(DEVICE(cpu), CRIS_CPU_IRQ));
sysbus_connect_irq(s, 1, qdev_get_gpio_in(DEVICE(cpu), CRIS_CPU_NMI));
for (i = 0; i < 30; i++) {
irq[i] = qdev_get_gpio_in(dev, i);
}
nmi[0] = qdev_get_gpio_in(dev, 30);
nmi[1] = qdev_get_gpio_in(dev, 31);
etraxfs_dmac = etraxfs_dmac_init(0x30000000, 10);
for (i = 0; i < 10; i++) {
/* On ETRAX, odd numbered channels are inputs. */
etraxfs_dmac_connect(etraxfs_dmac, i, irq + 7 + i, i & 1);
}
/* Add the two ethernet blocks. */
dma_eth = g_malloc0(sizeof dma_eth[0] * 4); /* Allocate 4 channels. */
etraxfs_eth_init(&nd_table[0], 0x30034000, 1, &dma_eth[0], &dma_eth[1]);
if (nb_nics > 1) {
etraxfs_eth_init(&nd_table[1], 0x30036000, 2, &dma_eth[2], &dma_eth[3]);
}
/* The DMA Connector block is missing, hardwire things for now. */
etraxfs_dmac_connect_client(etraxfs_dmac, 0, &dma_eth[0]);
etraxfs_dmac_connect_client(etraxfs_dmac, 1, &dma_eth[1]);
if (nb_nics > 1) {
etraxfs_dmac_connect_client(etraxfs_dmac, 6, &dma_eth[2]);
etraxfs_dmac_connect_client(etraxfs_dmac, 7, &dma_eth[3]);
}
/* 2 timers. */
sysbus_create_varargs("etraxfs,timer", 0x3001e000, irq[0x1b], nmi[1], NULL);
sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
for (i = 0; i < 4; i++) {
sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000,
irq[0x14 + i]);
}
if (kernel_filename) {
li.image_filename = kernel_filename;
li.cmdline = kernel_cmdline;
cris_load_image(cpu, &li);
} else if (!qtest_enabled()) {
fprintf(stderr, "Kernel image must be specified\n");
exit(1);
}
}
| 15,146 |
FFmpeg | 4acea512f36b96256535b45b1a7e723c61c89c31 | 1 | static int mjpeg_decode_app(MJpegDecodeContext *s)
{
int len, id, i;
len = get_bits(&s->gb, 16);
if (len < 6)
return AVERROR_INVALIDDATA;
if (8 * len > get_bits_left(&s->gb))
return AVERROR_INVALIDDATA;
id = get_bits_long(&s->gb, 32);
len -= 6;
if (s->avctx->debug & FF_DEBUG_STARTCODE) {
char id_str[32];
av_get_codec_tag_string(id_str, sizeof(id_str), av_bswap32(id));
av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n", id_str, id, len);
}
/* Buggy AVID, it puts EOI only at every 10th frame. */
/* Also, this fourcc is used by non-avid files too, it holds some
information, but it's always present in AVID-created files. */
if (id == AV_RB32("AVI1")) {
/* structure:
4bytes AVI1
1bytes polarity
1bytes always zero
4bytes field_size
4bytes field_size_less_padding
*/
s->buggy_avid = 1;
i = get_bits(&s->gb, 8); len--;
av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i);
#if 0
skip_bits(&s->gb, 8);
skip_bits(&s->gb, 32);
skip_bits(&s->gb, 32);
len -= 10;
#endif
}
// len -= 2;
if (id == AV_RB32("JFIF")) {
int t_w, t_h, v1, v2;
skip_bits(&s->gb, 8); /* the trailing zero-byte */
v1 = get_bits(&s->gb, 8);
v2 = get_bits(&s->gb, 8);
skip_bits(&s->gb, 8);
s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16);
s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16);
if ( s->avctx->sample_aspect_ratio.num <= 0
|| s->avctx->sample_aspect_ratio.den <= 0) {
s->avctx->sample_aspect_ratio.num = 0;
s->avctx->sample_aspect_ratio.den = 1;
}
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO,
"mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
v1, v2,
s->avctx->sample_aspect_ratio.num,
s->avctx->sample_aspect_ratio.den);
len -= 8;
if (len >= 2) {
t_w = get_bits(&s->gb, 8);
t_h = get_bits(&s->gb, 8);
if (t_w && t_h) {
/* skip thumbnail */
if (len -10 - (t_w * t_h * 3) > 0)
len -= t_w * t_h * 3;
}
len -= 2;
}
}
if ( id == AV_RB32("Adob")
&& len >= 7
&& show_bits(&s->gb, 8) == 'e'
&& show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) {
skip_bits(&s->gb, 8); /* 'e' */
skip_bits(&s->gb, 16); /* version */
skip_bits(&s->gb, 16); /* flags0 */
skip_bits(&s->gb, 16); /* flags1 */
s->adobe_transform = get_bits(&s->gb, 8);
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform);
len -= 7;
}
if (id == AV_RB32("LJIF")) {
int rgb = s->rgb;
int pegasus_rct = s->pegasus_rct;
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO,
"Pegasus lossless jpeg header found\n");
skip_bits(&s->gb, 16); /* version ? */
skip_bits(&s->gb, 16); /* unknown always 0? */
skip_bits(&s->gb, 16); /* unknown always 0? */
skip_bits(&s->gb, 16); /* unknown always 0? */
switch (i=get_bits(&s->gb, 8)) {
case 1:
rgb = 1;
pegasus_rct = 0;
break;
case 2:
rgb = 1;
pegasus_rct = 1;
break;
default:
av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace %d\n", i);
}
len -= 9;
if (s->got_picture)
if (rgb != s->rgb || pegasus_rct != s->pegasus_rct) {
av_log(s->avctx, AV_LOG_WARNING, "Mismatching LJIF tag\n");
}
s->rgb = rgb;
s->pegasus_rct = pegasus_rct;
}
if (id == AV_RL32("colr") && len > 0) {
s->colr = get_bits(&s->gb, 8);
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "COLR %d\n", s->colr);
len --;
}
if (id == AV_RL32("xfrm") && len > 0) {
s->xfrm = get_bits(&s->gb, 8);
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "XFRM %d\n", s->xfrm);
len --;
}
/* JPS extension by VRex */
if (s->start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) {
int flags, layout, type;
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n");
skip_bits(&s->gb, 32); len -= 4; /* JPS_ */
skip_bits(&s->gb, 16); len -= 2; /* block length */
skip_bits(&s->gb, 8); /* reserved */
flags = get_bits(&s->gb, 8);
layout = get_bits(&s->gb, 8);
type = get_bits(&s->gb, 8);
len -= 4;
s->stereo3d = av_stereo3d_alloc();
if (!s->stereo3d) {
}
if (type == 0) {
s->stereo3d->type = AV_STEREO3D_2D;
} else if (type == 1) {
switch (layout) {
case 0x01:
s->stereo3d->type = AV_STEREO3D_LINES;
break;
case 0x02:
s->stereo3d->type = AV_STEREO3D_SIDEBYSIDE;
break;
case 0x03:
s->stereo3d->type = AV_STEREO3D_TOPBOTTOM;
break;
}
if (!(flags & 0x04)) {
s->stereo3d->flags = AV_STEREO3D_FLAG_INVERT;
}
}
}
/* EXIF metadata */
if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) {
GetByteContext gbytes;
int ret, le, ifd_offset, bytes_read;
const uint8_t *aligned;
skip_bits(&s->gb, 16); // skip padding
len -= 2;
// init byte wise reading
aligned = align_get_bits(&s->gb);
bytestream2_init(&gbytes, aligned, len);
// read TIFF header
ret = ff_tdecode_header(&gbytes, &le, &ifd_offset);
if (ret) {
av_log(s->avctx, AV_LOG_ERROR, "mjpeg: invalid TIFF header in EXIF data\n");
} else {
bytestream2_seek(&gbytes, ifd_offset, SEEK_SET);
// read 0th IFD and store the metadata
// (return values > 0 indicate the presence of subimage metadata)
ret = avpriv_exif_decode_ifd(s->avctx, &gbytes, le, 0, &s->exif_metadata);
if (ret < 0) {
av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error decoding EXIF data\n");
}
}
bytes_read = bytestream2_tell(&gbytes);
skip_bits(&s->gb, bytes_read << 3);
len -= bytes_read;
}
/* Apple MJPEG-A */
if ((s->start_code == APP1) && (len > (0x28 - 8))) {
id = get_bits_long(&s->gb, 32);
len -= 4;
/* Apple MJPEG-A */
if (id == AV_RB32("mjpg")) {
#if 0
skip_bits(&s->gb, 32); /* field size */
skip_bits(&s->gb, 32); /* pad field size */
skip_bits(&s->gb, 32); /* next off */
skip_bits(&s->gb, 32); /* quant off */
skip_bits(&s->gb, 32); /* huff off */
skip_bits(&s->gb, 32); /* image off */
skip_bits(&s->gb, 32); /* scan off */
skip_bits(&s->gb, 32); /* data off */
#endif
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
}
}
out:
/* slow but needed for extreme adobe jpegs */
if (len < 0)
av_log(s->avctx, AV_LOG_ERROR,
"mjpeg: error, decode_app parser read over the end\n");
while (--len > 0)
skip_bits(&s->gb, 8);
return 0;
} | 15,148 |
FFmpeg | b4b8ca24f62473528949fe047085eb084364124b | 1 | static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
{
int got_frame;
int ret;
av_assert0(!avctx->internal->buffer_frame->buf[0]);
if (!pkt)
pkt = avctx->internal->buffer_pkt;
// This is the lesser evil. The field is for compatibility with legacy users
// of the legacy API, and users using the new API should not be forced to
// even know about this field.
avctx->refcounted_frames = 1;
// Some codecs (at least wma lossless) will crash when feeding drain packets
// after EOF was signaled.
if (avctx->internal->draining_done)
return AVERROR_EOF;
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
&got_frame, pkt);
if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
ret = pkt->size;
} else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,
&got_frame, pkt);
} else {
ret = AVERROR(EINVAL);
}
if (ret == AVERROR(EAGAIN))
ret = pkt->size;
if (avctx->internal->draining && !got_frame)
avctx->internal->draining_done = 1;
if (ret < 0)
return ret;
if (ret >= pkt->size) {
av_packet_unref(avctx->internal->buffer_pkt);
} else {
int consumed = ret;
if (pkt != avctx->internal->buffer_pkt) {
av_packet_unref(avctx->internal->buffer_pkt);
if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)
return ret;
}
avctx->internal->buffer_pkt->data += consumed;
avctx->internal->buffer_pkt->size -= consumed;
avctx->internal->buffer_pkt->pts = AV_NOPTS_VALUE;
avctx->internal->buffer_pkt->dts = AV_NOPTS_VALUE;
}
if (got_frame)
av_assert0(avctx->internal->buffer_frame->buf[0]);
return 0;
}
| 15,149 |
FFmpeg | a6cd154463bea7eb56d28192db4c8c6d83f67fd7 | 1 | void ff_h264_free_tables(H264Context *h, int free_rbsp)
{
int i;
av_freep(&h->intra4x4_pred_mode);
av_freep(&h->chroma_pred_mode_table);
av_freep(&h->cbp_table);
av_freep(&h->mvd_table[0]);
av_freep(&h->mvd_table[1]);
av_freep(&h->direct_table);
av_freep(&h->non_zero_count);
av_freep(&h->slice_table_base);
h->slice_table = NULL;
av_freep(&h->list_counts);
av_freep(&h->mb2b_xy);
av_freep(&h->mb2br_xy);
av_buffer_pool_uninit(&h->qscale_table_pool);
av_buffer_pool_uninit(&h->mb_type_pool);
av_buffer_pool_uninit(&h->motion_val_pool);
av_buffer_pool_uninit(&h->ref_index_pool);
if (free_rbsp && h->DPB) {
for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
ff_h264_unref_picture(h, &h->DPB[i]);
av_freep(&h->DPB);
}
h->cur_pic_ptr = NULL;
for (i = 0; i < h->nb_slice_ctx; i++) {
H264SliceContext *sl = &h->slice_ctx[i];
av_freep(&sl->dc_val_base);
av_freep(&sl->er.mb_index2xy);
av_freep(&sl->er.error_status_table);
av_freep(&sl->er.er_temp_buffer);
av_freep(&sl->bipred_scratchpad);
av_freep(&sl->edge_emu_buffer);
av_freep(&sl->top_borders[0]);
av_freep(&sl->top_borders[1]);
sl->bipred_scratchpad_allocated = 0;
sl->edge_emu_buffer_allocated = 0;
sl->top_borders_allocated[0] = 0;
sl->top_borders_allocated[1] = 0;
if (free_rbsp) {
av_freep(&sl->rbsp_buffer);
sl->rbsp_buffer_size = 0;
}
}
}
| 15,150 |
qemu | f38b5b7fc4e27724afc72b91efa2bc82f84bb25e | 1 | static bool s390_gen_initial_iplb(S390IPLState *ipl)
{
DeviceState *dev_st;
dev_st = get_boot_device(0);
if (dev_st) {
VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *)
object_dynamic_cast(OBJECT(qdev_get_parent_bus(dev_st)->parent),
TYPE_VIRTIO_CCW_DEVICE);
SCSIDevice *sd = (SCSIDevice *) object_dynamic_cast(OBJECT(dev_st),
TYPE_SCSI_DEVICE);
if (virtio_ccw_dev) {
CcwDevice *ccw_dev = CCW_DEVICE(virtio_ccw_dev);
ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
ipl->iplb.blk0_len =
cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN);
ipl->iplb.pbt = S390_IPL_TYPE_CCW;
ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;
return true;
} else if (sd) {
SCSIBus *bus = scsi_bus_from_device(sd);
VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus);
VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw, vdev);
CcwDevice *ccw_dev = CCW_DEVICE(scsi_ccw);
ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);
ipl->iplb.blk0_len =
cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN);
ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI;
ipl->iplb.scsi.lun = cpu_to_be32(sd->lun);
ipl->iplb.scsi.target = cpu_to_be16(sd->id);
ipl->iplb.scsi.channel = cpu_to_be16(sd->channel);
ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno);
ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3;
return true;
return false; | 15,151 |
FFmpeg | 067485b673f6ac4b1207d6fc975d1fd968edc68e | 1 | static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
{
int bin, blk, gs;
int end_bap, gaq_mode;
GetBitContext *gbc = &s->gbc;
int gaq_gain[AC3_MAX_COEFS];
gaq_mode = get_bits(gbc, 2);
end_bap = (gaq_mode < 2) ? 12 : 17;
/* if GAQ gain is used, decode gain codes for bins with hebap between
8 and end_bap */
gs = 0;
if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
/* read 1-bit GAQ gain codes */
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
}
} else if (gaq_mode == EAC3_GAQ_124) {
/* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
int gc = 2;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
if (gc++ == 2) {
int group_code = get_bits(gbc, 5);
if (group_code > 26) {
av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
group_code = 26;
}
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
gc = 0;
}
}
}
}
gs=0;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
int hebap = s->bap[ch][bin];
int bits = ff_eac3_bits_vs_hebap[hebap];
if (!hebap) {
/* zero-mantissa dithering */
for (blk = 0; blk < 6; blk++) {
s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
}
} else if (hebap < 8) {
/* Vector Quantization */
int v = get_bits(gbc, bits);
for (blk = 0; blk < 6; blk++) {
s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
}
} else {
/* Gain Adaptive Quantization */
int gbits, log_gain;
if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
log_gain = gaq_gain[gs++];
} else {
log_gain = 0;
}
gbits = bits - log_gain;
for (blk = 0; blk < 6; blk++) {
int mant = get_sbits(gbc, gbits);
if (log_gain && mant == -(1 << (gbits-1))) {
/* large mantissa */
int b;
int mbits = bits - (2 - log_gain);
mant = get_sbits(gbc, mbits);
mant <<= (23 - (mbits - 1));
/* remap mantissa value to correct for asymmetric quantization */
if (mant >= 0)
b = 1 << (23 - log_gain);
else
b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
} else {
/* small mantissa, no GAQ, or Gk=1 */
mant <<= 24 - bits;
if (!log_gain) {
/* remap mantissa value for no GAQ or Gk=1 */
mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
}
}
s->pre_mantissa[ch][bin][blk] = mant;
}
}
idct6(s->pre_mantissa[ch][bin]);
}
}
| 15,152 |
qemu | e92f0e1910f0655a0edd8d87c5a7262d36517a89 | 1 | int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count)
{
Coroutine *co;
DiscardCo rwco = {
.bs = bs,
.offset = offset,
.count = count,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_pdiscard_co_entry(&rwco);
} else {
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
qemu_coroutine_enter(co);
BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE);
}
return rwco.ret;
}
| 15,153 |
qemu | ce5b1bbf624b977a55ff7f85bb3871682d03baff | 1 | static void alpha_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
AlphaCPU *cpu = ALPHA_CPU(obj);
CPUAlphaState *env = &cpu->env;
cs->env_ptr = env;
cpu_exec_init(cs, &error_abort);
tlb_flush(cs, 1);
alpha_translate_init();
#if defined(CONFIG_USER_ONLY)
env->ps = PS_USER_MODE;
cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
| FPCR_UNFD | FPCR_INED | FPCR_DNOD
| FPCR_DYN_NORMAL));
#endif
env->lock_addr = -1;
env->fen = 1;
}
| 15,154 |
FFmpeg | 7149fce2cac0474a5fbc5b47add1158cd8bb283e | 1 | static void render_line(int x0, int y0, int x1, int y1, float *buf)
{
int dy = y1 - y0;
int adx = x1 - x0;
int ady = FFABS(dy);
int sy = dy < 0 ? -1 : 1;
buf[x0] = ff_vorbis_floor1_inverse_db_table[y0];
if (ady*2 <= adx) { // optimized common case
render_line_unrolled(x0, y0, x1, sy, ady, adx, buf);
} else {
int base = dy / adx;
int x = x0;
int y = y0;
int err = -adx;
ady -= FFABS(base) * adx;
while (++x < x1) {
y += base;
err += ady;
if (err >= 0) {
err -= adx;
y += sy;
}
buf[x] = ff_vorbis_floor1_inverse_db_table[y];
}
}
}
| 15,155 |
qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | 1 | void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
{
int ret = 0;
if (f->ops->after_ram_iterate) {
ret = f->ops->after_ram_iterate(f, f->opaque, flags);
if (ret < 0) {
qemu_file_set_error(f, ret);
}
}
}
| 15,156 |
FFmpeg | ea7f080749d68a431226ce196014da38761a0d82 | 1 | void ff_rtsp_close_streams(AVFormatContext *s)
{
RTSPState *rt = s->priv_data;
int i;
RTSPStream *rtsp_st;
ff_rtsp_undo_setup(s);
for (i = 0; i < rt->nb_rtsp_streams; i++) {
rtsp_st = rt->rtsp_streams[i];
if (rtsp_st) {
if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context)
rtsp_st->dynamic_handler->close(
rtsp_st->dynamic_protocol_context);
}
}
av_free(rt->rtsp_streams);
if (rt->asf_ctx) {
av_close_input_stream (rt->asf_ctx);
rt->asf_ctx = NULL;
}
av_free(rt->p);
av_free(rt->recvbuf);
} | 15,157 |
qemu | 15fa08f8451babc88d733bd411d4c94976f9d0f8 | 1 | static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
{
DisasContext *dc = container_of(dcbase, DisasContext, base);
dc->insn_start_idx = tcg_op_buf_count();
tcg_gen_insn_start(dc->pc, 0, 0);
}
| 15,158 |
FFmpeg | 229ccce6cca7748f53cb4b6a8d035ddce5ac6b72 | 1 | int ff_xvid_rate_control_init(MpegEncContext *s){
char *tmp_name;
int fd, i;
xvid_plg_create_t xvid_plg_create = { 0 };
xvid_plugin_2pass2_t xvid_2pass2 = { 0 };
fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx);
if (fd == -1) {
av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
return -1;
}
for(i=0; i<s->rc_context.num_entries; i++){
static const char frame_types[] = " ipbs";
char tmp[256];
RateControlEntry *rce;
rce= &s->rc_context.entry[i];
snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n",
frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
if (write(fd, tmp, strlen(tmp)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno));
return AVERROR(errno);
}
}
xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0);
xvid_2pass2.filename= tmp_name;
xvid_2pass2.bitrate= s->avctx->bit_rate;
xvid_2pass2.vbv_size= s->avctx->rc_buffer_size;
xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate;
xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy;
xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0);
xvid_plg_create.fbase= s->avctx->time_base.den;
xvid_plg_create.fincr= s->avctx->time_base.num;
xvid_plg_create.param= &xvid_2pass2;
if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){
av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n");
return -1;
}
return 0;
} | 15,160 |
qemu | d6b6abc51dda79a97f2c7bd6652c1940c068f1ec | 1 | void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
void *data, size_t len)
{
int i, index;
void *ptr = NULL;
assert(s->files);
index = be32_to_cpu(s->files->count);
assert(index < fw_cfg_file_slots(s));
for (i = 0; i < index; i++) {
if (strcmp(filename, s->files->f[i].name) == 0) {
ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
data, len);
s->files->f[i].size = cpu_to_be32(len);
return ptr;
}
}
/* add new one */
fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
return NULL;
}
| 15,161 |
qemu | 922453bca6a927bb527068ae8679d587cfa45dbc | 0 | int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const char *id = qdict_get_str(qdict, "id");
BlockDriverState *bs;
bs = bdrv_find(id);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, id);
return -1;
}
if (bdrv_in_use(bs)) {
qerror_report(QERR_DEVICE_IN_USE, id);
return -1;
}
/* quiesce block driver; prevent further io */
qemu_aio_flush();
bdrv_flush(bs);
bdrv_close(bs);
/* if we have a device attached to this BlockDriverState
* then we need to make the drive anonymous until the device
* can be removed. If this is a drive with no device backing
* then we can just get rid of the block driver state right here.
*/
if (bdrv_get_attached_dev(bs)) {
bdrv_make_anon(bs);
} else {
drive_uninit(drive_get_by_blockdev(bs));
}
return 0;
}
| 15,162 |
qemu | bbc01ca7f265f2c5be8aee7c9ce1d10aa26063f5 | 0 | static void init_proc_970FX (CPUPPCState *env)
{
gen_spr_ne_601(env);
gen_spr_7xx(env);
/* Time base */
gen_tbl(env);
/* Hardware implementation registers */
/* XXX : not implemented */
spr_register(env, SPR_HID0, "HID0",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_clear,
0x60000000);
/* XXX : not implemented */
spr_register(env, SPR_HID1, "HID1",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
0x00000000);
/* XXX : not implemented */
spr_register(env, SPR_970_HID5, "HID5",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
POWERPC970_HID5_INIT);
/* Memory management */
/* XXX: not correct */
gen_low_BATs(env);
spr_register(env, SPR_HIOR, "SPR_HIOR",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_hior, &spr_write_hior,
0x00000000);
spr_register(env, SPR_CTRL, "SPR_CTRL",
SPR_NOACCESS, SPR_NOACCESS,
SPR_NOACCESS, &spr_write_generic,
0x00000000);
spr_register(env, SPR_UCTRL, "SPR_UCTRL",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, SPR_NOACCESS,
0x00000000);
spr_register(env, SPR_VRSAVE, "SPR_VRSAVE",
&spr_read_generic, &spr_write_generic,
&spr_read_generic, &spr_write_generic,
0x00000000);
#if !defined(CONFIG_USER_ONLY)
env->slb_nr = 64;
#endif
init_excp_970(env);
env->dcache_line_size = 128;
env->icache_line_size = 128;
/* Allocate hardware IRQ controller */
ppc970_irq_init(env);
/* Can't find information on what this should be on reset. This
* value is the one used by 74xx processors. */
vscr_init(env, 0x00010000);
}
| 15,164 |
qemu | a980f7f2c2f4d7e9a1eba4f804cd66dbd458b6d4 | 0 | static QPCIBus *pci_test_start(int socket)
{
char *cmdline;
cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
"virtio-net-pci,netdev=hs0", socket);
qtest_start(cmdline);
g_free(cmdline);
return qpci_init_pc(NULL);
}
| 15,165 |
qemu | c16547326988cc321c9bff43ed91cbe753e52892 | 0 | static void ppc_prep_init(QEMUMachineInitArgs *args)
{
ram_addr_t ram_size = args->ram_size;
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
MemoryRegion *sysmem = get_system_memory();
PowerPCCPU *cpu = NULL;
CPUPPCState *env = NULL;
char *filename;
nvram_t nvram;
M48t59State *m48t59;
MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);
PortioList *port_list = g_new(PortioList, 1);
#if 0
MemoryRegion *xcsr = g_new(MemoryRegion, 1);
#endif
int linux_boot, i, nb_nics1, bios_size;
MemoryRegion *ram = g_new(MemoryRegion, 1);
MemoryRegion *bios = g_new(MemoryRegion, 1);
uint32_t kernel_base, initrd_base;
long kernel_size, initrd_size;
DeviceState *dev;
PCIHostState *pcihost;
PCIBus *pci_bus;
PCIDevice *pci;
ISABus *isa_bus;
ISADevice *isa;
qemu_irq *cpu_exit_irq;
int ppc_boot_device;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
sysctrl = g_malloc0(sizeof(sysctrl_t));
linux_boot = (kernel_filename != NULL);
/* init CPUs */
if (cpu_model == NULL)
cpu_model = "602";
for (i = 0; i < smp_cpus; i++) {
cpu = cpu_ppc_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "Unable to find PowerPC CPU definition\n");
exit(1);
}
env = &cpu->env;
if (env->flags & POWERPC_FLAG_RTC_CLK) {
/* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
cpu_ppc_tb_init(env, 7812500UL);
} else {
/* Set time-base frequency to 100 Mhz */
cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
}
qemu_register_reset(ppc_prep_reset, cpu);
}
/* allocate RAM */
memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);
vmstate_register_ram_global(ram);
memory_region_add_subregion(sysmem, 0, ram);
/* allocate and load BIOS */
memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE);
memory_region_set_readonly(bios, true);
memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios);
vmstate_register_ram_global(bios);
if (bios_name == NULL)
bios_name = BIOS_FILENAME;
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (filename) {
bios_size = load_elf(filename, NULL, NULL, NULL,
NULL, NULL, 1, ELF_MACHINE, 0);
if (bios_size < 0) {
bios_size = get_image_size(filename);
if (bios_size > 0 && bios_size <= BIOS_SIZE) {
hwaddr bios_addr;
bios_size = (bios_size + 0xfff) & ~0xfff;
bios_addr = (uint32_t)(-bios_size);
bios_size = load_image_targphys(filename, bios_addr, bios_size);
}
if (bios_size > BIOS_SIZE) {
fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n",
bios_name, bios_size);
exit(1);
}
}
} else {
bios_size = -1;
}
if (bios_size < 0 && !qtest_enabled()) {
fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n",
bios_name);
exit(1);
}
if (filename) {
g_free(filename);
}
if (linux_boot) {
kernel_base = KERNEL_LOAD_ADDR;
/* now we can load the kernel */
kernel_size = load_image_targphys(kernel_filename, kernel_base,
ram_size - kernel_base);
if (kernel_size < 0) {
hw_error("qemu: could not load kernel '%s'\n", kernel_filename);
exit(1);
}
/* load initrd */
if (initrd_filename) {
initrd_base = INITRD_LOAD_ADDR;
initrd_size = load_image_targphys(initrd_filename, initrd_base,
ram_size - initrd_base);
if (initrd_size < 0) {
hw_error("qemu: could not load initial ram disk '%s'\n",
initrd_filename);
}
} else {
initrd_base = 0;
initrd_size = 0;
}
ppc_boot_device = 'm';
} else {
kernel_base = 0;
kernel_size = 0;
initrd_base = 0;
initrd_size = 0;
ppc_boot_device = '\0';
/* For now, OHW cannot boot from the network. */
for (i = 0; boot_device[i] != '\0'; i++) {
if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
ppc_boot_device = boot_device[i];
break;
}
}
if (ppc_boot_device == '\0') {
fprintf(stderr, "No valid boot device for Mac99 machine\n");
exit(1);
}
}
if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
hw_error("Only 6xx bus is supported on PREP machine\n");
}
dev = qdev_create(NULL, "raven-pcihost");
pcihost = PCI_HOST_BRIDGE(dev);
object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);
qdev_init_nofail(dev);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
if (pci_bus == NULL) {
fprintf(stderr, "Couldn't create PCI host controller.\n");
exit(1);
}
/* PCI -> ISA bridge */
pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");
cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
cpu = POWERPC_CPU(first_cpu);
qdev_connect_gpio_out(&pci->qdev, 0,
cpu->env.irq_inputs[PPC6xx_INPUT_INT]);
qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);
sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));
sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));
sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));
sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));
isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0"));
/* Super I/O (parallel + serial ports) */
isa = isa_create(isa_bus, TYPE_PC87312);
dev = DEVICE(isa);
qdev_prop_set_uint8(dev, "config", 13); /* fdc, ser0, ser1, par0 */
qdev_init_nofail(dev);
/* Register 8 MB of ISA IO space (needed for non-contiguous map) */
memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl,
"ppc-io", 0x00800000);
memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);
/* init basic PC hardware */
pci_vga_init(pci_bus);
nb_nics1 = nb_nics;
if (nb_nics1 > NE2000_NB_MAX)
nb_nics1 = NE2000_NB_MAX;
for(i = 0; i < nb_nics1; i++) {
if (nd_table[i].model == NULL) {
nd_table[i].model = g_strdup("ne2k_isa");
}
if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i],
&nd_table[i]);
} else {
pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL);
}
}
ide_drive_get(hd, MAX_IDE_BUS);
for(i = 0; i < MAX_IDE_BUS; i++) {
isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i],
hd[2 * i],
hd[2 * i + 1]);
}
isa_create_simple(isa_bus, "i8042");
cpu = POWERPC_CPU(first_cpu);
sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];
portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep");
portio_list_add(port_list, get_system_io(), 0x0);
/* PowerPC control and status register group */
#if 0
memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);
memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);
#endif
if (usb_enabled(false)) {
pci_create_simple(pci_bus, -1, "pci-ohci");
}
m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);
if (m48t59 == NULL)
return;
sysctrl->nvram = m48t59;
/* Initialise NVRAM */
nvram.opaque = m48t59;
nvram.read_fn = &m48t59_read;
nvram.write_fn = &m48t59_write;
PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
kernel_base, kernel_size,
kernel_cmdline,
initrd_base, initrd_size,
/* XXX: need an option to load a NVRAM image */
0,
graphic_width, graphic_height, graphic_depth);
}
| 15,166 |
qemu | 57407ea44cc0a3d630b9b89a2be011f1955ce5c1 | 0 | static void smc91c111_cleanup(NetClientState *nc)
{
smc91c111_state *s = qemu_get_nic_opaque(nc);
s->nic = NULL;
}
| 15,167 |
qemu | 7d08c73e7bdc39b10e5f2f5acdce700f17ffe962 | 0 | e1000e_setup_tx_offloads(E1000ECore *core, struct e1000e_tx *tx)
{
if (tx->props.tse && tx->props.cptse) {
net_tx_pkt_build_vheader(tx->tx_pkt, true, true, tx->props.mss);
net_tx_pkt_update_ip_checksums(tx->tx_pkt);
e1000x_inc_reg_if_not_full(core->mac, TSCTC);
return;
}
if (tx->props.sum_needed & E1000_TXD_POPTS_TXSM) {
net_tx_pkt_build_vheader(tx->tx_pkt, false, true, 0);
}
if (tx->props.sum_needed & E1000_TXD_POPTS_IXSM) {
net_tx_pkt_update_ip_hdr_checksum(tx->tx_pkt);
}
}
| 15,168 |
qemu | 494a8ebe713055d3946183f4b395f85a18b43e9e | 0 | static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
const struct iovec *iov,
int iovcnt, off_t offset)
{
ssize_t ret;
#ifdef CONFIG_PREADV
ret = pwritev(fs->fd, iov, iovcnt, offset);
#else
ret = lseek(fs->fd, offset, SEEK_SET);
if (ret >= 0) {
ret = writev(fs->fd, iov, iovcnt);
}
#endif
#ifdef CONFIG_SYNC_FILE_RANGE
if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) {
/*
* Initiate a writeback. This is not a data integrity sync.
* We want to ensure that we don't leave dirty pages in the cache
* after write when writeout=immediate is sepcified.
*/
sync_file_range(fs->fd, offset, ret,
SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
}
#endif
return ret;
}
| 15,169 |
qemu | b227a8e9aa5f27d29f77ba90d5eb9d0662a1175e | 0 | static int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx,
target_ulong eaddr, int rw, int access_type)
{
ppc6xx_tlb_t *tlb;
int nr, best, way;
int ret;
best = -1;
ret = -1; /* No TLB found */
for (way = 0; way < env->nb_ways; way++) {
nr = ppc6xx_tlb_getnum(env, eaddr, way,
access_type == ACCESS_CODE ? 1 : 0);
tlb = &env->tlb[nr].tlb6;
/* This test "emulates" the PTE index match for hardware TLBs */
if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {
#if defined (DEBUG_SOFTWARE_TLB)
if (loglevel != 0) {
fprintf(logfile, "TLB %d/%d %s [" ADDRX " " ADDRX
"] <> " ADDRX "\n",
nr, env->nb_tlb,
pte_is_valid(tlb->pte0) ? "valid" : "inval",
tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr);
}
#endif
continue;
}
#if defined (DEBUG_SOFTWARE_TLB)
if (loglevel != 0) {
fprintf(logfile, "TLB %d/%d %s " ADDRX " <> " ADDRX " " ADDRX
" %c %c\n",
nr, env->nb_tlb,
pte_is_valid(tlb->pte0) ? "valid" : "inval",
tlb->EPN, eaddr, tlb->pte1,
rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D');
}
#endif
switch (pte32_check(ctx, tlb->pte0, tlb->pte1, 0, rw)) {
case -3:
/* TLB inconsistency */
return -1;
case -2:
/* Access violation */
ret = -2;
best = nr;
break;
case -1:
default:
/* No match */
break;
case 0:
/* access granted */
/* XXX: we should go on looping to check all TLBs consistency
* but we can speed-up the whole thing as the
* result would be undefined if TLBs are not consistent.
*/
ret = 0;
best = nr;
goto done;
}
}
if (best != -1) {
done:
#if defined (DEBUG_SOFTWARE_TLB)
if (loglevel != 0) {
fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n",
ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret);
}
#endif
/* Update page flags */
pte_update_flags(ctx, &env->tlb[best].tlb6.pte1, ret, rw);
}
return ret;
}
| 15,170 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static inline bool media_is_dvd(SCSIDiskState *s)
{
uint64_t nb_sectors;
if (s->qdev.type != TYPE_ROM) {
return false;
}
if (!bdrv_is_inserted(s->qdev.conf.bs)) {
return false;
}
bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
return nb_sectors > CD_MAX_SECTORS;
}
| 15,171 |
FFmpeg | ce87711df563a9d2d0537a062b86bb91b15ea1a0 | 0 | int avpriv_exif_decode_ifd(AVCodecContext *avctx, GetByteContext *gbytes, int le,
int depth, AVDictionary **metadata)
{
int i, ret;
int entries;
entries = ff_tget_short(gbytes, le);
if (bytestream2_get_bytes_left(gbytes) < entries * 12) {
return AVERROR_INVALIDDATA;
}
for (i = 0; i < entries; i++) {
if ((ret = exif_decode_tag(avctx, gbytes, le, depth, metadata)) < 0) {
return ret;
}
}
// return next IDF offset or 0x000000000 or a value < 0 for failure
return ff_tget_long(gbytes, le);
}
| 15,174 |
qemu | 10c4c98ab7dc18169b37b76f6ea5e60ebe65222b | 0 | DeviceState *qdev_create(BusState *bus, const char *name)
{
DeviceType *t;
DeviceState *dev;
for (t = device_type_list; t; t = t->next) {
if (strcmp(t->info->name, name) == 0) {
break;
}
}
if (!t) {
hw_error("Unknown device '%s'\n", name);
}
dev = qemu_mallocz(t->info->size);
dev->type = t;
if (!bus) {
/* ???: This assumes system busses have no additional state. */
if (!main_system_bus) {
main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState),
NULL, "main-system-bus");
}
bus = main_system_bus;
}
if (t->info->bus_type != bus->type) {
/* TODO: Print bus type names. */
hw_error("Device '%s' on wrong bus type (%d/%d)", name,
t->info->bus_type, bus->type);
}
dev->parent_bus = bus;
LIST_INSERT_HEAD(&bus->children, dev, sibling);
return dev;
}
| 15,175 |
qemu | 7a0e58fa648736a75f2a6943afd2ab08ea15b8e0 | 0 | static CPAccessResult ats_access(CPUARMState *env, const ARMCPRegInfo *ri)
{
if (ri->opc2 & 4) {
/* Other states are only available with TrustZone; in
* a non-TZ implementation these registers don't exist
* at all, which is an Uncategorized trap. This underdecoding
* is safe because the reginfo is NO_MIGRATE.
*/
return CP_ACCESS_TRAP_UNCATEGORIZED;
}
return CP_ACCESS_OK;
}
| 15,177 |
qemu | 2a0c46da967e5dc8cfe73b1b6fe7a1600c04f461 | 0 | on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
{
uint32_t *capabilities = (incoming->capabilities);
int num_capabilities =
1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t));
int i;
QemuThread thread_id;
incoming->version = ntohl(incoming->version);
if (incoming->version != VSCARD_VERSION) {
if (verbose > 0) {
printf("warning: host has version %d, we have %d\n",
verbose, VSCARD_VERSION);
}
}
if (incoming->magic != VSCARD_MAGIC) {
printf("unexpected magic: got %d, expected %d\n",
incoming->magic, VSCARD_MAGIC);
return -1;
}
for (i = 0 ; i < num_capabilities; ++i) {
capabilities[i] = ntohl(capabilities[i]);
}
/* Future: check capabilities */
/* remove whatever reader might be left in qemu,
* in case of an unclean previous exit. */
send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0);
/* launch the event_thread. This will trigger reader adds for all the
* existing readers */
qemu_thread_create(&thread_id, "vsc/event", event_thread, NULL, 0);
return 0;
}
| 15,178 |
qemu | 3d344c2aabb7bc9b414321e3c52872901edebdda | 0 | static GenericList *qmp_input_next_list(Visitor *v, GenericList *tail,
size_t size)
{
QmpInputVisitor *qiv = to_qiv(v);
StackObject *so = &qiv->stack[qiv->nb_stack - 1];
if (!so->entry) {
return NULL;
}
tail->next = g_malloc0(size);
return tail->next;
}
| 15,180 |
qemu | 6769da29c7a3caa9de4020db87f495de692cf8e2 | 0 | static size_t handle_aiocb_ioctl(struct qemu_paiocb *aiocb)
{
int ret;
ret = ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioctl_buf);
if (ret == -1)
return -errno;
/*
* This looks weird, but the aio code only consideres a request
* successfull if it has written the number full number of bytes.
*
* Now we overload aio_nbytes as aio_ioctl_cmd for the ioctl command,
* so in fact we return the ioctl command here to make posix_aio_read()
* happy..
*/
return aiocb->aio_nbytes;
}
| 15,181 |
qemu | a7812ae412311d7d47f8aa85656faadac9d64b56 | 0 | static always_inline void gen_load_mem (DisasContext *ctx,
void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1, int flags),
int ra, int rb, int32_t disp16,
int fp, int clear)
{
TCGv addr;
if (unlikely(ra == 31))
return;
addr = tcg_temp_new(TCG_TYPE_I64);
if (rb != 31) {
tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
if (clear)
tcg_gen_andi_i64(addr, addr, ~0x7);
} else {
if (clear)
disp16 &= ~0x7;
tcg_gen_movi_i64(addr, disp16);
}
if (fp)
tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx);
else
tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx);
tcg_temp_free(addr);
}
| 15,182 |
qemu | 72cf2d4f0e181d0d3a3122e04129c58a95da713e | 0 | int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len,
int flags)
{
target_ulong len_mask = ~(len - 1);
CPUWatchpoint *wp;
TAILQ_FOREACH(wp, &env->watchpoints, entry) {
if (addr == wp->vaddr && len_mask == wp->len_mask
&& flags == (wp->flags & ~BP_WATCHPOINT_HIT)) {
cpu_watchpoint_remove_by_ref(env, wp);
return 0;
}
}
return -ENOENT;
}
| 15,184 |
FFmpeg | 9f61abc8111c7c43f49ca012e957a108b9cc7610 | 0 | static int segment_start(AVFormatContext *s, int write_header)
{
SegmentContext *c = s->priv_data;
AVFormatContext *oc = c->avf;
int err = 0;
if (write_header) {
avformat_free_context(oc);
c->avf = NULL;
if ((err = segment_mux_init(s)) < 0)
return err;
oc = c->avf;
}
if (c->wrap)
c->number %= c->wrap;
if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
s->filename, c->number++) < 0)
return AVERROR(EINVAL);
if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0)
return err;
if (oc->oformat->priv_class && oc->priv_data)
av_opt_set(oc->priv_data, "resend_headers", "1", 0); /* mpegts specific */
if (write_header) {
if ((err = avformat_write_header(oc, NULL)) < 0)
return err;
}
return 0;
}
| 15,185 |
qemu | ca5c1457d614fec718aaec7bdf3663dec37e1e50 | 0 | static void s390x_cpu_set_id(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
S390CPU *cpu = S390_CPU(obj);
DeviceState *dev = DEVICE(obj);
const int64_t min = 0;
const int64_t max = UINT32_MAX;
Error *err = NULL;
int64_t value;
if (dev->realized) {
error_setg(errp, "Attempt to set property '%s' on '%s' after "
"it was realized", name, object_get_typename(obj));
return;
}
visit_type_int(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
return;
}
if (value < min || value > max) {
error_setg(errp, "Property %s.%s doesn't take value %" PRId64
" (minimum: %" PRId64 ", maximum: %" PRId64 ")" ,
object_get_typename(obj), name, value, min, max);
return;
}
cpu->id = value;
}
| 15,186 |
qemu | a0d98a712fbb1f22e347299006e4004bb985eb34 | 0 | static void sunmouse_event(void *opaque,
int dx, int dy, int dz, int buttons_state)
{
ChannelState *s = opaque;
int ch;
MS_DPRINTF("dx=%d dy=%d buttons=%01x\n", dx, dy, buttons_state);
ch = 0x80 | 0x7; /* protocol start byte, no buttons pressed */
if (buttons_state & MOUSE_EVENT_LBUTTON)
ch ^= 0x4;
if (buttons_state & MOUSE_EVENT_MBUTTON)
ch ^= 0x2;
if (buttons_state & MOUSE_EVENT_RBUTTON)
ch ^= 0x1;
put_queue(s, ch);
ch = dx;
if (ch > 127)
ch=127;
else if (ch < -127)
ch=-127;
put_queue(s, ch & 0xff);
ch = -dy;
if (ch > 127)
ch=127;
else if (ch < -127)
ch=-127;
put_queue(s, ch & 0xff);
// MSC protocol specify two extra motion bytes
put_queue(s, 0);
put_queue(s, 0);
}
| 15,188 |
qemu | 86f6ae67e157362f3b141649874213ce01dcc622 | 0 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
uint8_t *buf, uint64_t start,
uint64_t count)
{
hbitmap_serialize_part(bitmap->bitmap, buf, start, count);
}
| 15,189 |
qemu | 081dd1fe36f0ccc04130d1edd136c787c5f8cc50 | 0 | int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info,
Error **errp)
{
unsigned long sectors = info->size / BDRV_SECTOR_SIZE;
if (info->size / BDRV_SECTOR_SIZE != sectors) {
error_setg(errp, "Export size %" PRIu64 " too large for 32-bit kernel",
info->size);
return -E2BIG;
}
trace_nbd_init_set_socket();
if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) {
int serrno = errno;
error_setg(errp, "Failed to set NBD socket");
return -serrno;
}
trace_nbd_init_set_block_size(BDRV_SECTOR_SIZE);
if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) {
int serrno = errno;
error_setg(errp, "Failed setting NBD block size");
return -serrno;
}
trace_nbd_init_set_size(sectors);
if (info->size % BDRV_SECTOR_SIZE) {
trace_nbd_init_trailing_bytes(info->size % BDRV_SECTOR_SIZE);
}
if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) {
int serrno = errno;
error_setg(errp, "Failed setting size (in blocks)");
return -serrno;
}
if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) info->flags) < 0) {
if (errno == ENOTTY) {
int read_only = (info->flags & NBD_FLAG_READ_ONLY) != 0;
trace_nbd_init_set_readonly();
if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) {
int serrno = errno;
error_setg(errp, "Failed setting read-only attribute");
return -serrno;
}
} else {
int serrno = errno;
error_setg(errp, "Failed setting flags");
return -serrno;
}
}
trace_nbd_init_finish();
return 0;
}
| 15,190 |
qemu | 414f5d1448fef9aad6d37f1d40d1158396573447 | 0 | void helper_dcbz(CPUPPCState *env, target_ulong addr, uint32_t is_dcbzl)
{
int dcbz_size = env->dcache_line_size;
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
if (!is_dcbzl &&
(env->excp_model == POWERPC_EXCP_970) &&
((env->spr[SPR_970_HID5] >> 7) & 0x3) == 1) {
dcbz_size = 32;
}
#endif
/* XXX add e500mc support */
do_dcbz(env, addr, dcbz_size);
}
| 15,192 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static void nvme_rw_cb(void *opaque, int ret)
{
NvmeRequest *req = opaque;
NvmeSQueue *sq = req->sq;
NvmeCtrl *n = sq->ctrl;
NvmeCQueue *cq = n->cq[sq->cqid];
block_acct_done(bdrv_get_stats(n->conf.bs), &req->acct);
if (!ret) {
req->status = NVME_SUCCESS;
} else {
req->status = NVME_INTERNAL_DEV_ERROR;
}
qemu_sglist_destroy(&req->qsg);
nvme_enqueue_req_completion(cq, req);
}
| 15,193 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.