id
int32 0
27.3k
| func
stringlengths 26
142k
| target
bool 2
classes | project
stringclasses 2
values | commit_id
stringlengths 40
40
|
---|---|---|---|---|
3,797 | AioContext *bdrv_get_aio_context(BlockDriverState *bs)
{
/* Currently BlockDriverState always uses the main loop AioContext */
return qemu_get_aio_context();
}
| false | qemu | dcd042282d855edf70df90b7d61d33b515320b7a |
3,798 | static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
{
FramePool *pool = s->internal->pool;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format);
int i;
if (pic->data[0]) {
av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
return -1;
}
if (!desc) {
av_log(s, AV_LOG_ERROR,
"Unable to get pixel format descriptor for format %s\n",
av_get_pix_fmt_name(pic->format));
return AVERROR(EINVAL);
}
memset(pic->data, 0, sizeof(pic->data));
pic->extended_data = pic->data;
for (i = 0; i < 4 && pool->pools[i]; i++) {
pic->linesize[i] = pool->linesize[i];
pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
if (!pic->buf[i])
goto fail;
pic->data[i] = pic->buf[i]->data;
}
for (; i < AV_NUM_DATA_POINTERS; i++) {
pic->data[i] = NULL;
pic->linesize[i] = 0;
}
if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
avpriv_set_systematic_pal2((uint32_t *)pic->data[1], pic->format);
if (s->debug & FF_DEBUG_BUFFERS)
av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
return 0;
fail:
av_frame_unref(pic);
return AVERROR(ENOMEM);
}
| false | FFmpeg | bdf7093bd0cb78d39df8a32cfdc9188d7a960278 |
3,801 | static int qio_dns_resolver_lookup_sync_nop(QIODNSResolver *resolver,
SocketAddress *addr,
size_t *naddrs,
SocketAddress ***addrs,
Error **errp)
{
*naddrs = 1;
*addrs = g_new0(SocketAddress *, 1);
(*addrs)[0] = QAPI_CLONE(SocketAddress, addr);
return 0;
}
| false | qemu | dfd100f242370886bb6732f70f1f7cbd8eb9fedc |
3,802 | static int nvdimm_plugged_device_list(Object *obj, void *opaque)
{
GSList **list = opaque;
if (object_dynamic_cast(obj, TYPE_NVDIMM)) {
*list = g_slist_append(*list, DEVICE(obj));
}
object_child_foreach(obj, nvdimm_plugged_device_list, opaque);
return 0;
}
| false | qemu | cf7c0ff521b0710079aa28f21937fb7dbb3f5224 |
3,803 | AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
const char *opaque, Error **errp)
{
int fd;
Monitor *mon = cur_mon;
MonFdset *mon_fdset = NULL;
MonFdsetFd *mon_fdset_fd;
AddfdInfo *fdinfo;
fd = qemu_chr_fe_get_msgfd(mon->chr);
if (fd == -1) {
error_set(errp, QERR_FD_NOT_SUPPLIED);
goto error;
}
if (has_fdset_id) {
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
/* Break if match found or match impossible due to ordering by ID */
if (fdset_id <= mon_fdset->id) {
if (fdset_id < mon_fdset->id) {
mon_fdset = NULL;
}
break;
}
}
}
if (mon_fdset == NULL) {
int64_t fdset_id_prev = -1;
MonFdset *mon_fdset_cur = QLIST_FIRST(&mon_fdsets);
if (has_fdset_id) {
if (fdset_id < 0) {
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id",
"a non-negative value");
goto error;
}
/* Use specified fdset ID */
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
mon_fdset_cur = mon_fdset;
if (fdset_id < mon_fdset_cur->id) {
break;
}
}
} else {
/* Use first available fdset ID */
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
mon_fdset_cur = mon_fdset;
if (fdset_id_prev == mon_fdset_cur->id - 1) {
fdset_id_prev = mon_fdset_cur->id;
continue;
}
break;
}
}
mon_fdset = g_malloc0(sizeof(*mon_fdset));
if (has_fdset_id) {
mon_fdset->id = fdset_id;
} else {
mon_fdset->id = fdset_id_prev + 1;
}
/* The fdset list is ordered by fdset ID */
if (!mon_fdset_cur) {
QLIST_INSERT_HEAD(&mon_fdsets, mon_fdset, next);
} else if (mon_fdset->id < mon_fdset_cur->id) {
QLIST_INSERT_BEFORE(mon_fdset_cur, mon_fdset, next);
} else {
QLIST_INSERT_AFTER(mon_fdset_cur, mon_fdset, next);
}
}
mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
mon_fdset_fd->fd = fd;
mon_fdset_fd->removed = false;
if (has_opaque) {
mon_fdset_fd->opaque = g_strdup(opaque);
}
QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
fdinfo = g_malloc0(sizeof(*fdinfo));
fdinfo->fdset_id = mon_fdset->id;
fdinfo->fd = mon_fdset_fd->fd;
return fdinfo;
error:
if (fd != -1) {
close(fd);
}
return NULL;
}
| false | qemu | e446f70d54b4920e8ca5af509271b69eab86e37b |
3,804 | static BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
unsigned long int req, void *buf,
BlockDriverCompletionFunc *cb, void *opaque)
{
RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
acb->bs = bs;
acb->aio_type = QEMU_AIO_IOCTL;
acb->aio_fildes = fd;
acb->aio_offset = 0;
acb->aio_ioctl_buf = buf;
acb->aio_ioctl_cmd = req;
return thread_pool_submit_aio(aio_worker, acb, cb, opaque);
}
| false | qemu | c208e8c2d88eea2bbafc2850d8856525637e495d |
3,805 | static int readv_f(BlockBackend *blk, int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return qemuio_command_usage(&readv_cmd);
}
}
if (optind > argc - 2) {
return qemuio_command_usage(&readv_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab);
if (buf == NULL) {
return 0;
}
gettimeofday(&t1, NULL);
cnt = do_aio_readv(blk, &qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
goto out;
}
if (Pflag) {
void *cmp_buf = g_malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %"
PRId64 ", %zd bytes\n", offset, qiov.size);
}
g_free(cmp_buf);
}
if (qflag) {
goto out;
}
if (vflag) {
dump_buffer(buf, offset, qiov.size);
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_iovec_destroy(&qiov);
qemu_io_free(buf);
return 0;
}
| false | qemu | b062ad86dcd33ab39be5060b0655d8e13834b167 |
3,806 | static void iter_func(QObject *obj, void *opaque)
{
QInt *qi;
fail_unless(opaque == NULL);
qi = qobject_to_qint(obj);
fail_unless(qi != NULL);
fail_unless((qint_get_int(qi) >= 0) && (qint_get_int(qi) <= iter_max));
iter_called++;
}
| false | qemu | 91479dd0b5bd3b087b92ddd7bc3f2c54982cfe17 |
3,807 | int avfilter_init_str(AVFilterContext *filter, const char *args)
{
return avfilter_init_filter(filter, args, NULL);
}
| false | FFmpeg | 0acf7e268b2f873379cd854b4d5aaba6f9c1f0b5 |
3,808 | SerialState *serial_mm_init(MemoryRegion *address_space,
hwaddr base, int it_shift,
qemu_irq irq, int baudbase,
CharDriverState *chr, enum device_endian end)
{
SerialState *s;
Error *err = NULL;
s = g_malloc0(sizeof(SerialState));
s->it_shift = it_shift;
s->irq = irq;
s->baudbase = baudbase;
s->chr = chr;
serial_realize_core(s, &err);
if (err != NULL) {
error_report("%s", error_get_pretty(err));
error_free(err);
exit(1);
}
vmstate_register(NULL, base, &vmstate_serial, s);
memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], s,
"serial", 8 << it_shift);
memory_region_add_subregion(address_space, base, &s->io);
serial_update_msl(s);
return s;
}
| false | qemu | a30cf8760f4a59797fc060c3c5a13b7749551d0c |
3,809 | static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f)
{
VirtIONet *n = VIRTIO_NET(vdev);
int i;
qemu_put_buffer(f, n->mac, ETH_ALEN);
qemu_put_be32(f, n->vqs[0].tx_waiting);
qemu_put_be32(f, n->mergeable_rx_bufs);
qemu_put_be16(f, n->status);
qemu_put_byte(f, n->promisc);
qemu_put_byte(f, n->allmulti);
qemu_put_be32(f, n->mac_table.in_use);
qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
qemu_put_be32(f, n->has_vnet_hdr);
qemu_put_byte(f, n->mac_table.multi_overflow);
qemu_put_byte(f, n->mac_table.uni_overflow);
qemu_put_byte(f, n->alluni);
qemu_put_byte(f, n->nomulti);
qemu_put_byte(f, n->nouni);
qemu_put_byte(f, n->nobcast);
qemu_put_byte(f, n->has_ufo);
if (n->max_queues > 1) {
qemu_put_be16(f, n->max_queues);
qemu_put_be16(f, n->curr_queues);
for (i = 1; i < n->curr_queues; i++) {
qemu_put_be32(f, n->vqs[i].tx_waiting);
}
}
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
qemu_put_be64(f, n->curr_guest_offloads);
}
}
| false | qemu | 95129d6fc9ead97155627a4ca0cfd37282883658 |
3,810 | udp_listen(port, laddr, lport, flags)
u_int port;
u_int32_t laddr;
u_int lport;
int flags;
{
struct sockaddr_in addr;
struct socket *so;
int addrlen = sizeof(struct sockaddr_in), opt = 1;
if ((so = socreate()) == NULL) {
free(so);
return NULL;
}
so->s = socket(AF_INET,SOCK_DGRAM,0);
so->so_expire = curtime + SO_EXPIRE;
insque(so,&udb);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = port;
if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) {
udp_detach(so);
return NULL;
}
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
/* setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); */
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
so->so_lport = lport;
so->so_laddr.s_addr = laddr;
if (flags != SS_FACCEPTONCE)
so->so_expire = 0;
so->so_state = SS_ISFCONNECTED;
return so;
}
| false | qemu | 242acf3af4605adce933906bdc053b2414181ec7 |
3,812 | void cpu_x86_inject_mce(Monitor *mon, CPUState *cenv, int bank,
uint64_t status, uint64_t mcg_status, uint64_t addr,
uint64_t misc, int flags)
{
unsigned bank_num = cenv->mcg_cap & 0xff;
CPUState *env;
int flag = 0;
if (!cenv->mcg_cap) {
monitor_printf(mon, "MCE injection not supported\n");
return;
}
if (bank >= bank_num) {
monitor_printf(mon, "Invalid MCE bank number\n");
return;
}
if (!(status & MCI_STATUS_VAL)) {
monitor_printf(mon, "Invalid MCE status code\n");
return;
}
if ((flags & MCE_INJECT_BROADCAST)
&& !cpu_x86_support_mca_broadcast(cenv)) {
monitor_printf(mon, "Guest CPU does not support MCA broadcast\n");
return;
}
if (kvm_enabled()) {
if (flags & MCE_INJECT_BROADCAST) {
flag |= MCE_BROADCAST;
}
kvm_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc, flag);
} else {
qemu_inject_x86_mce(mon, cenv, bank, status, mcg_status, addr, misc,
flags);
if (flags & MCE_INJECT_BROADCAST) {
for (env = first_cpu; env != NULL; env = env->next_cpu) {
if (cenv == env) {
continue;
}
qemu_inject_x86_mce(mon, env, 1,
MCI_STATUS_VAL | MCI_STATUS_UC,
MCG_STATUS_MCIP | MCG_STATUS_RIPV, 0, 0,
flags);
}
}
}
}
| false | qemu | d5bfda334adf9af62df5709cdac38f523f815f47 |
3,813 | static void piix3_set_irq(void *opaque, int irq_num, int level)
{
int i, pic_irq, pic_level;
PIIX3State *piix3 = opaque;
/* now we change the pic irq level according to the piix irq mappings */
/* XXX: optimize */
pic_irq = piix3->dev.config[0x60 + irq_num];
if (pic_irq < 16) {
/* The pic level is the logical OR of all the PCI irqs mapped
to it */
pic_level = 0;
for (i = 0; i < 4; i++) {
if (pic_irq == piix3->dev.config[0x60 + i]) {
pic_level |= pci_bus_get_irq_level(piix3->dev.bus, i);
}
}
qemu_set_irq(piix3->pic[pic_irq], pic_level);
}
}
| false | qemu | ab431c283e7055bcd6fb622f212bb29e84a6a134 |
3,816 | static void mirror_iteration_done(MirrorOp *op, int ret)
{
MirrorBlockJob *s = op->s;
struct iovec *iov;
int64_t chunk_num;
int i, nb_chunks, sectors_per_chunk;
trace_mirror_iteration_done(s, op->sector_num * BDRV_SECTOR_SIZE,
op->nb_sectors * BDRV_SECTOR_SIZE, ret);
s->in_flight--;
s->sectors_in_flight -= op->nb_sectors;
iov = op->qiov.iov;
for (i = 0; i < op->qiov.niov; i++) {
MirrorBuffer *buf = (MirrorBuffer *) iov[i].iov_base;
QSIMPLEQ_INSERT_TAIL(&s->buf_free, buf, next);
s->buf_free_count++;
}
sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
chunk_num = op->sector_num / sectors_per_chunk;
nb_chunks = DIV_ROUND_UP(op->nb_sectors, sectors_per_chunk);
bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
if (ret >= 0) {
if (s->cow_bitmap) {
bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
}
if (!s->initial_zeroing_ongoing) {
s->common.offset += (uint64_t)op->nb_sectors * BDRV_SECTOR_SIZE;
}
}
qemu_iovec_destroy(&op->qiov);
g_free(op);
if (s->waiting_for_io) {
qemu_coroutine_enter(s->common.co);
}
}
| false | qemu | b436982f04fb33bb29fcdea190bd1fdc97dc65ef |
3,817 | static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
size_t size)
{
VIOsPAPRDevice *sdev = DO_UPCAST(NICState, nc, nc)->opaque;
VIOsPAPRVLANDevice *dev = (VIOsPAPRVLANDevice *)sdev;
vlan_bd_t rxq_bd = vio_ldq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF);
vlan_bd_t bd;
int buf_ptr = dev->use_buf_ptr;
uint64_t handle;
uint8_t control;
dprintf("spapr_vlan_receive() [%s] rx_bufs=%d\n", sdev->qdev.id,
dev->rx_bufs);
if (!dev->isopen) {
return -1;
}
if (!dev->rx_bufs) {
return -1;
}
do {
buf_ptr += 8;
if (buf_ptr >= SPAPR_TCE_PAGE_SIZE) {
buf_ptr = VLAN_RX_BDS_OFF;
}
bd = vio_ldq(sdev, dev->buf_list + buf_ptr);
dprintf("use_buf_ptr=%d bd=0x%016llx\n",
buf_ptr, (unsigned long long)bd);
} while ((!(bd & VLAN_BD_VALID) || (VLAN_BD_LEN(bd) < (size + 8)))
&& (buf_ptr != dev->use_buf_ptr));
if (!(bd & VLAN_BD_VALID) || (VLAN_BD_LEN(bd) < (size + 8))) {
/* Failed to find a suitable buffer */
return -1;
}
/* Remove the buffer from the pool */
dev->rx_bufs--;
dev->use_buf_ptr = buf_ptr;
vio_stq(sdev, dev->buf_list + dev->use_buf_ptr, 0);
dprintf("Found buffer: ptr=%d num=%d\n", dev->use_buf_ptr, dev->rx_bufs);
/* Transfer the packet data */
if (spapr_vio_dma_write(sdev, VLAN_BD_ADDR(bd) + 8, buf, size) < 0) {
return -1;
}
dprintf("spapr_vlan_receive: DMA write completed\n");
/* Update the receive queue */
control = VLAN_RXQC_TOGGLE | VLAN_RXQC_VALID;
if (rxq_bd & VLAN_BD_TOGGLE) {
control ^= VLAN_RXQC_TOGGLE;
}
handle = vio_ldq(sdev, VLAN_BD_ADDR(bd));
vio_stq(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 8, handle);
vio_stl(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 4, size);
vio_sth(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 2, 8);
vio_stb(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr, control);
dprintf("wrote rxq entry (ptr=0x%llx): 0x%016llx 0x%016llx\n",
(unsigned long long)dev->rxq_ptr,
(unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
dev->rxq_ptr),
(unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
dev->rxq_ptr + 8));
dev->rxq_ptr += 16;
if (dev->rxq_ptr >= VLAN_BD_LEN(rxq_bd)) {
dev->rxq_ptr = 0;
vio_stq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF, rxq_bd ^ VLAN_BD_TOGGLE);
}
if (sdev->signal_state & 1) {
qemu_irq_pulse(sdev->qirq);
}
return size;
}
| false | qemu | a307d59434ba78b97544b42b8cfd24a1b62e39a6 |
3,818 | int av_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
return ret;
ret= s->oformat->write_packet(s, pkt);
if(!ret)
ret= url_ferror(s->pb);
return ret;
}
| false | FFmpeg | 75b9ed04b977bfd467816f7e60c6511ef89b8a2b |
3,821 | av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
{
int i, j, n;
if (nbits < 2 || nbits > 16)
goto fail;
s->nbits = nbits;
n = 1 << nbits;
s->revtab = av_malloc(n * sizeof(uint16_t));
if (!s->revtab)
goto fail;
s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
if (!s->tmp_buf)
goto fail;
s->inverse = inverse;
s->fft_permute = ff_fft_permute_c;
s->fft_calc = ff_fft_calc_c;
#if CONFIG_MDCT
s->imdct_calc = ff_imdct_calc_c;
s->imdct_half = ff_imdct_half_c;
s->mdct_calc = ff_mdct_calc_c;
#endif
if (ARCH_ARM) ff_fft_init_arm(s);
if (HAVE_ALTIVEC) ff_fft_init_altivec(s);
if (HAVE_MMX) ff_fft_init_mmx(s);
for(j=4; j<=nbits; j++) {
ff_init_ff_cos_tabs(j);
}
for(i=0; i<n; i++)
s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
return 0;
fail:
av_freep(&s->revtab);
av_freep(&s->tmp_buf);
return -1;
}
| false | FFmpeg | e6b1ed693ae4098e6b9eabf938fc31ec0b09b120 |
3,822 | DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
pixman_format_code_t format,
int linesize, uint64_t addr)
{
DisplaySurface *surface;
hwaddr size;
void *data;
if (linesize == 0) {
linesize = width * PIXMAN_FORMAT_BPP(format) / 8;
}
size = linesize * height;
data = cpu_physical_memory_map(addr, &size, 0);
if (size != linesize * height) {
cpu_physical_memory_unmap(data, size, 0, 0);
return NULL;
}
surface = qemu_create_displaysurface_from
(width, height, format, linesize, data);
pixman_image_set_destroy_function
(surface->image, qemu_unmap_displaysurface_guestmem, NULL);
return surface;
}
| true | qemu | f76b84a04b75e98eee56e8dc277564d0fbb99018 |
3,823 | static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
{
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
AVFilterContext *ctx = inlink->dst;
OverlayContext *over = ctx->priv;
av_unused AVFilterLink *outlink = ctx->outputs[0];
inlink->dst->outputs[0]->out_buf = outpicref;
outpicref->pts = av_rescale_q(outpicref->pts, ctx->inputs[MAIN]->time_base,
ctx->outputs[0]->time_base);
if (!over->overpicref || over->overpicref->pts < outpicref->pts) {
if (!over->overpicref_next)
avfilter_request_frame(ctx->inputs[OVERLAY]);
if (over->overpicref && over->overpicref_next &&
over->overpicref_next->pts <= outpicref->pts) {
avfilter_unref_buffer(over->overpicref);
over->overpicref = over->overpicref_next;
over->overpicref_next = NULL;
}
}
av_dlog(ctx, "main_pts:%s main_pts_time:%s",
av_ts2str(outpicref->pts), av_ts2timestr(outpicref->pts, &outlink->time_base));
if (over->overpicref)
av_dlog(ctx, " over_pts:%s over_pts_time:%s",
av_ts2str(over->overpicref->pts), av_ts2timestr(over->overpicref->pts, &outlink->time_base));
av_dlog(ctx, "\n");
avfilter_start_frame(inlink->dst->outputs[0], outpicref);
}
| true | FFmpeg | 06bf6d3bc04979bd39ecdc7311d0daf8aee7e10f |
3,825 | static void monitor_puts(Monitor *mon, const char *str)
{
char c;
for(;;) {
assert(mon->outbuf_index < sizeof(mon->outbuf) - 1);
c = *str++;
if (c == '\0')
break;
if (c == '\n')
mon->outbuf[mon->outbuf_index++] = '\r';
mon->outbuf[mon->outbuf_index++] = c;
if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
|| c == '\n')
monitor_flush(mon);
}
}
| true | qemu | e1f2641b5926d20f63d36f0de45206be774da8da |
3,826 | void timer_del(QEMUTimer *ts)
{
QEMUTimerList *timer_list = ts->timer_list;
qemu_mutex_lock(&timer_list->active_timers_lock);
timer_del_locked(timer_list, ts);
qemu_mutex_unlock(&timer_list->active_timers_lock);
}
| true | qemu | cd1bd53a669c88f219ca47b538889cd918605fea |
3,827 | static void put_bitmap(QEMUFile *f, void *pv, size_t size)
{
unsigned long *bmp = pv;
int i, idx = 0;
for (i = 0; i < BITS_TO_U64S(size); i++) {
uint64_t w = bmp[idx++];
if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) {
w |= ((uint64_t)bmp[idx++]) << 32;
}
qemu_put_be64(f, w);
}
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 |
3,828 | void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
{
func(data);
}
| true | qemu | 12d4536f7d911b6d87a766ad7300482ea663cea2 |
3,829 | static int dirac_decode_picture_header(DiracContext *s)
{
unsigned retire, picnum;
int i, j, ret;
int64_t refdist, refnum;
GetBitContext *gb = &s->gb;
/* [DIRAC_STD] 11.1.1 Picture Header. picture_header() PICTURE_NUM */
picnum = s->current_picture->avframe->display_picture_number = get_bits_long(gb, 32);
av_log(s->avctx,AV_LOG_DEBUG,"PICTURE_NUM: %d\n",picnum);
/* if this is the first keyframe after a sequence header, start our
reordering from here */
if (s->frame_number < 0)
s->frame_number = picnum;
s->ref_pics[0] = s->ref_pics[1] = NULL;
for (i = 0; i < s->num_refs; i++) {
refnum = (picnum + dirac_get_se_golomb(gb)) & 0xFFFFFFFF;
refdist = INT64_MAX;
/* find the closest reference to the one we want */
/* Jordi: this is needed if the referenced picture hasn't yet arrived */
for (j = 0; j < MAX_REFERENCE_FRAMES && refdist; j++)
if (s->ref_frames[j]
&& FFABS(s->ref_frames[j]->avframe->display_picture_number - refnum) < refdist) {
s->ref_pics[i] = s->ref_frames[j];
refdist = FFABS(s->ref_frames[j]->avframe->display_picture_number - refnum);
}
if (!s->ref_pics[i] || refdist)
av_log(s->avctx, AV_LOG_DEBUG, "Reference not found\n");
/* if there were no references at all, allocate one */
if (!s->ref_pics[i])
for (j = 0; j < MAX_FRAMES; j++)
if (!s->all_frames[j].avframe->data[0]) {
s->ref_pics[i] = &s->all_frames[j];
get_buffer_with_edge(s->avctx, s->ref_pics[i]->avframe, AV_GET_BUFFER_FLAG_REF);
break;
}
if (!s->ref_pics[i]) {
av_log(s->avctx, AV_LOG_ERROR, "Reference could not be allocated\n");
return AVERROR_INVALIDDATA;
}
}
/* retire the reference frames that are not used anymore */
if (s->current_picture->reference) {
retire = (picnum + dirac_get_se_golomb(gb)) & 0xFFFFFFFF;
if (retire != picnum) {
DiracFrame *retire_pic = remove_frame(s->ref_frames, retire);
if (retire_pic)
retire_pic->reference &= DELAYED_PIC_REF;
else
av_log(s->avctx, AV_LOG_DEBUG, "Frame to retire not found\n");
}
/* if reference array is full, remove the oldest as per the spec */
while (add_frame(s->ref_frames, MAX_REFERENCE_FRAMES, s->current_picture)) {
av_log(s->avctx, AV_LOG_ERROR, "Reference frame overflow\n");
remove_frame(s->ref_frames, s->ref_frames[0]->avframe->display_picture_number)->reference &= DELAYED_PIC_REF;
}
}
if (s->num_refs) {
ret = dirac_unpack_prediction_parameters(s); /* [DIRAC_STD] 11.2 Picture Prediction Data. picture_prediction() */
if (ret < 0)
return ret;
ret = dirac_unpack_block_motion_data(s); /* [DIRAC_STD] 12. Block motion data syntax */
if (ret < 0)
return ret;
}
ret = dirac_unpack_idwt_params(s); /* [DIRAC_STD] 11.3 Wavelet transform data */
if (ret < 0)
return ret;
init_planes(s);
return 0;
}
| true | FFmpeg | db79dedb1ae5dd38432eee3f09155e26f3f2d95a |
3,830 | static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
{
int ret = 0, i;
int got_output = 0;
AVPacket avpkt;
if (!ist->saw_first_ts) {
ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
ist->pts = 0;
if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
ist->dts += av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);
ist->pts = ist->dts; //unused but better to set it to a value thats not totally wrong
}
ist->saw_first_ts = 1;
}
if (ist->next_dts == AV_NOPTS_VALUE)
ist->next_dts = ist->dts;
if (ist->next_pts == AV_NOPTS_VALUE)
ist->next_pts = ist->pts;
if (!pkt) {
/* EOF handling */
av_init_packet(&avpkt);
avpkt.data = NULL;
avpkt.size = 0;
goto handle_eof;
} else {
avpkt = *pkt;
}
if (pkt->dts != AV_NOPTS_VALUE) {
ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
ist->next_pts = ist->pts = ist->dts;
}
// while we have more to decode or while the decoder did output something on EOF
while (ist->decoding_needed && (avpkt.size > 0 || (!pkt && got_output))) {
int duration;
handle_eof:
ist->pts = ist->next_pts;
ist->dts = ist->next_dts;
switch (ist->dec_ctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ret = decode_audio (ist, &avpkt, &got_output);
break;
case AVMEDIA_TYPE_VIDEO:
ret = decode_video (ist, &avpkt, &got_output);
if (avpkt.duration) {
duration = av_rescale_q(avpkt.duration, ist->st->time_base, AV_TIME_BASE_Q);
} else if(ist->dec_ctx->framerate.num != 0 && ist->dec_ctx->framerate.den != 0) {
int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict+1 : ist->dec_ctx->ticks_per_frame;
duration = ((int64_t)AV_TIME_BASE *
ist->dec_ctx->framerate.den * ticks) /
ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame;
} else
duration = 0;
if(ist->dts != AV_NOPTS_VALUE && duration) {
ist->next_dts += duration;
}else
ist->next_dts = AV_NOPTS_VALUE;
if (got_output)
ist->next_pts += duration; //FIXME the duration is not correct in some cases
break;
case AVMEDIA_TYPE_SUBTITLE:
ret = transcode_subtitles(ist, &avpkt, &got_output);
break;
default:
return -1;
}
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n",
ist->file_index, ist->st->index, av_err2str(ret));
if (exit_on_error)
exit_program(1);
break;
}
avpkt.dts=
avpkt.pts= AV_NOPTS_VALUE;
// touch data and size only if not EOF
if (pkt) {
if(ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO)
ret = avpkt.size;
avpkt.data += ret;
avpkt.size -= ret;
}
if (!got_output) {
continue;
}
if (got_output && !pkt)
break;
}
/* after flushing, send an EOF on all the filter inputs attached to the stream */
/* except when looping we need to flush but not to send an EOF */
if (!pkt && ist->decoding_needed && !got_output && !no_eof) {
int ret = send_filter_eof(ist);
if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n");
exit_program(1);
}
}
/* handle stream copy */
if (!ist->decoding_needed) {
ist->dts = ist->next_dts;
switch (ist->dec_ctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) /
ist->dec_ctx->sample_rate;
break;
case AVMEDIA_TYPE_VIDEO:
if (ist->framerate.num) {
// TODO: Remove work-around for c99-to-c89 issue 7
AVRational time_base_q = AV_TIME_BASE_Q;
int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
} else if (pkt->duration) {
ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
} else if(ist->dec_ctx->framerate.num != 0) {
int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;
ist->next_dts += ((int64_t)AV_TIME_BASE *
ist->dec_ctx->framerate.den * ticks) /
ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame;
}
break;
}
ist->pts = ist->dts;
ist->next_pts = ist->next_dts;
}
for (i = 0; pkt && i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
if (!check_output_constraints(ist, ost) || ost->encoding_needed)
continue;
do_streamcopy(ist, ost, pkt);
}
return got_output;
}
| true | FFmpeg | 8f6f2322285fc14f8f16377db50355864019a757 |
3,831 | static int interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,
int stream_index, int flush)
{
AVStream *st = s->streams[stream_index];
AudioInterleaveContext *aic = st->priv_data;
int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);
if (!size || (!flush && size == av_fifo_size(aic->fifo)))
return 0;
av_new_packet(pkt, size);
av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);
pkt->dts = pkt->pts = aic->dts;
pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
pkt->stream_index = stream_index;
aic->dts += pkt->duration;
aic->samples++;
if (!*aic->samples)
aic->samples = aic->samples_per_frame;
return size;
}
| false | FFmpeg | 1967cd4e4c1cd96dfa195ce14e4b212ddb70586d |
3,833 | static void memcard_write(void *opaque, target_phys_addr_t addr, uint64_t value,
unsigned size)
{
MilkymistMemcardState *s = opaque;
trace_milkymist_memcard_memory_write(addr, value);
addr >>= 2;
switch (addr) {
case R_PENDING:
/* clear rx pending bits */
s->regs[R_PENDING] &= ~(value & (PENDING_CMD_RX | PENDING_DAT_RX));
update_pending_bits(s);
break;
case R_CMD:
if (!s->enabled) {
break;
}
if (s->ignore_next_cmd) {
s->ignore_next_cmd = 0;
break;
}
s->command[s->command_write_ptr] = value & 0xff;
s->command_write_ptr = (s->command_write_ptr + 1) % 6;
if (s->command_write_ptr == 0) {
memcard_sd_command(s);
}
break;
case R_DAT:
if (!s->enabled) {
break;
}
sd_write_data(s->card, (value >> 24) & 0xff);
sd_write_data(s->card, (value >> 16) & 0xff);
sd_write_data(s->card, (value >> 8) & 0xff);
sd_write_data(s->card, value & 0xff);
break;
case R_ENABLE:
s->regs[addr] = value;
update_pending_bits(s);
break;
case R_CLK2XDIV:
case R_START:
s->regs[addr] = value;
break;
default:
error_report("milkymist_memcard: write access to unknown register 0x"
TARGET_FMT_plx, addr << 2);
break;
}
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c |
3,835 | static uint32_t arm_v7m_load_vector(ARMCPU *cpu)
{
CPUState *cs = CPU(cpu);
CPUARMState *env = &cpu->env;
MemTxResult result;
hwaddr vec = env->v7m.vecbase + env->v7m.exception * 4;
uint32_t addr;
addr = address_space_ldl(cs->as, vec,
MEMTXATTRS_UNSPECIFIED, &result);
if (result != MEMTX_OK) {
/* Architecturally this should cause a HardFault setting HSFR.VECTTBL,
* which would then be immediately followed by our failing to load
* the entry vector for that HardFault, which is a Lockup case.
* Since we don't model Lockup, we just report this guest error
* via cpu_abort().
*/
cpu_abort(cs, "Failed to read from exception vector table "
"entry %08x\n", (unsigned)vec);
}
return addr;
}
| false | qemu | 45db7ba681ede57113a67499840e69ee586bcdf2 |
3,836 | static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque)
{
SerialState *s = opaque;
if (s->tsr_retry <= 0) {
if (s->fcr & UART_FCR_FE) {
s->tsr = fifo8_is_full(&s->xmit_fifo) ?
0 : fifo8_pop(&s->xmit_fifo);
if (!s->xmit_fifo.num) {
s->lsr |= UART_LSR_THRE;
}
} else if ((s->lsr & UART_LSR_THRE)) {
return FALSE;
} else {
s->tsr = s->thr;
s->lsr |= UART_LSR_THRE;
s->lsr &= ~UART_LSR_TEMT;
}
}
if (s->mcr & UART_MCR_LOOP) {
/* in loopback mode, say that we just received a char */
serial_receive1(s, &s->tsr, 1);
} else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) {
if (s->tsr_retry >= 0 && s->tsr_retry < MAX_XMIT_RETRY &&
qemu_chr_fe_add_watch(s->chr, G_IO_OUT, serial_xmit, s) > 0) {
s->tsr_retry++;
return FALSE;
}
s->tsr_retry = 0;
} else {
s->tsr_retry = 0;
}
s->last_xmit_ts = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
if (s->lsr & UART_LSR_THRE) {
s->lsr |= UART_LSR_TEMT;
s->thr_ipending = 1;
serial_update_irq(s);
}
return FALSE;
}
| false | qemu | 88c1ee73d3231c74ff90bcfc084a7589670ec244 |
3,837 | ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)
{
uint8_t buf[NBD_REQUEST_SIZE];
TRACE("Sending request to server: "
"{ .from = %" PRIu64", .len = %" PRIu32 ", .handle = %" PRIu64
", .flags = %" PRIx16 ", .type = %" PRIu16 " }",
request->from, request->len, request->handle,
request->flags, request->type);
stl_be_p(buf, NBD_REQUEST_MAGIC);
stw_be_p(buf + 4, request->flags);
stw_be_p(buf + 6, request->type);
stq_be_p(buf + 8, request->handle);
stq_be_p(buf + 16, request->from);
stl_be_p(buf + 24, request->len);
return write_sync(ioc, buf, sizeof(buf), NULL);
}
| false | qemu | d1fdf257d52822695f5ace6c586e059aa17d4b79 |
3,839 | static AVFilterContext *create_filter(AVFilterGraph *ctx, int index,
const char *name, const char *args,
AVClass *log_ctx)
{
AVFilterContext *filt;
AVFilter *filterdef;
char inst_name[30];
snprintf(inst_name, sizeof(inst_name), "Parsed filter %d", index);
if(!(filterdef = avfilter_get_by_name(name))) {
av_log(log_ctx, AV_LOG_ERROR,
"no such filter: '%s'\n", name);
return NULL;
}
if(!(filt = avfilter_open(filterdef, inst_name))) {
av_log(log_ctx, AV_LOG_ERROR,
"error creating filter '%s'\n", name);
return NULL;
}
if(avfilter_graph_add_filter(ctx, filt) < 0)
return NULL;
if(avfilter_init_filter(filt, args, NULL)) {
av_log(log_ctx, AV_LOG_ERROR,
"error initializing filter '%s' with args '%s'\n", name, args);
return NULL;
}
return filt;
}
| false | FFmpeg | 5e600185453e1a0ded70a59701f60a0022a88e42 |
3,840 | static void scsi_dma_complete_noio(void *opaque, int ret)
{
SCSIDiskReq *r = (SCSIDiskReq *)opaque;
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
}
if (r->req.io_canceled) {
goto done;
}
if (ret < 0) {
if (scsi_handle_rw_error(r, -ret)) {
goto done;
}
}
r->sector += r->sector_count;
r->sector_count = 0;
if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
scsi_write_do_fua(r);
return;
} else {
scsi_req_complete(&r->req, GOOD);
}
done:
if (!r->req.io_canceled) {
scsi_req_unref(&r->req);
}
}
| false | qemu | 3df9caf88f5c0859ae380101fea47609ba1dbfbd |
3,841 | int vnc_display_password(DisplayState *ds, const char *password)
{
VncDisplay *vs = vnc_display;
if (!vs) {
return -EINVAL;
}
if (!password) {
/* This is not the intention of this interface but err on the side
of being safe */
return vnc_display_disable_login(ds);
}
if (vs->password) {
g_free(vs->password);
vs->password = NULL;
}
vs->password = g_strdup(password);
if (vs->auth == VNC_AUTH_NONE) {
vs->auth = VNC_AUTH_VNC;
}
return 0;
}
| false | qemu | cf864569cd9134ee503ad9eb6be2881001c0ed80 |
3,842 | START_TEST(qdict_get_str_test)
{
const char *p;
const char *key = "key";
const char *str = "string";
qdict_put(tests_dict, key, qstring_from_str(str));
p = qdict_get_str(tests_dict, key);
fail_unless(p != NULL);
fail_unless(strcmp(p, str) == 0);
}
| false | qemu | ac531cb6e542b1e61d668604adf9dc5306a948c0 |
3,843 | static void rtas_set_tce_bypass(sPAPREnvironment *spapr, uint32_t token,
uint32_t nargs, target_ulong args,
uint32_t nret, target_ulong rets)
{
VIOsPAPRBus *bus = spapr->vio_bus;
VIOsPAPRDevice *dev;
uint32_t unit, enable;
if (nargs != 2) {
rtas_st(rets, 0, -3);
return;
}
unit = rtas_ld(args, 0);
enable = rtas_ld(args, 1);
dev = spapr_vio_find_by_reg(bus, unit);
if (!dev) {
rtas_st(rets, 0, -3);
return;
}
if (!dev->tcet) {
rtas_st(rets, 0, -3);
return;
}
spapr_tce_set_bypass(dev->tcet, !!enable);
rtas_st(rets, 0, 0);
}
| false | qemu | 210b580b106fa798149e28aa13c66b325a43204e |
3,844 | void uuid_generate(uuid_t out)
{
memset(out, 0, sizeof(uuid_t));
}
| false | qemu | 8ba2aae32c40f544def6be7ae82be9bcb781e01d |
3,846 | static void test_unaligned_write_same(void)
{
QVirtIOSCSI *vs;
uint8_t buf[512] = { 0 };
const uint8_t write_same_cdb[CDB_SIZE] = { 0x41, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x02, 0x00 };
qvirtio_scsi_start("-drive file=blkdebug::null-co://,if=none,id=dr1"
",format=raw,file.align=4k "
"-device scsi-disk,drive=dr1,lun=0,scsi-id=1");
vs = qvirtio_scsi_pci_init(PCI_SLOT);
g_assert_cmphex(0, ==,
virtio_scsi_do_command(vs, write_same_cdb, NULL, 0, buf, 512));
qvirtio_scsi_pci_free(vs);
qvirtio_scsi_stop();
}
| false | qemu | 4bb7b0daf8ea34bcc582642d35a2e4902f7841db |
3,847 | static void *spapr_build_fdt(sPAPRMachineState *spapr,
hwaddr rtas_addr,
hwaddr rtas_size)
{
MachineState *machine = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(machine);
sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
int ret;
void *fdt;
sPAPRPHBState *phb;
char *buf;
fdt = g_malloc0(FDT_MAX_SIZE);
_FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE)));
/* Root node */
_FDT(fdt_setprop_string(fdt, 0, "device_type", "chrp"));
_FDT(fdt_setprop_string(fdt, 0, "model", "IBM pSeries (emulated by qemu)"));
_FDT(fdt_setprop_string(fdt, 0, "compatible", "qemu,pseries"));
/*
* Add info to guest to indentify which host is it being run on
* and what is the uuid of the guest
*/
if (kvmppc_get_host_model(&buf)) {
_FDT(fdt_setprop_string(fdt, 0, "host-model", buf));
g_free(buf);
}
if (kvmppc_get_host_serial(&buf)) {
_FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));
g_free(buf);
}
buf = qemu_uuid_unparse_strdup(&qemu_uuid);
_FDT(fdt_setprop_string(fdt, 0, "vm,uuid", buf));
if (qemu_uuid_set) {
_FDT(fdt_setprop_string(fdt, 0, "system-id", buf));
}
g_free(buf);
if (qemu_get_vm_name()) {
_FDT(fdt_setprop_string(fdt, 0, "ibm,partition-name",
qemu_get_vm_name()));
}
_FDT(fdt_setprop_cell(fdt, 0, "#address-cells", 2));
_FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2));
/* /interrupt controller */
spapr_dt_xics(spapr->xics, fdt, PHANDLE_XICP);
ret = spapr_populate_memory(spapr, fdt);
if (ret < 0) {
error_report("couldn't setup memory nodes in fdt");
exit(1);
}
/* /vdevice */
spapr_dt_vdevice(spapr->vio_bus, fdt);
if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) {
ret = spapr_rng_populate_dt(fdt);
if (ret < 0) {
error_report("could not set up rng device in the fdt");
exit(1);
}
}
QLIST_FOREACH(phb, &spapr->phbs, list) {
ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);
if (ret < 0) {
error_report("couldn't setup PCI devices in fdt");
exit(1);
}
}
/* cpus */
spapr_populate_cpus_dt_node(fdt, spapr);
if (smc->dr_lmb_enabled) {
_FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));
}
if (mc->query_hotpluggable_cpus) {
int offset = fdt_path_offset(fdt, "/cpus");
ret = spapr_drc_populate_dt(fdt, offset, NULL,
SPAPR_DR_CONNECTOR_TYPE_CPU);
if (ret < 0) {
error_report("Couldn't set up CPU DR device tree properties");
exit(1);
}
}
/* /event-sources */
spapr_dt_events(fdt, spapr->check_exception_irq);
/* /rtas */
spapr_dt_rtas(spapr, fdt);
/* /chosen */
spapr_dt_chosen(spapr, fdt);
/* /hypervisor */
if (kvm_enabled()) {
spapr_dt_hypervisor(spapr, fdt);
}
/* Build memory reserve map */
if (spapr->kernel_size) {
_FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_size)));
}
if (spapr->initrd_size) {
_FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, spapr->initrd_size)));
}
/* ibm,client-architecture-support updates */
ret = spapr_dt_cas_updates(spapr, fdt, spapr->ov5_cas);
if (ret < 0) {
error_report("couldn't setup CAS properties fdt");
exit(1);
}
return fdt;
}
| false | qemu | ffbb1705a33df8e2fb12b24d96663d63b22eaf8b |
3,848 | static void cpu_unlink_tb(CPUState *env)
{
#if defined(CONFIG_USE_NPTL)
/* FIXME: TB unchaining isn't SMP safe. For now just ignore the
problem and hope the cpu will stop of its own accord. For userspace
emulation this often isn't actually as bad as it sounds. Often
signals are used primarily to interrupt blocking syscalls. */
#else
TranslationBlock *tb;
static spinlock_t interrupt_lock = SPIN_LOCK_UNLOCKED;
tb = env->current_tb;
/* if the cpu is currently executing code, we must unlink it and
all the potentially executing TB */
if (tb && !testandset(&interrupt_lock)) {
env->current_tb = NULL;
tb_reset_jump_recursive(tb);
resetlock(&interrupt_lock);
}
#endif
}
| false | qemu | f76cfe56d9bc281685c5120bf765d29d9323756f |
3,849 | void ppc_hash64_store_hpte(PowerPCCPU *cpu, hwaddr ptex,
uint64_t pte0, uint64_t pte1)
{
CPUPPCState *env = &cpu->env;
hwaddr offset = ptex * HASH_PTE_SIZE_64;
if (env->external_htab == MMU_HASH64_KVM_MANAGED_HPT) {
kvmppc_write_hpte(ptex, pte0, pte1);
return;
}
if (env->external_htab) {
stq_p(env->external_htab + offset, pte0);
stq_p(env->external_htab + offset + HASH_PTE_SIZE_64 / 2, pte1);
} else {
hwaddr base = ppc_hash64_hpt_base(cpu);
stq_phys(CPU(cpu)->as, base + offset, pte0);
stq_phys(CPU(cpu)->as, base + offset + HASH_PTE_SIZE_64 / 2, pte1);
}
}
| false | qemu | e57ca75ce3b2bd33102573a8c0555d62e1bcfceb |
3,850 | static int get_last_needed_nal(H264Context *h)
{
int nals_needed = 0;
int i;
for (i = 0; i < h->pkt.nb_nals; i++) {
H2645NAL *nal = &h->pkt.nals[i];
GetBitContext gb;
/* packets can sometimes contain multiple PPS/SPS,
* e.g. two PAFF field pictures in one packet, or a demuxer
* which splits NALs strangely if so, when frame threading we
* can't start the next thread until we've read all of them */
switch (nal->type) {
case NAL_SPS:
case NAL_PPS:
nals_needed = i;
break;
case NAL_DPA:
case NAL_IDR_SLICE:
case NAL_SLICE:
init_get_bits(&gb, nal->data + 1, (nal->size - 1) * 8);
if (!get_ue_golomb(&gb))
nals_needed = i;
}
}
return nals_needed;
}
| false | FFmpeg | 5c2fb561d94fc51d76ab21d6f7cc5b6cc3aa599c |
3,851 | static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
rcu_register_thread();
qemu_mutex_lock_iothread();
qemu_thread_get_self(cpu->thread);
CPU_FOREACH(cpu) {
cpu->thread_id = qemu_get_thread_id();
cpu->created = true;
cpu->can_do_io = 1;
}
qemu_cond_signal(&qemu_cpu_cond);
/* wait for initial kick-off after machine start */
while (first_cpu->stopped) {
qemu_cond_wait(first_cpu->halt_cond, &qemu_global_mutex);
/* process any pending work */
CPU_FOREACH(cpu) {
current_cpu = cpu;
qemu_wait_io_event_common(cpu);
}
}
start_tcg_kick_timer();
cpu = first_cpu;
/* process any pending work */
cpu->exit_request = 1;
while (1) {
/* Account partial waits to QEMU_CLOCK_VIRTUAL. */
qemu_account_warp_timer();
if (!cpu) {
cpu = first_cpu;
}
while (cpu && !cpu->queued_work_first && !cpu->exit_request) {
atomic_mb_set(&tcg_current_rr_cpu, cpu);
current_cpu = cpu;
qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
(cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
if (cpu_can_run(cpu)) {
int r;
r = tcg_cpu_exec(cpu);
if (r == EXCP_DEBUG) {
cpu_handle_guest_debug(cpu);
break;
} else if (r == EXCP_ATOMIC) {
qemu_mutex_unlock_iothread();
cpu_exec_step_atomic(cpu);
qemu_mutex_lock_iothread();
break;
}
} else if (cpu->stop) {
if (cpu->unplug) {
cpu = CPU_NEXT(cpu);
}
break;
}
cpu = CPU_NEXT(cpu);
} /* while (cpu && !cpu->exit_request).. */
/* Does not need atomic_mb_set because a spurious wakeup is okay. */
atomic_set(&tcg_current_rr_cpu, NULL);
if (cpu && cpu->exit_request) {
atomic_mb_set(&cpu->exit_request, 0);
}
handle_icount_deadline();
qemu_tcg_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus));
deal_with_unplugged_cpus();
}
return NULL;
}
| false | qemu | 6b8f0187a4d7c263e356302f8d308655372a4b5b |
3,852 | static QPCIDevice *start_ahci_device(QPCIDevice *ahci, void **hba_base)
{
/* Map AHCI's ABAR (BAR5) */
*hba_base = qpci_iomap(ahci, 5, NULL);
/* turns on pci.cmd.iose, pci.cmd.mse and pci.cmd.bme */
qpci_device_enable(ahci);
return ahci;
}
| false | qemu | c2f3029fbc5e7beb4cfb7ac264e10838fada524e |
3,853 | static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
BlockInterfaceType type,
Error **errp)
{
const char *buf;
const char *serial;
int ro = 0;
int bdrv_flags = 0;
int on_read_error, on_write_error;
DriveInfo *dinfo;
ThrottleConfig cfg;
int snapshot = 0;
bool copy_on_read;
int ret;
Error *error = NULL;
QemuOpts *opts;
const char *id;
bool has_driver_specific_opts;
BlockDriver *drv = NULL;
/* Check common options by copying from bs_opts to opts, all other options
* stay in bs_opts for processing by bdrv_open(). */
id = qdict_get_try_str(bs_opts, "id");
opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
return NULL;
}
qemu_opts_absorb_qdict(opts, bs_opts, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
goto early_err;
}
if (id) {
qdict_del(bs_opts, "id");
}
has_driver_specific_opts = !!qdict_size(bs_opts);
/* extract parameters */
snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
ro = qemu_opt_get_bool(opts, "read-only", 0);
copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
serial = qemu_opt_get(opts, "serial");
if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
error_setg(errp, "invalid discard option");
goto early_err;
}
}
if (qemu_opt_get_bool(opts, "cache.writeback", true)) {
bdrv_flags |= BDRV_O_CACHE_WB;
}
if (qemu_opt_get_bool(opts, "cache.direct", false)) {
bdrv_flags |= BDRV_O_NOCACHE;
}
if (qemu_opt_get_bool(opts, "cache.no-flush", false)) {
bdrv_flags |= BDRV_O_NO_FLUSH;
}
#ifdef CONFIG_LINUX_AIO
if ((buf = qemu_opt_get(opts, "aio")) != NULL) {
if (!strcmp(buf, "native")) {
bdrv_flags |= BDRV_O_NATIVE_AIO;
} else if (!strcmp(buf, "threads")) {
/* this is the default */
} else {
error_setg(errp, "invalid aio option");
goto early_err;
}
}
#endif
if ((buf = qemu_opt_get(opts, "format")) != NULL) {
if (is_help_option(buf)) {
error_printf("Supported formats:");
bdrv_iterate_format(bdrv_format_print, NULL);
error_printf("\n");
goto early_err;
}
drv = bdrv_find_format(buf);
if (!drv) {
error_setg(errp, "'%s' invalid format", buf);
goto early_err;
}
}
/* disk I/O throttling */
memset(&cfg, 0, sizeof(cfg));
cfg.buckets[THROTTLE_BPS_TOTAL].avg =
qemu_opt_get_number(opts, "throttling.bps-total", 0);
cfg.buckets[THROTTLE_BPS_READ].avg =
qemu_opt_get_number(opts, "throttling.bps-read", 0);
cfg.buckets[THROTTLE_BPS_WRITE].avg =
qemu_opt_get_number(opts, "throttling.bps-write", 0);
cfg.buckets[THROTTLE_OPS_TOTAL].avg =
qemu_opt_get_number(opts, "throttling.iops-total", 0);
cfg.buckets[THROTTLE_OPS_READ].avg =
qemu_opt_get_number(opts, "throttling.iops-read", 0);
cfg.buckets[THROTTLE_OPS_WRITE].avg =
qemu_opt_get_number(opts, "throttling.iops-write", 0);
cfg.buckets[THROTTLE_BPS_TOTAL].max =
qemu_opt_get_number(opts, "throttling.bps-total-max", 0);
cfg.buckets[THROTTLE_BPS_READ].max =
qemu_opt_get_number(opts, "throttling.bps-read-max", 0);
cfg.buckets[THROTTLE_BPS_WRITE].max =
qemu_opt_get_number(opts, "throttling.bps-write-max", 0);
cfg.buckets[THROTTLE_OPS_TOTAL].max =
qemu_opt_get_number(opts, "throttling.iops-total-max", 0);
cfg.buckets[THROTTLE_OPS_READ].max =
qemu_opt_get_number(opts, "throttling.iops-read-max", 0);
cfg.buckets[THROTTLE_OPS_WRITE].max =
qemu_opt_get_number(opts, "throttling.iops-write-max", 0);
cfg.op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0);
if (!check_throttle_config(&cfg, &error)) {
error_propagate(errp, error);
goto early_err;
}
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) {
error_setg(errp, "werror is not supported by this bus type");
goto early_err;
}
on_write_error = parse_block_error_action(buf, 0, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
goto early_err;
}
}
on_read_error = BLOCKDEV_ON_ERROR_REPORT;
if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type != IF_NONE) {
error_report("rerror is not supported by this bus type");
goto early_err;
}
on_read_error = parse_block_error_action(buf, 1, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
goto early_err;
}
}
/* init */
dinfo = g_malloc0(sizeof(*dinfo));
dinfo->id = g_strdup(qemu_opts_id(opts));
dinfo->bdrv = bdrv_new(dinfo->id);
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
dinfo->bdrv->read_only = ro;
dinfo->type = type;
dinfo->refcount = 1;
if (serial != NULL) {
dinfo->serial = g_strdup(serial);
}
QTAILQ_INSERT_TAIL(&drives, dinfo, next);
bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error);
/* disk I/O throttling */
if (throttle_enabled(&cfg)) {
bdrv_io_limits_enable(dinfo->bdrv);
bdrv_set_io_limits(dinfo->bdrv, &cfg);
}
if (!file || !*file) {
if (has_driver_specific_opts) {
file = NULL;
} else {
QDECREF(bs_opts);
qemu_opts_del(opts);
return dinfo;
}
}
if (snapshot) {
/* always use cache=unsafe with snapshot */
bdrv_flags &= ~BDRV_O_CACHE_MASK;
bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH);
}
if (copy_on_read) {
bdrv_flags |= BDRV_O_COPY_ON_READ;
}
if (runstate_check(RUN_STATE_INMIGRATE)) {
bdrv_flags |= BDRV_O_INCOMING;
}
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
QINCREF(bs_opts);
ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
if (ret < 0) {
error_setg(errp, "could not open disk image %s: %s",
file ?: dinfo->id, error_get_pretty(error));
error_free(error);
goto err;
}
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
QDECREF(bs_opts);
qemu_opts_del(opts);
return dinfo;
err:
bdrv_unref(dinfo->bdrv);
g_free(dinfo->id);
QTAILQ_REMOVE(&drives, dinfo, next);
g_free(dinfo);
early_err:
QDECREF(bs_opts);
qemu_opts_del(opts);
return NULL;
}
| false | qemu | ee13ed1cbc5f7f848e417f587c93ca1f36d83eb0 |
3,854 | static void tcp_chr_connect(void *opaque)
{
CharDriverState *chr = opaque;
TCPCharDriver *s = chr->opaque;
struct sockaddr_storage ss, ps;
socklen_t ss_len = sizeof(ss), ps_len = sizeof(ps);
memset(&ss, 0, ss_len);
if (getsockname(s->fd, (struct sockaddr *) &ss, &ss_len) != 0) {
snprintf(chr->filename, CHR_MAX_FILENAME_SIZE,
"Error in getsockname: %s\n", strerror(errno));
} else if (getpeername(s->fd, (struct sockaddr *) &ps, &ps_len) != 0) {
snprintf(chr->filename, CHR_MAX_FILENAME_SIZE,
"Error in getpeername: %s\n", strerror(errno));
} else {
sockaddr_to_str(chr->filename, CHR_MAX_FILENAME_SIZE,
&ss, ss_len, &ps, ps_len,
s->is_listen, s->is_telnet);
}
s->connected = 1;
if (s->chan) {
chr->fd_in_tag = io_add_watch_poll(s->chan, tcp_chr_read_poll,
tcp_chr_read, chr);
}
qemu_chr_be_generic_open(chr);
}
| false | qemu | 0ff0fad23d3693ecf7a0c462cdb48f0e60f93808 |
3,855 | static inline int get_bat(CPUPPCState *env, mmu_ctx_t *ctx,
target_ulong virtual, int rw, int type)
{
target_ulong *BATlt, *BATut, *BATu, *BATl;
target_ulong BEPIl, BEPIu, bl;
int i, valid, prot;
int ret = -1;
LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__,
type == ACCESS_CODE ? 'I' : 'D', virtual);
switch (type) {
case ACCESS_CODE:
BATlt = env->IBAT[1];
BATut = env->IBAT[0];
break;
default:
BATlt = env->DBAT[1];
BATut = env->DBAT[0];
break;
}
for (i = 0; i < env->nb_BATs; i++) {
BATu = &BATut[i];
BATl = &BATlt[i];
BEPIu = *BATu & 0xF0000000;
BEPIl = *BATu & 0x0FFE0000;
if (unlikely(env->mmu_model == POWERPC_MMU_601)) {
bat_601_size_prot(env, &bl, &valid, &prot, BATu, BATl);
} else {
bat_size_prot(env, &bl, &valid, &prot, BATu, BATl);
}
LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx
" BATl " TARGET_FMT_lx "\n", __func__,
type == ACCESS_CODE ? 'I' : 'D', i, virtual, *BATu, *BATl);
if ((virtual & 0xF0000000) == BEPIu &&
((virtual & 0x0FFE0000) & ~bl) == BEPIl) {
/* BAT matches */
if (valid != 0) {
/* Get physical address */
ctx->raddr = (*BATl & 0xF0000000) |
((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |
(virtual & 0x0001F000);
/* Compute access rights */
ctx->prot = prot;
ret = check_prot(ctx->prot, rw, type);
if (ret == 0) {
LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n",
i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-',
ctx->prot & PAGE_WRITE ? 'W' : '-');
}
break;
}
}
}
if (ret < 0) {
#if defined(DEBUG_BATS)
if (qemu_log_enabled()) {
LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", virtual);
for (i = 0; i < 4; i++) {
BATu = &BATut[i];
BATl = &BATlt[i];
BEPIu = *BATu & 0xF0000000;
BEPIl = *BATu & 0x0FFE0000;
bl = (*BATu & 0x00001FFC) << 15;
LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx
" BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "
TARGET_FMT_lx " " TARGET_FMT_lx "\n",
__func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual,
*BATu, *BATl, BEPIu, BEPIl, bl);
}
}
#endif
}
/* No hit */
return ret;
}
| false | qemu | 629bd516fda67c95ba1c7d1393bacb9e68ea0712 |
3,856 | static void ehci_flush_qh(EHCIQueue *q)
{
uint32_t *qh = (uint32_t *) &q->qh;
uint32_t dwords = sizeof(EHCIqh) >> 2;
uint32_t addr = NLPTR_GET(q->qhaddr);
put_dwords(addr + 3 * sizeof(uint32_t), qh + 3, dwords - 3);
}
| false | qemu | 68d553587c0aa271c3eb2902921b503740d775b6 |
3,857 | static void v9fs_statfs(void *opaque)
{
int32_t fid;
ssize_t retval = 0;
size_t offset = 7;
V9fsFidState *fidp;
struct statfs stbuf;
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
pdu_unmarshal(pdu, offset, "d", &fid);
fidp = get_fid(pdu, fid);
if (fidp == NULL) {
retval = -ENOENT;
goto out_nofid;
}
retval = v9fs_co_statfs(pdu, &fidp->path, &stbuf);
if (retval < 0) {
goto out;
}
retval = offset;
retval += v9fs_fill_statfs(s, pdu, &stbuf);
out:
put_fid(pdu, fidp);
out_nofid:
complete_pdu(s, pdu, retval);
return;
}
| false | qemu | ddca7f86ac022289840e0200fd4050b2b58e9176 |
3,860 | static enum AVPixelFormat get_chroma_format(SchroChromaFormat schro_pix_fmt)
{
int num_formats = sizeof(schro_pixel_format_map) /
sizeof(schro_pixel_format_map[0]);
int idx;
for (idx = 0; idx < num_formats; ++idx)
if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt)
return schro_pixel_format_map[idx].ff_pix_fmt;
return AV_PIX_FMT_NONE;
}
| true | FFmpeg | 220b24c7c97dc033ceab1510549f66d0e7b52ef1 |
3,861 | static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
{
unsigned int opc, op2, op3, rn, op4;
opc = extract32(insn, 21, 4);
op2 = extract32(insn, 16, 5);
op3 = extract32(insn, 10, 6);
rn = extract32(insn, 5, 5);
op4 = extract32(insn, 0, 5);
if (op4 != 0x0 || op3 != 0x0 || op2 != 0x1f) {
unallocated_encoding(s);
}
switch (opc) {
case 0: /* BR */
case 2: /* RET */
break;
case 1: /* BLR */
tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
break;
case 4: /* ERET */
case 5: /* DRPS */
if (rn != 0x1f) {
unallocated_encoding(s);
} else {
unsupported_encoding(s, insn);
}
default:
unallocated_encoding(s);
}
tcg_gen_mov_i64(cpu_pc, cpu_reg(s, rn));
} | true | qemu | 52e60cdd342dc48116edb81b443ba8c0a0c6f1a3 |
3,862 | static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr,
int idx)
{
OpenPICState *opp = opaque;
IRQ_src_t *src;
IRQ_dst_t *dst;
uint32_t retval;
int n_IRQ;
DPRINTF("%s: cpu %d addr " TARGET_FMT_plx "\n", __func__, idx, addr);
retval = 0xFFFFFFFF;
if (idx < 0) {
return retval;
}
if (addr & 0xF)
return retval;
dst = &opp->dst[idx];
addr &= 0xFF0;
switch (addr) {
case 0x80: /* PCTP */
retval = dst->pctp;
break;
case 0x90: /* WHOAMI */
retval = idx;
break;
case 0xA0: /* PIAC */
DPRINTF("Lower OpenPIC INT output\n");
qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]);
n_IRQ = IRQ_get_next(opp, &dst->raised);
DPRINTF("PIAC: irq=%d\n", n_IRQ);
if (n_IRQ == -1) {
/* No more interrupt pending */
retval = opp->spve;
} else {
src = &opp->src[n_IRQ];
if (!(src->ipvp & IPVP_ACTIVITY_MASK) ||
!(IPVP_PRIORITY(src->ipvp) > dst->pctp)) {
/* - Spurious level-sensitive IRQ
* - Priorities has been changed
* and the pending IRQ isn't allowed anymore
*/
src->ipvp &= ~IPVP_ACTIVITY_MASK;
retval = opp->spve;
} else {
/* IRQ enter servicing state */
IRQ_setbit(&dst->servicing, n_IRQ);
retval = IPVP_VECTOR(opp, src->ipvp);
}
IRQ_resetbit(&dst->raised, n_IRQ);
dst->raised.next = -1;
if (!(src->ipvp & IPVP_SENSE_MASK)) {
/* edge-sensitive IRQ */
src->ipvp &= ~IPVP_ACTIVITY_MASK;
src->pending = 0;
}
if ((n_IRQ >= opp->irq_ipi0) && (n_IRQ < (opp->irq_ipi0 + MAX_IPI))) {
src->ide &= ~(1 << idx);
if (src->ide && !(src->ipvp & IPVP_SENSE_MASK)) {
/* trigger on CPUs that didn't know about it yet */
openpic_set_irq(opp, n_IRQ, 1);
openpic_set_irq(opp, n_IRQ, 0);
/* if all CPUs knew about it, set active bit again */
src->ipvp |= IPVP_ACTIVITY_MASK;
}
}
}
break;
case 0xB0: /* PEOI */
retval = 0;
break;
default:
break;
}
DPRINTF("%s: => %08x\n", __func__, retval);
return retval;
}
| true | qemu | af7e9e74c6a62a5bcd911726a9e88d28b61490e0 |
3,863 | static const unsigned char *seq_decode_op3(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst)
{
int pos, offset;
do {
pos = *src++;
offset = ((pos >> 3) & 7) * seq->frame.linesize[0] + (pos & 7);
dst[offset] = *src++;
} while (!(pos & 0x80));
return src;
}
| true | FFmpeg | 5d7e3d71673d64a16b58430a0027afadb6b3a54e |
3,864 | static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
{
Vp3DecodeContext *s = avctx->priv_data;
int visible_width, visible_height, colorspace;
int offset_x = 0, offset_y = 0;
AVRational fps, aspect;
s->theora = get_bits_long(gb, 24);
av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora);
/* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */
/* but previous versions have the image flipped relative to vp3 */
if (s->theora < 0x030200)
{
s->flipped_image = 1;
av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
}
visible_width = s->width = get_bits(gb, 16) << 4;
visible_height = s->height = get_bits(gb, 16) << 4;
if(av_image_check_size(s->width, s->height, 0, avctx)){
av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height);
s->width= s->height= 0;
return -1;
}
if (s->theora >= 0x030200) {
visible_width = get_bits_long(gb, 24);
visible_height = get_bits_long(gb, 24);
offset_x = get_bits(gb, 8); /* offset x */
offset_y = get_bits(gb, 8); /* offset y, from bottom */
}
fps.num = get_bits_long(gb, 32);
fps.den = get_bits_long(gb, 32);
if (fps.num && fps.den) {
av_reduce(&avctx->time_base.num, &avctx->time_base.den,
fps.den, fps.num, 1<<30);
}
aspect.num = get_bits_long(gb, 24);
aspect.den = get_bits_long(gb, 24);
if (aspect.num && aspect.den) {
av_reduce(&avctx->sample_aspect_ratio.num,
&avctx->sample_aspect_ratio.den,
aspect.num, aspect.den, 1<<30);
}
if (s->theora < 0x030200)
skip_bits(gb, 5); /* keyframe frequency force */
colorspace = get_bits(gb, 8);
skip_bits(gb, 24); /* bitrate */
skip_bits(gb, 6); /* quality hint */
if (s->theora >= 0x030200)
{
skip_bits(gb, 5); /* keyframe frequency force */
avctx->pix_fmt = theora_pix_fmts[get_bits(gb, 2)];
if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "Invalid pixel format\n");
return AVERROR_INVALIDDATA;
}
skip_bits(gb, 3); /* reserved */
}
// align_get_bits(gb);
if ( visible_width <= s->width && visible_width > s->width-16
&& visible_height <= s->height && visible_height > s->height-16
&& !offset_x && (offset_y == s->height - visible_height))
avcodec_set_dimensions(avctx, visible_width, visible_height);
else
avcodec_set_dimensions(avctx, s->width, s->height);
if (colorspace == 1) {
avctx->color_primaries = AVCOL_PRI_BT470M;
} else if (colorspace == 2) {
avctx->color_primaries = AVCOL_PRI_BT470BG;
}
if (colorspace == 1 || colorspace == 2) {
avctx->colorspace = AVCOL_SPC_BT470BG;
avctx->color_trc = AVCOL_TRC_BT709;
}
return 0;
}
| true | FFmpeg | a56d963f111b1a192cdabb05500f8083bd77ca93 |
3,865 | static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
{
CDXLDemuxContext *cdxl = s->priv_data;
AVIOContext *pb = s->pb;
uint32_t current_size, video_size, image_size;
uint16_t audio_size, palette_size, width, height;
int64_t pos;
int ret;
if (pb->eof_reached)
return AVERROR_EOF;
pos = avio_tell(pb);
if (!cdxl->read_chunk &&
avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE)
return AVERROR_EOF;
if (cdxl->header[0] != 1) {
av_log(s, AV_LOG_ERROR, "non-standard cdxl file\n");
return AVERROR_INVALIDDATA;
}
current_size = AV_RB32(&cdxl->header[2]);
width = AV_RB16(&cdxl->header[14]);
height = AV_RB16(&cdxl->header[16]);
palette_size = AV_RB16(&cdxl->header[20]);
audio_size = AV_RB16(&cdxl->header[22]);
image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
video_size = palette_size + image_size;
if (palette_size > 512)
return AVERROR_INVALIDDATA;
if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE)
return AVERROR_INVALIDDATA;
if (cdxl->read_chunk && audio_size) {
if (cdxl->audio_stream_index == -1) {
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = 0;
st->codec->codec_id = CODEC_ID_PCM_S8;
st->codec->channels = cdxl->header[1] & 0x10 ? 2 : 1;
st->codec->sample_rate = cdxl->sample_rate;
st->start_time = 0;
cdxl->audio_stream_index = st->index;
avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate);
}
ret = av_get_packet(pb, pkt, audio_size);
if (ret < 0)
return ret;
pkt->stream_index = cdxl->audio_stream_index;
pkt->pos = pos;
pkt->duration = audio_size;
cdxl->read_chunk = 0;
} else {
if (cdxl->video_stream_index == -1) {
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_tag = 0;
st->codec->codec_id = CODEC_ID_CDXL;
st->codec->width = width;
st->codec->height = height;
st->start_time = 0;
cdxl->video_stream_index = st->index;
if (cdxl->framerate)
avpriv_set_pts_info(st, 64, cdxl->fps.den, cdxl->fps.num);
else
avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate);
}
if (av_new_packet(pkt, video_size + CDXL_HEADER_SIZE) < 0)
return AVERROR(ENOMEM);
memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE);
ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size);
if (ret < 0) {
av_free_packet(pkt);
return ret;
}
pkt->stream_index = cdxl->video_stream_index;
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->pos = pos;
pkt->duration = cdxl->framerate ? 1 : audio_size ? audio_size : 220;
cdxl->read_chunk = audio_size;
}
if (!cdxl->read_chunk)
avio_skip(pb, current_size - audio_size - video_size - CDXL_HEADER_SIZE);
return ret;
} | true | FFmpeg | d7804de351da059bf0c41c2bc2bbc02dbb755c0f |
3,866 | static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
CadenceGEMState *s;
unsigned rxbufsize, bytes_to_copy;
unsigned rxbuf_offset;
uint8_t rxbuf[2048];
uint8_t *rxbuf_ptr;
bool first_desc = true;
int maf;
s = qemu_get_nic_opaque(nc);
/* Is this destination MAC address "for us" ? */
maf = gem_mac_address_filter(s, buf);
if (maf == GEM_RX_REJECT) {
return -1;
/* Discard packets with receive length error enabled ? */
if (s->regs[GEM_NWCFG] & GEM_NWCFG_LERR_DISC) {
unsigned type_len;
/* Fish the ethertype / length field out of the RX packet */
type_len = buf[12] << 8 | buf[13];
/* It is a length field, not an ethertype */
if (type_len < 0x600) {
if (size < type_len) {
/* discard */
return -1;
/*
* Determine configured receive buffer offset (probably 0)
*/
rxbuf_offset = (s->regs[GEM_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
GEM_NWCFG_BUFF_OFST_S;
/* The configure size of each receive buffer. Determines how many
* buffers needed to hold this packet.
*/
rxbufsize = ((s->regs[GEM_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL;
/* Pad to minimum length. Assume FCS field is stripped, logic
* below will increment it to the real minimum of 64 when
* not FCS stripping
*/
if (size < 60) {
size = 60;
/* Strip of FCS field ? (usually yes) */
if (s->regs[GEM_NWCFG] & GEM_NWCFG_STRIP_FCS) {
rxbuf_ptr = (void *)buf;
} else {
unsigned crc_val;
/* The application wants the FCS field, which QEMU does not provide.
* We must try and calculate one.
*/
memcpy(rxbuf, buf, size);
memset(rxbuf + size, 0, sizeof(rxbuf) - size);
rxbuf_ptr = rxbuf;
crc_val = cpu_to_le32(crc32(0, rxbuf, MAX(size, 60)));
memcpy(rxbuf + size, &crc_val, sizeof(crc_val));
bytes_to_copy += 4;
size += 4;
DB_PRINT("config bufsize: %d packet size: %ld\n", rxbufsize, size);
while (bytes_to_copy) {
/* Do nothing if receive is not enabled. */
if (!gem_can_receive(nc)) {
assert(!first_desc);
return -1;
DB_PRINT("copy %d bytes to 0x%x\n", MIN(bytes_to_copy, rxbufsize),
rx_desc_get_buffer(s->rx_desc));
/* Copy packet data to emulated DMA buffer */
cpu_physical_memory_write(rx_desc_get_buffer(s->rx_desc) + rxbuf_offset,
rxbuf_ptr, MIN(bytes_to_copy, rxbufsize));
rxbuf_ptr += MIN(bytes_to_copy, rxbufsize);
bytes_to_copy -= MIN(bytes_to_copy, rxbufsize);
/* Update the descriptor. */
if (first_desc) {
rx_desc_set_sof(s->rx_desc);
first_desc = false;
if (bytes_to_copy == 0) {
rx_desc_set_eof(s->rx_desc);
rx_desc_set_length(s->rx_desc, size);
rx_desc_set_ownership(s->rx_desc);
switch (maf) {
case GEM_RX_PROMISCUOUS_ACCEPT:
break;
case GEM_RX_BROADCAST_ACCEPT:
rx_desc_set_broadcast(s->rx_desc);
break;
case GEM_RX_UNICAST_HASH_ACCEPT:
rx_desc_set_unicast_hash(s->rx_desc);
break;
case GEM_RX_MULTICAST_HASH_ACCEPT:
rx_desc_set_multicast_hash(s->rx_desc);
break;
case GEM_RX_REJECT:
abort();
default: /* SAR */
rx_desc_set_sar(s->rx_desc, maf);
/* Descriptor write-back. */
cpu_physical_memory_write(s->rx_desc_addr,
(uint8_t *)s->rx_desc, sizeof(s->rx_desc));
/* Next descriptor */
if (rx_desc_get_wrap(s->rx_desc)) {
DB_PRINT("wrapping RX descriptor list\n");
s->rx_desc_addr = s->regs[GEM_RXQBASE];
} else {
DB_PRINT("incrementing RX descriptor list\n");
s->rx_desc_addr += 8;
gem_get_rx_desc(s);
/* Count it */
gem_receive_updatestats(s, buf, size);
s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
s->regs[GEM_ISR] |= GEM_INT_RXCMPL & ~(s->regs[GEM_IMR]);
/* Handle interrupt consequences */
gem_update_int_status(s);
return size;
| true | qemu | 244381ec19ce1412b474f41b5f30fe1da846451b |
3,867 | static int mpegts_read_close(AVFormatContext *s)
{
MpegTSContext *ts = s->priv_data;
int i;
clear_programs(ts);
for(i=0;i<NB_PID_MAX;i++)
if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]);
return 0;
}
| true | FFmpeg | a717f9904227d7979473bad40c50eb40af41d01d |
3,868 | int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
enum AVSampleFormat sample_fmt, int align)
{
int line_size;
int sample_size = av_get_bytes_per_sample(sample_fmt);
int planar = av_sample_fmt_is_planar(sample_fmt);
/* validate parameter ranges */
if (!sample_size || nb_samples <= 0 || nb_channels <= 0)
/* auto-select alignment if not specified */
if (!align) {
align = 1;
nb_samples = FFALIGN(nb_samples, 32);
}
/* check for integer overflow */
if (nb_channels > INT_MAX / align ||
(int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
line_size = planar ? FFALIGN(nb_samples * sample_size, align) :
FFALIGN(nb_samples * sample_size * nb_channels, align);
if (linesize)
*linesize = line_size;
return planar ? line_size * nb_channels : line_size;
} | true | FFmpeg | 0e830094ad0dc251613a0aa3234d9c5c397e02e6 |
3,869 | int pt_setxattr(FsContext *ctx, const char *path, const char *name, void *value,
size_t size, int flags)
{
char *buffer;
int ret;
buffer = rpath(ctx, path);
ret = lsetxattr(buffer, name, value, size, flags);
g_free(buffer);
return ret;
}
| true | qemu | 3e36aba757f76673007a80b3cd56a4062c2e3462 |
3,870 | static void gen_b(DisasContext *ctx)
{
target_ulong li, target;
ctx->exception = POWERPC_EXCP_BRANCH;
/* sign extend LI */
#if defined(TARGET_PPC64)
if (ctx->sf_mode)
li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
else
#endif
li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
if (likely(AA(ctx->opcode) == 0))
target = ctx->nip + li - 4;
else
target = li;
if (LK(ctx->opcode))
gen_setlr(ctx, ctx->nip);
gen_goto_tb(ctx, 0, target);
} | true | qemu | 697ab892786d47008807a49f57b2fd86adfcd098 |
3,871 | bool qdict_get_bool(const QDict *qdict, const char *key)
{
QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL);
return qbool_get_bool(qobject_to_qbool(obj));
}
| true | qemu | 14b6160099f0caf5dc9d62e637b007bc5d719a96 |
3,872 | static void adx_encode(unsigned char *adx,const short *wav,
ADXChannelState *prev)
{
int scale;
int i;
int s0,s1,s2,d;
int max=0;
int min=0;
int data[32];
s1 = prev->s1;
s2 = prev->s2;
for(i=0;i<32;i++) {
s0 = wav[i];
d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL;
data[i]=d;
if (max<d) max=d;
if (min>d) min=d;
s2 = s1;
s1 = s0;
}
prev->s1 = s1;
prev->s2 = s2;
/* -8..+7 */
if (max==0 && min==0) {
memset(adx,0,18);
return;
}
if (max/7>-min/8) scale = max/7;
else scale = -min/8;
if (scale==0) scale=1;
AV_WB16(adx, scale);
for(i=0;i<16;i++) {
adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf);
}
}
| true | FFmpeg | 954d94dd5e13ba7a5e9e049d0f980bddced9644c |
3,874 | static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
BdrvTrackedRequest *req, int64_t offset, unsigned int bytes,
int64_t align, QEMUIOVector *qiov, int flags)
{
BlockDriver *drv = bs->drv;
bool waited;
int ret;
int64_t start_sector = offset >> BDRV_SECTOR_BITS;
int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE);
assert(is_power_of_2(align));
assert((offset & (align - 1)) == 0);
assert((bytes & (align - 1)) == 0);
assert(!qiov || bytes == qiov->size);
assert((bs->open_flags & BDRV_O_NO_IO) == 0);
assert(!(flags & ~BDRV_REQ_MASK));
waited = wait_serialising_requests(req);
assert(!waited || !req->serialising);
assert(req->overlap_offset <= offset);
assert(offset + bytes <= req->overlap_offset + req->overlap_bytes);
ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req);
if (!ret && bs->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF &&
!(flags & BDRV_REQ_ZERO_WRITE) && drv->bdrv_co_pwrite_zeroes &&
qemu_iovec_is_zero(qiov)) {
flags |= BDRV_REQ_ZERO_WRITE;
if (bs->detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP) {
flags |= BDRV_REQ_MAY_UNMAP;
}
}
if (ret < 0) {
/* Do nothing, write notifier decided to fail this request */
} else if (flags & BDRV_REQ_ZERO_WRITE) {
bdrv_debug_event(bs, BLKDBG_PWRITEV_ZERO);
ret = bdrv_co_do_pwrite_zeroes(bs, offset, bytes, flags);
} else {
bdrv_debug_event(bs, BLKDBG_PWRITEV);
ret = bdrv_driver_pwritev(bs, offset, bytes, qiov, flags);
}
bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE);
bdrv_set_dirty(bs, start_sector, end_sector - start_sector);
if (bs->wr_highest_offset < offset + bytes) {
bs->wr_highest_offset = offset + bytes;
}
if (ret >= 0) {
bs->total_sectors = MAX(bs->total_sectors, end_sector);
}
return ret;
} | true | qemu | 3ff2f67a7c24183fcbcfe1332e5223ac6f96438c |
3,875 | int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
const void *pp, unsigned pp_size,
const void *qm, unsigned qm_size,
int (*commit_bs_si)(AVCodecContext *,
DECODER_BUFFER_DESC *bs,
DECODER_BUFFER_DESC *slice))
{
AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
unsigned buffer_count = 0;
#if CONFIG_D3D11VA
D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4];
#endif
#if CONFIG_DXVA2
DXVA2_DecodeBufferDesc buffer2[4];
#endif
DECODER_BUFFER_DESC *buffer = NULL, *buffer_slice = NULL;
int result, runs = 0;
HRESULT hr;
unsigned type;
do {
ff_dxva2_lock(avctx);
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,
get_surface(frame),
0, NULL);
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_BeginFrame(DXVA2_CONTEXT(ctx)->decoder,
get_surface(frame),
NULL);
#endif
if (hr != E_PENDING || ++runs > 50)
break;
ff_dxva2_unlock(avctx);
av_usleep(2000);
} while(1);
if (FAILED(hr)) {
av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr);
ff_dxva2_unlock(avctx);
return -1;
}
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count];
type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
}
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
buffer = &buffer2[buffer_count];
type = DXVA2_PictureParametersBufferType;
}
#endif
result = ff_dxva2_commit_buffer(avctx, ctx, buffer,
type,
pp, pp_size, 0);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add picture parameter buffer\n");
goto end;
}
buffer_count++;
if (qm_size > 0) {
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count];
type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX;
}
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
buffer = &buffer2[buffer_count];
type = DXVA2_InverseQuantizationMatrixBufferType;
}
#endif
result = ff_dxva2_commit_buffer(avctx, ctx, buffer,
type,
qm, qm_size, 0);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add inverse quantization matrix buffer\n");
goto end;
}
buffer_count++;
}
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count + 0];
buffer_slice = &buffer11[buffer_count + 1];
}
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
buffer = &buffer2[buffer_count + 0];
buffer_slice = &buffer2[buffer_count + 1];
}
#endif
result = commit_bs_si(avctx,
buffer,
buffer_slice);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add bitstream or slice control buffer\n");
goto end;
}
buffer_count += 2;
/* TODO Film Grain when possible */
assert(buffer_count == 1 + (qm_size > 0) + 2);
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder,
buffer_count, buffer11);
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
DXVA2_DecodeExecuteParams exec = {
.NumCompBuffers = buffer_count,
.pCompressedBuffers = buffer2,
.pExtensionData = NULL,
};
hr = IDirectXVideoDecoder_Execute(DXVA2_CONTEXT(ctx)->decoder, &exec);
}
#endif
if (FAILED(hr)) {
av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%x\n", hr);
result = -1;
}
end:
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder);
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL);
#endif
ff_dxva2_unlock(avctx);
if (FAILED(hr)) {
av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%x\n", hr);
result = -1;
}
return result;
}
| false | FFmpeg | 70143a3954e1c4412efb2bf1a3a818adea2d3abf |
3,876 | static void put_no_rnd_pixels_x2_mmx( UINT8 *block, const UINT8 *pixels, int line_size, int h)
{
UINT8 *p;
const UINT8 *pix;
p = block;
pix = pixels;
MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
"movq 1%1, %%mm1\n\t"
"movq %%mm0, %%mm2\n\t"
"movq %%mm1, %%mm3\n\t"
"punpcklbw %%mm7, %%mm0\n\t"
"punpcklbw %%mm7, %%mm1\n\t"
"punpckhbw %%mm7, %%mm2\n\t"
"punpckhbw %%mm7, %%mm3\n\t"
"paddusw %%mm1, %%mm0\n\t"
"paddusw %%mm3, %%mm2\n\t"
"psrlw $1, %%mm0\n\t"
"psrlw $1, %%mm2\n\t"
"packuswb %%mm2, %%mm0\n\t"
"movq %%mm0, %0\n\t"
:"=m"(*p)
:"m"(*pix)
:"memory");
pix += line_size;
p += line_size;
} while (--h);
}
| false | FFmpeg | 91abb473fb8432226918da4fe03365ebaf688978 |
3,877 | static int attribute_align_arg av_buffersrc_add_frame_internal(AVFilterContext *ctx,
AVFrame *frame, int flags)
{
BufferSourceContext *s = ctx->priv;
AVFrame *copy;
int ret;
if (!frame) {
s->eof = 1;
return 0;
} else if (s->eof)
return AVERROR(EINVAL);
if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) {
switch (ctx->outputs[0]->type) {
case AVMEDIA_TYPE_VIDEO:
CHECK_VIDEO_PARAM_CHANGE(ctx, s, frame->width, frame->height,
frame->format);
break;
case AVMEDIA_TYPE_AUDIO:
/* For layouts unknown on input but known on link after negotiation. */
if (!frame->channel_layout)
frame->channel_layout = s->channel_layout;
CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout,
frame->format);
break;
default:
return AVERROR(EINVAL);
}
}
if (!av_fifo_space(s->fifo) &&
(ret = av_fifo_realloc2(s->fifo, av_fifo_size(s->fifo) +
sizeof(copy))) < 0)
return ret;
if (!(copy = av_frame_alloc()))
return AVERROR(ENOMEM);
av_frame_move_ref(copy, frame);
if ((ret = av_fifo_generic_write(s->fifo, ©, sizeof(copy), NULL)) < 0) {
av_frame_move_ref(frame, copy);
av_frame_free(©);
return ret;
}
if ((flags & AV_BUFFERSRC_FLAG_PUSH))
if ((ret = ctx->output_pads[0].request_frame(ctx->outputs[0])) < 0)
return ret;
return 0;
}
| false | FFmpeg | f29c28a884c01ea63559fd6bc2250a6b5f78cbb0 |
3,878 | static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offset)
{
AVPacket pkt1, *pkt = &pkt1;
AVStream *st;
int read_size, i, ret;
int64_t end_time;
int64_t filesize, offset, duration;
/* free previous packet */
if (ic->cur_st && ic->cur_st->parser)
av_free_packet(&ic->cur_pkt);
ic->cur_st = NULL;
/* flush packet queue */
flush_packet_queue(ic);
for(i=0;i<ic->nb_streams;i++) {
st = ic->streams[i];
if (st->parser) {
av_parser_close(st->parser);
st->parser= NULL;
}
}
/* we read the first packets to get the first PTS (not fully
accurate, but it is enough now) */
url_fseek(&ic->pb, 0, SEEK_SET);
read_size = 0;
for(;;) {
if (read_size >= DURATION_MAX_READ_SIZE)
break;
/* if all info is available, we can stop */
for(i = 0;i < ic->nb_streams; i++) {
st = ic->streams[i];
if (st->start_time == AV_NOPTS_VALUE)
break;
}
if (i == ic->nb_streams)
break;
ret = av_read_packet(ic, pkt);
if (ret != 0)
break;
read_size += pkt->size;
st = ic->streams[pkt->stream_index];
if (pkt->pts != AV_NOPTS_VALUE) {
if (st->start_time == AV_NOPTS_VALUE)
st->start_time = pkt->pts;
}
av_free_packet(pkt);
}
/* estimate the end time (duration) */
/* XXX: may need to support wrapping */
filesize = ic->file_size;
offset = filesize - DURATION_MAX_READ_SIZE;
if (offset < 0)
offset = 0;
url_fseek(&ic->pb, offset, SEEK_SET);
read_size = 0;
for(;;) {
if (read_size >= DURATION_MAX_READ_SIZE)
break;
ret = av_read_packet(ic, pkt);
if (ret != 0)
break;
read_size += pkt->size;
st = ic->streams[pkt->stream_index];
if (pkt->pts != AV_NOPTS_VALUE &&
st->start_time != AV_NOPTS_VALUE) {
end_time = pkt->pts;
duration = end_time - st->start_time;
if (duration > 0) {
if (st->duration == AV_NOPTS_VALUE ||
st->duration < duration)
st->duration = duration;
}
}
av_free_packet(pkt);
}
fill_all_stream_timings(ic);
url_fseek(&ic->pb, old_offset, SEEK_SET);
for(i=0; i<ic->nb_streams; i++){
st= ic->streams[i];
st->cur_dts= st->first_dts;
}
} | true | FFmpeg | cc5297e871f2a30b62b972c6479ab1d4fdc14132 |
3,879 | static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
int size, int64_t pos, uint64_t cluster_time,
uint64_t block_duration, int is_keyframe,
int64_t cluster_pos)
{
uint64_t timecode = AV_NOPTS_VALUE;
MatroskaTrack *track;
int res = 0;
AVStream *st;
int16_t block_time;
uint32_t *lace_size = NULL;
int n, flags, laces = 0;
uint64_t num, duration;
if ((n = matroska_ebmlnum_uint(matroska, data, size, &num)) < 0) {
av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n");
return n;
}
data += n;
size -= n;
track = matroska_find_track_by_num(matroska, num);
if (!track || !track->stream) {
av_log(matroska->ctx, AV_LOG_INFO,
"Invalid stream %"PRIu64" or size %u\n", num, size);
return AVERROR_INVALIDDATA;
} else if (size <= 3)
return 0;
st = track->stream;
if (st->discard >= AVDISCARD_ALL)
return res;
block_time = AV_RB16(data);
data += 2;
flags = *data++;
size -= 3;
if (is_keyframe == -1)
is_keyframe = flags & 0x80 ? AV_PKT_FLAG_KEY : 0;
if (cluster_time != (uint64_t)-1
&& (block_time >= 0 || cluster_time >= -block_time)) {
timecode = cluster_time + block_time;
if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE
&& timecode < track->end_timecode)
is_keyframe = 0; /* overlapping subtitles are not key frame */
if (is_keyframe)
av_add_index_entry(st, cluster_pos, timecode, 0,0,AVINDEX_KEYFRAME);
}
if (matroska->skip_to_keyframe && track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
if (!is_keyframe || timecode < matroska->skip_to_timecode)
return res;
matroska->skip_to_keyframe = 0;
}
res = matroska_parse_laces(matroska, &data, &size, (flags & 0x06) >> 1,
&lace_size, &laces);
if (res)
goto end;
if (block_duration != AV_NOPTS_VALUE) {
duration = block_duration / laces;
if (block_duration != duration * laces) {
av_log(matroska->ctx, AV_LOG_WARNING,
"Incorrect block_duration, possibly corrupted container");
}
} else {
duration = track->default_duration / matroska->time_scale;
block_duration = duration * laces;
}
if (timecode != AV_NOPTS_VALUE)
track->end_timecode =
FFMAX(track->end_timecode, timecode + block_duration);
for (n = 0; n < laces; n++) {
if ((st->codec->codec_id == AV_CODEC_ID_RA_288 ||
st->codec->codec_id == AV_CODEC_ID_COOK ||
st->codec->codec_id == AV_CODEC_ID_SIPR ||
st->codec->codec_id == AV_CODEC_ID_ATRAC3) &&
st->codec->block_align && track->audio.sub_packet_size) {
res = matroska_parse_rm_audio(matroska, track, st, data, size,
timecode, duration, pos);
if (res)
goto end;
} else {
res = matroska_parse_frame(matroska, track, st, data, lace_size[n],
timecode, duration,
pos, !n? is_keyframe : 0);
if (res)
goto end;
}
if (timecode != AV_NOPTS_VALUE)
timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
data += lace_size[n];
size -= lace_size[n];
}
end:
av_free(lace_size);
return res;
}
| true | FFmpeg | 25a80a931a3829f9d730971dbd269aa39cc273f6 |
3,880 | GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path,
GAChannelCallback cb, gpointer opaque)
{
GAChannel *c = g_malloc0(sizeof(GAChannel));
SECURITY_ATTRIBUTES sec_attrs;
if (!ga_channel_open(c, method, path)) {
g_critical("error opening channel");
g_free(c);
return NULL;
}
c->cb = cb;
c->user_data = opaque;
sec_attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
sec_attrs.lpSecurityDescriptor = NULL;
sec_attrs.bInheritHandle = false;
c->rstate.buf_size = QGA_READ_COUNT_DEFAULT;
c->rstate.buf = g_malloc(QGA_READ_COUNT_DEFAULT);
c->rstate.ov.hEvent = CreateEvent(&sec_attrs, FALSE, FALSE, NULL);
c->source = ga_channel_create_watch(c);
g_source_attach(c->source, NULL);
return c;
}
| true | qemu | f3a06403b82c7f036564e4caf18b52ce6885fcfb |
3,881 | static void coroutine_fn verify_entered_step_2(void *opaque)
{
Coroutine *caller = (Coroutine *)opaque;
g_assert(qemu_coroutine_entered(caller));
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
qemu_coroutine_yield();
/* Once more to check it still works after yielding */
g_assert(qemu_coroutine_entered(caller));
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
qemu_coroutine_yield();
}
| true | qemu | 6b2fef739127ee6135d5ccc2da0bf1f3bebf66b7 |
3,882 | static void mirror_complete(BlockJob *job, Error **errp)
{
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
int ret;
ret = bdrv_open_backing_file(s->target);
if (ret < 0) {
char backing_filename[PATH_MAX];
bdrv_get_full_backing_filename(s->target, backing_filename,
sizeof(backing_filename));
error_set(errp, QERR_OPEN_FILE_FAILED, backing_filename);
return;
}
if (!s->synced) {
error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
return;
}
s->should_complete = true;
block_job_resume(job);
}
| true | qemu | 31ca6d077c24b7aaa322d8930e3e5debbdb4a047 |
3,883 | decode_cabac_residual_internal(const H264Context *h, H264SliceContext *sl,
int16_t *block,
int cat, int n, const uint8_t *scantable,
const uint32_t *qmul, int max_coeff,
int is_dc, int chroma422)
{
static const int significant_coeff_flag_offset[2][14] = {
{ 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 },
{ 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 }
};
static const int last_coeff_flag_offset[2][14] = {
{ 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748 },
{ 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757 }
};
static const int coeff_abs_level_m1_offset[14] = {
227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766
};
static const uint8_t significant_coeff_flag_offset_8x8[2][63] = {
{ 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 },
{ 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
};
static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
/* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
* 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
* map node ctx => cabac ctx for level=1 */
static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
/* map node ctx => cabac ctx for level>1 */
static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
{ 5, 5, 5, 5, 6, 7, 8, 9 },
{ 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
};
static const uint8_t coeff_abs_level_transition[2][8] = {
/* update node ctx after decoding a level=1 */
{ 1, 2, 3, 3, 4, 5, 6, 7 },
/* update node ctx after decoding a level>1 */
{ 4, 4, 4, 4, 5, 6, 7, 7 }
};
int index[64];
int last;
int coeff_count = 0;
int node_ctx = 0;
uint8_t *significant_coeff_ctx_base;
uint8_t *last_coeff_ctx_base;
uint8_t *abs_level_m1_ctx_base;
#if !ARCH_X86
#define CABAC_ON_STACK
#endif
#ifdef CABAC_ON_STACK
#define CC &cc
CABACContext cc;
cc.range = sl->cabac.range;
cc.low = sl->cabac.low;
cc.bytestream= sl->cabac.bytestream;
#if !UNCHECKED_BITSTREAM_READER || ARCH_AARCH64
cc.bytestream_end = sl->cabac.bytestream_end;
#endif
#else
#define CC &sl->cabac
#endif
significant_coeff_ctx_base = sl->cabac_state
+ significant_coeff_flag_offset[MB_FIELD(sl)][cat];
last_coeff_ctx_base = sl->cabac_state
+ last_coeff_flag_offset[MB_FIELD(sl)][cat];
abs_level_m1_ctx_base = sl->cabac_state
+ coeff_abs_level_m1_offset[cat];
if( !is_dc && max_coeff == 64 ) {
#define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \
for(last= 0; last < coefs; last++) { \
uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \
if( get_cabac( CC, sig_ctx )) { \
uint8_t *last_ctx = last_coeff_ctx_base + last_off; \
index[coeff_count++] = last; \
if( get_cabac( CC, last_ctx ) ) { \
last= max_coeff; \
break; \
} \
} \
}\
if( last == max_coeff -1 ) {\
index[coeff_count++] = last;\
}
const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD(sl)];
#ifdef decode_significance
coeff_count = decode_significance_8x8(CC, significant_coeff_ctx_base, index,
last_coeff_ctx_base, sig_off);
} else {
if (is_dc && chroma422) { // dc 422
DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
} else {
coeff_count = decode_significance(CC, max_coeff, significant_coeff_ctx_base, index,
last_coeff_ctx_base-significant_coeff_ctx_base);
}
#else
DECODE_SIGNIFICANCE( 63, sig_off[last], ff_h264_last_coeff_flag_offset_8x8[last] );
} else {
if (is_dc && chroma422) { // dc 422
DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
} else {
DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
}
#endif
}
av_assert2(coeff_count > 0);
if( is_dc ) {
if( cat == 3 )
h->cbp_table[sl->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX);
else
h->cbp_table[sl->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX);
sl->non_zero_count_cache[scan8[n]] = coeff_count;
} else {
if( max_coeff == 64 )
fill_rectangle(&sl->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
else {
av_assert2( cat == 1 || cat == 2 || cat == 4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 );
sl->non_zero_count_cache[scan8[n]] = coeff_count;
}
}
#define STORE_BLOCK(type) \
do { \
uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \
\
int j= scantable[index[--coeff_count]]; \
\
if( get_cabac( CC, ctx ) == 0 ) { \
node_ctx = coeff_abs_level_transition[0][node_ctx]; \
if( is_dc ) { \
((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \
}else{ \
((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \
} \
} else { \
int coeff_abs = 2; \
ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \
node_ctx = coeff_abs_level_transition[1][node_ctx]; \
\
while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
coeff_abs++; \
} \
\
if( coeff_abs >= 15 ) { \
int j = 0; \
while (get_cabac_bypass(CC) && j < 30) { \
j++; \
} \
\
coeff_abs=1; \
while( j-- ) { \
coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
} \
coeff_abs+= 14U; \
} \
\
if( is_dc ) { \
((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \
}else{ \
((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \
} \
} \
} while ( coeff_count );
if (h->pixel_shift) {
STORE_BLOCK(int32_t)
} else {
STORE_BLOCK(int16_t)
}
#ifdef CABAC_ON_STACK
sl->cabac.range = cc.range ;
sl->cabac.low = cc.low ;
sl->cabac.bytestream= cc.bytestream;
#endif
}
| true | FFmpeg | a3a408259912e6d9337837c5d63c4b826778530f |
3,884 | static int opus_header(AVFormatContext *avf, int idx)
{
struct ogg *ogg = avf->priv_data;
struct ogg_stream *os = &ogg->streams[idx];
AVStream *st = avf->streams[idx];
struct oggopus_private *priv = os->private;
uint8_t *packet = os->buf + os->pstart;
if (!priv) {
priv = os->private = av_mallocz(sizeof(*priv));
if (!priv)
return AVERROR(ENOMEM);
}
if (os->flags & OGG_FLAG_BOS) {
if (os->psize < OPUS_HEAD_SIZE || (AV_RL8(packet + 8) & 0xF0) != 0)
return AVERROR_INVALIDDATA;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_OPUS;
st->codecpar->channels = AV_RL8(packet + 9);
priv->pre_skip = AV_RL16(packet + 10);
st->codecpar->initial_padding = priv->pre_skip;
/*orig_sample_rate = AV_RL32(packet + 12);*/
/*gain = AV_RL16(packet + 16);*/
/*channel_map = AV_RL8 (packet + 18);*/
if (ff_alloc_extradata(st->codecpar, os->psize))
return AVERROR(ENOMEM);
memcpy(st->codecpar->extradata, packet, os->psize);
st->codecpar->sample_rate = 48000;
st->codecpar->seek_preroll = av_rescale(OPUS_SEEK_PREROLL_MS,
st->codecpar->sample_rate, 1000);
avpriv_set_pts_info(st, 64, 1, 48000);
priv->need_comments = 1;
return 1;
}
if (priv->need_comments) {
if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
return AVERROR_INVALIDDATA;
ff_vorbis_stream_comment(avf, st, packet + 8, os->psize - 8);
priv->need_comments--;
return 1;
}
return 0;
} | true | FFmpeg | a3a0b5bd0aaae314619d5b41fb918aacd908a5ae |
3,885 | av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
SwsFilter *dstFilter)
{
int i;
int usesVFilter, usesHFilter;
int unscaled;
SwsFilter dummyFilter = { NULL, NULL, NULL, NULL };
int srcW = c->srcW;
int srcH = c->srcH;
int dstW = c->dstW;
int dstH = c->dstH;
int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 16, 16);
int dst_stride_px = dst_stride >> 1;
int flags, cpu_flags;
enum AVPixelFormat srcFormat = c->srcFormat;
enum AVPixelFormat dstFormat = c->dstFormat;
const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
cpu_flags = av_get_cpu_flags();
flags = c->flags;
emms_c();
if (!rgb15to16)
ff_rgb2rgb_init();
unscaled = (srcW == dstW && srcH == dstH);
if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) &&
av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) {
if (!sws_isSupportedInput(srcFormat)) {
av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
sws_format_name(srcFormat));
return AVERROR(EINVAL);
}
if (!sws_isSupportedOutput(dstFormat)) {
av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
sws_format_name(dstFormat));
return AVERROR(EINVAL);
}
}
i = flags & (SWS_POINT |
SWS_AREA |
SWS_BILINEAR |
SWS_FAST_BILINEAR |
SWS_BICUBIC |
SWS_X |
SWS_GAUSS |
SWS_LANCZOS |
SWS_SINC |
SWS_SPLINE |
SWS_BICUBLIN);
/* provide a default scaler if not set by caller */
if (!i) {
if (dstW < srcW && dstH < srcH)
flags |= SWS_GAUSS;
else if (dstW > srcW && dstH > srcH)
flags |= SWS_SINC;
else
flags |= SWS_LANCZOS;
c->flags = flags;
} else if (i & (i - 1)) {
av_log(c, AV_LOG_ERROR,
"Exactly one scaler algorithm must be chosen\n");
return AVERROR(EINVAL);
}
/* sanity check */
if (srcW < 4 || srcH < 1 || dstW < 8 || dstH < 1) {
/* FIXME check if these are enough and try to lower them after
* fixing the relevant parts of the code */
av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",
srcW, srcH, dstW, dstH);
return AVERROR(EINVAL);
}
if (!dstFilter)
dstFilter = &dummyFilter;
if (!srcFilter)
srcFilter = &dummyFilter;
c->lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
c->lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
c->vRounder = 4 * 0x0001000100010001ULL;
usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
(srcFilter->chrV && srcFilter->chrV->length > 1) ||
(dstFilter->lumV && dstFilter->lumV->length > 1) ||
(dstFilter->chrV && dstFilter->chrV->length > 1);
usesHFilter = (srcFilter->lumH && srcFilter->lumH->length > 1) ||
(srcFilter->chrH && srcFilter->chrH->length > 1) ||
(dstFilter->lumH && dstFilter->lumH->length > 1) ||
(dstFilter->chrH && dstFilter->chrH->length > 1);
getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat);
getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
if (isPlanarRGB(dstFormat)) {
if (!(flags & SWS_FULL_CHR_H_INT)) {
av_log(c, AV_LOG_DEBUG,
"%s output is not supported with half chroma resolution, switching to full\n",
av_get_pix_fmt_name(dstFormat));
flags |= SWS_FULL_CHR_H_INT;
c->flags = flags;
}
}
/* reuse chroma for 2 pixels RGB/BGR unless user wants full
* chroma interpolation */
if (flags & SWS_FULL_CHR_H_INT &&
isAnyRGB(dstFormat) &&
!isPlanarRGB(dstFormat) &&
dstFormat != AV_PIX_FMT_RGBA &&
dstFormat != AV_PIX_FMT_ARGB &&
dstFormat != AV_PIX_FMT_BGRA &&
dstFormat != AV_PIX_FMT_ABGR &&
dstFormat != AV_PIX_FMT_RGB24 &&
dstFormat != AV_PIX_FMT_BGR24) {
av_log(c, AV_LOG_ERROR,
"full chroma interpolation for destination format '%s' not yet implemented\n",
sws_format_name(dstFormat));
flags &= ~SWS_FULL_CHR_H_INT;
c->flags = flags;
}
if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT))
c->chrDstHSubSample = 1;
// drop some chroma lines if the user wants it
c->vChrDrop = (flags & SWS_SRC_V_CHR_DROP_MASK) >>
SWS_SRC_V_CHR_DROP_SHIFT;
c->chrSrcVSubSample += c->vChrDrop;
/* drop every other pixel for chroma calculation unless user
* wants full chroma */
if (isAnyRGB(srcFormat) && !(flags & SWS_FULL_CHR_H_INP) &&
srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
srcFormat != AV_PIX_FMT_GBRP9BE && srcFormat != AV_PIX_FMT_GBRP9LE &&
srcFormat != AV_PIX_FMT_GBRP10BE && srcFormat != AV_PIX_FMT_GBRP10LE &&
srcFormat != AV_PIX_FMT_GBRAP10BE && srcFormat != AV_PIX_FMT_GBRAP10LE &&
srcFormat != AV_PIX_FMT_GBRP12BE && srcFormat != AV_PIX_FMT_GBRP12LE &&
srcFormat != AV_PIX_FMT_GBRP16BE && srcFormat != AV_PIX_FMT_GBRP16LE &&
((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
(flags & SWS_FAST_BILINEAR)))
c->chrSrcHSubSample = 1;
// Note the AV_CEIL_RSHIFT is so that we always round toward +inf.
c->chrSrcW = AV_CEIL_RSHIFT(srcW, c->chrSrcHSubSample);
c->chrSrcH = AV_CEIL_RSHIFT(srcH, c->chrSrcVSubSample);
c->chrDstW = AV_CEIL_RSHIFT(dstW, c->chrDstHSubSample);
c->chrDstH = AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample);
/* unscaled special cases */
if (unscaled && !usesHFilter && !usesVFilter &&
(c->srcRange == c->dstRange || isAnyRGB(dstFormat))) {
ff_get_unscaled_swscale(c);
if (c->swscale) {
if (flags & SWS_PRINT_INFO)
av_log(c, AV_LOG_INFO,
"using unscaled %s -> %s special converter\n",
sws_format_name(srcFormat), sws_format_name(dstFormat));
return 0;
}
}
c->srcBpc = desc_src->comp[0].depth;
if (c->srcBpc < 8)
c->srcBpc = 8;
c->dstBpc = desc_dst->comp[0].depth;
if (c->dstBpc < 8)
c->dstBpc = 8;
if (c->dstBpc == 16)
dst_stride <<= 1;
FF_ALLOC_OR_GOTO(c, c->formatConvBuffer,
(FFALIGN(srcW, 16) * 2 * FFALIGN(c->srcBpc, 8) >> 3) + 16,
fail);
if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 12) {
c->canMMXEXTBeUsed = (dstW >= srcW && (dstW & 31) == 0 &&
(srcW & 15) == 0) ? 1 : 0;
if (!c->canMMXEXTBeUsed && dstW >= srcW && (srcW & 15) == 0
&& (flags & SWS_FAST_BILINEAR)) {
if (flags & SWS_PRINT_INFO)
av_log(c, AV_LOG_INFO,
"output width is not a multiple of 32 -> no MMXEXT scaler\n");
}
if (usesHFilter)
c->canMMXEXTBeUsed = 0;
} else
c->canMMXEXTBeUsed = 0;
c->chrXInc = (((int64_t)c->chrSrcW << 16) + (c->chrDstW >> 1)) / c->chrDstW;
c->chrYInc = (((int64_t)c->chrSrcH << 16) + (c->chrDstH >> 1)) / c->chrDstH;
/* Match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src
* to pixel n-2 of dst, but only for the FAST_BILINEAR mode otherwise do
* correct scaling.
* n-2 is the last chrominance sample available.
* This is not perfect, but no one should notice the difference, the more
* correct variant would be like the vertical one, but that would require
* some special code for the first and last pixel */
if (flags & SWS_FAST_BILINEAR) {
if (c->canMMXEXTBeUsed) {
c->lumXInc += 20;
c->chrXInc += 20;
}
// we don't use the x86 asm scaler if MMX is available
else if (INLINE_MMX(cpu_flags)) {
c->lumXInc = ((int64_t)(srcW - 2) << 16) / (dstW - 2) - 20;
c->chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
}
}
#define USE_MMAP (HAVE_MMAP && HAVE_MPROTECT && defined MAP_ANONYMOUS)
/* precalculate horizontal scaler filter coefficients */
{
#if HAVE_MMXEXT_INLINE
// can't downscale !!!
if (c->canMMXEXTBeUsed && (flags & SWS_FAST_BILINEAR)) {
c->lumMmxextFilterCodeSize = init_hscaler_mmxext(dstW, c->lumXInc, NULL,
NULL, NULL, 8);
c->chrMmxextFilterCodeSize = init_hscaler_mmxext(c->chrDstW, c->chrXInc,
NULL, NULL, NULL, 4);
#if USE_MMAP
c->lumMmxextFilterCode = mmap(NULL, c->lumMmxextFilterCodeSize,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
c->chrMmxextFilterCode = mmap(NULL, c->chrMmxextFilterCodeSize,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
#elif HAVE_VIRTUALALLOC
c->lumMmxextFilterCode = VirtualAlloc(NULL,
c->lumMmxextFilterCodeSize,
MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
c->chrMmxextFilterCode = VirtualAlloc(NULL,
c->chrMmxextFilterCodeSize,
MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
#else
c->lumMmxextFilterCode = av_malloc(c->lumMmxextFilterCodeSize);
c->chrMmxextFilterCode = av_malloc(c->chrMmxextFilterCodeSize);
#endif
if (!c->lumMmxextFilterCode || !c->chrMmxextFilterCode)
return AVERROR(ENOMEM);
FF_ALLOCZ_OR_GOTO(c, c->hLumFilter, (dstW / 8 + 8) * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(c, c->hChrFilter, (c->chrDstW / 4 + 8) * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW / 2 / 8 + 8) * sizeof(int32_t), fail);
FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW / 2 / 4 + 8) * sizeof(int32_t), fail);
init_hscaler_mmxext(dstW, c->lumXInc, c->lumMmxextFilterCode,
c->hLumFilter, c->hLumFilterPos, 8);
init_hscaler_mmxext(c->chrDstW, c->chrXInc, c->chrMmxextFilterCode,
c->hChrFilter, c->hChrFilterPos, 4);
#if USE_MMAP
mprotect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize, PROT_EXEC | PROT_READ);
mprotect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize, PROT_EXEC | PROT_READ);
#endif
} else
#endif /* HAVE_MMXEXT_INLINE */
{
const int filterAlign = X86_MMX(cpu_flags) ? 4 :
PPC_ALTIVEC(cpu_flags) ? 8 : 1;
if (initFilter(&c->hLumFilter, &c->hLumFilterPos,
&c->hLumFilterSize, c->lumXInc,
srcW, dstW, filterAlign, 1 << 14,
(flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags,
cpu_flags, srcFilter->lumH, dstFilter->lumH,
c->param, 1) < 0)
goto fail;
if (initFilter(&c->hChrFilter, &c->hChrFilterPos,
&c->hChrFilterSize, c->chrXInc,
c->chrSrcW, c->chrDstW, filterAlign, 1 << 14,
(flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags,
cpu_flags, srcFilter->chrH, dstFilter->chrH,
c->param, 1) < 0)
goto fail;
}
} // initialize horizontal stuff
/* precalculate vertical scaler filter coefficients */
{
const int filterAlign = X86_MMX(cpu_flags) ? 2 :
PPC_ALTIVEC(cpu_flags) ? 8 : 1;
if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize,
c->lumYInc, srcH, dstH, filterAlign, (1 << 12),
(flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags,
cpu_flags, srcFilter->lumV, dstFilter->lumV,
c->param, 0) < 0)
goto fail;
if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize,
c->chrYInc, c->chrSrcH, c->chrDstH,
filterAlign, (1 << 12),
(flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags,
cpu_flags, srcFilter->chrV, dstFilter->chrV,
c->param, 0) < 0)
goto fail;
#if HAVE_ALTIVEC
FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof(vector signed short) * c->vLumFilterSize * c->dstH, fail);
FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof(vector signed short) * c->vChrFilterSize * c->chrDstH, fail);
for (i = 0; i < c->vLumFilterSize * c->dstH; i++) {
int j;
short *p = (short *)&c->vYCoeffsBank[i];
for (j = 0; j < 8; j++)
p[j] = c->vLumFilter[i];
}
for (i = 0; i < c->vChrFilterSize * c->chrDstH; i++) {
int j;
short *p = (short *)&c->vCCoeffsBank[i];
for (j = 0; j < 8; j++)
p[j] = c->vChrFilter[i];
}
#endif
}
// calculate buffer sizes so that they won't run out while handling these damn slices
c->vLumBufSize = c->vLumFilterSize;
c->vChrBufSize = c->vChrFilterSize;
for (i = 0; i < dstH; i++) {
int chrI = (int64_t)i * c->chrDstH / dstH;
int nextSlice = FFMAX(c->vLumFilterPos[i] + c->vLumFilterSize - 1,
((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)
<< c->chrSrcVSubSample));
nextSlice >>= c->chrSrcVSubSample;
nextSlice <<= c->chrSrcVSubSample;
if (c->vLumFilterPos[i] + c->vLumBufSize < nextSlice)
c->vLumBufSize = nextSlice - c->vLumFilterPos[i];
if (c->vChrFilterPos[chrI] + c->vChrBufSize <
(nextSlice >> c->chrSrcVSubSample))
c->vChrBufSize = (nextSlice >> c->chrSrcVSubSample) -
c->vChrFilterPos[chrI];
}
/* Allocate pixbufs (we use dynamic allocation because otherwise we would
* need to allocate several megabytes to handle all possible cases) */
FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize * 3 * sizeof(int16_t *), fail);
FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize * 3 * sizeof(int16_t *), fail);
FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize * 3 * sizeof(int16_t *), fail);
if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat))
FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize * 3 * sizeof(int16_t *), fail);
/* Note we need at least one pixel more at the end because of the MMX code
* (just in case someone wants to replace the 4000/8000). */
/* align at 16 bytes for AltiVec */
for (i = 0; i < c->vLumBufSize; i++) {
FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i + c->vLumBufSize],
dst_stride + 16, fail);
c->lumPixBuf[i] = c->lumPixBuf[i + c->vLumBufSize];
}
// 64 / (c->dstBpc & ~7) is the same as 16 / sizeof(scaling_intermediate)
c->uv_off_px = dst_stride_px + 64 / (c->dstBpc & ~7);
c->uv_off_byte = dst_stride + 16;
for (i = 0; i < c->vChrBufSize; i++) {
FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i + c->vChrBufSize],
dst_stride * 2 + 32, fail);
c->chrUPixBuf[i] = c->chrUPixBuf[i + c->vChrBufSize];
c->chrVPixBuf[i] = c->chrVPixBuf[i + c->vChrBufSize]
= c->chrUPixBuf[i] + (dst_stride >> 1) + 8;
}
if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
for (i = 0; i < c->vLumBufSize; i++) {
FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i + c->vLumBufSize],
dst_stride + 16, fail);
c->alpPixBuf[i] = c->alpPixBuf[i + c->vLumBufSize];
}
// try to avoid drawing green stuff between the right end and the stride end
for (i = 0; i < c->vChrBufSize; i++)
memset(c->chrUPixBuf[i], 64, dst_stride * 2 + 1);
assert(c->chrDstH <= dstH);
if (flags & SWS_PRINT_INFO) {
if (flags & SWS_FAST_BILINEAR)
av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, ");
else if (flags & SWS_BILINEAR)
av_log(c, AV_LOG_INFO, "BILINEAR scaler, ");
else if (flags & SWS_BICUBIC)
av_log(c, AV_LOG_INFO, "BICUBIC scaler, ");
else if (flags & SWS_X)
av_log(c, AV_LOG_INFO, "Experimental scaler, ");
else if (flags & SWS_POINT)
av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");
else if (flags & SWS_AREA)
av_log(c, AV_LOG_INFO, "Area Averaging scaler, ");
else if (flags & SWS_BICUBLIN)
av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");
else if (flags & SWS_GAUSS)
av_log(c, AV_LOG_INFO, "Gaussian scaler, ");
else if (flags & SWS_SINC)
av_log(c, AV_LOG_INFO, "Sinc scaler, ");
else if (flags & SWS_LANCZOS)
av_log(c, AV_LOG_INFO, "Lanczos scaler, ");
else if (flags & SWS_SPLINE)
av_log(c, AV_LOG_INFO, "Bicubic spline scaler, ");
else
av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");
av_log(c, AV_LOG_INFO, "from %s to %s%s ",
sws_format_name(srcFormat),
#ifdef DITHER1XBPP
dstFormat == AV_PIX_FMT_BGR555 || dstFormat == AV_PIX_FMT_BGR565 ||
dstFormat == AV_PIX_FMT_RGB444BE || dstFormat == AV_PIX_FMT_RGB444LE ||
dstFormat == AV_PIX_FMT_BGR444BE || dstFormat == AV_PIX_FMT_BGR444LE ?
"dithered " : "",
#else
"",
#endif
sws_format_name(dstFormat));
if (INLINE_MMXEXT(cpu_flags))
av_log(c, AV_LOG_INFO, "using MMXEXT\n");
else if (INLINE_AMD3DNOW(cpu_flags))
av_log(c, AV_LOG_INFO, "using 3DNOW\n");
else if (INLINE_MMX(cpu_flags))
av_log(c, AV_LOG_INFO, "using MMX\n");
else if (PPC_ALTIVEC(cpu_flags))
av_log(c, AV_LOG_INFO, "using AltiVec\n");
else
av_log(c, AV_LOG_INFO, "using C\n");
av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
av_log(c, AV_LOG_DEBUG,
"lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
av_log(c, AV_LOG_DEBUG,
"chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH,
c->chrXInc, c->chrYInc);
}
c->swscale = ff_getSwsFunc(c);
return 0;
fail: // FIXME replace things by appropriate error codes
return -1;
}
| true | FFmpeg | 5e3f6dc70198426fe0741e3017826b8bf3ee5ad8 |
3,886 | static int spapr_vio_busdev_init(DeviceState *qdev)
{
VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
char *id;
if (dev->reg != -1) {
/*
* Explicitly assigned address, just verify that no-one else
* is using it. other mechanism). We have to open code this
* rather than using spapr_vio_find_by_reg() because sdev
* itself is already in the list.
*/
VIOsPAPRDevice *other = reg_conflict(dev);
if (other) {
fprintf(stderr, "vio: %s and %s devices conflict at address %#x\n",
object_get_typename(OBJECT(qdev)),
object_get_typename(OBJECT(&other->qdev)),
dev->reg);
return -1;
}
} else {
/* Need to assign an address */
VIOsPAPRBus *bus = DO_UPCAST(VIOsPAPRBus, bus, dev->qdev.parent_bus);
do {
dev->reg = bus->next_reg++;
} while (reg_conflict(dev));
}
/* Don't overwrite ids assigned on the command line */
if (!dev->qdev.id) {
id = vio_format_dev_name(dev);
if (!id) {
return -1;
}
dev->qdev.id = id;
}
dev->qirq = spapr_allocate_msi(dev->vio_irq_num, &dev->vio_irq_num);
if (!dev->qirq) {
return -1;
}
rtce_init(dev);
return pc->init(dev);
}
| true | qemu | ad0ebb91cd8b5fdc4a583b03645677771f420a46 |
3,887 | static void generate_joint_tables(HYuvContext *s)
{
uint16_t symbols[1 << VLC_BITS];
uint16_t bits[1 << VLC_BITS];
uint8_t len[1 << VLC_BITS];
if (s->bitstream_bpp < 24) {
int p, i, y, u;
for (p = 0; p < 3; p++) {
for (i = y = 0; y < 256; y++) {
int len0 = s->len[0][y];
int limit = VLC_BITS - len0;
if (limit <= 0)
continue;
for (u = 0; u < 256; u++) {
int len1 = s->len[p][u];
if (len1 > limit)
continue;
len[i] = len0 + len1;
bits[i] = (s->bits[0][y] << len1) + s->bits[p][u];
symbols[i] = (y << 8) + u;
if (symbols[i] != 0xffff) // reserved to mean "invalid"
i++;
}
}
ff_free_vlc(&s->vlc[3 + p]);
ff_init_vlc_sparse(&s->vlc[3 + p], VLC_BITS, i, len, 1, 1,
bits, 2, 2, symbols, 2, 2, 0);
}
} else {
uint8_t (*map)[4] = (uint8_t(*)[4]) s->pix_bgr_map;
int i, b, g, r, code;
int p0 = s->decorrelate;
int p1 = !s->decorrelate;
/* Restrict the range to +/-16 because that's pretty much guaranteed
* to cover all the combinations that fit in 11 bits total, and it
* does not matter if we miss a few rare codes. */
for (i = 0, g = -16; g < 16; g++) {
int len0 = s->len[p0][g & 255];
int limit0 = VLC_BITS - len0;
if (limit0 < 2)
continue;
for (b = -16; b < 16; b++) {
int len1 = s->len[p1][b & 255];
int limit1 = limit0 - len1;
if (limit1 < 1)
continue;
code = (s->bits[p0][g & 255] << len1) + s->bits[p1][b & 255];
for (r = -16; r < 16; r++) {
int len2 = s->len[2][r & 255];
if (len2 > limit1)
continue;
len[i] = len0 + len1 + len2;
bits[i] = (code << len2) + s->bits[2][r & 255];
if (s->decorrelate) {
map[i][G] = g;
map[i][B] = g + b;
map[i][R] = g + r;
} else {
map[i][B] = g;
map[i][G] = b;
map[i][R] = r;
}
i++;
}
}
}
ff_free_vlc(&s->vlc[3]);
init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0);
}
}
| true | FFmpeg | d0393d79bc3d61c9f2ff832c0e273b7774ff0269 |
3,888 | static DeviceState *slavio_intctl_init(target_phys_addr_t addr,
target_phys_addr_t addrg,
qemu_irq **parent_irq)
{
DeviceState *dev;
SysBusDevice *s;
unsigned int i, j;
dev = qdev_create(NULL, "slavio_intctl");
qdev_init(dev);
s = sysbus_from_qdev(dev);
for (i = 0; i < MAX_CPUS; i++) {
for (j = 0; j < MAX_PILS; j++) {
sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
}
}
sysbus_mmio_map(s, 0, addrg);
for (i = 0; i < MAX_CPUS; i++) {
sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
}
return dev;
}
| true | qemu | e23a1b33b53d25510320b26d9f154e19c6c99725 |
3,889 | static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id)
{
stellaris_enet_state *s = (stellaris_enet_state *)opaque;
int i;
if (version_id != 1)
return -EINVAL;
s->ris = qemu_get_be32(f);
s->im = qemu_get_be32(f);
s->rctl = qemu_get_be32(f);
s->tctl = qemu_get_be32(f);
s->thr = qemu_get_be32(f);
s->mctl = qemu_get_be32(f);
s->mdv = qemu_get_be32(f);
s->mtxd = qemu_get_be32(f);
s->mrxd = qemu_get_be32(f);
s->np = qemu_get_be32(f);
s->tx_fifo_len = qemu_get_be32(f);
qemu_get_buffer(f, s->tx_fifo, sizeof(s->tx_fifo));
for (i = 0; i < 31; i++) {
s->rx[i].len = qemu_get_be32(f);
qemu_get_buffer(f, s->rx[i].data, sizeof(s->rx[i].data));
}
s->next_packet = qemu_get_be32(f);
s->rx_fifo_offset = qemu_get_be32(f);
return 0;
}
| true | qemu | 2e1198672759eda6e122ff38fcf6df06f27e0fe2 |
3,890 | AudioState *AUD_init (void)
{
size_t i;
int done = 0;
const char *drvname;
AudioState *s = &glob_audio_state;
LIST_INIT (&s->hw_head_out);
LIST_INIT (&s->hw_head_in);
LIST_INIT (&s->cap_head);
atexit (audio_atexit);
s->ts = qemu_new_timer (vm_clock, audio_timer, s);
if (!s->ts) {
dolog ("Could not create audio timer\n");
return NULL;
}
audio_process_options ("AUDIO", audio_options);
s->nb_hw_voices_out = conf.fixed_out.nb_voices;
s->nb_hw_voices_in = conf.fixed_in.nb_voices;
if (s->nb_hw_voices_out <= 0) {
dolog ("Bogus number of playback voices %d, setting to 1\n",
s->nb_hw_voices_out);
s->nb_hw_voices_out = 1;
}
if (s->nb_hw_voices_in <= 0) {
dolog ("Bogus number of capture voices %d, setting to 0\n",
s->nb_hw_voices_in);
s->nb_hw_voices_in = 0;
}
{
int def;
drvname = audio_get_conf_str ("QEMU_AUDIO_DRV", NULL, &def);
}
if (drvname) {
int found = 0;
for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
if (!strcmp (drvname, drvtab[i]->name)) {
done = !audio_driver_init (s, drvtab[i]);
found = 1;
break;
}
}
if (!found) {
dolog ("Unknown audio driver `%s'\n", drvname);
dolog ("Run with -audio-help to list available drivers\n");
}
}
if (!done) {
for (i = 0; !done && i < ARRAY_SIZE (drvtab); i++) {
if (drvtab[i]->can_be_default) {
done = !audio_driver_init (s, drvtab[i]);
}
}
}
if (!done) {
done = !audio_driver_init (s, &no_audio_driver);
if (!done) {
dolog ("Could not initialize audio subsystem\n");
}
else {
dolog ("warning: Using timer based audio emulation\n");
}
}
if (done) {
VMChangeStateEntry *e;
if (conf.period.hertz <= 0) {
if (conf.period.hertz < 0) {
dolog ("warning: Timer period is negative - %d "
"treating as zero\n",
conf.period.hertz);
}
conf.period.ticks = 1;
}
else {
conf.period.ticks = ticks_per_sec / conf.period.hertz;
}
e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
if (!e) {
dolog ("warning: Could not register change state handler\n"
"(Audio can continue looping even after stopping the VM)\n");
}
}
else {
qemu_del_timer (s->ts);
return NULL;
}
LIST_INIT (&s->card_head);
register_savevm ("audio", 0, 1, audio_save, audio_load, s);
qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
return s;
}
| true | qemu | 0d9acba8fddbf970c7353083e6a60b47017ce3e4 |
3,891 | static void s390_cpu_model_initfn(Object *obj)
{ | true | qemu | ad5afd07b628cd0610ea322ad60b5ad03aa250c8 |
3,892 | static void spapr_finalize_fdt(sPAPREnvironment *spapr,
target_phys_addr_t fdt_addr,
target_phys_addr_t rtas_addr,
target_phys_addr_t rtas_size)
{
int ret;
void *fdt;
sPAPRPHBState *phb;
fdt = g_malloc(FDT_MAX_SIZE);
/* open out the base tree into a temp buffer for the final tweaks */
_FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));
ret = spapr_populate_vdevice(spapr->vio_bus, fdt);
if (ret < 0) {
fprintf(stderr, "couldn't setup vio devices in fdt\n");
exit(1);
}
QLIST_FOREACH(phb, &spapr->phbs, list) {
ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);
}
if (ret < 0) {
fprintf(stderr, "couldn't setup PCI devices in fdt\n");
exit(1);
}
/* RTAS */
ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size);
if (ret < 0) {
fprintf(stderr, "Couldn't set up RTAS device tree properties\n");
}
/* Advertise NUMA via ibm,associativity */
if (nb_numa_nodes > 1) {
ret = spapr_set_associativity(fdt, spapr);
if (ret < 0) {
fprintf(stderr, "Couldn't set up NUMA device tree properties\n");
}
}
if (!spapr->has_graphics) {
spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
}
_FDT((fdt_pack(fdt)));
if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {
hw_error("FDT too big ! 0x%x bytes (max is 0x%x)\n",
fdt_totalsize(fdt), FDT_MAX_SIZE);
exit(1);
}
cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));
g_free(fdt);
}
| true | qemu | 7f763a5d994bbddb50705d2e50decdf52937521f |
3,893 | void ff_check_pixfmt_descriptors(void){
int i, j;
for (i=0; i<FF_ARRAY_ELEMS(av_pix_fmt_descriptors); i++) {
const AVPixFmtDescriptor *d = &av_pix_fmt_descriptors[i];
uint8_t fill[4][8+6+3] = {{0}};
uint8_t *data[4] = {fill[0], fill[1], fill[2], fill[3]};
int linesize[4] = {0,0,0,0};
uint16_t tmp[2];
if (!d->name && !d->nb_components && !d->log2_chroma_w && !d->log2_chroma_h && !d->flags)
continue;
// av_log(NULL, AV_LOG_DEBUG, "Checking: %s\n", d->name);
av_assert0(d->log2_chroma_w <= 3);
av_assert0(d->log2_chroma_h <= 3);
av_assert0(d->nb_components <= 4);
av_assert0(d->name && d->name[0]);
av_assert0((d->nb_components==4 || d->nb_components==2) == !!(d->flags & AV_PIX_FMT_FLAG_ALPHA));
av_assert2(av_get_pix_fmt(d->name) == i);
for (j=0; j<FF_ARRAY_ELEMS(d->comp); j++) {
const AVComponentDescriptor *c = &d->comp[j];
if(j>=d->nb_components) {
av_assert0(!c->plane && !c->step_minus1 && !c->offset_plus1 && !c->shift && !c->depth_minus1);
continue;
}
if (d->flags & AV_PIX_FMT_FLAG_BITSTREAM) {
av_assert0(c->step_minus1 >= c->depth_minus1);
} else {
av_assert0(8*(c->step_minus1+1) >= c->depth_minus1+1);
}
av_read_image_line(tmp, (void*)data, linesize, d, 0, 0, j, 2, 0);
if (!strncmp(d->name, "bayer_", 6))
continue;
av_assert0(tmp[0] == 0 && tmp[1] == 0);
tmp[0] = tmp[1] = (1<<(c->depth_minus1 + 1)) - 1;
av_write_image_line(tmp, data, linesize, d, 0, 0, j, 2);
}
}
}
| true | FFmpeg | f3ba91a3f1d9e99aebfe22278b0633f996e3fbe1 |
3,894 | static void disas_thumb_insn(CPUState *env, DisasContext *s)
{
uint32_t val, insn, op, rm, rn, rd, shift, cond;
int32_t offset;
int i;
TCGv tmp;
TCGv tmp2;
TCGv addr;
if (s->condexec_mask) {
cond = s->condexec_cond;
if (cond != 0x0e) { /* Skip conditional when condition is AL. */
s->condlabel = gen_new_label();
gen_test_cc(cond ^ 1, s->condlabel);
s->condjmp = 1;
}
}
insn = lduw_code(s->pc);
s->pc += 2;
switch (insn >> 12) {
case 0: case 1:
rd = insn & 7;
op = (insn >> 11) & 3;
if (op == 3) {
/* add/subtract */
rn = (insn >> 3) & 7;
tmp = load_reg(s, rn);
if (insn & (1 << 10)) {
/* immediate */
tmp2 = new_tmp();
tcg_gen_movi_i32(tmp2, (insn >> 6) & 7);
} else {
/* reg */
rm = (insn >> 6) & 7;
tmp2 = load_reg(s, rm);
}
if (insn & (1 << 9)) {
if (s->condexec_mask)
tcg_gen_sub_i32(tmp, tmp, tmp2);
else
gen_helper_sub_cc(tmp, tmp, tmp2);
} else {
if (s->condexec_mask)
tcg_gen_add_i32(tmp, tmp, tmp2);
else
gen_helper_add_cc(tmp, tmp, tmp2);
}
dead_tmp(tmp2);
store_reg(s, rd, tmp);
} else {
/* shift immediate */
rm = (insn >> 3) & 7;
shift = (insn >> 6) & 0x1f;
tmp = load_reg(s, rm);
gen_arm_shift_im(tmp, op, shift, s->condexec_mask == 0);
if (!s->condexec_mask)
gen_logic_CC(tmp);
store_reg(s, rd, tmp);
}
break;
case 2: case 3:
/* arithmetic large immediate */
op = (insn >> 11) & 3;
rd = (insn >> 8) & 0x7;
if (op == 0) { /* mov */
tmp = new_tmp();
tcg_gen_movi_i32(tmp, insn & 0xff);
if (!s->condexec_mask)
gen_logic_CC(tmp);
store_reg(s, rd, tmp);
} else {
tmp = load_reg(s, rd);
tmp2 = new_tmp();
tcg_gen_movi_i32(tmp2, insn & 0xff);
switch (op) {
case 1: /* cmp */
gen_helper_sub_cc(tmp, tmp, tmp2);
dead_tmp(tmp);
dead_tmp(tmp2);
break;
case 2: /* add */
if (s->condexec_mask)
tcg_gen_add_i32(tmp, tmp, tmp2);
else
gen_helper_add_cc(tmp, tmp, tmp2);
dead_tmp(tmp2);
store_reg(s, rd, tmp);
break;
case 3: /* sub */
if (s->condexec_mask)
tcg_gen_sub_i32(tmp, tmp, tmp2);
else
gen_helper_sub_cc(tmp, tmp, tmp2);
dead_tmp(tmp2);
store_reg(s, rd, tmp);
break;
}
}
break;
case 4:
if (insn & (1 << 11)) {
rd = (insn >> 8) & 7;
/* load pc-relative. Bit 1 of PC is ignored. */
val = s->pc + 2 + ((insn & 0xff) * 4);
val &= ~(uint32_t)2;
addr = new_tmp();
tcg_gen_movi_i32(addr, val);
tmp = gen_ld32(addr, IS_USER(s));
dead_tmp(addr);
store_reg(s, rd, tmp);
break;
}
if (insn & (1 << 10)) {
/* data processing extended or blx */
rd = (insn & 7) | ((insn >> 4) & 8);
rm = (insn >> 3) & 0xf;
op = (insn >> 8) & 3;
switch (op) {
case 0: /* add */
tmp = load_reg(s, rd);
tmp2 = load_reg(s, rm);
tcg_gen_add_i32(tmp, tmp, tmp2);
dead_tmp(tmp2);
store_reg(s, rd, tmp);
break;
case 1: /* cmp */
tmp = load_reg(s, rd);
tmp2 = load_reg(s, rm);
gen_helper_sub_cc(tmp, tmp, tmp2);
dead_tmp(tmp2);
dead_tmp(tmp);
break;
case 2: /* mov/cpy */
tmp = load_reg(s, rm);
store_reg(s, rd, tmp);
break;
case 3:/* branch [and link] exchange thumb register */
tmp = load_reg(s, rm);
if (insn & (1 << 7)) {
val = (uint32_t)s->pc | 1;
tmp2 = new_tmp();
tcg_gen_movi_i32(tmp2, val);
store_reg(s, 14, tmp2);
}
gen_bx(s, tmp);
break;
}
break;
}
/* data processing register */
rd = insn & 7;
rm = (insn >> 3) & 7;
op = (insn >> 6) & 0xf;
if (op == 2 || op == 3 || op == 4 || op == 7) {
/* the shift/rotate ops want the operands backwards */
val = rm;
rm = rd;
rd = val;
val = 1;
} else {
val = 0;
}
if (op == 9) { /* neg */
tmp = new_tmp();
tcg_gen_movi_i32(tmp, 0);
} else if (op != 0xf) { /* mvn doesn't read its first operand */
tmp = load_reg(s, rd);
} else {
TCGV_UNUSED(tmp);
}
tmp2 = load_reg(s, rm);
switch (op) {
case 0x0: /* and */
tcg_gen_and_i32(tmp, tmp, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp);
break;
case 0x1: /* eor */
tcg_gen_xor_i32(tmp, tmp, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp);
break;
case 0x2: /* lsl */
if (s->condexec_mask) {
gen_helper_shl(tmp2, tmp2, tmp);
} else {
gen_helper_shl_cc(tmp2, tmp2, tmp);
gen_logic_CC(tmp2);
}
break;
case 0x3: /* lsr */
if (s->condexec_mask) {
gen_helper_shr(tmp2, tmp2, tmp);
} else {
gen_helper_shr_cc(tmp2, tmp2, tmp);
gen_logic_CC(tmp2);
}
break;
case 0x4: /* asr */
if (s->condexec_mask) {
gen_helper_sar(tmp2, tmp2, tmp);
} else {
gen_helper_sar_cc(tmp2, tmp2, tmp);
gen_logic_CC(tmp2);
}
break;
case 0x5: /* adc */
if (s->condexec_mask)
gen_adc(tmp, tmp2);
else
gen_helper_adc_cc(tmp, tmp, tmp2);
break;
case 0x6: /* sbc */
if (s->condexec_mask)
gen_sub_carry(tmp, tmp, tmp2);
else
gen_helper_sbc_cc(tmp, tmp, tmp2);
break;
case 0x7: /* ror */
if (s->condexec_mask) {
tcg_gen_andi_i32(tmp, tmp, 0x1f);
tcg_gen_rotr_i32(tmp2, tmp2, tmp);
} else {
gen_helper_ror_cc(tmp2, tmp2, tmp);
gen_logic_CC(tmp2);
}
break;
case 0x8: /* tst */
tcg_gen_and_i32(tmp, tmp, tmp2);
gen_logic_CC(tmp);
rd = 16;
break;
case 0x9: /* neg */
if (s->condexec_mask)
tcg_gen_neg_i32(tmp, tmp2);
else
gen_helper_sub_cc(tmp, tmp, tmp2);
break;
case 0xa: /* cmp */
gen_helper_sub_cc(tmp, tmp, tmp2);
rd = 16;
break;
case 0xb: /* cmn */
gen_helper_add_cc(tmp, tmp, tmp2);
rd = 16;
break;
case 0xc: /* orr */
tcg_gen_or_i32(tmp, tmp, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp);
break;
case 0xd: /* mul */
tcg_gen_mul_i32(tmp, tmp, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp);
break;
case 0xe: /* bic */
tcg_gen_andc_i32(tmp, tmp, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp);
break;
case 0xf: /* mvn */
tcg_gen_not_i32(tmp2, tmp2);
if (!s->condexec_mask)
gen_logic_CC(tmp2);
val = 1;
rm = rd;
break;
}
if (rd != 16) {
if (val) {
store_reg(s, rm, tmp2);
if (op != 0xf)
dead_tmp(tmp);
} else {
store_reg(s, rd, tmp);
dead_tmp(tmp2);
}
} else {
dead_tmp(tmp);
dead_tmp(tmp2);
}
break;
case 5:
/* load/store register offset. */
rd = insn & 7;
rn = (insn >> 3) & 7;
rm = (insn >> 6) & 7;
op = (insn >> 9) & 7;
addr = load_reg(s, rn);
tmp = load_reg(s, rm);
tcg_gen_add_i32(addr, addr, tmp);
dead_tmp(tmp);
if (op < 3) /* store */
tmp = load_reg(s, rd);
switch (op) {
case 0: /* str */
gen_st32(tmp, addr, IS_USER(s));
break;
case 1: /* strh */
gen_st16(tmp, addr, IS_USER(s));
break;
case 2: /* strb */
gen_st8(tmp, addr, IS_USER(s));
break;
case 3: /* ldrsb */
tmp = gen_ld8s(addr, IS_USER(s));
break;
case 4: /* ldr */
tmp = gen_ld32(addr, IS_USER(s));
break;
case 5: /* ldrh */
tmp = gen_ld16u(addr, IS_USER(s));
break;
case 6: /* ldrb */
tmp = gen_ld8u(addr, IS_USER(s));
break;
case 7: /* ldrsh */
tmp = gen_ld16s(addr, IS_USER(s));
break;
}
if (op >= 3) /* load */
store_reg(s, rd, tmp);
dead_tmp(addr);
break;
case 6:
/* load/store word immediate offset */
rd = insn & 7;
rn = (insn >> 3) & 7;
addr = load_reg(s, rn);
val = (insn >> 4) & 0x7c;
tcg_gen_addi_i32(addr, addr, val);
if (insn & (1 << 11)) {
/* load */
tmp = gen_ld32(addr, IS_USER(s));
store_reg(s, rd, tmp);
} else {
/* store */
tmp = load_reg(s, rd);
gen_st32(tmp, addr, IS_USER(s));
}
dead_tmp(addr);
break;
case 7:
/* load/store byte immediate offset */
rd = insn & 7;
rn = (insn >> 3) & 7;
addr = load_reg(s, rn);
val = (insn >> 6) & 0x1f;
tcg_gen_addi_i32(addr, addr, val);
if (insn & (1 << 11)) {
/* load */
tmp = gen_ld8u(addr, IS_USER(s));
store_reg(s, rd, tmp);
} else {
/* store */
tmp = load_reg(s, rd);
gen_st8(tmp, addr, IS_USER(s));
}
dead_tmp(addr);
break;
case 8:
/* load/store halfword immediate offset */
rd = insn & 7;
rn = (insn >> 3) & 7;
addr = load_reg(s, rn);
val = (insn >> 5) & 0x3e;
tcg_gen_addi_i32(addr, addr, val);
if (insn & (1 << 11)) {
/* load */
tmp = gen_ld16u(addr, IS_USER(s));
store_reg(s, rd, tmp);
} else {
/* store */
tmp = load_reg(s, rd);
gen_st16(tmp, addr, IS_USER(s));
}
dead_tmp(addr);
break;
case 9:
/* load/store from stack */
rd = (insn >> 8) & 7;
addr = load_reg(s, 13);
val = (insn & 0xff) * 4;
tcg_gen_addi_i32(addr, addr, val);
if (insn & (1 << 11)) {
/* load */
tmp = gen_ld32(addr, IS_USER(s));
store_reg(s, rd, tmp);
} else {
/* store */
tmp = load_reg(s, rd);
gen_st32(tmp, addr, IS_USER(s));
}
dead_tmp(addr);
break;
case 10:
/* add to high reg */
rd = (insn >> 8) & 7;
if (insn & (1 << 11)) {
/* SP */
tmp = load_reg(s, 13);
} else {
/* PC. bit 1 is ignored. */
tmp = new_tmp();
tcg_gen_movi_i32(tmp, (s->pc + 2) & ~(uint32_t)2);
}
val = (insn & 0xff) * 4;
tcg_gen_addi_i32(tmp, tmp, val);
store_reg(s, rd, tmp);
break;
case 11:
/* misc */
op = (insn >> 8) & 0xf;
switch (op) {
case 0:
/* adjust stack pointer */
tmp = load_reg(s, 13);
val = (insn & 0x7f) * 4;
if (insn & (1 << 7))
val = -(int32_t)val;
tcg_gen_addi_i32(tmp, tmp, val);
store_reg(s, 13, tmp);
break;
case 2: /* sign/zero extend. */
ARCH(6);
rd = insn & 7;
rm = (insn >> 3) & 7;
tmp = load_reg(s, rm);
switch ((insn >> 6) & 3) {
case 0: gen_sxth(tmp); break;
case 1: gen_sxtb(tmp); break;
case 2: gen_uxth(tmp); break;
case 3: gen_uxtb(tmp); break;
}
store_reg(s, rd, tmp);
break;
case 4: case 5: case 0xc: case 0xd:
/* push/pop */
addr = load_reg(s, 13);
if (insn & (1 << 8))
offset = 4;
else
offset = 0;
for (i = 0; i < 8; i++) {
if (insn & (1 << i))
offset += 4;
}
if ((insn & (1 << 11)) == 0) {
tcg_gen_addi_i32(addr, addr, -offset);
}
for (i = 0; i < 8; i++) {
if (insn & (1 << i)) {
if (insn & (1 << 11)) {
/* pop */
tmp = gen_ld32(addr, IS_USER(s));
store_reg(s, i, tmp);
} else {
/* push */
tmp = load_reg(s, i);
gen_st32(tmp, addr, IS_USER(s));
}
/* advance to the next address. */
tcg_gen_addi_i32(addr, addr, 4);
}
}
TCGV_UNUSED(tmp);
if (insn & (1 << 8)) {
if (insn & (1 << 11)) {
/* pop pc */
tmp = gen_ld32(addr, IS_USER(s));
/* don't set the pc until the rest of the instruction
has completed */
} else {
/* push lr */
tmp = load_reg(s, 14);
gen_st32(tmp, addr, IS_USER(s));
}
tcg_gen_addi_i32(addr, addr, 4);
}
if ((insn & (1 << 11)) == 0) {
tcg_gen_addi_i32(addr, addr, -offset);
}
/* write back the new stack pointer */
store_reg(s, 13, addr);
/* set the new PC value */
if ((insn & 0x0900) == 0x0900)
gen_bx(s, tmp);
break;
case 1: case 3: case 9: case 11: /* czb */
rm = insn & 7;
tmp = load_reg(s, rm);
s->condlabel = gen_new_label();
s->condjmp = 1;
if (insn & (1 << 11))
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, s->condlabel);
else
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, s->condlabel);
dead_tmp(tmp);
offset = ((insn & 0xf8) >> 2) | (insn & 0x200) >> 3;
val = (uint32_t)s->pc + 2;
val += offset;
gen_jmp(s, val);
break;
case 15: /* IT, nop-hint. */
if ((insn & 0xf) == 0) {
gen_nop_hint(s, (insn >> 4) & 0xf);
break;
}
/* If Then. */
s->condexec_cond = (insn >> 4) & 0xe;
s->condexec_mask = insn & 0x1f;
/* No actual code generated for this insn, just setup state. */
break;
case 0xe: /* bkpt */
gen_exception_insn(s, 2, EXCP_BKPT);
break;
case 0xa: /* rev */
ARCH(6);
rn = (insn >> 3) & 0x7;
rd = insn & 0x7;
tmp = load_reg(s, rn);
switch ((insn >> 6) & 3) {
case 0: tcg_gen_bswap32_i32(tmp, tmp); break;
case 1: gen_rev16(tmp); break;
case 3: gen_revsh(tmp); break;
default: goto illegal_op;
}
store_reg(s, rd, tmp);
break;
case 6: /* cps */
ARCH(6);
if (IS_USER(s))
break;
if (IS_M(env)) {
tmp = tcg_const_i32((insn & (1 << 4)) != 0);
/* PRIMASK */
if (insn & 1) {
addr = tcg_const_i32(16);
gen_helper_v7m_msr(cpu_env, addr, tmp);
tcg_temp_free_i32(addr);
}
/* FAULTMASK */
if (insn & 2) {
addr = tcg_const_i32(17);
gen_helper_v7m_msr(cpu_env, addr, tmp);
tcg_temp_free_i32(addr);
}
tcg_temp_free_i32(tmp);
gen_lookup_tb(s);
} else {
if (insn & (1 << 4))
shift = CPSR_A | CPSR_I | CPSR_F;
else
shift = 0;
gen_set_psr_im(s, ((insn & 7) << 6), 0, shift);
}
break;
default:
goto undef;
}
break;
case 12:
/* load/store multiple */
rn = (insn >> 8) & 0x7;
addr = load_reg(s, rn);
for (i = 0; i < 8; i++) {
if (insn & (1 << i)) {
if (insn & (1 << 11)) {
/* load */
tmp = gen_ld32(addr, IS_USER(s));
store_reg(s, i, tmp);
} else {
/* store */
tmp = load_reg(s, i);
gen_st32(tmp, addr, IS_USER(s));
}
/* advance to the next address */
tcg_gen_addi_i32(addr, addr, 4);
}
}
/* Base register writeback. */
if ((insn & (1 << rn)) == 0) {
store_reg(s, rn, addr);
} else {
dead_tmp(addr);
}
break;
case 13:
/* conditional branch or swi */
cond = (insn >> 8) & 0xf;
if (cond == 0xe)
goto undef;
if (cond == 0xf) {
/* swi */
gen_set_pc_im(s->pc);
s->is_jmp = DISAS_SWI;
break;
}
/* generate a conditional jump to next instruction */
s->condlabel = gen_new_label();
gen_test_cc(cond ^ 1, s->condlabel);
s->condjmp = 1;
/* jump to the offset */
val = (uint32_t)s->pc + 2;
offset = ((int32_t)insn << 24) >> 24;
val += offset << 1;
gen_jmp(s, val);
break;
case 14:
if (insn & (1 << 11)) {
if (disas_thumb2_insn(env, s, insn))
goto undef32;
break;
}
/* unconditional branch */
val = (uint32_t)s->pc;
offset = ((int32_t)insn << 21) >> 21;
val += (offset << 1) + 2;
gen_jmp(s, val);
break;
case 15:
if (disas_thumb2_insn(env, s, insn))
goto undef32;
break;
}
return;
undef32:
gen_exception_insn(s, 4, EXCP_UDEF);
return;
illegal_op:
undef:
gen_exception_insn(s, 2, EXCP_UDEF);
}
| true | qemu | 7d1b0095bff7157e856d1d0e6c4295641ced2752 |
3,895 | int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
{
BDRVQcowState *s = bs->opaque;
QCowSnapshot *sn;
int i, snapshot_index, l1_size2;
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
if (snapshot_index < 0)
return -ENOENT;
sn = &s->snapshots[snapshot_index];
if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0)
goto fail;
if (qcow2_grow_l1_table(bs, sn->l1_size) < 0)
goto fail;
s->l1_size = sn->l1_size;
l1_size2 = s->l1_size * sizeof(uint64_t);
/* copy the snapshot l1 table to the current l1 table */
if (bdrv_pread(bs->file, sn->l1_table_offset,
s->l1_table, l1_size2) != l1_size2)
goto fail;
if (bdrv_pwrite(bs->file, s->l1_table_offset,
s->l1_table, l1_size2) != l1_size2)
goto fail;
for(i = 0;i < s->l1_size; i++) {
be64_to_cpus(&s->l1_table[i]);
}
if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0)
goto fail;
#ifdef DEBUG_ALLOC
qcow2_check_refcounts(bs);
#endif
return 0;
fail:
return -EIO;
}
| true | qemu | 8b3b720620a1137a1b794fc3ed64734236f94e06 |
3,896 | static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
{
struct XenDevice *xendev;
char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
char **dev = NULL, *dom0;
unsigned int cdev, j;
/* setup watch */
dom0 = xs_get_domain_path(xenstore, 0);
snprintf(token, sizeof(token), "be:%p:%d:%p", type, dom, ops);
snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
free(dom0);
if (!xs_watch(xenstore, path, token)) {
xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
return -1;
}
/* look for backends */
dev = xs_directory(xenstore, 0, path, &cdev);
if (!dev) {
return 0;
}
for (j = 0; j < cdev; j++) {
xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
if (xendev == NULL) {
continue;
}
xen_be_check_state(xendev);
}
free(dev);
return 0;
}
| true | qemu | 33876dfad64bc481f59c5e9ccf60db78624c4b93 |
3,897 | static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,
int point_transform, int nb_components)
{
int i, mb_x, mb_y, mask;
int bits= (s->bits+7)&~7;
int resync_mb_y = 0;
int resync_mb_x = 0;
point_transform += bits - s->bits;
mask = ((1 << s->bits) - 1) << point_transform;
av_assert0(nb_components>=1 && nb_components<=4);
for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
if (get_bits_left(&s->gb) < 1) {
av_log(s->avctx, AV_LOG_ERROR, "bitstream end in yuv_scan\n");
return AVERROR_INVALIDDATA;
}
if (s->restart_interval && !s->restart_count){
s->restart_count = s->restart_interval;
resync_mb_x = mb_x;
resync_mb_y = mb_y;
}
if(!mb_x || mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || s->interlaced){
int toprow = mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x;
int leftcol = !mb_x || mb_y == resync_mb_y && mb_x == resync_mb_x;
for (i = 0; i < nb_components; i++) {
uint8_t *ptr;
uint16_t *ptr16;
int n, h, v, x, y, c, j, linesize;
n = s->nb_blocks[i];
c = s->comp_index[i];
h = s->h_scount[i];
v = s->v_scount[i];
x = 0;
y = 0;
linesize= s->linesize[c];
if(bits>8) linesize /= 2;
for(j=0; j<n; j++) {
int pred, dc;
dc = mjpeg_decode_dc(s, s->dc_index[i]);
if(dc == 0xFFFFF)
return -1;
if ( h * mb_x + x >= s->width
|| v * mb_y + y >= s->height) {
// Nothing to do
} else if (bits<=8) {
ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
if(y==0 && toprow){
if(x==0 && leftcol){
pred= 1 << (bits - 1);
}else{
pred= ptr[-1];
}
}else{
if(x==0 && leftcol){
pred= ptr[-linesize];
}else{
PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
}
}
if (s->interlaced && s->bottom_field)
ptr += linesize >> 1;
pred &= mask;
*ptr= pred + ((unsigned)dc << point_transform);
}else{
ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
if(y==0 && toprow){
if(x==0 && leftcol){
pred= 1 << (bits - 1);
}else{
pred= ptr16[-1];
}
}else{
if(x==0 && leftcol){
pred= ptr16[-linesize];
}else{
PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
}
}
if (s->interlaced && s->bottom_field)
ptr16 += linesize >> 1;
pred &= mask;
*ptr16= pred + (dc << point_transform);
}
if (++x == h) {
x = 0;
y++;
}
}
}
} else {
for (i = 0; i < nb_components; i++) {
uint8_t *ptr;
uint16_t *ptr16;
int n, h, v, x, y, c, j, linesize, dc;
n = s->nb_blocks[i];
c = s->comp_index[i];
h = s->h_scount[i];
v = s->v_scount[i];
x = 0;
y = 0;
linesize = s->linesize[c];
if(bits>8) linesize /= 2;
for (j = 0; j < n; j++) {
int pred;
dc = mjpeg_decode_dc(s, s->dc_index[i]);
if(dc == 0xFFFFF)
return -1;
if ( h * mb_x + x >= s->width
|| v * mb_y + y >= s->height) {
// Nothing to do
} else if (bits<=8) {
ptr = s->picture_ptr->data[c] +
(linesize * (v * mb_y + y)) +
(h * mb_x + x); //FIXME optimize this crap
PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
pred &= mask;
*ptr = pred + (dc << point_transform);
}else{
ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
pred &= mask;
*ptr16= pred + (dc << point_transform);
}
if (++x == h) {
x = 0;
y++;
}
}
}
}
if (s->restart_interval && !--s->restart_count) {
align_get_bits(&s->gb);
skip_bits(&s->gb, 16); /* skip RSTn */
}
}
}
return 0;
}
| true | FFmpeg | 4b72d5cd6f9341dcafdbc1b9030166aa987b8304 |
3,898 | inline static int push_frame(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
ShowWavesContext *showwaves = outlink->src->priv;
int nb_channels = inlink->channels;
int ret, i;
if ((ret = ff_filter_frame(outlink, showwaves->outpicref)) >= 0)
showwaves->req_fullfilled = 1;
showwaves->outpicref = NULL;
showwaves->buf_idx = 0;
for (i = 0; i <= nb_channels; i++)
showwaves->buf_idy[i] = 0;
return ret;
}
| true | FFmpeg | 86476c510ebd14d33ed02289d71bae874f8707a4 |
3,899 | static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
{
int status;
status = virtio_blk_handle_scsi_req(req->dev, req->elem);
virtio_blk_req_complete(req, status);
virtio_blk_free_request(req);
}
| true | qemu | f897bf751fbd95e4015b95d202c706548586813a |
3,900 | static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx)
{
GetByteContext gbc;
PutByteContext pbc;
GetBitContext gb;
H2645NAL sps_nal = { NULL };
HEVCSPS sps = { 0 };
HEVCVPS vps = { 0 };
uint8_t vps_buf[128], vps_rbsp_buf[128];
uint8_t *new_extradata;
unsigned int sps_id;
int ret, i, type, vps_size;
if (!avctx->extradata_size) {
av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx\n");
return AVERROR_UNKNOWN;
}
/* parse the SPS */
ret = ff_h2645_extract_rbsp(avctx->extradata + 4, avctx->extradata_size - 4, &sps_nal);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error unescaping the SPS buffer\n");
return ret;
}
ret = init_get_bits8(&gb, sps_nal.data, sps_nal.size);
if (ret < 0) {
av_freep(&sps_nal.rbsp_buffer);
return ret;
}
get_bits(&gb, 1);
type = get_bits(&gb, 6);
if (type != NAL_SPS) {
av_log(avctx, AV_LOG_ERROR, "Unexpected NAL type in the extradata: %d\n",
type);
av_freep(&sps_nal.rbsp_buffer);
return AVERROR_INVALIDDATA;
}
get_bits(&gb, 9);
ret = ff_hevc_parse_sps(&sps, &gb, &sps_id, 0, NULL, avctx);
av_freep(&sps_nal.rbsp_buffer);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error parsing the SPS\n");
return ret;
}
/* generate the VPS */
vps.vps_max_layers = 1;
vps.vps_max_sub_layers = sps.max_sub_layers;
memcpy(&vps.ptl, &sps.ptl, sizeof(vps.ptl));
vps.vps_sub_layer_ordering_info_present_flag = 1;
for (i = 0; i < MAX_SUB_LAYERS; i++) {
vps.vps_max_dec_pic_buffering[i] = sps.temporal_layer[i].max_dec_pic_buffering;
vps.vps_num_reorder_pics[i] = sps.temporal_layer[i].num_reorder_pics;
vps.vps_max_latency_increase[i] = sps.temporal_layer[i].max_latency_increase;
}
vps.vps_num_layer_sets = 1;
vps.vps_timing_info_present_flag = sps.vui.vui_timing_info_present_flag;
vps.vps_num_units_in_tick = sps.vui.vui_num_units_in_tick;
vps.vps_time_scale = sps.vui.vui_time_scale;
vps.vps_poc_proportional_to_timing_flag = sps.vui.vui_poc_proportional_to_timing_flag;
vps.vps_num_ticks_poc_diff_one = sps.vui.vui_num_ticks_poc_diff_one_minus1 + 1;
/* generate the encoded RBSP form of the VPS */
ret = ff_hevc_encode_nal_vps(&vps, sps.vps_id, vps_rbsp_buf, sizeof(vps_rbsp_buf));
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error writing the VPS\n");
return ret;
}
/* escape and add the startcode */
bytestream2_init(&gbc, vps_rbsp_buf, ret);
bytestream2_init_writer(&pbc, vps_buf, sizeof(vps_buf));
bytestream2_put_be32(&pbc, 1); // startcode
bytestream2_put_byte(&pbc, NAL_VPS << 1); // NAL
bytestream2_put_byte(&pbc, 1); // header
while (bytestream2_get_bytes_left(&gbc)) {
uint32_t b = bytestream2_peek_be24(&gbc);
if (b <= 3) {
bytestream2_put_be24(&pbc, 3);
bytestream2_skip(&gbc, 2);
} else
bytestream2_put_byte(&pbc, bytestream2_get_byte(&gbc));
}
vps_size = bytestream2_tell_p(&pbc);
new_extradata = av_mallocz(vps_size + avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!new_extradata)
return AVERROR(ENOMEM);
memcpy(new_extradata, vps_buf, vps_size);
memcpy(new_extradata + vps_size, avctx->extradata, avctx->extradata_size);
av_freep(&avctx->extradata);
avctx->extradata = new_extradata;
avctx->extradata_size += vps_size;
return 0;
}
| false | FFmpeg | cc13bc8c4f0f4afa30d0b94c3f3a369ccd2aaf0b |
3,902 | static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
QCELPContext *q = avctx->priv_data;
float *outbuffer = data;
int i;
float quantized_lspf[10], lpc[10];
float gain[16];
float *formant_mem;
if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q)
{
warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
goto erasure;
}
if(q->bitrate == RATE_OCTAVE &&
(q->first16bits = AV_RB16(buf)) == 0xFFFF)
{
warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on.");
goto erasure;
}
if(q->bitrate > SILENCE)
{
const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate];
const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate]
+ qcelp_unpacking_bitmaps_lengths[q->bitrate];
uint8_t *unpacked_data = (uint8_t *)&q->frame;
init_get_bits(&q->gb, buf, 8*buf_size);
memset(&q->frame, 0, sizeof(QCELPFrame));
for(; bitmaps < bitmaps_end; bitmaps++)
unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos;
// Check for erasures/blanks on rates 1, 1/4 and 1/8.
if(q->frame.reserved)
{
warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area.");
goto erasure;
}
if(q->bitrate == RATE_QUARTER &&
codebook_sanity_check_for_rate_quarter(q->frame.cbgain))
{
warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed.");
goto erasure;
}
if(q->bitrate >= RATE_HALF)
{
for(i=0; i<4; i++)
{
if(q->frame.pfrac[i] && q->frame.plag[i] >= 124)
{
warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter.");
goto erasure;
}
}
}
}
decode_gain_and_index(q, gain);
compute_svector(q, gain, outbuffer);
if(decode_lspf(q, quantized_lspf) < 0)
{
warn_insufficient_frame_quality(avctx, "Badly received packets in frame.");
goto erasure;
}
apply_pitch_filters(q, outbuffer);
if(q->bitrate == I_F_Q)
{
erasure:
q->bitrate = I_F_Q;
q->erasure_count++;
decode_gain_and_index(q, gain);
compute_svector(q, gain, outbuffer);
decode_lspf(q, quantized_lspf);
apply_pitch_filters(q, outbuffer);
}else
q->erasure_count = 0;
formant_mem = q->formant_mem + 10;
for(i=0; i<4; i++)
{
interpolate_lpc(q, quantized_lspf, lpc, i);
ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40,
10);
formant_mem += 40;
}
// postfilter, as per TIA/EIA/IS-733 2.4.8.6
postfilter(q, outbuffer, lpc);
memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float));
memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf));
q->prev_bitrate = q->bitrate;
*data_size = 160 * sizeof(*outbuffer);
return buf_size;
}
| false | FFmpeg | e43dd3d2a8e106169e707484090a2d973ece2184 |
3,903 | int avio_read(AVIOContext *s, unsigned char *buf, int size)
{
int len, size1;
size1 = size;
while (size > 0) {
len = FFMIN(s->buf_end - s->buf_ptr, size);
if (len == 0 || s->write_flag) {
if((s->direct || size > s->buffer_size) && !s->update_checksum) {
// bypass the buffer and read data directly into buf
if(s->read_packet)
len = s->read_packet(s->opaque, buf, size);
else
len = AVERROR_EOF;
if (len == AVERROR_EOF) {
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
s->eof_reached = 1;
break;
} else if (len < 0) {
s->eof_reached = 1;
s->error= len;
break;
} else {
s->pos += len;
s->bytes_read += len;
size -= len;
buf += len;
// reset the buffer
s->buf_ptr = s->buffer;
s->buf_end = s->buffer/* + len*/;
}
} else {
fill_buffer(s);
len = s->buf_end - s->buf_ptr;
if (len == 0)
break;
}
} else {
memcpy(buf, s->buf_ptr, len);
buf += len;
s->buf_ptr += len;
size -= len;
}
}
if (size1 == size) {
if (s->error) return s->error;
if (avio_feof(s)) return AVERROR_EOF;
}
return size1 - size;
}
| false | FFmpeg | a606f27f4c610708fa96e35eed7b7537d3d8f712 |
3,904 | static int hls_probe(AVProbeData *p)
{
/* Require #EXTM3U at the start, and either one of the ones below
* somewhere for a proper match. */
if (strncmp(p->buf, "#EXTM3U", 7))
return 0;
if (p->filename && !av_match_ext(p->filename, "m3u8,m3u"))
return 0;
if (strstr(p->buf, "#EXT-X-STREAM-INF:") ||
strstr(p->buf, "#EXT-X-TARGETDURATION:") ||
strstr(p->buf, "#EXT-X-MEDIA-SEQUENCE:"))
return AVPROBE_SCORE_MAX;
return 0;
}
| false | FFmpeg | cde57eee98d2e26daeeb1ba0cdd1f3d3acb3eb8a |
3,905 | static int svq1_motion_inter_block(MpegEncContext *s, GetBitContext *bitbuf,
uint8_t *current, uint8_t *previous,
int pitch, svq1_pmv *motion, int x, int y)
{
uint8_t *src;
uint8_t *dst;
svq1_pmv mv;
svq1_pmv *pmv[3];
int result;
/* predict and decode motion vector */
pmv[0] = &motion[0];
if (y == 0) {
pmv[1] =
pmv[2] = pmv[0];
} else {
pmv[1] = &motion[x / 8 + 2];
pmv[2] = &motion[x / 8 + 4];
}
result = svq1_decode_motion_vector(bitbuf, &mv, pmv);
if (result != 0)
return result;
motion[0].x =
motion[x / 8 + 2].x =
motion[x / 8 + 3].x = mv.x;
motion[0].y =
motion[x / 8 + 2].y =
motion[x / 8 + 3].y = mv.y;
if (y + (mv.y >> 1) < 0)
mv.y = 0;
if (x + (mv.x >> 1) < 0)
mv.x = 0;
src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1)) * pitch];
dst = current;
s->dsp.put_pixels_tab[0][(mv.y & 1) << 1 | (mv.x & 1)](dst, src, pitch, 16);
return 0;
}
| false | FFmpeg | 7b9fc769e40a7709fa59a54e2a810f76364eee4b |
3,906 | int opt_default(void *optctx, const char *opt, const char *arg)
{
const AVOption *o;
int consumed = 0;
char opt_stripped[128];
const char *p;
const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
#if CONFIG_AVRESAMPLE
const AVClass *rc = avresample_get_class();
#endif
const AVClass *sc, *swr_class;
if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
av_log_set_level(AV_LOG_DEBUG);
if (!(p = strchr(opt, ':')))
p = opt + strlen(opt);
av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
if ((o = opt_find(&cc, opt_stripped, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
(o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
av_dict_set(&codec_opts, opt, arg, FLAGS);
consumed = 1;
}
if ((o = opt_find(&fc, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
av_dict_set(&format_opts, opt, arg, FLAGS);
if (consumed)
av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
consumed = 1;
}
#if CONFIG_SWSCALE
sc = sws_get_class();
if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
struct SwsContext *sws = sws_alloc_context();
int ret = av_opt_set(sws, opt, arg, 0);
sws_freeContext(sws);
if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
!strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
!strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
return AVERROR(EINVAL);
}
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
return ret;
}
av_dict_set(&sws_dict, opt, arg, FLAGS);
consumed = 1;
}
#else
if (!consumed && !strcmp(opt, "sws_flags")) {
av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
consumed = 1;
}
#endif
#if CONFIG_SWRESAMPLE
swr_class = swr_get_class();
if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
struct SwrContext *swr = swr_alloc();
int ret = av_opt_set(swr, opt, arg, 0);
swr_free(&swr);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
return ret;
}
av_dict_set(&swr_opts, opt, arg, FLAGS);
consumed = 1;
}
#endif
#if CONFIG_AVRESAMPLE
if ((o=opt_find(&rc, opt, NULL, 0,
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
av_dict_set(&resample_opts, opt, arg, FLAGS);
consumed = 1;
}
#endif
if (consumed)
return 0;
return AVERROR_OPTION_NOT_FOUND;
}
| false | FFmpeg | 254c64c574dfc427721942fa84e4d24d6b6cc4c2 |
3,908 | static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)
{
int i, ret;
Error *err = NULL;
XHCIState *xhci = XHCI(dev);
dev->config[PCI_CLASS_PROG] = 0x30; /* xHCI */
dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
dev->config[0x60] = 0x30; /* release number */
usb_xhci_init(xhci);
if (xhci->msi != ON_OFF_AUTO_OFF) {
ret = msi_init(dev, 0x70, xhci->numintrs, true, false, &err);
/* Any error other than -ENOTSUP(board's MSI support is broken)
* is a programming error */
assert(!ret || ret == -ENOTSUP);
if (ret && xhci->msi == ON_OFF_AUTO_ON) {
/* Can't satisfy user's explicit msi=on request, fail */
error_append_hint(&err, "You have to use msi=auto (default) or "
"msi=off with this machine type.\n");
error_propagate(errp, err);
return;
}
assert(!err || xhci->msi == ON_OFF_AUTO_AUTO);
/* With msi=auto, we fall back to MSI off silently */
error_free(err);
}
if (xhci->numintrs > MAXINTRS) {
xhci->numintrs = MAXINTRS;
}
while (xhci->numintrs & (xhci->numintrs - 1)) { /* ! power of 2 */
xhci->numintrs++;
}
if (xhci->numintrs < 1) {
xhci->numintrs = 1;
}
if (xhci->numslots > MAXSLOTS) {
xhci->numslots = MAXSLOTS;
}
if (xhci->numslots < 1) {
xhci->numslots = 1;
}
if (xhci_get_flag(xhci, XHCI_FLAG_ENABLE_STREAMS)) {
xhci->max_pstreams_mask = 7; /* == 256 primary streams */
} else {
xhci->max_pstreams_mask = 0;
}
xhci->mfwrap_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_mfwrap_timer, xhci);
memory_region_init(&xhci->mem, OBJECT(xhci), "xhci", LEN_REGS);
memory_region_init_io(&xhci->mem_cap, OBJECT(xhci), &xhci_cap_ops, xhci,
"capabilities", LEN_CAP);
memory_region_init_io(&xhci->mem_oper, OBJECT(xhci), &xhci_oper_ops, xhci,
"operational", 0x400);
memory_region_init_io(&xhci->mem_runtime, OBJECT(xhci), &xhci_runtime_ops, xhci,
"runtime", LEN_RUNTIME);
memory_region_init_io(&xhci->mem_doorbell, OBJECT(xhci), &xhci_doorbell_ops, xhci,
"doorbell", LEN_DOORBELL);
memory_region_add_subregion(&xhci->mem, 0, &xhci->mem_cap);
memory_region_add_subregion(&xhci->mem, OFF_OPER, &xhci->mem_oper);
memory_region_add_subregion(&xhci->mem, OFF_RUNTIME, &xhci->mem_runtime);
memory_region_add_subregion(&xhci->mem, OFF_DOORBELL, &xhci->mem_doorbell);
for (i = 0; i < xhci->numports; i++) {
XHCIPort *port = &xhci->ports[i];
uint32_t offset = OFF_OPER + 0x400 + 0x10 * i;
port->xhci = xhci;
memory_region_init_io(&port->mem, OBJECT(xhci), &xhci_port_ops, port,
port->name, 0x10);
memory_region_add_subregion(&xhci->mem, offset, &port->mem);
}
pci_register_bar(dev, 0,
PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
&xhci->mem);
if (pci_bus_is_express(dev->bus) ||
xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) {
ret = pcie_endpoint_cap_init(dev, 0xa0);
assert(ret >= 0);
}
if (xhci->msix != ON_OFF_AUTO_OFF) {
/* TODO check for errors */
msix_init(dev, xhci->numintrs,
&xhci->mem, 0, OFF_MSIX_TABLE,
&xhci->mem, 0, OFF_MSIX_PBA,
0x90);
}
}
| true | qemu | 20729dbd0109b9d9065447dba354f10bcf78d0d6 |
3,910 | int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
uint32_t len)
{
int i, index;
if (!s->files) {
int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
s->files = g_malloc0(dsize);
fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
}
index = be32_to_cpu(s->files->count);
if (index == FW_CFG_FILE_SLOTS) {
fprintf(stderr, "fw_cfg: out of file slots\n");
return 0;
}
fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
filename);
for (i = 0; i < index; i++) {
if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
trace_fw_cfg_add_file_dupe(s, s->files->f[index].name);
return 1;
}
}
s->files->f[index].size = cpu_to_be32(len);
s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
s->files->count = cpu_to_be32(index+1);
return 1;
}
| true | qemu | 4cad3867b6df2c0826ae508a9fe15dd0b9d8936a |
3,911 | static void *postcopy_ram_fault_thread(void *opaque)
{
MigrationIncomingState *mis = opaque;
struct uffd_msg msg;
int ret;
RAMBlock *rb = NULL;
RAMBlock *last_rb = NULL; /* last RAMBlock we sent part of */
trace_postcopy_ram_fault_thread_entry();
qemu_sem_post(&mis->fault_thread_sem);
while (true) {
ram_addr_t rb_offset;
struct pollfd pfd[2];
/*
* We're mainly waiting for the kernel to give us a faulting HVA,
* however we can be told to quit via userfault_quit_fd which is
* an eventfd
*/
pfd[0].fd = mis->userfault_fd;
pfd[0].events = POLLIN;
pfd[0].revents = 0;
pfd[1].fd = mis->userfault_quit_fd;
pfd[1].events = POLLIN; /* Waiting for eventfd to go positive */
pfd[1].revents = 0;
if (poll(pfd, 2, -1 /* Wait forever */) == -1) {
error_report("%s: userfault poll: %s", __func__, strerror(errno));
break;
}
if (pfd[1].revents) {
trace_postcopy_ram_fault_thread_quit();
break;
}
ret = read(mis->userfault_fd, &msg, sizeof(msg));
if (ret != sizeof(msg)) {
if (errno == EAGAIN) {
/*
* if a wake up happens on the other thread just after
* the poll, there is nothing to read.
*/
continue;
}
if (ret < 0) {
error_report("%s: Failed to read full userfault message: %s",
__func__, strerror(errno));
break;
} else {
error_report("%s: Read %d bytes from userfaultfd expected %zd",
__func__, ret, sizeof(msg));
break; /* Lost alignment, don't know what we'd read next */
}
}
if (msg.event != UFFD_EVENT_PAGEFAULT) {
error_report("%s: Read unexpected event %ud from userfaultfd",
__func__, msg.event);
continue; /* It's not a page fault, shouldn't happen */
}
rb = qemu_ram_block_from_host(
(void *)(uintptr_t)msg.arg.pagefault.address,
true, &rb_offset);
if (!rb) {
error_report("postcopy_ram_fault_thread: Fault outside guest: %"
PRIx64, (uint64_t)msg.arg.pagefault.address);
break;
}
rb_offset &= ~(qemu_ram_pagesize(rb) - 1);
trace_postcopy_ram_fault_thread_request(msg.arg.pagefault.address,
qemu_ram_get_idstr(rb),
rb_offset);
/*
* Send the request to the source - we want to request one
* of our host page sizes (which is >= TPS)
*/
if (rb != last_rb) {
last_rb = rb;
migrate_send_rp_req_pages(mis, qemu_ram_get_idstr(rb),
rb_offset, qemu_ram_pagesize(rb));
} else {
/* Save some space */
migrate_send_rp_req_pages(mis, NULL,
rb_offset, qemu_ram_pagesize(rb));
}
}
trace_postcopy_ram_fault_thread_exit();
return NULL;
}
| true | qemu | 3be98be4e9f59055afb5f2b27f9296c7093b4e75 |
3,912 | static ssize_t qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
Error **errp)
{
unsigned char opcode, fin, has_mask;
size_t header_size;
size_t payload_len;
QIOChannelWebsockHeader *header =
(QIOChannelWebsockHeader *)ioc->encinput.buffer;
if (ioc->payload_remain) {
error_setg(errp,
"Decoding header but %zu bytes of payload remain",
ioc->payload_remain);
return -1;
}
if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT) {
/* header not complete */
return QIO_CHANNEL_ERR_BLOCK;
}
fin = (header->b0 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_FIN) >>
QIO_CHANNEL_WEBSOCK_HEADER_SHIFT_FIN;
opcode = header->b0 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_OPCODE;
has_mask = (header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_HAS_MASK) >>
QIO_CHANNEL_WEBSOCK_HEADER_SHIFT_HAS_MASK;
payload_len = header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_PAYLOAD_LEN;
if (opcode == QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) {
/* disconnect */
return 0;
}
/* Websocket frame sanity check:
* * Websocket fragmentation is not supported.
* * All websockets frames sent by a client have to be masked.
* * Only binary encoding is supported.
*/
if (!fin) {
error_setg(errp, "websocket fragmentation is not supported");
return -1;
}
if (!has_mask) {
error_setg(errp, "websocket frames must be masked");
return -1;
}
if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
error_setg(errp, "only binary websocket frames are supported");
return -1;
}
if (payload_len < QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT) {
ioc->payload_remain = payload_len;
header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT;
ioc->mask = header->u.m;
} else if (payload_len == QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT &&
ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT) {
ioc->payload_remain = be16_to_cpu(header->u.s16.l16);
header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT;
ioc->mask = header->u.s16.m16;
} else if (payload_len == QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_64_BIT &&
ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT) {
ioc->payload_remain = be64_to_cpu(header->u.s64.l64);
header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT;
ioc->mask = header->u.s64.m64;
} else {
/* header not complete */
return QIO_CHANNEL_ERR_BLOCK;
}
buffer_advance(&ioc->encinput, header_size);
return 1;
}
| true | qemu | eefa3d8ef649f9055611361e2201cca49f8c3433 |
3,914 | static int vscsi_send_iu(VSCSIState *s, vscsi_req *req,
uint64_t length, uint8_t format)
{
long rc, rc1;
/* First copy the SRP */
rc = spapr_vio_dma_write(&s->vdev, req->crq.s.IU_data_ptr,
&req->iu, length);
if (rc) {
fprintf(stderr, "vscsi_send_iu: DMA write failure !\n");
}
req->crq.s.valid = 0x80;
req->crq.s.format = format;
req->crq.s.reserved = 0x00;
req->crq.s.timeout = cpu_to_be16(0x0000);
req->crq.s.IU_length = cpu_to_be16(length);
req->crq.s.IU_data_ptr = req->iu.srp.rsp.tag; /* right byte order */
if (rc == 0) {
req->crq.s.status = 0x99; /* Just needs to be non-zero */
} else {
req->crq.s.status = 0x00;
}
rc1 = spapr_vio_send_crq(&s->vdev, req->crq.raw);
if (rc1) {
fprintf(stderr, "vscsi_send_iu: Error sending response\n");
return rc1;
}
return rc;
}
| true | qemu | 22956a3755749b9cf6375ad024d58c1d277100bf |
3,915 | static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
{
AVStream *st = s->streams[1];
int av_unused tmp, tmp2;
int samples, size;
uint64_t pos = avio_tell(s->pb);
unsigned dts;
int ret;
dts = avio_rb32(s->pb);
st->codec->sample_rate = avio_rb32(s->pb);
samples = avio_rb32(s->pb);
tmp = avio_rb32(s->pb);
av_dlog(s, "packet num %d\n", tmp);
tmp = avio_rb16(s->pb); // unknown
av_dlog(s, "unknown %d\n", tmp);
tmp = avio_r8(s->pb); // major version
tmp2 = avio_r8(s->pb); // minor version
av_dlog(s, "version %d.%d\n", tmp, tmp2);
tmp = avio_rb32(s->pb); // unknown
av_dlog(s, "unknown %d\n", tmp);
size = atom->size - 8 - (avio_tell(s->pb) - pos);
if (size < 0)
return -1;
ret = av_get_packet(s->pb, pkt, size);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "error reading audio packet\n");
return ret;
}
pkt->stream_index = 1;
pkt->dts = dts;
pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
pkt->dts, pkt->duration, samples, st->codec->sample_rate);
return 0;
}
| true | FFmpeg | df92ac18528bac4566fc4f5ba4d607c1265791ea |
Subsets and Splits