project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
qemu | 64d7e9a421fea0ac50b44541f5521de455e7cd5d | 0 | int pit_get_initial_count(PITState *pit, int channel)
{
PITChannelState *s = &pit->channels[channel];
return s->count;
}
| 9,569 |
qemu | 6e99c631f116221d169ea53953d91b8aa74d297a | 0 | static void net_socket_update_fd_handler(NetSocketState *s)
{
qemu_set_fd_handler2(s->fd,
s->read_poll ? net_socket_can_send : NULL,
s->read_poll ? s->send_fn : NULL,
s->write_poll ? net_socket_writable : NULL,
s);
}
| 9,570 |
qemu | 61007b316cd71ee7333ff7a0a749a8949527575f | 0 | static void bdrv_throttle_read_timer_cb(void *opaque)
{
BlockDriverState *bs = opaque;
qemu_co_enter_next(&bs->throttled_reqs[0]);
}
| 9,571 |
qemu | 104494ea25ef6286d79e2f17d609f7ef4cd2dcce | 0 | static void host_x86_cpu_initfn(Object *obj)
{
X86CPU *cpu = X86_CPU(obj);
CPUX86State *env = &cpu->env;
KVMState *s = kvm_state;
/* We can't fill the features array here because we don't know yet if
* "migratable" is true or false.
*/
cpu->host_features = true;
/* If KVM is disabled, cpu_x86_create() will already report an error */
if (kvm_enabled()) {
env->cpuid_level = kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX);
env->cpuid_xlevel = kvm_arch_get_supported_cpuid(s, 0x80000000, 0, R_EAX);
env->cpuid_xlevel2 = kvm_arch_get_supported_cpuid(s, 0xC0000000, 0, R_EAX);
}
object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort);
}
| 9,572 |
qemu | 594a53607e5bd4a2b7555a7a2908d2c406fea9aa | 0 | void usb_device_attach(USBDevice *dev, Error **errp)
{
USBBus *bus = usb_bus_from_device(dev);
USBPort *port = dev->port;
char devspeed[32], portspeed[32];
assert(port != NULL);
assert(!dev->attached);
usb_mask_to_str(devspeed, sizeof(devspeed), dev->speedmask);
usb_mask_to_str(portspeed, sizeof(portspeed), port->speedmask);
trace_usb_port_attach(bus->busnr, port->path,
devspeed, portspeed);
if (!(port->speedmask & dev->speedmask)) {
error_setg(errp, "Warning: speed mismatch trying to attach"
" usb device \"%s\" (%s speed)"
" to bus \"%s\", port \"%s\" (%s speed)",
dev->product_desc, devspeed,
bus->qbus.name, port->path, portspeed);
return;
}
dev->attached++;
usb_attach(port);
}
| 9,573 |
qemu | 42a268c241183877192c376d03bd9b6d527407c7 | 0 | static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
TCGv_i32 addr, int size)
{
TCGv_i32 tmp;
TCGv_i64 val64, extaddr;
int done_label;
int fail_label;
/* if (env->exclusive_addr == addr && env->exclusive_val == [addr]) {
[addr] = {Rt};
{Rd} = 0;
} else {
{Rd} = 1;
} */
fail_label = gen_new_label();
done_label = gen_new_label();
extaddr = tcg_temp_new_i64();
tcg_gen_extu_i32_i64(extaddr, addr);
tcg_gen_brcond_i64(TCG_COND_NE, extaddr, cpu_exclusive_addr, fail_label);
tcg_temp_free_i64(extaddr);
tmp = tcg_temp_new_i32();
switch (size) {
case 0:
gen_aa32_ld8u(tmp, addr, get_mem_index(s));
break;
case 1:
gen_aa32_ld16u(tmp, addr, get_mem_index(s));
break;
case 2:
case 3:
gen_aa32_ld32u(tmp, addr, get_mem_index(s));
break;
default:
abort();
}
val64 = tcg_temp_new_i64();
if (size == 3) {
TCGv_i32 tmp2 = tcg_temp_new_i32();
TCGv_i32 tmp3 = tcg_temp_new_i32();
tcg_gen_addi_i32(tmp2, addr, 4);
gen_aa32_ld32u(tmp3, tmp2, get_mem_index(s));
tcg_temp_free_i32(tmp2);
tcg_gen_concat_i32_i64(val64, tmp, tmp3);
tcg_temp_free_i32(tmp3);
} else {
tcg_gen_extu_i32_i64(val64, tmp);
}
tcg_temp_free_i32(tmp);
tcg_gen_brcond_i64(TCG_COND_NE, val64, cpu_exclusive_val, fail_label);
tcg_temp_free_i64(val64);
tmp = load_reg(s, rt);
switch (size) {
case 0:
gen_aa32_st8(tmp, addr, get_mem_index(s));
break;
case 1:
gen_aa32_st16(tmp, addr, get_mem_index(s));
break;
case 2:
case 3:
gen_aa32_st32(tmp, addr, get_mem_index(s));
break;
default:
abort();
}
tcg_temp_free_i32(tmp);
if (size == 3) {
tcg_gen_addi_i32(addr, addr, 4);
tmp = load_reg(s, rt2);
gen_aa32_st32(tmp, addr, get_mem_index(s));
tcg_temp_free_i32(tmp);
}
tcg_gen_movi_i32(cpu_R[rd], 0);
tcg_gen_br(done_label);
gen_set_label(fail_label);
tcg_gen_movi_i32(cpu_R[rd], 1);
gen_set_label(done_label);
tcg_gen_movi_i64(cpu_exclusive_addr, -1);
}
| 9,575 |
qemu | 96165b9eb4207a34a87c46df731d3cc42c052e13 | 0 | static int gdbserver_open(int port)
{
struct sockaddr_in sockaddr;
int fd, ret;
fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
return -1;
}
#ifndef _WIN32
fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif
socket_set_fast_reuse(fd);
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(port);
sockaddr.sin_addr.s_addr = 0;
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
if (ret < 0) {
perror("bind");
close(fd);
return -1;
}
ret = listen(fd, 0);
if (ret < 0) {
perror("listen");
close(fd);
return -1;
}
return fd;
}
| 9,578 |
qemu | 2b584959ed300ddff4acba0d7554becad5f274fd | 0 | void bdrv_get_geometry_hint(BlockDriverState *bs,
int *pcyls, int *pheads, int *psecs)
{
*pcyls = bs->cyls;
*pheads = bs->heads;
*psecs = bs->secs;
}
| 9,580 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint64_t arm_thiswdog_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
arm_mptimer_state *s = (arm_mptimer_state *)opaque;
int id = get_current_cpu(s);
return timerblock_read(&s->timerblock[id * 2 + 1], addr, size);
}
| 9,581 |
qemu | d7a4155265416a1c8f3067b59e68bf5fda1d6215 | 0 | e1000_set_link_status(NetClientState *nc)
{
E1000State *s = qemu_get_nic_opaque(nc);
uint32_t old_status = s->mac_reg[STATUS];
if (nc->link_down) {
e1000_link_down(s);
} else {
if (s->compat_flags & E1000_FLAG_AUTONEG &&
s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN &&
s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG &&
!(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) {
/* emulate auto-negotiation if supported */
timer_mod(s->autoneg_timer,
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
} else {
e1000_link_up(s);
}
}
if (s->mac_reg[STATUS] != old_status)
set_ics(s, 0, E1000_ICR_LSC);
}
| 9,582 |
FFmpeg | c988f97566cdf536ba0dcbc0d77d885456852060 | 0 | static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple){
MpegEncContext * const s = &h->s;
int i;
int step = 1;
int offset = 1;
int uvoffset= 1;
int top_idx = 1;
int skiplast= 0;
src_y -= linesize;
src_cb -= uvlinesize;
src_cr -= uvlinesize;
if(!simple && FRAME_MBAFF){
if(s->mb_y&1){
offset = MB_MBAFF ? 1 : 17;
uvoffset= MB_MBAFF ? 1 : 9;
if(!MB_MBAFF){
*(uint64_t*)(h->top_borders[0][s->mb_x]+ 0)= *(uint64_t*)(src_y + 15*linesize);
*(uint64_t*)(h->top_borders[0][s->mb_x]+ 8)= *(uint64_t*)(src_y +8+15*linesize);
if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
*(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+7*uvlinesize);
*(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+7*uvlinesize);
}
}
}else{
if(!MB_MBAFF){
h->left_border[0]= h->top_borders[0][s->mb_x][15];
if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7 ];
h->left_border[34+18]= h->top_borders[0][s->mb_x][16+8+7];
}
skiplast= 1;
}
offset =
uvoffset=
top_idx = MB_MBAFF ? 0 : 1;
}
step= MB_MBAFF ? 2 : 1;
}
// There are two lines saved, the line above the the top macroblock of a pair,
// and the line above the bottom macroblock
h->left_border[offset]= h->top_borders[top_idx][s->mb_x][15];
for(i=1; i<17 - skiplast; i++){
h->left_border[offset+i*step]= src_y[15+i* linesize];
}
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize);
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize);
if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
h->left_border[uvoffset+34 ]= h->top_borders[top_idx][s->mb_x][16+7];
h->left_border[uvoffset+34+18]= h->top_borders[top_idx][s->mb_x][24+7];
for(i=1; i<9 - skiplast; i++){
h->left_border[uvoffset+34 +i*step]= src_cb[7+i*uvlinesize];
h->left_border[uvoffset+34+18+i*step]= src_cr[7+i*uvlinesize];
}
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+16)= *(uint64_t*)(src_cb+8*uvlinesize);
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+24)= *(uint64_t*)(src_cr+8*uvlinesize);
}
}
| 9,587 |
qemu | 30fd3e27907dfd1c0c66cc1339657af1a2ce1d4b | 0 | static ssize_t qio_channel_file_readv(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
int **fds,
size_t *nfds,
Error **errp)
{
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
ssize_t ret;
retry:
ret = readv(fioc->fd, iov, niov);
if (ret < 0) {
if (errno == EAGAIN ||
errno == EWOULDBLOCK) {
return QIO_CHANNEL_ERR_BLOCK;
}
if (errno == EINTR) {
goto retry;
}
error_setg_errno(errp, errno,
"Unable to read from file");
return -1;
}
return ret;
}
| 9,588 |
qemu | 059bca46bbfd7f16cd2ccca631b91334e08d9abb | 0 | int mmap_frag(unsigned long host_start,
unsigned long start, unsigned long end,
int prot, int flags, int fd, unsigned long offset)
{
unsigned long host_end, ret, addr;
int prot1, prot_new;
host_end = host_start + qemu_host_page_size;
/* get the protection of the target pages outside the mapping */
prot1 = 0;
for(addr = host_start; addr < host_end; addr++) {
if (addr < start || addr >= end)
prot1 |= page_get_flags(addr);
}
if (prot1 == 0) {
/* no page was there, so we allocate one */
ret = (long)mmap((void *)host_start, qemu_host_page_size, prot,
flags | MAP_ANONYMOUS, -1, 0);
if (ret == -1)
return ret;
}
prot1 &= PAGE_BITS;
prot_new = prot | prot1;
if (!(flags & MAP_ANONYMOUS)) {
/* msync() won't work here, so we return an error if write is
possible while it is a shared mapping */
#ifndef __APPLE__
if ((flags & MAP_TYPE) == MAP_SHARED &&
#else
if ((flags & MAP_SHARED) &&
#endif
(prot & PROT_WRITE))
return -EINVAL;
/* adjust protection to be able to read */
if (!(prot1 & PROT_WRITE))
mprotect((void *)host_start, qemu_host_page_size, prot1 | PROT_WRITE);
/* read the corresponding file data */
pread(fd, (void *)start, end - start, offset);
/* put final protection */
if (prot_new != (prot1 | PROT_WRITE))
mprotect((void *)host_start, qemu_host_page_size, prot_new);
} else {
/* just update the protection */
if (prot_new != prot1) {
mprotect((void *)host_start, qemu_host_page_size, prot_new);
}
}
return 0;
}
| 9,589 |
FFmpeg | 851ded8918c977d8160c6617b69604f758cabf50 | 0 | static int decode_cabac_field_decoding_flag(H264Context *h) {
MpegEncContext * const s = &h->s;
const int mb_x = s->mb_x;
const int mb_y = s->mb_y & ~1;
const int mba_xy = mb_x - 1 + mb_y *s->mb_stride;
const int mbb_xy = mb_x + (mb_y-2)*s->mb_stride;
unsigned int ctx = 0;
if( h->slice_table[mba_xy] == h->slice_num && IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) ) {
ctx += 1;
}
if( h->slice_table[mbb_xy] == h->slice_num && IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) ) {
ctx += 1;
}
return get_cabac( &h->cabac, &h->cabac_state[70 + ctx] );
}
| 9,590 |
FFmpeg | ad3b6fa7d83db7de951ed891649af93a47e74be5 | 0 | static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
uint8_t *dstPtr= dst[0];
const uint8_t *srcPtr= src[0];
int i;
void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
switch(c->srcFormat) {
#define CASE(pixfmt, prefix) \
case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
interpolate = bayer_##prefix##_to_rgb24_interpolate; \
break;
CASE(AV_PIX_FMT_BAYER_BGGR8, bggr8)
CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
CASE(AV_PIX_FMT_BAYER_RGGB8, rggb8)
CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
CASE(AV_PIX_FMT_BAYER_GBRG8, gbrg8)
CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
CASE(AV_PIX_FMT_BAYER_GRBG8, grbg8)
CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
#undef CASE
default: return 0;
}
copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
srcPtr += 2 * srcStride[0];
dstPtr += 2 * dstStride[0];
for (i = 2; i < srcSliceH - 2; i += 2) {
interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
srcPtr += 2 * srcStride[0];
dstPtr += 2 * dstStride[0];
}
copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
return srcSliceH;
}
| 9,591 |
FFmpeg | 1d16a1cf99488f16492b1bb48e023f4da8377e07 | 0 | static void ff_h264_idct_add16_mmx(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
int i;
for(i=0; i<16; i++){
if(nnzc[ scan8[i] ])
ff_h264_idct_add_mmx(dst + block_offset[i], block + i*16, stride);
}
}
| 9,592 |
FFmpeg | 3ba056017f978ba69ea933c593f0e616b3632261 | 0 | static char *make_digest_auth(HTTPAuthState *state, const char *username,
const char *password, const char *uri,
const char *method)
{
DigestParams *digest = &state->digest_params;
int len;
uint32_t cnonce_buf[2];
char cnonce[17];
char nc[9];
int i;
char A1hash[33], A2hash[33], response[33];
struct AVMD5 *md5ctx;
uint8_t hash[16];
char *authstr;
digest->nc++;
snprintf(nc, sizeof(nc), "%08x", digest->nc);
/* Generate a client nonce. */
for (i = 0; i < 2; i++)
cnonce_buf[i] = av_get_random_seed();
ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);
cnonce[2*sizeof(cnonce_buf)] = 0;
md5ctx = av_md5_alloc();
if (!md5ctx)
return NULL;
av_md5_init(md5ctx);
update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL);
av_md5_final(md5ctx, hash);
ff_data_to_hex(A1hash, hash, 16, 1);
A1hash[32] = 0;
if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {
} else if (!strcmp(digest->algorithm, "MD5-sess")) {
av_md5_init(md5ctx);
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL);
av_md5_final(md5ctx, hash);
ff_data_to_hex(A1hash, hash, 16, 1);
A1hash[32] = 0;
} else {
/* Unsupported algorithm */
av_free(md5ctx);
return NULL;
}
av_md5_init(md5ctx);
update_md5_strings(md5ctx, method, ":", uri, NULL);
av_md5_final(md5ctx, hash);
ff_data_to_hex(A2hash, hash, 16, 1);
A2hash[32] = 0;
av_md5_init(md5ctx);
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);
if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) {
update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, NULL);
}
update_md5_strings(md5ctx, ":", A2hash, NULL);
av_md5_final(md5ctx, hash);
ff_data_to_hex(response, hash, 16, 1);
response[32] = 0;
av_free(md5ctx);
if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) {
} else if (!strcmp(digest->qop, "auth-int")) {
/* qop=auth-int not supported */
return NULL;
} else {
/* Unsupported qop value. */
return NULL;
}
len = strlen(username) + strlen(state->realm) + strlen(digest->nonce) +
strlen(uri) + strlen(response) + strlen(digest->algorithm) +
strlen(digest->opaque) + strlen(digest->qop) + strlen(cnonce) +
strlen(nc) + 150;
authstr = av_malloc(len);
if (!authstr)
return NULL;
snprintf(authstr, len, "Authorization: Digest ");
/* TODO: Escape the quoted strings properly. */
av_strlcatf(authstr, len, "username=\"%s\"", username);
av_strlcatf(authstr, len, ",realm=\"%s\"", state->realm);
av_strlcatf(authstr, len, ",nonce=\"%s\"", digest->nonce);
av_strlcatf(authstr, len, ",uri=\"%s\"", uri);
av_strlcatf(authstr, len, ",response=\"%s\"", response);
if (digest->algorithm[0])
av_strlcatf(authstr, len, ",algorithm=%s", digest->algorithm);
if (digest->opaque[0])
av_strlcatf(authstr, len, ",opaque=\"%s\"", digest->opaque);
if (digest->qop[0]) {
av_strlcatf(authstr, len, ",qop=\"%s\"", digest->qop);
av_strlcatf(authstr, len, ",cnonce=\"%s\"", cnonce);
av_strlcatf(authstr, len, ",nc=%s", nc);
}
av_strlcatf(authstr, len, "\r\n");
return authstr;
}
| 9,593 |
FFmpeg | 28215b3700723da0c0beb93945702b6fb2b3596d | 1 | static void vector_fmul_vfp(float *dst, const float *src, int len)
{
int tmp;
asm volatile(
"fmrx %[tmp], fpscr\n\t"
"orr %[tmp], %[tmp], #(3 << 16)\n\t" /* set vector size to 4 */
"fmxr fpscr, %[tmp]\n\t"
"fldmias %[dst_r]!, {s0-s3}\n\t"
"fldmias %[src]!, {s8-s11}\n\t"
"fldmias %[dst_r]!, {s4-s7}\n\t"
"fldmias %[src]!, {s12-s15}\n\t"
"fmuls s8, s0, s8\n\t"
"1:\n\t"
"subs %[len], %[len], #16\n\t"
"fmuls s12, s4, s12\n\t"
"fldmiasge %[dst_r]!, {s16-s19}\n\t"
"fldmiasge %[src]!, {s24-s27}\n\t"
"fldmiasge %[dst_r]!, {s20-s23}\n\t"
"fldmiasge %[src]!, {s28-s31}\n\t"
"fmulsge s24, s16, s24\n\t"
"fstmias %[dst_w]!, {s8-s11}\n\t"
"fstmias %[dst_w]!, {s12-s15}\n\t"
"fmulsge s28, s20, s28\n\t"
"fldmiasgt %[dst_r]!, {s0-s3}\n\t"
"fldmiasgt %[src]!, {s8-s11}\n\t"
"fldmiasgt %[dst_r]!, {s4-s7}\n\t"
"fldmiasgt %[src]!, {s12-s15}\n\t"
"fmulsge s8, s0, s8\n\t"
"fstmiasge %[dst_w]!, {s24-s27}\n\t"
"fstmiasge %[dst_w]!, {s28-s31}\n\t"
"bgt 1b\n\t"
"bic %[tmp], %[tmp], #(7 << 16)\n\t" /* set vector size back to 1 */
"fmxr fpscr, %[tmp]\n\t"
: [dst_w] "+&r" (dst), [dst_r] "+&r" (dst), [src] "+&r" (src), [len] "+&r" (len), [tmp] "=&r" (tmp)
:
: "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");
}
| 9,594 |
qemu | 9ed5726c043958359b0f1fa44ab3e4f25f9d9a47 | 1 | static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch)
{
int32_t offset;
int rs, rt, rd, sa;
uint32_t op, op1, op2;
int16_t imm;
/* make sure instructions are on a word boundary */
if (ctx->pc & 0x3) {
env->CP0_BadVAddr = ctx->pc;
generate_exception(ctx, EXCP_AdEL);
return;
}
/* Handle blikely not taken case */
if ((ctx->hflags & MIPS_HFLAG_BMASK_BASE) == MIPS_HFLAG_BL) {
int l1 = gen_new_label();
MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
tcg_gen_movi_i32(hflags, ctx->hflags & ~MIPS_HFLAG_BMASK);
gen_goto_tb(ctx, 1, ctx->pc + 4);
gen_set_label(l1);
}
if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
tcg_gen_debug_insn_start(ctx->pc);
op = MASK_OP_MAJOR(ctx->opcode);
rs = (ctx->opcode >> 21) & 0x1f;
rt = (ctx->opcode >> 16) & 0x1f;
rd = (ctx->opcode >> 11) & 0x1f;
sa = (ctx->opcode >> 6) & 0x1f;
imm = (int16_t)ctx->opcode;
switch (op) {
case OPC_SPECIAL:
op1 = MASK_SPECIAL(ctx->opcode);
switch (op1) {
case OPC_SLL: /* Shift with immediate */
case OPC_SRA:
gen_shift_imm(env, ctx, op1, rd, rt, sa);
break;
case OPC_SRL:
switch ((ctx->opcode >> 21) & 0x1f) {
case 1:
/* rotr is decoded as srl on non-R2 CPUs */
if (env->insn_flags & ISA_MIPS32R2) {
op1 = OPC_ROTR;
}
/* Fallthrough */
case 0:
gen_shift_imm(env, ctx, op1, rd, rt, sa);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_MOVN: /* Conditional move */
case OPC_MOVZ:
check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32 |
INSN_LOONGSON2E | INSN_LOONGSON2F);
gen_cond_move(env, op1, rd, rs, rt);
break;
case OPC_ADD ... OPC_SUBU:
gen_arith(env, ctx, op1, rd, rs, rt);
break;
case OPC_SLLV: /* Shifts */
case OPC_SRAV:
gen_shift(env, ctx, op1, rd, rs, rt);
break;
case OPC_SRLV:
switch ((ctx->opcode >> 6) & 0x1f) {
case 1:
/* rotrv is decoded as srlv on non-R2 CPUs */
if (env->insn_flags & ISA_MIPS32R2) {
op1 = OPC_ROTRV;
}
/* Fallthrough */
case 0:
gen_shift(env, ctx, op1, rd, rs, rt);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_SLT: /* Set on less than */
case OPC_SLTU:
gen_slt(env, op1, rd, rs, rt);
break;
case OPC_AND: /* Logic*/
case OPC_OR:
case OPC_NOR:
case OPC_XOR:
gen_logic(env, op1, rd, rs, rt);
break;
case OPC_MULT ... OPC_DIVU:
if (sa) {
check_insn(env, ctx, INSN_VR54XX);
op1 = MASK_MUL_VR54XX(ctx->opcode);
gen_mul_vr54xx(ctx, op1, rd, rs, rt);
} else
gen_muldiv(ctx, op1, rs, rt);
break;
case OPC_JR ... OPC_JALR:
gen_compute_branch(ctx, op1, 4, rs, rd, sa);
*is_branch = 1;
break;
case OPC_TGE ... OPC_TEQ: /* Traps */
case OPC_TNE:
gen_trap(ctx, op1, rs, rt, -1);
break;
case OPC_MFHI: /* Move from HI/LO */
case OPC_MFLO:
gen_HILO(ctx, op1, rd);
break;
case OPC_MTHI:
case OPC_MTLO: /* Move to HI/LO */
gen_HILO(ctx, op1, rs);
break;
case OPC_PMON: /* Pmon entry point, also R4010 selsl */
#ifdef MIPS_STRICT_STANDARD
MIPS_INVAL("PMON / selsl");
generate_exception(ctx, EXCP_RI);
#else
gen_helper_0i(pmon, sa);
#endif
break;
case OPC_SYSCALL:
generate_exception(ctx, EXCP_SYSCALL);
ctx->bstate = BS_STOP;
break;
case OPC_BREAK:
generate_exception(ctx, EXCP_BREAK);
break;
case OPC_SPIM:
#ifdef MIPS_STRICT_STANDARD
MIPS_INVAL("SPIM");
generate_exception(ctx, EXCP_RI);
#else
/* Implemented as RI exception for now. */
MIPS_INVAL("spim (unofficial)");
generate_exception(ctx, EXCP_RI);
#endif
break;
case OPC_SYNC:
/* Treat as NOP. */
break;
case OPC_MOVCI:
check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
if (env->CP0_Config1 & (1 << CP0C1_FP)) {
check_cp1_enabled(ctx);
gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
(ctx->opcode >> 16) & 1);
} else {
generate_exception_err(ctx, EXCP_CpU, 1);
}
break;
#if defined(TARGET_MIPS64)
/* MIPS64 specific opcodes */
case OPC_DSLL:
case OPC_DSRA:
case OPC_DSLL32:
case OPC_DSRA32:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_shift_imm(env, ctx, op1, rd, rt, sa);
break;
case OPC_DSRL:
switch ((ctx->opcode >> 21) & 0x1f) {
case 1:
/* drotr is decoded as dsrl on non-R2 CPUs */
if (env->insn_flags & ISA_MIPS32R2) {
op1 = OPC_DROTR;
}
/* Fallthrough */
case 0:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_shift_imm(env, ctx, op1, rd, rt, sa);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_DSRL32:
switch ((ctx->opcode >> 21) & 0x1f) {
case 1:
/* drotr32 is decoded as dsrl32 on non-R2 CPUs */
if (env->insn_flags & ISA_MIPS32R2) {
op1 = OPC_DROTR32;
}
/* Fallthrough */
case 0:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_shift_imm(env, ctx, op1, rd, rt, sa);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_DADD ... OPC_DSUBU:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_arith(env, ctx, op1, rd, rs, rt);
break;
case OPC_DSLLV:
case OPC_DSRAV:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_shift(env, ctx, op1, rd, rs, rt);
break;
case OPC_DSRLV:
switch ((ctx->opcode >> 6) & 0x1f) {
case 1:
/* drotrv is decoded as dsrlv on non-R2 CPUs */
if (env->insn_flags & ISA_MIPS32R2) {
op1 = OPC_DROTRV;
}
/* Fallthrough */
case 0:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_shift(env, ctx, op1, rd, rs, rt);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_DMULT ... OPC_DDIVU:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_muldiv(ctx, op1, rs, rt);
break;
#endif
default: /* Invalid */
MIPS_INVAL("special");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_SPECIAL2:
op1 = MASK_SPECIAL2(ctx->opcode);
switch (op1) {
case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
case OPC_MSUB ... OPC_MSUBU:
check_insn(env, ctx, ISA_MIPS32);
gen_muldiv(ctx, op1, rs, rt);
break;
case OPC_MUL:
gen_arith(env, ctx, op1, rd, rs, rt);
break;
case OPC_CLO:
case OPC_CLZ:
check_insn(env, ctx, ISA_MIPS32);
gen_cl(ctx, op1, rd, rs);
break;
case OPC_SDBBP:
/* XXX: not clear which exception should be raised
* when in debug mode...
*/
check_insn(env, ctx, ISA_MIPS32);
if (!(ctx->hflags & MIPS_HFLAG_DM)) {
generate_exception(ctx, EXCP_DBp);
} else {
generate_exception(ctx, EXCP_DBp);
}
/* Treat as NOP. */
break;
case OPC_DIV_G_2F:
case OPC_DIVU_G_2F:
case OPC_MULT_G_2F:
case OPC_MULTU_G_2F:
case OPC_MOD_G_2F:
case OPC_MODU_G_2F:
check_insn(env, ctx, INSN_LOONGSON2F);
gen_loongson_integer(ctx, op1, rd, rs, rt);
break;
#if defined(TARGET_MIPS64)
case OPC_DCLO:
case OPC_DCLZ:
check_insn(env, ctx, ISA_MIPS64);
check_mips_64(ctx);
gen_cl(ctx, op1, rd, rs);
break;
case OPC_DMULT_G_2F:
case OPC_DMULTU_G_2F:
case OPC_DDIV_G_2F:
case OPC_DDIVU_G_2F:
case OPC_DMOD_G_2F:
case OPC_DMODU_G_2F:
check_insn(env, ctx, INSN_LOONGSON2F);
gen_loongson_integer(ctx, op1, rd, rs, rt);
break;
#endif
default: /* Invalid */
MIPS_INVAL("special2");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_SPECIAL3:
op1 = MASK_SPECIAL3(ctx->opcode);
switch (op1) {
case OPC_EXT:
case OPC_INS:
check_insn(env, ctx, ISA_MIPS32R2);
gen_bitops(ctx, op1, rt, rs, sa, rd);
break;
case OPC_BSHFL:
check_insn(env, ctx, ISA_MIPS32R2);
op2 = MASK_BSHFL(ctx->opcode);
gen_bshfl(ctx, op2, rt, rd);
break;
case OPC_RDHWR:
gen_rdhwr(env, ctx, rt, rd);
break;
case OPC_FORK:
check_insn(env, ctx, ASE_MT);
{
TCGv t0 = tcg_temp_new();
TCGv t1 = tcg_temp_new();
gen_load_gpr(t0, rt);
gen_load_gpr(t1, rs);
gen_helper_fork(t0, t1);
tcg_temp_free(t0);
tcg_temp_free(t1);
}
break;
case OPC_YIELD:
check_insn(env, ctx, ASE_MT);
{
TCGv t0 = tcg_temp_new();
save_cpu_state(ctx, 1);
gen_load_gpr(t0, rs);
gen_helper_yield(t0, t0);
gen_store_gpr(t0, rd);
tcg_temp_free(t0);
}
break;
case OPC_DIV_G_2E ... OPC_DIVU_G_2E:
case OPC_MULT_G_2E ... OPC_MULTU_G_2E:
case OPC_MOD_G_2E ... OPC_MODU_G_2E:
check_insn(env, ctx, INSN_LOONGSON2E);
gen_loongson_integer(ctx, op1, rd, rs, rt);
break;
#if defined(TARGET_MIPS64)
case OPC_DEXTM ... OPC_DEXT:
case OPC_DINSM ... OPC_DINS:
check_insn(env, ctx, ISA_MIPS64R2);
check_mips_64(ctx);
gen_bitops(ctx, op1, rt, rs, sa, rd);
break;
case OPC_DBSHFL:
check_insn(env, ctx, ISA_MIPS64R2);
check_mips_64(ctx);
op2 = MASK_DBSHFL(ctx->opcode);
gen_bshfl(ctx, op2, rt, rd);
break;
case OPC_DDIV_G_2E ... OPC_DDIVU_G_2E:
case OPC_DMULT_G_2E ... OPC_DMULTU_G_2E:
case OPC_DMOD_G_2E ... OPC_DMODU_G_2E:
check_insn(env, ctx, INSN_LOONGSON2E);
gen_loongson_integer(ctx, op1, rd, rs, rt);
break;
#endif
default: /* Invalid */
MIPS_INVAL("special3");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_REGIMM:
op1 = MASK_REGIMM(ctx->opcode);
switch (op1) {
case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
case OPC_BLTZAL ... OPC_BGEZALL:
gen_compute_branch(ctx, op1, 4, rs, -1, imm << 2);
*is_branch = 1;
break;
case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
case OPC_TNEI:
gen_trap(ctx, op1, rs, -1, imm);
break;
case OPC_SYNCI:
check_insn(env, ctx, ISA_MIPS32R2);
/* Treat as NOP. */
break;
default: /* Invalid */
MIPS_INVAL("regimm");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_CP0:
check_cp0_enabled(ctx);
op1 = MASK_CP0(ctx->opcode);
switch (op1) {
case OPC_MFC0:
case OPC_MTC0:
case OPC_MFTR:
case OPC_MTTR:
#if defined(TARGET_MIPS64)
case OPC_DMFC0:
case OPC_DMTC0:
#endif
#ifndef CONFIG_USER_ONLY
gen_cp0(env, ctx, op1, rt, rd);
#endif /* !CONFIG_USER_ONLY */
break;
case OPC_C0_FIRST ... OPC_C0_LAST:
#ifndef CONFIG_USER_ONLY
gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
#endif /* !CONFIG_USER_ONLY */
break;
case OPC_MFMC0:
#ifndef CONFIG_USER_ONLY
{
TCGv t0 = tcg_temp_new();
op2 = MASK_MFMC0(ctx->opcode);
switch (op2) {
case OPC_DMT:
check_insn(env, ctx, ASE_MT);
gen_helper_dmt(t0, t0);
gen_store_gpr(t0, rt);
break;
case OPC_EMT:
check_insn(env, ctx, ASE_MT);
gen_helper_emt(t0, t0);
gen_store_gpr(t0, rt);
break;
case OPC_DVPE:
check_insn(env, ctx, ASE_MT);
gen_helper_dvpe(t0, t0);
gen_store_gpr(t0, rt);
break;
case OPC_EVPE:
check_insn(env, ctx, ASE_MT);
gen_helper_evpe(t0, t0);
gen_store_gpr(t0, rt);
break;
case OPC_DI:
check_insn(env, ctx, ISA_MIPS32R2);
save_cpu_state(ctx, 1);
gen_helper_di(t0);
gen_store_gpr(t0, rt);
/* Stop translation as we may have switched the execution mode */
ctx->bstate = BS_STOP;
break;
case OPC_EI:
check_insn(env, ctx, ISA_MIPS32R2);
save_cpu_state(ctx, 1);
gen_helper_ei(t0);
gen_store_gpr(t0, rt);
/* Stop translation as we may have switched the execution mode */
ctx->bstate = BS_STOP;
break;
default: /* Invalid */
MIPS_INVAL("mfmc0");
generate_exception(ctx, EXCP_RI);
break;
}
tcg_temp_free(t0);
}
#endif /* !CONFIG_USER_ONLY */
break;
case OPC_RDPGPR:
check_insn(env, ctx, ISA_MIPS32R2);
gen_load_srsgpr(rt, rd);
break;
case OPC_WRPGPR:
check_insn(env, ctx, ISA_MIPS32R2);
gen_store_srsgpr(rt, rd);
break;
default:
MIPS_INVAL("cp0");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case OPC_ADDI: /* Arithmetic with immediate opcode */
case OPC_ADDIU:
gen_arith_imm(env, ctx, op, rt, rs, imm);
break;
case OPC_SLTI: /* Set on less than with immediate opcode */
case OPC_SLTIU:
gen_slt_imm(env, op, rt, rs, imm);
break;
case OPC_ANDI: /* Arithmetic with immediate opcode */
case OPC_LUI:
case OPC_ORI:
case OPC_XORI:
gen_logic_imm(env, op, rt, rs, imm);
break;
case OPC_J ... OPC_JAL: /* Jump */
offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
gen_compute_branch(ctx, op, 4, rs, rt, offset);
*is_branch = 1;
break;
case OPC_BEQ ... OPC_BGTZ: /* Branch */
case OPC_BEQL ... OPC_BGTZL:
gen_compute_branch(ctx, op, 4, rs, rt, imm << 2);
*is_branch = 1;
break;
case OPC_LB ... OPC_LWR: /* Load and stores */
case OPC_LL:
gen_ld(env, ctx, op, rt, rs, imm);
break;
case OPC_SB ... OPC_SW:
case OPC_SWR:
gen_st(ctx, op, rt, rs, imm);
break;
case OPC_SC:
gen_st_cond(ctx, op, rt, rs, imm);
break;
case OPC_CACHE:
check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
/* Treat as NOP. */
break;
case OPC_PREF:
check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
/* Treat as NOP. */
break;
/* Floating point (COP1). */
case OPC_LWC1:
case OPC_LDC1:
case OPC_SWC1:
case OPC_SDC1:
gen_cop1_ldst(env, ctx, op, rt, rs, imm);
break;
case OPC_CP1:
if (env->CP0_Config1 & (1 << CP0C1_FP)) {
check_cp1_enabled(ctx);
op1 = MASK_CP1(ctx->opcode);
switch (op1) {
case OPC_MFHC1:
case OPC_MTHC1:
check_insn(env, ctx, ISA_MIPS32R2);
case OPC_MFC1:
case OPC_CFC1:
case OPC_MTC1:
case OPC_CTC1:
gen_cp1(ctx, op1, rt, rd);
break;
#if defined(TARGET_MIPS64)
case OPC_DMFC1:
case OPC_DMTC1:
check_insn(env, ctx, ISA_MIPS3);
gen_cp1(ctx, op1, rt, rd);
break;
#endif
case OPC_BC1ANY2:
case OPC_BC1ANY4:
check_cop1x(ctx);
check_insn(env, ctx, ASE_MIPS3D);
/* fall through */
case OPC_BC1:
gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
(rt >> 2) & 0x7, imm << 2);
*is_branch = 1;
break;
case OPC_S_FMT:
case OPC_D_FMT:
case OPC_W_FMT:
case OPC_L_FMT:
case OPC_PS_FMT:
gen_farith(ctx, ctx->opcode & FOP(0x3f, 0x1f), rt, rd, sa,
(imm >> 8) & 0x7);
break;
default:
MIPS_INVAL("cp1");
generate_exception (ctx, EXCP_RI);
break;
}
} else {
generate_exception_err(ctx, EXCP_CpU, 1);
}
break;
/* COP2. */
case OPC_LWC2:
case OPC_LDC2:
case OPC_SWC2:
case OPC_SDC2:
case OPC_CP2:
/* COP2: Not implemented. */
generate_exception_err(ctx, EXCP_CpU, 2);
break;
case OPC_CP3:
if (env->CP0_Config1 & (1 << CP0C1_FP)) {
check_cp1_enabled(ctx);
op1 = MASK_CP3(ctx->opcode);
switch (op1) {
case OPC_LWXC1:
case OPC_LDXC1:
case OPC_LUXC1:
case OPC_SWXC1:
case OPC_SDXC1:
case OPC_SUXC1:
gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
break;
case OPC_PREFX:
/* Treat as NOP. */
break;
case OPC_ALNV_PS:
case OPC_MADD_S:
case OPC_MADD_D:
case OPC_MADD_PS:
case OPC_MSUB_S:
case OPC_MSUB_D:
case OPC_MSUB_PS:
case OPC_NMADD_S:
case OPC_NMADD_D:
case OPC_NMADD_PS:
case OPC_NMSUB_S:
case OPC_NMSUB_D:
case OPC_NMSUB_PS:
gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
break;
default:
MIPS_INVAL("cp3");
generate_exception (ctx, EXCP_RI);
break;
}
} else {
generate_exception_err(ctx, EXCP_CpU, 1);
}
break;
#if defined(TARGET_MIPS64)
/* MIPS64 opcodes */
case OPC_LWU:
case OPC_LDL ... OPC_LDR:
case OPC_LLD:
case OPC_LD:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_ld(env, ctx, op, rt, rs, imm);
break;
case OPC_SDL ... OPC_SDR:
case OPC_SD:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_st(ctx, op, rt, rs, imm);
break;
case OPC_SCD:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_st_cond(ctx, op, rt, rs, imm);
break;
case OPC_DADDI:
case OPC_DADDIU:
check_insn(env, ctx, ISA_MIPS3);
check_mips_64(ctx);
gen_arith_imm(env, ctx, op, rt, rs, imm);
break;
#endif
case OPC_JALX:
check_insn(env, ctx, ASE_MIPS16 | ASE_MICROMIPS);
offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
gen_compute_branch(ctx, op, 4, rs, rt, offset);
*is_branch = 1;
break;
case OPC_MDMX:
check_insn(env, ctx, ASE_MDMX);
/* MDMX: Not implemented. */
default: /* Invalid */
MIPS_INVAL("major opcode");
generate_exception(ctx, EXCP_RI);
break;
}
}
| 9,595 |
FFmpeg | 74dc728a2c2cc353da20cdc09b8cdfbbe14b7be8 | 1 | static void generate_2_noise_channels(MLPDecodeContext *m, unsigned int substr)
{
SubStream *s = &m->substream[substr];
unsigned int i;
uint32_t seed = s->noisegen_seed;
unsigned int maxchan = s->max_matrix_channel;
for (i = 0; i < s->blockpos; i++) {
uint16_t seed_shr7 = seed >> 7;
m->sample_buffer[i][maxchan+1] = ((int8_t)(seed >> 15)) << s->noise_shift;
m->sample_buffer[i][maxchan+2] = ((int8_t) seed_shr7) << s->noise_shift;
seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
}
s->noisegen_seed = seed;
}
| 9,596 |
FFmpeg | 142894d7202b5559d87f58df30baf48107a816f6 | 1 | static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
AVFilterContext *ctx = inlink->dst;
AudioEchoContext *s = ctx->priv;
AVFrame *out_frame;
if (av_frame_is_writable(frame)) {
out_frame = frame;
} else {
out_frame = ff_get_audio_buffer(inlink, frame->nb_samples);
if (!out_frame)
return AVERROR(ENOMEM);
av_frame_copy_props(out_frame, frame);
}
s->echo_samples(s, s->delayptrs, frame->extended_data, out_frame->extended_data,
frame->nb_samples, inlink->channels);
s->next_pts = frame->pts + av_rescale_q(frame->nb_samples, (AVRational){1, inlink->sample_rate}, inlink->time_base);
if (frame != out_frame)
av_frame_free(&frame);
return ff_filter_frame(ctx->outputs[0], out_frame);
}
| 9,597 |
qemu | 386bbf45720b00496d5b9f9137359801c4e7ac0e | 1 | static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
{
int size;
char *path;
void *ptr;
char name[32];
if (!pdev->romfile)
return 0;
if (strlen(pdev->romfile) == 0)
return 0;
if (!pdev->rom_bar) {
/*
* Load rom via fw_cfg instead of creating a rom bar,
* for 0.11 compatibility.
*/
int class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);
if (class == 0x0300) {
rom_add_vga(pdev->romfile);
} else {
rom_add_option(pdev->romfile, -1);
}
return 0;
}
path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);
if (path == NULL) {
path = qemu_strdup(pdev->romfile);
}
size = get_image_size(path);
if (size < 0) {
error_report("%s: failed to find romfile \"%s\"",
__FUNCTION__, pdev->romfile);
return -1;
}
if (size & (size - 1)) {
size = 1 << qemu_fls(size);
}
if (pdev->qdev.info->vmsd)
snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->vmsd->name);
else
snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->name);
pdev->rom_offset = qemu_ram_alloc(&pdev->qdev, name, size);
ptr = qemu_get_ram_ptr(pdev->rom_offset);
load_image(path, ptr);
if (is_default_rom) {
/* Only the default rom images will be patched (if needed). */
pci_patch_ids(pdev, ptr, size);
}
pci_register_bar(pdev, PCI_ROM_SLOT, size,
0, pci_map_option_rom);
return 0;
} | 9,599 |
qemu | aedbe19297907143f17b733a7ff0e0534377bed1 | 1 | void qemu_system_reset_request(void)
{
if (no_reboot) {
shutdown_requested = 1;
} else {
reset_requested = 1;
}
cpu_stop_current();
qemu_notify_event();
}
| 9,600 |
FFmpeg | b88be742fac7a77a8095e8155ba8790db4b77568 | 1 | static void encode_frame(VC2EncContext *s, const AVFrame *frame,
const char *aux_data, int field)
{
int i;
/* Sequence header */
encode_parse_info(s, DIRAC_PCODE_SEQ_HEADER);
encode_seq_header(s);
/* Encoder version */
if (aux_data) {
encode_parse_info(s, DIRAC_PCODE_AUX);
avpriv_put_string(&s->pb, aux_data, 1);
}
/* Picture header */
encode_parse_info(s, DIRAC_PCODE_PICTURE_HQ);
encode_picture_start(s);
for (i = 0; i < 3; i++) {
s->transform_args[i].ctx = s;
s->transform_args[i].field = field;
s->transform_args[i].plane = &s->plane[i];
s->transform_args[i].idata = frame->data[i];
s->transform_args[i].istride = frame->linesize[i];
}
/* Do a DWT transform */
s->avctx->execute(s->avctx, dwt_plane, s->transform_args, NULL, 3,
sizeof(TransformArgs));
/* Calculate per-slice quantizers and sizes */
calc_slice_sizes(s);
/* Init planes and encode slices */
encode_slices(s);
/* End sequence */
encode_parse_info(s, DIRAC_PCODE_END_SEQ);
}
| 9,601 |
qemu | 9b2fadda3e0196ffd485adde4fe9cdd6fae35300 | 1 | static void gen_tlbre_booke206(DisasContext *ctx)
{
#if defined(CONFIG_USER_ONLY)
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
#else
if (unlikely(ctx->pr)) {
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
return;
}
gen_helper_booke206_tlbre(cpu_env);
#endif
}
| 9,602 |
FFmpeg | 8630b2cd36c57918acfe18302fe77d1ceefbd676 | 1 | static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
int is_signed)
{
if (get_rac(c, state + 0))
return 0;
else {
int i, e, a;
e = 0;
while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
e++;
if (e > 31)
return AVERROR_INVALIDDATA;
}
a = 1;
for (i = e - 1; i >= 0; i--)
a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31
e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
return (a ^ e) - e;
}
}
| 9,603 |
FFmpeg | 0dbb48d91e9e97c7eb11f4ebc03c4ff4b6f5b692 | 1 | static int mpeg_mux_end(AVFormatContext *ctx)
{
MpegMuxContext *s = ctx->priv_data;
StreamInfo *stream;
int i;
/* flush each packet */
for(i=0;i<ctx->nb_streams;i++) {
stream = ctx->streams[i]->priv_data;
while (stream->buffer_ptr > 0) {
flush_packet(ctx, i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, s->last_scr);
}
}
/* End header according to MPEG1 systems standard. We do not write
it as it is usually not needed by decoders and because it
complicates MPEG stream concatenation. */
//put_be32(&ctx->pb, ISO_11172_END_CODE);
//put_flush_packet(&ctx->pb);
for(i=0;i<ctx->nb_streams;i++)
av_freep(&ctx->streams[i]->priv_data);
return 0;
}
| 9,604 |
qemu | 97a2ae34537882df34810d538ab1f51085499d2c | 1 | static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
{
BDRVRawState *s = bs->opaque;
int rc;
rc = fd_open(bs);
if (rc < 0) {
return rc;
}
if (!(flags & BDRV_REQ_MAY_UNMAP)) {
return -ENOTSUP;
}
if (!s->discard_zeroes) {
return -ENOTSUP;
}
return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
}
| 9,605 |
FFmpeg | f927c5b753f2ec1f037ad38cb55b4407dd7a9d79 | 1 | theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp, int64_t *dts)
{
struct ogg *ogg = ctx->priv_data;
struct ogg_stream *os = ogg->streams + idx;
struct theora_params *thp = os->private;
uint64_t iframe = gp >> thp->gpshift;
uint64_t pframe = gp & thp->gpmask;
if (thp->version < 0x030201)
iframe++;
if(!pframe)
os->pflags |= AV_PKT_FLAG_KEY;
if (dts)
*dts = iframe + pframe;
return iframe + pframe;
}
| 9,606 |
FFmpeg | 7fb92be7e50ea4ba5712804326c6814ae02dd190 | 1 | static void qtrle_decode_32bpp(QtrleContext *s, int stream_ptr, int row_ptr, int lines_to_change)
{
int rle_code;
int pixel_ptr;
int row_inc = s->frame.linesize[0];
unsigned char a, r, g, b;
unsigned int argb;
unsigned char *rgb = s->frame.data[0];
int pixel_limit = s->frame.linesize[0] * s->avctx->height;
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4;
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
/* there's another skip code in the stream */
CHECK_STREAM_PTR(1);
pixel_ptr += (s->buf[stream_ptr++] - 1) * 4;
} else if (rle_code < 0) {
/* decode the run length code */
rle_code = -rle_code;
CHECK_STREAM_PTR(4);
a = s->buf[stream_ptr++];
r = s->buf[stream_ptr++];
g = s->buf[stream_ptr++];
b = s->buf[stream_ptr++];
argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
CHECK_PIXEL_PTR(rle_code * 4);
while (rle_code--) {
*(unsigned int *)(&rgb[pixel_ptr]) = argb;
pixel_ptr += 4;
}
} else {
CHECK_STREAM_PTR(rle_code * 4);
CHECK_PIXEL_PTR(rle_code * 4);
/* copy pixels directly to output */
while (rle_code--) {
a = s->buf[stream_ptr++];
r = s->buf[stream_ptr++];
g = s->buf[stream_ptr++];
b = s->buf[stream_ptr++];
argb = (a << 24) | (r << 16) | (g << 8) | (b << 0);
*(unsigned int *)(&rgb[pixel_ptr]) = argb;
pixel_ptr += 4;
}
}
}
row_ptr += row_inc;
}
} | 9,608 |
qemu | c580dee4e170adad1ebdf901d32f0e1ed7d125b9 | 1 | int loader_exec(const char * filename, char ** argv, char ** envp,
struct target_pt_regs * regs, struct image_info *infop)
{
struct linux_binprm bprm;
int retval;
int i;
bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
bprm.page[i] = NULL;
retval = open(filename, O_RDONLY);
if (retval < 0)
return retval;
bprm.fd = retval;
bprm.filename = (char *)filename;
bprm.argc = count(argv);
bprm.argv = argv;
bprm.envc = count(envp);
bprm.envp = envp;
retval = prepare_binprm(&bprm);
if(retval>=0) {
if (bprm.buf[0] == 0x7f
&& bprm.buf[1] == 'E'
&& bprm.buf[2] == 'L'
&& bprm.buf[3] == 'F') {
retval = load_elf_binary(&bprm,regs,infop);
} else {
fprintf(stderr, "Unknown binary format\n");
return -1;
}
}
if(retval>=0) {
/* success. Initialize important registers */
do_init_thread(regs, infop);
return retval;
}
/* Something went wrong, return the inode and free the argument pages*/
for (i=0 ; i<MAX_ARG_PAGES ; i++) {
free(bprm.page[i]);
}
return(retval);
}
| 9,609 |
FFmpeg | ad2296ab3a131d3560c385e43437841987166804 | 1 | static av_always_inline SoftFloat autocorr_calc(int64_t accu)
{
int nz, mant, expo, round;
int i = (int)(accu >> 32);
if (i == 0) {
nz = 1;
} else {
nz = 0;
while (FFABS(i) < 0x40000000) {
i <<= 1;
nz++;
}
nz = 32-nz;
}
round = 1 << (nz-1);
mant = (int)((accu + round) >> nz);
mant = (mant + 0x40)>>7;
mant <<= 6;
expo = nz + 15;
return av_int2sf(mant, 30 - expo);
}
| 9,610 |
FFmpeg | 6394acaf36da3106f4793bda32730f8ff6b0ddb1 | 1 | static void search_for_ms(AACEncContext *s, ChannelElement *cpe,
const float lambda)
{
int start = 0, i, w, w2, g;
float M[128], S[128];
float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
SingleChannelElement *sce0 = &cpe->ch[0];
SingleChannelElement *sce1 = &cpe->ch[1];
if (!cpe->common_window)
return;
for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
for (g = 0; g < sce0->ics.num_swb; g++) {
if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
float dist1 = 0.0f, dist2 = 0.0f;
for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];
float minthr = FFMIN(band0->threshold, band1->threshold);
float maxthr = FFMAX(band0->threshold, band1->threshold);
for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
M[i] = (sce0->coeffs[start+w2*128+i]
+ sce1->coeffs[start+w2*128+i]) * 0.5;
S[i] = M[i]
- sce1->coeffs[start+w2*128+i];
}
abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
abs_pow34_v(R34, sce1->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);
abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);
dist1 += quantize_band_cost(s, sce0->coeffs + start + w2*128,
L34,
sce0->ics.swb_sizes[g],
sce0->sf_idx[(w+w2)*16+g],
sce0->band_type[(w+w2)*16+g],
lambda / band0->threshold, INFINITY, NULL);
dist1 += quantize_band_cost(s, sce1->coeffs + start + w2*128,
R34,
sce1->ics.swb_sizes[g],
sce1->sf_idx[(w+w2)*16+g],
sce1->band_type[(w+w2)*16+g],
lambda / band1->threshold, INFINITY, NULL);
dist2 += quantize_band_cost(s, M,
M34,
sce0->ics.swb_sizes[g],
sce0->sf_idx[(w+w2)*16+g],
sce0->band_type[(w+w2)*16+g],
lambda / maxthr, INFINITY, NULL);
dist2 += quantize_band_cost(s, S,
S34,
sce1->ics.swb_sizes[g],
sce1->sf_idx[(w+w2)*16+g],
sce1->band_type[(w+w2)*16+g],
lambda / minthr, INFINITY, NULL);
}
cpe->ms_mask[w*16+g] = dist2 < dist1;
}
start += sce0->ics.swb_sizes[g];
}
}
}
| 9,612 |
FFmpeg | f4e814f787d050ac65f507b1304dcdc4ffa56f29 | 1 | struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
int log_offset, void *log_ctx){
if(!s) s= swr_alloc();
if(!s) return NULL;
s->log_level_offset= log_offset;
s->log_ctx= log_ctx;
av_opt_set_int(s, "ocl", out_ch_layout, 0);
av_opt_set_int(s, "osf", out_sample_fmt, 0);
av_opt_set_int(s, "osr", out_sample_rate, 0);
av_opt_set_int(s, "icl", in_ch_layout, 0);
av_opt_set_int(s, "isf", in_sample_fmt, 0);
av_opt_set_int(s, "isr", in_sample_rate, 0);
av_opt_set_int(s, "tsf", AV_SAMPLE_FMT_NONE, 0);
av_opt_set_int(s, "ich", av_get_channel_layout_nb_channels(s-> in_ch_layout), 0);
av_opt_set_int(s, "och", av_get_channel_layout_nb_channels(s->out_ch_layout), 0);
av_opt_set_int(s, "uch", 0, 0);
return s;
}
| 9,614 |
FFmpeg | 8eb76217d0137b7adad438f6c923310fbc1fc4c1 | 1 | static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s, AVFrame *frame)
{
int x, y;
unsigned char P[4];
unsigned int flags = 0;
/* 2-color encoding for each 4x4 quadrant, or 2-color encoding on
* either top and bottom or left and right halves */
P[0] = bytestream2_get_byte(&s->stream_ptr);
P[1] = bytestream2_get_byte(&s->stream_ptr);
if (P[0] <= P[1]) {
for (y = 0; y < 16; y++) {
// new values for each 4x4 block
if (!(y & 3)) {
if (y) {
P[0] = bytestream2_get_byte(&s->stream_ptr);
P[1] = bytestream2_get_byte(&s->stream_ptr);
flags = bytestream2_get_le16(&s->stream_ptr);
for (x = 0; x < 4; x++, flags >>= 1)
*s->pixel_ptr++ = P[flags & 1];
s->pixel_ptr += s->stride - 4;
// switch to right half
if (y == 7) s->pixel_ptr -= 8 * s->stride - 4;
} else {
flags = bytestream2_get_le32(&s->stream_ptr);
P[2] = bytestream2_get_byte(&s->stream_ptr);
P[3] = bytestream2_get_byte(&s->stream_ptr);
if (P[2] <= P[3]) {
/* vertical split; left & right halves are 2-color encoded */
for (y = 0; y < 16; y++) {
for (x = 0; x < 4; x++, flags >>= 1)
*s->pixel_ptr++ = P[flags & 1];
s->pixel_ptr += s->stride - 4;
// switch to right half
if (y == 7) {
s->pixel_ptr -= 8 * s->stride - 4;
P[0] = P[2];
P[1] = P[3];
flags = bytestream2_get_le32(&s->stream_ptr);
} else {
/* horizontal split; top & bottom halves are 2-color encoded */
for (y = 0; y < 8; y++) {
if (y == 4) {
P[0] = P[2];
P[1] = P[3];
flags = bytestream2_get_le32(&s->stream_ptr);
for (x = 0; x < 8; x++, flags >>= 1)
*s->pixel_ptr++ = P[flags & 1];
s->pixel_ptr += s->line_inc;
/* report success */
return 0; | 9,615 |
qemu | 778358d0a8f74a76488daea3c1b6fb327d8135b4 | 1 | FpPort *fp_port_alloc(Rocker *r, char *sw_name,
MACAddr *start_mac, unsigned int index,
NICPeers *peers)
{
FpPort *port = g_malloc0(sizeof(FpPort));
if (!port) {
return NULL;
}
port->r = r;
port->index = index;
port->pport = index + 1;
/* front-panel switch port names are 1-based */
port->name = g_strdup_printf("%sp%d", sw_name, port->pport);
memcpy(port->conf.macaddr.a, start_mac, sizeof(port->conf.macaddr.a));
port->conf.macaddr.a[5] += index;
port->conf.bootindex = -1;
port->conf.peers = *peers;
port->nic = qemu_new_nic(&fp_port_info, &port->conf,
sw_name, NULL, port);
qemu_format_nic_info_str(qemu_get_queue(port->nic),
port->conf.macaddr.a);
fp_port_reset(port);
return port;
}
| 9,617 |
FFmpeg | aba232cfa9b193604ed98f3fa505378d006b1b3b | 1 | static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
{
AVStream *stream = fmt_ctx->streams[stream_idx];
AVCodecContext *dec_ctx;
AVCodec *dec;
const char *profile;
char val_str[128];
AVRational display_aspect_ratio;
probe_object_header("stream");
probe_int("index", stream->index);
if ((dec_ctx = stream->codec)) {
if ((dec = dec_ctx->codec)) {
probe_str("codec_name", dec->name);
probe_str("codec_long_name", dec->long_name);
} else {
probe_str("codec_name", "unknown");
}
probe_str("codec_type", media_type_string(dec_ctx->codec_type));
probe_str("codec_time_base",
rational_string(val_str, sizeof(val_str),
"/", &dec_ctx->time_base));
/* print AVI/FourCC tag */
av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
probe_str("codec_tag_string", val_str);
probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
dec_ctx->codec_tag));
/* print profile, if there is one */
if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile)))
probe_str("profile", profile);
switch (dec_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
probe_int("width", dec_ctx->width);
probe_int("height", dec_ctx->height);
probe_int("has_b_frames", dec_ctx->has_b_frames);
if (dec_ctx->sample_aspect_ratio.num) {
probe_str("sample_aspect_ratio",
rational_string(val_str, sizeof(val_str), ":",
&dec_ctx->sample_aspect_ratio));
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
dec_ctx->width * dec_ctx->sample_aspect_ratio.num,
dec_ctx->height * dec_ctx->sample_aspect_ratio.den,
1024*1024);
probe_str("display_aspect_ratio",
rational_string(val_str, sizeof(val_str), ":",
&display_aspect_ratio));
}
probe_str("pix_fmt",
dec_ctx->pix_fmt != PIX_FMT_NONE ? av_pix_fmt_descriptors[dec_ctx->pix_fmt].name
: "unknown");
probe_int("level", dec_ctx->level);
break;
case AVMEDIA_TYPE_AUDIO:
probe_str("sample_rate",
value_string(val_str, sizeof(val_str),
dec_ctx->sample_rate,
unit_hertz_str));
probe_int("channels", dec_ctx->channels);
probe_int("bits_per_sample",
av_get_bits_per_sample(dec_ctx->codec_id));
break;
}
} else {
probe_str("codec_type", "unknown");
}
if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
probe_int("id", stream->id);
probe_str("r_frame_rate",
rational_string(val_str, sizeof(val_str), "/",
&stream->r_frame_rate));
probe_str("avg_frame_rate",
rational_string(val_str, sizeof(val_str), "/",
&stream->avg_frame_rate));
probe_str("time_base",
rational_string(val_str, sizeof(val_str), "/",
&stream->time_base));
probe_str("start_time",
time_value_string(val_str, sizeof(val_str),
stream->start_time, &stream->time_base));
probe_str("duration",
time_value_string(val_str, sizeof(val_str),
stream->duration, &stream->time_base));
if (stream->nb_frames)
probe_int("nb_frames", stream->nb_frames);
probe_dict(stream->metadata, "tags");
probe_object_footer("stream");
}
| 9,618 |
qemu | 1a6d39fd71ddf90c5b76026cac4d5ff51fbaf8d8 | 0 | static int is_not_zero(const uint8_t *sector, int len)
{
/*
* Use long as the biggest available internal data type that fits into the
* CPU register and unroll the loop to smooth out the effect of memory
* latency.
*/
int i;
long d0, d1, d2, d3;
const long * const data = (const long *) sector;
len /= sizeof(long);
for(i = 0; i < len; i += 4) {
d0 = data[i + 0];
d1 = data[i + 1];
d2 = data[i + 2];
d3 = data[i + 3];
if (d0 || d1 || d2 || d3) {
return 1;
}
}
return 0;
}
| 9,620 |
qemu | 093209cd681fe9fb65bd8a1c2ff711b8168bbfcd | 0 | static void taihu_405ep_init(ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename,
const char *kernel_cmdline,
const char *initrd_filename,
const char *cpu_model)
{
char *filename;
CPUPPCState *env;
qemu_irq *pic;
ram_addr_t bios_offset;
target_phys_addr_t ram_bases[2], ram_sizes[2];
target_ulong bios_size;
target_ulong kernel_base, kernel_size, initrd_base, initrd_size;
int linux_boot;
int fl_idx, fl_sectors;
DriveInfo *dinfo;
/* RAM is soldered to the board so the size cannot be changed */
ram_bases[0] = qemu_ram_alloc(NULL, "taihu_405ep.ram-0", 0x04000000);
ram_sizes[0] = 0x04000000;
ram_bases[1] = qemu_ram_alloc(NULL, "taihu_405ep.ram-1", 0x04000000);
ram_sizes[1] = 0x04000000;
ram_size = 0x08000000;
#ifdef DEBUG_BOARD_INIT
printf("%s: register cpu\n", __func__);
#endif
env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
kernel_filename == NULL ? 0 : 1);
/* allocate and load BIOS */
#ifdef DEBUG_BOARD_INIT
printf("%s: register BIOS\n", __func__);
#endif
fl_idx = 0;
#if defined(USE_FLASH_BIOS)
dinfo = drive_get(IF_PFLASH, 0, fl_idx);
if (dinfo) {
bios_size = bdrv_getlength(dinfo->bdrv);
/* XXX: should check that size is 2MB */
// bios_size = 2 * 1024 * 1024;
fl_sectors = (bios_size + 65535) >> 16;
bios_offset = qemu_ram_alloc(NULL, "taihu_405ep.bios", bios_size);
#ifdef DEBUG_BOARD_INIT
printf("Register parallel flash %d size " TARGET_FMT_lx
" at offset %08lx addr " TARGET_FMT_lx " '%s' %d\n",
fl_idx, bios_size, bios_offset, -bios_size,
bdrv_get_device_name(dinfo->bdrv), fl_sectors);
#endif
pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
dinfo->bdrv, 65536, fl_sectors, 1,
4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
1);
fl_idx++;
} else
#endif
{
#ifdef DEBUG_BOARD_INIT
printf("Load BIOS from file\n");
#endif
if (bios_name == NULL)
bios_name = BIOS_FILENAME;
bios_offset = qemu_ram_alloc(NULL, "taihu_405ep.bios", BIOS_SIZE);
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (filename) {
bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > BIOS_SIZE) {
fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
bios_name);
exit(1);
}
bios_size = (bios_size + 0xfff) & ~0xfff;
cpu_register_physical_memory((uint32_t)(-bios_size),
bios_size, bios_offset | IO_MEM_ROM);
}
/* Register Linux flash */
dinfo = drive_get(IF_PFLASH, 0, fl_idx);
if (dinfo) {
bios_size = bdrv_getlength(dinfo->bdrv);
/* XXX: should check that size is 32MB */
bios_size = 32 * 1024 * 1024;
fl_sectors = (bios_size + 65535) >> 16;
#ifdef DEBUG_BOARD_INIT
printf("Register parallel flash %d size " TARGET_FMT_lx
" at offset %08lx addr " TARGET_FMT_lx " '%s'\n",
fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
bdrv_get_device_name(dinfo->bdrv));
#endif
bios_offset = qemu_ram_alloc(NULL, "taihu_405ep.flash", bios_size);
pflash_cfi02_register(0xfc000000, bios_offset,
dinfo->bdrv, 65536, fl_sectors, 1,
4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
1);
fl_idx++;
}
/* Register CLPD & LCD display */
#ifdef DEBUG_BOARD_INIT
printf("%s: register CPLD\n", __func__);
#endif
taihu_cpld_init(0x50100000);
/* Load kernel */
linux_boot = (kernel_filename != NULL);
if (linux_boot) {
#ifdef DEBUG_BOARD_INIT
printf("%s: load kernel\n", __func__);
#endif
kernel_base = KERNEL_LOAD_ADDR;
/* now we can load the kernel */
kernel_size = load_image_targphys(kernel_filename, kernel_base,
ram_size - kernel_base);
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
kernel_filename);
exit(1);
}
/* load initrd */
if (initrd_filename) {
initrd_base = INITRD_LOAD_ADDR;
initrd_size = load_image_targphys(initrd_filename, initrd_base,
ram_size - initrd_base);
if (initrd_size < 0) {
fprintf(stderr,
"qemu: could not load initial ram disk '%s'\n",
initrd_filename);
exit(1);
}
} else {
initrd_base = 0;
initrd_size = 0;
}
} else {
kernel_base = 0;
kernel_size = 0;
initrd_base = 0;
initrd_size = 0;
}
#ifdef DEBUG_BOARD_INIT
printf("%s: Done\n", __func__);
#endif
}
| 9,621 |
FFmpeg | 82dd7d0dec29ee59af91ce18c29eb151b363ff37 | 0 | static int decode_frame_header (bit_buffer_t *bitbuf,MpegEncContext *s) {
int frame_size_code;
/* unknown field */
get_bits (bitbuf, 8);
/* frame type */
s->pict_type = get_bits (bitbuf, 2);
if (s->pict_type == 3)
return -1;
if (s->pict_type == SVQ1_FRAME_INTRA) {
/* unknown fields */
if (s->f_code == 0x50 || s->f_code == 0x60) {
get_bits (bitbuf, 16);
}
if ((s->f_code ^ 0x10) >= 0x50) {
skip_bits(bitbuf,8*get_bits (bitbuf, 8));
}
get_bits (bitbuf, 2);
get_bits (bitbuf, 2);
get_bits (bitbuf, 1);
/* load frame size */
frame_size_code = get_bits (bitbuf, 3);
if (frame_size_code == 7) {
/* load width, height (12 bits each) */
s->width = get_bits (bitbuf, 12);
s->height = get_bits (bitbuf, 12);
if (!s->width || !s->height)
return -1;
} else {
/* get width, height from table */
s->width = frame_size_table[frame_size_code].width;
s->height = frame_size_table[frame_size_code].height;
}
}
/* unknown fields */
if (get_bits (bitbuf, 1) == 1) {
get_bits (bitbuf, 1);
get_bits (bitbuf, 1);
if (get_bits (bitbuf, 2) != 0)
return -1;
}
if (get_bits (bitbuf, 1) == 1) {
get_bits (bitbuf, 1);
get_bits (bitbuf, 4);
get_bits (bitbuf, 1);
get_bits (bitbuf, 2);
while (get_bits (bitbuf, 1) == 1) {
get_bits (bitbuf, 8);
}
}
return 0;
}
| 9,622 |
qemu | 3c529d935923a70519557d420db1d5a09a65086a | 0 | static void posix_aio_read(void *opaque)
{
PosixAioState *s = opaque;
RawAIOCB *acb, **pacb;
int ret;
ssize_t len;
/* read all bytes from signal pipe */
for (;;) {
char bytes[16];
len = read(s->rfd, bytes, sizeof(bytes));
if (len == -1 && errno == EINTR)
continue; /* try again */
if (len == sizeof(bytes))
continue; /* more to read */
break;
}
for(;;) {
pacb = &s->first_aio;
for(;;) {
acb = *pacb;
if (!acb)
goto the_end;
ret = aio_error(&acb->aiocb);
if (ret == ECANCELED) {
/* remove the request */
*pacb = acb->next;
raw_fd_pool_put(acb);
qemu_aio_release(acb);
} else if (ret != EINPROGRESS) {
/* end of aio */
if (ret == 0) {
ret = aio_return(&acb->aiocb);
if (ret == acb->aiocb.aio_nbytes)
ret = 0;
else
ret = -EINVAL;
} else {
ret = -ret;
}
/* remove the request */
*pacb = acb->next;
/* call the callback */
acb->common.cb(acb->common.opaque, ret);
raw_fd_pool_put(acb);
qemu_aio_release(acb);
break;
} else {
pacb = &acb->next;
}
}
}
the_end: ;
}
| 9,623 |
qemu | 079d0b7f1eedcc634c371fe05b617fdc55c8b762 | 0 | static int usbredir_handle_data(USBDevice *udev, USBPacket *p)
{
USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
uint8_t ep;
ep = p->devep;
if (p->pid == USB_TOKEN_IN) {
ep |= USB_DIR_IN;
}
switch (dev->endpoint[EP2I(ep)].type) {
case USB_ENDPOINT_XFER_CONTROL:
ERROR("handle_data called for control transfer on ep %02X\n", ep);
return USB_RET_NAK;
case USB_ENDPOINT_XFER_ISOC:
return usbredir_handle_iso_data(dev, p, ep);
case USB_ENDPOINT_XFER_BULK:
return usbredir_handle_bulk_data(dev, p, ep);
case USB_ENDPOINT_XFER_INT:
return usbredir_handle_interrupt_data(dev, p, ep);
default:
ERROR("handle_data ep %02X has unknown type %d\n", ep,
dev->endpoint[EP2I(ep)].type);
return USB_RET_NAK;
}
}
| 9,624 |
qemu | b853d4cbf2062813e84f9bb880feff8daf467e05 | 0 | int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu)
{
CPUState *cs = CPU(cpu);
struct kvm_s390_irq_state irq_state;
int r;
if (!kvm_check_extension(kvm_state, KVM_CAP_S390_IRQ_STATE)) {
return -ENOSYS;
}
if (cpu->irqstate_saved_size == 0) {
return 0;
}
irq_state.buf = (uint64_t) cpu->irqstate;
irq_state.len = cpu->irqstate_saved_size;
r = kvm_vcpu_ioctl(cs, KVM_S390_SET_IRQ_STATE, &irq_state);
if (r) {
error_report("Setting interrupt state failed %d", r);
}
return r;
}
| 9,625 |
qemu | bdb5ee3064d5ae786b0bcb6cf6ff4e3554a72990 | 0 | void do_info_roms(Monitor *mon)
{
Rom *rom;
QTAILQ_FOREACH(rom, &roms, next) {
if (!rom->fw_file) {
monitor_printf(mon, "addr=" TARGET_FMT_plx
" size=0x%06zx mem=%s name=\"%s\" \n",
rom->addr, rom->romsize,
rom->isrom ? "rom" : "ram",
rom->name);
} else {
monitor_printf(mon, "fw=%s%s%s"
" size=0x%06zx name=\"%s\" \n",
rom->fw_dir ? rom->fw_dir : "",
rom->fw_dir ? "/" : "",
rom->fw_file,
rom->romsize,
rom->name);
}
}
}
| 9,626 |
qemu | ad96090a01d848df67d70c5259ed8aa321fa8716 | 0 | static void do_smbios_option(const char *optarg)
{
if (smbios_entry_add(optarg) < 0) {
fprintf(stderr, "Wrong smbios provided\n");
exit(1);
}
}
| 9,628 |
qemu | 42a268c241183877192c376d03bd9b6d527407c7 | 0 | static ExitStatus gen_store_conditional(DisasContext *ctx, int ra, int rb,
int32_t disp16, int quad)
{
TCGv addr;
if (ra == 31) {
/* ??? Don't bother storing anything. The user can't tell
the difference, since the zero register always reads zero. */
return NO_EXIT;
}
#if defined(CONFIG_USER_ONLY)
addr = cpu_lock_st_addr;
#else
addr = tcg_temp_local_new();
#endif
tcg_gen_addi_i64(addr, load_gpr(ctx, rb), disp16);
#if defined(CONFIG_USER_ONLY)
/* ??? This is handled via a complicated version of compare-and-swap
in the cpu_loop. Hopefully one day we'll have a real CAS opcode
in TCG so that this isn't necessary. */
return gen_excp(ctx, quad ? EXCP_STQ_C : EXCP_STL_C, ra);
#else
/* ??? In system mode we are never multi-threaded, so CAS can be
implemented via a non-atomic load-compare-store sequence. */
{
int lab_fail, lab_done;
TCGv val;
lab_fail = gen_new_label();
lab_done = gen_new_label();
tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_lock_addr, lab_fail);
val = tcg_temp_new();
tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, quad ? MO_LEQ : MO_LESL);
tcg_gen_brcond_i64(TCG_COND_NE, val, cpu_lock_value, lab_fail);
tcg_gen_qemu_st_i64(cpu_ir[ra], addr, ctx->mem_idx,
quad ? MO_LEQ : MO_LEUL);
tcg_gen_movi_i64(cpu_ir[ra], 1);
tcg_gen_br(lab_done);
gen_set_label(lab_fail);
tcg_gen_movi_i64(cpu_ir[ra], 0);
gen_set_label(lab_done);
tcg_gen_movi_i64(cpu_lock_addr, -1);
tcg_temp_free(addr);
return NO_EXIT;
}
#endif
}
| 9,631 |
qemu | 4fa4ce7107c6ec432f185307158c5df91ce54308 | 0 | static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
void *value, size_t size, int flags)
{
char buffer[PATH_MAX];
return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
size, flags);
}
| 9,632 |
FFmpeg | eabbc64728c2fdb74f565aededec2ab023d20699 | 0 | static int mkv_write_attachments(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *dyn_cp, *pb = s->pb;
ebml_master attachments;
AVLFG c;
int i, ret;
if (!mkv->have_attachments)
return 0;
mkv->attachments = av_mallocz(sizeof(*mkv->attachments));
if (!mkv->attachments)
return ret;
av_lfg_init(&c, av_get_random_seed());
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_ATTACHMENTS, avio_tell(pb));
if (ret < 0) return ret;
ret = start_ebml_master_crc32(pb, &dyn_cp, &attachments, MATROSKA_ID_ATTACHMENTS, 0);
if (ret < 0) return ret;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
ebml_master attached_file;
mkv_attachment *attachment = mkv->attachments->entries;
AVDictionaryEntry *t;
const char *mimetype = NULL;
uint32_t fileuid;
if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
continue;
attachment = av_realloc_array(attachment, mkv->attachments->num_entries + 1, sizeof(mkv_attachment));
if (!attachment)
return AVERROR(ENOMEM);
mkv->attachments->entries = attachment;
attached_file = start_ebml_master(dyn_cp, MATROSKA_ID_ATTACHEDFILE, 0);
if (t = av_dict_get(st->metadata, "title", NULL, 0))
put_ebml_string(dyn_cp, MATROSKA_ID_FILEDESC, t->value);
if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) {
av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i);
return AVERROR(EINVAL);
}
put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, t->value);
if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
mimetype = t->value;
else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {
int i;
for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) {
mimetype = ff_mkv_mime_tags[i].str;
break;
}
for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) {
mimetype = ff_mkv_image_mime_tags[i].str;
break;
}
}
if (!mimetype) {
av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and "
"it cannot be deduced from the codec id.\n", i);
return AVERROR(EINVAL);
}
if (s->flags & AVFMT_FLAG_BITEXACT) {
struct AVSHA *sha = av_sha_alloc();
uint8_t digest[20];
if (!sha)
return AVERROR(ENOMEM);
av_sha_init(sha, 160);
av_sha_update(sha, st->codecpar->extradata, st->codecpar->extradata_size);
av_sha_final(sha, digest);
av_free(sha);
fileuid = AV_RL32(digest);
} else {
fileuid = av_lfg_get(&c);
}
av_log(s, AV_LOG_VERBOSE, "Using %.8"PRIx32" for attachment %d\n",
fileuid, mkv->attachments->num_entries);
put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size);
put_ebml_uint(dyn_cp, MATROSKA_ID_FILEUID, fileuid);
end_ebml_master(dyn_cp, attached_file);
mkv->attachments->entries[mkv->attachments->num_entries].stream_idx = i;
mkv->attachments->entries[mkv->attachments->num_entries++].fileuid = fileuid;
}
end_ebml_master_crc32(pb, &dyn_cp, mkv, attachments);
return 0;
}
| 9,633 |
qemu | e1833e1f96456fd8fc17463246fe0b2050e68efb | 0 | static void spr_write_dbatu (void *opaque, int sprn)
{
DisasContext *ctx = opaque;
gen_op_store_dbatu((sprn - SPR_DBAT0U) / 2);
RET_STOP(ctx);
}
| 9,634 |
qemu | 26572b8a0e90ee0c77587173a78fa293a1d2beb6 | 0 | void vga_hw_invalidate(void)
{
if (active_console->hw_invalidate)
active_console->hw_invalidate(active_console->hw);
}
| 9,635 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint32_t pmac_ide_readw (void *opaque,target_phys_addr_t addr)
{
uint16_t retval;
MACIOIDEState *d = opaque;
addr = (addr & 0xFFF) >> 4;
if (addr == 0) {
retval = ide_data_readw(&d->bus, 0);
} else {
retval = 0xFFFF;
}
retval = bswap16(retval);
return retval;
}
| 9,636 |
qemu | e1f8c729fa890c67bb4532f22c22ace6fb0e1aaf | 0 | DeviceState *pxa2xx_gpio_init(target_phys_addr_t base,
CPUState *env, qemu_irq *pic, int lines)
{
DeviceState *dev;
dev = qdev_create(NULL, "pxa2xx-gpio");
qdev_prop_set_int32(dev, "lines", lines);
qdev_prop_set_int32(dev, "ncpu", env->cpu_index);
qdev_init_nofail(dev);
sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[PXA2XX_PIC_GPIO_0]);
sysbus_connect_irq(sysbus_from_qdev(dev), 1, pic[PXA2XX_PIC_GPIO_1]);
sysbus_connect_irq(sysbus_from_qdev(dev), 2, pic[PXA2XX_PIC_GPIO_X]);
return dev;
}
| 9,637 |
qemu | ddca7f86ac022289840e0200fd4050b2b58e9176 | 0 | static void v9fs_renameat(void *opaque)
{
ssize_t err = 0;
size_t offset = 7;
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
int32_t olddirfid, newdirfid;
V9fsString old_name, new_name;
pdu_unmarshal(pdu, offset, "dsds", &olddirfid,
&old_name, &newdirfid, &new_name);
v9fs_path_write_lock(s);
err = v9fs_complete_renameat(pdu, olddirfid,
&old_name, newdirfid, &new_name);
v9fs_path_unlock(s);
if (!err) {
err = offset;
}
complete_pdu(s, pdu, err);
v9fs_string_free(&old_name);
v9fs_string_free(&new_name);
}
| 9,638 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static int ssi_sd_init(SSISlave *d)
{
DeviceState *dev = DEVICE(d);
ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d);
DriveInfo *dinfo;
s->mode = SSI_SD_CMD;
dinfo = drive_get_next(IF_SD);
s->sd = sd_init(dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL, true);
if (s->sd == NULL) {
return -1;
}
register_savevm(dev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
return 0;
}
| 9,640 |
qemu | 82ca891283a08cddd659b534592fe00f2159bc74 | 0 | static int vfio_mmap_bar(VFIOBAR *bar, MemoryRegion *mem, MemoryRegion *submem,
void **map, size_t size, off_t offset,
const char *name)
{
int ret = 0;
if (size && bar->flags & VFIO_REGION_INFO_FLAG_MMAP) {
int prot = 0;
if (bar->flags & VFIO_REGION_INFO_FLAG_READ) {
prot |= PROT_READ;
}
if (bar->flags & VFIO_REGION_INFO_FLAG_WRITE) {
prot |= PROT_WRITE;
}
*map = mmap(NULL, size, prot, MAP_SHARED,
bar->fd, bar->fd_offset + offset);
if (*map == MAP_FAILED) {
*map = NULL;
ret = -errno;
goto empty_region;
}
memory_region_init_ram_ptr(submem, name, size, *map);
} else {
empty_region:
/* Create a zero sized sub-region to make cleanup easy. */
memory_region_init(submem, name, 0);
}
memory_region_add_subregion(mem, offset, submem);
return ret;
}
| 9,641 |
FFmpeg | e49780f749b2ce8e229fb8257cd01f60e0661b54 | 0 | int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
AVFrame temp_pic;
int i;
assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
if (pic->data[0] && (pic->width != s->width || pic->height != s->height || pic->format != s->pix_fmt)) {
av_log(s, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
pic->width, pic->height, av_get_pix_fmt_name(pic->format), s->width, s->height, av_get_pix_fmt_name(s->pix_fmt));
s->release_buffer(s, pic);
}
/* If no picture return a new buffer */
if(pic->data[0] == NULL) {
/* We will copy from buffer, so must be readable */
pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
return s->get_buffer(s, pic);
}
/* If internal buffer type return the same buffer */
if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
if(s->pkt) pic->pkt_pts= s->pkt->pts;
else pic->pkt_pts= AV_NOPTS_VALUE;
pic->reordered_opaque= s->reordered_opaque;
return 0;
}
/*
* Not internal type and reget_buffer not overridden, emulate cr buffer
*/
temp_pic = *pic;
for(i = 0; i < AV_NUM_DATA_POINTERS; i++)
pic->data[i] = pic->base[i] = NULL;
pic->opaque = NULL;
/* Allocate new frame */
if (s->get_buffer(s, pic))
return -1;
/* Copy image data from old buffer to new buffer */
av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
s->height);
s->release_buffer(s, &temp_pic); // Release old frame
return 0;
}
| 9,644 |
qemu | 7385aed20db5d83979f683b9d0048674411e963c | 0 | void helper_ldfsr(CPUSPARCState *env, uint32_t new_fsr)
{
env->fsr = (new_fsr & FSR_LDFSR_MASK) | (env->fsr & FSR_LDFSR_OLDMASK);
set_fsr(env);
}
| 9,645 |
qemu | b7680cb6078bd7294a3dd86473d3f2fdee991dd0 | 0 | void qemu_thread_self(QemuThread *thread)
{
thread->thread = pthread_self();
}
| 9,646 |
qemu | f689d2811a36894618087e1e2cc3ade78e758e94 | 1 | static int create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr,
Error **errp)
{
void * ptr;
ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
error_setg_errno(errp, errno, "Failed to mmap shared memory");
return -1;
}
s->shm_fd = fd;
memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
s->ivshmem_size, ptr);
vmstate_register_ram(&s->ivshmem, DEVICE(s));
memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
/* region for shared memory */
pci_register_bar(PCI_DEVICE(s), 2, attr, &s->bar);
return 0;
}
| 9,648 |
FFmpeg | c23acbaed40101c677dfcfbbfe0d2c230a8e8f44 | 1 | static av_always_inline int vc1_filter_line(uint8_t* src, int stride, int pq){
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
int a0_sign = a0 >> 31; /* Store sign */
a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
if(a0 < pq){
int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
if(a1 < a0 || a2 < a0){
int clip = src[-1*stride] - src[ 0*stride];
int clip_sign = clip >> 31;
clip = ((clip ^ clip_sign) - clip_sign)>>1;
if(clip){
int a3 = FFMIN(a1, a2);
int d = 5 * (a3 - a0);
int d_sign = (d >> 31);
d = ((d ^ d_sign) - d_sign) >> 3;
d_sign ^= a0_sign;
if( d_sign ^ clip_sign )
d = 0;
else{
d = FFMIN(d, clip);
d = (d ^ d_sign) - d_sign; /* Restore sign */
src[-1*stride] = cm[src[-1*stride] - d];
src[ 0*stride] = cm[src[ 0*stride] + d];
}
return 1;
}
}
}
return 0;
}
| 9,652 |
FFmpeg | 1b648c7cdbee335c642bd2c05fe624fc195b85e6 | 0 | static AVCodec *choose_codec(OptionsContext *o, AVFormatContext *s, AVStream *st, enum AVMediaType type)
{
char *codec_name = NULL;
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
if (!codec_name) {
if (s->oformat) {
st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, type);
return avcodec_find_encoder(st->codec->codec_id);
}
} else if (!strcmp(codec_name, "copy"))
st->stream_copy = 1;
else {
st->codec->codec_id = find_codec_or_die(codec_name, type, s->iformat == NULL);
return s->oformat ? avcodec_find_encoder_by_name(codec_name) :
avcodec_find_decoder_by_name(codec_name);
}
return NULL;
}
| 9,653 |
qemu | 1ee24514aed34760fb2863d98bea3a1b705d9c9f | 1 | static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)
{
NvmeCQueue *cq;
NvmeCreateCq *c = (NvmeCreateCq *)cmd;
uint16_t cqid = le16_to_cpu(c->cqid);
uint16_t vector = le16_to_cpu(c->irq_vector);
uint16_t qsize = le16_to_cpu(c->qsize);
uint16_t qflags = le16_to_cpu(c->cq_flags);
uint64_t prp1 = le64_to_cpu(c->prp1);
if (!cqid || !nvme_check_cqid(n, cqid)) {
return NVME_INVALID_CQID | NVME_DNR;
}
if (!qsize || qsize > NVME_CAP_MQES(n->bar.cap)) {
return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR;
}
if (!prp1) {
return NVME_INVALID_FIELD | NVME_DNR;
}
if (vector > n->num_queues) {
return NVME_INVALID_IRQ_VECTOR | NVME_DNR;
}
if (!(NVME_CQ_FLAGS_PC(qflags))) {
return NVME_INVALID_FIELD | NVME_DNR;
}
cq = g_malloc0(sizeof(*cq));
nvme_init_cq(cq, n, prp1, cqid, vector, qsize + 1,
NVME_CQ_FLAGS_IEN(qflags));
return NVME_SUCCESS;
}
| 9,654 |
FFmpeg | fbdab6eca7874fbeba6aa79c269f345e4d43f5d4 | 1 | static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
int16_t *src2,
int height, int denom, int wx0, int wx1,
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
{
int x, y;
pixel *src = (pixel *)_src;
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
pixel *dst = (pixel *)_dst;
ptrdiff_t dststride = _dststride / sizeof(pixel);
const int8_t *filter = ff_hevc_epel_filters[mx - 1];
int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
int shift = 14 + 1 - BIT_DEPTH;
int log2Wd = denom + shift - 1;
src -= EPEL_EXTRA_BEFORE * srcstride;
for (y = 0; y < height + EPEL_EXTRA; y++) {
for (x = 0; x < width; x++)
tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += srcstride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
filter = ff_hevc_epel_filters[my - 1];
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++)
dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
tmp += MAX_PB_SIZE;
dst += dststride;
src2 += MAX_PB_SIZE;
}
}
| 9,655 |
FFmpeg | 928dc49d0e37db50a9d1359ef910cb1856aabfaf | 1 | static int vc1_decode_p_mb(VC1Context *v, DCTELEM block[6][64])
{
MpegEncContext *s = &v->s;
GetBitContext *gb = &s->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp; /* cbp decoding stuff */
int mqdiff, mquant; /* MB quantization */
int ttmb = v->ttfrm; /* MB Transform type */
int status;
static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
offset_table[6] = { 0, 1, 3, 7, 15, 31 };
int mb_has_coeffs = 1; /* last_flag */
int dmv_x, dmv_y; /* Differential MV components */
int index, index1; /* LUT indices */
int val, sign; /* temp values */
int first_block = 1;
int dst_idx, off;
int skipped, fourmv;
mquant = v->pq; /* Loosy initialization */
if (v->mv_type_is_raw)
fourmv = get_bits1(gb);
else
fourmv = v->mv_type_mb_plane[mb_pos];
if (v->skip_is_raw)
skipped = get_bits1(gb);
else
skipped = v->s.mbskip_table[mb_pos];
s->dsp.clear_blocks(s->block[0]);
if (!fourmv) /* 1MV mode */
{
if (!skipped)
{
GET_MVDATA(dmv_x, dmv_y);
s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
vc1_pred_mv(s, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
/* FIXME Set DC val for inter block ? */
if (s->mb_intra && !mb_has_coeffs)
{
GET_MQUANT();
s->ac_pred = get_bits(gb, 1);
cbp = 0;
}
else if (mb_has_coeffs)
{
if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
}
else
{
mquant = v->pq;
cbp = 0;
}
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table,
VC1_TTMB_VLC_BITS, 2);
if(!s->mb_intra) vc1_mc_1mv(v);
dst_idx = 0;
for (i=0; i<6; i++)
{
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
v->mb_type[0][s->block_index[i]] = s->mb_intra;
if(s->mb_intra) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
if(i == 2 || i == 3 || s->mb_y)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
if(i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
vc1_decode_intra_block(v, block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
vc1_inv_trans(block[i], 8, 8);
for(j = 0; j < 64; j++) block[i][j] += 128;
s->dsp.put_pixels_clamped(block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
/* TODO: proper loop filtering */
if(v->pq >= 9 && v->overlap) {
if(v->a_avail)
s->dsp.h263_v_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
if(v->c_avail)
s->dsp.h263_h_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
}
} else if(val) {
vc1_decode_p_block(v, block[i], i, mquant, ttmb, first_block);
if(!v->ttmbf && ttmb < 8) ttmb = -1;
first_block = 0;
s->dsp.add_pixels_clamped(block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
}
}
}
else //Skipped
{
s->mb_intra = 0;
for(i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
s->current_picture.qscale_table[mb_pos] = 0;
vc1_pred_mv(s, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
vc1_mc_1mv(v);
return 0;
}
} //1MV mode
else //4MV mode
{
if (!skipped /* unskipped MB */)
{
int intra_count = 0, coded_inter = 0;
int is_intra[6], is_coded[6];
/* Get CBPCY */
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
for (i=0; i<6; i++)
{
val = ((cbp >> (5 - i)) & 1);
s->dc_val[0][s->block_index[i]] = 0;
s->mb_intra = 0;
if(i < 4) {
dmv_x = dmv_y = 0;
s->mb_intra = 0;
mb_has_coeffs = 0;
if(val) {
GET_MVDATA(dmv_x, dmv_y);
}
vc1_pred_mv(s, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
intra_count += s->mb_intra;
is_intra[i] = s->mb_intra;
is_coded[i] = mb_has_coeffs;
}
if(i&4){
is_intra[i] = (intra_count >= 3);
is_coded[i] = val;
}
if(i == 4) vc1_mc_4mv_chroma(v);
v->mb_type[0][s->block_index[i]] = is_intra[i];
if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
}
dst_idx = 0;
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
/* test if block is intra and has pred */
{
int intrapred = 0;
for(i=0; i<6; i++)
if(is_intra[i]) {
if(v->mb_type[0][s->block_index[i] - s->block_wrap[i]] || v->mb_type[0][s->block_index[i] - 1]) {
intrapred = 1;
break;
}
}
if(intrapred)s->ac_pred = get_bits(gb, 1);
else s->ac_pred = 0;
}
if (!v->ttmbf && coded_inter)
ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 12);
for (i=0; i<6; i++)
{
dst_idx += i >> 2;
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
s->mb_intra = is_intra[i];
if (is_intra[i]) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
if(i == 2 || i == 3 || s->mb_y)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
if(i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
vc1_inv_trans(block[i], 8, 8);
for(j = 0; j < 64; j++) block[i][j] += 128;
s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
/* TODO: proper loop filtering */
if(v->pq >= 9 && v->overlap) {
if(v->a_avail)
s->dsp.h263_v_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
if(v->c_avail)
s->dsp.h263_h_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
}
} else if(is_coded[i]) {
status = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block);
if(!v->ttmbf && ttmb < 8) ttmb = -1;
first_block = 0;
s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
}
}
return status;
}
else //Skipped MB
{
s->mb_intra = 0;
for (i=0; i<6; i++) v->mb_type[0][s->block_index[i]] = 0;
for (i=0; i<4; i++)
{
vc1_pred_mv(s, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
vc1_mc_4mv_luma(v, i);
}
vc1_mc_4mv_chroma(v);
s->current_picture.qscale_table[mb_pos] = 0;
return 0;
}
}
/* Should never happen */
return -1;
}
| 9,656 |
qemu | 1b7f01d966f97b7820f3cdd471461cf0799a93cc | 1 | void qemu_co_rwlock_rdlock(CoRwlock *lock)
{
while (lock->writer) {
qemu_co_queue_wait(&lock->queue);
}
lock->reader++;
} | 9,657 |
qemu | 5330f32b71b1868bdb3b444733063cb5adc4e8e6 | 1 | static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset,
uint64_t size, Error **errp)
{
int ret;
BDRVQcow2State *s = bs->opaque;
uint8_t *dir, *dir_end;
Qcow2BitmapDirEntry *e;
uint32_t nb_dir_entries = 0;
Qcow2BitmapList *bm_list = NULL;
if (size == 0) {
error_setg(errp, "Requested bitmap directory size is zero");
return NULL;
}
if (size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) {
error_setg(errp, "Requested bitmap directory size is too big");
return NULL;
}
dir = g_try_malloc(size);
if (dir == NULL) {
error_setg(errp, "Failed to allocate space for bitmap directory");
return NULL;
}
dir_end = dir + size;
ret = bdrv_pread(bs->file, offset, dir, size);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read bitmap directory");
goto fail;
}
bm_list = bitmap_list_new();
for (e = (Qcow2BitmapDirEntry *)dir;
e < (Qcow2BitmapDirEntry *)dir_end;
e = next_dir_entry(e))
{
Qcow2Bitmap *bm;
if ((uint8_t *)(e + 1) > dir_end) {
goto broken_dir;
}
if (++nb_dir_entries > s->nb_bitmaps) {
error_setg(errp, "More bitmaps found than specified in header"
" extension");
goto fail;
}
bitmap_dir_entry_to_cpu(e);
if ((uint8_t *)next_dir_entry(e) > dir_end) {
goto broken_dir;
}
if (e->extra_data_size != 0) {
error_setg(errp, "Bitmap extra data is not supported");
goto fail;
}
ret = check_dir_entry(bs, e);
if (ret < 0) {
error_setg(errp, "Bitmap '%.*s' doesn't satisfy the constraints",
e->name_size, dir_entry_name_field(e));
goto fail;
}
bm = g_new(Qcow2Bitmap, 1);
bm->table.offset = e->bitmap_table_offset;
bm->table.size = e->bitmap_table_size;
bm->flags = e->flags;
bm->granularity_bits = e->granularity_bits;
bm->name = dir_entry_copy_name(e);
QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry);
}
if (nb_dir_entries != s->nb_bitmaps) {
error_setg(errp, "Less bitmaps found than specified in header"
" extension");
goto fail;
}
if ((uint8_t *)e != dir_end) {
goto broken_dir;
}
g_free(dir);
return bm_list;
broken_dir:
ret = -EINVAL;
error_setg(errp, "Broken bitmap directory");
fail:
g_free(dir);
bitmap_list_free(bm_list);
return NULL;
}
| 9,658 |
FFmpeg | 699201ac0ef64baee261bc6fc587d00724f195af | 0 | static void test_copy(const AVCodec *c1, const AVCodec *c2)
{
AVCodecContext *ctx1, *ctx2;
printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
ctx1 = avcodec_alloc_context3(c1);
ctx2 = avcodec_alloc_context3(c2);
ctx1->width = ctx1->height = 128;
if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
av_opt_set(ctx2->priv_data, "num", "667", 0);
av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
}
avcodec_copy_context(ctx2, ctx1);
test_copy_print_codec(ctx1);
test_copy_print_codec(ctx2);
if (ctx1->codec) {
printf("opened:\n");
avcodec_open2(ctx1, ctx1->codec, NULL);
if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
av_opt_set(ctx2->priv_data, "num", "667", 0);
av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
}
avcodec_copy_context(ctx2, ctx1);
test_copy_print_codec(ctx1);
test_copy_print_codec(ctx2);
avcodec_close(ctx1);
}
avcodec_free_context(&ctx1);
avcodec_free_context(&ctx2);
}
| 9,662 |
FFmpeg | 93fa8b2bf5eb4302b2b188e7cbc44bf4909fd510 | 0 | static int process_audio_header_elements(AVFormatContext *s)
{
int inHeader = 1;
EaDemuxContext *ea = s->priv_data;
ByteIOContext *pb = &s->pb;
int compression_type;
ea->num_channels = 1;
while (inHeader) {
int inSubheader;
uint8_t byte;
byte = get_byte(pb);
switch (byte) {
case 0xFD:
av_log (s, AV_LOG_INFO, "entered audio subheader\n");
inSubheader = 1;
while (inSubheader) {
uint8_t subbyte;
subbyte = get_byte(pb);
switch (subbyte) {
case 0x82:
ea->num_channels = read_arbitary(pb);
av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
break;
case 0x83:
compression_type = read_arbitary(pb);
av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", compression_type);
break;
case 0x85:
ea->num_samples = read_arbitary(pb);
av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
break;
case 0x8A:
av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
av_log (s, AV_LOG_INFO, "exited audio subheader\n");
inSubheader = 0;
break;
case 0xFF:
av_log (s, AV_LOG_INFO, "end of header block reached (within audio subheader)\n");
inSubheader = 0;
inHeader = 0;
break;
default:
av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
break;
}
}
break;
case 0xFF:
av_log (s, AV_LOG_INFO, "end of header block reached\n");
inHeader = 0;
break;
default:
av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
break;
}
}
ea->audio_codec = CODEC_ID_ADPCM_EA;
return 1;
}
| 9,663 |
FFmpeg | b67138598ce158e3083f6295a27b63e2065d5ecb | 0 | static int vc1_decode_b_mb_intfr(VC1Context *v)
{
MpegEncContext *s = &v->s;
GetBitContext *gb = &s->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
int mqdiff, mquant; /* MB quantization */
int ttmb = v->ttfrm; /* MB Transform type */
int mvsw = 0; /* motion vector switch */
int mb_has_coeffs = 1; /* last_flag */
int dmv_x, dmv_y; /* Differential MV components */
int val; /* temp value */
int first_block = 1;
int dst_idx, off;
int skipped, direct, twomv = 0;
int block_cbp = 0, pat, block_tt = 0;
int idx_mbmode = 0, mvbp;
int stride_y, fieldtx;
int bmvtype = BMV_TYPE_BACKWARD;
int dir, dir2;
mquant = v->pq; /* Lossy initialization */
s->mb_intra = 0;
if (v->skip_is_raw)
skipped = get_bits1(gb);
else
skipped = v->s.mbskip_table[mb_pos];
if (!skipped) {
idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
twomv = 1;
v->blk_mv_type[s->block_index[0]] = 1;
v->blk_mv_type[s->block_index[1]] = 1;
v->blk_mv_type[s->block_index[2]] = 1;
v->blk_mv_type[s->block_index[3]] = 1;
} else {
v->blk_mv_type[s->block_index[0]] = 0;
v->blk_mv_type[s->block_index[1]] = 0;
v->blk_mv_type[s->block_index[2]] = 0;
v->blk_mv_type[s->block_index[3]] = 0;
}
}
if (v->dmb_is_raw)
direct = get_bits1(gb);
else
direct = v->direct_mb_plane[mb_pos];
if (direct) {
s->mv[0][0][0] = s->current_picture.motion_val[0][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 0, s->quarter_sample);
s->mv[0][0][1] = s->current_picture.motion_val[0][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 0, s->quarter_sample);
s->mv[1][0][0] = s->current_picture.motion_val[1][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 1, s->quarter_sample);
s->mv[1][0][1] = s->current_picture.motion_val[1][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 1, s->quarter_sample);
if (twomv) {
s->mv[0][2][0] = s->current_picture.motion_val[0][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 0, s->quarter_sample);
s->mv[0][2][1] = s->current_picture.motion_val[0][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 0, s->quarter_sample);
s->mv[1][2][0] = s->current_picture.motion_val[1][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 1, s->quarter_sample);
s->mv[1][2][1] = s->current_picture.motion_val[1][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 1, s->quarter_sample);
for (i = 1; i < 4; i += 2) {
s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][i-1][0];
s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][i-1][1];
s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][i-1][0];
s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][i-1][1];
}
} else {
for (i = 1; i < 4; i++) {
s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][0][0];
s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][0][1];
s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][0][0];
s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][0][1];
}
}
}
if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
for (i = 0; i < 4; i++) {
s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = 0;
s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = 0;
s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
}
s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
s->mb_intra = v->is_intra[s->mb_x] = 1;
for (i = 0; i < 6; i++)
v->mb_type[0][s->block_index[i]] = 1;
fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = get_bits1(gb);
if (mb_has_coeffs)
cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
/* Set DC scale - y and c use the same (not sure if necessary here) */
s->y_dc_scale = s->y_dc_scale_table[mquant];
s->c_dc_scale = s->c_dc_scale_table[mquant];
dst_idx = 0;
for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
v->mb_type[0][s->block_index[i]] = s->mb_intra;
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
vc1_decode_intra_block(v, s->block[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
if (i > 3 && (s->flags & CODEC_FLAG_GRAY))
continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
if (i < 4) {
stride_y = s->linesize << fieldtx;
off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
} else {
stride_y = s->uvlinesize;
off = 0;
}
s->idsp.put_signed_pixels_clamped(s->block[i],
s->dest[dst_idx] + off,
stride_y);
}
} else {
s->mb_intra = v->is_intra[s->mb_x] = 0;
if (!direct) {
if (skipped || !s->mb_intra) {
bmvtype = decode012(gb);
switch (bmvtype) {
case 0:
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
break;
case 1:
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
break;
case 2:
bmvtype = BMV_TYPE_INTERPOLATED;
}
}
if (twomv && bmvtype != BMV_TYPE_INTERPOLATED)
mvsw = get_bits1(gb);
}
if (!skipped) { // inter MB
mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
if (mb_has_coeffs)
cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
if (!direct) {
if (bmvtype == BMV_TYPE_INTERPOLATED && twomv) {
v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
} else if (bmvtype == BMV_TYPE_INTERPOLATED || twomv) {
v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
}
}
for (i = 0; i < 6; i++)
v->mb_type[0][s->block_index[i]] = 0;
fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[0][idx_mbmode][1];
/* for all motion vector read MVDATA and motion compensate each block */
dst_idx = 0;
if (direct) {
if (twomv) {
for (i = 0; i < 4; i++) {
ff_vc1_mc_4mv_luma(v, i, 0, 0);
ff_vc1_mc_4mv_luma(v, i, 1, 1);
}
ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
} else {
ff_vc1_mc_1mv(v, 0);
ff_vc1_interp_mc(v);
}
} else if (twomv && bmvtype == BMV_TYPE_INTERPOLATED) {
mvbp = v->fourmvbp;
for (i = 0; i < 4; i++) {
dir = i==1 || i==3;
dmv_x = dmv_y = 0;
val = ((mvbp >> (3 - i)) & 1);
if (val)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
j = i > 1 ? 2 : 0;
ff_vc1_pred_mv_intfr(v, j, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
ff_vc1_mc_4mv_luma(v, j, dir, dir);
ff_vc1_mc_4mv_luma(v, j+1, dir, dir);
}
ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
} else if (bmvtype == BMV_TYPE_INTERPOLATED) {
mvbp = v->twomvbp;
dmv_x = dmv_y = 0;
if (mvbp & 2)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0);
ff_vc1_mc_1mv(v, 0);
dmv_x = dmv_y = 0;
if (mvbp & 1)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 1);
ff_vc1_interp_mc(v);
} else if (twomv) {
dir = bmvtype == BMV_TYPE_BACKWARD;
dir2 = dir;
if (mvsw)
dir2 = !dir;
mvbp = v->twomvbp;
dmv_x = dmv_y = 0;
if (mvbp & 2)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
dmv_x = dmv_y = 0;
if (mvbp & 1)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
ff_vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir2);
if (mvsw) {
for (i = 0; i < 2; i++) {
s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
}
} else {
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
ff_vc1_pred_mv_intfr(v, 2, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
}
ff_vc1_mc_4mv_luma(v, 0, dir, 0);
ff_vc1_mc_4mv_luma(v, 1, dir, 0);
ff_vc1_mc_4mv_luma(v, 2, dir2, 0);
ff_vc1_mc_4mv_luma(v, 3, dir2, 0);
ff_vc1_mc_4mv_chroma4(v, dir, dir2, 0);
} else {
dir = bmvtype == BMV_TYPE_BACKWARD;
mvbp = ff_vc1_mbmode_intfrp[0][idx_mbmode][2];
dmv_x = dmv_y = 0;
if (mvbp)
get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], dir);
v->blk_mv_type[s->block_index[0]] = 1;
v->blk_mv_type[s->block_index[1]] = 1;
v->blk_mv_type[s->block_index[2]] = 1;
v->blk_mv_type[s->block_index[3]] = 1;
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
for (i = 0; i < 2; i++) {
s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
}
ff_vc1_mc_1mv(v, dir);
}
if (cbp)
GET_MQUANT(); // p. 227
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && cbp)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (!fieldtx)
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
else
off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
if (val) {
pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
first_block, s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
(i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
block_cbp |= pat << (i << 2);
if (!v->ttmbf && ttmb < 8)
ttmb = -1;
first_block = 0;
}
}
} else { // skipped
dir = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
s->dc_val[0][s->block_index[i]] = 0;
}
s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
s->current_picture.qscale_table[mb_pos] = 0;
v->blk_mv_type[s->block_index[0]] = 0;
v->blk_mv_type[s->block_index[1]] = 0;
v->blk_mv_type[s->block_index[2]] = 0;
v->blk_mv_type[s->block_index[3]] = 0;
if (!direct) {
if (bmvtype == BMV_TYPE_INTERPOLATED) {
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0);
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 1);
} else {
dir = bmvtype == BMV_TYPE_BACKWARD;
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], dir);
if (mvsw) {
int dir2 = dir;
if (mvsw)
dir2 = !dir;
for (i = 0; i < 2; i++) {
s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
}
} else {
v->blk_mv_type[s->block_index[0]] = 1;
v->blk_mv_type[s->block_index[1]] = 1;
v->blk_mv_type[s->block_index[2]] = 1;
v->blk_mv_type[s->block_index[3]] = 1;
ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
for (i = 0; i < 2; i++) {
s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
}
}
}
}
ff_vc1_mc_1mv(v, dir);
if (direct || bmvtype == BMV_TYPE_INTERPOLATED) {
ff_vc1_interp_mc(v);
}
}
}
if (s->mb_x == s->mb_width - 1)
memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
v->cbp[s->mb_x] = block_cbp;
v->ttblk[s->mb_x] = block_tt;
return 0;
}
| 9,664 |
FFmpeg | 033e58941e684ac7190d6d1b06f31a677be4539f | 0 | static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
{
int start = 0, w, w2, g;
const float lambda = s->lambda;
const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f;
const float spread_threshold = NOISE_SPREAD_THRESHOLD*(lambda/120.f);
const float thr_mult = NOISE_LAMBDA_NUMERATOR/lambda;
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
start = 0;
for (g = 0; g < sce->ics.num_swb; g++) {
if (start*freq_mult > NOISE_LOW_LIMIT*(lambda/170.0f)) {
float energy = 0.0f, threshold = 0.0f, spread = 0.0f;
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
FFPsyBand *band = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
energy += band->energy;
threshold += band->threshold;
spread += band->spread;
}
if (spread > spread_threshold*sce->ics.group_len[w] &&
((sce->zeroes[w*16+g] && energy >= threshold) ||
energy < threshold*thr_mult*sce->ics.group_len[w])) {
sce->band_type[w*16+g] = NOISE_BT;
sce->pns_ener[w*16+g] = energy / sce->ics.group_len[w];
sce->zeroes[w*16+g] = 0;
}
}
start += sce->ics.swb_sizes[g];
}
}
}
| 9,665 |
qemu | c21bbcfa3ff4f6dc49fb01080ef598851aa424dd | 0 | static void curses_calc_pad(void)
{
if (is_graphic_console()) {
width = gwidth;
height = gheight;
} else {
width = COLS;
height = LINES;
}
if (screenpad)
delwin(screenpad);
clear();
refresh();
screenpad = newpad(height, width);
if (width > COLS) {
px = (width - COLS) / 2;
sminx = 0;
smaxx = COLS;
} else {
px = 0;
sminx = (COLS - width) / 2;
smaxx = sminx + width;
}
if (height > LINES) {
py = (height - LINES) / 2;
sminy = 0;
smaxy = LINES;
} else {
py = 0;
sminy = (LINES - height) / 2;
smaxy = sminy + height;
}
}
| 9,667 |
qemu | 9a78eead0c74333a394c0f7bbfc4423ac746fcd5 | 0 | static void fpu_dump_state(CPUState *env, FILE *f,
int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
int flags)
{
int i;
int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
#define printfpr(fp) \
do { \
if (is_fpu64) \
fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
" fd:%13g fs:%13g psu: %13g\n", \
(fp)->w[FP_ENDIAN_IDX], (fp)->d, \
(double)(fp)->fd, \
(double)(fp)->fs[FP_ENDIAN_IDX], \
(double)(fp)->fs[!FP_ENDIAN_IDX]); \
else { \
fpr_t tmp; \
tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
fpu_fprintf(f, "w:%08x d:%016" PRIx64 \
" fd:%13g fs:%13g psu:%13g\n", \
tmp.w[FP_ENDIAN_IDX], tmp.d, \
(double)tmp.fd, \
(double)tmp.fs[FP_ENDIAN_IDX], \
(double)tmp.fs[!FP_ENDIAN_IDX]); \
} \
} while(0)
fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
get_float_exception_flags(&env->active_fpu.fp_status));
for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
fpu_fprintf(f, "%3s: ", fregnames[i]);
printfpr(&env->active_fpu.fpr[i]);
}
#undef printfpr
}
| 9,668 |
qemu | 2c62f08ddbf3fa80dc7202eb9a2ea60ae44e2cc5 | 0 | static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
Error **errp)
{
PCIQXLDevice *qxl = opaque;
VGACommonState *vga = &qxl->vga;
switch (qxl->mode) {
case QXL_MODE_COMPAT:
case QXL_MODE_NATIVE:
qxl_render_update(qxl);
ppm_save(filename, qxl->ssd.ds, errp);
break;
case QXL_MODE_VGA:
vga->screen_dump(vga, filename, cswitch, errp);
break;
default:
break;
}
}
| 9,671 |
qemu | 51fc44768a5b71ad78fa40e609a58f71ed62775a | 0 | void qmp_input_send_event(int64_t console, InputEventList *events,
Error **errp)
{
InputEventList *e;
QemuConsole *con;
con = qemu_console_lookup_by_index(console);
if (!con) {
error_setg(errp, "console %" PRId64 " not found", console);
return;
}
if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
error_setg(errp, "VM not running");
return;
}
for (e = events; e != NULL; e = e->next) {
InputEvent *event = e->value;
if (!qemu_input_find_handler(1 << event->kind, con)) {
error_setg(errp, "Input handler not found for "
"event type %s",
InputEventKind_lookup[event->kind]);
return;
}
}
for (e = events; e != NULL; e = e->next) {
InputEvent *event = e->value;
qemu_input_event_send(con, event);
}
qemu_input_event_sync();
}
| 9,672 |
FFmpeg | fea471347218be0b8d1313b8f14ea9512e555d76 | 0 | static av_cold int cuvid_decode_init(AVCodecContext *avctx)
{
CuvidContext *ctx = avctx->priv_data;
AVCUDADeviceContext *device_hwctx;
AVHWDeviceContext *device_ctx;
AVHWFramesContext *hwframe_ctx;
CUVIDSOURCEDATAPACKET seq_pkt;
CUcontext cuda_ctx = NULL;
CUcontext dummy;
const AVBitStreamFilter *bsf;
int ret = 0;
enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA,
AV_PIX_FMT_NV12,
AV_PIX_FMT_NONE };
int probed_width = avctx->coded_width ? avctx->coded_width : 1280;
int probed_height = avctx->coded_height ? avctx->coded_height : 720;
// Accelerated transcoding scenarios with 'ffmpeg' require that the
// pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the
// pix_fmt for non-accelerated transcoding, do not need to be correct
// but need to be set to something. We arbitrarily pick NV12.
ret = ff_get_format(avctx, pix_fmts);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret);
return ret;
}
avctx->pix_fmt = ret;
if (ctx->resize_expr && sscanf(ctx->resize_expr, "%dx%d",
&ctx->resize.width, &ctx->resize.height) != 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid resize expressions\n");
ret = AVERROR(EINVAL);
goto error;
}
if (ctx->crop_expr && sscanf(ctx->crop_expr, "%dx%dx%dx%d",
&ctx->crop.top, &ctx->crop.bottom,
&ctx->crop.left, &ctx->crop.right) != 4) {
av_log(avctx, AV_LOG_ERROR, "Invalid cropping expressions\n");
ret = AVERROR(EINVAL);
goto error;
}
ret = cuvid_load_functions(&ctx->cvdl);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
goto error;
}
ctx->frame_queue = av_fifo_alloc(ctx->nb_surfaces * sizeof(CuvidParsedFrame));
if (!ctx->frame_queue) {
ret = AVERROR(ENOMEM);
goto error;
}
if (avctx->hw_frames_ctx) {
ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
if (!ctx->hwframe) {
ret = AVERROR(ENOMEM);
goto error;
}
hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
ctx->hwdevice = av_buffer_ref(hwframe_ctx->device_ref);
if (!ctx->hwdevice) {
ret = AVERROR(ENOMEM);
goto error;
}
} else {
if (avctx->hw_device_ctx) {
ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx);
if (!ctx->hwdevice) {
ret = AVERROR(ENOMEM);
goto error;
}
} else {
ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0);
if (ret < 0)
goto error;
}
ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice);
if (!ctx->hwframe) {
av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n");
ret = AVERROR(ENOMEM);
goto error;
}
hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
}
device_ctx = hwframe_ctx->device_ctx;
device_hwctx = device_ctx->hwctx;
cuda_ctx = device_hwctx->cuda_ctx;
ctx->cudl = device_hwctx->internal->cuda_dl;
memset(&ctx->cuparseinfo, 0, sizeof(ctx->cuparseinfo));
memset(&ctx->cuparse_ext, 0, sizeof(ctx->cuparse_ext));
memset(&seq_pkt, 0, sizeof(seq_pkt));
ctx->cuparseinfo.pExtVideoInfo = &ctx->cuparse_ext;
switch (avctx->codec->id) {
#if CONFIG_H264_CUVID_DECODER
case AV_CODEC_ID_H264:
ctx->cuparseinfo.CodecType = cudaVideoCodec_H264;
break;
#endif
#if CONFIG_HEVC_CUVID_DECODER
case AV_CODEC_ID_HEVC:
ctx->cuparseinfo.CodecType = cudaVideoCodec_HEVC;
break;
#endif
#if CONFIG_MJPEG_CUVID_DECODER
case AV_CODEC_ID_MJPEG:
ctx->cuparseinfo.CodecType = cudaVideoCodec_JPEG;
break;
#endif
#if CONFIG_MPEG1_CUVID_DECODER
case AV_CODEC_ID_MPEG1VIDEO:
ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG1;
break;
#endif
#if CONFIG_MPEG2_CUVID_DECODER
case AV_CODEC_ID_MPEG2VIDEO:
ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG2;
break;
#endif
#if CONFIG_MPEG4_CUVID_DECODER
case AV_CODEC_ID_MPEG4:
ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG4;
break;
#endif
#if CONFIG_VP8_CUVID_DECODER
case AV_CODEC_ID_VP8:
ctx->cuparseinfo.CodecType = cudaVideoCodec_VP8;
break;
#endif
#if CONFIG_VP9_CUVID_DECODER
case AV_CODEC_ID_VP9:
ctx->cuparseinfo.CodecType = cudaVideoCodec_VP9;
break;
#endif
#if CONFIG_VC1_CUVID_DECODER
case AV_CODEC_ID_VC1:
ctx->cuparseinfo.CodecType = cudaVideoCodec_VC1;
break;
#endif
default:
av_log(avctx, AV_LOG_ERROR, "Invalid CUVID codec!\n");
return AVERROR_BUG;
}
if (avctx->codec->id == AV_CODEC_ID_H264 || avctx->codec->id == AV_CODEC_ID_HEVC) {
if (avctx->codec->id == AV_CODEC_ID_H264)
bsf = av_bsf_get_by_name("h264_mp4toannexb");
else
bsf = av_bsf_get_by_name("hevc_mp4toannexb");
if (!bsf) {
ret = AVERROR_BSF_NOT_FOUND;
goto error;
}
if (ret = av_bsf_alloc(bsf, &ctx->bsf)) {
goto error;
}
if (((ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx)) < 0) || ((ret = av_bsf_init(ctx->bsf)) < 0)) {
av_bsf_free(&ctx->bsf);
goto error;
}
ctx->cuparse_ext.format.seqhdr_data_length = ctx->bsf->par_out->extradata_size;
memcpy(ctx->cuparse_ext.raw_seqhdr_data,
ctx->bsf->par_out->extradata,
FFMIN(sizeof(ctx->cuparse_ext.raw_seqhdr_data), ctx->bsf->par_out->extradata_size));
} else if (avctx->extradata_size > 0) {
ctx->cuparse_ext.format.seqhdr_data_length = avctx->extradata_size;
memcpy(ctx->cuparse_ext.raw_seqhdr_data,
avctx->extradata,
FFMIN(sizeof(ctx->cuparse_ext.raw_seqhdr_data), avctx->extradata_size));
}
ctx->cuparseinfo.ulMaxNumDecodeSurfaces = ctx->nb_surfaces;
ctx->cuparseinfo.ulMaxDisplayDelay = 4;
ctx->cuparseinfo.pUserData = avctx;
ctx->cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
ctx->cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode;
ctx->cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display;
ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0)
goto error;
ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo,
probed_width,
probed_height);
if (ret < 0)
goto error;
ret = CHECK_CU(ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo));
if (ret < 0)
goto error;
seq_pkt.payload = ctx->cuparse_ext.raw_seqhdr_data;
seq_pkt.payload_size = ctx->cuparse_ext.format.seqhdr_data_length;
if (seq_pkt.payload && seq_pkt.payload_size) {
ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt));
if (ret < 0)
goto error;
}
ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
if (ret < 0)
goto error;
ctx->prev_pts = INT64_MIN;
if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den)
av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
return 0;
error:
cuvid_decode_end(avctx);
return ret;
}
| 9,673 |
FFmpeg | 4c9080a7ef18ad71fb0a75c8d1c1803edd780edd | 0 | static void default_end_frame(AVFilterLink *inlink)
{
AVFilterLink *outlink = NULL;
if (inlink->dst->nb_outputs)
outlink = inlink->dst->outputs[0];
if (outlink) {
if (outlink->out_buf) {
avfilter_unref_buffer(outlink->out_buf);
outlink->out_buf = NULL;
}
ff_end_frame(outlink);
}
}
| 9,674 |
qemu | 6e0d8677cb443e7408c0b7a25a93c6596d7fa380 | 0 | static inline void gen_op_addq_ESP_im(int32_t val)
{
tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[R_ESP]));
tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, val);
tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[R_ESP]));
}
| 9,675 |
qemu | f0536bb848ad6eb2709a7dc675f261bd160c751b | 0 | static int img_snapshot(int argc, char **argv)
{
BlockDriverState *bs;
QEMUSnapshotInfo sn;
char *filename, *snapshot_name = NULL;
int c, ret = 0, bdrv_oflags;
int action = 0;
qemu_timeval tv;
bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;
/* Parse commandline parameters */
for(;;) {
c = getopt(argc, argv, "la:c:d:h");
if (c == -1) {
break;
}
switch(c) {
case '?':
case 'h':
help();
return 0;
case 'l':
if (action) {
help();
return 0;
}
action = SNAPSHOT_LIST;
bdrv_oflags &= ~BDRV_O_RDWR; /* no need for RW */
break;
case 'a':
if (action) {
help();
return 0;
}
action = SNAPSHOT_APPLY;
snapshot_name = optarg;
break;
case 'c':
if (action) {
help();
return 0;
}
action = SNAPSHOT_CREATE;
snapshot_name = optarg;
break;
case 'd':
if (action) {
help();
return 0;
}
action = SNAPSHOT_DELETE;
snapshot_name = optarg;
break;
}
}
if (optind >= argc) {
help();
}
filename = argv[optind++];
/* Open the image */
bs = bdrv_new_open(filename, NULL, bdrv_oflags);
if (!bs) {
return 1;
}
/* Perform the requested action */
switch(action) {
case SNAPSHOT_LIST:
dump_snapshots(bs);
break;
case SNAPSHOT_CREATE:
memset(&sn, 0, sizeof(sn));
pstrcpy(sn.name, sizeof(sn.name), snapshot_name);
qemu_gettimeofday(&tv);
sn.date_sec = tv.tv_sec;
sn.date_nsec = tv.tv_usec * 1000;
ret = bdrv_snapshot_create(bs, &sn);
if (ret) {
error_report("Could not create snapshot '%s': %d (%s)",
snapshot_name, ret, strerror(-ret));
}
break;
case SNAPSHOT_APPLY:
ret = bdrv_snapshot_goto(bs, snapshot_name);
if (ret) {
error_report("Could not apply snapshot '%s': %d (%s)",
snapshot_name, ret, strerror(-ret));
}
break;
case SNAPSHOT_DELETE:
ret = bdrv_snapshot_delete(bs, snapshot_name);
if (ret) {
error_report("Could not delete snapshot '%s': %d (%s)",
snapshot_name, ret, strerror(-ret));
}
break;
}
/* Cleanup */
bdrv_delete(bs);
if (ret) {
return 1;
}
return 0;
}
| 9,676 |
qemu | 488a1a5dfe9a9ba57fa6c6b6b98136ea494e0296 | 0 | static void pcnet_aprom_writeb(void *opaque, uint32_t addr, uint32_t val)
{
PCNetState *s = opaque;
#ifdef PCNET_DEBUG
printf("pcnet_aprom_writeb addr=0x%08x val=0x%02x\n", addr, val);
#endif
/* Check APROMWE bit to enable write access */
if (pcnet_bcr_readw(s,2) & 0x100)
s->prom[addr & 15] = val;
}
| 9,677 |
qemu | 0eb4a8c1df6db29e835daeb954352bfaa8994374 | 0 | static int qcow2_create2(const char *filename, int64_t total_size,
const char *backing_file, const char *backing_format,
int flags, size_t cluster_size, PreallocMode prealloc,
QemuOpts *opts, int version, int refcount_order,
const char *encryptfmt, Error **errp)
{
int cluster_bits;
QDict *options;
/* Calculate cluster_bits */
cluster_bits = ctz32(cluster_size);
if (cluster_bits < MIN_CLUSTER_BITS || cluster_bits > MAX_CLUSTER_BITS ||
(1 << cluster_bits) != cluster_size)
{
error_setg(errp, "Cluster size must be a power of two between %d and "
"%dk", 1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - 10));
return -EINVAL;
}
/*
* Open the image file and write a minimal qcow2 header.
*
* We keep things simple and start with a zero-sized image. We also
* do without refcount blocks or a L1 table for now. We'll fix the
* inconsistency later.
*
* We do need a refcount table because growing the refcount table means
* allocating two new refcount blocks - the seconds of which would be at
* 2 GB for 64k clusters, and we don't want to have a 2 GB initial file
* size for any qcow2 image.
*/
BlockBackend *blk;
QCowHeader *header;
uint64_t* refcount_table;
Error *local_err = NULL;
int ret;
if (prealloc == PREALLOC_MODE_FULL || prealloc == PREALLOC_MODE_FALLOC) {
int64_t prealloc_size =
qcow2_calc_prealloc_size(total_size, cluster_size, refcount_order);
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_abort);
qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc],
&error_abort);
}
ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
return ret;
}
blk = blk_new_open(filename, NULL, NULL,
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
&local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
return -EIO;
}
blk_set_allow_write_beyond_eof(blk, true);
/* Write the header */
QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
header = g_malloc0(cluster_size);
*header = (QCowHeader) {
.magic = cpu_to_be32(QCOW_MAGIC),
.version = cpu_to_be32(version),
.cluster_bits = cpu_to_be32(cluster_bits),
.size = cpu_to_be64(0),
.l1_table_offset = cpu_to_be64(0),
.l1_size = cpu_to_be32(0),
.refcount_table_offset = cpu_to_be64(cluster_size),
.refcount_table_clusters = cpu_to_be32(1),
.refcount_order = cpu_to_be32(refcount_order),
.header_length = cpu_to_be32(sizeof(*header)),
};
/* We'll update this to correct value later */
header->crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
if (flags & BLOCK_FLAG_LAZY_REFCOUNTS) {
header->compatible_features |=
cpu_to_be64(QCOW2_COMPAT_LAZY_REFCOUNTS);
}
ret = blk_pwrite(blk, 0, header, cluster_size, 0);
g_free(header);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write qcow2 header");
goto out;
}
/* Write a refcount table with one refcount block */
refcount_table = g_malloc0(2 * cluster_size);
refcount_table[0] = cpu_to_be64(2 * cluster_size);
ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size, 0);
g_free(refcount_table);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write refcount table");
goto out;
}
blk_unref(blk);
blk = NULL;
/*
* And now open the image and make it consistent first (i.e. increase the
* refcount of the cluster that is occupied by the header and the refcount
* table)
*/
options = qdict_new();
qdict_put_str(options, "driver", "qcow2");
blk = blk_new_open(filename, NULL, options,
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
&local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
goto out;
}
ret = qcow2_alloc_clusters(blk_bs(blk), 3 * cluster_size);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not allocate clusters for qcow2 "
"header and refcount table");
goto out;
} else if (ret != 0) {
error_report("Huh, first cluster in empty image is already in use?");
abort();
}
/* Create a full header (including things like feature table) */
ret = qcow2_update_header(blk_bs(blk));
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not update qcow2 header");
goto out;
}
/* Okay, now that we have a valid image, let's give it the right size */
ret = blk_truncate(blk, total_size, errp);
if (ret < 0) {
error_prepend(errp, "Could not resize image: ");
goto out;
}
/* Want a backing file? There you go.*/
if (backing_file) {
ret = bdrv_change_backing_file(blk_bs(blk), backing_file, backing_format);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not assign backing file '%s' "
"with format '%s'", backing_file, backing_format);
goto out;
}
}
/* Want encryption? There you go. */
if (encryptfmt) {
ret = qcow2_set_up_encryption(blk_bs(blk), encryptfmt, opts, errp);
if (ret < 0) {
goto out;
}
}
/* And if we're supposed to preallocate metadata, do that now */
if (prealloc != PREALLOC_MODE_OFF) {
BDRVQcow2State *s = blk_bs(blk)->opaque;
qemu_co_mutex_lock(&s->lock);
ret = preallocate(blk_bs(blk));
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not preallocate metadata");
goto out;
}
}
blk_unref(blk);
blk = NULL;
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning.
* Using BDRV_O_NO_IO, since encryption is now setup we don't want to
* have to setup decryption context. We're not doing any I/O on the top
* level BlockDriverState, only lower layers, where BDRV_O_NO_IO does
* not have effect.
*/
options = qdict_new();
qdict_put_str(options, "driver", "qcow2");
blk = blk_new_open(filename, NULL, options,
BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
&local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
goto out;
}
ret = 0;
out:
if (blk) {
blk_unref(blk);
}
return ret;
}
| 9,679 |
qemu | 7084851534c834f00652f90a9da5e4032bd22130 | 0 | static int protocol_version(VncState *vs, char *version, size_t len)
{
char local[13];
int maj, min;
memcpy(local, version, 12);
local[12] = 0;
if (sscanf(local, "RFB %03d.%03d\n", &maj, &min) != 2) {
vnc_client_error(vs);
return 0;
}
vnc_write_u32(vs, 1); /* None */
vnc_flush(vs);
vnc_read_when(vs, protocol_client_init, 1);
return 0;
}
| 9,680 |
qemu | 903585dec63ee83bd8149006e31f92ea789b38e3 | 0 | void ppce500_init(MachineState *machine, PPCE500Params *params)
{
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *ram = g_new(MemoryRegion, 1);
PCIBus *pci_bus;
CPUPPCState *env = NULL;
uint64_t elf_entry;
uint64_t elf_lowaddr;
hwaddr entry=0;
hwaddr loadaddr=UIMAGE_LOAD_BASE;
target_long kernel_size=0;
target_ulong dt_base = 0;
target_ulong initrd_base = 0;
target_long initrd_size = 0;
target_ulong cur_base = 0;
int i;
/* irq num for pin INTA, INTB, INTC and INTD is 1, 2, 3 and
* 4 respectively */
unsigned int pci_irq_nrs[PCI_NUM_PINS] = {1, 2, 3, 4};
qemu_irq **irqs, *mpic;
DeviceState *dev;
CPUPPCState *firstenv = NULL;
MemoryRegion *ccsr_addr_space;
SysBusDevice *s;
PPCE500CCSRState *ccsr;
/* Setup CPUs */
if (machine->cpu_model == NULL) {
machine->cpu_model = "e500v2_v30";
}
irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
for (i = 0; i < smp_cpus; i++) {
PowerPCCPU *cpu;
CPUState *cs;
qemu_irq *input;
cpu = cpu_ppc_init(machine->cpu_model);
if (cpu == NULL) {
fprintf(stderr, "Unable to initialize CPU!\n");
exit(1);
}
env = &cpu->env;
cs = CPU(cpu);
if (!firstenv) {
firstenv = env;
}
irqs[i] = irqs[0] + (i * OPENPIC_OUTPUT_NB);
input = (qemu_irq *)env->irq_inputs;
irqs[i][OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
irqs[i][OPENPIC_OUTPUT_CINT] = input[PPCE500_INPUT_CINT];
env->spr_cb[SPR_BOOKE_PIR].default_value = cs->cpu_index = i;
env->mpic_iack = MPC8544_CCSRBAR_BASE +
MPC8544_MPIC_REGS_OFFSET + 0xa0;
ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500);
/* Register reset handler */
if (!i) {
/* Primary CPU */
struct boot_info *boot_info;
boot_info = g_malloc0(sizeof(struct boot_info));
qemu_register_reset(ppce500_cpu_reset, cpu);
env->load_info = boot_info;
} else {
/* Secondary CPUs */
qemu_register_reset(ppce500_cpu_reset_sec, cpu);
}
}
env = firstenv;
/* Fixup Memory size on a alignment boundary */
ram_size &= ~(RAM_SIZES_ALIGN - 1);
machine->ram_size = ram_size;
/* Register Memory */
memory_region_init_ram(ram, NULL, "mpc8544ds.ram", ram_size);
vmstate_register_ram_global(ram);
memory_region_add_subregion(address_space_mem, 0, ram);
dev = qdev_create(NULL, "e500-ccsr");
object_property_add_child(qdev_get_machine(), "e500-ccsr",
OBJECT(dev), NULL);
qdev_init_nofail(dev);
ccsr = CCSR(dev);
ccsr_addr_space = &ccsr->ccsr_space;
memory_region_add_subregion(address_space_mem, MPC8544_CCSRBAR_BASE,
ccsr_addr_space);
mpic = ppce500_init_mpic(params, ccsr_addr_space, irqs);
/* Serial */
if (serial_hds[0]) {
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET,
0, mpic[42], 399193,
serial_hds[0], DEVICE_BIG_ENDIAN);
}
if (serial_hds[1]) {
serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET,
0, mpic[42], 399193,
serial_hds[1], DEVICE_BIG_ENDIAN);
}
/* General Utility device */
dev = qdev_create(NULL, "mpc8544-guts");
qdev_init_nofail(dev);
s = SYS_BUS_DEVICE(dev);
memory_region_add_subregion(ccsr_addr_space, MPC8544_UTIL_OFFSET,
sysbus_mmio_get_region(s, 0));
/* PCI */
dev = qdev_create(NULL, "e500-pcihost");
qdev_prop_set_uint32(dev, "first_slot", params->pci_first_slot);
qdev_prop_set_uint32(dev, "first_pin_irq", pci_irq_nrs[0]);
qdev_init_nofail(dev);
s = SYS_BUS_DEVICE(dev);
for (i = 0; i < PCI_NUM_PINS; i++) {
sysbus_connect_irq(s, i, mpic[pci_irq_nrs[i]]);
}
memory_region_add_subregion(ccsr_addr_space, MPC8544_PCI_REGS_OFFSET,
sysbus_mmio_get_region(s, 0));
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
if (!pci_bus)
printf("couldn't create PCI controller!\n");
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, MPC8544_PCI_IO);
if (pci_bus) {
/* Register network interfaces. */
for (i = 0; i < nb_nics; i++) {
pci_nic_init_nofail(&nd_table[i], pci_bus, "virtio", NULL);
}
}
/* Register spinning region */
sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL);
/* Load kernel. */
if (machine->kernel_filename) {
kernel_size = load_uimage(machine->kernel_filename, &entry,
&loadaddr, NULL);
if (kernel_size < 0) {
kernel_size = load_elf(machine->kernel_filename, NULL, NULL,
&elf_entry, &elf_lowaddr, NULL, 1,
ELF_MACHINE, 0);
entry = elf_entry;
loadaddr = elf_lowaddr;
}
/* XXX try again as binary */
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
machine->kernel_filename);
exit(1);
}
cur_base = loadaddr + kernel_size;
/* Reserve space for dtb */
dt_base = (cur_base + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
cur_base += DTB_MAX_SIZE;
}
/* Load initrd. */
if (machine->initrd_filename) {
initrd_base = (cur_base + INITRD_LOAD_PAD) & ~INITRD_PAD_MASK;
initrd_size = load_image_targphys(machine->initrd_filename, initrd_base,
ram_size - initrd_base);
if (initrd_size < 0) {
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
machine->initrd_filename);
exit(1);
}
cur_base = initrd_base + initrd_size;
}
/* If we're loading a kernel directly, we must load the device tree too. */
if (machine->kernel_filename) {
struct boot_info *boot_info;
int dt_size;
dt_size = ppce500_prep_device_tree(machine, params, dt_base,
initrd_base, initrd_size);
if (dt_size < 0) {
fprintf(stderr, "couldn't load device tree\n");
exit(1);
}
assert(dt_size < DTB_MAX_SIZE);
boot_info = env->load_info;
boot_info->entry = entry;
boot_info->dt_base = dt_base;
boot_info->dt_size = dt_size;
}
if (kvm_enabled()) {
kvmppc_init();
}
}
| 9,681 |
qemu | cf528b89580797050b8cf60fee6247f35531a675 | 0 | static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs)
{
int i;
NetClientState *nc;
n->mergeable_rx_bufs = mergeable_rx_bufs;
n->guest_hdr_len = n->mergeable_rx_bufs ?
sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
for (i = 0; i < n->max_queues; i++) {
nc = qemu_get_subqueue(n->nic, i);
if (peer_has_vnet_hdr(n) &&
tap_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) {
tap_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);
n->host_hdr_len = n->guest_hdr_len;
}
}
}
| 9,682 |
qemu | 72cf2d4f0e181d0d3a3122e04129c58a95da713e | 0 | void qemu_acl_reset(qemu_acl *acl)
{
qemu_acl_entry *entry;
/* Put back to deny by default, so there is no window
* of "open access" while the user re-initializes the
* access control list */
acl->defaultDeny = 1;
TAILQ_FOREACH(entry, &acl->entries, next) {
TAILQ_REMOVE(&acl->entries, entry, next);
free(entry->match);
free(entry);
}
acl->nentries = 0;
}
| 9,684 |
FFmpeg | 93db5e3fc41ac0242acab86c3e4ce3a3dfb80075 | 0 | static void mov_fix_index(MOVContext *mov, AVStream *st)
{
MOVStreamContext *msc = st->priv_data;
AVIndexEntry *e_old = st->index_entries;
int nb_old = st->nb_index_entries;
const AVIndexEntry *e_old_end = e_old + nb_old;
const AVIndexEntry *current = NULL;
MOVStts *ctts_data_old = msc->ctts_data;
int64_t ctts_index_old = 0;
int64_t ctts_sample_old = 0;
int64_t ctts_count_old = msc->ctts_count;
int64_t edit_list_media_time = 0;
int64_t edit_list_duration = 0;
int64_t frame_duration = 0;
int64_t edit_list_dts_counter = 0;
int64_t edit_list_dts_entry_end = 0;
int64_t edit_list_start_ctts_sample = 0;
int64_t curr_cts;
int64_t edit_list_index = 0;
int64_t index;
int64_t index_ctts_count;
int flags;
unsigned int ctts_allocated_size = 0;
int64_t start_dts = 0;
int64_t edit_list_media_time_dts = 0;
int64_t edit_list_start_encountered = 0;
int64_t search_timestamp = 0;
int64_t* frame_duration_buffer = NULL;
int num_discarded_begin = 0;
int first_non_zero_audio_edit = -1;
int packet_skip_samples = 0;
MOVIndexRange *current_index_range;
if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
return;
}
// allocate the index ranges array
msc->index_ranges = av_malloc((msc->elst_count + 1) * sizeof(msc->index_ranges[0]));
if (!msc->index_ranges) {
av_log(mov->fc, AV_LOG_ERROR, "Cannot allocate index ranges buffer\n");
return;
}
msc->current_index_range = msc->index_ranges;
current_index_range = msc->index_ranges - 1;
// Clean AVStream from traces of old index
st->index_entries = NULL;
st->index_entries_allocated_size = 0;
st->nb_index_entries = 0;
// Clean ctts fields of MOVStreamContext
msc->ctts_data = NULL;
msc->ctts_count = 0;
msc->ctts_index = 0;
msc->ctts_sample = 0;
// If the dts_shift is positive (in case of negative ctts values in mov),
// then negate the DTS by dts_shift
if (msc->dts_shift > 0)
edit_list_dts_entry_end -= msc->dts_shift;
// Offset the DTS by ctts[0] to make the PTS of the first frame 0
if (ctts_data_old && ctts_count_old > 0) {
edit_list_dts_entry_end -= ctts_data_old[0].duration;
av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by ctts[%d].duration: %d\n", 0, ctts_data_old[0].duration);
}
start_dts = edit_list_dts_entry_end;
while (get_edit_list_entry(mov, msc, edit_list_index, &edit_list_media_time,
&edit_list_duration, mov->time_scale)) {
av_log(mov->fc, AV_LOG_DEBUG, "Processing st: %d, edit list %"PRId64" - media time: %"PRId64", duration: %"PRId64"\n",
st->index, edit_list_index, edit_list_media_time, edit_list_duration);
edit_list_index++;
edit_list_dts_counter = edit_list_dts_entry_end;
edit_list_dts_entry_end += edit_list_duration;
num_discarded_begin = 0;
if (edit_list_media_time == -1) {
continue;
}
// If we encounter a non-negative edit list reset the skip_samples/start_pad fields and set them
// according to the edit list below.
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
if (first_non_zero_audio_edit < 0) {
first_non_zero_audio_edit = 1;
} else {
first_non_zero_audio_edit = 0;
}
if (first_non_zero_audio_edit > 0)
st->skip_samples = msc->start_pad = 0;
}
//find closest previous key frame
edit_list_media_time_dts = edit_list_media_time;
if (msc->dts_shift > 0) {
edit_list_media_time_dts -= msc->dts_shift;
}
// While reordering frame index according to edit list we must handle properly
// the scenario when edit list entry starts from none key frame.
// We find closest previous key frame and preserve it and consequent frames in index.
// All frames which are outside edit list entry time boundaries will be dropped after decoding.
search_timestamp = edit_list_media_time_dts;
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
// Audio decoders like AAC need need a decoder delay samples previous to the current sample,
// to correctly decode this frame. Hence for audio we seek to a frame 1 sec. before the
// edit_list_media_time to cover the decoder delay.
search_timestamp = FFMAX(search_timestamp - msc->time_scale, e_old[0].timestamp);
}
index = find_prev_closest_index(st, e_old, nb_old, search_timestamp, 0);
if (index == -1) {
av_log(mov->fc, AV_LOG_WARNING,
"st: %d edit list: %"PRId64" Missing key frame while searching for timestamp: %"PRId64"\n",
st->index, edit_list_index, search_timestamp);
index = find_prev_closest_index(st, e_old, nb_old, search_timestamp, AVSEEK_FLAG_ANY);
if (index == -1) {
av_log(mov->fc, AV_LOG_WARNING,
"st: %d edit list %"PRId64" Cannot find an index entry before timestamp: %"PRId64".\n"
"Rounding edit list media time to zero.\n",
st->index, edit_list_index, search_timestamp);
index = 0;
edit_list_media_time = 0;
}
}
current = e_old + index;
ctts_index_old = 0;
ctts_sample_old = 0;
// set ctts_index properly for the found key frame
for (index_ctts_count = 0; index_ctts_count < index; index_ctts_count++) {
if (ctts_data_old && ctts_index_old < ctts_count_old) {
ctts_sample_old++;
if (ctts_data_old[ctts_index_old].count == ctts_sample_old) {
ctts_index_old++;
ctts_sample_old = 0;
}
}
}
edit_list_start_ctts_sample = ctts_sample_old;
// Iterate over index and arrange it according to edit list
edit_list_start_encountered = 0;
for (; current < e_old_end; current++, index++) {
// check if frame outside edit list mark it for discard
frame_duration = (current + 1 < e_old_end) ?
((current + 1)->timestamp - current->timestamp) : edit_list_duration;
flags = current->flags;
// frames (pts) before or after edit list
curr_cts = current->timestamp + msc->dts_shift;
if (ctts_data_old && ctts_index_old < ctts_count_old) {
av_log(mov->fc, AV_LOG_DEBUG, "shifted frame pts, curr_cts: %"PRId64" @ %"PRId64", ctts: %d, ctts_count: %"PRId64"\n",
curr_cts, ctts_index_old, ctts_data_old[ctts_index_old].duration, ctts_count_old);
curr_cts += ctts_data_old[ctts_index_old].duration;
ctts_sample_old++;
if (ctts_sample_old == ctts_data_old[ctts_index_old].count) {
if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count,
&ctts_allocated_size,
ctts_data_old[ctts_index_old].count - edit_list_start_ctts_sample,
ctts_data_old[ctts_index_old].duration) == -1) {
av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n",
ctts_index_old,
ctts_data_old[ctts_index_old].count - edit_list_start_ctts_sample,
ctts_data_old[ctts_index_old].duration);
break;
}
ctts_index_old++;
ctts_sample_old = 0;
edit_list_start_ctts_sample = 0;
}
}
if (curr_cts < edit_list_media_time || curr_cts >= (edit_list_duration + edit_list_media_time)) {
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id != AV_CODEC_ID_VORBIS &&
curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time &&
first_non_zero_audio_edit > 0) {
packet_skip_samples = edit_list_media_time - curr_cts;
st->skip_samples += packet_skip_samples;
// Shift the index entry timestamp by packet_skip_samples to be correct.
edit_list_dts_counter -= packet_skip_samples;
if (edit_list_start_encountered == 0) {
edit_list_start_encountered = 1;
// Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for
// discarded packets.
if (frame_duration_buffer) {
fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
frame_duration_buffer, num_discarded_begin);
av_freep(&frame_duration_buffer);
}
}
av_log(mov->fc, AV_LOG_DEBUG, "skip %d audio samples from curr_cts: %"PRId64"\n", packet_skip_samples, curr_cts);
} else {
flags |= AVINDEX_DISCARD_FRAME;
av_log(mov->fc, AV_LOG_DEBUG, "drop a frame at curr_cts: %"PRId64" @ %"PRId64"\n", curr_cts, index);
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && edit_list_start_encountered == 0) {
num_discarded_begin++;
frame_duration_buffer = av_realloc(frame_duration_buffer,
num_discarded_begin * sizeof(int64_t));
if (!frame_duration_buffer) {
av_log(mov->fc, AV_LOG_ERROR, "Cannot reallocate frame duration buffer\n");
break;
}
frame_duration_buffer[num_discarded_begin - 1] = frame_duration;
// Increment skip_samples for the first non-zero audio edit list
if (first_non_zero_audio_edit > 0 && st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
st->skip_samples += frame_duration;
msc->start_pad = st->skip_samples;
}
}
}
} else if (edit_list_start_encountered == 0) {
edit_list_start_encountered = 1;
// Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for
// discarded packets.
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && frame_duration_buffer) {
fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
frame_duration_buffer, num_discarded_begin);
av_freep(&frame_duration_buffer);
}
}
if (add_index_entry(st, current->pos, edit_list_dts_counter, current->size,
current->min_distance, flags) == -1) {
av_log(mov->fc, AV_LOG_ERROR, "Cannot add index entry\n");
break;
}
// Update the index ranges array
if (current_index_range < msc->index_ranges || index != current_index_range->end) {
current_index_range++;
current_index_range->start = index;
}
current_index_range->end = index + 1;
// Only start incrementing DTS in frame_duration amounts, when we encounter a frame in edit list.
if (edit_list_start_encountered > 0) {
edit_list_dts_counter = edit_list_dts_counter + frame_duration;
}
// Break when found first key frame after edit entry completion
if (((curr_cts + frame_duration) >= (edit_list_duration + edit_list_media_time)) &&
((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)))) {
if (ctts_data_old && ctts_sample_old != 0) {
if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count,
&ctts_allocated_size,
ctts_sample_old - edit_list_start_ctts_sample,
ctts_data_old[ctts_index_old].duration) == -1) {
av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n",
ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample,
ctts_data_old[ctts_index_old].duration);
break;
}
}
break;
}
}
}
// Update av stream length
st->duration = edit_list_dts_entry_end - start_dts;
// Free the old index and the old CTTS structures
av_free(e_old);
av_free(ctts_data_old);
// Null terminate the index ranges array
current_index_range++;
current_index_range->start = 0;
current_index_range->end = 0;
msc->current_index = msc->index_ranges[0].start;
}
| 9,685 |
qemu | 622b520fb4ca50b5028485f1d225317ece0a42b9 | 0 | int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
{
Location loc;
DriveInfo *dinfo;
int res = 0, unit;
loc_push_none(&loc);
for (unit = 0; unit < MAX_SCSI_DEVS; unit++) {
dinfo = drive_get(IF_SCSI, bus->busnr, unit);
if (dinfo == NULL) {
continue;
}
qemu_opts_loc_restore(dinfo->opts);
if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit)) {
res = -1;
break;
}
}
loc_pop(&loc);
return res;
}
| 9,686 |
qemu | 8ac55351459055f2faee585d9ba2f84707741815 | 0 | static void hda_codec_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
k->realize = hda_codec_dev_realize;
k->exit = hda_codec_dev_exit;
set_bit(DEVICE_CATEGORY_SOUND, k->categories);
k->bus_type = TYPE_HDA_BUS;
k->props = hda_props;
}
| 9,687 |
FFmpeg | 0058584580b87feb47898e60e4b80c7f425882ad | 0 | static inline void downmix_stereo_to_mono(float *samples)
{
int i;
for (i = 0; i < 256; i++) {
samples[i] += samples[i + 256];
samples[i + 256] = 0;
}
}
| 9,690 |
FFmpeg | daa7a1d4431b6acf1f93c4a98b3de123abf4ca18 | 0 | static int thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg, int *ret, int job_count)
{
ThreadContext *c= avctx->thread_opaque;
c->func2 = func2;
return thread_execute(avctx, NULL, arg, ret, job_count, 0);
}
| 9,691 |
FFmpeg | 01e4537f66c6d054f8c7bdbdd5b3cfb4220d12fe | 0 | static void flat_print_section_header(WriterContext *wctx)
{
FlatContext *flat = wctx->priv;
AVBPrint *buf = &flat->section_header[wctx->level];
int i;
/* build section header */
av_bprint_clear(buf);
for (i = 1; i <= wctx->level; i++) {
if (flat->hierarchical ||
!(wctx->section[i]->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER)))
av_bprintf(buf, "%s%s", wctx->section[i]->name, flat->sep_str);
}
}
| 9,692 |
FFmpeg | 269fc8e04906ffd965aa19425ca90980b23c6508 | 0 | static int write_header(AVFormatContext *s)
{
AVCodecContext *codec = s->streams[0]->codec;
if (s->nb_streams > 1) {
av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
return AVERROR(EINVAL);
}
if (codec->codec_id != AV_CODEC_ID_WAVPACK) {
av_log(s, AV_LOG_ERROR, "unsupported codec\n");
return AVERROR(EINVAL);
}
if (codec->extradata_size > 0) {
avpriv_report_missing_feature(s, "remuxing from matroska container");
return AVERROR_PATCHWELCOME;
}
avpriv_set_pts_info(s->streams[0], 64, 1, codec->sample_rate);
return 0;
}
| 9,693 |
FFmpeg | 1dc42050185d63c1de5d16146fbaee92640af187 | 0 | static int default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
{
AVFilterLink *outlink = NULL;
if (inlink->dst->nb_outputs)
outlink = inlink->dst->outputs[0];
if (outlink) {
outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
if (!outlink->out_buf)
return AVERROR(ENOMEM);
avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
}
return 0;
}
| 9,694 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint64_t ivshmem_io_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
IVShmemState *s = opaque;
uint32_t ret;
switch (addr)
{
case INTRMASK:
ret = ivshmem_IntrMask_read(s);
break;
case INTRSTATUS:
ret = ivshmem_IntrStatus_read(s);
break;
case IVPOSITION:
/* return my VM ID if the memory is mapped */
if (s->shm_fd > 0) {
ret = s->vm_id;
} else {
ret = -1;
}
break;
default:
IVSHMEM_DPRINTF("why are we reading " TARGET_FMT_plx "\n", addr);
ret = 0;
}
return ret;
}
| 9,695 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static void omap_os_timer_write(void *opaque, target_phys_addr_t addr,
uint64_t value, unsigned size)
{
struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) opaque;
int offset = addr & OMAP_MPUI_REG_MASK;
if (size != 4) {
return omap_badwidth_write32(opaque, addr, value);
}
switch (offset) {
case 0x00: /* TVR */
s->timer.reset_val = value & 0x00ffffff;
break;
case 0x04: /* TCR */
OMAP_RO_REG(addr);
break;
case 0x08: /* CR */
s->timer.ar = (value >> 3) & 1;
s->timer.it_ena = (value >> 2) & 1;
if (s->timer.st != (value & 1) || (value & 2)) {
omap_timer_sync(&s->timer);
s->timer.enable = value & 1;
s->timer.st = value & 1;
omap_timer_update(&s->timer);
}
break;
default:
OMAP_BAD_REG(addr);
}
}
| 9,696 |
qemu | eabb7b91b36b202b4dac2df2d59d698e3aff197a | 0 | static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond,
TCGArg arg0, TCGArg arg1, TCGArg arg2,
int const_arg2)
{
int crop, sh;
assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32);
/* Ignore high bits of a potential constant arg2. */
if (type == TCG_TYPE_I32) {
arg2 = (uint32_t)arg2;
}
/* Handle common and trivial cases before handling anything else. */
if (arg2 == 0) {
switch (cond) {
case TCG_COND_EQ:
tcg_out_setcond_eq0(s, type, arg0, arg1);
return;
case TCG_COND_NE:
if (TCG_TARGET_REG_BITS == 64 && type == TCG_TYPE_I32) {
tcg_out_ext32u(s, TCG_REG_R0, arg1);
arg1 = TCG_REG_R0;
}
tcg_out_setcond_ne0(s, arg0, arg1);
return;
case TCG_COND_GE:
tcg_out32(s, NOR | SAB(arg1, arg0, arg1));
arg1 = arg0;
/* FALLTHRU */
case TCG_COND_LT:
/* Extract the sign bit. */
if (type == TCG_TYPE_I32) {
tcg_out_shri32(s, arg0, arg1, 31);
} else {
tcg_out_shri64(s, arg0, arg1, 63);
}
return;
default:
break;
}
}
/* If we have ISEL, we can implement everything with 3 or 4 insns.
All other cases below are also at least 3 insns, so speed up the
code generator by not considering them and always using ISEL. */
if (HAVE_ISEL) {
int isel, tab;
tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type);
isel = tcg_to_isel[cond];
tcg_out_movi(s, type, arg0, 1);
if (isel & 1) {
/* arg0 = (bc ? 0 : 1) */
tab = TAB(arg0, 0, arg0);
isel &= ~1;
} else {
/* arg0 = (bc ? 1 : 0) */
tcg_out_movi(s, type, TCG_REG_R0, 0);
tab = TAB(arg0, arg0, TCG_REG_R0);
}
tcg_out32(s, isel | tab);
return;
}
switch (cond) {
case TCG_COND_EQ:
arg1 = tcg_gen_setcond_xor(s, arg1, arg2, const_arg2);
tcg_out_setcond_eq0(s, type, arg0, arg1);
return;
case TCG_COND_NE:
arg1 = tcg_gen_setcond_xor(s, arg1, arg2, const_arg2);
/* Discard the high bits only once, rather than both inputs. */
if (TCG_TARGET_REG_BITS == 64 && type == TCG_TYPE_I32) {
tcg_out_ext32u(s, TCG_REG_R0, arg1);
arg1 = TCG_REG_R0;
}
tcg_out_setcond_ne0(s, arg0, arg1);
return;
case TCG_COND_GT:
case TCG_COND_GTU:
sh = 30;
crop = 0;
goto crtest;
case TCG_COND_LT:
case TCG_COND_LTU:
sh = 29;
crop = 0;
goto crtest;
case TCG_COND_GE:
case TCG_COND_GEU:
sh = 31;
crop = CRNOR | BT(7, CR_EQ) | BA(7, CR_LT) | BB(7, CR_LT);
goto crtest;
case TCG_COND_LE:
case TCG_COND_LEU:
sh = 31;
crop = CRNOR | BT(7, CR_EQ) | BA(7, CR_GT) | BB(7, CR_GT);
crtest:
tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type);
if (crop) {
tcg_out32(s, crop);
}
tcg_out32(s, MFOCRF | RT(TCG_REG_R0) | FXM(7));
tcg_out_rlw(s, RLWINM, arg0, TCG_REG_R0, sh, 31, 31);
break;
default:
tcg_abort();
}
}
| 9,698 |
qemu | 09e68369a88d7de0f988972bf28eec1b80cc47f9 | 0 | static void qmp_input_optional(Visitor *v, const char *name, bool *present)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, false, NULL);
if (!qobj) {
*present = false;
return;
}
*present = true;
}
| 9,702 |
qemu | a89f364ae8740dfc31b321eed9ee454e996dc3c1 | 0 | static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
{
uint32_t cad, nid, data;
HDACodecDevice *codec;
HDACodecDeviceClass *cdc;
cad = (verb >> 28) & 0x0f;
if (verb & (1 << 27)) {
/* indirect node addressing, not specified in HDA 1.0 */
dprint(d, 1, "%s: indirect node addressing (guest bug?)\n", __FUNCTION__);
return -1;
}
nid = (verb >> 20) & 0x7f;
data = verb & 0xfffff;
codec = hda_codec_find(&d->codecs, cad);
if (codec == NULL) {
dprint(d, 1, "%s: addressed non-existing codec\n", __FUNCTION__);
return -1;
}
cdc = HDA_CODEC_DEVICE_GET_CLASS(codec);
cdc->command(codec, nid, data);
return 0;
}
| 9,703 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static void timerblock_write(void *opaque, target_phys_addr_t addr,
uint64_t value, unsigned size)
{
timerblock *tb = (timerblock *)opaque;
int64_t old;
switch (addr) {
case 0: /* Load */
tb->load = value;
/* Fall through. */
case 4: /* Counter. */
if ((tb->control & 1) && tb->count) {
/* Cancel the previous timer. */
qemu_del_timer(tb->timer);
}
tb->count = value;
if (tb->control & 1) {
timerblock_reload(tb, 1);
}
break;
case 8: /* Control. */
old = tb->control;
tb->control = value;
if (((old & 1) == 0) && (value & 1)) {
if (tb->count == 0 && (tb->control & 2)) {
tb->count = tb->load;
}
timerblock_reload(tb, 1);
}
break;
case 12: /* Interrupt status. */
tb->status &= ~value;
timerblock_update_irq(tb);
break;
}
}
| 9,704 |
FFmpeg | 2c7158169859eb2dd49a72337f9f3f28347da77a | 0 | int av_find_best_stream(AVFormatContext *ic,
enum AVMediaType type,
int wanted_stream_nb,
int related_stream,
AVCodec **decoder_ret,
int flags)
{
int i, nb_streams = ic->nb_streams, stream_number = 0;
int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;
unsigned *program = NULL;
AVCodec *decoder = NULL, *best_decoder = NULL;
if (related_stream >= 0 && wanted_stream_nb < 0) {
AVProgram *p = find_program_from_stream(ic, related_stream);
if (p) {
program = p->stream_index;
nb_streams = p->nb_stream_indexes;
}
}
for (i = 0; i < nb_streams; i++) {
AVStream *st = ic->streams[program ? program[i] : i];
AVCodecContext *avctx = st->codec;
if (avctx->codec_type != type)
continue;
if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb)
continue;
if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))
continue;
if (decoder_ret) {
decoder = avcodec_find_decoder(st->codec->codec_id);
if (!decoder) {
if (ret < 0)
ret = AVERROR_DECODER_NOT_FOUND;
continue;
}
}
if (best_count >= st->codec_info_nb_frames)
continue;
best_count = st->codec_info_nb_frames;
ret = program ? program[i] : i;
best_decoder = decoder;
if (program && i == nb_streams - 1 && ret < 0) {
program = NULL;
nb_streams = ic->nb_streams;
i = 0; /* no related stream found, try again with everything */
}
}
if (decoder_ret)
*decoder_ret = best_decoder;
return ret;
}
| 9,705 |
qemu | f5bebbbb28dc7a149a891f0f1e112fb50bb72664 | 0 | BlockDriverState *bdrv_new(const char *device_name, Error **errp)
{
BlockDriverState *bs;
int i;
if (*device_name && !bdrv_is_valid_name(device_name)) {
error_setg(errp, "Invalid device name");
return NULL;
}
if (bdrv_find(device_name)) {
error_setg(errp, "Device with id '%s' already exists",
device_name);
return NULL;
}
if (bdrv_find_node(device_name)) {
error_setg(errp,
"Device name '%s' conflicts with an existing node name",
device_name);
return NULL;
}
bs = g_new0(BlockDriverState, 1);
QLIST_INIT(&bs->dirty_bitmaps);
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
if (device_name[0] != '\0') {
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
}
for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) {
QLIST_INIT(&bs->op_blockers[i]);
}
bdrv_iostatus_disable(bs);
notifier_list_init(&bs->close_notifiers);
notifier_with_return_list_init(&bs->before_write_notifiers);
qemu_co_queue_init(&bs->throttled_reqs[0]);
qemu_co_queue_init(&bs->throttled_reqs[1]);
bs->refcnt = 1;
bs->aio_context = qemu_get_aio_context();
return bs;
}
| 9,708 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.