id
int32 0
27.3k
| func
stringlengths 26
142k
| target
bool 2
classes | project
stringclasses 2
values | commit_id
stringlengths 40
40
|
---|---|---|---|---|
5,819 | static void ioreq_release(struct ioreq *ioreq)
{
struct XenBlkDev *blkdev = ioreq->blkdev;
LIST_REMOVE(ioreq, list);
memset(ioreq, 0, sizeof(*ioreq));
ioreq->blkdev = blkdev;
LIST_INSERT_HEAD(&blkdev->freelist, ioreq, list);
blkdev->requests_finished--;
}
| false | qemu | 72cf2d4f0e181d0d3a3122e04129c58a95da713e |
5,821 | static void static_write(void *opaque, hwaddr offset, uint64_t value,
unsigned size)
{
#ifdef SPY
printf("%s: value %08lx written at " PA_FMT "\n",
__FUNCTION__, value, offset);
#endif
}
| false | qemu | a89f364ae8740dfc31b321eed9ee454e996dc3c1 |
5,822 | static inline void set_fsr(CPUSPARCState *env)
{
int rnd_mode;
switch (env->fsr & FSR_RD_MASK) {
case FSR_RD_NEAREST:
rnd_mode = float_round_nearest_even;
break;
default:
case FSR_RD_ZERO:
rnd_mode = float_round_to_zero;
break;
case FSR_RD_POS:
rnd_mode = float_round_up;
break;
case FSR_RD_NEG:
rnd_mode = float_round_down;
break;
}
set_float_rounding_mode(rnd_mode, &env->fp_status);
}
| false | qemu | 7385aed20db5d83979f683b9d0048674411e963c |
5,823 | static void *kvm_cpu_thread_fn(void *arg)
{
CPUState *env = arg;
int r;
qemu_mutex_lock(&qemu_global_mutex);
qemu_thread_self(env->thread);
r = kvm_init_vcpu(env);
if (r < 0) {
fprintf(stderr, "kvm_init_vcpu failed: %s\n", strerror(-r));
exit(1);
}
qemu_kvm_init_cpu_signals(env);
/* signal CPU creation */
env->created = 1;
qemu_cond_signal(&qemu_cpu_cond);
/* and wait for machine initialization */
while (!qemu_system_ready)
qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100);
while (1) {
if (cpu_can_run(env))
qemu_cpu_exec(env);
qemu_kvm_wait_io_event(env);
}
return NULL;
}
| false | qemu | 7e97cd88148876bad36ee7c66d526dcaed328d0d |
5,824 | void HELPER(stfl)(CPUS390XState *env)
{
uint64_t words[MAX_STFL_WORDS];
LowCore *lowcore;
lowcore = cpu_map_lowcore(env);
do_stfle(env, words);
lowcore->stfl_fac_list = cpu_to_be32(words[0] >> 32);
cpu_unmap_lowcore(lowcore);
}
| false | qemu | f74990a5d019751c545e9800a3376b6336e77d38 |
5,828 | static int nbd_can_accept(void *opaque)
{
return nb_fds < shared;
}
| false | qemu | e4afbf4fb4d026510700cb40bb72dea9aef14e3b |
5,830 | static void pci_update_mappings(PCIDevice *d)
{
PCIIORegion *r;
int i;
pcibus_t new_addr;
for(i = 0; i < PCI_NUM_REGIONS; i++) {
r = &d->io_regions[i];
/* this region isn't registered */
if (!r->size)
continue;
new_addr = pci_bar_address(d, i, r->type, r->size);
/* This bar isn't changed */
if (new_addr == r->addr)
continue;
/* now do the real mapping */
if (r->addr != PCI_BAR_UNMAPPED) {
trace_pci_update_mappings_del(d, pci_bus_num(d->bus),
PCI_SLOT(d->devfn),
PCI_FUNC(d->devfn),
i, r->addr, r->size);
memory_region_del_subregion(r->address_space, r->memory);
}
r->addr = new_addr;
if (r->addr != PCI_BAR_UNMAPPED) {
trace_pci_update_mappings_add(d, pci_bus_num(d->bus),
PCI_SLOT(d->devfn),
PCI_FUNC(d->devfn),
i, r->addr, r->size);
memory_region_add_subregion_overlap(r->address_space,
r->addr, r->memory, 1);
}
}
pci_update_vga(d);
}
| false | qemu | fd56e0612b6454a282fa6a953fdb09281a98c589 |
5,832 | static QObject* bdrv_info_stats_bs(BlockDriverState *bs)
{
QObject *res;
QDict *dict;
res = qobject_from_jsonf("{ 'stats': {"
"'rd_bytes': %" PRId64 ","
"'wr_bytes': %" PRId64 ","
"'rd_operations': %" PRId64 ","
"'wr_operations': %" PRId64 ","
"'wr_highest_offset': %" PRId64 ","
"'flush_operations': %" PRId64
"} }",
bs->nr_bytes[BDRV_ACCT_READ],
bs->nr_bytes[BDRV_ACCT_WRITE],
bs->nr_ops[BDRV_ACCT_READ],
bs->nr_ops[BDRV_ACCT_WRITE],
bs->wr_highest_sector *
(uint64_t)BDRV_SECTOR_SIZE,
bs->nr_ops[BDRV_ACCT_FLUSH]);
dict = qobject_to_qdict(res);
if (*bs->device_name) {
qdict_put(dict, "device", qstring_from_str(bs->device_name));
}
if (bs->file) {
QObject *parent = bdrv_info_stats_bs(bs->file);
qdict_put_obj(dict, "parent", parent);
}
return res;
}
| false | qemu | c488c7f649106d09df76f697adccbe6e72520b26 |
5,833 | static void sun4m_common_init(int ram_size, int boot_device, DisplayState *ds,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model,
unsigned int machine)
{
sun4m_hw_init(&hwdefs[machine], ram_size, ds, cpu_model);
sun4m_load_kernel(hwdefs[machine].vram_size, ram_size, boot_device,
kernel_filename, kernel_cmdline, initrd_filename,
hwdefs[machine].machine_id);
}
| false | qemu | 4edebb0e8e14a5b934114b5ff74cb86437bb2532 |
5,835 | static int pmp_packet(AVFormatContext *s, AVPacket *pkt)
{
PMPContext *pmp = s->priv_data;
AVIOContext *pb = s->pb;
int ret = 0;
int i;
if (url_feof(pb))
return AVERROR_EOF;
if (pmp->cur_stream == 0) {
int num_packets;
pmp->audio_packets = avio_r8(pb);
num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1;
avio_skip(pb, 8);
pmp->current_packet = 0;
av_fast_malloc(&pmp->packet_sizes,
&pmp->packet_sizes_alloc,
num_packets * sizeof(*pmp->packet_sizes));
if (!pmp->packet_sizes_alloc) {
av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n");
return AVERROR(ENOMEM);
for (i = 0; i < num_packets; i++)
pmp->packet_sizes[i] = avio_rl32(pb);
ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
if (ret >= 0) {
ret = 0;
// FIXME: this is a hack that should be removed once
// compute_pkt_fields() can handle timestamps properly
if (pmp->cur_stream == 0)
pkt->dts = s->streams[0]->cur_dts++;
pkt->stream_index = pmp->cur_stream;
if (pmp->current_packet % pmp->audio_packets == 0)
pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
pmp->current_packet++;
return ret;
| true | FFmpeg | 8b1cd25ca7e64e6128fa2902d78e48bfeeec9786 |
5,836 | void virtio_queue_notify(VirtIODevice *vdev, int n)
{
if (n < VIRTIO_PCI_QUEUE_MAX) {
virtio_queue_notify_vq(&vdev->vq[n]);
}
}
| true | qemu | 7157e2e23e89adcd436caeab31fdd6b47eded377 |
5,838 | int av_picture_crop(AVPicture *dst, const AVPicture *src,
enum PixelFormat pix_fmt, int top_band, int left_band)
{
int y_shift;
int x_shift;
if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
return -1;
y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
if (is_yuv_planar(&pix_fmt_info[pix_fmt])) {
dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
} else{
if(top_band % (1<<y_shift) || left_band % (1<<x_shift))
return -1;
if(left_band) //FIXME add support for this too
return -1;
dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
}
dst->linesize[0] = src->linesize[0];
dst->linesize[1] = src->linesize[1];
dst->linesize[2] = src->linesize[2];
return 0;
}
| false | FFmpeg | d7e14c0d103a2c9cca6c50568e09b40d6f48ea19 |
5,839 | void ff_put_h264_qpel16_mc30_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_hz_qrt_16w_msa(src - 2, stride, dst, stride, 16, 1);
}
| false | FFmpeg | b5da07d4340a8e8e40dcd1900977a76ff31fbb84 |
5,841 | static int wv_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
WVContext *wc = s->priv_data;
int ret, samples;
if (url_feof(&s->pb))
return -EIO;
if(wc->block_parsed){
if(wv_read_block_header(s, &s->pb) < 0)
return -1;
}
samples = LE_32(wc->extra);
/* should not happen but who knows */
if(samples * 2 * wc->chan > AVCODEC_MAX_AUDIO_FRAME_SIZE){
av_log(s, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n");
return -EIO;
}
if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE) < 0)
return AVERROR_NOMEM;
memcpy(pkt->data, wc->extra, WV_EXTRA_SIZE);
ret = get_buffer(&s->pb, pkt->data + WV_EXTRA_SIZE, wc->blksize);
if(ret != wc->blksize){
av_free_packet(pkt);
return AVERROR_IO;
}
pkt->stream_index = 0;
wc->block_parsed = 1;
pkt->size = ret + WV_EXTRA_SIZE;
return 0;
}
| false | FFmpeg | 4ec0beaa593860796feead14132506226a1edf0e |
5,842 | static void calc_masking(DCAEncContext *c, const int32_t *input)
{
int i, k, band, ch, ssf;
int32_t data[512];
for (i = 0; i < 256; i++)
for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
c->masking_curve_cb[ssf][i] = -2047;
for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
for (ch = 0; ch < c->fullband_channels; ch++) {
const int chi = c->channel_order_tab[ch];
for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++)
data[i] = c->history[k][ch];
for (k -= 512; i < 512; i++, k++)
data[i] = input[k * c->channels + chi];
adjust_jnd(c->samplerate_index, data, c->masking_curve_cb[ssf]);
}
for (i = 0; i < 256; i++) {
int32_t m = 2048;
for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
if (c->masking_curve_cb[ssf][i] < m)
m = c->masking_curve_cb[ssf][i];
c->eff_masking_curve_cb[i] = m;
}
for (band = 0; band < 32; band++) {
c->band_masking_cb[band] = 2048;
walk_band_low(c, band, 0, update_band_masking, NULL);
walk_band_high(c, band, 0, update_band_masking, NULL);
}
}
| false | FFmpeg | a6191d098a03f94685ae4c072bfdf10afcd86223 |
5,843 | static coroutine_fn void nbd_trip(void *opaque)
{
NBDClient *client = opaque;
NBDExport *exp = client->exp;
NBDRequestData *req;
NBDRequest request = { 0 }; /* GCC thinks it can be used uninitialized */
int ret;
int flags;
int reply_data_len = 0;
Error *local_err = NULL;
char *msg = NULL;
trace_nbd_trip();
if (client->closing) {
nbd_client_put(client);
return;
}
req = nbd_request_get(client);
ret = nbd_co_receive_request(req, &request, &local_err);
client->recv_coroutine = NULL;
nbd_client_receive_next_request(client);
if (ret == -EIO) {
goto disconnect;
}
if (ret < 0) {
goto reply;
}
if (client->closing) {
/*
* The client may be closed when we are blocked in
* nbd_co_receive_request()
*/
goto done;
}
switch (request.type) {
case NBD_CMD_READ:
/* XXX: NBD Protocol only documents use of FUA with WRITE */
if (request.flags & NBD_CMD_FLAG_FUA) {
ret = blk_co_flush(exp->blk);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "flush failed");
break;
}
}
ret = blk_pread(exp->blk, request.from + exp->dev_offset,
req->data, request.len);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "reading from file failed");
break;
}
reply_data_len = request.len;
break;
case NBD_CMD_WRITE:
if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
error_setg(&local_err, "Export is read-only");
ret = -EROFS;
break;
}
flags = 0;
if (request.flags & NBD_CMD_FLAG_FUA) {
flags |= BDRV_REQ_FUA;
}
ret = blk_pwrite(exp->blk, request.from + exp->dev_offset,
req->data, request.len, flags);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "writing to file failed");
}
break;
case NBD_CMD_WRITE_ZEROES:
if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
error_setg(&local_err, "Export is read-only");
ret = -EROFS;
break;
}
flags = 0;
if (request.flags & NBD_CMD_FLAG_FUA) {
flags |= BDRV_REQ_FUA;
}
if (!(request.flags & NBD_CMD_FLAG_NO_HOLE)) {
flags |= BDRV_REQ_MAY_UNMAP;
}
ret = blk_pwrite_zeroes(exp->blk, request.from + exp->dev_offset,
request.len, flags);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "writing to file failed");
}
break;
case NBD_CMD_DISC:
/* unreachable, thanks to special case in nbd_co_receive_request() */
abort();
case NBD_CMD_FLUSH:
ret = blk_co_flush(exp->blk);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "flush failed");
}
break;
case NBD_CMD_TRIM:
ret = blk_co_pdiscard(exp->blk, request.from + exp->dev_offset,
request.len);
if (ret < 0) {
error_setg_errno(&local_err, -ret, "discard failed");
}
break;
default:
error_setg(&local_err, "invalid request type (%" PRIu32 ") received",
request.type);
ret = -EINVAL;
}
reply:
if (local_err) {
/* If we get here, local_err was not a fatal error, and should be sent
* to the client. */
assert(ret < 0);
msg = g_strdup(error_get_pretty(local_err));
error_report_err(local_err);
local_err = NULL;
}
if (client->structured_reply &&
(ret < 0 || request.type == NBD_CMD_READ)) {
if (ret < 0) {
ret = nbd_co_send_structured_error(req->client, request.handle,
-ret, msg, &local_err);
} else {
ret = nbd_co_send_structured_read(req->client, request.handle,
request.from, req->data,
reply_data_len, &local_err);
}
} else {
ret = nbd_co_send_simple_reply(req->client, request.handle,
ret < 0 ? -ret : 0,
req->data, reply_data_len, &local_err);
}
g_free(msg);
if (ret < 0) {
error_prepend(&local_err, "Failed to send reply: ");
goto disconnect;
}
/* We must disconnect after NBD_CMD_WRITE if we did not
* read the payload.
*/
if (!req->complete) {
error_setg(&local_err, "Request handling failed in intermediate state");
goto disconnect;
}
done:
nbd_request_put(req);
nbd_client_put(client);
return;
disconnect:
if (local_err) {
error_reportf_err(local_err, "Disconnect client, due to: ");
}
nbd_request_put(req);
client_close(client, true);
nbd_client_put(client);
}
| true | qemu | ef8c887ee01a4e4c8c5c28c86ea5b45162c51bcd |
5,844 | static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,
int8_t exp_shift, uint8_t *exp,
uint8_t *bap, uint16_t *qmant, int n)
{
int i;
for (i = 0; i < n; i++) {
int v;
int c = fixed_coef[i];
int e = exp[i] - exp_shift;
int b = bap[i];
switch (b) {
case 0:
v = 0;
break;
case 1:
v = sym_quant(c, e, 3);
switch (s->mant1_cnt) {
case 0:
s->qmant1_ptr = &qmant[i];
v = 9 * v;
s->mant1_cnt = 1;
break;
case 1:
*s->qmant1_ptr += 3 * v;
s->mant1_cnt = 2;
v = 128;
break;
default:
*s->qmant1_ptr += v;
s->mant1_cnt = 0;
v = 128;
break;
}
break;
case 2:
v = sym_quant(c, e, 5);
switch (s->mant2_cnt) {
case 0:
s->qmant2_ptr = &qmant[i];
v = 25 * v;
s->mant2_cnt = 1;
break;
case 1:
*s->qmant2_ptr += 5 * v;
s->mant2_cnt = 2;
v = 128;
break;
default:
*s->qmant2_ptr += v;
s->mant2_cnt = 0;
v = 128;
break;
}
break;
case 3:
v = sym_quant(c, e, 7);
break;
case 4:
v = sym_quant(c, e, 11);
switch (s->mant4_cnt) {
case 0:
s->qmant4_ptr = &qmant[i];
v = 11 * v;
s->mant4_cnt = 1;
break;
default:
*s->qmant4_ptr += v;
s->mant4_cnt = 0;
v = 128;
break;
}
break;
case 5:
v = sym_quant(c, e, 15);
break;
case 14:
v = asym_quant(c, e, 14);
break;
case 15:
v = asym_quant(c, e, 16);
break;
default:
v = asym_quant(c, e, b - 1);
break;
}
qmant[i] = v;
}
}
| true | FFmpeg | 323e6fead07c75f418e4b60704a4f437bb3483b2 |
5,848 | static inline void tb_alloc_page(TranslationBlock *tb,
unsigned int n, tb_page_addr_t page_addr)
{
PageDesc *p;
#ifndef CONFIG_USER_ONLY
bool page_already_protected;
#endif
assert_memory_lock();
tb->page_addr[n] = page_addr;
p = page_find_alloc(page_addr >> TARGET_PAGE_BITS, 1);
tb->page_next[n] = p->first_tb;
#ifndef CONFIG_USER_ONLY
page_already_protected = p->first_tb != NULL;
#endif
p->first_tb = (TranslationBlock *)((uintptr_t)tb | n);
invalidate_page_bitmap(p);
#if defined(CONFIG_USER_ONLY)
if (p->flags & PAGE_WRITE) {
target_ulong addr;
PageDesc *p2;
int prot;
/* force the host page as non writable (writes will have a
page fault + mprotect overhead) */
page_addr &= qemu_host_page_mask;
prot = 0;
for (addr = page_addr; addr < page_addr + qemu_host_page_size;
addr += TARGET_PAGE_SIZE) {
p2 = page_find(addr >> TARGET_PAGE_BITS);
if (!p2) {
continue;
}
prot |= p2->flags;
p2->flags &= ~PAGE_WRITE;
}
mprotect(g2h(page_addr), qemu_host_page_size,
(prot & PAGE_BITS) & ~PAGE_WRITE);
#ifdef DEBUG_TB_INVALIDATE
printf("protecting code page: 0x" TARGET_FMT_lx "\n",
page_addr);
#endif
}
#else
/* if some code is already present, then the pages are already
protected. So we handle the case where only the first TB is
allocated in a physical page */
if (!page_already_protected) {
tlb_protect_code(page_addr);
}
#endif
}
| true | qemu | 67a5b5d2f6eb6d3b980570223ba5c478487ddb6f |
5,849 | void address_space_destroy(AddressSpace *as)
{
/* Flush out anything from MemoryListeners listening in on this */
memory_region_transaction_begin();
as->root = NULL;
memory_region_transaction_commit();
QTAILQ_REMOVE(&address_spaces, as, address_spaces_link);
address_space_destroy_dispatch(as);
flatview_destroy(as->current_map);
g_free(as->current_map);
} | true | qemu | 4c19eb721a5929f2277d33a98bb59963c58c2e3b |
5,850 | static void test_submit(void)
{
WorkerTestData data = { .n = 0 };
thread_pool_submit(pool, worker_cb, &data);
qemu_aio_wait_all();
g_assert_cmpint(data.n, ==, 1);
}
| true | qemu | 35ecde26018207fe723bec6efbd340db6e9c2d53 |
5,851 | static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
int *got_frame, uint8_t *data_start,
unsigned int data_size)
{
WebPContext *s = avctx->priv_data;
AVPacket pkt;
int ret;
if (!s->initialized) {
ff_vp8_decode_init(avctx);
s->initialized = 1;
if (s->has_alpha)
avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
}
s->lossless = 0;
if (data_size > INT_MAX) {
av_log(avctx, AV_LOG_ERROR, "unsupported chunk size\n");
return AVERROR_PATCHWELCOME;
}
av_init_packet(&pkt);
pkt.data = data_start;
pkt.size = data_size;
ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
if (s->has_alpha) {
ret = vp8_lossy_decode_alpha(avctx, p, s->alpha_data,
s->alpha_data_size);
}
} | true | FFmpeg | 9bf4523e40148fdd27064ab570952bd8c4d1016e |
5,853 | static void vfio_calxeda_xgmac_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VFIOCalxedaXgmacDeviceClass *vcxc =
VFIO_CALXEDA_XGMAC_DEVICE_CLASS(klass);
vcxc->parent_realize = dc->realize;
dc->realize = calxeda_xgmac_realize;
dc->desc = "VFIO Calxeda XGMAC";
dc->vmsd = &vfio_platform_calxeda_xgmac_vmstate;
} | true | qemu | e4f4fb1eca795e36f363b4647724221e774523c1 |
5,854 | static void ppcuic_set_irq (void *opaque, int irq_num, int level)
{
ppcuic_t *uic;
uint32_t mask, sr;
uic = opaque;
mask = 1 << (31-irq_num);
LOG_UIC("%s: irq %d level %d uicsr %08" PRIx32
" mask %08" PRIx32 " => %08" PRIx32 " %08" PRIx32 "\n",
__func__, irq_num, level,
uic->uicsr, mask, uic->uicsr & mask, level << irq_num);
if (irq_num < 0 || irq_num > 31)
return;
sr = uic->uicsr;
/* Update status register */
if (uic->uictr & mask) {
/* Edge sensitive interrupt */
if (level == 1)
uic->uicsr |= mask;
} else {
/* Level sensitive interrupt */
if (level == 1) {
uic->uicsr |= mask;
uic->level |= mask;
} else {
uic->uicsr &= ~mask;
uic->level &= ~mask;
}
}
LOG_UIC("%s: irq %d level %d sr %" PRIx32 " => "
"%08" PRIx32 "\n", __func__, irq_num, level, uic->uicsr, sr);
if (sr != uic->uicsr)
ppcuic_trigger_irq(uic);
}
| true | qemu | a1f7f97b950a46393b0e55a9a0082e70f540cbbd |
5,856 | static int avi_sync(AVFormatContext *s, int exit_early)
{
AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb;
int n;
unsigned int d[8];
unsigned int size;
int64_t i, sync;
start_sync:
memset(d, -1, sizeof(d));
for(i=sync=avio_tell(pb); !url_feof(pb); i++) {
int j;
for(j=0; j<7; j++)
d[j]= d[j+1];
d[7]= avio_r8(pb);
size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
n= get_stream_idx(d+2);
//av_log(s, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
if(i + (uint64_t)size > avi->fsize || d[0] > 127)
//parse ix##
if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams)
//parse JUNK
||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')
||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){
avio_skip(pb, size);
//av_log(s, AV_LOG_DEBUG, "SKIP\n");
goto start_sync;
//parse stray LIST
if(d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T'){
avio_skip(pb, 4);
goto start_sync;
n= get_stream_idx(d);
if(!((i-avi->last_pkt_pos)&1) && get_stream_idx(d+1) < s->nb_streams)
//detect ##ix chunk and skip
if(d[2] == 'i' && d[3] == 'x' && n < s->nb_streams){
avio_skip(pb, size);
goto start_sync;
//parse ##dc/##wb
if(n < s->nb_streams){
AVStream *st;
AVIStream *ast;
st = s->streams[n];
ast = st->priv_data;
if(s->nb_streams>=2){
AVStream *st1 = s->streams[1];
AVIStream *ast1= st1->priv_data;
//workaround for broken small-file-bug402.avi
if( d[2] == 'w' && d[3] == 'b'
&& n==0
&& st ->codec->codec_type == AVMEDIA_TYPE_VIDEO
&& st1->codec->codec_type == AVMEDIA_TYPE_AUDIO
&& ast->prefix == 'd'*256+'c'
&& (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
){
n=1;
st = st1;
ast = ast1;
av_log(s, AV_LOG_WARNING, "Invalid stream + prefix combination, assuming audio.\n");
if( (st->discard >= AVDISCARD_DEFAULT && size==0)
/*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering
|| st->discard >= AVDISCARD_ALL){
if (!exit_early) {
ast->frame_offset += get_duration(ast, size);
avio_skip(pb, size);
goto start_sync;
if (d[2] == 'p' && d[3] == 'c' && size<=4*256+4) {
int k = avio_r8(pb);
int last = (k + avio_r8(pb) - 1) & 0xFF;
avio_rl16(pb); //flags
for (; k <= last; k++)
ast->pal[k] = 0xFF<<24 | avio_rb32(pb)>>8;// b + (g << 8) + (r << 16);
ast->has_pal= 1;
goto start_sync;
} else if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
d[2]*256+d[3] == ast->prefix /*||
(d[2] == 'd' && d[3] == 'c') ||
(d[2] == 'w' && d[3] == 'b')*/) {
if (exit_early)
return 0;
//av_log(s, AV_LOG_DEBUG, "OK\n");
if(d[2]*256+d[3] == ast->prefix)
ast->prefix_count++;
else{
ast->prefix= d[2]*256+d[3];
ast->prefix_count= 0;
avi->stream_index= n;
ast->packet_size= size + 8;
ast->remaining= size;
if(size || !ast->sample_size){
uint64_t pos= avio_tell(pb) - 8;
if(!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos){
av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME);
return 0;
if(pb->error)
return pb->error;
return AVERROR_EOF; | true | FFmpeg | 096231d497457be9496b0be01ff6da2093186c3c |
5,857 | static void ide_atapi_cmd(IDEState *s)
{
const uint8_t *packet;
uint8_t *buf;
int max_len;
packet = s->io_buffer;
buf = s->io_buffer;
#ifdef DEBUG_IDE_ATAPI
{
int i;
printf("ATAPI limit=0x%x packet:", s->lcyl | (s->hcyl << 8));
for(i = 0; i < ATAPI_PACKET_SIZE; i++) {
printf(" %02x", packet[i]);
printf("\n");
#endif
/* If there's a UNIT_ATTENTION condition pending, only
REQUEST_SENSE and INQUIRY commands are allowed to complete. */
if (s->sense_key == SENSE_UNIT_ATTENTION &&
s->io_buffer[0] != GPCMD_REQUEST_SENSE &&
s->io_buffer[0] != GPCMD_INQUIRY) {
ide_atapi_cmd_check_status(s);
return;
switch(s->io_buffer[0]) {
case GPCMD_TEST_UNIT_READY:
if (bdrv_is_inserted(s->bs) && !s->cdrom_changed) {
ide_atapi_cmd_ok(s);
} else {
s->cdrom_changed = 0;
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
case GPCMD_MODE_SENSE_6:
case GPCMD_MODE_SENSE_10:
{
int action, code;
if (packet[0] == GPCMD_MODE_SENSE_10)
else
max_len = packet[4];
action = packet[2] >> 6;
code = packet[2] & 0x3f;
switch(action) {
case 0: /* current values */
switch(code) {
case GPMODE_R_W_ERROR_PAGE: /* error recovery */
cpu_to_ube16(&buf[0], 16 + 6);
buf[2] = 0x70;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
buf[8] = 0x01;
buf[9] = 0x06;
buf[10] = 0x00;
buf[11] = 0x05;
buf[12] = 0x00;
buf[13] = 0x00;
buf[14] = 0x00;
buf[15] = 0x00;
ide_atapi_cmd_reply(s, 16, max_len);
case GPMODE_AUDIO_CTL_PAGE:
cpu_to_ube16(&buf[0], 24 + 6);
buf[2] = 0x70;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
/* Fill with CDROM audio volume */
buf[17] = 0;
buf[19] = 0;
buf[21] = 0;
buf[23] = 0;
ide_atapi_cmd_reply(s, 24, max_len);
case GPMODE_CAPABILITIES_PAGE:
cpu_to_ube16(&buf[0], 28 + 6);
buf[2] = 0x70;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
buf[8] = 0x2a;
buf[9] = 0x12;
buf[10] = 0x00;
buf[11] = 0x00;
/* Claim PLAY_AUDIO capability (0x01) since some Linux
code checks for this to automount media. */
buf[12] = 0x71;
buf[13] = 3 << 5;
buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
if (bdrv_is_locked(s->bs))
buf[6] |= 1 << 1;
buf[15] = 0x00;
cpu_to_ube16(&buf[16], 706);
buf[18] = 0;
buf[19] = 2;
cpu_to_ube16(&buf[20], 512);
cpu_to_ube16(&buf[22], 706);
buf[24] = 0;
buf[25] = 0;
buf[26] = 0;
buf[27] = 0;
ide_atapi_cmd_reply(s, 28, max_len);
default:
goto error_cmd;
case 1: /* changeable values */
goto error_cmd;
case 2: /* default values */
goto error_cmd;
default:
case 3: /* saved values */
ASC_SAVING_PARAMETERS_NOT_SUPPORTED);
case GPCMD_REQUEST_SENSE:
max_len = packet[4];
memset(buf, 0, 18);
buf[0] = 0x70 | (1 << 7);
buf[2] = s->sense_key;
buf[7] = 10;
buf[12] = s->asc;
if (s->sense_key == SENSE_UNIT_ATTENTION)
s->sense_key = SENSE_NONE;
ide_atapi_cmd_reply(s, 18, max_len);
case GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
if (bdrv_is_inserted(s->bs)) {
bdrv_set_locked(s->bs, packet[4] & 1);
ide_atapi_cmd_ok(s);
} else {
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
case GPCMD_READ_10:
case GPCMD_READ_12:
{
int nb_sectors, lba;
if (packet[0] == GPCMD_READ_10)
nb_sectors = ube16_to_cpu(packet + 7);
else
nb_sectors = ube32_to_cpu(packet + 6);
lba = ube32_to_cpu(packet + 2);
if (nb_sectors == 0) {
ide_atapi_cmd_ok(s);
ide_atapi_cmd_read(s, lba, nb_sectors, 2048);
case GPCMD_READ_CD:
{
int nb_sectors, lba, transfer_request;
nb_sectors = (packet[6] << 16) | (packet[7] << 8) | packet[8];
lba = ube32_to_cpu(packet + 2);
if (nb_sectors == 0) {
ide_atapi_cmd_ok(s);
transfer_request = packet[9];
switch(transfer_request & 0xf8) {
case 0x00:
/* nothing */
ide_atapi_cmd_ok(s);
case 0x10:
/* normal read */
ide_atapi_cmd_read(s, lba, nb_sectors, 2048);
case 0xf8:
/* read all data */
ide_atapi_cmd_read(s, lba, nb_sectors, 2352);
default:
case GPCMD_SEEK:
{
unsigned int lba;
uint64_t total_sectors;
bdrv_get_geometry(s->bs, &total_sectors);
total_sectors >>= 2;
if (total_sectors == 0) {
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
lba = ube32_to_cpu(packet + 2);
if (lba >= total_sectors) {
ASC_LOGICAL_BLOCK_OOR);
ide_atapi_cmd_ok(s);
case GPCMD_START_STOP_UNIT:
{
int start, eject, err = 0;
start = packet[4] & 1;
eject = (packet[4] >> 1) & 1;
if (eject) {
err = bdrv_eject(s->bs, !start);
switch (err) {
case 0:
ide_atapi_cmd_ok(s);
case -EBUSY:
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIA_REMOVAL_PREVENTED);
default:
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
case GPCMD_MECHANISM_STATUS:
{
max_len = ube16_to_cpu(packet + 8);
cpu_to_ube16(buf, 0);
/* no current LBA */
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 1;
cpu_to_ube16(buf + 6, 0);
ide_atapi_cmd_reply(s, 8, max_len);
case GPCMD_READ_TOC_PMA_ATIP:
{
int format, msf, start_track, len;
uint64_t total_sectors;
bdrv_get_geometry(s->bs, &total_sectors);
total_sectors >>= 2;
if (total_sectors == 0) {
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
format = packet[9] >> 6;
msf = (packet[1] >> 1) & 1;
start_track = packet[6];
switch(format) {
case 0:
len = cdrom_read_toc(total_sectors, buf, msf, start_track);
if (len < 0)
goto error_cmd;
ide_atapi_cmd_reply(s, len, max_len);
case 1:
/* multi session : only a single session defined */
memset(buf, 0, 12);
buf[1] = 0x0a;
buf[2] = 0x01;
buf[3] = 0x01;
ide_atapi_cmd_reply(s, 12, max_len);
case 2:
len = cdrom_read_toc_raw(total_sectors, buf, msf, start_track);
if (len < 0)
goto error_cmd;
ide_atapi_cmd_reply(s, len, max_len);
default:
error_cmd:
case GPCMD_READ_CDVD_CAPACITY:
{
uint64_t total_sectors;
bdrv_get_geometry(s->bs, &total_sectors);
total_sectors >>= 2;
if (total_sectors == 0) {
ide_atapi_cmd_error(s, SENSE_NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
/* NOTE: it is really the number of sectors minus 1 */
cpu_to_ube32(buf, total_sectors - 1);
cpu_to_ube32(buf + 4, 2048);
ide_atapi_cmd_reply(s, 8, 8);
case GPCMD_READ_DVD_STRUCTURE:
{
int media = packet[1];
int format = packet[7];
int ret;
max_len = ube16_to_cpu(packet + 8);
if (format < 0xff) {
if (media_is_cd(s)) {
ASC_INCOMPATIBLE_FORMAT);
} else if (!media_present(s)) {
memset(buf, 0, max_len > IDE_DMA_BUF_SECTORS * 512 + 4 ?
IDE_DMA_BUF_SECTORS * 512 + 4 : max_len);
switch (format) {
case 0x00 ... 0x7f:
case 0xff:
if (media == 0) {
ret = ide_dvd_read_structure(s, format, packet, buf);
if (ret < 0)
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, -ret);
else
ide_atapi_cmd_reply(s, ret, max_len);
/* TODO: BD support, fall through for now */
/* Generic disk structures */
case 0x80: /* TODO: AACS volume identifier */
case 0x81: /* TODO: AACS media serial number */
case 0x82: /* TODO: AACS media identifier */
case 0x83: /* TODO: AACS media key block */
case 0x90: /* TODO: List of recognized format layers */
case 0xc0: /* TODO: Write protection status */
default:
case GPCMD_SET_SPEED:
ide_atapi_cmd_ok(s);
case GPCMD_INQUIRY:
max_len = packet[4];
buf[0] = 0x05; /* CD-ROM */
buf[1] = 0x80; /* removable */
buf[2] = 0x00; /* ISO */
buf[3] = 0x21; /* ATAPI-2 (XXX: put ATAPI-4 ?) */
buf[4] = 31; /* additional length */
buf[5] = 0; /* reserved */
buf[6] = 0; /* reserved */
buf[7] = 0; /* reserved */
padstr8(buf + 8, 8, "QEMU");
padstr8(buf + 16, 16, "QEMU DVD-ROM");
padstr8(buf + 32, 4, s->version);
ide_atapi_cmd_reply(s, 36, max_len);
case GPCMD_GET_CONFIGURATION:
{
uint32_t len;
uint8_t index = 0;
/* only feature 0 is supported */
if (packet[2] != 0 || packet[3] != 0) {
/* XXX: could result in alignment problems in some architectures */
/*
* XXX: avoid overflow for io_buffer if max_len is bigger than
* the size of that buffer (dimensioned to max number of
* sectors to transfer at once)
*
* Only a problem if the feature/profiles grow.
*/
if (max_len > 512) /* XXX: assume 1 sector */
max_len = 512;
memset(buf, 0, max_len);
/*
* the number of sectors from the media tells us which profile
* to use as current. 0 means there is no media
*/
if (media_is_dvd(s))
cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM);
else if (media_is_cd(s))
cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM);
buf[10] = 0x02 | 0x01; /* persistent and current */
len = 12; /* headers: 8 + 4 */
len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM);
len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM);
cpu_to_ube32(buf, len - 4); /* data length */
ide_atapi_cmd_reply(s, len, max_len);
default:
ASC_ILLEGAL_OPCODE); | true | qemu | 253cb7b9909806b83d73269afb9cf0ab3fa2ce2c |
5,858 | void rgb16tobgr15(const uint8_t *src, uint8_t *dst, unsigned int src_size)
{
unsigned i;
unsigned num_pixels = src_size >> 1;
for(i=0; i<num_pixels; i++)
{
unsigned b,g,r;
register uint16_t rgb;
rgb = src[2*i];
r = rgb&0x1F;
g = (rgb&0x7E0)>>5;
b = (rgb&0xF800)>>11;
dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
}
}
| true | FFmpeg | 7f526efd17973ec6d2204f7a47b6923e2be31363 |
5,859 | static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,
int evpd, int pc, void **inq, Error **errp)
{
int full_size;
struct scsi_task *task = NULL;
task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, 64);
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
goto fail;
}
full_size = scsi_datain_getfullsize(task);
if (full_size > task->datain.size) {
scsi_free_scsi_task(task);
/* we need more data for the full list */
task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, full_size);
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
goto fail;
}
}
*inq = scsi_datain_unmarshall(task);
if (*inq == NULL) {
error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob");
goto fail;
}
return task;
fail:
if (!error_is_set(errp)) {
error_setg(errp, "iSCSI: Inquiry command failed : %s",
iscsi_get_error(iscsi));
}
if (task != NULL) {
scsi_free_scsi_task(task);
}
return NULL;
}
| true | qemu | 172fc4dd33e604dcf868c28e73398c19e161708b |
5,861 | int kvm_arch_handle_exit(CPUPPCState *env, struct kvm_run *run)
{
int ret;
switch (run->exit_reason) {
case KVM_EXIT_DCR:
if (run->dcr.is_write) {
dprintf("handle dcr write\n");
ret = kvmppc_handle_dcr_write(env, run->dcr.dcrn, run->dcr.data);
} else {
dprintf("handle dcr read\n");
ret = kvmppc_handle_dcr_read(env, run->dcr.dcrn, &run->dcr.data);
}
break;
case KVM_EXIT_HLT:
dprintf("handle halt\n");
ret = kvmppc_handle_halt(env);
break;
#ifdef CONFIG_PSERIES
case KVM_EXIT_PAPR_HCALL:
dprintf("handle PAPR hypercall\n");
run->papr_hcall.ret = spapr_hypercall(env, run->papr_hcall.nr,
run->papr_hcall.args);
ret = 1;
break;
#endif
default:
fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
ret = -1;
break;
}
return ret;
}
| true | qemu | 78e8fde26c032931ca2ae13bfc7c59e38afd17ee |
5,862 | static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val)
{
static const S390Opcode ni_insns[4] = {
RI_NILL, RI_NILH, RI_NIHL, RI_NIHH
};
static const S390Opcode nif_insns[2] = {
RIL_NILF, RIL_NIHF
};
uint64_t valid = (type == TCG_TYPE_I32 ? 0xffffffffull : -1ull);
int i;
/* Look for the zero-extensions. */
if ((val & valid) == 0xffffffff) {
tgen_ext32u(s, dest, dest);
return;
}
if (facilities & FACILITY_EXT_IMM) {
if ((val & valid) == 0xff) {
tgen_ext8u(s, TCG_TYPE_I64, dest, dest);
return;
}
if ((val & valid) == 0xffff) {
tgen_ext16u(s, TCG_TYPE_I64, dest, dest);
return;
}
}
/* Try all 32-bit insns that can perform it in one go. */
for (i = 0; i < 4; i++) {
tcg_target_ulong mask = ~(0xffffull << i*16);
if (((val | ~valid) & mask) == mask) {
tcg_out_insn_RI(s, ni_insns[i], dest, val >> i*16);
return;
}
}
/* Try all 48-bit insns that can perform it in one go. */
if (facilities & FACILITY_EXT_IMM) {
for (i = 0; i < 2; i++) {
tcg_target_ulong mask = ~(0xffffffffull << i*32);
if (((val | ~valid) & mask) == mask) {
tcg_out_insn_RIL(s, nif_insns[i], dest, val >> i*32);
return;
}
}
}
if ((facilities & FACILITY_GEN_INST_EXT) && risbg_mask(val)) {
int msb, lsb;
if ((val & 0x8000000000000001ull) == 0x8000000000000001ull) {
/* Achieve wraparound by swapping msb and lsb. */
msb = 63 - ctz64(~val);
lsb = clz64(~val) + 1;
} else {
msb = clz64(val);
lsb = 63 - ctz64(val);
}
tcg_out_risbg(s, dest, dest, msb, lsb, 0, 1);
return;
}
/* Fall back to loading the constant. */
tcg_out_movi(s, type, TCG_TMP0, val);
if (type == TCG_TYPE_I32) {
tcg_out_insn(s, RR, NR, dest, TCG_TMP0);
} else {
tcg_out_insn(s, RRE, NGR, dest, TCG_TMP0);
}
}
| true | qemu | a1756896546fccf39eef6f282dcbd2f9292c1286 |
5,863 | static inline void RENAME(rgb16to24)(const uint8_t *src, uint8_t *dst, unsigned src_size)
{
const uint16_t *end;
#ifdef HAVE_MMX
const uint16_t *mm_end;
#endif
uint8_t *d = (uint8_t *)dst;
const uint16_t *s = (const uint16_t *)src;
end = s + src_size/2;
#ifdef HAVE_MMX
__asm __volatile(PREFETCH" %0"::"m"(*s):"memory");
mm_end = end - 7;
while(s < mm_end)
{
__asm __volatile(
PREFETCH" 32%1\n\t"
"movq %1, %%mm0\n\t"
"movq %1, %%mm1\n\t"
"movq %1, %%mm2\n\t"
"pand %2, %%mm0\n\t"
"pand %3, %%mm1\n\t"
"pand %4, %%mm2\n\t"
"psllq $3, %%mm0\n\t"
"psrlq $3, %%mm1\n\t"
"psrlq $8, %%mm2\n\t"
"movq %%mm0, %%mm3\n\t"
"movq %%mm1, %%mm4\n\t"
"movq %%mm2, %%mm5\n\t"
"punpcklwd %5, %%mm0\n\t"
"punpcklwd %5, %%mm1\n\t"
"punpcklwd %5, %%mm2\n\t"
"punpckhwd %5, %%mm3\n\t"
"punpckhwd %5, %%mm4\n\t"
"punpckhwd %5, %%mm5\n\t"
"psllq $8, %%mm1\n\t"
"psllq $16, %%mm2\n\t"
"por %%mm1, %%mm0\n\t"
"por %%mm2, %%mm0\n\t"
"psllq $8, %%mm4\n\t"
"psllq $16, %%mm5\n\t"
"por %%mm4, %%mm3\n\t"
"por %%mm5, %%mm3\n\t"
"movq %%mm0, %%mm6\n\t"
"movq %%mm3, %%mm7\n\t"
"movq 8%1, %%mm0\n\t"
"movq 8%1, %%mm1\n\t"
"movq 8%1, %%mm2\n\t"
"pand %2, %%mm0\n\t"
"pand %3, %%mm1\n\t"
"pand %4, %%mm2\n\t"
"psllq $3, %%mm0\n\t"
"psrlq $3, %%mm1\n\t"
"psrlq $8, %%mm2\n\t"
"movq %%mm0, %%mm3\n\t"
"movq %%mm1, %%mm4\n\t"
"movq %%mm2, %%mm5\n\t"
"punpcklwd %5, %%mm0\n\t"
"punpcklwd %5, %%mm1\n\t"
"punpcklwd %5, %%mm2\n\t"
"punpckhwd %5, %%mm3\n\t"
"punpckhwd %5, %%mm4\n\t"
"punpckhwd %5, %%mm5\n\t"
"psllq $8, %%mm1\n\t"
"psllq $16, %%mm2\n\t"
"por %%mm1, %%mm0\n\t"
"por %%mm2, %%mm0\n\t"
"psllq $8, %%mm4\n\t"
"psllq $16, %%mm5\n\t"
"por %%mm4, %%mm3\n\t"
"por %%mm5, %%mm3\n\t"
:"=m"(*d)
:"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null)
:"memory");
/* Borrowed 32 to 24 */
__asm __volatile(
"movq %%mm0, %%mm4\n\t"
"movq %%mm3, %%mm5\n\t"
"movq %%mm6, %%mm0\n\t"
"movq %%mm7, %%mm1\n\t"
"movq %%mm4, %%mm6\n\t"
"movq %%mm5, %%mm7\n\t"
"movq %%mm0, %%mm2\n\t"
"movq %%mm1, %%mm3\n\t"
"psrlq $8, %%mm2\n\t"
"psrlq $8, %%mm3\n\t"
"psrlq $8, %%mm6\n\t"
"psrlq $8, %%mm7\n\t"
"pand %2, %%mm0\n\t"
"pand %2, %%mm1\n\t"
"pand %2, %%mm4\n\t"
"pand %2, %%mm5\n\t"
"pand %3, %%mm2\n\t"
"pand %3, %%mm3\n\t"
"pand %3, %%mm6\n\t"
"pand %3, %%mm7\n\t"
"por %%mm2, %%mm0\n\t"
"por %%mm3, %%mm1\n\t"
"por %%mm6, %%mm4\n\t"
"por %%mm7, %%mm5\n\t"
"movq %%mm1, %%mm2\n\t"
"movq %%mm4, %%mm3\n\t"
"psllq $48, %%mm2\n\t"
"psllq $32, %%mm3\n\t"
"pand %4, %%mm2\n\t"
"pand %5, %%mm3\n\t"
"por %%mm2, %%mm0\n\t"
"psrlq $16, %%mm1\n\t"
"psrlq $32, %%mm4\n\t"
"psllq $16, %%mm5\n\t"
"por %%mm3, %%mm1\n\t"
"pand %6, %%mm5\n\t"
"por %%mm5, %%mm4\n\t"
MOVNTQ" %%mm0, %0\n\t"
MOVNTQ" %%mm1, 8%0\n\t"
MOVNTQ" %%mm4, 16%0"
:"=m"(*d)
:"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh)
:"memory");
d += 24;
s += 8;
}
__asm __volatile(SFENCE:::"memory");
__asm __volatile(EMMS:::"memory");
#endif
while(s < end)
{
register uint16_t bgr;
bgr = *s++;
*d++ = (bgr&0x1F)<<3;
*d++ = (bgr&0x7E0)>>3;
*d++ = (bgr&0xF800)>>8;
}
}
| true | FFmpeg | 7f526efd17973ec6d2204f7a47b6923e2be31363 |
5,865 | static void gen_tlbsx_40x(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
#else
TCGv t0;
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
return;
}
t0 = tcg_temp_new();
gen_addr_reg_index(ctx, t0);
gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
tcg_temp_free(t0);
if (Rc(ctx->opcode)) {
TCGLabel *l1 = gen_new_label();
tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
gen_set_label(l1);
}
#endif
}
| true | qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 |
5,866 | static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
AVStream *stream,
PayloadContext *h264_data,
const char *attr, const char *value)
{
AVCodecParameters *par = stream->codecpar;
if (!strcmp(attr, "packetization-mode")) {
av_log(s, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));
h264_data->packetization_mode = atoi(value);
/*
* Packetization Mode:
* 0 or not present: Single NAL mode (Only nals from 1-23 are allowed)
* 1: Non-interleaved Mode: 1-23, 24 (STAP-A), 28 (FU-A) are allowed.
* 2: Interleaved Mode: 25 (STAP-B), 26 (MTAP16), 27 (MTAP24), 28 (FU-A),
* and 29 (FU-B) are allowed.
*/
if (h264_data->packetization_mode > 1)
av_log(s, AV_LOG_ERROR,
"Interleaved RTP mode is not supported yet.\n");
} else if (!strcmp(attr, "profile-level-id")) {
if (strlen(value) == 6)
parse_profile_level_id(s, h264_data, value);
} else if (!strcmp(attr, "sprop-parameter-sets")) {
int ret;
if (value[strlen(value) - 1] == ',') {
av_log(s, AV_LOG_WARNING, "Missing PPS in sprop-parameter-sets, ignoring\n");
return 0;
}
par->extradata_size = 0;
av_freep(&par->extradata);
ret = ff_h264_parse_sprop_parameter_sets(s, &par->extradata,
&par->extradata_size, value);
av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n",
par->extradata, par->extradata_size);
return ret;
}
return 0;
}
| true | FFmpeg | c42a1388a6d1bfd8001bf6a4241d8ca27e49326d |
5,868 | int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
{
if ( s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold
&& s->slice_context_count == 1
&& s->pb.buf == s->avctx->internal->byte_buffer) {
int lastgob_pos = s->ptr_lastgob - s->pb.buf;
int vbv_pos = s->vbv_delay_ptr - s->pb.buf;
uint8_t *new_buffer = NULL;
int new_buffer_size = 0;
av_fast_padded_malloc(&new_buffer, &new_buffer_size,
s->avctx->internal->byte_buffer_size + size_increase);
if (!new_buffer)
memcpy(new_buffer, s->avctx->internal->byte_buffer, s->avctx->internal->byte_buffer_size);
av_free(s->avctx->internal->byte_buffer);
s->avctx->internal->byte_buffer = new_buffer;
s->avctx->internal->byte_buffer_size = new_buffer_size;
rebase_put_bits(&s->pb, new_buffer, new_buffer_size);
s->ptr_lastgob = s->pb.buf + lastgob_pos;
s->vbv_delay_ptr = s->pb.buf + vbv_pos;
if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < threshold)
return AVERROR(EINVAL);
return 0; | true | FFmpeg | b65efbc0f4195421c15d2a6c228d331eec5b31c3 |
5,870 | int64_t object_property_get_int(Object *obj, const char *name,
Error **errp)
{
QObject *ret = object_property_get_qobject(obj, name, errp);
QInt *qint;
int64_t retval;
if (!ret) {
return -1;
}
qint = qobject_to_qint(ret);
if (!qint) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int");
retval = -1;
} else {
retval = qint_get_int(qint);
}
QDECREF(qint);
return retval;
}
| true | qemu | 560f19f162529d691619ac69ed032321c7f5f1fb |
5,871 | void av_get_channel_layout_string(char *buf, int buf_size,
int nb_channels, uint64_t channel_layout)
{
int i;
if (nb_channels <= 0)
nb_channels = av_get_channel_layout_nb_channels(channel_layout);
for (i = 0; channel_layout_map[i].name; i++)
if (nb_channels == channel_layout_map[i].nb_channels &&
channel_layout == channel_layout_map[i].layout) {
av_strlcpy(buf, channel_layout_map[i].name, buf_size);
return;
}
snprintf(buf, buf_size, "%d channels", nb_channels);
if (channel_layout) {
int i, ch;
av_strlcat(buf, " (", buf_size);
for (i = 0, ch = 0; i < 64; i++) {
if ((channel_layout & (1L << i))) {
const char *name = get_channel_name(i);
if (name) {
if (ch > 0)
av_strlcat(buf, "|", buf_size);
av_strlcat(buf, name, buf_size);
}
ch++;
}
}
av_strlcat(buf, ")", buf_size);
}
}
| true | FFmpeg | 019dd2365729d44d66a5b629102e1ecb919f4f67 |
5,872 | int qemu_read_password(char *buf, int buf_size)
{
uint8_t ch;
int i, ret;
printf("password: ");
fflush(stdout);
term_init();
i = 0;
for (;;) {
ret = read(0, &ch, 1);
if (ret == -1) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
}
} else if (ret == 0) {
ret = -1;
break;
} else {
if (ch == '\r' ||
ch == '\n') {
ret = 0;
break;
}
if (i < (buf_size - 1)) {
buf[i++] = ch;
}
}
}
term_exit();
buf[i] = '\0';
printf("\n");
return ret;
}
| true | qemu | 788cf9f8c8cbda53843e060540f3e91a060eb744 |
5,873 | static void smbios_build_type_1_fields(const char *t)
{
char buf[1024];
if (get_param_value(buf, sizeof(buf), "manufacturer", t))
smbios_add_field(1, offsetof(struct smbios_type_1, manufacturer_str),
strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "product", t))
smbios_add_field(1, offsetof(struct smbios_type_1, product_name_str),
strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "version", t))
smbios_add_field(1, offsetof(struct smbios_type_1, version_str),
strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "serial", t))
smbios_add_field(1, offsetof(struct smbios_type_1, serial_number_str),
strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "uuid", t)) {
if (qemu_uuid_parse(buf, qemu_uuid) != 0) {
fprintf(stderr, "Invalid SMBIOS UUID string\n");
exit(1);
}
}
if (get_param_value(buf, sizeof(buf), "sku", t))
smbios_add_field(1, offsetof(struct smbios_type_1, sku_number_str),
strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "family", t))
smbios_add_field(1, offsetof(struct smbios_type_1, family_str),
strlen(buf) + 1, buf);
}
| false | qemu | 5bb95e41868b461f37159efb48908828ebd7ab36 |
5,876 | int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
uint16_t stctl;
IRB irb;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
return 3;
}
stctl = s->ctrl & SCSW_CTRL_MASK_STCTL;
/* Prepare the irb for the guest. */
memset(&irb, 0, sizeof(IRB));
/* Copy scsw from current status. */
memcpy(&irb.scsw, s, sizeof(SCSW));
if (stctl & SCSW_STCTL_STATUS_PEND) {
if (s->cstat & (SCSW_CSTAT_DATA_CHECK |
SCSW_CSTAT_CHN_CTRL_CHK |
SCSW_CSTAT_INTF_CTRL_CHK)) {
irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF;
irb.esw[0] = 0x04804000;
} else {
irb.esw[0] = 0x00800000;
}
/* If a unit check is pending, copy sense data. */
if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) &&
(p->chars & PMCW_CHARS_MASK_CSENSE)) {
int i;
irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF | SCSW_FLAGS_MASK_ECTL;
/* Attention: sense_data is already BE! */
memcpy(irb.ecw, sch->sense_data, sizeof(sch->sense_data));
for (i = 0; i < ARRAY_SIZE(irb.ecw); i++) {
irb.ecw[i] = be32_to_cpu(irb.ecw[i]);
}
irb.esw[1] = 0x01000000 | (sizeof(sch->sense_data) << 8);
}
}
/* Store the irb to the guest. */
copy_irb_to_guest(target_irb, &irb, p, irb_len);
return ((stctl & SCSW_STCTL_STATUS_PEND) == 0);
}
| false | qemu | c679e74d2e29fa08ede9121d59aee4e9675611d7 |
5,877 | void helper_ldq_kernel(uint64_t t0, uint64_t t1)
{
ldq_kernel(t1, t0);
}
| false | qemu | 2374e73edafff0586cbfb67c333c5a7588f81fd5 |
5,878 | static void lm32_uclinux_init(MachineState *machine)
{
const char *cpu_model = machine->cpu_model;
const char *kernel_filename = machine->kernel_filename;
const char *kernel_cmdline = machine->kernel_cmdline;
const char *initrd_filename = machine->initrd_filename;
LM32CPU *cpu;
CPULM32State *env;
DriveInfo *dinfo;
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
qemu_irq *cpu_irq, irq[32];
HWSetup *hw;
ResetInfo *reset_info;
int i;
/* memory map */
hwaddr flash_base = 0x04000000;
size_t flash_sector_size = 256 * 1024;
size_t flash_size = 32 * 1024 * 1024;
hwaddr ram_base = 0x08000000;
size_t ram_size = 64 * 1024 * 1024;
hwaddr uart0_base = 0x80000000;
hwaddr timer0_base = 0x80002000;
hwaddr timer1_base = 0x80010000;
hwaddr timer2_base = 0x80012000;
int uart0_irq = 0;
int timer0_irq = 1;
int timer1_irq = 20;
int timer2_irq = 21;
hwaddr hwsetup_base = 0x0bffe000;
hwaddr cmdline_base = 0x0bfff000;
hwaddr initrd_base = 0x08400000;
size_t initrd_max = 0x01000000;
reset_info = g_malloc0(sizeof(ResetInfo));
if (cpu_model == NULL) {
cpu_model = "lm32-full";
}
cpu = cpu_lm32_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "qemu: unable to find CPU '%s'\n", cpu_model);
exit(1);
}
env = &cpu->env;
reset_info->cpu = cpu;
reset_info->flash_base = flash_base;
memory_region_init_ram(phys_ram, NULL, "lm32_uclinux.sdram", ram_size,
&error_abort);
vmstate_register_ram_global(phys_ram);
memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
dinfo = drive_get(IF_PFLASH, 0, 0);
/* Spansion S29NS128P */
pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
flash_sector_size, flash_size / flash_sector_size,
1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
/* create irq lines */
cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
env->pic_state = lm32_pic_init(*cpu_irq);
for (i = 0; i < 32; i++) {
irq[i] = qdev_get_gpio_in(env->pic_state, i);
}
sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
/* make sure juart isn't the first chardev */
env->juart_state = lm32_juart_init();
reset_info->bootstrap_pc = flash_base;
if (kernel_filename) {
uint64_t entry;
int kernel_size;
kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
1, ELF_MACHINE, 0);
reset_info->bootstrap_pc = entry;
if (kernel_size < 0) {
kernel_size = load_image_targphys(kernel_filename, ram_base,
ram_size);
reset_info->bootstrap_pc = ram_base;
}
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
kernel_filename);
exit(1);
}
}
/* generate a rom with the hardware description */
hw = hwsetup_init();
hwsetup_add_cpu(hw, "LM32", 75000000);
hwsetup_add_flash(hw, "flash", flash_base, flash_size);
hwsetup_add_ddr_sdram(hw, "ddr_sdram", ram_base, ram_size);
hwsetup_add_timer(hw, "timer0", timer0_base, timer0_irq);
hwsetup_add_timer(hw, "timer1_dev_only", timer1_base, timer1_irq);
hwsetup_add_timer(hw, "timer2_dev_only", timer2_base, timer2_irq);
hwsetup_add_uart(hw, "uart", uart0_base, uart0_irq);
hwsetup_add_trailer(hw);
hwsetup_create_rom(hw, hwsetup_base);
hwsetup_free(hw);
reset_info->hwsetup_base = hwsetup_base;
if (kernel_cmdline && strlen(kernel_cmdline)) {
pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
kernel_cmdline);
reset_info->cmdline_base = cmdline_base;
}
if (initrd_filename) {
size_t initrd_size;
initrd_size = load_image_targphys(initrd_filename, initrd_base,
initrd_max);
reset_info->initrd_base = initrd_base;
reset_info->initrd_size = initrd_size;
}
qemu_register_reset(main_cpu_reset, reset_info);
}
| false | qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce |
5,879 | static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, int size_min,
int (*transfer_func)(URLContext *h, unsigned char *buf, int size))
{
int ret, len;
int fast_retries = 5;
int64_t wait_since = 0;
len = 0;
while (len < size_min) {
ret = transfer_func(h, buf+len, size-len);
if (ret == AVERROR(EINTR))
continue;
if (h->flags & AVIO_FLAG_NONBLOCK)
return ret;
if (ret == AVERROR(EAGAIN)) {
ret = 0;
if (fast_retries) {
fast_retries--;
} else {
if (h->rw_timeout) {
if (!wait_since)
wait_since = av_gettime();
else if (av_gettime() > wait_since + h->rw_timeout)
return AVERROR(EIO);
}
av_usleep(1000);
}
} else if (ret < 1)
return (ret < 0 && ret != AVERROR_EOF) ? ret : len;
if (ret)
fast_retries = FFMAX(fast_retries, 2);
len += ret;
if (len < size && ff_check_interrupt(&h->interrupt_callback))
return AVERROR_EXIT;
}
return len;
}
| false | FFmpeg | 34fd21120d8672357293cb83d8c9b770850db516 |
5,881 | static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
{
VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
DeviceState *qdev = DEVICE(ccw_dev);
Error *err = NULL;
char *bus_name;
/*
* For command line compatibility, this sets the virtio-scsi-device bus
* name as before.
*/
if (qdev->id) {
bus_name = g_strdup_printf("%s.0", qdev->id);
virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
g_free(bus_name);
}
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
if (err) {
error_propagate(errp, err);
}
}
| false | qemu | 621ff94d5074d88253a5818c6b9c4db718fbfc65 |
5,882 | static void mpc8544_guts_write(void *opaque, target_phys_addr_t addr,
uint64_t value, unsigned size)
{
addr &= MPC8544_GUTS_MMIO_SIZE - 1;
switch (addr) {
case MPC8544_GUTS_ADDR_RSTCR:
if (value & MPC8544_GUTS_RSTCR_RESET) {
qemu_system_reset_request();
}
break;
default:
fprintf(stderr, "guts: Unknown register write: %x = %x\n",
(int)addr, (unsigned)value);
break;
}
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c |
5,883 | static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
{
return s->ops->chown(&s->ctx, path->data, uid, gid);
}
| false | qemu | f7613bee32ebd13ff4a8d721a59cf27b1fe5d94b |
5,884 | static int check_host_key_knownhosts(BDRVSSHState *s,
const char *host, int port)
{
const char *home;
char *knh_file = NULL;
LIBSSH2_KNOWNHOSTS *knh = NULL;
struct libssh2_knownhost *found;
int ret, r;
const char *hostkey;
size_t len;
int type;
hostkey = libssh2_session_hostkey(s->session, &len, &type);
if (!hostkey) {
ret = -EINVAL;
session_error_report(s, "failed to read remote host key");
goto out;
}
knh = libssh2_knownhost_init(s->session);
if (!knh) {
ret = -EINVAL;
session_error_report(s, "failed to initialize known hosts support");
goto out;
}
home = getenv("HOME");
if (home) {
knh_file = g_strdup_printf("%s/.ssh/known_hosts", home);
} else {
knh_file = g_strdup_printf("/root/.ssh/known_hosts");
}
/* Read all known hosts from OpenSSH-style known_hosts file. */
libssh2_knownhost_readfile(knh, knh_file, LIBSSH2_KNOWNHOST_FILE_OPENSSH);
r = libssh2_knownhost_checkp(knh, host, port, hostkey, len,
LIBSSH2_KNOWNHOST_TYPE_PLAIN|
LIBSSH2_KNOWNHOST_KEYENC_RAW,
&found);
switch (r) {
case LIBSSH2_KNOWNHOST_CHECK_MATCH:
/* OK */
DPRINTF("host key OK: %s", found->key);
break;
case LIBSSH2_KNOWNHOST_CHECK_MISMATCH:
ret = -EINVAL;
session_error_report(s, "host key does not match the one in known_hosts (found key %s)",
found->key);
goto out;
case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND:
ret = -EINVAL;
session_error_report(s, "no host key was found in known_hosts");
goto out;
case LIBSSH2_KNOWNHOST_CHECK_FAILURE:
ret = -EINVAL;
session_error_report(s, "failure matching the host key with known_hosts");
goto out;
default:
ret = -EINVAL;
session_error_report(s, "unknown error matching the host key with known_hosts (%d)",
r);
goto out;
}
/* known_hosts checking successful. */
ret = 0;
out:
if (knh != NULL) {
libssh2_knownhost_free(knh);
}
g_free(knh_file);
return ret;
}
| false | qemu | 01c2b265fce921d6460e06f5af4dfb405119cbab |
5,885 | static void numa_add(const char *optarg)
{
char option[128];
char *endptr;
unsigned long long value, endvalue;
int nodenr;
optarg = get_opt_name(option, 128, optarg, ',') + 1;
if (!strcmp(option, "node")) {
if (get_param_value(option, 128, "nodeid", optarg) == 0) {
nodenr = nb_numa_nodes;
} else {
nodenr = strtoull(option, NULL, 10);
}
if (get_param_value(option, 128, "mem", optarg) == 0) {
node_mem[nodenr] = 0;
} else {
int64_t sval;
sval = strtosz(option, &endptr);
if (sval < 0 || *endptr) {
fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
exit(1);
}
node_mem[nodenr] = sval;
}
if (get_param_value(option, 128, "cpus", optarg) == 0) {
node_cpumask[nodenr] = 0;
} else {
value = strtoull(option, &endptr, 10);
if (value >= 64) {
value = 63;
fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
} else {
if (*endptr == '-') {
endvalue = strtoull(endptr+1, &endptr, 10);
if (endvalue >= 63) {
endvalue = 62;
fprintf(stderr,
"only 63 CPUs in NUMA mode supported.\n");
}
value = (2ULL << endvalue) - (1ULL << value);
} else {
value = 1ULL << value;
}
}
node_cpumask[nodenr] = value;
}
nb_numa_nodes++;
}
return;
}
| false | qemu | ee785fed5dd035d4b12142cacec6d3c344426dec |
5,886 | static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state)
{
sPAPRDRConnector *drc = spapr_drc_by_index(idx);
if (!drc) {
return RTAS_OUT_PARAM_ERROR;
}
trace_spapr_drc_set_dr_indicator(idx, state);
drc->dr_indicator = state;
return RTAS_OUT_SUCCESS;
}
| false | qemu | 67fea71bf3be579ad0be5abe34cd6fa1bc65ad5b |
5,888 | static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
{
/* We have to ignore passthrough devices */
if (!strcmp(d->name, "xen-pci-passthrough")) {
return;
}
switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) {
case PCI_CLASS_STORAGE_IDE:
pci_piix3_xen_ide_unplug(DEVICE(d));
break;
case PCI_CLASS_STORAGE_SCSI:
case PCI_CLASS_STORAGE_EXPRESS:
object_unparent(OBJECT(d));
break;
default:
break;
}
}
| false | qemu | ae4d2eb273b167dad748ea4249720319240b1ac2 |
5,889 | static void monitor_start_input(void)
{
readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
}
| false | qemu | 396f929762d10ba2c7b38f7e8a2276dd066be2d7 |
5,890 | MKSCALE16(scale16be, AV_RB16, AV_WB16)
MKSCALE16(scale16le, AV_RL16, AV_WL16)
static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
const AVPixFmtDescriptor *desc;
RawVideoContext *context = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int linesize_align = 4;
int stride;
int res, len;
int need_copy;
AVFrame *frame = data;
if (avctx->width <= 0) {
av_log(avctx, AV_LOG_ERROR, "width is not set\n");
return AVERROR_INVALIDDATA;
}
if (avctx->height <= 0) {
av_log(avctx, AV_LOG_ERROR, "height is not set\n");
return AVERROR_INVALIDDATA;
}
if (context->is_nut_mono)
stride = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
else if (context->is_nut_pal8)
stride = avctx->width;
else
stride = avpkt->size / avctx->height;
av_log(avctx, AV_LOG_DEBUG, "PACKET SIZE: %d, STRIDE: %d\n", avpkt->size, stride);
if (stride == 0 || avpkt->size < stride * avctx->height) {
av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
return AVERROR_INVALIDDATA;
}
desc = av_pix_fmt_desc_get(avctx->pix_fmt);
if ((avctx->bits_per_coded_sample == 8 || avctx->bits_per_coded_sample == 4 ||
avctx->bits_per_coded_sample == 2 || avctx->bits_per_coded_sample == 1 ||
(avctx->bits_per_coded_sample == 0 && (context->is_nut_pal8 || context->is_mono)) ) &&
(context->is_mono || context->is_pal8) &&
(!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' ') ||
context->is_nut_mono || context->is_nut_pal8)) {
context->is_1_2_4_8_bpp = 1;
if (context->is_mono) {
int row_bytes = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
FFALIGN(row_bytes, 16) * 8,
avctx->height, 1);
} else
context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
FFALIGN(avctx->width, 16),
avctx->height, 1);
} else {
context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16;
context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width,
avctx->height, 1);
}
if (context->frame_size < 0)
return context->frame_size;
need_copy = !avpkt->buf || context->is_1_2_4_8_bpp || context->is_yuv2 || context->is_lt_16bpp;
frame->pict_type = AV_PICTURE_TYPE_I;
frame->key_frame = 1;
res = ff_decode_frame_props(avctx, frame);
if (res < 0)
return res;
av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos);
av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration);
if (context->tff >= 0) {
frame->interlaced_frame = 1;
frame->top_field_first = context->tff;
}
if ((res = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
return res;
if (need_copy)
frame->buf[0] = av_buffer_alloc(FFMAX(context->frame_size, buf_size));
else
frame->buf[0] = av_buffer_ref(avpkt->buf);
if (!frame->buf[0])
return AVERROR(ENOMEM);
// 1, 2, 4 and 8 bpp in avi/mov, 1 and 8 bpp in nut
if (context->is_1_2_4_8_bpp) {
int i, j, row_pix = 0;
uint8_t *dst = frame->buf[0]->data;
buf_size = context->frame_size - (context->is_pal8 ? AVPALETTE_SIZE : 0);
if (avctx->bits_per_coded_sample == 8 || context->is_nut_pal8 || context->is_mono) {
int pix_per_byte = context->is_mono ? 8 : 1;
for (i = 0, j = 0; j < buf_size && i<avpkt->size; i++, j++) {
dst[j] = buf[i];
row_pix += pix_per_byte;
if (row_pix >= avctx->width) {
i += stride - (i % stride) - 1;
j += 16 - (j % 16) - 1;
row_pix = 0;
}
}
} else if (avctx->bits_per_coded_sample == 4) {
for (i = 0, j = 0; 2 * j + 1 < buf_size && i<avpkt->size; i++, j++) {
dst[2 * j + 0] = buf[i] >> 4;
dst[2 * j + 1] = buf[i] & 15;
row_pix += 2;
if (row_pix >= avctx->width) {
i += stride - (i % stride) - 1;
j += 8 - (j % 8) - 1;
row_pix = 0;
}
}
} else if (avctx->bits_per_coded_sample == 2) {
for (i = 0, j = 0; 4 * j + 3 < buf_size && i<avpkt->size; i++, j++) {
dst[4 * j + 0] = buf[i] >> 6;
dst[4 * j + 1] = buf[i] >> 4 & 3;
dst[4 * j + 2] = buf[i] >> 2 & 3;
dst[4 * j + 3] = buf[i] & 3;
row_pix += 4;
if (row_pix >= avctx->width) {
i += stride - (i % stride) - 1;
j += 4 - (j % 4) - 1;
row_pix = 0;
}
}
} else {
av_assert0(avctx->bits_per_coded_sample == 1);
for (i = 0, j = 0; 8 * j + 7 < buf_size && i<avpkt->size; i++, j++) {
dst[8 * j + 0] = buf[i] >> 7;
dst[8 * j + 1] = buf[i] >> 6 & 1;
dst[8 * j + 2] = buf[i] >> 5 & 1;
dst[8 * j + 3] = buf[i] >> 4 & 1;
dst[8 * j + 4] = buf[i] >> 3 & 1;
dst[8 * j + 5] = buf[i] >> 2 & 1;
dst[8 * j + 6] = buf[i] >> 1 & 1;
dst[8 * j + 7] = buf[i] & 1;
row_pix += 8;
if (row_pix >= avctx->width) {
i += stride - (i % stride) - 1;
j += 2 - (j % 2) - 1;
row_pix = 0;
}
}
}
linesize_align = 16;
buf = dst;
} else if (context->is_lt_16bpp) {
uint8_t *dst = frame->buf[0]->data;
int packed = (avctx->codec_tag & 0xFFFFFF) == MKTAG('B','I','T', 0);
int swap = avctx->codec_tag >> 24;
if (packed && swap) {
av_fast_padded_malloc(&context->bitstream_buf, &context->bitstream_buf_size, buf_size);
if (!context->bitstream_buf)
return AVERROR(ENOMEM);
if (swap == 16)
context->bbdsp.bswap16_buf(context->bitstream_buf, (const uint16_t*)buf, buf_size / 2);
else if (swap == 32)
context->bbdsp.bswap_buf(context->bitstream_buf, (const uint32_t*)buf, buf_size / 4);
else
return AVERROR_INVALIDDATA;
buf = context->bitstream_buf;
}
if (desc->flags & AV_PIX_FMT_FLAG_BE)
scale16be(avctx, dst, buf, buf_size, packed);
else
scale16le(avctx, dst, buf, buf_size, packed);
buf = dst;
} else if (need_copy) {
memcpy(frame->buf[0]->data, buf, buf_size);
buf = frame->buf[0]->data;
}
if (avctx->codec_tag == MKTAG('A', 'V', '1', 'x') ||
avctx->codec_tag == MKTAG('A', 'V', 'u', 'p'))
buf += buf_size - context->frame_size;
len = context->frame_size - (avctx->pix_fmt==AV_PIX_FMT_PAL8 ? AVPALETTE_SIZE : 0);
if (buf_size < len && ((avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0) || !need_copy)) {
av_log(avctx, AV_LOG_ERROR, "Invalid buffer size, packet size %d < expected frame_size %d\n", buf_size, len);
av_buffer_unref(&frame->buf[0]);
return AVERROR(EINVAL);
}
if ((res = av_image_fill_arrays(frame->data, frame->linesize,
buf, avctx->pix_fmt,
avctx->width, avctx->height, 1)) < 0) {
av_buffer_unref(&frame->buf[0]);
return res;
}
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE,
NULL);
int ret;
if (!context->palette)
context->palette = av_buffer_alloc(AVPALETTE_SIZE);
if (!context->palette) {
av_buffer_unref(&frame->buf[0]);
return AVERROR(ENOMEM);
}
ret = av_buffer_make_writable(&context->palette);
if (ret < 0) {
av_buffer_unref(&frame->buf[0]);
return ret;
}
if (pal) {
memcpy(context->palette->data, pal, AVPALETTE_SIZE);
frame->palette_has_changed = 1;
} else if (context->is_nut_pal8) {
int vid_size = avctx->width * avctx->height;
int pal_size = avpkt->size - vid_size;
if (avpkt->size > vid_size && pal_size <= AVPALETTE_SIZE) {
pal = avpkt->data + vid_size;
memcpy(context->palette->data, pal, pal_size);
frame->palette_has_changed = 1;
}
}
}
if ((avctx->pix_fmt==AV_PIX_FMT_RGB24 ||
avctx->pix_fmt==AV_PIX_FMT_BGR24 ||
avctx->pix_fmt==AV_PIX_FMT_GRAY8 ||
avctx->pix_fmt==AV_PIX_FMT_RGB555LE ||
avctx->pix_fmt==AV_PIX_FMT_RGB555BE ||
avctx->pix_fmt==AV_PIX_FMT_RGB565LE ||
avctx->pix_fmt==AV_PIX_FMT_MONOWHITE ||
avctx->pix_fmt==AV_PIX_FMT_MONOBLACK ||
avctx->pix_fmt==AV_PIX_FMT_PAL8) &&
FFALIGN(frame->linesize[0], linesize_align) * avctx->height <= buf_size)
frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align);
if (avctx->pix_fmt == AV_PIX_FMT_NV12 && avctx->codec_tag == MKTAG('N', 'V', '1', '2') &&
FFALIGN(frame->linesize[0], linesize_align) * avctx->height +
FFALIGN(frame->linesize[1], linesize_align) * ((avctx->height + 1) / 2) <= buf_size) {
int la0 = FFALIGN(frame->linesize[0], linesize_align);
frame->data[1] += (la0 - frame->linesize[0]) * avctx->height;
frame->linesize[0] = la0;
frame->linesize[1] = FFALIGN(frame->linesize[1], linesize_align);
}
if ((avctx->pix_fmt == AV_PIX_FMT_PAL8 && buf_size < context->frame_size) ||
(desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)) {
frame->buf[1] = av_buffer_ref(context->palette);
if (!frame->buf[1]) {
av_buffer_unref(&frame->buf[0]);
return AVERROR(ENOMEM);
}
frame->data[1] = frame->buf[1]->data;
}
if (avctx->pix_fmt == AV_PIX_FMT_BGR24 &&
((frame->linesize[0] + 3) & ~3) * avctx->height <= buf_size)
frame->linesize[0] = (frame->linesize[0] + 3) & ~3;
if (context->flip)
flip(avctx, frame);
if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2') ||
avctx->codec_tag == MKTAG('Y', 'V', '1', '6') ||
avctx->codec_tag == MKTAG('Y', 'V', '2', '4') ||
avctx->codec_tag == MKTAG('Y', 'V', 'U', '9'))
FFSWAP(uint8_t *, frame->data[1], frame->data[2]);
if (avctx->codec_tag == AV_RL32("I420") && (avctx->width+1)*(avctx->height+1) * 3/2 == buf_size) {
frame->data[1] = frame->data[1] + (avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height;
frame->data[2] = frame->data[2] + ((avctx->width+1)*(avctx->height+1) -avctx->width*avctx->height)*5/4;
}
if (avctx->codec_tag == AV_RL32("yuv2") &&
avctx->pix_fmt == AV_PIX_FMT_YUYV422) {
int x, y;
uint8_t *line = frame->data[0];
for (y = 0; y < avctx->height; y++) {
for (x = 0; x < avctx->width; x++)
line[2 * x + 1] ^= 0x80;
line += frame->linesize[0];
}
}
if (avctx->codec_tag == AV_RL32("b64a") &&
avctx->pix_fmt == AV_PIX_FMT_RGBA64BE) {
uint8_t *dst = frame->data[0];
uint64_t v;
int x;
for (x = 0; x >> 3 < avctx->width * avctx->height; x += 8) {
v = AV_RB64(&dst[x]);
AV_WB64(&dst[x], v << 16 | v >> 48);
}
}
if (avctx->field_order > AV_FIELD_PROGRESSIVE) { /* we have interlaced material flagged in container */
frame->interlaced_frame = 1;
if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
frame->top_field_first = 1;
}
*got_frame = 1;
return buf_size;
}
| false | FFmpeg | 5f0bc0215a0f7099a2bcba5dced2e045e70fee61 |
5,891 | static void opt_qmin(const char *arg)
{
video_qmin = atoi(arg);
if (video_qmin < 0 ||
video_qmin > 31) {
fprintf(stderr, "qmin must be >= 1 and <= 31\n");
exit(1);
}
}
| false | FFmpeg | 6e0d8c06c7af61859e8d7bc2351a607d8abeab75 |
5,892 | void migrate_decompress_threads_join(void)
{
int i, thread_count;
quit_decomp_thread = true;
thread_count = migrate_decompress_threads();
for (i = 0; i < thread_count; i++) {
qemu_mutex_lock(&decomp_param[i].mutex);
qemu_cond_signal(&decomp_param[i].cond);
qemu_mutex_unlock(&decomp_param[i].mutex);
}
for (i = 0; i < thread_count; i++) {
qemu_thread_join(decompress_threads + i);
qemu_mutex_destroy(&decomp_param[i].mutex);
qemu_cond_destroy(&decomp_param[i].cond);
g_free(decomp_param[i].compbuf);
}
g_free(decompress_threads);
g_free(decomp_param);
decompress_threads = NULL;
decomp_param = NULL;
}
| false | qemu | 90e56fb46d0a7add88ed463efa4e723a6238f692 |
5,893 | ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
if (drv && drv->bdrv_get_specific_info) {
return drv->bdrv_get_specific_info(bs);
}
return NULL;
}
| false | qemu | 61007b316cd71ee7333ff7a0a749a8949527575f |
5,894 | do_gen_eob_worker(DisasContext *s, bool inhibit, bool recheck_tf, TCGv jr)
{
gen_update_cc_op(s);
/* If several instructions disable interrupts, only the first does it. */
if (inhibit && !(s->flags & HF_INHIBIT_IRQ_MASK)) {
gen_set_hflag(s, HF_INHIBIT_IRQ_MASK);
} else {
gen_reset_hflag(s, HF_INHIBIT_IRQ_MASK);
}
if (s->tb->flags & HF_RF_MASK) {
gen_helper_reset_rf(cpu_env);
}
if (s->singlestep_enabled) {
gen_helper_debug(cpu_env);
} else if (recheck_tf) {
gen_helper_rechecking_single_step(cpu_env);
tcg_gen_exit_tb(0);
} else if (s->tf) {
gen_helper_single_step(cpu_env);
} else if (!TCGV_IS_UNUSED(jr)) {
TCGv vaddr = tcg_temp_new();
tcg_gen_add_tl(vaddr, jr, cpu_seg_base[R_CS]);
tcg_gen_lookup_and_goto_ptr(vaddr);
tcg_temp_free(vaddr);
} else {
tcg_gen_exit_tb(0);
}
s->is_jmp = DISAS_TB_JUMP;
}
| false | qemu | 1e39d97af086d525cd0408eaa5d19783ea165906 |
5,895 | SocketAddressLegacy *socket_local_address(int fd, Error **errp)
{
struct sockaddr_storage ss;
socklen_t sslen = sizeof(ss);
if (getsockname(fd, (struct sockaddr *)&ss, &sslen) < 0) {
error_setg_errno(errp, errno, "%s",
"Unable to query local socket address");
return NULL;
}
return socket_sockaddr_to_address(&ss, sslen, errp);
}
| false | qemu | bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 |
5,896 | static void machine_numa_finish_init(MachineState *machine)
{
int i;
bool default_mapping;
GString *s = g_string_new(NULL);
MachineClass *mc = MACHINE_GET_CLASS(machine);
const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
assert(nb_numa_nodes);
for (i = 0; i < possible_cpus->len; i++) {
if (possible_cpus->cpus[i].props.has_node_id) {
break;
}
}
default_mapping = (i == possible_cpus->len);
for (i = 0; i < possible_cpus->len; i++) {
const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
if (!cpu_slot->props.has_node_id) {
if (default_mapping) {
/* fetch default mapping from board and enable it */
CpuInstanceProperties props = cpu_slot->props;
props.has_node_id = true;
machine_set_cpu_numa_node(machine, &props, &error_fatal);
} else {
/* record slots with not set mapping,
* TODO: make it hard error in future */
char *cpu_str = cpu_slot_to_string(cpu_slot);
g_string_append_printf(s, "%sCPU %d [%s]",
s->len ? ", " : "", i, cpu_str);
g_free(cpu_str);
}
}
}
if (s->len && !qtest_enabled()) {
error_report("warning: CPU(s) not present in any NUMA nodes: %s",
s->str);
error_report("warning: All CPU(s) up to maxcpus should be described "
"in NUMA config, ability to start up with partial NUMA "
"mappings is obsoleted and will be removed in future");
}
g_string_free(s, true);
}
| false | qemu | d41f3e750d2c06c613cb1b8db7724f0fbc0a2b14 |
5,897 | void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
Error **errp)
{
AioContext *aio_context;
BdrvDirtyBitmap *bitmap;
BlockDriverState *bs;
bitmap = block_dirty_bitmap_lookup(node, name, &bs, &aio_context, errp);
if (!bitmap || !bs) {
return;
}
if (bdrv_dirty_bitmap_frozen(bitmap)) {
error_setg(errp,
"Bitmap '%s' is currently frozen and cannot be modified",
name);
goto out;
} else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
error_setg(errp,
"Bitmap '%s' is currently disabled and cannot be cleared",
name);
goto out;
}
bdrv_clear_dirty_bitmap(bitmap, NULL);
out:
aio_context_release(aio_context);
}
| false | qemu | 2119882c7eb7e2c612b24fc0c8d86f5887d6f1c3 |
5,898 | FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
{
DeviceState *dev;
SysBusDevice *d;
FWCfgState *s;
dev = qdev_create(NULL, "fw_cfg");
qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port);
qdev_prop_set_uint32(dev, "data_iobase", data_port);
qdev_init_nofail(dev);
d = sysbus_from_qdev(dev);
s = DO_UPCAST(FWCfgState, busdev.qdev, dev);
if (ctl_addr) {
sysbus_mmio_map(d, 0, ctl_addr);
}
if (data_addr) {
sysbus_mmio_map(d, 1, data_addr);
}
fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
fw_cfg_bootsplash(s);
fw_cfg_reboot(s);
s->machine_ready.notify = fw_cfg_machine_ready;
qemu_add_machine_init_done_notifier(&s->machine_ready);
return s;
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c |
5,900 | static void boston_flash_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
}
| true | qemu | 2d896b454a0e19ec4c1ddbb0e0b65b7e54fcedf3 |
5,901 | static void revert_cdlms(WmallDecodeCtx *s, int ch,
int coef_begin, int coef_end)
{
int icoef, pred, ilms, num_lms, residue, input;
num_lms = s->cdlms_ttl[ch];
for (ilms = num_lms - 1; ilms >= 0; ilms--) {
for (icoef = coef_begin; icoef < coef_end; icoef++) {
pred = 1 << (s->cdlms[ch][ilms].scaling - 1);
residue = s->channel_residues[ch][icoef];
pred += s->dsp.scalarproduct_and_madd_int16(s->cdlms[ch][ilms].coefs,
s->cdlms[ch][ilms].lms_prevvalues
+ s->cdlms[ch][ilms].recent,
s->cdlms[ch][ilms].lms_updates
+ s->cdlms[ch][ilms].recent,
s->cdlms[ch][ilms].order,
WMASIGN(residue));
input = residue + (pred >> s->cdlms[ch][ilms].scaling);
lms_update(s, ch, ilms, input);
s->channel_residues[ch][icoef] = input;
}
}
} | true | FFmpeg | 49bf712a892901bd6a2e8815d085487180894d8c |
5,902 | static void utf8_string(void)
{
/*
* FIXME Current behavior for invalid UTF-8 sequences is
* incorrect. This test expects current, incorrect results.
* They're all marked "bug:" below, and are to be replaced by
* correct ones as the bugs get fixed.
*
* The JSON parser rejects some invalid sequences, but accepts
* others without correcting the problem.
*
* We should either reject all invalid sequences, or minimize
* overlong sequences and replace all other invalid sequences by a
* suitable replacement character. A common choice for
* replacement is U+FFFD.
*
* Problem: we can't easily deal with embedded U+0000. Parsing
* the JSON string "this \\u0000" is fun" yields "this \0 is fun",
* which gets misinterpreted as NUL-terminated "this ". We should
* consider using overlong encoding \xC0\x80 for U+0000 ("modified
* UTF-8").
*
* Most test cases are scraped from Markus Kuhn's UTF-8 decoder
* capability and stress test at
* http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
*/
static const struct {
const char *json_in;
const char *utf8_out;
const char *json_out; /* defaults to @json_in */
const char *utf8_in; /* defaults to @utf8_out */
} test_cases[] = {
/*
* Bug markers used here:
* - bug: not corrected
* JSON parser fails to correct invalid sequence(s)
* - bug: rejected
* JSON parser rejects invalid sequence(s)
* We may choose to define this as feature
* - bug: want "..."
* JSON parser produces incorrect result, this is the
* correct one, assuming replacement character U+FFFF
* We may choose to reject instead of replace
*/
/* 1 Some correct UTF-8 text */
{
/* a bit of German */
"\"Falsches \xC3\x9C" "ben von Xylophonmusik qu\xC3\xA4lt"
" jeden gr\xC3\xB6\xC3\x9F" "eren Zwerg.\"",
"Falsches \xC3\x9C" "ben von Xylophonmusik qu\xC3\xA4lt"
" jeden gr\xC3\xB6\xC3\x9F" "eren Zwerg.",
"\"Falsches \\u00DCben von Xylophonmusik qu\\u00E4lt"
" jeden gr\\u00F6\\u00DFeren Zwerg.\"",
},
{
/* a bit of Greek */
"\"\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5\"",
"\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5",
"\"\\u03BA\\u1F79\\u03C3\\u03BC\\u03B5\"",
},
/* 2 Boundary condition test cases */
/* 2.1 First possible sequence of a certain length */
/* 2.1.1 1 byte U+0000 */
{
"\"\\u0000\"",
"", /* bug: want overlong "\xC0\x80" */
"\"\\u0000\"",
"\xC0\x80",
},
/* 2.1.2 2 bytes U+0080 */
{
"\"\xC2\x80\"",
"\xC2\x80",
"\"\\u0080\"",
},
/* 2.1.3 3 bytes U+0800 */
{
"\"\xE0\xA0\x80\"",
"\xE0\xA0\x80",
"\"\\u0800\"",
},
/* 2.1.4 4 bytes U+10000 */
{
"\"\xF0\x90\x80\x80\"",
"\xF0\x90\x80\x80",
"\"\\uD800\\uDC00\"",
},
/* 2.1.5 5 bytes U+200000 */
{
"\"\xF8\x88\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF8\x88\x80\x80\x80",
},
/* 2.1.6 6 bytes U+4000000 */
{
"\"\xFC\x84\x80\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFC\x84\x80\x80\x80\x80",
},
/* 2.2 Last possible sequence of a certain length */
/* 2.2.1 1 byte U+007F */
{
"\"\x7F\"",
"\x7F",
"\"\\u007F\"",
},
/* 2.2.2 2 bytes U+07FF */
{
"\"\xDF\xBF\"",
"\xDF\xBF",
"\"\\u07FF\"",
},
/*
* 2.2.3 3 bytes U+FFFC
* The last possible sequence is actually U+FFFF. But that's
* a noncharacter, and already covered by its own test case
* under 5.3. Same for U+FFFE. U+FFFD is the last character
* in the BMP, and covered under 2.3. Because of U+FFFD's
* special role as replacement character, it's worth testing
* U+FFFC here.
*/
{
"\"\xEF\xBF\xBC\"",
"\xEF\xBF\xBC",
"\"\\uFFFC\"",
},
/* 2.2.4 4 bytes U+1FFFFF */
{
"\"\xF7\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF7\xBF\xBF\xBF",
},
/* 2.2.5 5 bytes U+3FFFFFF */
{
"\"\xFB\xBF\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFB\xBF\xBF\xBF\xBF",
},
/* 2.2.6 6 bytes U+7FFFFFFF */
{
"\"\xFD\xBF\xBF\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFD\xBF\xBF\xBF\xBF\xBF",
},
/* 2.3 Other boundary conditions */
{
/* last one before surrogate range: U+D7FF */
"\"\xED\x9F\xBF\"",
"\xED\x9F\xBF",
"\"\\uD7FF\"",
},
{
/* first one after surrogate range: U+E000 */
"\"\xEE\x80\x80\"",
"\xEE\x80\x80",
"\"\\uE000\"",
},
{
/* last one in BMP: U+FFFD */
"\"\xEF\xBF\xBD\"",
"\xEF\xBF\xBD",
"\"\\uFFFD\"",
},
{
/* last one in last plane: U+10FFFD */
"\"\xF4\x8F\xBF\xBD\"",
"\xF4\x8F\xBF\xBD",
"\"\\uDBFF\\uDFFD\""
},
{
/* first one beyond Unicode range: U+110000 */
"\"\xF4\x90\x80\x80\"",
"\xF4\x90\x80\x80",
"\"\\uFFFD\"",
},
/* 3 Malformed sequences */
/* 3.1 Unexpected continuation bytes */
/* 3.1.1 First continuation byte */
{
"\"\x80\"",
"\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.1.2 Last continuation byte */
{
"\"\xBF\"",
"\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.1.3 2 continuation bytes */
{
"\"\x80\xBF\"",
"\x80\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
/* 3.1.4 3 continuation bytes */
{
"\"\x80\xBF\x80\"",
"\x80\xBF\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\\uFFFD\"",
},
/* 3.1.5 4 continuation bytes */
{
"\"\x80\xBF\x80\xBF\"",
"\x80\xBF\x80\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
},
/* 3.1.6 5 continuation bytes */
{
"\"\x80\xBF\x80\xBF\x80\"",
"\x80\xBF\x80\xBF\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
},
/* 3.1.7 6 continuation bytes */
{
"\"\x80\xBF\x80\xBF\x80\xBF\"",
"\x80\xBF\x80\xBF\x80\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
},
/* 3.1.8 7 continuation bytes */
{
"\"\x80\xBF\x80\xBF\x80\xBF\x80\"",
"\x80\xBF\x80\xBF\x80\xBF\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
},
/* 3.1.9 Sequence of all 64 possible continuation bytes */
{
"\"\x80\x81\x82\x83\x84\x85\x86\x87"
"\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
"\x90\x91\x92\x93\x94\x95\x96\x97"
"\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
"\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7"
"\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
"\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7"
"\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\"",
/* bug: not corrected */
"\x80\x81\x82\x83\x84\x85\x86\x87"
"\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
"\x90\x91\x92\x93\x94\x95\x96\x97"
"\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
"\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7"
"\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
"\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7"
"\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF",
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\""
},
/* 3.2 Lonely start characters */
/* 3.2.1 All 32 first bytes of 2-byte sequences, followed by space */
{
"\"\xC0 \xC1 \xC2 \xC3 \xC4 \xC5 \xC6 \xC7 "
"\xC8 \xC9 \xCA \xCB \xCC \xCD \xCE \xCF "
"\xD0 \xD1 \xD2 \xD3 \xD4 \xD5 \xD6 \xD7 "
"\xD8 \xD9 \xDA \xDB \xDC \xDD \xDE \xDF \"",
NULL, /* bug: rejected */
"\"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \"",
"\xC0 \xC1 \xC2 \xC3 \xC4 \xC5 \xC6 \xC7 "
"\xC8 \xC9 \xCA \xCB \xCC \xCD \xCE \xCF "
"\xD0 \xD1 \xD2 \xD3 \xD4 \xD5 \xD6 \xD7 "
"\xD8 \xD9 \xDA \xDB \xDC \xDD \xDE \xDF ",
},
/* 3.2.2 All 16 first bytes of 3-byte sequences, followed by space */
{
"\"\xE0 \xE1 \xE2 \xE3 \xE4 \xE5 \xE6 \xE7 "
"\xE8 \xE9 \xEA \xEB \xEC \xED \xEE \xEF \"",
/* bug: not corrected */
"\xE0 \xE1 \xE2 \xE3 \xE4 \xE5 \xE6 \xE7 "
"\xE8 \xE9 \xEA \xEB \xEC \xED \xEE \xEF ",
"\"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \"",
},
/* 3.2.3 All 8 first bytes of 4-byte sequences, followed by space */
{
"\"\xF0 \xF1 \xF2 \xF3 \xF4 \xF5 \xF6 \xF7 \"",
NULL, /* bug: rejected */
"\"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \"",
"\xF0 \xF1 \xF2 \xF3 \xF4 \xF5 \xF6 \xF7 ",
},
/* 3.2.4 All 4 first bytes of 5-byte sequences, followed by space */
{
"\"\xF8 \xF9 \xFA \xFB \"",
NULL, /* bug: rejected */
"\"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \"",
"\xF8 \xF9 \xFA \xFB ",
},
/* 3.2.5 All 2 first bytes of 6-byte sequences, followed by space */
{
"\"\xFC \xFD \"",
NULL, /* bug: rejected */
"\"\\uFFFD \\uFFFD \"",
"\xFC \xFD ",
},
/* 3.3 Sequences with last continuation byte missing */
/* 3.3.1 2-byte sequence with last byte missing (U+0000) */
{
"\"\xC0\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xC0",
},
/* 3.3.2 3-byte sequence with last byte missing (U+0000) */
{
"\"\xE0\x80\"",
"\xE0\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.3.3 4-byte sequence with last byte missing (U+0000) */
{
"\"\xF0\x80\x80\"",
"\xF0\x80\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.3.4 5-byte sequence with last byte missing (U+0000) */
{
"\"\xF8\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF8\x80\x80\x80",
},
/* 3.3.5 6-byte sequence with last byte missing (U+0000) */
{
"\"\xFC\x80\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFC\x80\x80\x80\x80",
},
/* 3.3.6 2-byte sequence with last byte missing (U+07FF) */
{
"\"\xDF\"",
"\xDF", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.3.7 3-byte sequence with last byte missing (U+FFFF) */
{
"\"\xEF\xBF\"",
"\xEF\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 3.3.8 4-byte sequence with last byte missing (U+1FFFFF) */
{
"\"\xF7\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF7\xBF\xBF",
},
/* 3.3.9 5-byte sequence with last byte missing (U+3FFFFFF) */
{
"\"\xFB\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFB\xBF\xBF\xBF",
},
/* 3.3.10 6-byte sequence with last byte missing (U+7FFFFFFF) */
{
"\"\xFD\xBF\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFD\xBF\xBF\xBF\xBF",
},
/* 3.4 Concatenation of incomplete sequences */
{
"\"\xC0\xE0\x80\xF0\x80\x80\xF8\x80\x80\x80\xFC\x80\x80\x80\x80"
"\xDF\xEF\xBF\xF7\xBF\xBF\xFB\xBF\xBF\xBF\xFD\xBF\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
"\xC0\xE0\x80\xF0\x80\x80\xF8\x80\x80\x80\xFC\x80\x80\x80\x80"
"\xDF\xEF\xBF\xF7\xBF\xBF\xFB\xBF\xBF\xBF\xFD\xBF\xBF\xBF\xBF",
},
/* 3.5 Impossible bytes */
{
"\"\xFE\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFE",
},
{
"\"\xFF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFF",
},
{
"\"\xFE\xFE\xFF\xFF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
"\xFE\xFE\xFF\xFF",
},
/* 4 Overlong sequences */
/* 4.1 Overlong '/' */
{
"\"\xC0\xAF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xC0\xAF",
},
{
"\"\xE0\x80\xAF\"",
"\xE0\x80\xAF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
"\"\xF0\x80\x80\xAF\"",
"\xF0\x80\x80\xAF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
"\"\xF8\x80\x80\x80\xAF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF8\x80\x80\x80\xAF",
},
{
"\"\xFC\x80\x80\x80\x80\xAF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFC\x80\x80\x80\x80\xAF",
},
/*
* 4.2 Maximum overlong sequences
* Highest Unicode value that is still resulting in an
* overlong sequence if represented with the given number of
* bytes. This is a boundary test for safe UTF-8 decoders.
*/
{
/* \U+007F */
"\"\xC1\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xC1\xBF",
},
{
/* \U+07FF */
"\"\xE0\x9F\xBF\"",
"\xE0\x9F\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/*
* \U+FFFC
* The actual maximum would be U+FFFF, but that's a
* noncharacter. Testing U+FFFC seems more useful. See
* also 2.2.3
*/
"\"\xF0\x8F\xBF\xBC\"",
"\xF0\x8F\xBF\xBC", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+1FFFFF */
"\"\xF8\x87\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF8\x87\xBF\xBF\xBF",
},
{
/* \U+3FFFFFF */
"\"\xFC\x83\xBF\xBF\xBF\xBF\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFC\x83\xBF\xBF\xBF\xBF",
},
/* 4.3 Overlong representation of the NUL character */
{
/* \U+0000 */
"\"\xC0\x80\"",
NULL, /* bug: rejected */
"\"\\u0000\"",
"\xC0\x80",
},
{
/* \U+0000 */
"\"\xE0\x80\x80\"",
"\xE0\x80\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+0000 */
"\"\xF0\x80\x80\x80\"",
"\xF0\x80\x80\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+0000 */
"\"\xF8\x80\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xF8\x80\x80\x80\x80",
},
{
/* \U+0000 */
"\"\xFC\x80\x80\x80\x80\x80\"",
NULL, /* bug: rejected */
"\"\\uFFFD\"",
"\xFC\x80\x80\x80\x80\x80",
},
/* 5 Illegal code positions */
/* 5.1 Single UTF-16 surrogates */
{
/* \U+D800 */
"\"\xED\xA0\x80\"",
"\xED\xA0\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DB7F */
"\"\xED\xAD\xBF\"",
"\xED\xAD\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DB80 */
"\"\xED\xAE\x80\"",
"\xED\xAE\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DBFF */
"\"\xED\xAF\xBF\"",
"\xED\xAF\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DC00 */
"\"\xED\xB0\x80\"",
"\xED\xB0\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DF80 */
"\"\xED\xBE\x80\"",
"\xED\xBE\x80", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+DFFF */
"\"\xED\xBF\xBF\"",
"\xED\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* 5.2 Paired UTF-16 surrogates */
{
/* \U+D800\U+DC00 */
"\"\xED\xA0\x80\xED\xB0\x80\"",
"\xED\xA0\x80\xED\xB0\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+D800\U+DFFF */
"\"\xED\xA0\x80\xED\xBF\xBF\"",
"\xED\xA0\x80\xED\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DB7F\U+DC00 */
"\"\xED\xAD\xBF\xED\xB0\x80\"",
"\xED\xAD\xBF\xED\xB0\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DB7F\U+DFFF */
"\"\xED\xAD\xBF\xED\xBF\xBF\"",
"\xED\xAD\xBF\xED\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DB80\U+DC00 */
"\"\xED\xAE\x80\xED\xB0\x80\"",
"\xED\xAE\x80\xED\xB0\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DB80\U+DFFF */
"\"\xED\xAE\x80\xED\xBF\xBF\"",
"\xED\xAE\x80\xED\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DBFF\U+DC00 */
"\"\xED\xAF\xBF\xED\xB0\x80\"",
"\xED\xAF\xBF\xED\xB0\x80", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
{
/* \U+DBFF\U+DFFF */
"\"\xED\xAF\xBF\xED\xBF\xBF\"",
"\xED\xAF\xBF\xED\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\\uFFFD\"",
},
/* 5.3 Other illegal code positions */
/* BMP noncharacters */
{
/* \U+FFFE */
"\"\xEF\xBF\xBE\"",
"\xEF\xBF\xBE", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* \U+FFFF */
"\"\xEF\xBF\xBF\"",
"\xEF\xBF\xBF", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* U+FDD0 */
"\"\xEF\xB7\x90\"",
"\xEF\xB7\x90", /* bug: not corrected */
"\"\\uFFFD\"",
},
{
/* U+FDEF */
"\"\xEF\xB7\xAF\"",
"\xEF\xB7\xAF", /* bug: not corrected */
"\"\\uFFFD\"",
},
/* Plane 1 .. 16 noncharacters */
{
/* U+1FFFE U+1FFFF U+2FFFE U+2FFFF ... U+10FFFE U+10FFFF */
"\"\xF0\x9F\xBF\xBE\xF0\x9F\xBF\xBF"
"\xF0\xAF\xBF\xBE\xF0\xAF\xBF\xBF"
"\xF0\xBF\xBF\xBE\xF0\xBF\xBF\xBF"
"\xF1\x8F\xBF\xBE\xF1\x8F\xBF\xBF"
"\xF1\x9F\xBF\xBE\xF1\x9F\xBF\xBF"
"\xF1\xAF\xBF\xBE\xF1\xAF\xBF\xBF"
"\xF1\xBF\xBF\xBE\xF1\xBF\xBF\xBF"
"\xF2\x8F\xBF\xBE\xF2\x8F\xBF\xBF"
"\xF2\x9F\xBF\xBE\xF2\x9F\xBF\xBF"
"\xF2\xAF\xBF\xBE\xF2\xAF\xBF\xBF"
"\xF2\xBF\xBF\xBE\xF2\xBF\xBF\xBF"
"\xF3\x8F\xBF\xBE\xF3\x8F\xBF\xBF"
"\xF3\x9F\xBF\xBE\xF3\x9F\xBF\xBF"
"\xF3\xAF\xBF\xBE\xF3\xAF\xBF\xBF"
"\xF3\xBF\xBF\xBE\xF3\xBF\xBF\xBF"
"\xF4\x8F\xBF\xBE\xF4\x8F\xBF\xBF\"",
/* bug: not corrected */
"\xF0\x9F\xBF\xBE\xF0\x9F\xBF\xBF"
"\xF0\xAF\xBF\xBE\xF0\xAF\xBF\xBF"
"\xF0\xBF\xBF\xBE\xF0\xBF\xBF\xBF"
"\xF1\x8F\xBF\xBE\xF1\x8F\xBF\xBF"
"\xF1\x9F\xBF\xBE\xF1\x9F\xBF\xBF"
"\xF1\xAF\xBF\xBE\xF1\xAF\xBF\xBF"
"\xF1\xBF\xBF\xBE\xF1\xBF\xBF\xBF"
"\xF2\x8F\xBF\xBE\xF2\x8F\xBF\xBF"
"\xF2\x9F\xBF\xBE\xF2\x9F\xBF\xBF"
"\xF2\xAF\xBF\xBE\xF2\xAF\xBF\xBF"
"\xF2\xBF\xBF\xBE\xF2\xBF\xBF\xBF"
"\xF3\x8F\xBF\xBE\xF3\x8F\xBF\xBF"
"\xF3\x9F\xBF\xBE\xF3\x9F\xBF\xBF"
"\xF3\xAF\xBF\xBE\xF3\xAF\xBF\xBF"
"\xF3\xBF\xBF\xBE\xF3\xBF\xBF\xBF"
"\xF4\x8F\xBF\xBE\xF4\x8F\xBF\xBF",
"\"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\"",
},
{}
};
int i;
QObject *obj;
QString *str;
const char *json_in, *utf8_out, *utf8_in, *json_out;
for (i = 0; test_cases[i].json_in; i++) {
json_in = test_cases[i].json_in;
utf8_out = test_cases[i].utf8_out;
utf8_in = test_cases[i].utf8_in ?: test_cases[i].utf8_out;
json_out = test_cases[i].json_out ?: test_cases[i].json_in;
obj = qobject_from_json(json_in, NULL);
if (utf8_out) {
str = qobject_to_qstring(obj);
g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
} else {
g_assert(!obj);
}
qobject_decref(obj);
obj = QOBJECT(qstring_from_str(utf8_in));
str = qobject_to_json(obj);
if (json_out) {
g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, json_out);
} else {
g_assert(!str);
}
QDECREF(str);
qobject_decref(obj);
/*
* Disabled, because qobject_from_json() is buggy, and I can't
* be bothered to add the expected incorrect results.
* FIXME Enable once these bugs have been fixed.
*/
if (0 && json_out != json_in) {
obj = qobject_from_json(json_out, NULL);
str = qobject_to_qstring(obj);
g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
}
}
}
| true | qemu | aec4b054ea36c53c8b887da99f20010133b84378 |
5,903 | static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts, int64_t *pkt_dts)
{
AVFrame *decoded_frame, *filtered_frame = NULL;
void *buffer_to_free = NULL;
int i, ret = 0;
float quality = 0;
#if CONFIG_AVFILTER
int frame_available = 1;
#endif
int duration=0;
int64_t *best_effort_timestamp;
AVRational *frame_sample_aspect;
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
return AVERROR(ENOMEM);
else
avcodec_get_frame_defaults(ist->decoded_frame);
decoded_frame = ist->decoded_frame;
pkt->pts = *pkt_pts;
pkt->dts = *pkt_dts;
*pkt_pts = AV_NOPTS_VALUE;
if (pkt->duration) {
duration = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
} else if(ist->st->codec->time_base.num != 0) {
int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
duration = ((int64_t)AV_TIME_BASE *
ist->st->codec->time_base.num * ticks) /
ist->st->codec->time_base.den;
}
if(*pkt_dts != AV_NOPTS_VALUE && duration) {
*pkt_dts += duration;
}else
*pkt_dts = AV_NOPTS_VALUE;
ret = avcodec_decode_video2(ist->st->codec,
decoded_frame, got_output, pkt);
if (ret < 0)
return ret;
quality = same_quant ? decoded_frame->quality : 0;
if (!*got_output) {
/* no picture yet */
return ret;
}
best_effort_timestamp= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "best_effort_timestamp");
if(*best_effort_timestamp != AV_NOPTS_VALUE)
ist->next_pts = ist->pts = *best_effort_timestamp;
ist->next_pts += duration;
pkt->size = 0;
pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
#if CONFIG_AVFILTER
frame_sample_aspect= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "sample_aspect_ratio");
for(i=0;i<nb_output_streams;i++) {
OutputStream *ost = ost = &output_streams[i];
if(check_output_constraints(ist, ost)){
if (!frame_sample_aspect->num)
*frame_sample_aspect = ist->st->sample_aspect_ratio;
decoded_frame->pts = ist->pts;
av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE);
}
}
#endif
rate_emu_sleep(ist);
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = &output_streams[i];
int frame_size;
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
continue;
#if CONFIG_AVFILTER
if (ost->input_video_filter) {
frame_available = av_buffersink_poll_frame(ost->output_video_filter);
}
while (frame_available) {
if (ost->output_video_filter) {
AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0){
av_log(0, AV_LOG_WARNING, "AV Filter told us it has a frame available but failed to output one\n");
goto cont;
}
if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) {
av_free(buffer_to_free);
return AVERROR(ENOMEM);
} else
avcodec_get_frame_defaults(ist->filtered_frame);
filtered_frame = ist->filtered_frame;
*filtered_frame= *decoded_frame; //for me_threshold
if (ost->picref) {
avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref);
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
}
}
if (ost->picref->video && !ost->frame_aspect_ratio)
ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
#else
filtered_frame = decoded_frame;
#endif
do_video_out(output_files[ost->file_index].ctx, ost, ist, filtered_frame, &frame_size,
same_quant ? quality : ost->st->codec->global_quality);
if (vstats_filename && frame_size)
do_video_stats(output_files[ost->file_index].ctx, ost, frame_size);
#if CONFIG_AVFILTER
cont:
frame_available = ost->output_video_filter && av_buffersink_poll_frame(ost->output_video_filter);
avfilter_unref_buffer(ost->picref);
}
#endif
}
av_free(buffer_to_free);
return ret;
}
| true | FFmpeg | 1f273c2bf22c49e5f668debf52c497dabee636c7 |
5,904 | SubchDev *css_create_sch(CssDevId bus_id, bool is_virtual, bool squash_mcss,
Error **errp)
{
uint16_t schid = 0;
SubchDev *sch;
if (bus_id.valid) {
if (is_virtual != (bus_id.cssid == VIRTUAL_CSSID)) {
error_setg(errp, "cssid %hhx not valid for %s devices",
bus_id.cssid,
(is_virtual ? "virtual" : "non-virtual"));
return NULL;
}
}
if (bus_id.valid) {
if (squash_mcss) {
bus_id.cssid = channel_subsys.default_cssid;
} else if (!channel_subsys.css[bus_id.cssid]) {
css_create_css_image(bus_id.cssid, false);
}
if (!css_find_free_subch_for_devno(bus_id.cssid, bus_id.ssid,
bus_id.devid, &schid, errp)) {
return NULL;
}
} else if (squash_mcss || is_virtual) {
bus_id.cssid = channel_subsys.default_cssid;
if (!css_find_free_subch_and_devno(bus_id.cssid, &bus_id.ssid,
&bus_id.devid, &schid, errp)) {
return NULL;
}
} else {
for (bus_id.cssid = 0; bus_id.cssid < MAX_CSSID; ++bus_id.cssid) {
if (bus_id.cssid == VIRTUAL_CSSID) {
continue;
}
if (!channel_subsys.css[bus_id.cssid]) {
css_create_css_image(bus_id.cssid, false);
}
if (css_find_free_subch_and_devno(bus_id.cssid, &bus_id.ssid,
&bus_id.devid, &schid,
NULL)) {
break;
}
if (bus_id.cssid == MAX_CSSID) {
error_setg(errp, "Virtual channel subsystem is full!");
return NULL;
}
}
}
sch = g_new0(SubchDev, 1);
sch->cssid = bus_id.cssid;
sch->ssid = bus_id.ssid;
sch->devno = bus_id.devid;
sch->schid = schid;
css_subch_assign(sch->cssid, sch->ssid, schid, sch->devno, sch);
return sch;
}
| true | qemu | 99577c492fb2916165ed9bc215f058877f0a4106 |
5,906 | static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
{
int ret = 0;
uint64_t bytes = 0;
uint32_t blocks;
size_t block_size = DEFAULT_CLUSTER_SIZE;
uint32_t image_type = VDI_TYPE_DYNAMIC;
VdiHeader header;
size_t i;
size_t bmap_size;
int64_t offset = 0;
Error *local_err = NULL;
BlockDriverState *bs = NULL;
uint32_t *bmap = NULL;
logout("\n");
/* Read out options. */
bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
#if defined(CONFIG_VDI_BLOCK_SIZE)
/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
block_size = qemu_opt_get_size_del(opts,
BLOCK_OPT_CLUSTER_SIZE,
DEFAULT_CLUSTER_SIZE);
#endif
#if defined(CONFIG_VDI_STATIC_IMAGE)
if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
image_type = VDI_TYPE_STATIC;
}
#endif
if (bytes > VDI_DISK_SIZE_MAX) {
ret = -ENOTSUP;
error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
", max supported is 0x%" PRIx64 ")",
bytes, VDI_DISK_SIZE_MAX);
goto exit;
}
ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
}
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
NULL, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto exit;
}
/* We need enough blocks to store the given disk size,
so always round up. */
blocks = (bytes + block_size - 1) / block_size;
bmap_size = blocks * sizeof(uint32_t);
bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE -1));
memset(&header, 0, sizeof(header));
pstrcpy(header.text, sizeof(header.text), VDI_TEXT);
header.signature = VDI_SIGNATURE;
header.version = VDI_VERSION_1_1;
header.header_size = 0x180;
header.image_type = image_type;
header.offset_bmap = 0x200;
header.offset_data = 0x200 + bmap_size;
header.sector_size = SECTOR_SIZE;
header.disk_size = bytes;
header.block_size = block_size;
header.blocks_in_image = blocks;
if (image_type == VDI_TYPE_STATIC) {
header.blocks_allocated = blocks;
}
uuid_generate(header.uuid_image);
uuid_generate(header.uuid_last_snap);
/* There is no need to set header.uuid_link or header.uuid_parent here. */
#if defined(CONFIG_VDI_DEBUG)
vdi_header_print(&header);
#endif
vdi_header_to_le(&header);
ret = bdrv_pwrite_sync(bs, offset, &header, sizeof(header));
if (ret < 0) {
error_setg(errp, "Error writing header to %s", filename);
goto exit;
}
offset += sizeof(header);
if (bmap_size > 0) {
bmap = g_malloc0(bmap_size);
for (i = 0; i < blocks; i++) {
if (image_type == VDI_TYPE_STATIC) {
bmap[i] = i;
} else {
bmap[i] = VDI_UNALLOCATED;
}
}
ret = bdrv_pwrite_sync(bs, offset, bmap, bmap_size);
if (ret < 0) {
error_setg(errp, "Error writing bmap to %s", filename);
goto exit;
}
offset += bmap_size;
}
if (image_type == VDI_TYPE_STATIC) {
ret = bdrv_truncate(bs, offset + blocks * block_size);
if (ret < 0) {
error_setg(errp, "Failed to statically allocate %s", filename);
goto exit;
}
}
exit:
bdrv_unref(bs);
g_free(bmap);
return ret;
}
| true | qemu | 17cce735780f0ff6a2ef173c34614bd47acd56e5 |
5,907 | static int brpix_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
BRPixContext *s = avctx->priv_data;
AVFrame *frame_out = data;
int ret;
GetByteContext gb;
unsigned int bytes_pp;
unsigned int magic[4];
unsigned int chunk_type;
unsigned int data_len;
BRPixHeader hdr;
bytestream2_init(&gb, avpkt->data, avpkt->size);
magic[0] = bytestream2_get_be32(&gb);
magic[1] = bytestream2_get_be32(&gb);
magic[2] = bytestream2_get_be32(&gb);
magic[3] = bytestream2_get_be32(&gb);
if (magic[0] != 0x12 ||
magic[1] != 0x8 ||
magic[2] != 0x2 ||
magic[3] != 0x2) {
av_log(avctx, AV_LOG_ERROR, "Not a BRender PIX file\n");
return AVERROR_INVALIDDATA;
chunk_type = bytestream2_get_be32(&gb);
if (chunk_type != 0x3 && chunk_type != 0x3d) {
av_log(avctx, AV_LOG_ERROR, "Invalid chunk type %d\n", chunk_type);
return AVERROR_INVALIDDATA;
ret = brpix_decode_header(&hdr, &gb);
if (!ret) {
av_log(avctx, AV_LOG_ERROR, "Invalid header length\n");
return AVERROR_INVALIDDATA;
switch (hdr.format) {
case 3:
avctx->pix_fmt = AV_PIX_FMT_PAL8;
bytes_pp = 1;
break;
case 4:
avctx->pix_fmt = AV_PIX_FMT_RGB555BE;
bytes_pp = 2;
break;
case 5:
avctx->pix_fmt = AV_PIX_FMT_RGB565BE;
bytes_pp = 2;
break;
case 6:
avctx->pix_fmt = AV_PIX_FMT_RGB24;
bytes_pp = 3;
break;
case 7:
avctx->pix_fmt = AV_PIX_FMT_0RGB;
bytes_pp = 4;
break;
case 18:
avctx->pix_fmt = AV_PIX_FMT_GRAY8A;
bytes_pp = 2;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Format %d is not supported\n",
hdr.format);
return AVERROR_PATCHWELCOME;
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
if (av_image_check_size(hdr.width, hdr.height, 0, avctx) < 0)
return AVERROR_INVALIDDATA;
if (hdr.width != avctx->width || hdr.height != avctx->height)
avcodec_set_dimensions(avctx, hdr.width, hdr.height);
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
chunk_type = bytestream2_get_be32(&gb);
if (avctx->pix_fmt == AV_PIX_FMT_PAL8 &&
(chunk_type == 0x3 || chunk_type == 0x3d)) {
BRPixHeader palhdr;
ret = brpix_decode_header(&palhdr, &gb);
if (!ret) {
av_log(avctx, AV_LOG_ERROR, "Invalid palette header length\n");
return AVERROR_INVALIDDATA;
if (palhdr.format != 7) {
av_log(avctx, AV_LOG_ERROR, "Palette is not in 0RGB format\n");
return AVERROR_INVALIDDATA;
chunk_type = bytestream2_get_be32(&gb);
data_len = bytestream2_get_be32(&gb);
bytestream2_skip(&gb, 8);
if (chunk_type != 0x21 || data_len != 1032 ||
bytestream2_get_bytes_left(&gb) < 1032) {
av_log(avctx, AV_LOG_ERROR, "Invalid palette data\n");
return AVERROR_INVALIDDATA;
// convert 0RGB to machine endian format (ARGB32)
bytestream2_skipu(&gb, 1);
*pal_out++ = (0xFFU << 24) | bytestream2_get_be24u(&gb);
bytestream2_skip(&gb, 8);
chunk_type = bytestream2_get_be32(&gb);
data_len = bytestream2_get_be32(&gb);
bytestream2_skip(&gb, 8);
// read the image data to the buffer
{
unsigned int bytes_per_scanline = bytes_pp * hdr.width;
unsigned int bytes_left = bytestream2_get_bytes_left(&gb);
if (chunk_type != 0x21 || data_len != bytes_left ||
bytes_left / bytes_per_scanline < hdr.height)
{
av_log(avctx, AV_LOG_ERROR, "Invalid image data\n");
return AVERROR_INVALIDDATA;
av_image_copy_plane(s->frame.data[0], s->frame.linesize[0],
avpkt->data + bytestream2_tell(&gb),
bytes_per_scanline,
bytes_per_scanline, hdr.height);
*frame_out = s->frame;
*got_frame = 1;
return avpkt->size; | true | FFmpeg | 551d8b58ebc03114d4231df92e366ffb7bf7ff62 |
5,909 | static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
{
int i, csize = 1;
int32_t *src[3], i0, i1, i2;
float *srcf[3], i0f, i1f, i2f;
for (i = 0; i < 3; i++)
if (tile->codsty[0].transform == FF_DWT97)
srcf[i] = tile->comp[i].f_data;
else
src [i] = tile->comp[i].i_data;
for (i = 0; i < 2; i++)
csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
switch (tile->codsty[0].transform) {
case FF_DWT97:
for (i = 0; i < csize; i++) {
i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);
i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])
- (f_ict_params[2] * *srcf[2]);
i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);
*srcf[0]++ = i0f;
*srcf[1]++ = i1f;
*srcf[2]++ = i2f;
break;
case FF_DWT97_INT:
for (i = 0; i < csize; i++) {
i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
- (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);
i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
*src[0]++ = i0;
*src[1]++ = i1;
*src[2]++ = i2;
break;
case FF_DWT53:
for (i = 0; i < csize; i++) {
i1 = *src[0] - (*src[2] + *src[1] >> 2);
i0 = i1 + *src[2];
i2 = i1 + *src[1];
*src[0]++ = i0;
*src[1]++ = i1;
*src[2]++ = i2;
break; | true | FFmpeg | ac3b01a9c0607961f4540fe62040833870f5deb1 |
5,911 | static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
{
AVStream *st = c->fc->streams[c->fc->nb_streams-1];
MOVStreamContext *sc = st->priv_data;
int entries, i, j;
get_be32(pb); // version + flags
entries = get_be32(pb);
if (entries >= UINT_MAX / sizeof(*sc->drefs))
return -1;
sc->drefs_count = entries;
sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));
for (i = 0; i < sc->drefs_count; i++) {
MOV_dref_t *dref = &sc->drefs[i];
uint32_t size = get_be32(pb);
offset_t next = url_ftell(pb) + size - 4;
dref->type = get_le32(pb);
get_be32(pb); // version + flags
dprintf(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);
if (dref->type == MKTAG('a','l','i','s') && size > 150) {
/* macintosh alias record */
uint16_t volume_len, len;
char volume[28];
int16_t type;
url_fskip(pb, 10);
volume_len = get_byte(pb);
volume_len = FFMIN(volume_len, 27);
get_buffer(pb, volume, 27);
volume[volume_len] = 0;
av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len);
url_fskip(pb, 112);
for (type = 0; type != -1 && url_ftell(pb) < next; ) {
type = get_be16(pb);
len = get_be16(pb);
av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);
if (len&1)
len += 1;
if (type == 2) { // absolute path
dref->path = av_mallocz(len+1);
get_buffer(pb, dref->path, len);
if (!strncmp(dref->path, volume, volume_len)) {
len -= volume_len;
memmove(dref->path, dref->path+volume_len, len);
dref->path[len] = 0;
}
for (j = 0; j < len; j++)
if (dref->path[j] == ':')
dref->path[j] = '/';
av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);
} else
url_fskip(pb, len);
}
}
url_fseek(pb, next, SEEK_SET);
}
return 0;
}
| true | FFmpeg | dbb7cbf26ed44d258c56e976de3300d87b716875 |
5,912 | int usb_handle_packet(USBDevice *dev, USBPacket *p)
{
int ret;
if (dev == NULL) {
return USB_RET_NODEV;
}
assert(dev->addr == p->devaddr);
assert(dev->state == USB_STATE_DEFAULT);
assert(p->owner == NULL);
if (p->devep == 0) {
/* control pipe */
switch (p->pid) {
case USB_TOKEN_SETUP:
ret = do_token_setup(dev, p);
break;
case USB_TOKEN_IN:
ret = do_token_in(dev, p);
break;
case USB_TOKEN_OUT:
ret = do_token_out(dev, p);
break;
default:
ret = USB_RET_STALL;
break;
}
} else {
/* data pipe */
ret = usb_device_handle_data(dev, p);
}
if (ret == USB_RET_ASYNC) {
p->owner = usb_ep_get(dev, p->pid, p->devep);
}
return ret;
}
| true | qemu | f53c398aa603cea135ee58fd15249aeff7b9c7ea |
5,914 | static void old_pc_system_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw)
{
char *filename;
MemoryRegion *bios, *isa_bios;
int bios_size, isa_bios_size;
int ret;
/* BIOS load */
if (bios_name == NULL) {
bios_name = BIOS_FILENAME;
}
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (filename) {
bios_size = get_image_size(filename);
} else {
bios_size = -1;
}
if (bios_size <= 0 ||
(bios_size % 65536) != 0) {
goto bios_error;
}
bios = g_malloc(sizeof(*bios));
memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_abort);
vmstate_register_ram_global(bios);
if (!isapc_ram_fw) {
memory_region_set_readonly(bios, true);
}
ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
if (ret != 0) {
bios_error:
fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
exit(1);
}
g_free(filename);
/* map the last 128KB of the BIOS in ISA space */
isa_bios_size = bios_size;
if (isa_bios_size > (128 * 1024)) {
isa_bios_size = 128 * 1024;
}
isa_bios = g_malloc(sizeof(*isa_bios));
memory_region_init_alias(isa_bios, NULL, "isa-bios", bios,
bios_size - isa_bios_size, isa_bios_size);
memory_region_add_subregion_overlap(rom_memory,
0x100000 - isa_bios_size,
isa_bios,
1);
if (!isapc_ram_fw) {
memory_region_set_readonly(isa_bios, true);
}
/* map all the bios at the top of memory */
memory_region_add_subregion(rom_memory,
(uint32_t)(-bios_size),
bios);
}
| true | qemu | f8ed85ac992c48814d916d5df4d44f9a971c5de4 |
5,916 | static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run)
{
CPUState *cs = CPU(cpu);
CPUPPCState *env = &cpu->env;
struct kvm_debug_exit_arch *arch_info = &run->debug.arch;
int handle = 0;
if (kvm_find_sw_breakpoint(cs, arch_info->address)) {
handle = 1;
} else {
/* QEMU is not able to handle debug exception, so inject
* program exception to guest;
* Yes program exception NOT debug exception !!
* For software breakpoint QEMU uses a privileged instruction;
* So there cannot be any reason that we are here for guest
* set debug exception, only possibility is guest executed a
* privileged / illegal instruction and that's why we are
* injecting a program interrupt.
*/
cpu_synchronize_state(cs);
/* env->nip is PC, so increment this by 4 to use
* ppc_cpu_do_interrupt(), which set srr0 = env->nip - 4.
*/
env->nip += 4;
cs->exception_index = POWERPC_EXCP_PROGRAM;
env->error_code = POWERPC_EXCP_INVAL;
ppc_cpu_do_interrupt(cs);
}
return handle;
}
| true | qemu | 88365d17d586bcf0d9f4432447db345f72278a2a |
5,917 | void helper_ldda_asi(target_ulong addr, int asi, int rd)
{
if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
|| ((env->def->features & CPU_FEATURE_HYPV)
&& asi >= 0x30 && asi < 0x80
&& !(env->hpstate & HS_PRIV)))
raise_exception(TT_PRIV_ACT);
switch (asi) {
case 0x24: // Nucleus quad LDD 128 bit atomic
case 0x2c: // Nucleus quad LDD 128 bit atomic LE
helper_check_align(addr, 0xf);
if (rd == 0) {
env->gregs[1] = ldq_kernel(addr + 8);
if (asi == 0x2c)
bswap64s(&env->gregs[1]);
} else if (rd < 8) {
env->gregs[rd] = ldq_kernel(addr);
env->gregs[rd + 1] = ldq_kernel(addr + 8);
if (asi == 0x2c) {
bswap64s(&env->gregs[rd]);
bswap64s(&env->gregs[rd + 1]);
}
} else {
env->regwptr[rd] = ldq_kernel(addr);
env->regwptr[rd + 1] = ldq_kernel(addr + 8);
if (asi == 0x2c) {
bswap64s(&env->regwptr[rd]);
bswap64s(&env->regwptr[rd + 1]);
}
}
break;
default:
helper_check_align(addr, 0x3);
if (rd == 0)
env->gregs[1] = helper_ld_asi(addr + 4, asi, 4, 0);
else if (rd < 8) {
env->gregs[rd] = helper_ld_asi(addr, asi, 4, 0);
env->gregs[rd + 1] = helper_ld_asi(addr + 4, asi, 4, 0);
} else {
env->regwptr[rd] = helper_ld_asi(addr, asi, 4, 0);
env->regwptr[rd + 1] = helper_ld_asi(addr + 4, asi, 4, 0);
}
break;
}
}
| true | qemu | 2aae2b8e0abd58e76d616bcbe93c6966d06d0188 |
5,918 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VBDecContext * const c = avctx->priv_data;
uint8_t *outptr, *srcptr;
int i, j;
int flags;
uint32_t size;
int rest = buf_size;
int offset = 0;
if(c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
c->pic.reference = 3;
if(avctx->get_buffer(avctx, &c->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
c->stream = buf;
flags = bytestream_get_le16(&c->stream);
rest -= 2;
if(flags & VB_HAS_GMC){
i = (int16_t)bytestream_get_le16(&c->stream);
j = (int16_t)bytestream_get_le16(&c->stream);
offset = i + j * avctx->width;
rest -= 4;
}
if(flags & VB_HAS_VIDEO){
size = bytestream_get_le32(&c->stream);
if(size > rest){
av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n");
return -1;
}
vb_decode_framedata(c, c->stream, size, offset);
c->stream += size - 4;
rest -= size;
}
if(flags & VB_HAS_PALETTE){
size = bytestream_get_le32(&c->stream);
if(size > rest){
av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n");
return -1;
}
vb_decode_palette(c, size);
rest -= size;
}
memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
c->pic.palette_has_changed = flags & VB_HAS_PALETTE;
outptr = c->pic.data[0];
srcptr = c->frame;
for(i = 0; i < avctx->height; i++){
memcpy(outptr, srcptr, avctx->width);
srcptr += avctx->width;
outptr += c->pic.linesize[0];
}
FFSWAP(uint8_t*, c->frame, c->prev_frame);
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
| true | FFmpeg | 5b98ea1b7309fd43694b92e990439636630f408a |
5,919 | static inline void RENAME(bgr32ToY)(uint8_t *dst, uint8_t *src, int width)
{
int i;
for(i=0; i<width; i++)
{
int b= ((uint32_t*)src)[i]&0xFF;
int g= (((uint32_t*)src)[i]>>8)&0xFF;
int r= (((uint32_t*)src)[i]>>16)&0xFF;
dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT);
}
}
| true | FFmpeg | 2da0d70d5eebe42f9fcd27ee554419ebe2a5da06 |
5,921 | static void gen_read_xer(TCGv dst)
{
TCGv t0 = tcg_temp_new();
TCGv t1 = tcg_temp_new();
TCGv t2 = tcg_temp_new();
tcg_gen_mov_tl(dst, cpu_xer);
tcg_gen_shli_tl(t0, cpu_so, XER_SO);
tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
tcg_gen_or_tl(t0, t0, t1);
tcg_gen_or_tl(dst, dst, t2);
tcg_gen_or_tl(dst, dst, t0);
tcg_temp_free(t0);
tcg_temp_free(t1);
tcg_temp_free(t2);
}
| true | qemu | dd09c36159858c66ab6e47c688e4177dd3912bf0 |
5,922 | Object *object_dynamic_cast(Object *obj, const char *typename)
{
if (object_class_dynamic_cast(object_get_class(obj), typename)) {
return obj;
}
return NULL;
}
| true | qemu | b7f43fe46029d8fd0594cd599fa2599dcce0f553 |
5,924 | static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
{
h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta);
}
| false | FFmpeg | dd561441b1e849df7d8681c6f32af82d4088dafd |
5,925 | static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
int buf_size, void *data)
{
SVQ1Context * const s = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p= (AVFrame*)&s->picture;
AVFrame temp;
int i;
if(avctx->pix_fmt != PIX_FMT_YUV410P){
av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
return -1;
}
if(!s->current_picture.data[0]){
avctx->get_buffer(avctx, &s->current_picture);
avctx->get_buffer(avctx, &s->last_picture);
s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16);
}
temp= s->current_picture;
s->current_picture= s->last_picture;
s->last_picture= temp;
init_put_bits(&s->pb, buf, buf_size);
*p = *pict;
p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? FF_P_TYPE : FF_I_TYPE;
p->key_frame = p->pict_type == FF_I_TYPE;
svq1_write_header(s, p->pict_type);
for(i=0; i<3; i++){
if(svq1_encode_plane(s, i,
s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i],
s->frame_width / (i?4:1), s->frame_height / (i?4:1),
s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
return -1;
}
// align_put_bits(&s->pb);
while(put_bits_count(&s->pb) & 31)
put_bits(&s->pb, 1, 0);
flush_put_bits(&s->pb);
return put_bits_count(&s->pb) / 8;
}
| true | FFmpeg | a7494872d5a673f064b0570f4359c8d1a3ea1051 |
5,926 | static void xics_common_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
dc->reset = xics_common_reset;
} | true | qemu | b1fc72f0fb0aeae4194ff89c454aabe019983d0d |
5,927 | static BlockJob *test_block_job_start(unsigned int iterations,
bool use_timer,
int rc, int *result)
{
BlockDriverState *bs;
TestBlockJob *s;
TestBlockJobCBData *data;
data = g_new0(TestBlockJobCBData, 1);
bs = bdrv_new();
s = block_job_create(&test_block_job_driver, bs, 0, test_block_job_cb,
data, &error_abort);
s->iterations = iterations;
s->use_timer = use_timer;
s->rc = rc;
s->result = result;
s->common.co = qemu_coroutine_create(test_block_job_run);
data->job = s;
data->result = result;
qemu_coroutine_enter(s->common.co, s);
return &s->common;
}
| true | qemu | 7f0317cfc8da620cdb38cb5cfec5f82b8dd05403 |
5,929 | static int cook_decode_init(AVCodecContext *avctx)
{
COOKextradata *e = avctx->extradata;
COOKContext *q = avctx->priv_data;
/* Take care of the codec specific extradata. */
if (avctx->extradata_size <= 0) {
av_log(NULL,AV_LOG_ERROR,"Necessary extradata missing!\n");
} else {
/* 8 for mono, 16 for stereo, ? for multichannel
Swap to right endianness so we don't need to care later on. */
av_log(NULL,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
if (avctx->extradata_size >= 8){
e->cookversion = be2me_32(e->cookversion);
e->samples_per_frame = be2me_16(e->samples_per_frame);
e->subbands = be2me_16(e->subbands);
}
if (avctx->extradata_size >= 16){
e->js_subband_start = be2me_16(e->js_subband_start);
e->js_vlc_bits = be2me_16(e->js_vlc_bits);
}
}
/* Take data from the AVCodecContext (RM container). */
q->sample_rate = avctx->sample_rate;
q->nb_channels = avctx->channels;
q->bit_rate = avctx->bit_rate;
/* Initialize state. */
q->random_state = 1;
/* Initialize extradata related variables. */
q->samples_per_channel = e->samples_per_frame / q->nb_channels;
q->samples_per_frame = e->samples_per_frame;
q->subbands = e->subbands;
q->bits_per_subpacket = avctx->block_align * 8;
/* Initialize default data states. */
q->js_subband_start = 0;
q->log2_numvector_size = 5;
q->total_subbands = q->subbands;
/* Initialize version-dependent variables */
av_log(NULL,AV_LOG_DEBUG,"e->cookversion=%x\n",e->cookversion);
switch (e->cookversion) {
case MONO_COOK1:
if (q->nb_channels != 1) {
av_log(NULL,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
}
av_log(NULL,AV_LOG_DEBUG,"MONO_COOK1\n");
break;
case MONO_COOK2:
if (q->nb_channels != 1) {
q->joint_stereo = 0;
q->bits_per_subpacket = q->bits_per_subpacket/2;
}
av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n");
break;
case JOINT_STEREO:
if (q->nb_channels != 2) {
av_log(NULL,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
}
av_log(NULL,AV_LOG_DEBUG,"JOINT_STEREO\n");
if (avctx->extradata_size >= 16){
q->total_subbands = q->subbands + e->js_subband_start;
q->js_subband_start = e->js_subband_start;
q->joint_stereo = 1;
q->js_vlc_bits = e->js_vlc_bits;
}
if (q->samples_per_channel > 256) {
q->log2_numvector_size = 6;
}
if (q->samples_per_channel > 512) {
q->log2_numvector_size = 7;
}
break;
case MC_COOK:
av_log(NULL,AV_LOG_ERROR,"MC_COOK not supported!\n");
break;
default:
av_log(NULL,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
break;
}
/* Initialize variable relations */
q->mlt_size = q->samples_per_channel;
q->numvector_size = (1 << q->log2_numvector_size);
/* Generate tables */
init_rootpow2table(q);
init_pow2table(q);
init_gain_table(q);
if (init_cook_vlc_tables(q) != 0)
/* Pad the databuffer with FF_INPUT_BUFFER_PADDING_SIZE,
this is for the bitstreamreader. */
if ((q->decoded_bytes_buffer = av_mallocz((avctx->block_align+(4-avctx->block_align%4) + FF_INPUT_BUFFER_PADDING_SIZE)*sizeof(uint8_t))) == NULL)
q->decode_buf_ptr[0] = q->decode_buffer_1;
q->decode_buf_ptr[1] = q->decode_buffer_2;
q->decode_buf_ptr[2] = q->decode_buffer_3;
q->decode_buf_ptr[3] = q->decode_buffer_4;
q->decode_buf_ptr2[0] = q->decode_buffer_3;
q->decode_buf_ptr2[1] = q->decode_buffer_4;
q->previous_buffer_ptr[0] = q->mono_previous_buffer1;
q->previous_buffer_ptr[1] = q->mono_previous_buffer2;
/* Initialize transform. */
if ( init_cook_mlt(q) == 0 )
/* Try to catch some obviously faulty streams, othervise it might be exploitable */
if (q->total_subbands > 53) {
av_log(NULL,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
}
if (q->subbands > 50) {
av_log(NULL,AV_LOG_ERROR,"subbands > 50, report sample!\n");
}
if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
} else {
av_log(NULL,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
}
#ifdef COOKDEBUG
dump_cook_context(q,e);
#endif
return 0;
} | true | FFmpeg | 3a1a7e32ace7af47de74e8ae779cb4e04c89aa97 |
5,930 | static int check_for_block_signature(BlockDriverState *bs, const uint8_t *buf)
{
static const uint8_t signatures[][4] = {
{ 'Q', 'F', 'I', 0xfb }, /* qcow/qcow2 */
{ 'C', 'O', 'W', 'D' }, /* VMDK3 */
{ 'V', 'M', 'D', 'K' }, /* VMDK4 */
{ 'O', 'O', 'O', 'M' }, /* UML COW */
{}
};
int i;
for (i = 0; signatures[i][0] != 0; i++) {
if (memcmp(buf, signatures[i], 4) == 0) {
return 1;
}
}
return 0;
}
| true | qemu | 8b33d9eeba91422ee2d73b6936ad57262d18cf5a |
5,932 | static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVParallelsState *s = bs->opaque;
ParallelsHeader ph;
int ret, size, i;
QemuOpts *opts = NULL;
Error *local_err = NULL;
char *buf;
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
false, errp);
if (!bs->file) {
return -EINVAL;
}
ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
if (ret < 0) {
goto fail;
}
bs->total_sectors = le64_to_cpu(ph.nb_sectors);
if (le32_to_cpu(ph.version) != HEADER_VERSION) {
goto fail_format;
}
if (!memcmp(ph.magic, HEADER_MAGIC, 16)) {
s->off_multiplier = 1;
bs->total_sectors = 0xffffffff & bs->total_sectors;
} else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) {
s->off_multiplier = le32_to_cpu(ph.tracks);
} else {
goto fail_format;
}
s->tracks = le32_to_cpu(ph.tracks);
if (s->tracks == 0) {
error_setg(errp, "Invalid image: Zero sectors per track");
ret = -EINVAL;
goto fail;
}
if (s->tracks > INT32_MAX/513) {
error_setg(errp, "Invalid image: Too big cluster");
ret = -EFBIG;
goto fail;
}
s->bat_size = le32_to_cpu(ph.bat_entries);
if (s->bat_size > INT_MAX / sizeof(uint32_t)) {
error_setg(errp, "Catalog too large");
ret = -EFBIG;
goto fail;
}
size = bat_entry_off(s->bat_size);
s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs));
s->header = qemu_try_blockalign(bs->file->bs, s->header_size);
if (s->header == NULL) {
ret = -ENOMEM;
goto fail;
}
s->data_end = le32_to_cpu(ph.data_off);
if (s->data_end == 0) {
s->data_end = ROUND_UP(bat_entry_off(s->bat_size), BDRV_SECTOR_SIZE);
}
if (s->data_end < s->header_size) {
/* there is not enough unused space to fit to block align between BAT
and actual data. We can't avoid read-modify-write... */
s->header_size = size;
}
ret = bdrv_pread(bs->file, 0, s->header, s->header_size);
if (ret < 0) {
goto fail;
}
s->bat_bitmap = (uint32_t *)(s->header + 1);
for (i = 0; i < s->bat_size; i++) {
int64_t off = bat2sect(s, i);
if (off >= s->data_end) {
s->data_end = off + s->tracks;
}
}
if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) {
/* Image was not closed correctly. The check is mandatory */
s->header_unclean = true;
if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_CHECK)) {
error_setg(errp, "parallels: Image was not closed correctly; "
"cannot be opened read/write");
ret = -EACCES;
goto fail;
}
}
opts = qemu_opts_create(¶llels_runtime_opts, NULL, 0, &local_err);
if (local_err != NULL) {
goto fail_options;
}
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err != NULL) {
goto fail_options;
}
s->prealloc_size =
qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err);
g_free(buf);
if (local_err != NULL) {
goto fail_options;
}
if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs),
PREALLOC_MODE_OFF, NULL) != 0) {
s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
}
if (flags & BDRV_O_RDWR) {
s->header->inuse = cpu_to_le32(HEADER_INUSE_MAGIC);
ret = parallels_update_header(bs);
if (ret < 0) {
goto fail;
}
}
s->bat_dirty_block = 4 * getpagesize();
s->bat_dirty_bmap =
bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
qemu_co_mutex_init(&s->lock);
return 0;
fail_format:
error_setg(errp, "Image not in Parallels format");
ret = -EINVAL;
fail:
qemu_vfree(s->header);
return ret;
fail_options:
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
}
| true | qemu | e5e6268348972aaf415d7931bbd808b3fdba6cb1 |
5,933 | static void __attribute__((constructor)) st_init(void)
{
atexit(st_flush_trace_buffer);
}
| true | qemu | 0b5538c300a56c3cfb33022840fe0b4968147e7a |
5,935 | static void test_qemu_strtoull_full_max(void)
{
const char *str = g_strdup_printf("%lld", ULLONG_MAX);
uint64_t res = 999;
int err;
err = qemu_strtoull(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, ULLONG_MAX);
}
| true | qemu | d6f723b513a0c3c4e58343b7c52a2f9850861fa0 |
5,936 | static av_cold int mss1_decode_init(AVCodecContext *avctx)
{
MSS1Context * const c = avctx->priv_data;
int ret;
c->ctx.avctx = avctx;
c->pic = av_frame_alloc();
if (!c->pic)
return AVERROR(ENOMEM);
ret = ff_mss12_decode_init(&c->ctx, 0, &c->sc, NULL);
avctx->pix_fmt = AV_PIX_FMT_PAL8;
return ret;
} | true | FFmpeg | 331fae80a1fb9b027442047fb564c02c6c41e70b |
5,938 | static int ioreq_map(struct ioreq *ioreq)
{
XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
int i, j, new_maps = 0;
PersistentGrant *grant;
/* domids and refs variables will contain the information necessary
* to map the grants that are needed to fulfill this request.
*
* After mapping the needed grants, the page array will contain the
* memory address of each granted page in the order specified in ioreq
* (disregarding if it's a persistent grant or not).
*/
if (ioreq->v.niov == 0 || ioreq->mapped == 1) {
return 0;
}
if (ioreq->blkdev->feature_persistent) {
for (i = 0; i < ioreq->v.niov; i++) {
grant = g_tree_lookup(ioreq->blkdev->persistent_gnts,
GUINT_TO_POINTER(ioreq->refs[i]));
if (grant != NULL) {
page[i] = grant->page;
xen_be_printf(&ioreq->blkdev->xendev, 3,
"using persistent-grant %" PRIu32 "\n",
ioreq->refs[i]);
} else {
/* Add the grant to the list of grants that
* should be mapped
*/
domids[new_maps] = ioreq->domids[i];
refs[new_maps] = ioreq->refs[i];
page[i] = NULL;
new_maps++;
}
}
/* Set the protection to RW, since grants may be reused later
* with a different protection than the one needed for this request
*/
ioreq->prot = PROT_WRITE | PROT_READ;
} else {
/* All grants in the request should be mapped */
memcpy(refs, ioreq->refs, sizeof(refs));
memcpy(domids, ioreq->domids, sizeof(domids));
memset(page, 0, sizeof(page));
new_maps = ioreq->v.niov;
}
if (batch_maps && new_maps) {
ioreq->pages = xc_gnttab_map_grant_refs
(gnt, new_maps, domids, refs, ioreq->prot);
if (ioreq->pages == NULL) {
xen_be_printf(&ioreq->blkdev->xendev, 0,
"can't map %d grant refs (%s, %d maps)\n",
new_maps, strerror(errno), ioreq->blkdev->cnt_map);
return -1;
}
for (i = 0, j = 0; i < ioreq->v.niov; i++) {
if (page[i] == NULL) {
page[i] = ioreq->pages + (j++) * XC_PAGE_SIZE;
}
}
ioreq->blkdev->cnt_map += new_maps;
} else if (new_maps) {
for (i = 0; i < new_maps; i++) {
ioreq->page[i] = xc_gnttab_map_grant_ref
(gnt, domids[i], refs[i], ioreq->prot);
if (ioreq->page[i] == NULL) {
xen_be_printf(&ioreq->blkdev->xendev, 0,
"can't map grant ref %d (%s, %d maps)\n",
refs[i], strerror(errno), ioreq->blkdev->cnt_map);
ioreq->mapped = 1;
ioreq_unmap(ioreq);
return -1;
}
ioreq->blkdev->cnt_map++;
}
for (i = 0, j = 0; i < ioreq->v.niov; i++) {
if (page[i] == NULL) {
page[i] = ioreq->page[j++];
}
}
}
if (ioreq->blkdev->feature_persistent) {
while ((ioreq->blkdev->persistent_gnt_count < ioreq->blkdev->max_grants)
&& new_maps) {
/* Go through the list of newly mapped grants and add as many
* as possible to the list of persistently mapped grants.
*
* Since we start at the end of ioreq->page(s), we only need
* to decrease new_maps to prevent this granted pages from
* being unmapped in ioreq_unmap.
*/
grant = g_malloc0(sizeof(*grant));
new_maps--;
if (batch_maps) {
grant->page = ioreq->pages + (new_maps) * XC_PAGE_SIZE;
} else {
grant->page = ioreq->page[new_maps];
}
grant->blkdev = ioreq->blkdev;
xen_be_printf(&ioreq->blkdev->xendev, 3,
"adding grant %" PRIu32 " page: %p\n",
refs[new_maps], grant->page);
g_tree_insert(ioreq->blkdev->persistent_gnts,
GUINT_TO_POINTER(refs[new_maps]),
grant);
ioreq->blkdev->persistent_gnt_count++;
}
}
for (i = 0; i < ioreq->v.niov; i++) {
ioreq->v.iov[i].iov_base += (uintptr_t)page[i];
}
ioreq->mapped = 1;
ioreq->num_unmap = new_maps;
return 0;
}
| true | qemu | 2f01dfacb56bc7a0d4639adc9dff9aae131e6216 |
5,939 | static void *aio_thread(void *unused)
{
sigset_t set;
/* block all signals */
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, NULL);
while (1) {
struct qemu_paiocb *aiocb;
size_t offset;
int ret = 0;
pthread_mutex_lock(&lock);
while (TAILQ_EMPTY(&request_list) &&
!(ret == ETIMEDOUT)) {
struct timespec ts = { 0 };
qemu_timeval tv;
qemu_gettimeofday(&tv);
ts.tv_sec = tv.tv_sec + 10;
ret = pthread_cond_timedwait(&cond, &lock, &ts);
}
if (ret == ETIMEDOUT)
break;
aiocb = TAILQ_FIRST(&request_list);
TAILQ_REMOVE(&request_list, aiocb, node);
offset = 0;
aiocb->active = 1;
idle_threads--;
pthread_mutex_unlock(&lock);
while (offset < aiocb->aio_nbytes) {
ssize_t len;
if (aiocb->is_write)
len = pwrite(aiocb->aio_fildes,
(const char *)aiocb->aio_buf + offset,
aiocb->aio_nbytes - offset,
aiocb->aio_offset + offset);
else
len = pread(aiocb->aio_fildes,
(char *)aiocb->aio_buf + offset,
aiocb->aio_nbytes - offset,
aiocb->aio_offset + offset);
if (len == -1 && errno == EINTR)
continue;
else if (len == -1) {
pthread_mutex_lock(&lock);
aiocb->ret = -errno;
pthread_mutex_unlock(&lock);
break;
} else if (len == 0)
break;
offset += len;
pthread_mutex_lock(&lock);
aiocb->ret = offset;
pthread_mutex_unlock(&lock);
}
pthread_mutex_lock(&lock);
idle_threads++;
pthread_mutex_unlock(&lock);
sigqueue(getpid(),
aiocb->aio_sigevent.sigev_signo,
aiocb->aio_sigevent.sigev_value);
}
idle_threads--;
cur_threads--;
pthread_mutex_unlock(&lock);
return NULL;
}
| true | qemu | f094a78220187996e33ba5adce29789326cf6c3c |
5,940 | int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
int max_size)
{
uint32_t mrk;
int i, tmp;
const uint16_t *ssrc = (const uint16_t *) src;
uint16_t *sdst = (uint16_t *) dst;
PutBitContext pb;
if ((unsigned) src_size > (unsigned) max_size)
src_size = max_size;
mrk = AV_RB32(src);
switch (mrk) {
case DCA_SYNCWORD_CORE_BE:
memcpy(dst, src, src_size);
return src_size;
case DCA_SYNCWORD_CORE_LE:
for (i = 0; i < (src_size + 1) >> 1; i++)
*sdst++ = av_bswap16(*ssrc++);
return src_size;
case DCA_SYNCWORD_CORE_14B_BE:
case DCA_SYNCWORD_CORE_14B_LE:
init_put_bits(&pb, dst, max_size);
for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
tmp = ((mrk == DCA_SYNCWORD_CORE_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
put_bits(&pb, 14, tmp);
}
flush_put_bits(&pb);
return (put_bits_count(&pb) + 7) >> 3;
default:
return AVERROR_INVALIDDATA;
}
}
| true | FFmpeg | b06cb15b9d7928bf54b639c9f9f7658c2c38bfb9 |
5,941 | av_cold void ff_vp8dsp_init_arm(VP8DSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (have_armv6(cpu_flags))
ff_vp8dsp_init_armv6(dsp);
if (have_neon(cpu_flags))
ff_vp8dsp_init_neon(dsp);
}
| false | FFmpeg | b8664c929437d6d079e16979c496a2db40cf2324 |
5,942 | static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
G723_1_Context *p = avctx->priv_data;
int16_t unq_lpc[LPC_ORDER * SUBFRAMES];
int16_t qnt_lpc[LPC_ORDER * SUBFRAMES];
int16_t cur_lsp[LPC_ORDER];
int16_t weighted_lpc[LPC_ORDER * SUBFRAMES << 1];
int16_t vector[FRAME_LEN + PITCH_MAX];
int offset, ret;
int16_t *in = (const int16_t *)frame->data[0];
HFParam hf[4];
int i, j;
highpass_filter(in, &p->hpf_fir_mem, &p->hpf_iir_mem);
memcpy(vector, p->prev_data, HALF_FRAME_LEN * sizeof(int16_t));
memcpy(vector + HALF_FRAME_LEN, in, FRAME_LEN * sizeof(int16_t));
comp_lpc_coeff(vector, unq_lpc);
lpc2lsp(&unq_lpc[LPC_ORDER * 3], p->prev_lsp, cur_lsp);
lsp_quantize(p->lsp_index, cur_lsp, p->prev_lsp);
/* Update memory */
memcpy(vector + LPC_ORDER, p->prev_data + SUBFRAME_LEN,
sizeof(int16_t) * SUBFRAME_LEN);
memcpy(vector + LPC_ORDER + SUBFRAME_LEN, in,
sizeof(int16_t) * (HALF_FRAME_LEN + SUBFRAME_LEN));
memcpy(p->prev_data, in + HALF_FRAME_LEN,
sizeof(int16_t) * HALF_FRAME_LEN);
memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN);
perceptual_filter(p, weighted_lpc, unq_lpc, vector);
memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN);
memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX);
memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN);
scale_vector(vector, vector, FRAME_LEN + PITCH_MAX);
p->pitch_lag[0] = estimate_pitch(vector, PITCH_MAX);
p->pitch_lag[1] = estimate_pitch(vector, PITCH_MAX + HALF_FRAME_LEN);
for (i = PITCH_MAX, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
comp_harmonic_coeff(vector + i, p->pitch_lag[j >> 1], hf + j);
memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX);
memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN);
memcpy(p->prev_weight_sig, vector + FRAME_LEN, sizeof(int16_t) * PITCH_MAX);
for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
harmonic_filter(hf + j, vector + PITCH_MAX + i, in + i);
inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, 0);
lsp_interpolate(qnt_lpc, cur_lsp, p->prev_lsp);
memcpy(p->prev_lsp, cur_lsp, sizeof(int16_t) * LPC_ORDER);
offset = 0;
for (i = 0; i < SUBFRAMES; i++) {
int16_t impulse_resp[SUBFRAME_LEN];
int16_t residual[SUBFRAME_LEN + PITCH_ORDER - 1];
int16_t flt_in[SUBFRAME_LEN];
int16_t zero[LPC_ORDER], fir[LPC_ORDER], iir[LPC_ORDER];
/**
* Compute the combined impulse response of the synthesis filter,
* formant perceptual weighting filter and harmonic noise shaping filter
*/
memset(zero, 0, sizeof(int16_t) * LPC_ORDER);
memset(vector, 0, sizeof(int16_t) * PITCH_MAX);
memset(flt_in, 0, sizeof(int16_t) * SUBFRAME_LEN);
flt_in[0] = 1 << 13; /* Unit impulse */
synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
zero, zero, flt_in, vector + PITCH_MAX, 1);
harmonic_filter(hf + i, vector + PITCH_MAX, impulse_resp);
/* Compute the combined zero input response */
flt_in[0] = 0;
memcpy(fir, p->perf_fir_mem, sizeof(int16_t) * LPC_ORDER);
memcpy(iir, p->perf_iir_mem, sizeof(int16_t) * LPC_ORDER);
synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
fir, iir, flt_in, vector + PITCH_MAX, 0);
memcpy(vector, p->harmonic_mem, sizeof(int16_t) * PITCH_MAX);
harmonic_noise_sub(hf + i, vector + PITCH_MAX, in);
acb_search(p, residual, impulse_resp, in, i);
gen_acb_excitation(residual, p->prev_excitation,p->pitch_lag[i >> 1],
&p->subframe[i], p->cur_rate);
sub_acb_contrib(residual, impulse_resp, in);
fcb_search(p, impulse_resp, in, i);
/* Reconstruct the excitation */
gen_acb_excitation(impulse_resp, p->prev_excitation, p->pitch_lag[i >> 1],
&p->subframe[i], RATE_6300);
memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN,
sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
for (j = 0; j < SUBFRAME_LEN; j++)
in[j] = av_clip_int16((in[j] << 1) + impulse_resp[j]);
memcpy(p->prev_excitation + PITCH_MAX - SUBFRAME_LEN, in,
sizeof(int16_t) * SUBFRAME_LEN);
/* Update filter memories */
synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
p->perf_fir_mem, p->perf_iir_mem,
in, vector + PITCH_MAX, 0);
memmove(p->harmonic_mem, p->harmonic_mem + SUBFRAME_LEN,
sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
memcpy(p->harmonic_mem + PITCH_MAX - SUBFRAME_LEN, vector + PITCH_MAX,
sizeof(int16_t) * SUBFRAME_LEN);
in += SUBFRAME_LEN;
offset += LPC_ORDER;
}
if ((ret = ff_alloc_packet2(avctx, avpkt, 24)))
return ret;
*got_packet_ptr = 1;
avpkt->size = pack_bitstream(p, avpkt->data, avpkt->size);
return 0;
}
| false | FFmpeg | bcaf64b605442e1622d16da89d4ec0e7730b8a8c |
5,943 | void ff_wmv2_idct_c(short * block){
int i;
for(i=0;i<64;i+=8){
wmv2_idct_row(block+i);
}
for(i=0;i<8;i++){
wmv2_idct_col(block+i);
}
}
| true | FFmpeg | e6bc38fd49c94726b45d5d5cc2b756ad8ec49ee0 |
5,944 | type_init(parallel_register_types)
static bool parallel_init(ISABus *bus, int index, CharDriverState *chr)
{
DeviceState *dev;
ISADevice *isadev;
isadev = isa_try_create(bus, "isa-parallel");
if (!isadev) {
return false;
}
dev = DEVICE(isadev);
qdev_prop_set_uint32(dev, "index", index);
qdev_prop_set_chr(dev, "chardev", chr);
if (qdev_init(dev) < 0) {
return false;
}
return true;
}
| true | qemu | 4bc6a3e54e06c47b8e23bfa3d873fa2f42dfec02 |
5,945 | static void ehci_execute_complete(EHCIQueue *q)
{
EHCIPacket *p = QTAILQ_FIRST(&q->packets);
assert(p != NULL);
assert(p->qtdaddr == q->qtdaddr);
assert(p->async != EHCI_ASYNC_INFLIGHT);
p->async = EHCI_ASYNC_NONE;
DPRINTF("execute_complete: qhaddr 0x%x, next %x, qtdaddr 0x%x, status %d\n",
q->qhaddr, q->qh.next, q->qtdaddr, q->usb_status);
if (p->usb_status < 0) {
switch (p->usb_status) {
case USB_RET_IOERROR:
case USB_RET_NODEV:
q->qh.token |= (QTD_TOKEN_HALT | QTD_TOKEN_XACTERR);
set_field(&q->qh.token, 0, QTD_TOKEN_CERR);
ehci_record_interrupt(q->ehci, USBSTS_ERRINT);
break;
case USB_RET_STALL:
q->qh.token |= QTD_TOKEN_HALT;
ehci_record_interrupt(q->ehci, USBSTS_ERRINT);
break;
case USB_RET_NAK:
set_field(&q->qh.altnext_qtd, 0, QH_ALTNEXT_NAKCNT);
return; /* We're not done yet with this transaction */
case USB_RET_BABBLE:
q->qh.token |= (QTD_TOKEN_HALT | QTD_TOKEN_BABBLE);
ehci_record_interrupt(q->ehci, USBSTS_ERRINT);
break;
default:
/* should not be triggerable */
fprintf(stderr, "USB invalid response %d\n", p->usb_status);
assert(0);
break;
}
} else if ((p->usb_status > p->tbytes) && (p->pid == USB_TOKEN_IN)) {
p->usb_status = USB_RET_BABBLE;
q->qh.token |= (QTD_TOKEN_HALT | QTD_TOKEN_BABBLE);
ehci_record_interrupt(q->ehci, USBSTS_ERRINT);
} else {
// TODO check 4.12 for splits
if (p->tbytes && p->pid == USB_TOKEN_IN) {
p->tbytes -= p->usb_status;
} else {
p->tbytes = 0;
}
DPRINTF("updating tbytes to %d\n", p->tbytes);
set_field(&q->qh.token, p->tbytes, QTD_TOKEN_TBYTES);
}
ehci_finish_transfer(q, p->usb_status);
qemu_sglist_destroy(&p->sgl);
usb_packet_unmap(&p->packet);
q->qh.token ^= QTD_TOKEN_DTOGGLE;
q->qh.token &= ~QTD_TOKEN_ACTIVE;
if (q->qh.token & QTD_TOKEN_IOC) {
ehci_record_interrupt(q->ehci, USBSTS_INT);
}
}
| true | qemu | e2f89926f19d2940eda070542501f39f51a8c81f |
5,946 | static void vector_fmul_reverse_vfp(float *dst, const float *src0, const float *src1, int len)
{
src1 += len;
asm volatile(
"fldmdbs %[src1]!, {s0-s3}\n\t"
"fldmias %[src0]!, {s8-s11}\n\t"
"fldmdbs %[src1]!, {s4-s7}\n\t"
"fldmias %[src0]!, {s12-s15}\n\t"
"fmuls s8, s3, s8\n\t"
"fmuls s9, s2, s9\n\t"
"fmuls s10, s1, s10\n\t"
"fmuls s11, s0, s11\n\t"
"1:\n\t"
"subs %[len], %[len], #16\n\t"
"fldmdbsge %[src1]!, {s16-s19}\n\t"
"fmuls s12, s7, s12\n\t"
"fldmiasge %[src0]!, {s24-s27}\n\t"
"fmuls s13, s6, s13\n\t"
"fldmdbsge %[src1]!, {s20-s23}\n\t"
"fmuls s14, s5, s14\n\t"
"fldmiasge %[src0]!, {s28-s31}\n\t"
"fmuls s15, s4, s15\n\t"
"fmulsge s24, s19, s24\n\t"
"fldmdbsgt %[src1]!, {s0-s3}\n\t"
"fmulsge s25, s18, s25\n\t"
"fstmias %[dst]!, {s8-s13}\n\t"
"fmulsge s26, s17, s26\n\t"
"fldmiasgt %[src0]!, {s8-s11}\n\t"
"fmulsge s27, s16, s27\n\t"
"fmulsge s28, s23, s28\n\t"
"fldmdbsgt %[src1]!, {s4-s7}\n\t"
"fmulsge s29, s22, s29\n\t"
"fstmias %[dst]!, {s14-s15}\n\t"
"fmulsge s30, s21, s30\n\t"
"fmulsge s31, s20, s31\n\t"
"fmulsge s8, s3, s8\n\t"
"fldmiasgt %[src0]!, {s12-s15}\n\t"
"fmulsge s9, s2, s9\n\t"
"fmulsge s10, s1, s10\n\t"
"fstmiasge %[dst]!, {s24-s27}\n\t"
"fmulsge s11, s0, s11\n\t"
"fstmiasge %[dst]!, {s28-s31}\n\t"
"bgt 1b\n\t"
: [dst] "+&r" (dst), [src0] "+&r" (src0), [src1] "+&r" (src1), [len] "+&r" (len)
:
: "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
"s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
"s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
"cc", "memory");
}
| true | FFmpeg | 28215b3700723da0c0beb93945702b6fb2b3596d |
5,947 | static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size)
{
BDRVQcowState *s = bs->opaque;
int i, nb_clusters, refcount;
nb_clusters = size_to_clusters(s, size);
retry:
for(i = 0; i < nb_clusters; i++) {
int64_t next_cluster_index = s->free_cluster_index++;
refcount = get_refcount(bs, next_cluster_index);
if (refcount < 0) {
return refcount;
} else if (refcount != 0) {
goto retry;
}
}
#ifdef DEBUG_ALLOC2
fprintf(stderr, "alloc_clusters: size=%" PRId64 " -> %" PRId64 "\n",
size,
(s->free_cluster_index - nb_clusters) << s->cluster_bits);
#endif
return (s->free_cluster_index - nb_clusters) << s->cluster_bits;
}
| true | qemu | bb572aefbdac290363bfa5ca0e810ccce0a14ed6 |
5,949 | double parse_number_or_die(const char *context, const char *numstr, int type,
double min, double max)
{
char *tail;
const char *error;
double d = av_strtod(numstr, &tail);
if (*tail)
error = "Expected number for %s but found: %s\n";
else if (d < min || d > max)
error = "The value for %s was %s which is not within %f - %f\n";
else if (type == OPT_INT64 && (int64_t)d != d)
error = "Expected int64 for %s but found %s\n";
else if (type == OPT_INT && (int)d != d)
error = "Expected int for %s but found %s\n";
else
return d;
av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
exit(1);
return 0;
}
| true | FFmpeg | 636ced8e1dc8248a1353b416240b93d70ad03edb |
5,950 | static int qemu_rbd_snap_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_tab)
{
BDRVRBDState *s = bs->opaque;
QEMUSnapshotInfo *sn_info, *sn_tab = NULL;
int i, snap_count;
rbd_snap_info_t *snaps;
int max_snaps = RBD_MAX_SNAPS;
do {
snaps = g_malloc(sizeof(*snaps) * max_snaps);
snap_count = rbd_snap_list(s->image, snaps, &max_snaps);
if (snap_count <= 0) {
g_free(snaps);
}
} while (snap_count == -ERANGE);
if (snap_count <= 0) {
goto done;
}
sn_tab = g_malloc0(snap_count * sizeof(QEMUSnapshotInfo));
for (i = 0; i < snap_count; i++) {
const char *snap_name = snaps[i].name;
sn_info = sn_tab + i;
pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), snap_name);
pstrcpy(sn_info->name, sizeof(sn_info->name), snap_name);
sn_info->vm_state_size = snaps[i].size;
sn_info->date_sec = 0;
sn_info->date_nsec = 0;
sn_info->vm_clock_nsec = 0;
}
rbd_snap_list_end(snaps);
g_free(snaps);
done:
*psn_tab = sn_tab;
return snap_count;
}
| true | qemu | 5839e53bbc0fec56021d758aab7610df421ed8c8 |
5,951 | static void init_fps(int bf, int audio_preroll, int fps)
{
AVStream *st;
ctx = avformat_alloc_context();
if (!ctx)
exit(1);
ctx->oformat = av_guess_format(format, NULL, NULL);
if (!ctx->oformat)
exit(1);
ctx->pb = avio_alloc_context(iobuf, sizeof(iobuf), AVIO_FLAG_WRITE, NULL, NULL, io_write, NULL);
if (!ctx->pb)
exit(1);
ctx->flags |= AVFMT_FLAG_BITEXACT;
st = avformat_new_stream(ctx, NULL);
if (!st)
exit(1);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_H264;
st->codec->width = 640;
st->codec->height = 480;
st->time_base.num = 1;
st->time_base.den = 30;
st->codec->extradata_size = sizeof(h264_extradata);
st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
exit(1);
memcpy(st->codec->extradata, h264_extradata, sizeof(h264_extradata));
st->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
video_st = st;
st = avformat_new_stream(ctx, NULL);
if (!st)
exit(1);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = AV_CODEC_ID_AAC;
st->codec->sample_rate = 44100;
st->codec->channels = 2;
st->time_base.num = 1;
st->time_base.den = 44100;
st->codec->extradata_size = sizeof(aac_extradata);
st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
exit(1);
memcpy(st->codec->extradata, aac_extradata, sizeof(aac_extradata));
st->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
audio_st = st;
if (avformat_write_header(ctx, &opts) < 0)
exit(1);
av_dict_free(&opts);
frames = 0;
gop_size = 30;
duration = video_st->time_base.den / fps;
audio_duration = 1024 * audio_st->time_base.den / audio_st->codec->sample_rate;
if (audio_preroll)
audio_preroll = 2048 * audio_st->time_base.den / audio_st->codec->sample_rate;
bframes = bf;
video_dts = bframes ? -duration : 0;
audio_dts = -audio_preroll;
}
| true | FFmpeg | 5b70fb8fee4af3b13f29a2dc7222fd3c9782f79b |
5,952 | GList *g_list_insert_sorted_merged(GList *list, gpointer data,
GCompareFunc func)
{
GList *l, *next = NULL;
Range *r, *nextr;
if (!list) {
list = g_list_insert_sorted(list, data, func);
return list;
}
nextr = data;
l = list;
while (l && l != next && nextr) {
r = l->data;
if (ranges_can_merge(r, nextr)) {
range_merge(r, nextr);
l = g_list_remove_link(l, next);
next = g_list_next(l);
if (next) {
nextr = next->data;
} else {
nextr = NULL;
}
} else {
l = g_list_next(l);
}
}
if (!l) {
list = g_list_insert_sorted(list, data, func);
}
return list;
}
| true | qemu | 7c47959d0cb05db43014141a156ada0b6d53a750 |
5,953 | static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
int* buf_size, int type,
uint32_t **lace_buf, int *laces)
{
int res = 0, n, size = *buf_size;
uint8_t *data = *buf;
uint32_t *lace_size;
if (!type) {
*laces = 1;
*lace_buf = av_mallocz(sizeof(int));
if (!*lace_buf)
return AVERROR(ENOMEM);
*lace_buf[0] = size;
return 0;
}
av_assert0(size > 0);
*laces = *data + 1;
data += 1;
size -= 1;
lace_size = av_mallocz(*laces * sizeof(int));
if (!lace_size)
return AVERROR(ENOMEM);
switch (type) {
case 0x1: /* Xiph lacing */ {
uint8_t temp;
uint32_t total = 0;
for (n = 0; res == 0 && n < *laces - 1; n++) {
while (1) {
if (size == 0) {
res = AVERROR_INVALIDDATA;
break;
}
temp = *data;
lace_size[n] += temp;
data += 1;
size -= 1;
if (temp != 0xff)
break;
}
total += lace_size[n];
}
if (size <= total) {
res = AVERROR_INVALIDDATA;
break;
}
lace_size[n] = size - total;
break;
}
case 0x2: /* fixed-size lacing */
if (size % (*laces)) {
res = AVERROR_INVALIDDATA;
break;
}
for (n = 0; n < *laces; n++)
lace_size[n] = size / *laces;
break;
case 0x3: /* EBML lacing */ {
uint64_t num;
uint64_t total;
n = matroska_ebmlnum_uint(matroska, data, size, &num);
if (n < 0) {
av_log(matroska->ctx, AV_LOG_INFO,
"EBML block data error\n");
res = n;
break;
}
data += n;
size -= n;
total = lace_size[0] = num;
for (n = 1; res == 0 && n < *laces - 1; n++) {
int64_t snum;
int r;
r = matroska_ebmlnum_sint(matroska, data, size, &snum);
if (r < 0) {
av_log(matroska->ctx, AV_LOG_INFO,
"EBML block data error\n");
res = r;
break;
}
data += r;
size -= r;
lace_size[n] = lace_size[n - 1] + snum;
total += lace_size[n];
}
if (size <= total) {
res = AVERROR_INVALIDDATA;
break;
}
lace_size[*laces - 1] = size - total;
break;
}
}
*buf = data;
*lace_buf = lace_size;
*buf_size = size;
return res;
}
| true | FFmpeg | 115c3bc41f24185477de7e012b799e47693e3b5e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.