id
int32 0
27.3k
| func
stringlengths 26
142k
| target
bool 2
classes | project
stringclasses 2
values | commit_id
stringlengths 40
40
|
---|---|---|---|---|
8,232 | static int parse_picture_segment(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
PGSSubContext *ctx = avctx->priv_data;
uint8_t sequence_desc;
unsigned int rle_bitmap_len, width, height;
uint16_t picture_id;
if (buf_size <= 4)
return -1;
buf_size -= 4;
picture_id = bytestream_get_be16(&buf);
/* skip 1 unknown byte: Version Number */
buf++;
/* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */
sequence_desc = bytestream_get_byte(&buf);
if (!(sequence_desc & 0x80)) {
/* Additional RLE data */
if (buf_size > ctx->pictures[picture_id].rle_remaining_len)
return -1;
memcpy(ctx->pictures[picture_id].rle + ctx->pictures[picture_id].rle_data_len, buf, buf_size);
ctx->pictures[picture_id].rle_data_len += buf_size;
ctx->pictures[picture_id].rle_remaining_len -= buf_size;
return 0;
}
if (buf_size <= 7)
return -1;
buf_size -= 7;
/* Decode rle bitmap length, stored size includes width/height data */
rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
/* Get bitmap dimensions from data */
width = bytestream_get_be16(&buf);
height = bytestream_get_be16(&buf);
/* Make sure the bitmap is not too large */
if (avctx->width < width || avctx->height < height) {
av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger than video.\n");
return -1;
}
if (buf_size > rle_bitmap_len) {
av_log(avctx, AV_LOG_ERROR, "too much RLE data\n");
return AVERROR_INVALIDDATA;
}
ctx->pictures[picture_id].w = width;
ctx->pictures[picture_id].h = height;
av_fast_malloc(&ctx->pictures[picture_id].rle, &ctx->pictures[picture_id].rle_buffer_size, rle_bitmap_len);
if (!ctx->pictures[picture_id].rle)
return -1;
memcpy(ctx->pictures[picture_id].rle, buf, buf_size);
ctx->pictures[picture_id].rle_data_len = buf_size;
ctx->pictures[picture_id].rle_remaining_len = rle_bitmap_len - buf_size;
return 0;
}
| true | FFmpeg | 1a01dc83434fbdd1f6604c73afc022795bfb4783 |
8,234 | static void sun4m_fdc_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->props = sun4m_fdc_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
} | true | qemu | e4f4fb1eca795e36f363b4647724221e774523c1 |
8,235 | static int64_t get_pts(const char *buf, int *duration)
{
int i, hour, min, sec, hsec;
int he, me, se, mse;
for (i=0; i<2; i++) {
int64_t start, end;
if (sscanf(buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
&hour, &min, &sec, &hsec, &he, &me, &se, &mse) == 8) {
min += 60*hour;
sec += 60*min;
start = sec*1000+hsec;
me += 60*he;
se += 60*me;
end = se*1000+mse;
*duration = end - start;
return start;
}
buf += strcspn(buf, "\n") + 1;
}
return AV_NOPTS_VALUE;
}
| true | FFmpeg | a96b39de622592cb595bf20ae009ed415b98cde9 |
8,236 | void qemu_savevm_state_begin(QEMUFile *f,
const MigrationParams *params)
{
SaveStateEntry *se;
int ret;
trace_savevm_state_begin();
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
if (!se->ops || !se->ops->set_params) {
continue;
}
se->ops->set_params(params, se->opaque);
}
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
if (!se->ops || !se->ops->save_live_setup) {
continue;
}
if (se->ops && se->ops->is_active) {
if (!se->ops->is_active(se->opaque)) {
continue;
}
}
save_section_header(f, se, QEMU_VM_SECTION_START);
ret = se->ops->save_live_setup(f, se->opaque);
if (ret < 0) {
qemu_file_set_error(f, ret);
break;
}
}
} | true | qemu | f68945d42bab700d95b87f62e0898606ce2421ed |
8,237 | static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
VirtualConsole *vc = chr->opaque;
return vc ? write(vc->fd, buf, len) : len;
}
| true | qemu | d4370741402a97b8b6d0c38fef18ab38bf25ab22 |
8,238 | int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
{
if (!strcasecmp(color_string, "random") || !strcasecmp(color_string, "bikeshed")) {
int rgba = av_get_random_seed();
rgba_color[0] = rgba >> 24;
rgba_color[1] = rgba >> 16;
rgba_color[2] = rgba >> 8;
rgba_color[3] = rgba;
} else
if (!strncmp(color_string, "0x", 2)) {
char *tail;
int len = strlen(color_string);
unsigned int rgba = strtoul(color_string, &tail, 16);
if (*tail || (len != 8 && len != 10)) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string);
return AVERROR(EINVAL);
}
if (len == 10) {
rgba_color[3] = rgba;
rgba >>= 8;
}
rgba_color[0] = rgba >> 16;
rgba_color[1] = rgba >> 8;
rgba_color[2] = rgba;
} else {
const ColorEntry *entry = bsearch(color_string,
color_table,
FF_ARRAY_ELEMS(color_table),
sizeof(ColorEntry),
color_table_compare);
if (!entry) {
av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string);
return AVERROR(EINVAL);
}
memcpy(rgba_color, entry->rgba_color, 4);
}
return 0;
}
| false | FFmpeg | 8e094dd6674e3fd503e1fc2f68883fd3f73a5bd1 |
8,239 | av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
{
MJpegContext *m;
av_assert0(s->slice_context_count == 1);
if (s->width > 65500 || s->height > 65500) {
av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
return AVERROR(EINVAL);
}
m = av_malloc(sizeof(MJpegContext));
if (!m)
return AVERROR(ENOMEM);
s->min_qcoeff=-1023;
s->max_qcoeff= 1023;
// Build default Huffman tables.
// These may be overwritten later with more optimal Huffman tables, but
// they are needed at least right now for some processes like trellis.
ff_mjpeg_build_huffman_codes(m->huff_size_dc_luminance,
m->huff_code_dc_luminance,
avpriv_mjpeg_bits_dc_luminance,
avpriv_mjpeg_val_dc);
ff_mjpeg_build_huffman_codes(m->huff_size_dc_chrominance,
m->huff_code_dc_chrominance,
avpriv_mjpeg_bits_dc_chrominance,
avpriv_mjpeg_val_dc);
ff_mjpeg_build_huffman_codes(m->huff_size_ac_luminance,
m->huff_code_ac_luminance,
avpriv_mjpeg_bits_ac_luminance,
avpriv_mjpeg_val_ac_luminance);
ff_mjpeg_build_huffman_codes(m->huff_size_ac_chrominance,
m->huff_code_ac_chrominance,
avpriv_mjpeg_bits_ac_chrominance,
avpriv_mjpeg_val_ac_chrominance);
ff_init_uni_ac_vlc(m->huff_size_ac_luminance, m->uni_ac_vlc_len);
ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len);
s->intra_ac_vlc_length =
s->intra_ac_vlc_last_length = m->uni_ac_vlc_len;
s->intra_chroma_ac_vlc_length =
s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;
// Buffers start out empty.
m->huff_ncode = 0;
s->mjpeg_ctx = m;
return alloc_huffman(s);
}
| false | FFmpeg | 3e1507a9547ac09b6ff4372123cde09f19218f3d |
8,240 | void fft_calc_altivec(FFTContext *s, FFTComplex *z)
{
POWERPC_TBL_DECLARE(altivec_fft_num, s->nbits >= 6);
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
int ln = s->nbits;
int j, np, np2;
int nblocks, nloops;
register FFTComplex *p, *q;
FFTComplex *exptab = s->exptab;
int l;
FFTSample tmp_re, tmp_im;
POWERPC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
np = 1 << ln;
/* pass 0 */
p=&z[0];
j=(np >> 1);
do {
BF(p[0].re, p[0].im, p[1].re, p[1].im,
p[0].re, p[0].im, p[1].re, p[1].im);
p+=2;
} while (--j != 0);
/* pass 1 */
p=&z[0];
j=np >> 2;
if (s->inverse) {
do {
BF(p[0].re, p[0].im, p[2].re, p[2].im,
p[0].re, p[0].im, p[2].re, p[2].im);
BF(p[1].re, p[1].im, p[3].re, p[3].im,
p[1].re, p[1].im, -p[3].im, p[3].re);
p+=4;
} while (--j != 0);
} else {
do {
BF(p[0].re, p[0].im, p[2].re, p[2].im,
p[0].re, p[0].im, p[2].re, p[2].im);
BF(p[1].re, p[1].im, p[3].re, p[3].im,
p[1].re, p[1].im, p[3].im, -p[3].re);
p+=4;
} while (--j != 0);
}
/* pass 2 .. ln-1 */
nblocks = np >> 3;
nloops = 1 << 2;
np2 = np >> 1;
do {
p = z;
q = z + nloops;
for (j = 0; j < nblocks; ++j) {
BF(p->re, p->im, q->re, q->im,
p->re, p->im, q->re, q->im);
p++;
q++;
for(l = nblocks; l < np2; l += nblocks) {
CMUL(tmp_re, tmp_im, exptab[l].re, exptab[l].im, q->re, q->im);
BF(p->re, p->im, q->re, q->im,
p->re, p->im, tmp_re, tmp_im);
p++;
q++;
}
p += nloops;
q += nloops;
}
nblocks = nblocks >> 1;
nloops = nloops << 1;
} while (nblocks != 0);
POWERPC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
#ifdef CONFIG_DARWIN
register const vector float vczero = (const vector float)(0.);
#else
register const vector float vczero = (const vector float){0.,0.,0.,0.};
#endif
int ln = s->nbits;
int j, np, np2;
int nblocks, nloops;
register FFTComplex *p, *q;
FFTComplex *cptr, *cptr1;
int k;
POWERPC_TBL_START_COUNT(altivec_fft_num, s->nbits >= 6);
np = 1 << ln;
{
vector float *r, a, b, a1, c1, c2;
r = (vector float *)&z[0];
c1 = vcii(p,p,n,n);
if (s->inverse)
{
c2 = vcii(p,p,n,p);
}
else
{
c2 = vcii(p,p,p,n);
}
j = (np >> 2);
do {
a = vec_ld(0, r);
a1 = vec_ld(sizeof(vector float), r);
b = vec_perm(a,a,vcprmle(1,0,3,2));
a = vec_madd(a,c1,b);
/* do the pass 0 butterfly */
b = vec_perm(a1,a1,vcprmle(1,0,3,2));
b = vec_madd(a1,c1,b);
/* do the pass 0 butterfly */
/* multiply third by -i */
b = vec_perm(b,b,vcprmle(2,3,1,0));
/* do the pass 1 butterfly */
vec_st(vec_madd(b,c2,a), 0, r);
vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
r += 2;
} while (--j != 0);
}
/* pass 2 .. ln-1 */
nblocks = np >> 3;
nloops = 1 << 2;
np2 = np >> 1;
cptr1 = s->exptab1;
do {
p = z;
q = z + nloops;
j = nblocks;
do {
cptr = cptr1;
k = nloops >> 1;
do {
vector float a,b,c,t1;
a = vec_ld(0, (float*)p);
b = vec_ld(0, (float*)q);
/* complex mul */
c = vec_ld(0, (float*)cptr);
/* cre*re cim*re */
t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
c = vec_ld(sizeof(vector float), (float*)cptr);
/* -cim*im cre*im */
b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
/* butterfly */
vec_st(vec_add(a,b), 0, (float*)p);
vec_st(vec_sub(a,b), 0, (float*)q);
p += 2;
q += 2;
cptr += 4;
} while (--k);
p += nloops;
q += nloops;
} while (--j);
cptr1 += nloops * 2;
nblocks = nblocks >> 1;
nloops = nloops << 1;
} while (nblocks != 0);
POWERPC_TBL_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
}
| false | FFmpeg | e45a2872fafe631c14aee9f79d0963d68c4fc1fd |
8,242 | Aml *aml_and(Aml *arg1, Aml *arg2)
{
Aml *var = aml_opcode(0x7B /* AndOp */);
aml_append(var, arg1);
aml_append(var, arg2);
build_append_byte(var->buf, 0x00 /* NullNameOp */);
return var;
}
| false | qemu | 439e2a6e10ed7f5da819bf7dcaa54b8cfdbeab0d |
8,243 | static QObject *parser_context_peek_token(JSONParserContext *ctxt)
{
assert(!g_queue_is_empty(ctxt->buf));
return g_queue_peek_head(ctxt->buf);
}
| false | qemu | 9bada8971173345ceb37ed1a47b00a01a4dd48cf |
8,244 | static int nbd_handle_reply_err(QIOChannel *ioc, nbd_opt_reply *reply,
Error **errp)
{
char *msg = NULL;
int result = -1;
if (!(reply->type & (1 << 31))) {
return 1;
}
if (reply->length) {
if (reply->length > NBD_MAX_BUFFER_SIZE) {
error_setg(errp, "server's error message is too long");
goto cleanup;
}
msg = g_malloc(reply->length + 1);
if (read_sync(ioc, msg, reply->length, errp) < 0) {
error_prepend(errp, "failed to read option error message");
goto cleanup;
}
msg[reply->length] = '\0';
}
switch (reply->type) {
case NBD_REP_ERR_UNSUP:
TRACE("server doesn't understand request %" PRIx32
", attempting fallback", reply->option);
result = 0;
goto cleanup;
case NBD_REP_ERR_POLICY:
error_setg(errp, "Denied by server for option %" PRIx32,
reply->option);
break;
case NBD_REP_ERR_INVALID:
error_setg(errp, "Invalid data length for option %" PRIx32,
reply->option);
break;
case NBD_REP_ERR_PLATFORM:
error_setg(errp, "Server lacks support for option %" PRIx32,
reply->option);
break;
case NBD_REP_ERR_TLS_REQD:
error_setg(errp, "TLS negotiation required before option %" PRIx32,
reply->option);
break;
case NBD_REP_ERR_SHUTDOWN:
error_setg(errp, "Server shutting down before option %" PRIx32,
reply->option);
break;
default:
error_setg(errp, "Unknown error code when asking for option %" PRIx32,
reply->option);
break;
}
if (msg) {
error_append_hint(errp, "%s\n", msg);
}
cleanup:
g_free(msg);
if (result < 0) {
nbd_send_opt_abort(ioc);
}
return result;
}
| false | qemu | d1fdf257d52822695f5ace6c586e059aa17d4b79 |
8,245 | static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num)
{
gen_update_cc_op(s);
set_cc_op(s, CC_OP_DYNAMIC);
if (s->jmp_opt) {
gen_goto_tb(s, tb_num, eip);
s->is_jmp = DISAS_TB_JUMP;
} else {
gen_jmp_im(eip);
gen_eob(s);
}
}
| false | qemu | 1e39d97af086d525cd0408eaa5d19783ea165906 |
8,246 | void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
{
uint32_t srs;
srs = env->pregs[PR_SRS];
srs &= 3;
env->sregs[srs][sreg] = env->regs[reg];
#if !defined(CONFIG_USER_ONLY)
if (srs == 1 || srs == 2) {
if (sreg == 6) {
/* Writes to tlb-hi write to mm_cause as a side
effect. */
env->sregs[SFR_RW_MM_TLB_HI] = env->regs[reg];
env->sregs[SFR_R_MM_CAUSE] = env->regs[reg];
}
else if (sreg == 5) {
uint32_t set;
uint32_t idx;
uint32_t lo, hi;
uint32_t vaddr;
int tlb_v;
idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
set >>= 4;
set &= 3;
idx &= 15;
/* We've just made a write to tlb_lo. */
lo = env->sregs[SFR_RW_MM_TLB_LO];
/* Writes are done via r_mm_cause. */
hi = env->sregs[SFR_R_MM_CAUSE];
vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
13, 31);
vaddr <<= TARGET_PAGE_BITS;
tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
3, 3);
env->tlbsets[srs - 1][set][idx].lo = lo;
env->tlbsets[srs - 1][set][idx].hi = hi;
D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
vaddr, tlb_v, env->pc);
tlb_flush_page(env, vaddr);
}
}
#endif
}
| false | qemu | 3e18c6bf7740e4a75503b803ec7d5dc29a531e4f |
8,248 | static inline void gen_intermediate_code_internal(CPUX86State *env,
TranslationBlock *tb,
int search_pc)
{
DisasContext dc1, *dc = &dc1;
target_ulong pc_ptr;
uint16_t *gen_opc_end;
CPUBreakpoint *bp;
int j, lj;
uint64_t flags;
target_ulong pc_start;
target_ulong cs_base;
int num_insns;
int max_insns;
/* generate intermediate code */
pc_start = tb->pc;
cs_base = tb->cs_base;
flags = tb->flags;
dc->pe = (flags >> HF_PE_SHIFT) & 1;
dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
dc->ss32 = (flags >> HF_SS32_SHIFT) & 1;
dc->addseg = (flags >> HF_ADDSEG_SHIFT) & 1;
dc->f_st = 0;
dc->vm86 = (flags >> VM_SHIFT) & 1;
dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
dc->iopl = (flags >> IOPL_SHIFT) & 3;
dc->tf = (flags >> TF_SHIFT) & 1;
dc->singlestep_enabled = env->singlestep_enabled;
dc->cc_op = CC_OP_DYNAMIC;
dc->cs_base = cs_base;
dc->tb = tb;
dc->popl_esp_hack = 0;
/* select memory access functions */
dc->mem_index = 0;
if (flags & HF_SOFTMMU_MASK) {
if (dc->cpl == 3)
dc->mem_index = 2 * 4;
else
dc->mem_index = 1 * 4;
}
dc->cpuid_features = env->cpuid_features;
dc->cpuid_ext_features = env->cpuid_ext_features;
dc->cpuid_ext2_features = env->cpuid_ext2_features;
dc->cpuid_ext3_features = env->cpuid_ext3_features;
#ifdef TARGET_X86_64
dc->lma = (flags >> HF_LMA_SHIFT) & 1;
dc->code64 = (flags >> HF_CS64_SHIFT) & 1;
#endif
dc->flags = flags;
dc->jmp_opt = !(dc->tf || env->singlestep_enabled ||
(flags & HF_INHIBIT_IRQ_MASK)
#ifndef CONFIG_SOFTMMU
|| (flags & HF_SOFTMMU_MASK)
#endif
);
#if 0
/* check addseg logic */
if (!dc->addseg && (dc->vm86 || !dc->pe || !dc->code32))
printf("ERROR addseg\n");
#endif
cpu_T[0] = tcg_temp_new();
cpu_T[1] = tcg_temp_new();
cpu_A0 = tcg_temp_new();
cpu_T3 = tcg_temp_new();
cpu_tmp0 = tcg_temp_new();
cpu_tmp1_i64 = tcg_temp_new_i64();
cpu_tmp2_i32 = tcg_temp_new_i32();
cpu_tmp3_i32 = tcg_temp_new_i32();
cpu_tmp4 = tcg_temp_new();
cpu_tmp5 = tcg_temp_new();
cpu_ptr0 = tcg_temp_new_ptr();
cpu_ptr1 = tcg_temp_new_ptr();
gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
dc->is_jmp = DISAS_NEXT;
pc_ptr = pc_start;
lj = -1;
num_insns = 0;
max_insns = tb->cflags & CF_COUNT_MASK;
if (max_insns == 0)
max_insns = CF_COUNT_MASK;
gen_icount_start();
for(;;) {
if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
if (bp->pc == pc_ptr &&
!((bp->flags & BP_CPU) && (tb->flags & HF_RF_MASK))) {
gen_debug(dc, pc_ptr - dc->cs_base);
break;
}
}
}
if (search_pc) {
j = gen_opc_ptr - gen_opc_buf;
if (lj < j) {
lj++;
while (lj < j)
gen_opc_instr_start[lj++] = 0;
}
gen_opc_pc[lj] = pc_ptr;
gen_opc_cc_op[lj] = dc->cc_op;
gen_opc_instr_start[lj] = 1;
gen_opc_icount[lj] = num_insns;
}
if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
gen_io_start();
pc_ptr = disas_insn(dc, pc_ptr);
num_insns++;
/* stop translation if indicated */
if (dc->is_jmp)
break;
/* if single step mode, we generate only one instruction and
generate an exception */
/* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
the flag and abort the translation to give the irqs a
change to be happen */
if (dc->tf || dc->singlestep_enabled ||
(flags & HF_INHIBIT_IRQ_MASK)) {
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
break;
}
/* if too long translation, stop generation too */
if (gen_opc_ptr >= gen_opc_end ||
(pc_ptr - pc_start) >= (TARGET_PAGE_SIZE - 32) ||
num_insns >= max_insns) {
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
break;
}
if (singlestep) {
gen_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
break;
}
}
if (tb->cflags & CF_LAST_IO)
gen_io_end();
gen_icount_end(tb, num_insns);
*gen_opc_ptr = INDEX_op_end;
/* we don't forget to fill the last values */
if (search_pc) {
j = gen_opc_ptr - gen_opc_buf;
lj++;
while (lj <= j)
gen_opc_instr_start[lj++] = 0;
}
#ifdef DEBUG_DISAS
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
int disas_flags;
qemu_log("----------------\n");
qemu_log("IN: %s\n", lookup_symbol(pc_start));
#ifdef TARGET_X86_64
if (dc->code64)
disas_flags = 2;
else
#endif
disas_flags = !dc->code32;
log_target_disas(pc_start, pc_ptr - pc_start, disas_flags);
qemu_log("\n");
}
#endif
if (!search_pc) {
tb->size = pc_ptr - pc_start;
tb->icount = num_insns;
}
}
| false | qemu | a9321a4d49d65d29c2926a51aedc5b91a01f3591 |
8,251 | static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice *vdev, int nr)
{
VFIOQuirk *quirk;
VFIONvidiaBAR5Quirk *bar5;
VFIOConfigWindowQuirk *window;
if (!vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
!vdev->has_vga || nr != 5) {
return;
}
quirk = g_malloc0(sizeof(*quirk));
quirk->mem = g_new0(MemoryRegion, 4);
quirk->nr_mem = 4;
bar5 = quirk->data = g_malloc0(sizeof(*bar5) +
(sizeof(VFIOConfigWindowMatch) * 2));
window = &bar5->window;
window->vdev = vdev;
window->address_offset = 0x8;
window->data_offset = 0xc;
window->nr_matches = 2;
window->matches[0].match = 0x1800;
window->matches[0].mask = PCI_CONFIG_SPACE_SIZE - 1;
window->matches[1].match = 0x88000;
window->matches[1].mask = PCIE_CONFIG_SPACE_SIZE - 1;
window->bar = nr;
window->addr_mem = bar5->addr_mem = &quirk->mem[0];
window->data_mem = bar5->data_mem = &quirk->mem[1];
memory_region_init_io(window->addr_mem, OBJECT(vdev),
&vfio_generic_window_address_quirk, window,
"vfio-nvidia-bar5-window-address-quirk", 4);
memory_region_add_subregion_overlap(&vdev->bars[nr].region.mem,
window->address_offset,
window->addr_mem, 1);
memory_region_set_enabled(window->addr_mem, false);
memory_region_init_io(window->data_mem, OBJECT(vdev),
&vfio_generic_window_data_quirk, window,
"vfio-nvidia-bar5-window-data-quirk", 4);
memory_region_add_subregion_overlap(&vdev->bars[nr].region.mem,
window->data_offset,
window->data_mem, 1);
memory_region_set_enabled(window->data_mem, false);
memory_region_init_io(&quirk->mem[2], OBJECT(vdev),
&vfio_nvidia_bar5_quirk_master, bar5,
"vfio-nvidia-bar5-master-quirk", 4);
memory_region_add_subregion_overlap(&vdev->bars[nr].region.mem,
0, &quirk->mem[2], 1);
memory_region_init_io(&quirk->mem[3], OBJECT(vdev),
&vfio_nvidia_bar5_quirk_enable, bar5,
"vfio-nvidia-bar5-enable-quirk", 4);
memory_region_add_subregion_overlap(&vdev->bars[nr].region.mem,
4, &quirk->mem[3], 1);
QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next);
trace_vfio_quirk_nvidia_bar5_probe(vdev->vbasedev.name);
}
| false | qemu | f5793fd9e1fd89808f4adbfe690235b094176a37 |
8,252 | static void RENAME(lumRangeToJpeg)(int16_t *dst, int width)
{
int i;
for (i = 0; i < width; i++)
dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14;
}
| false | FFmpeg | d1adad3cca407f493c3637e20ecd4f7124e69212 |
8,253 | Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
{
Coroutine *co;
co = QSLIST_FIRST(&pool);
if (co) {
QSLIST_REMOVE_HEAD(&pool, pool_next);
pool_size--;
} else {
co = qemu_coroutine_new();
}
co->entry = entry;
return co;
}
| false | qemu | b84c4586234b26ccc875595713f6f4491e5b3385 |
8,256 | static size_t write_to_port(VirtIOSerialPort *port,
const uint8_t *buf, size_t size)
{
VirtQueueElement elem;
VirtQueue *vq;
size_t offset = 0;
size_t len = 0;
vq = port->ivq;
if (!virtio_queue_ready(vq)) {
return 0;
}
if (!size) {
return 0;
}
while (offset < size) {
int i;
if (!virtqueue_pop(vq, &elem)) {
break;
}
for (i = 0; offset < size && i < elem.in_num; i++) {
len = MIN(elem.in_sg[i].iov_len, size - offset);
memcpy(elem.in_sg[i].iov_base, buf + offset, len);
offset += len;
}
virtqueue_push(vq, &elem, len);
}
virtio_notify(&port->vser->vdev, vq);
return offset;
}
| false | qemu | e30f328c7429d4e891ce6da26af95c607f392739 |
8,257 | static char *tcg_get_arg_str_idx(TCGContext *s, char *buf, int buf_size,
int idx)
{
TCGTemp *ts;
assert(idx >= 0 && idx < s->nb_temps);
ts = &s->temps[idx];
assert(ts);
if (idx < s->nb_globals) {
pstrcpy(buf, buf_size, ts->name);
} else {
if (ts->temp_local)
snprintf(buf, buf_size, "loc%d", idx - s->nb_globals);
else
snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals);
}
return buf;
}
| false | qemu | 9a8a5ae69d3a436e51a7eb2edafe254572f60823 |
8,258 | static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1);
*spec_info = (ImageInfoSpecific){
.kind = IMAGE_INFO_SPECIFIC_KIND_QCOW2,
{
.qcow2 = g_new(ImageInfoSpecificQCow2, 1),
},
};
if (s->qcow_version == 2) {
*spec_info->qcow2 = (ImageInfoSpecificQCow2){
.compat = g_strdup("0.10"),
.refcount_bits = s->refcount_bits,
};
} else if (s->qcow_version == 3) {
*spec_info->qcow2 = (ImageInfoSpecificQCow2){
.compat = g_strdup("1.1"),
.lazy_refcounts = s->compatible_features &
QCOW2_COMPAT_LAZY_REFCOUNTS,
.has_lazy_refcounts = true,
.corrupt = s->incompatible_features &
QCOW2_INCOMPAT_CORRUPT,
.has_corrupt = true,
.refcount_bits = s->refcount_bits,
};
}
return spec_info;
}
| false | qemu | 6a8f9661dc3c088ed0d2f5b41d940190407cbdc5 |
8,259 | static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
{
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
assert(kvm_enabled());
x86_cpu_def->name = "host";
host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx);
x86_cpu_def->level = eax;
x86_cpu_def->vendor1 = ebx;
x86_cpu_def->vendor2 = edx;
x86_cpu_def->vendor3 = ecx;
host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx);
x86_cpu_def->family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF);
x86_cpu_def->model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12);
x86_cpu_def->stepping = eax & 0x0F;
x86_cpu_def->ext_features = ecx;
x86_cpu_def->features = edx;
if (x86_cpu_def->level >= 7) {
x86_cpu_def->cpuid_7_0_ebx_features = kvm_arch_get_supported_cpuid(kvm_state, 0x7, 0, R_EBX);
} else {
x86_cpu_def->cpuid_7_0_ebx_features = 0;
}
host_cpuid(0x80000000, 0, &eax, &ebx, &ecx, &edx);
x86_cpu_def->xlevel = eax;
host_cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx);
x86_cpu_def->ext2_features = edx;
x86_cpu_def->ext3_features = ecx;
cpu_x86_fill_model_id(x86_cpu_def->model_id);
x86_cpu_def->vendor_override = 0;
/* Call Centaur's CPUID instruction. */
if (x86_cpu_def->vendor1 == CPUID_VENDOR_VIA_1 &&
x86_cpu_def->vendor2 == CPUID_VENDOR_VIA_2 &&
x86_cpu_def->vendor3 == CPUID_VENDOR_VIA_3) {
host_cpuid(0xC0000000, 0, &eax, &ebx, &ecx, &edx);
if (eax >= 0xC0000001) {
/* Support VIA max extended level */
x86_cpu_def->xlevel2 = eax;
host_cpuid(0xC0000001, 0, &eax, &ebx, &ecx, &edx);
x86_cpu_def->ext4_features = edx;
}
}
/*
* Every SVM feature requires emulation support in KVM - so we can't just
* read the host features here. KVM might even support SVM features not
* available on the host hardware. Just set all bits and mask out the
* unsupported ones later.
*/
x86_cpu_def->svm_features = -1;
}
| false | qemu | 12869995ea4f436ab76af5059fd2e9ae83c6cf9d |
8,260 | static uint32_t scsi_init_iovec(SCSIDiskReq *r, size_t size)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
if (!r->iov.iov_base) {
r->buflen = size;
r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen);
}
r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
return r->qiov.size / 512;
}
| false | qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce |
8,261 | static void hax_process_section(MemoryRegionSection *section, uint8_t flags)
{
MemoryRegion *mr = section->mr;
hwaddr start_pa = section->offset_within_address_space;
ram_addr_t size = int128_get64(section->size);
unsigned int delta;
uint64_t host_va;
/* We only care about RAM and ROM regions */
if (!memory_region_is_ram(mr)) {
if (memory_region_is_romd(mr)) {
/* HAXM kernel module does not support ROMD yet */
fprintf(stderr, "%s: Warning: Ignoring ROMD region 0x%016" PRIx64
"->0x%016" PRIx64 "\n", __func__, start_pa,
start_pa + size);
}
return;
}
/* Adjust start_pa and size so that they are page-aligned. (Cf
* kvm_set_phys_mem() in kvm-all.c).
*/
delta = qemu_real_host_page_size - (start_pa & ~qemu_real_host_page_mask);
delta &= ~qemu_real_host_page_mask;
if (delta > size) {
return;
}
start_pa += delta;
size -= delta;
size &= qemu_real_host_page_mask;
if (!size || (start_pa & ~qemu_real_host_page_mask)) {
return;
}
host_va = (uintptr_t)memory_region_get_ram_ptr(mr)
+ section->offset_within_region + delta;
if (memory_region_is_rom(section->mr)) {
flags |= HAX_RAM_INFO_ROM;
}
/* the kernel module interface uses 32-bit sizes (but we could split...) */
g_assert(size <= UINT32_MAX);
hax_update_mapping(start_pa, size, host_va, flags);
}
| false | qemu | 8297be80f7cf71e09617669a8bd8b2836dcfd4c3 |
8,263 | void avcodec_get_context_defaults(AVCodecContext *s){
memset(s, 0, sizeof(AVCodecContext));
s->av_class= &av_codec_context_class;
s->bit_rate= 800*1000;
s->bit_rate_tolerance= s->bit_rate*10;
s->qmin= 2;
s->qmax= 31;
s->mb_qmin= 2;
s->mb_qmax= 31;
s->rc_eq= "tex^qComp";
s->qcompress= 0.5;
s->max_qdiff= 3;
s->b_quant_factor=1.25;
s->b_quant_offset=1.25;
s->i_quant_factor=-0.8;
s->i_quant_offset=0.0;
s->error_concealment= 3;
s->error_resilience= 1;
s->workaround_bugs= FF_BUG_AUTODETECT;
s->frame_rate_base= 1;
s->frame_rate = 25;
s->gop_size= 50;
s->me_method= ME_EPZS;
s->get_buffer= avcodec_default_get_buffer;
s->release_buffer= avcodec_default_release_buffer;
s->get_format= avcodec_default_get_format;
s->execute= avcodec_default_execute;
s->thread_count=1;
s->me_subpel_quality=8;
s->lmin= FF_QP2LAMBDA * s->qmin;
s->lmax= FF_QP2LAMBDA * s->qmax;
s->sample_aspect_ratio= (AVRational){0,1};
s->ildct_cmp= FF_CMP_VSAD;
s->profile= FF_PROFILE_UNKNOWN;
s->level= FF_LEVEL_UNKNOWN;
s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
s->palctrl = NULL;
s->reget_buffer= avcodec_default_reget_buffer;
}
| false | FFmpeg | 6e0d8c06c7af61859e8d7bc2351a607d8abeab75 |
8,264 | static void gen_sraiq(DisasContext *ctx)
{
int sh = SH(ctx->opcode);
int l1 = gen_new_label();
TCGv t0 = tcg_temp_new();
TCGv t1 = tcg_temp_new();
tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
tcg_gen_or_tl(t0, t0, t1);
gen_store_spr(SPR_MQ, t0);
tcg_gen_movi_tl(cpu_ca, 0);
tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
tcg_gen_movi_tl(cpu_ca, 1);
gen_set_label(l1);
tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
tcg_temp_free(t0);
tcg_temp_free(t1);
if (unlikely(Rc(ctx->opcode) != 0))
gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
}
| false | qemu | 42a268c241183877192c376d03bd9b6d527407c7 |
8,265 | static const mon_cmd_t *monitor_parse_command(Monitor *mon,
const char *cmdline,
int start,
mon_cmd_t *table,
QDict *qdict)
{
const char *p, *typestr;
int c;
const mon_cmd_t *cmd;
char cmdname[256];
char buf[1024];
char *key;
/* extract the command name */
p = get_command_name(cmdline + start, cmdname, sizeof(cmdname));
if (!p)
return NULL;
cmd = search_dispatch_table(table, cmdname);
if (!cmd) {
monitor_printf(mon, "unknown command: '%.*s'\n",
(int)(p - cmdline), cmdline);
return NULL;
}
/* filter out following useless space */
while (qemu_isspace(*p)) {
p++;
}
/* search sub command */
if (cmd->sub_table != NULL) {
/* check if user set additional command */
if (*p == '\0') {
return cmd;
}
return monitor_parse_command(mon, cmdline, p - cmdline,
cmd->sub_table, qdict);
}
/* parse the parameters */
typestr = cmd->args_type;
for(;;) {
typestr = key_get_info(typestr, &key);
if (!typestr)
break;
c = *typestr;
typestr++;
switch(c) {
case 'F':
case 'B':
case 's':
{
int ret;
while (qemu_isspace(*p))
p++;
if (*typestr == '?') {
typestr++;
if (*p == '\0') {
/* no optional string: NULL argument */
break;
}
}
ret = get_str(buf, sizeof(buf), &p);
if (ret < 0) {
switch(c) {
case 'F':
monitor_printf(mon, "%s: filename expected\n",
cmdname);
break;
case 'B':
monitor_printf(mon, "%s: block device name expected\n",
cmdname);
break;
default:
monitor_printf(mon, "%s: string expected\n", cmdname);
break;
}
goto fail;
}
qdict_put(qdict, key, qstring_from_str(buf));
}
break;
case 'O':
{
QemuOptsList *opts_list;
QemuOpts *opts;
opts_list = qemu_find_opts(key);
if (!opts_list || opts_list->desc->name) {
goto bad_type;
}
while (qemu_isspace(*p)) {
p++;
}
if (!*p)
break;
if (get_str(buf, sizeof(buf), &p) < 0) {
goto fail;
}
opts = qemu_opts_parse(opts_list, buf, 1);
if (!opts) {
goto fail;
}
qemu_opts_to_qdict(opts, qdict);
qemu_opts_del(opts);
}
break;
case '/':
{
int count, format, size;
while (qemu_isspace(*p))
p++;
if (*p == '/') {
/* format found */
p++;
count = 1;
if (qemu_isdigit(*p)) {
count = 0;
while (qemu_isdigit(*p)) {
count = count * 10 + (*p - '0');
p++;
}
}
size = -1;
format = -1;
for(;;) {
switch(*p) {
case 'o':
case 'd':
case 'u':
case 'x':
case 'i':
case 'c':
format = *p++;
break;
case 'b':
size = 1;
p++;
break;
case 'h':
size = 2;
p++;
break;
case 'w':
size = 4;
p++;
break;
case 'g':
case 'L':
size = 8;
p++;
break;
default:
goto next;
}
}
next:
if (*p != '\0' && !qemu_isspace(*p)) {
monitor_printf(mon, "invalid char in format: '%c'\n",
*p);
goto fail;
}
if (format < 0)
format = default_fmt_format;
if (format != 'i') {
/* for 'i', not specifying a size gives -1 as size */
if (size < 0)
size = default_fmt_size;
default_fmt_size = size;
}
default_fmt_format = format;
} else {
count = 1;
format = default_fmt_format;
if (format != 'i') {
size = default_fmt_size;
} else {
size = -1;
}
}
qdict_put(qdict, "count", qint_from_int(count));
qdict_put(qdict, "format", qint_from_int(format));
qdict_put(qdict, "size", qint_from_int(size));
}
break;
case 'i':
case 'l':
case 'M':
{
int64_t val;
while (qemu_isspace(*p))
p++;
if (*typestr == '?' || *typestr == '.') {
if (*typestr == '?') {
if (*p == '\0') {
typestr++;
break;
}
} else {
if (*p == '.') {
p++;
while (qemu_isspace(*p))
p++;
} else {
typestr++;
break;
}
}
typestr++;
}
if (get_expr(mon, &val, &p))
goto fail;
/* Check if 'i' is greater than 32-bit */
if ((c == 'i') && ((val >> 32) & 0xffffffff)) {
monitor_printf(mon, "\'%s\' has failed: ", cmdname);
monitor_printf(mon, "integer is for 32-bit values\n");
goto fail;
} else if (c == 'M') {
if (val < 0) {
monitor_printf(mon, "enter a positive value\n");
goto fail;
}
val <<= 20;
}
qdict_put(qdict, key, qint_from_int(val));
}
break;
case 'o':
{
int64_t val;
char *end;
while (qemu_isspace(*p)) {
p++;
}
if (*typestr == '?') {
typestr++;
if (*p == '\0') {
break;
}
}
val = strtosz(p, &end);
if (val < 0) {
monitor_printf(mon, "invalid size\n");
goto fail;
}
qdict_put(qdict, key, qint_from_int(val));
p = end;
}
break;
case 'T':
{
double val;
while (qemu_isspace(*p))
p++;
if (*typestr == '?') {
typestr++;
if (*p == '\0') {
break;
}
}
if (get_double(mon, &val, &p) < 0) {
goto fail;
}
if (p[0] && p[1] == 's') {
switch (*p) {
case 'm':
val /= 1e3; p += 2; break;
case 'u':
val /= 1e6; p += 2; break;
case 'n':
val /= 1e9; p += 2; break;
}
}
if (*p && !qemu_isspace(*p)) {
monitor_printf(mon, "Unknown unit suffix\n");
goto fail;
}
qdict_put(qdict, key, qfloat_from_double(val));
}
break;
case 'b':
{
const char *beg;
bool val;
while (qemu_isspace(*p)) {
p++;
}
beg = p;
while (qemu_isgraph(*p)) {
p++;
}
if (p - beg == 2 && !memcmp(beg, "on", p - beg)) {
val = true;
} else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) {
val = false;
} else {
monitor_printf(mon, "Expected 'on' or 'off'\n");
goto fail;
}
qdict_put(qdict, key, qbool_from_bool(val));
}
break;
case '-':
{
const char *tmp = p;
int skip_key = 0;
/* option */
c = *typestr++;
if (c == '\0')
goto bad_type;
while (qemu_isspace(*p))
p++;
if (*p == '-') {
p++;
if(c != *p) {
if(!is_valid_option(p, typestr)) {
monitor_printf(mon, "%s: unsupported option -%c\n",
cmdname, *p);
goto fail;
} else {
skip_key = 1;
}
}
if(skip_key) {
p = tmp;
} else {
/* has option */
p++;
qdict_put(qdict, key, qbool_from_bool(true));
}
}
}
break;
case 'S':
{
/* package all remaining string */
int len;
while (qemu_isspace(*p)) {
p++;
}
if (*typestr == '?') {
typestr++;
if (*p == '\0') {
/* no remaining string: NULL argument */
break;
}
}
len = strlen(p);
if (len <= 0) {
monitor_printf(mon, "%s: string expected\n",
cmdname);
break;
}
qdict_put(qdict, key, qstring_from_str(p));
p += len;
}
break;
default:
bad_type:
monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c);
goto fail;
}
g_free(key);
key = NULL;
}
/* check that all arguments were parsed */
while (qemu_isspace(*p))
p++;
if (*p != '\0') {
monitor_printf(mon, "%s: extraneous characters at the end of line\n",
cmdname);
goto fail;
}
return cmd;
fail:
g_free(key);
return NULL;
}
| false | qemu | ae50212ff717f3d295ebff352eb7d6cc08332b7e |
8,266 | opts_start_struct(Visitor *v, void **obj, const char *kind,
const char *name, size_t size, Error **errp)
{
OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
const QemuOpt *opt;
*obj = g_malloc0(size > 0 ? size : 1);
if (ov->depth++ > 0) {
return;
}
ov->unprocessed_opts = g_hash_table_new_full(&g_str_hash, &g_str_equal,
NULL, &destroy_list);
QTAILQ_FOREACH(opt, &ov->opts_root->head, next) {
/* ensured by qemu-option.c::opts_do_parse() */
assert(strcmp(opt->name, "id") != 0);
opts_visitor_insert(ov->unprocessed_opts, opt);
}
if (ov->opts_root->id != NULL) {
ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
ov->fake_id_opt->name = "id";
ov->fake_id_opt->str = ov->opts_root->id;
opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt);
}
}
| false | qemu | b774539743c52ef605c6e2cbac19376c2757cb86 |
8,267 | static UserDefTwo *nested_struct_create(void)
{
UserDefTwo *udnp = g_malloc0(sizeof(*udnp));
udnp->string0 = strdup("test_string0");
udnp->dict1 = g_malloc0(sizeof(*udnp->dict1));
udnp->dict1->string1 = strdup("test_string1");
udnp->dict1->dict2 = g_malloc0(sizeof(*udnp->dict1->dict2));
udnp->dict1->dict2->userdef = g_new0(UserDefOne, 1);
udnp->dict1->dict2->userdef->base = g_new0(UserDefZero, 1);
udnp->dict1->dict2->userdef->base->integer = 42;
udnp->dict1->dict2->userdef->string = strdup("test_string");
udnp->dict1->dict2->string = strdup("test_string2");
udnp->dict1->dict3 = g_malloc0(sizeof(*udnp->dict1->dict3));
udnp->dict1->has_dict3 = true;
udnp->dict1->dict3->userdef = g_new0(UserDefOne, 1);
udnp->dict1->dict3->userdef->base = g_new0(UserDefZero, 1);
udnp->dict1->dict3->userdef->base->integer = 43;
udnp->dict1->dict3->userdef->string = strdup("test_string");
udnp->dict1->dict3->string = strdup("test_string3");
return udnp;
}
| false | qemu | ddf21908961073199f3d186204da4810f2ea150b |
8,268 | static void gem_write(void *opaque, hwaddr offset, uint64_t val,
unsigned size)
{
GemState *s = (GemState *)opaque;
uint32_t readonly;
DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val);
offset >>= 2;
/* Squash bits which are read only in write value */
val &= ~(s->regs_ro[offset]);
/* Preserve (only) bits which are read only and wtc in register */
readonly = s->regs[offset] & (s->regs_ro[offset] | s->regs_w1c[offset]);
/* Copy register write to backing store */
s->regs[offset] = (val & ~s->regs_w1c[offset]) | readonly;
/* do w1c */
s->regs[offset] &= ~(s->regs_w1c[offset] & val);
/* Handle register write side effects */
switch (offset) {
case GEM_NWCTRL:
if (val & GEM_NWCTRL_RXENA) {
gem_get_rx_desc(s);
}
if (val & GEM_NWCTRL_TXSTART) {
gem_transmit(s);
}
if (!(val & GEM_NWCTRL_TXENA)) {
/* Reset to start of Q when transmit disabled. */
s->tx_desc_addr = s->regs[GEM_TXQBASE];
}
if (val & GEM_NWCTRL_RXENA) {
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}
break;
case GEM_TXSTATUS:
gem_update_int_status(s);
break;
case GEM_RXQBASE:
s->rx_desc_addr = val;
break;
case GEM_TXQBASE:
s->tx_desc_addr = val;
break;
case GEM_RXSTATUS:
gem_update_int_status(s);
break;
case GEM_IER:
s->regs[GEM_IMR] &= ~val;
gem_update_int_status(s);
break;
case GEM_IDR:
s->regs[GEM_IMR] |= val;
gem_update_int_status(s);
break;
case GEM_SPADDR1LO:
case GEM_SPADDR2LO:
case GEM_SPADDR3LO:
case GEM_SPADDR4LO:
s->sar_active[(offset - GEM_SPADDR1LO) / 2] = false;
break;
case GEM_SPADDR1HI:
case GEM_SPADDR2HI:
case GEM_SPADDR3HI:
case GEM_SPADDR4HI:
s->sar_active[(offset - GEM_SPADDR1HI) / 2] = true;
break;
case GEM_PHYMNTNC:
if (val & GEM_PHYMNTNC_OP_W) {
uint32_t phy_addr, reg_num;
phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
if (phy_addr == BOARD_PHY_ADDRESS) {
reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
gem_phy_write(s, reg_num, val);
}
}
break;
}
DB_PRINT("newval: 0x%08x\n", s->regs[offset]);
}
| false | qemu | 8202aa539135a44906c38f82a469234ec65e0ef7 |
8,269 | uint32_t cpu_ppc_load_decr (CPUState *env)
{
ppc_tb_t *tb_env = env->tb_env;
uint32_t decr;
decr = muldiv64(tb_env->decr_next - qemu_get_clock(vm_clock),
tb_env->tb_freq, ticks_per_sec);
#if defined(DEBUG_TB)
printf("%s: 0x%08x\n", __func__, decr);
#endif
return decr;
}
| false | qemu | 4e588a4d0e1683488282658c057d4b44976d77d8 |
8,270 | static int wm8750_event(I2CSlave *i2c, enum i2c_event event)
{
WM8750State *s = WM8750(i2c);
switch (event) {
case I2C_START_SEND:
s->i2c_len = 0;
break;
case I2C_FINISH:
#ifdef VERBOSE
if (s->i2c_len < 2)
printf("%s: message too short (%i bytes)\n",
__FUNCTION__, s->i2c_len);
#endif
break;
default:
break;
}
return 0;
}
| false | qemu | a89f364ae8740dfc31b321eed9ee454e996dc3c1 |
8,272 | static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
AMRWBContext *s = avctx->priv_data;
const int16_t *samples = (const int16_t *)frame->data[0];
int size, ret;
if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE)))
return ret;
if (s->last_bitrate != avctx->bit_rate) {
s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
s->last_bitrate = avctx->bit_rate;
}
size = E_IF_encode(s->state, s->mode, samples, avpkt->data, s->allow_dtx);
if (size <= 0 || size > MAX_PACKET_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Error encoding frame\n");
return AVERROR(EINVAL);
}
if (frame->pts != AV_NOPTS_VALUE)
avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
avpkt->size = size;
*got_packet_ptr = 1;
return 0;
}
| false | FFmpeg | bcaf64b605442e1622d16da89d4ec0e7730b8a8c |
8,275 | static int decode_2(SANMVideoContext *ctx)
{
int cx, cy, ret;
for (cy = 0; cy != ctx->aligned_height; cy += 8) {
for (cx = 0; cx != ctx->aligned_width; cx += 8) {
if (ret = codec2subblock(ctx, cx, cy, 8))
return ret;
}
}
return 0;
}
| false | FFmpeg | 3b9dd906d18f4cd801ceedd20d800a7e53074be9 |
8,277 | static bool cmd_write_pio(IDEState *s, uint8_t cmd)
{
bool lba48 = (cmd == WIN_WRITE_EXT);
if (!s->bs) {
ide_abort_command(s);
return true;
}
ide_cmd_lba48_transform(s, lba48);
s->req_nb_sectors = 1;
s->status = SEEK_STAT | READY_STAT;
ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
s->media_changed = 1;
return false;
}
| false | qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce |
8,278 | static uint64_t cirrus_mmio_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
CirrusVGAState *s = opaque;
if (addr >= 0x100) {
return cirrus_mmio_blt_read(s, addr - 0x100);
} else {
return cirrus_vga_ioport_read(s, addr + 0x3c0);
}
}
| false | qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c |
8,279 | static int ffv1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
FFV1Context *f = avctx->priv_data;
RangeCoder *const c = &f->slice_context[0]->c;
int used_count = 0;
uint8_t keystate = 128;
uint8_t *buf_p;
int i, ret;
f->frame = pict;
if ((ret = ff_alloc_packet(pkt, avctx->width * avctx->height *
((8 * 2 + 1 + 1) * 4) / 8 +
AV_INPUT_BUFFER_MIN_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
ff_init_range_encoder(c, pkt->data, pkt->size);
ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
if (avctx->gop_size == 0 || f->picture_number % avctx->gop_size == 0) {
put_rac(c, &keystate, 1);
f->key_frame = 1;
f->gob_count++;
write_header(f);
} else {
put_rac(c, &keystate, 0);
f->key_frame = 0;
}
if (f->ac > 1) {
int i;
for (i = 1; i < 256; i++) {
c->one_state[i] = f->state_transition[i];
c->zero_state[256 - i] = 256 - c->one_state[i];
}
}
for (i = 1; i < f->slice_count; i++) {
FFV1Context *fs = f->slice_context[i];
uint8_t *start = pkt->data +
(pkt->size - used_count) * (int64_t)i / f->slice_count;
int len = pkt->size / f->slice_count;
ff_init_range_encoder(&fs->c, start, len);
}
avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL,
f->slice_count, sizeof(void *));
buf_p = pkt->data;
for (i = 0; i < f->slice_count; i++) {
FFV1Context *fs = f->slice_context[i];
int bytes;
if (fs->ac) {
uint8_t state = 129;
put_rac(&fs->c, &state, 0);
bytes = ff_rac_terminate(&fs->c);
} else {
flush_put_bits(&fs->pb); // FIXME: nicer padding
bytes = fs->ac_byte_count + (put_bits_count(&fs->pb) + 7) / 8;
}
if (i > 0 || f->version > 2) {
av_assert0(bytes < pkt->size / f->slice_count);
memmove(buf_p, fs->c.bytestream_start, bytes);
av_assert0(bytes < (1 << 24));
AV_WB24(buf_p + bytes, bytes);
bytes += 3;
}
if (f->ec) {
unsigned v;
buf_p[bytes++] = 0;
v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, bytes);
AV_WL32(buf_p + bytes, v);
bytes += 4;
}
buf_p += bytes;
}
if ((avctx->flags & AV_CODEC_FLAG_PASS1) && (f->picture_number & 31) == 0) {
int j, k, m;
char *p = avctx->stats_out;
char *end = p + STATS_OUT_SIZE;
memset(f->rc_stat, 0, sizeof(f->rc_stat));
for (i = 0; i < f->quant_table_count; i++)
memset(f->rc_stat2[i], 0, f->context_count[i] * sizeof(*f->rc_stat2[i]));
for (j = 0; j < f->slice_count; j++) {
FFV1Context *fs = f->slice_context[j];
for (i = 0; i < 256; i++) {
f->rc_stat[i][0] += fs->rc_stat[i][0];
f->rc_stat[i][1] += fs->rc_stat[i][1];
}
for (i = 0; i < f->quant_table_count; i++) {
for (k = 0; k < f->context_count[i]; k++)
for (m = 0; m < 32; m++) {
f->rc_stat2[i][k][m][0] += fs->rc_stat2[i][k][m][0];
f->rc_stat2[i][k][m][1] += fs->rc_stat2[i][k][m][1];
}
}
}
for (j = 0; j < 256; j++) {
snprintf(p, end - p, "%" PRIu64 " %" PRIu64 " ",
f->rc_stat[j][0], f->rc_stat[j][1]);
p += strlen(p);
}
snprintf(p, end - p, "\n");
for (i = 0; i < f->quant_table_count; i++) {
for (j = 0; j < f->context_count[i]; j++)
for (m = 0; m < 32; m++) {
snprintf(p, end - p, "%" PRIu64 " %" PRIu64 " ",
f->rc_stat2[i][j][m][0], f->rc_stat2[i][j][m][1]);
p += strlen(p);
}
}
snprintf(p, end - p, "%d\n", f->gob_count);
} else if (avctx->flags & AV_CODEC_FLAG_PASS1)
avctx->stats_out[0] = '\0';
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->key_frame = f->key_frame;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
f->picture_number++;
pkt->size = buf_p - pkt->data;
pkt->flags |= AV_PKT_FLAG_KEY * f->key_frame;
*got_packet = 1;
return 0;
}
| false | FFmpeg | 4bb1070c154e49d35805fbcdac9c9e92f702ef96 |
8,280 | static void setup_frame(int usig, struct emulated_sigaction *ka,
target_sigset_t *set, CPUState *regs)
{
struct sigframe *frame;
abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame));
int i, err = 0;
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0))
return;
err |= setup_sigcontext(&frame->sc, /*&frame->fpstate,*/ regs, set->sig[0]);
for(i = 1; i < TARGET_NSIG_WORDS; i++) {
if (__put_user(set->sig[i], &frame->extramask[i - 1]))
goto end;
}
if (err == 0)
err = setup_return(regs, ka, &frame->retcode, frame, usig);
end:
unlock_user_struct(frame, frame_addr, 1);
// return err;
}
| false | qemu | f8b0aa25599782eef91edc00ebf620bd14db720c |
8,281 | int qemu_uuid_parse(const char *str, uint8_t *uuid)
{
int ret;
if(strlen(str) != 36)
return -1;
ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
&uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
&uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], &uuid[15]);
if(ret != 16)
return -1;
#ifdef TARGET_I386
smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
#endif
return 0;
}
| false | qemu | ad96090a01d848df67d70c5259ed8aa321fa8716 |
8,282 | QError *qerror_from_info(const char *file, int linenr, const char *func,
const char *fmt, va_list *va)
{
QError *qerr;
qerr = qerror_new();
loc_save(&qerr->loc);
qerr->linenr = linenr;
qerr->file = file;
qerr->func = func;
if (!fmt) {
qerror_abort(qerr, "QDict not specified");
}
qerror_set_data(qerr, fmt, va);
qerror_set_desc(qerr, fmt);
return qerr;
}
| false | qemu | 2a74440547ea0a15195224fa2b7784b267cbfe15 |
8,283 | fork_exec(struct socket *so, const char *ex, int do_pty)
{
int s;
struct sockaddr_in addr;
int addrlen = sizeof(addr);
int opt;
int master = -1;
char *argv[256];
#if 0
char buff[256];
#endif
/* don't want to clobber the original */
char *bptr;
const char *curarg;
int c, i, ret;
DEBUG_CALL("fork_exec");
DEBUG_ARG("so = %lx", (long)so);
DEBUG_ARG("ex = %lx", (long)ex);
DEBUG_ARG("do_pty = %lx", (long)do_pty);
if (do_pty == 2) {
#if 0
if (slirp_openpty(&master, &s) == -1) {
lprint("Error: openpty failed: %s\n", strerror(errno));
return 0;
}
#else
return 0;
#endif
} else {
addr.sin_family = AF_INET;
addr.sin_port = 0;
addr.sin_addr.s_addr = INADDR_ANY;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
listen(s, 1) < 0) {
lprint("Error: inet socket: %s\n", strerror(errno));
closesocket(s);
return 0;
}
}
switch(fork()) {
case -1:
lprint("Error: fork failed: %s\n", strerror(errno));
close(s);
if (do_pty == 2)
close(master);
return 0;
case 0:
/* Set the DISPLAY */
if (do_pty == 2) {
(void) close(master);
#ifdef TIOCSCTTY /* XXXXX */
(void) setsid();
ioctl(s, TIOCSCTTY, (char *)NULL);
#endif
} else {
getsockname(s, (struct sockaddr *)&addr, &addrlen);
close(s);
/*
* Connect to the socket
* XXX If any of these fail, we're in trouble!
*/
s = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_addr = loopback_addr;
do {
ret = connect(s, (struct sockaddr *)&addr, addrlen);
} while (ret < 0 && errno == EINTR);
}
#if 0
if (x_port >= 0) {
#ifdef HAVE_SETENV
sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
setenv("DISPLAY", buff, 1);
#else
sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
putenv(buff);
#endif
}
#endif
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
for (s = getdtablesize() - 1; s >= 3; s--)
close(s);
i = 0;
bptr = strdup(ex); /* No need to free() this */
if (do_pty == 1) {
/* Setup "slirp.telnetd -x" */
argv[i++] = "slirp.telnetd";
argv[i++] = "-x";
argv[i++] = bptr;
} else
do {
/* Change the string into argv[] */
curarg = bptr;
while (*bptr != ' ' && *bptr != (char)0)
bptr++;
c = *bptr;
*bptr++ = (char)0;
argv[i++] = strdup(curarg);
} while (c);
argv[i] = 0;
execvp(argv[0], argv);
/* Ooops, failed, let's tell the user why */
{
char buff[256];
sprintf(buff, "Error: execvp of %s failed: %s\n",
argv[0], strerror(errno));
write(2, buff, strlen(buff)+1);
}
close(0); close(1); close(2); /* XXX */
exit(1);
default:
if (do_pty == 2) {
close(s);
so->s = master;
} else {
/*
* XXX this could block us...
* XXX Should set a timer here, and if accept() doesn't
* return after X seconds, declare it a failure
* The only reason this will block forever is if socket()
* of connect() fail in the child process
*/
do {
so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
} while (so->s < 0 && errno == EINTR);
closesocket(s);
opt = 1;
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
opt = 1;
setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
}
fd_nonblock(so->s);
/* Append the telnet options now */
if (so->so_m != 0 && do_pty == 1) {
sbappend(so, so->so_m);
so->so_m = 0;
}
return 1;
}
}
| false | qemu | 242acf3af4605adce933906bdc053b2414181ec7 |
8,285 | static int bmdma_prepare_buf(IDEDMA *dma, int is_write)
{
BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
IDEState *s = bmdma_active_if(bm);
struct {
uint32_t addr;
uint32_t size;
} prd;
int l, len;
qemu_sglist_init(&s->sg, s->nsector / (BMDMA_PAGE_SIZE / 512) + 1);
s->io_buffer_size = 0;
for(;;) {
if (bm->cur_prd_len == 0) {
/* end of table (with a fail safe of one page) */
if (bm->cur_prd_last ||
(bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE)
return s->io_buffer_size != 0;
cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);
bm->cur_addr += 8;
prd.addr = le32_to_cpu(prd.addr);
prd.size = le32_to_cpu(prd.size);
len = prd.size & 0xfffe;
if (len == 0)
len = 0x10000;
bm->cur_prd_len = len;
bm->cur_prd_addr = prd.addr;
bm->cur_prd_last = (prd.size & 0x80000000);
}
l = bm->cur_prd_len;
if (l > 0) {
qemu_sglist_add(&s->sg, bm->cur_prd_addr, l);
bm->cur_prd_addr += l;
bm->cur_prd_len -= l;
s->io_buffer_size += l;
}
}
return 1;
}
| false | qemu | 552908fef5b67ad9d96b76d7cb8371ebc26c9bc8 |
8,286 | void timer_mod(QEMUTimer *ts, int64_t expire_time)
{
timer_mod_ns(ts, expire_time * ts->scale);
}
| false | qemu | c2b38b277a7882a592f4f2ec955084b2b756daaa |
8,287 | ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
ram_addr_t size, void *host)
{
RAMBlock *new_block, *block;
size = TARGET_PAGE_ALIGN(size);
new_block = qemu_mallocz(sizeof(*new_block));
if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
char *id = dev->parent_bus->info->get_dev_path(dev);
if (id) {
snprintf(new_block->idstr, sizeof(new_block->idstr), "%s/", id);
qemu_free(id);
}
}
pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (!strcmp(block->idstr, new_block->idstr)) {
fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
new_block->idstr);
abort();
}
}
new_block->host = host;
new_block->offset = find_ram_offset(size);
new_block->length = size;
QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,
last_ram_offset() >> TARGET_PAGE_BITS);
memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
0xff, size >> TARGET_PAGE_BITS);
if (kvm_enabled())
kvm_setup_guest_memory(new_block->host, size);
return new_block->offset;
}
| false | qemu | 6977dfe6af975d72a8140dbc91effe8b8f2a58f8 |
8,288 | static bool qemu_opt_get_bool_helper(QemuOpts *opts, const char *name,
bool defval, bool del)
{
QemuOpt *opt = qemu_opt_find(opts, name);
bool ret = defval;
if (opt == NULL) {
const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
if (desc && desc->def_value_str) {
parse_option_bool(name, desc->def_value_str, &ret, &error_abort);
}
return ret;
}
assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
ret = opt->value.boolean;
if (del) {
qemu_opt_del_all(opts, name);
}
return ret;
}
| false | qemu | 435db4cf29b88b6612e30acda01cd18788dff458 |
8,289 | static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
int label_index, intptr_t addend)
{
TCGLabel *l;
TCGRelocation *r;
l = &s->labels[label_index];
if (l->has_value) {
/* FIXME: This may break relocations on RISC targets that
modify instruction fields in place. The caller may not have
written the initial value. */
patch_reloc(code_ptr, type, l->u.value, addend);
} else {
/* add a new relocation entry */
r = tcg_malloc(sizeof(TCGRelocation));
r->type = type;
r->ptr = code_ptr;
r->addend = addend;
r->next = l->u.first_reloc;
l->u.first_reloc = r;
}
}
| false | qemu | bec1631100323fac0900aea71043d5c4e22fc2fa |
8,290 | static int mov_write_packet(AVFormatContext *s, int stream_index,
const uint8_t *buf, int size, int64_t pts)
{
MOVContext *mov = s->priv_data;
ByteIOContext *pb = &s->pb;
AVCodecContext *enc = &s->streams[stream_index]->codec;
MOVTrack* trk = &mov->tracks[stream_index];
int cl, id;
unsigned int samplesInChunk = 0;
if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
if (enc->codec_type == CODEC_TYPE_VIDEO ) {
samplesInChunk = 1;
}
else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
if( enc->codec_id == CODEC_ID_AMR_NB) {
/* We must find out how many AMR blocks there are in one packet */
static uint16_t packed_size[16] =
{13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
int len = 0;
while (len < size && samplesInChunk < 100) {
len += packed_size[(buf[len] >> 3) & 0x0F];
samplesInChunk++;
}
}
else if(enc->codec_id == CODEC_ID_PCM_ALAW) {
samplesInChunk = size/enc->channels;
}
else {
samplesInChunk = 1;
}
}
if ((enc->codec_id == CODEC_ID_MPEG4 || enc->codec_id == CODEC_ID_AAC)
&& trk->vosLen == 0) {
assert(enc->extradata_size);
trk->vosLen = enc->extradata_size;
trk->vosData = av_malloc(trk->vosLen);
memcpy(trk->vosData, enc->extradata, trk->vosLen);
}
cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
if (trk->ents_allocated <= trk->entry) {
trk->cluster = av_realloc(trk->cluster, (cl+1)*sizeof(void*));
if (!trk->cluster)
return -1;
trk->cluster[cl] = av_malloc(MOV_INDEX_CLUSTER_SIZE*sizeof(MOVIentry));
if (!trk->cluster[cl])
return -1;
trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
}
if (mov->mdat_written == 0) {
mov_write_mdat_tag(pb, mov);
mov->mdat_written = 1;
mov->time = Timestamp();
}
trk->cluster[cl][id].pos = url_ftell(pb) - mov->movi_list;
trk->cluster[cl][id].samplesInChunk = samplesInChunk;
trk->cluster[cl][id].size = size;
trk->cluster[cl][id].entries = samplesInChunk;
if(enc->codec_type == CODEC_TYPE_VIDEO) {
trk->cluster[cl][id].key_frame = enc->coded_frame->key_frame;
if(enc->coded_frame->pict_type == FF_I_TYPE)
trk->hasKeyframes = 1;
}
trk->enc = enc;
trk->entry++;
trk->sampleCount += samplesInChunk;
trk->mdat_size += size;
put_buffer(pb, buf, size);
put_flush_packet(pb);
return 0;
}
| false | FFmpeg | 69dde1ad36b7d95b8b9268f414aa6c076212ed41 |
8,292 | static uint32_t nvdimm_get_max_xfer_label_size(void)
{
uint32_t max_get_size, max_set_size, dsm_memory_size = 4096;
/*
* the max data ACPI can read one time which is transferred by
* the response of 'Get Namespace Label Data' function.
*/
max_get_size = dsm_memory_size - sizeof(NvdimmFuncGetLabelDataOut);
/*
* the max data ACPI can write one time which is transferred by
* 'Set Namespace Label Data' function.
*/
max_set_size = dsm_memory_size - offsetof(NvdimmDsmIn, arg3) -
sizeof(NvdimmFuncSetLabelDataIn);
return MIN(max_get_size, max_set_size);
}
| false | qemu | cb88ebd7542458c22f3051646f268dcea6109abc |
8,293 | static void imx_fec_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
{
IMXFECState *s = IMX_FEC(opaque);
FEC_PRINTF("writing 0x%08x @ 0x%" HWADDR_PRIx "\n", (int)value, addr);
switch (addr & 0x3ff) {
case 0x004: /* EIR */
s->eir &= ~value;
break;
case 0x008: /* EIMR */
s->eimr = value;
break;
case 0x010: /* RDAR */
if ((s->ecr & FEC_EN) && !s->rx_enabled) {
imx_fec_enable_rx(s);
}
break;
case 0x014: /* TDAR */
if (s->ecr & FEC_EN) {
imx_fec_do_tx(s);
}
break;
case 0x024: /* ECR */
s->ecr = value;
if (value & FEC_RESET) {
imx_fec_reset(DEVICE(s));
}
if ((s->ecr & FEC_EN) == 0) {
s->rx_enabled = 0;
}
break;
case 0x040: /* MMFR */
/* store the value */
s->mmfr = value;
if (extract32(value, 28, 1)) {
do_phy_write(s, extract32(value, 18, 9), extract32(value, 0, 16));
} else {
s->mmfr = do_phy_read(s, extract32(value, 18, 9));
}
/* raise the interrupt as the PHY operation is done */
s->eir |= FEC_INT_MII;
break;
case 0x044: /* MSCR */
s->mscr = value & 0xfe;
break;
case 0x064: /* MIBC */
/* TODO: Implement MIB. */
s->mibc = (value & 0x80000000) ? 0xc0000000 : 0;
break;
case 0x084: /* RCR */
s->rcr = value & 0x07ff003f;
/* TODO: Implement LOOP mode. */
break;
case 0x0c4: /* TCR */
/* We transmit immediately, so raise GRA immediately. */
s->tcr = value;
if (value & 1) {
s->eir |= FEC_INT_GRA;
}
break;
case 0x0e4: /* PALR */
s->conf.macaddr.a[0] = value >> 24;
s->conf.macaddr.a[1] = value >> 16;
s->conf.macaddr.a[2] = value >> 8;
s->conf.macaddr.a[3] = value;
break;
case 0x0e8: /* PAUR */
s->conf.macaddr.a[4] = value >> 24;
s->conf.macaddr.a[5] = value >> 16;
break;
case 0x0ec: /* OPDR */
break;
case 0x118: /* IAUR */
case 0x11c: /* IALR */
case 0x120: /* GAUR */
case 0x124: /* GALR */
/* TODO: implement MAC hash filtering. */
break;
case 0x144: /* TFWR */
s->tfwr = value & 3;
break;
case 0x14c: /* FRBR */
/* FRBR writes ignored. */
break;
case 0x150: /* FRSR */
s->frsr = (value & 0x3fc) | 0x400;
break;
case 0x180: /* ERDSR */
s->erdsr = value & ~3;
s->rx_descriptor = s->erdsr;
break;
case 0x184: /* ETDSR */
s->etdsr = value & ~3;
s->tx_descriptor = s->etdsr;
break;
case 0x188: /* EMRBR */
s->emrbr = value & 0x7f0;
break;
case 0x300: /* MIIGSK_CFGR */
s->miigsk_cfgr = value & 0x53;
break;
case 0x308: /* MIIGSK_ENR */
s->miigsk_enr = (value & 0x2) ? 0x6 : 0;
break;
default:
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad address at offset 0x%"
HWADDR_PRIx "\n", TYPE_IMX_FEC, __func__, addr);
break;
}
imx_fec_update(s);
}
| false | qemu | 4816dc168b5745708eba4c005f5e8771623ee405 |
8,294 | static void replay_enable(const char *fname, int mode)
{
const char *fmode = NULL;
assert(!replay_file);
switch (mode) {
case REPLAY_MODE_RECORD:
fmode = "wb";
break;
case REPLAY_MODE_PLAY:
fmode = "rb";
break;
default:
fprintf(stderr, "Replay: internal error: invalid replay mode\n");
exit(1);
}
atexit(replay_finish);
replay_mutex_init();
replay_file = fopen(fname, fmode);
if (replay_file == NULL) {
fprintf(stderr, "Replay: open %s: %s\n", fname, strerror(errno));
exit(1);
}
replay_filename = g_strdup(fname);
replay_mode = mode;
replay_data_kind = -1;
replay_state.instructions_count = 0;
replay_state.current_step = 0;
/* skip file header for RECORD and check it for PLAY */
if (replay_mode == REPLAY_MODE_RECORD) {
fseek(replay_file, HEADER_SIZE, SEEK_SET);
} else if (replay_mode == REPLAY_MODE_PLAY) {
unsigned int version = replay_get_dword();
if (version != REPLAY_VERSION) {
fprintf(stderr, "Replay: invalid input log file version\n");
exit(1);
}
/* go to the beginning */
fseek(replay_file, HEADER_SIZE, SEEK_SET);
replay_fetch_data_kind();
}
replay_init_events();
}
| false | qemu | f186d64d8fda4bb22c15beb8e45b7814fbd8b51e |
8,295 | static bool raw_is_inserted(BlockDriverState *bs)
{
return bdrv_is_inserted(bs->file->bs);
}
| false | qemu | 1354c473789a91ba603d40bdf2521e3221c0a69f |
8,298 | static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
{
int ret;
DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
stage, block_mig_state.submitted, block_mig_state.transferred);
if (stage < 0) {
blk_mig_cleanup(mon);
return 0;
}
if (block_mig_state.blk_enable != 1) {
/* no need to migrate storage */
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
return 1;
}
if (stage == 1) {
init_blk_migration(mon, f);
/* start track dirty blocks */
set_dirty_tracking(1);
}
flush_blks(f);
ret = qemu_file_get_error(f);
if (ret) {
blk_mig_cleanup(mon);
return ret;
}
blk_mig_reset_dirty_cursor();
if (stage == 2) {
/* control the rate of transfer */
while ((block_mig_state.submitted +
block_mig_state.read_done) * BLOCK_SIZE <
qemu_file_get_rate_limit(f)) {
if (block_mig_state.bulk_completed == 0) {
/* first finish the bulk phase */
if (blk_mig_save_bulked_block(mon, f) == 0) {
/* finished saving bulk on all devices */
block_mig_state.bulk_completed = 1;
}
} else {
if (blk_mig_save_dirty_block(mon, f, 1) == 0) {
/* no more dirty blocks */
break;
}
}
}
flush_blks(f);
ret = qemu_file_get_error(f);
if (ret) {
blk_mig_cleanup(mon);
return ret;
}
}
if (stage == 3) {
/* we know for sure that save bulk is completed and
all async read completed */
assert(block_mig_state.submitted == 0);
while (blk_mig_save_dirty_block(mon, f, 0) != 0);
blk_mig_cleanup(mon);
/* report completion */
qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);
ret = qemu_file_get_error(f);
if (ret) {
return ret;
}
monitor_printf(mon, "Block migration completed\n");
}
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
return ((stage == 2) && is_stage2_completed());
}
| false | qemu | 539de1246d355d3b8aa33fb7cde732352d8827c7 |
8,299 | int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
{
char line[1024], group[64], id[64], arg[64], value[1024];
Location loc;
QemuOptsList *list = NULL;
Error *local_err = NULL;
QemuOpts *opts = NULL;
int res = -1, lno = 0;
loc_push_none(&loc);
while (fgets(line, sizeof(line), fp) != NULL) {
loc_set_file(fname, ++lno);
if (line[0] == '\n') {
/* skip empty lines */
continue;
}
if (line[0] == '#') {
/* comment */
continue;
}
if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
/* group with id */
list = find_list(lists, group, &local_err);
if (local_err) {
error_report_err(local_err);
goto out;
}
opts = qemu_opts_create(list, id, 1, NULL);
continue;
}
if (sscanf(line, "[%63[^]]]", group) == 1) {
/* group without id */
list = find_list(lists, group, &local_err);
if (local_err) {
error_report_err(local_err);
goto out;
}
opts = qemu_opts_create(list, NULL, 0, &error_abort);
continue;
}
value[0] = '\0';
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2 ||
sscanf(line, " %63s = \"\"", arg) == 1) {
/* arg = value */
if (opts == NULL) {
error_report("no group defined");
goto out;
}
qemu_opt_set(opts, arg, value, &local_err);
if (local_err) {
error_report_err(local_err);
goto out;
}
continue;
}
error_report("parse error");
goto out;
}
if (ferror(fp)) {
error_report("error reading file");
goto out;
}
res = 0;
out:
loc_pop(&loc);
return res;
}
| false | qemu | e5766d6ec7524345f4c0fa284c065b68c5e93049 |
8,300 | static void qmp_input_check_struct(Visitor *v, Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
StackObject *tos = &qiv->stack[qiv->nb_stack - 1];
assert(qiv->nb_stack > 0);
if (qiv->strict) {
GHashTable *const top_ht = tos->h;
if (top_ht) {
GHashTableIter iter;
const char *key;
g_hash_table_iter_init(&iter, top_ht);
if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) {
error_setg(errp, QERR_QMP_EXTRA_MEMBER, key);
}
}
}
}
| false | qemu | 3d344c2aabb7bc9b414321e3c52872901edebdda |
8,301 | int ff_get_line(AVIOContext *s, char *buf, int maxlen)
{
int i = 0;
char c;
do {
c = avio_r8(s);
if (c && i < maxlen-1)
buf[i++] = c;
} while (c != '\n' && c != '\r' && c);
if (c == '\r' && avio_r8(s) != '\n')
avio_skip(s, -1);
buf[i] = 0;
return i;
}
| false | FFmpeg | eac5c7b8377f3f0e8262ab44e5ccb2c7ed060cdd |
8,302 | e1000e_intrmgr_delay_tx_causes(E1000ECore *core, uint32_t *causes)
{
static const uint32_t delayable_causes = E1000_ICR_TXQ0 |
E1000_ICR_TXQ1 |
E1000_ICR_TXQE |
E1000_ICR_TXDW;
if (msix_enabled(core->owner)) {
return false;
}
/* Clean up all causes that may be delayed */
core->delayed_causes |= *causes & delayable_causes;
*causes &= ~delayable_causes;
/* If there are causes that cannot be delayed */
if (causes != 0) {
return false;
}
/* All causes delayed */
e1000e_intrmgr_rearm_timer(&core->tidv);
if (!core->tadv.running && (core->mac[TADV] != 0)) {
e1000e_intrmgr_rearm_timer(&core->tadv);
}
return true;
}
| false | qemu | 1ac6c07f4288b0a563310fad0cdabb3a47c85607 |
8,303 | static int qcow2_make_empty(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
uint64_t start_sector;
int sector_step = INT_MAX / BDRV_SECTOR_SIZE;
int l1_clusters, ret = 0;
l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
if (s->qcow_version >= 3 && !s->snapshots &&
3 + l1_clusters <= s->refcount_block_size) {
/* The following function only works for qcow2 v3 images (it requires
* the dirty flag) and only as long as there are no snapshots (because
* it completely empties the image). Furthermore, the L1 table and three
* additional clusters (image header, refcount table, one refcount
* block) have to fit inside one refcount block. */
return make_completely_empty(bs);
}
/* This fallback code simply discards every active cluster; this is slow,
* but works in all cases */
for (start_sector = 0; start_sector < bs->total_sectors;
start_sector += sector_step)
{
/* As this function is generally used after committing an external
* snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
* default action for this kind of discard is to pass the discard,
* which will ideally result in an actually smaller image file, as
* is probably desired. */
ret = qcow2_discard_clusters(bs, start_sector * BDRV_SECTOR_SIZE,
MIN(sector_step,
bs->total_sectors - start_sector),
QCOW2_DISCARD_SNAPSHOT, true);
if (ret < 0) {
break;
}
}
return ret;
}
| false | qemu | a3e1505daec31ef56f0489f8c8fff1b8e4ca92bd |
8,304 | static void s390_cpu_full_reset(CPUState *s)
{
S390CPU *cpu = S390_CPU(s);
S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
CPUS390XState *env = &cpu->env;
int i;
scc->parent_reset(s);
cpu->env.sigp_order = 0;
s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
memset(env, 0, offsetof(CPUS390XState, end_reset_fields));
/* architectured initial values for CR 0 and 14 */
env->cregs[0] = CR0_RESET;
env->cregs[14] = CR14_RESET;
/* architectured initial value for Breaking-Event-Address register */
env->gbea = 1;
env->pfault_token = -1UL;
env->ext_index = -1;
for (i = 0; i < ARRAY_SIZE(env->io_index); i++) {
env->io_index[i] = -1;
}
env->mchk_index = -1;
/* tininess for underflow is detected before rounding */
set_float_detect_tininess(float_tininess_before_rounding,
&env->fpu_status);
/* Reset state inside the kernel that we cannot access yet from QEMU. */
if (kvm_enabled()) {
kvm_s390_reset_vcpu(cpu);
}
}
| false | qemu | d516f74c99b1a2c289cfba0bacf125cbc9b681e3 |
8,305 | static bool ufd_version_check(int ufd)
{
struct uffdio_api api_struct;
uint64_t ioctl_mask;
api_struct.api = UFFD_API;
api_struct.features = 0;
if (ioctl(ufd, UFFDIO_API, &api_struct)) {
error_report("postcopy_ram_supported_by_host: UFFDIO_API failed: %s",
strerror(errno));
return false;
}
ioctl_mask = (__u64)1 << _UFFDIO_REGISTER |
(__u64)1 << _UFFDIO_UNREGISTER;
if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
error_report("Missing userfault features: %" PRIx64,
(uint64_t)(~api_struct.ioctls & ioctl_mask));
return false;
}
if (getpagesize() != ram_pagesize_summary()) {
bool have_hp = false;
/* We've got a huge page */
#ifdef UFFD_FEATURE_MISSING_HUGETLBFS
have_hp = api_struct.features & UFFD_FEATURE_MISSING_HUGETLBFS;
#endif
if (!have_hp) {
error_report("Userfault on this host does not support huge pages");
return false;
}
}
return true;
}
| false | qemu | d7651f150d61936344c4fab45eaeb0716c606af2 |
8,306 | static void string_output_append(StringOutputVisitor *sov, int64_t a)
{
Range *r = g_malloc0(sizeof(*r));
r->begin = a;
r->end = a + 1;
sov->ranges = range_list_insert(sov->ranges, r);
}
| false | qemu | a0efbf16604770b9d805bcf210ec29942321134f |
8,307 | static void aarch64_cpu_register(const ARMCPUInfo *info)
{
TypeInfo type_info = {
.parent = TYPE_AARCH64_CPU,
.instance_size = sizeof(ARMCPU),
.instance_init = info->initfn,
.class_size = sizeof(ARMCPUClass),
.class_init = info->class_init,
};
/* TODO: drop when we support more CPUs - all entries will have name set */
if (!info->name) {
return;
}
type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
type_register(&type_info);
g_free((void *)type_info.name);
}
| false | qemu | 83e6813a93e38976391b8c382c3375e3e188df3e |
8,308 | static void tx_fifo_push(lan9118_state *s, uint32_t val)
{
int n;
if (s->txp->fifo_used == s->tx_fifo_size) {
s->int_sts |= TDFO_INT;
return;
}
switch (s->txp->state) {
case TX_IDLE:
s->txp->cmd_a = val & 0x831f37ff;
s->txp->fifo_used++;
s->txp->state = TX_B;
s->txp->buffer_size = extract32(s->txp->cmd_a, 0, 11);
s->txp->offset = extract32(s->txp->cmd_a, 16, 5);
break;
case TX_B:
if (s->txp->cmd_a & 0x2000) {
/* First segment */
s->txp->cmd_b = val;
s->txp->fifo_used++;
/* End alignment does not include command words. */
n = (s->txp->buffer_size + s->txp->offset + 3) >> 2;
switch ((n >> 24) & 3) {
case 1:
n = (-n) & 3;
break;
case 2:
n = (-n) & 7;
break;
default:
n = 0;
}
s->txp->pad = n;
s->txp->len = 0;
}
DPRINTF("Block len:%d offset:%d pad:%d cmd %08x\n",
s->txp->buffer_size, s->txp->offset, s->txp->pad,
s->txp->cmd_a);
s->txp->state = TX_DATA;
break;
case TX_DATA:
if (s->txp->offset >= 4) {
s->txp->offset -= 4;
break;
}
if (s->txp->buffer_size <= 0 && s->txp->pad != 0) {
s->txp->pad--;
} else {
n = 4;
while (s->txp->offset) {
val >>= 8;
n--;
s->txp->offset--;
}
/* Documentation is somewhat unclear on the ordering of bytes
in FIFO words. Empirical results show it to be little-endian.
*/
/* TODO: FIFO overflow checking. */
while (n--) {
s->txp->data[s->txp->len] = val & 0xff;
s->txp->len++;
val >>= 8;
s->txp->buffer_size--;
}
s->txp->fifo_used++;
}
if (s->txp->buffer_size <= 0 && s->txp->pad == 0) {
if (s->txp->cmd_a & 0x1000) {
do_tx_packet(s);
}
if (s->txp->cmd_a & 0x80000000) {
s->int_sts |= TX_IOC_INT;
}
s->txp->state = TX_IDLE;
}
break;
}
}
| false | qemu | c444dfabfc21cb5f093862100e333b808eea32e4 |
8,309 | int ff_h264_decode_ref_pic_list_reordering(H264Context *h)
{
int list, index, pic_structure, i;
print_short_term(h);
print_long_term(h);
for (list = 0; list < h->list_count; list++) {
for (i = 0; i < h->ref_count[list]; i++)
COPY_PICTURE(&h->ref_list[list][i], &h->default_ref_list[list][i]);
if (get_bits1(&h->gb)) {
int pred = h->curr_pic_num;
for (index = 0; ; index++) {
unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(&h->gb);
unsigned int pic_id;
int i;
Picture *ref = NULL;
if (reordering_of_pic_nums_idc == 3)
break;
if (index >= h->ref_count[list]) {
av_log(h->avctx, AV_LOG_ERROR, "reference count overflow\n");
return -1;
}
if (reordering_of_pic_nums_idc < 3) {
if (reordering_of_pic_nums_idc < 2) {
const unsigned int abs_diff_pic_num = get_ue_golomb(&h->gb) + 1;
int frame_num;
if (abs_diff_pic_num > h->max_pic_num) {
av_log(h->avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n");
return -1;
}
if (reordering_of_pic_nums_idc == 0)
pred -= abs_diff_pic_num;
else
pred += abs_diff_pic_num;
pred &= h->max_pic_num - 1;
frame_num = pic_num_extract(h, pred, &pic_structure);
for (i = h->short_ref_count - 1; i >= 0; i--) {
ref = h->short_ref[i];
assert(ref->reference);
assert(!ref->long_ref);
if (ref->frame_num == frame_num &&
(ref->reference & pic_structure))
break;
}
if (i >= 0)
ref->pic_id = pred;
} else {
int long_idx;
pic_id = get_ue_golomb(&h->gb); //long_term_pic_idx
long_idx = pic_num_extract(h, pic_id, &pic_structure);
if (long_idx > 31) {
av_log(h->avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n");
return -1;
}
ref = h->long_ref[long_idx];
assert(!(ref && !ref->reference));
if (ref && (ref->reference & pic_structure)) {
ref->pic_id = pic_id;
assert(ref->long_ref);
i = 0;
} else {
i = -1;
}
}
if (i < 0) {
av_log(h->avctx, AV_LOG_ERROR, "reference picture missing during reorder\n");
memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME
} else {
for (i = index; i + 1 < h->ref_count[list]; i++) {
if (ref->long_ref == h->ref_list[list][i].long_ref &&
ref->pic_id == h->ref_list[list][i].pic_id)
break;
}
for (; i > index; i--) {
COPY_PICTURE(&h->ref_list[list][i], &h->ref_list[list][i - 1]);
}
COPY_PICTURE(&h->ref_list[list][index], ref);
if (FIELD_PICTURE(h)) {
pic_as_field(&h->ref_list[list][index], pic_structure);
}
}
} else {
av_log(h->avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");
return -1;
}
}
}
}
for (list = 0; list < h->list_count; list++) {
for (index = 0; index < h->ref_count[list]; index++) {
if (!h->ref_list[list][index].f.data[0]) {
av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\n");
if (h->default_ref_list[list][0].f.data[0])
COPY_PICTURE(&h->ref_list[list][index], &h->default_ref_list[list][0]);
else
return -1;
}
}
}
return 0;
}
| false | FFmpeg | a553c6a347d3d28d7ee44c3df3d5c4ee780dba23 |
8,310 | static enum AVHWDeviceType hw_device_match_type_by_hwaccel(enum HWAccelID hwaccel_id)
{
int i;
if (hwaccel_id == HWACCEL_NONE)
return AV_HWDEVICE_TYPE_NONE;
for (i = 0; hwaccels[i].name; i++) {
if (hwaccels[i].id == hwaccel_id)
return hwaccels[i].device_type;
}
return AV_HWDEVICE_TYPE_NONE;
}
| false | FFmpeg | b0cd14fb1dab4b044f7fe6b53ac635409849de77 |
8,312 | int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count,
const uint8_t *in_arg [SWR_CH_MAX], int in_count){
AudioData * in= &s->in;
AudioData *out= &s->out;
if(s->drop_output > 0){
int ret;
uint8_t *tmp_arg[SWR_CH_MAX];
if((ret=swri_realloc_audio(&s->drop_temp, s->drop_output))<0)
return ret;
reversefill_audiodata(&s->drop_temp, tmp_arg);
s->drop_output *= -1; //FIXME find a less hackish solution
ret = swr_convert(s, tmp_arg, -s->drop_output, in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesnt matter
s->drop_output *= -1;
if(ret>0)
s->drop_output -= ret;
if(s->drop_output || !out_arg)
return 0;
in_count = 0;
}
if(!in_arg){
if(s->resample){
if (!s->flushed)
s->resampler->flush(s);
s->resample_in_constraint = 0;
s->flushed = 1;
}else if(!s->in_buffer_count){
return 0;
}
}else
fill_audiodata(in , (void*)in_arg);
fill_audiodata(out, out_arg);
if(s->resample){
int ret = swr_convert_internal(s, out, out_count, in, in_count);
if(ret>0 && !s->drop_output)
s->outpts += ret * (int64_t)s->in_sample_rate;
return ret;
}else{
AudioData tmp= *in;
int ret2=0;
int ret, size;
size = FFMIN(out_count, s->in_buffer_count);
if(size){
buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
ret= swr_convert_internal(s, out, size, &tmp, size);
if(ret<0)
return ret;
ret2= ret;
s->in_buffer_count -= ret;
s->in_buffer_index += ret;
buf_set(out, out, ret);
out_count -= ret;
if(!s->in_buffer_count)
s->in_buffer_index = 0;
}
if(in_count){
size= s->in_buffer_index + s->in_buffer_count + in_count - out_count;
if(in_count > out_count) { //FIXME move after swr_convert_internal
if( size > s->in_buffer.count
&& s->in_buffer_count + in_count - out_count <= s->in_buffer_index){
buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
copy(&s->in_buffer, &tmp, s->in_buffer_count);
s->in_buffer_index=0;
}else
if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0)
return ret;
}
if(out_count){
size = FFMIN(in_count, out_count);
ret= swr_convert_internal(s, out, size, in, size);
if(ret<0)
return ret;
buf_set(in, in, ret);
in_count -= ret;
ret2 += ret;
}
if(in_count){
buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);
copy(&tmp, in, in_count);
s->in_buffer_count += in_count;
}
}
if(ret2>0 && !s->drop_output)
s->outpts += ret2 * (int64_t)s->in_sample_rate;
return ret2;
}
}
| false | FFmpeg | b481d09bd9c7b3cba617a7811d7015ea0472e4ee |
8,314 | av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
{
MJpegDecodeContext *s = avctx->priv_data;
int ret;
if (!s->picture_ptr) {
s->picture = av_frame_alloc();
if (!s->picture)
return AVERROR(ENOMEM);
s->picture_ptr = s->picture;
}
s->avctx = avctx;
ff_blockdsp_init(&s->bdsp, avctx);
ff_hpeldsp_init(&s->hdsp, avctx->flags);
ff_idctdsp_init(&s->idsp, avctx);
ff_init_scantable(s->idsp.idct_permutation, &s->scantable,
ff_zigzag_direct);
s->buffer_size = 0;
s->buffer = NULL;
s->start_code = -1;
s->first_picture = 1;
s->org_height = avctx->coded_height;
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
avctx->colorspace = AVCOL_SPC_BT470BG;
if ((ret = build_basic_mjpeg_vlc(s)) < 0)
return ret;
if (s->extern_huff) {
av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0)
return ret;
if ((ret = ff_mjpeg_decode_dht(s))) {
av_log(avctx, AV_LOG_ERROR,
"mjpeg: error using external huffman table\n");
return ret;
}
}
if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */
s->interlace_polarity = 1; /* bottom field first */
av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n");
}
if (avctx->codec->id == AV_CODEC_ID_AMV)
s->flipped = 1;
return 0;
}
| false | FFmpeg | dcc39ee10e82833ce24aa57926c00ffeb1948198 |
8,315 | static int seg_write_trailer(struct AVFormatContext *s)
{
SegmentContext *seg = s->priv_data;
AVFormatContext *oc = seg->avf;
int ret = 0;
if (!oc)
goto fail;
if (!seg->write_header_trailer) {
if ((ret = segment_end(oc, 0)) < 0)
goto fail;
open_null_ctx(&oc->pb);
ret = av_write_trailer(oc);
close_null_ctx(oc->pb);
} else {
ret = segment_end(oc, 1);
}
if (ret < 0)
goto fail;
if (seg->list && seg->list_type == LIST_HLS) {
if ((ret = segment_hls_window(s, 1) < 0))
goto fail;
}
fail:
avio_close(seg->pb);
avformat_free_context(oc);
return ret;
}
| false | FFmpeg | 8a78ae2d2101622fd244b99178d8bc61175c878e |
8,316 | int ff_tempfile(const char *prefix, char **filename) {
int fd=-1;
#if !HAVE_MKSTEMP
*filename = tempnam(".", prefix);
#else
size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
*filename = av_malloc(len);
#endif
/* -----common section-----*/
if (*filename == NULL) {
av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
return -1;
}
#if !HAVE_MKSTEMP
fd = avpriv_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
#else
snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
fd = mkstemp(*filename);
if (fd < 0) {
snprintf(*filename, len, "./%sXXXXXX", prefix);
fd = mkstemp(*filename);
}
#endif
/* -----common section-----*/
if (fd < 0) {
av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
return -1;
}
return fd; /* success */
}
| false | FFmpeg | f929ab0569ff31ed5a59b0b0adb7ce09df3fca39 |
8,317 | static void ffm_seek1(AVFormatContext *s, int64_t pos1)
{
FFMContext *ffm = s->priv_data;
ByteIOContext *pb = s->pb;
int64_t pos;
pos = pos1 + ffm->write_index;
if (pos >= ffm->file_size)
pos -= (ffm->file_size - FFM_PACKET_SIZE);
#ifdef DEBUG_SEEK
av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
#endif
url_fseek(pb, pos, SEEK_SET);
}
| false | FFmpeg | 92a0f338786b629c5661f5b552e32c6154c3389d |
8,318 | static int decode_init(AVCodecContext * avctx)
{
MPADecodeContext *s = avctx->priv_data;
static int init=0;
int i, j, k;
#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
avctx->sample_fmt= SAMPLE_FMT_S32;
#else
avctx->sample_fmt= SAMPLE_FMT_S16;
#endif
if(avctx->antialias_algo != FF_AA_FLOAT)
s->compute_antialias= compute_antialias_integer;
else
s->compute_antialias= compute_antialias_float;
if (!init && !avctx->parse_only) {
/* scale factors table for layer 1/2 */
for(i=0;i<64;i++) {
int shift, mod;
/* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
shift = (i / 3);
mod = i % 3;
scale_factor_modshift[i] = mod | (shift << 2);
}
/* scale factor multiply for layer 1 */
for(i=0;i<15;i++) {
int n, norm;
n = i + 2;
norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
dprintf("%d: norm=%x s=%x %x %x\n",
i, norm,
scale_factor_mult[i][0],
scale_factor_mult[i][1],
scale_factor_mult[i][2]);
}
ff_mpa_synth_init(window);
/* huffman decode tables */
for(i=1;i<16;i++) {
const HuffTable *h = &mpa_huff_tables[i];
int xsize, x, y;
unsigned int n;
uint8_t tmp_bits [256];
uint16_t tmp_codes[256];
memset(tmp_bits , 0, sizeof(tmp_bits ));
memset(tmp_codes, 0, sizeof(tmp_codes));
xsize = h->xsize;
n = xsize * xsize;
j = 0;
for(x=0;x<xsize;x++) {
for(y=0;y<xsize;y++){
tmp_bits [(x << 4) | y]= h->bits [j ];
tmp_codes[(x << 4) | y]= h->codes[j++];
}
}
/* XXX: fail test */
init_vlc(&huff_vlc[i], 7, 256,
tmp_bits, 1, 1, tmp_codes, 2, 2, 1);
}
for(i=0;i<2;i++) {
init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, 1);
}
for(i=0;i<9;i++) {
k = 0;
for(j=0;j<22;j++) {
band_index_long[i][j] = k;
k += band_size_long[i][j];
}
band_index_long[i][22] = k;
}
/* compute n ^ (4/3) and store it in mantissa/exp format */
table_4_3_exp= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_exp[0]));
if(!table_4_3_exp)
return -1;
table_4_3_value= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_value[0]));
if(!table_4_3_value)
return -1;
int_pow_init();
for(i=1;i<TABLE_4_3_SIZE;i++) {
double f, fm;
int e, m;
f = pow((double)(i/4), 4.0 / 3.0) * pow(2, (i&3)*0.25);
fm = frexp(f, &e);
m = (uint32_t)(fm*(1LL<<31) + 0.5);
e+= FRAC_BITS - 31 + 5;
/* normalized to FRAC_BITS */
table_4_3_value[i] = m;
// av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0));
table_4_3_exp[i] = -e;
}
for(i=0; i<512*16; i++){
int exponent= (i>>4)-400;
double f= pow(i&15, 4.0 / 3.0) * pow(2, exponent*0.25 + FRAC_BITS + 5);
expval_table[exponent+400][i&15]= lrintf(f);
if((i&15)==1)
exp_table[exponent+400]= lrintf(f);
}
for(i=0;i<7;i++) {
float f;
int v;
if (i != 6) {
f = tan((double)i * M_PI / 12.0);
v = FIXR(f / (1.0 + f));
} else {
v = FIXR(1.0);
}
is_table[0][i] = v;
is_table[1][6 - i] = v;
}
/* invalid values */
for(i=7;i<16;i++)
is_table[0][i] = is_table[1][i] = 0.0;
for(i=0;i<16;i++) {
double f;
int e, k;
for(j=0;j<2;j++) {
e = -(j + 1) * ((i + 1) >> 1);
f = pow(2.0, e / 4.0);
k = i & 1;
is_table_lsf[j][k ^ 1][i] = FIXR(f);
is_table_lsf[j][k][i] = FIXR(1.0);
dprintf("is_table_lsf %d %d: %x %x\n",
i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]);
}
}
for(i=0;i<8;i++) {
float ci, cs, ca;
ci = ci_table[i];
cs = 1.0 / sqrt(1.0 + ci * ci);
ca = cs * ci;
csa_table[i][0] = FIXHR(cs/4);
csa_table[i][1] = FIXHR(ca/4);
csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
csa_table_float[i][0] = cs;
csa_table_float[i][1] = ca;
csa_table_float[i][2] = ca + cs;
csa_table_float[i][3] = ca - cs;
// printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
// av_log(NULL, AV_LOG_DEBUG,"%f %f %f %f\n", cs, ca, ca+cs, ca-cs);
}
/* compute mdct windows */
for(i=0;i<36;i++) {
for(j=0; j<4; j++){
double d;
if(j==2 && i%3 != 1)
continue;
d= sin(M_PI * (i + 0.5) / 36.0);
if(j==1){
if (i>=30) d= 0;
else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0);
else if(i>=18) d= 1;
}else if(j==3){
if (i< 6) d= 0;
else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0);
else if(i< 18) d= 1;
}
//merge last stage of imdct into the window coefficients
d*= 0.5 / cos(M_PI*(2*i + 19)/72);
if(j==2)
mdct_win[j][i/3] = FIXHR((d / (1<<5)));
else
mdct_win[j][i ] = FIXHR((d / (1<<5)));
// av_log(NULL, AV_LOG_DEBUG, "%2d %d %f\n", i,j,d / (1<<5));
}
}
/* NOTE: we do frequency inversion adter the MDCT by changing
the sign of the right window coefs */
for(j=0;j<4;j++) {
for(i=0;i<36;i+=2) {
mdct_win[j + 4][i] = mdct_win[j][i];
mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
}
}
#if defined(DEBUG)
for(j=0;j<8;j++) {
av_log(avctx, AV_LOG_DEBUG, "win%d=\n", j);
for(i=0;i<36;i++)
av_log(avctx, AV_LOG_DEBUG, "%f, ", (double)mdct_win[j][i] / FRAC_ONE);
av_log(avctx, AV_LOG_DEBUG, "\n");
}
#endif
init = 1;
}
s->inbuf_index = 0;
s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];
s->inbuf_ptr = s->inbuf;
#ifdef DEBUG
s->frame_count = 0;
#endif
if (avctx->codec_id == CODEC_ID_MP3ADU)
s->adu_mode = 1;
return 0;
}
| false | FFmpeg | bc2d2757bb532fa260c373adb00f4e47766e3449 |
8,319 | void checkasm_check_vf_threshold(void)
{
check_threshold_8();
report("threshold8");
}
| false | FFmpeg | 179a2f04eb2bd6df7221883a92dc4e00cf94394b |
8,320 | 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);
memset(bprm->page, 0, sizeof(bprm->page));
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);
#if defined(TARGET_HAS_BFLT)
} else if (bprm->buf[0] == 'b'
&& bprm->buf[1] == 'F'
&& bprm->buf[2] == 'L'
&& bprm->buf[3] == 'T') {
retval = load_flt_binary(bprm,regs,infop);
#endif
} 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);
}
| true | qemu | 7dd47667b9b0b23807fc1a550644fc2427462f41 |
8,321 | static int mp_get_vlc(MotionPixelsContext *mp, GetBitContext *gb)
{
int i;
i = (mp->codes_count == 1) ? 0 : get_vlc2(gb, mp->vlc.table, mp->max_codes_bits, 1);
return mp->codes[i].delta;
} | true | FFmpeg | ca41c72c6d9515d9045bd3b68104525dee81b8d0 |
8,322 | uint64_t helper_mulqv(CPUAlphaState *env, uint64_t op1, uint64_t op2)
{
uint64_t tl, th;
muls64(&tl, &th, op1, op2);
/* If th != 0 && th != -1, then we had an overflow */
if (unlikely((th + 1) > 1)) {
arith_excp(env, GETPC(), EXC_M_IOV, 0);
}
return tl;
}
| true | qemu | 4d1628e832dfc6ec02b0d196f6cc250aaa7bf3b3 |
8,323 | PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
{
PCIRTL8139State *d;
RTL8139State *s;
uint8_t *pci_conf;
d = (PCIRTL8139State *)pci_register_device(bus,
"RTL8139", sizeof(PCIRTL8139State),
devfn,
NULL, NULL);
pci_conf = d->dev.config;
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8139);
pci_conf[0x04] = 0x05; /* command = I/O space, Bus Master */
pci_conf[0x08] = RTL8139_PCI_REVID; /* PCI revision ID; >=0x20 is for 8139C+ */
pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
pci_conf[0x0e] = 0x00; /* header_type */
pci_conf[0x3d] = 1; /* interrupt pin 0 */
pci_conf[0x34] = 0xdc;
s = &d->rtl8139;
/* I/O handler for memory-mapped I/O */
s->rtl8139_mmio_io_addr =
cpu_register_io_memory(0, rtl8139_mmio_read, rtl8139_mmio_write, s);
pci_register_io_region(&d->dev, 0, 0x100,
PCI_ADDRESS_SPACE_IO, rtl8139_ioport_map);
pci_register_io_region(&d->dev, 1, 0x100,
PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
s->pci_dev = (PCIDevice *)d;
memcpy(s->macaddr, nd->macaddr, 6);
rtl8139_reset(s);
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
rtl8139_receive, rtl8139_can_receive, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
s->cplus_txbuffer = NULL;
s->cplus_txbuffer_len = 0;
s->cplus_txbuffer_offset = 0;
register_savevm("rtl8139", -1, 4, rtl8139_save, rtl8139_load, s);
#ifdef RTL8139_ONBOARD_TIMER
s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s);
qemu_mod_timer(s->timer,
rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
#endif /* RTL8139_ONBOARD_TIMER */
return (PCIDevice *)d;
}
| true | qemu | b946a1533209f61a93e34898aebb5b43154b99c3 |
8,324 | void usb_wakeup(USBEndpoint *ep, unsigned int stream)
{
USBDevice *dev = ep->dev;
USBBus *bus = usb_bus_from_device(dev);
if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) {
dev->port->ops->wakeup(dev->port);
if (bus->ops->wakeup_endpoint) {
bus->ops->wakeup_endpoint(bus, ep, stream);
| true | qemu | 26022652c6fd067b9fa09280f5a6d6284a21c73f |
8,325 | target_ulong helper_load_slb_vsid(CPUPPCState *env, target_ulong rb)
{
target_ulong rt;
if (ppc_load_slb_vsid(env, rb, &rt) < 0) {
helper_raise_exception_err(env, POWERPC_EXCP_PROGRAM,
POWERPC_EXCP_INVAL);
}
return rt;
}
| true | qemu | 4cc2cc085586cdb787a24d78a7ba032fa657275a |
8,326 | static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track)
{
int tag = track->par->codec_tag;
int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE;
AVStream *st = track->st;
int rate = av_q2d(find_fps(s, st));
if (!tag)
tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag
if (track->par->format == AV_PIX_FMT_YUV420P10) {
if (track->par->width == 960 && track->par->height == 720) {
if (!interlaced) {
if (rate == 24) tag = MKTAG('a','i','5','p');
else if (rate == 25) tag = MKTAG('a','i','5','q');
else if (rate == 30) tag = MKTAG('a','i','5','p');
else if (rate == 50) tag = MKTAG('a','i','5','q');
else if (rate == 60) tag = MKTAG('a','i','5','p');
}
} else if (track->par->width == 1440 && track->par->height == 1080) {
if (!interlaced) {
if (rate == 24) tag = MKTAG('a','i','5','3');
else if (rate == 25) tag = MKTAG('a','i','5','2');
else if (rate == 30) tag = MKTAG('a','i','5','3');
} else {
if (rate == 50) tag = MKTAG('a','i','5','5');
else if (rate == 60) tag = MKTAG('a','i','5','6');
}
}
} else if (track->par->format == AV_PIX_FMT_YUV422P10) {
if (track->par->width == 1280 && track->par->height == 720) {
if (!interlaced) {
if (rate == 24) tag = MKTAG('a','i','1','p');
else if (rate == 25) tag = MKTAG('a','i','1','q');
else if (rate == 30) tag = MKTAG('a','i','1','p');
else if (rate == 50) tag = MKTAG('a','i','1','q');
else if (rate == 60) tag = MKTAG('a','i','1','p');
}
} else if (track->par->width == 1920 && track->par->height == 1080) {
if (!interlaced) {
if (rate == 24) tag = MKTAG('a','i','1','3');
else if (rate == 25) tag = MKTAG('a','i','1','2');
else if (rate == 30) tag = MKTAG('a','i','1','3');
} else {
if (rate == 25) tag = MKTAG('a','i','1','5');
else if (rate == 50) tag = MKTAG('a','i','1','5');
else if (rate == 60) tag = MKTAG('a','i','1','6');
}
} else if ( track->par->width == 4096 && track->par->height == 2160
|| track->par->width == 3840 && track->par->height == 2160
|| track->par->width == 2048 && track->par->height == 1080) {
tag = MKTAG('a','i','v','x');
}
}
return tag;
}
| true | FFmpeg | 77bc507f6f001b9f5fa75c664106261bd8f2c971 |
8,327 | static int64_t get_dts(AVFormatContext *s, int64_t pos)
{
AVIOContext *pb = s->pb;
int64_t dts;
ffm_seek1(s, pos);
avio_skip(pb, 4);
dts = avio_rb64(pb);
av_dlog(s, "dts=%0.6f\n", dts / 1000000.0);
return dts;
}
| false | FFmpeg | 229843aa359ae0c9519977d7fa952688db63f559 |
8,328 | static void apply_channel_coupling(AC3EncodeContext *s)
{
LOCAL_ALIGNED_16(CoefType, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
#if CONFIG_AC3ENC_FLOAT
LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
#else
int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords;
#endif
int av_uninit(blk), ch, bnd, i, j;
CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
int cpl_start, num_cpl_coefs;
memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
#if CONFIG_AC3ENC_FLOAT
memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
#endif
/* align start to 16-byte boundary. align length to multiple of 32.
note: coupling start bin % 4 will always be 1 */
cpl_start = s->start_freq[CPL_CH] - 1;
num_cpl_coefs = FFALIGN(s->num_cpl_subbands * 12 + 1, 32);
cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
/* calculate coupling channel from fbw channels */
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start];
if (!block->cpl_in_use)
continue;
memset(cpl_coef, 0, num_cpl_coefs * sizeof(*cpl_coef));
for (ch = 1; ch <= s->fbw_channels; ch++) {
CoefType *ch_coef = &block->mdct_coef[ch][cpl_start];
if (!block->channel_in_cpl[ch])
continue;
for (i = 0; i < num_cpl_coefs; i++)
cpl_coef[i] += ch_coef[i];
}
/* coefficients must be clipped in order to be encoded */
clip_coefficients(&s->adsp, cpl_coef, num_cpl_coefs);
}
/* calculate energy in each band in coupling channel and each fbw channel */
/* TODO: possibly use SIMD to speed up energy calculation */
bnd = 0;
i = s->start_freq[CPL_CH];
while (i < s->cpl_end_freq) {
int band_size = s->cpl_band_sizes[bnd];
for (ch = CPL_CH; ch <= s->fbw_channels; ch++) {
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use || (ch > CPL_CH && !block->channel_in_cpl[ch]))
continue;
for (j = 0; j < band_size; j++) {
CoefType v = block->mdct_coef[ch][i+j];
MAC_COEF(energy[blk][ch][bnd], v, v);
}
}
}
i += band_size;
bnd++;
}
/* calculate coupling coordinates for all blocks for all channels */
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use)
continue;
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (!block->channel_in_cpl[ch])
continue;
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy[blk][ch][bnd],
energy[blk][CPL_CH][bnd]);
}
}
}
/* determine which blocks to send new coupling coordinates for */
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
AC3Block *block0 = blk ? &s->blocks[blk-1] : NULL;
memset(block->new_cpl_coords, 0, sizeof(block->new_cpl_coords));
if (block->cpl_in_use) {
/* send new coordinates if this is the first block, if previous
* block did not use coupling but this block does, the channels
* using coupling has changed from the previous block, or the
* coordinate difference from the last block for any channel is
* greater than a threshold value. */
if (blk == 0 || !block0->cpl_in_use) {
for (ch = 1; ch <= s->fbw_channels; ch++)
block->new_cpl_coords[ch] = 1;
} else {
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (!block->channel_in_cpl[ch])
continue;
if (!block0->channel_in_cpl[ch]) {
block->new_cpl_coords[ch] = 1;
} else {
CoefSumType coord_diff = 0;
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] -
cpl_coords[blk ][ch][bnd]);
}
coord_diff /= s->num_cpl_bands;
if (coord_diff > NEW_CPL_COORD_THRESHOLD)
block->new_cpl_coords[ch] = 1;
}
}
}
}
}
/* calculate final coupling coordinates, taking into account reusing of
coordinates in successive blocks */
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
blk = 0;
while (blk < s->num_blocks) {
int av_uninit(blk1);
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use) {
blk++;
continue;
}
for (ch = 1; ch <= s->fbw_channels; ch++) {
CoefSumType energy_ch, energy_cpl;
if (!block->channel_in_cpl[ch])
continue;
energy_cpl = energy[blk][CPL_CH][bnd];
energy_ch = energy[blk][ch][bnd];
blk1 = blk+1;
while (!s->blocks[blk1].new_cpl_coords[ch] && blk1 < s->num_blocks) {
if (s->blocks[blk1].cpl_in_use) {
energy_cpl += energy[blk1][CPL_CH][bnd];
energy_ch += energy[blk1][ch][bnd];
}
blk1++;
}
cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy_ch, energy_cpl);
}
blk = blk1;
}
}
/* calculate exponents/mantissas for coupling coordinates */
for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use)
continue;
#if CONFIG_AC3ENC_FLOAT
s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1],
cpl_coords[blk][1],
s->fbw_channels * 16);
#endif
s->ac3dsp.extract_exponents(block->cpl_coord_exp[1],
fixed_cpl_coords[blk][1],
s->fbw_channels * 16);
for (ch = 1; ch <= s->fbw_channels; ch++) {
int bnd, min_exp, max_exp, master_exp;
if (!block->new_cpl_coords[ch])
continue;
/* determine master exponent */
min_exp = max_exp = block->cpl_coord_exp[ch][0];
for (bnd = 1; bnd < s->num_cpl_bands; bnd++) {
int exp = block->cpl_coord_exp[ch][bnd];
min_exp = FFMIN(exp, min_exp);
max_exp = FFMAX(exp, max_exp);
}
master_exp = ((max_exp - 15) + 2) / 3;
master_exp = FFMAX(master_exp, 0);
while (min_exp < master_exp * 3)
master_exp--;
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
block->cpl_coord_exp[ch][bnd] = av_clip(block->cpl_coord_exp[ch][bnd] -
master_exp * 3, 0, 15);
}
block->cpl_master_exp[ch] = master_exp;
/* quantize mantissas */
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
int cpl_exp = block->cpl_coord_exp[ch][bnd];
int cpl_mant = (fixed_cpl_coords[blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24;
if (cpl_exp == 15)
cpl_mant >>= 1;
else
cpl_mant -= 16;
block->cpl_coord_mant[ch][bnd] = cpl_mant;
}
}
}
if (CONFIG_EAC3_ENCODER && s->eac3)
ff_eac3_set_cpl_states(s);
}
| false | FFmpeg | d85ebea3f3b68ebccfe308fa839fc30fa634e4de |
8,329 | static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
WVMuxContext *wc = s->priv_data;
AVCodecContext *codec = s->streams[0]->codec;
AVIOContext *pb = s->pb;
uint64_t size;
uint32_t flags;
uint32_t left = pkt->size;
uint8_t *ptr = pkt->data;
int off = codec->channels > 2 ? 4 : 0;
/* FIXME: Simplify decoder/demuxer so bellow code can support midstream
* change of stream parameters */
wc->duration += pkt->duration;
ffio_wfourcc(pb, "wvpk");
if (off) {
size = AV_RL32(pkt->data);
if (size <= 12)
return AVERROR_INVALIDDATA;
size -= 12;
} else {
size = pkt->size;
}
if (size + off > left)
return AVERROR_INVALIDDATA;
avio_wl32(pb, size + 12);
avio_wl16(pb, 0x410);
avio_w8(pb, 0);
avio_w8(pb, 0);
avio_wl32(pb, -1);
avio_wl32(pb, pkt->pts);
ptr += off; left -= off;
flags = AV_RL32(ptr + 4);
avio_write(pb, ptr, size);
ptr += size; left -= size;
while (!(flags & WV_END_BLOCK) &&
(left >= 4 + WV_EXTRA_SIZE)) {
ffio_wfourcc(pb, "wvpk");
size = AV_RL32(ptr);
ptr += 4; left -= 4;
if (size < 24 || size - 24 > left)
return AVERROR_INVALIDDATA;
avio_wl32(pb, size);
avio_wl16(pb, 0x410);
avio_w8(pb, 0);
avio_w8(pb, 0);
avio_wl32(pb, -1);
avio_wl32(pb, pkt->pts);
flags = AV_RL32(ptr + 4);
avio_write(pb, ptr, WV_EXTRA_SIZE);
ptr += WV_EXTRA_SIZE; left -= WV_EXTRA_SIZE;
avio_write(pb, ptr, size - 24);
ptr += size - 24; left -= size - 24;
}
return 0;
}
| false | FFmpeg | 269fc8e04906ffd965aa19425ca90980b23c6508 |
8,330 | static void compute_antialias_integer(MPADecodeContext *s,
GranuleDef *g)
{
int32_t *ptr, *csa;
int n, i;
/* we antialias only "long" bands */
if (g->block_type == 2) {
if (!g->switch_point)
return;
/* XXX: check this for 8000Hz case */
n = 1;
} else {
n = SBLIMIT - 1;
}
ptr = g->sb_hybrid + 18;
for(i = n;i > 0;i--) {
int tmp0, tmp1, tmp2;
csa = &csa_table[0][0];
#define INT_AA(j) \
tmp0 = 4*(ptr[-1-j]);\
tmp1 = 4*(ptr[ j]);\
tmp2= MULH(tmp0 + tmp1, csa[0+4*j]);\
ptr[-1-j] = tmp2 - MULH(tmp1, csa[2+4*j]);\
ptr[ j] = tmp2 + MULH(tmp0, csa[3+4*j]);
INT_AA(0)
INT_AA(1)
INT_AA(2)
INT_AA(3)
INT_AA(4)
INT_AA(5)
INT_AA(6)
INT_AA(7)
ptr += 18;
}
}
| true | FFmpeg | 44f1698a3824836d32708ae93e78ac1f2310a07e |
8,331 | static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
{
static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static const uint8_t vlan[] = {0x81, 0x00};
uint8_t *ptr = (uint8_t *)buf;
int i;
if (n->promisc)
return 1;
if (!memcmp(&ptr[12], vlan, sizeof(vlan))) {
int vid = be16_to_cpup((uint16_t *)(ptr + 14)) & 0xfff;
if (!(n->vlans[vid >> 5] & (1U << (vid & 0x1f))))
return 0;
}
if (ptr[0] & 1) { // multicast
if (!memcmp(ptr, bcast, sizeof(bcast))) {
return 1;
} else if (n->allmulti) {
return 1;
}
} else { // unicast
if (!memcmp(ptr, n->mac, ETH_ALEN)) {
return 1;
}
}
for (i = 0; i < n->mac_table.in_use; i++) {
if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN))
return 1;
}
return 0;
}
| true | qemu | 8fd2a2f1a9048b9e37a898c2a5e9ef59d0c1a095 |
8,332 | static void expand_rle_row(unsigned char *optr, unsigned char *iptr,
int chan_offset, int pixelstride)
{
unsigned char pixel, count;
#ifndef WORDS_BIGENDIAN
/* rgba -> bgra for rgba32 on little endian cpus */
if (pixelstride == 4 && chan_offset != 3) {
chan_offset = 2 - chan_offset;
}
#endif
optr += chan_offset;
while (1) {
pixel = *iptr++;
if (!(count = (pixel & 0x7f))) {
return;
}
if (pixel & 0x80) {
while (count--) {
*optr = *iptr;
optr += pixelstride;
iptr++;
}
} else {
pixel = *iptr++;
while (count--) {
*optr = pixel;
optr += pixelstride;
}
}
}
}
| true | FFmpeg | 44f110f509d0ab4fc73b9f2363a97c6577d3850f |
8,333 | static void rtsp_cmd_describe(HTTPContext *c, const char *url)
{
FFStream *stream;
char path1[1024];
const char *path;
uint8_t *content;
int content_length, len;
struct sockaddr_in my_addr;
/* find which url is asked */
url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
path = path1;
if (*path == '/')
path++;
for(stream = first_stream; stream != NULL; stream = stream->next) {
if (!stream->is_feed && !strcmp(stream->fmt->name, "rtp") &&
!strcmp(path, stream->filename)) {
goto found;
}
}
/* no stream found */
rtsp_reply_error(c, RTSP_STATUS_SERVICE); /* XXX: right error ? */
return;
found:
/* prepare the media description in sdp format */
/* get the host IP */
len = sizeof(my_addr);
getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
content_length = prepare_sdp_description(stream, &content, my_addr.sin_addr);
if (content_length < 0) {
rtsp_reply_error(c, RTSP_STATUS_INTERNAL);
return;
}
rtsp_reply_header(c, RTSP_STATUS_OK);
url_fprintf(c->pb, "Content-Type: application/sdp\r\n");
url_fprintf(c->pb, "Content-Length: %d\r\n", content_length);
url_fprintf(c->pb, "\r\n");
put_buffer(c->pb, content, content_length);
}
| true | FFmpeg | 25e3e53d4092e7b69a4d681824fa0f7b2731bb1e |
8,334 | av_cold int ff_vp8_decode_free(AVCodecContext *avctx)
{
VP8Context *s = avctx->priv_data;
int i;
vp8_decode_flush_impl(avctx, 1);
for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++)
av_frame_free(&s->frames[i].tf.f);
} | true | FFmpeg | a84f0e8d8f293df3c535f9b893730a835bed6520 |
8,335 | static void spapr_alloc_htab(sPAPRMachineState *spapr)
{
long shift;
int index;
/* allocate hash page table. For now we always make this 16mb,
* later we should probably make it scale to the size of guest
* RAM */
shift = kvmppc_reset_htab(spapr->htab_shift);
if (shift > 0) {
/* Kernel handles htab, we don't need to allocate one */
if (shift != spapr->htab_shift) {
error_setg(&error_abort, "Failed to allocate HTAB of requested size, try with smaller maxmem");
}
spapr->htab_shift = shift;
kvmppc_kern_htab = true;
} else {
/* Allocate htab */
spapr->htab = qemu_memalign(HTAB_SIZE(spapr), HTAB_SIZE(spapr));
/* And clear it */
memset(spapr->htab, 0, HTAB_SIZE(spapr));
for (index = 0; index < HTAB_SIZE(spapr) / HASH_PTE_SIZE_64; index++) {
DIRTY_HPTE(HPTE(spapr->htab, index));
}
}
}
| true | qemu | b41d320fef705289d2b73f4949731eb2e189161d |
8,336 | static int qemu_rdma_get_buffer(void *opaque, uint8_t *buf,
int64_t pos, int size)
{
QEMUFileRDMA *r = opaque;
RDMAContext *rdma = r->rdma;
RDMAControlHeader head;
int ret = 0;
CHECK_ERROR_STATE();
/*
* First, we hold on to the last SEND message we
* were given and dish out the bytes until we run
* out of bytes.
*/
r->len = qemu_rdma_fill(r->rdma, buf, size, 0);
if (r->len) {
return r->len;
}
/*
* Once we run out, we block and wait for another
* SEND message to arrive.
*/
ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_QEMU_FILE);
if (ret < 0) {
rdma->error_state = ret;
return ret;
}
/*
* SEND was received with new bytes, now try again.
*/
return qemu_rdma_fill(r->rdma, buf, size, 0);
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 |
8,338 | static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
{
av_free(bin->data);
if (!(bin->data = av_malloc(length)))
return AVERROR(ENOMEM);
bin->size = length;
bin->pos = avio_tell(pb);
if (avio_read(pb, bin->data, length) != length) {
av_freep(&bin->data);
return AVERROR(EIO);
}
return 0;
}
| true | FFmpeg | 30be1ea33e5525266ad871bed60b1893a53caeaf |
8,339 | void avcodec_init(void)
{
static int inited = 0;
if (inited != 0)
return;
inited = 1;
dsputil_static_init();
}
| false | FFmpeg | 5e53486545726987ab4482321d4dcf7e23e7652f |
8,341 | void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt) {
double scale = s->dither.noise_scale;
#define TMP_EXTRA 2
double *tmp = av_malloc_array(len + TMP_EXTRA, sizeof(double));
int i;
for(i=0; i<len + TMP_EXTRA; i++){
double v;
seed = seed* 1664525 + 1013904223;
switch(s->dither.method){
case SWR_DITHER_RECTANGULAR: v= ((double)seed) / UINT_MAX - 0.5; break;
default:
av_assert0(s->dither.method < SWR_DITHER_NB);
v = ((double)seed) / UINT_MAX;
seed = seed*1664525 + 1013904223;
v-= ((double)seed) / UINT_MAX;
break;
}
tmp[i] = v;
}
for(i=0; i<len; i++){
double v;
switch(s->dither.method){
default:
av_assert0(s->dither.method < SWR_DITHER_NB);
v = tmp[i];
break;
case SWR_DITHER_TRIANGULAR_HIGHPASS :
v = (- tmp[i] + 2*tmp[i+1] - tmp[i+2]) / sqrt(6);
break;
}
v*= scale;
switch(noise_fmt){
case AV_SAMPLE_FMT_S16P: ((int16_t*)dst)[i] = v; break;
case AV_SAMPLE_FMT_S32P: ((int32_t*)dst)[i] = v; break;
case AV_SAMPLE_FMT_FLTP: ((float *)dst)[i] = v; break;
case AV_SAMPLE_FMT_DBLP: ((double *)dst)[i] = v; break;
default: av_assert0(0);
}
}
av_free(tmp);
}
| false | FFmpeg | 196b885a5f0aa3ca022c1fa99509f47341239784 |
8,342 | static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
int log2_cb_size, int cb_depth)
{
HEVCLocalContext *lc = s->HEVClc;
const int cb_size = 1 << log2_cb_size;
int ret;
lc->ct.depth = cb_depth;
if (x0 + cb_size <= s->sps->width &&
y0 + cb_size <= s->sps->height &&
log2_cb_size > s->sps->log2_min_cb_size) {
SAMPLE(s->split_cu_flag, x0, y0) =
ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);
} else {
SAMPLE(s->split_cu_flag, x0, y0) =
(log2_cb_size > s->sps->log2_min_cb_size);
}
if (s->pps->cu_qp_delta_enabled_flag &&
log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {
lc->tu.is_cu_qp_delta_coded = 0;
lc->tu.cu_qp_delta = 0;
}
if (SAMPLE(s->split_cu_flag, x0, y0)) {
const int cb_size_split = cb_size >> 1;
const int x1 = x0 + cb_size_split;
const int y1 = y0 + cb_size_split;
int more_data = 0;
more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
return more_data;
if (more_data && x1 < s->sps->width)
more_data = hls_coding_quadtree(s, x1, y0, log2_cb_size - 1, cb_depth + 1);
if (more_data && y1 < s->sps->height)
more_data = hls_coding_quadtree(s, x0, y1, log2_cb_size - 1, cb_depth + 1);
if (more_data && x1 < s->sps->width &&
y1 < s->sps->height) {
return hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1);
}
if (more_data)
return ((x1 + cb_size_split) < s->sps->width ||
(y1 + cb_size_split) < s->sps->height);
else
return 0;
} else {
ret = hls_coding_unit(s, x0, y0, log2_cb_size);
if (ret < 0)
return ret;
if ((!((x0 + cb_size) %
(1 << (s->sps->log2_ctb_size))) ||
(x0 + cb_size >= s->sps->width)) &&
(!((y0 + cb_size) %
(1 << (s->sps->log2_ctb_size))) ||
(y0 + cb_size >= s->sps->height))) {
int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s);
return !end_of_slice_flag;
} else {
return 1;
}
}
return 0;
}
| true | FFmpeg | 96c4ba2392b9cd55a5e84cb28db5c0c7e53cd390 |
8,343 | static void test_uuid_unparse_strdup(void)
{
int i;
for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
char *out;
if (!uuid_test_data[i].check_unparse) {
continue;
}
out = qemu_uuid_unparse_strdup(&uuid_test_data[i].uuid);
g_assert_cmpstr(uuid_test_data[i].uuidstr, ==, out);
}
} | true | qemu | d9c05e507f7a6647cd7b106c8784f1f15a0e4f5c |
8,344 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
{
SmackVContext * const smk = avctx->priv_data;
uint8_t *out;
uint32_t *pal;
GetBitContext gb;
int blocks, blk, bw, bh;
int i;
int stride;
if(buf_size == 769)
return 0;
if(smk->pic.data[0])
avctx->release_buffer(avctx, &smk->pic);
smk->pic.reference = 1;
smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if(avctx->reget_buffer(avctx, &smk->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
/* make the palette available on the way out */
pal = (uint32_t*)smk->pic.data[1];
smk->pic.palette_has_changed = buf[0] & 1;
smk->pic.key_frame = !!(buf[0] & 2);
if(smk->pic.key_frame)
smk->pic.pict_type = FF_I_TYPE;
else
smk->pic.pict_type = FF_P_TYPE;
buf++;
for(i = 0; i < 256; i++)
*pal++ = bytestream_get_be24(&buf);
buf_size -= 769;
last_reset(smk->mmap_tbl, smk->mmap_last);
last_reset(smk->mclr_tbl, smk->mclr_last);
last_reset(smk->full_tbl, smk->full_last);
last_reset(smk->type_tbl, smk->type_last);
init_get_bits(&gb, buf, buf_size * 8);
blk = 0;
bw = avctx->width >> 2;
bh = avctx->height >> 2;
blocks = bw * bh;
out = smk->pic.data[0];
stride = smk->pic.linesize[0];
while(blk < blocks) {
int type, run, mode;
uint16_t pix;
type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
run = block_runs[(type >> 2) & 0x3F];
switch(type & 3){
case SMK_BLK_MONO:
while(run-- && blk < blocks){
int clr, map;
int hi, lo;
clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last);
map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last);
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
hi = clr >> 8;
lo = clr & 0xFF;
for(i = 0; i < 4; i++) {
if(map & 1) out[0] = hi; else out[0] = lo;
if(map & 2) out[1] = hi; else out[1] = lo;
if(map & 4) out[2] = hi; else out[2] = lo;
if(map & 8) out[3] = hi; else out[3] = lo;
map >>= 4;
out += stride;
}
blk++;
}
break;
case SMK_BLK_FULL:
mode = 0;
if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
if(get_bits1(&gb)) mode = 1;
else if(get_bits1(&gb)) mode = 2;
}
while(run-- && blk < blocks){
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
switch(mode){
case 0:
for(i = 0; i < 4; i++) {
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
AV_WL16(out+2,pix);
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
AV_WL16(out,pix);
out += stride;
}
break;
case 1:
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
out[0] = out[1] = pix & 0xFF;
out[2] = out[3] = pix >> 8;
out += stride;
out[0] = out[1] = pix & 0xFF;
out[2] = out[3] = pix >> 8;
out += stride;
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
out[0] = out[1] = pix & 0xFF;
out[2] = out[3] = pix >> 8;
out += stride;
out[0] = out[1] = pix & 0xFF;
out[2] = out[3] = pix >> 8;
out += stride;
break;
case 2:
for(i = 0; i < 2; i++) {
uint16_t pix1, pix2;
pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
AV_WL16(out,pix1);
AV_WL16(out+2,pix2);
out += stride;
AV_WL16(out,pix1);
AV_WL16(out+2,pix2);
out += stride;
}
break;
}
blk++;
}
break;
case SMK_BLK_SKIP:
while(run-- && blk < blocks)
blk++;
break;
case SMK_BLK_FILL:
mode = type >> 8;
while(run-- && blk < blocks){
uint32_t col;
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
col = mode * 0x01010101;
for(i = 0; i < 4; i++) {
*((uint32_t*)out) = col;
out += stride;
}
blk++;
}
break;
}
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = smk->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
| true | FFmpeg | 909063f74551141e181ff806fabe133ebc5e369e |
8,345 | static void core_region_del(MemoryListener *listener,
MemoryRegionSection *section)
{
cpu_register_physical_memory_log(section, false);
}
| true | qemu | 54688b1ec1f468c7272b837ff57298068aaedf5f |
8,346 | void do_store_msr (CPUPPCState *env, target_ulong value)
{
int enter_pm;
value &= env->msr_mask;
if (((value >> MSR_IR) & 1) != msr_ir ||
((value >> MSR_DR) & 1) != msr_dr) {
/* Flush all tlb when changing translation mode */
tlb_flush(env, 1);
env->interrupt_request |= CPU_INTERRUPT_EXITTB;
}
#if 0
if (loglevel != 0) {
fprintf(logfile, "%s: T0 %08lx\n", __func__, value);
}
#endif
switch (PPC_EXCP(env)) {
case PPC_FLAGS_EXCP_602:
case PPC_FLAGS_EXCP_603:
if (((value >> MSR_TGPR) & 1) != msr_tgpr) {
/* Swap temporary saved registers with GPRs */
swap_gpr_tgpr(env);
}
break;
default:
break;
}
#if defined (TARGET_PPC64)
msr_sf = (value >> MSR_SF) & 1;
msr_isf = (value >> MSR_ISF) & 1;
msr_hv = (value >> MSR_HV) & 1;
#endif
msr_ucle = (value >> MSR_UCLE) & 1;
msr_vr = (value >> MSR_VR) & 1; /* VR / SPE */
msr_ap = (value >> MSR_AP) & 1;
msr_sa = (value >> MSR_SA) & 1;
msr_key = (value >> MSR_KEY) & 1;
msr_pow = (value >> MSR_POW) & 1; /* POW / WE */
msr_tlb = (value >> MSR_TLB) & 1; /* TLB / TGPR / CE */
msr_ile = (value >> MSR_ILE) & 1;
msr_ee = (value >> MSR_EE) & 1;
msr_pr = (value >> MSR_PR) & 1;
msr_fp = (value >> MSR_FP) & 1;
msr_me = (value >> MSR_ME) & 1;
msr_fe0 = (value >> MSR_FE0) & 1;
msr_se = (value >> MSR_SE) & 1; /* SE / DWE / UBLE */
msr_be = (value >> MSR_BE) & 1; /* BE / DE */
msr_fe1 = (value >> MSR_FE1) & 1;
msr_al = (value >> MSR_AL) & 1;
msr_ip = (value >> MSR_IP) & 1;
msr_ir = (value >> MSR_IR) & 1; /* IR / IS */
msr_dr = (value >> MSR_DR) & 1; /* DR / DS */
msr_pe = (value >> MSR_PE) & 1; /* PE / EP */
msr_px = (value >> MSR_PX) & 1; /* PX / PMM */
msr_ri = (value >> MSR_RI) & 1;
msr_le = (value >> MSR_LE) & 1;
do_compute_hflags(env);
enter_pm = 0;
switch (PPC_EXCP(env)) {
case PPC_FLAGS_EXCP_603:
/* Don't handle SLEEP mode: we should disable all clocks...
* No dynamic power-management.
*/
if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00C00000) != 0)
enter_pm = 1;
break;
case PPC_FLAGS_EXCP_604:
if (msr_pow == 1)
enter_pm = 1;
break;
case PPC_FLAGS_EXCP_7x0:
if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00E00000) != 0)
enter_pm = 1;
break;
default:
break;
}
if (enter_pm) {
/* power save: exit cpu loop */
env->halted = 1;
env->exception_index = EXCP_HLT;
cpu_loop_exit();
}
}
| true | qemu | c19dbb9426a34a8e8cfdc5c285e8562ff3fe4f7a |
8,347 | static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
{
const uint8_t* as_pack;
int freq, stype, smpls, quant, i, ach;
as_pack = dv_extract_pack(frame, dv_audio_source);
if (!as_pack || !c->sys) { /* No audio ? */
c->ach = 0;
smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH, 3 - 8CH */
quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
if (stype > 3) {
av_log(c->fctx, AV_LOG_ERROR, "stype %d is invalid\n", stype);
c->ach = 0;
/* note: ach counts PAIRS of channels (i.e. stereo channels) */
ach = ((int[4]){ 1, 0, 2, 4})[stype];
if (ach == 1 && quant && freq == 2)
ach = 2;
/* Dynamic handling of the audio streams in DV */
for (i = 0; i < ach; i++) {
if (!c->ast[i]) {
c->ast[i] = avformat_new_stream(c->fctx, NULL);
if (!c->ast[i])
break;
avpriv_set_pts_info(c->ast[i], 64, 1, 30000);
c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
av_init_packet(&c->audio_pkt[i]);
c->audio_pkt[i].size = 0;
c->audio_pkt[i].data = c->audio_buf[i];
c->audio_pkt[i].stream_index = c->ast[i]->index;
c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY;
c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
c->ast[i]->codec->channels = 2;
c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;
c->ast[i]->start_time = 0;
c->ach = i;
return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */; | true | FFmpeg | 0ab3687924457cb4fd81897bd39ab3cc5b699588 |
8,348 | QEMUFile *qemu_fopen_socket(int fd, const char *mode)
{
QEMUFileSocket *s;
if (qemu_file_mode_is_not_valid(mode)) {
return NULL;
}
s = g_malloc0(sizeof(QEMUFileSocket));
s->fd = fd;
if (mode[0] == 'w') {
qemu_set_block(s->fd);
s->file = qemu_fopen_ops(s, &socket_write_ops);
} else {
s->file = qemu_fopen_ops(s, &socket_read_ops);
}
return s->file;
}
| true | qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 |
8,349 | static void aio_rfifolock_cb(void *opaque)
{
/* Kick owner thread in case they are blocked in aio_poll() */
aio_notify(opaque);
}
| true | qemu | ca96ac44dcd290566090b2435bc828fded356ad9 |
8,350 | int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
QCryptoTLSCreds *tlscreds, const char *hostname,
QIOChannel **outioc, NBDExportInfo *info,
Error **errp)
{
char buf[256];
uint64_t magic;
int rc;
bool zeroes = true;
bool structured_reply = info->structured_reply;
trace_nbd_receive_negotiate(tlscreds, hostname ? hostname : "<null>");
info->structured_reply = false;
rc = -EINVAL;
if (outioc) {
*outioc = NULL;
if (tlscreds && !outioc) {
error_setg(errp, "Output I/O channel required for TLS");
if (nbd_read(ioc, buf, 8, errp) < 0) {
error_prepend(errp, "Failed to read data");
buf[8] = '\0';
if (strlen(buf) == 0) {
error_setg(errp, "Server connection closed unexpectedly");
magic = ldq_be_p(buf);
trace_nbd_receive_negotiate_magic(magic);
if (memcmp(buf, "NBDMAGIC", 8) != 0) {
error_setg(errp, "Invalid magic received");
if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) {
error_prepend(errp, "Failed to read magic");
magic = be64_to_cpu(magic);
trace_nbd_receive_negotiate_magic(magic);
if (magic == NBD_OPTS_MAGIC) {
uint32_t clientflags = 0;
uint16_t globalflags;
bool fixedNewStyle = false;
if (nbd_read(ioc, &globalflags, sizeof(globalflags), errp) < 0) {
error_prepend(errp, "Failed to read server flags");
globalflags = be16_to_cpu(globalflags);
trace_nbd_receive_negotiate_server_flags(globalflags);
if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) {
fixedNewStyle = true;
clientflags |= NBD_FLAG_C_FIXED_NEWSTYLE;
if (globalflags & NBD_FLAG_NO_ZEROES) {
zeroes = false;
clientflags |= NBD_FLAG_C_NO_ZEROES;
/* client requested flags */
clientflags = cpu_to_be32(clientflags);
if (nbd_write(ioc, &clientflags, sizeof(clientflags), errp) < 0) {
error_prepend(errp, "Failed to send clientflags field");
if (tlscreds) {
if (fixedNewStyle) {
*outioc = nbd_receive_starttls(ioc, tlscreds, hostname, errp);
if (!*outioc) {
ioc = *outioc;
} else {
error_setg(errp, "Server does not support STARTTLS");
if (!name) {
trace_nbd_receive_negotiate_default_name();
name = "";
if (fixedNewStyle) {
int result;
/* Try NBD_OPT_GO first - if it works, we are done (it
* also gives us a good message if the server requires
* TLS). If it is not available, fall back to
* NBD_OPT_LIST for nicer error messages about a missing
* export, then use NBD_OPT_EXPORT_NAME. */
result = nbd_opt_go(ioc, name, info, errp);
if (result > 0) {
return 0;
/* Check our desired export is present in the
* server export list. Since NBD_OPT_EXPORT_NAME
* cannot return an error message, running this
* query gives us better error reporting if the
* export name is not available.
*/
if (nbd_receive_query_exports(ioc, name, errp) < 0) {
/* write the export name request */
if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, name,
errp) < 0) {
/* Read the response */
if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
error_prepend(errp, "Failed to read export length");
be64_to_cpus(&info->size);
if (nbd_read(ioc, &info->flags, sizeof(info->flags), errp) < 0) {
error_prepend(errp, "Failed to read export flags");
be16_to_cpus(&info->flags);
} else if (magic == NBD_CLIENT_MAGIC) {
uint32_t oldflags;
if (name) {
error_setg(errp, "Server does not support export names");
if (tlscreds) {
error_setg(errp, "Server does not support STARTTLS");
if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) {
error_prepend(errp, "Failed to read export length");
be64_to_cpus(&info->size);
if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
error_prepend(errp, "Failed to read export flags");
be32_to_cpus(&oldflags);
if (oldflags & ~0xffff) {
error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags);
info->flags = oldflags;
} else {
error_setg(errp, "Bad magic received");
trace_nbd_receive_negotiate_size_flags(info->size, info->flags);
if (zeroes && nbd_drop(ioc, 124, errp) < 0) {
error_prepend(errp, "Failed to read reserved block");
rc = 0;
fail:
return rc; | true | qemu | f140e3000371e67ff4e00df3213e2d576d9c91be |
8,351 | static int get_codec_data(AVIOContext *pb, AVStream *vst,
AVStream *ast, int myth)
{
nuv_frametype frametype;
if (!vst && !myth)
return 1; // no codec data needed
while (!pb->eof_reached) {
int size, subtype;
frametype = avio_r8(pb);
switch (frametype) {
case NUV_EXTRADATA:
subtype = avio_r8(pb);
avio_skip(pb, 6);
size = PKTSIZE(avio_rl32(pb));
if (vst && subtype == 'R') {
vst->codec->extradata_size = size;
vst->codec->extradata = av_malloc(size);
avio_read(pb, vst->codec->extradata, size);
size = 0;
if (!myth)
return 1;
}
break;
case NUV_MYTHEXT:
avio_skip(pb, 7);
size = PKTSIZE(avio_rl32(pb));
if (size != 128 * 4)
break;
avio_rl32(pb); // version
if (vst) {
vst->codec->codec_tag = avio_rl32(pb);
vst->codec->codec_id =
ff_codec_get_id(ff_codec_bmp_tags, vst->codec->codec_tag);
if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G'))
vst->codec->codec_id = AV_CODEC_ID_NUV;
} else
avio_skip(pb, 4);
if (ast) {
int id;
ast->codec->codec_tag = avio_rl32(pb);
ast->codec->sample_rate = avio_rl32(pb);
ast->codec->bits_per_coded_sample = avio_rl32(pb);
ast->codec->channels = avio_rl32(pb);
ast->codec->channel_layout = 0;
id = ff_wav_codec_get_id(ast->codec->codec_tag,
ast->codec->bits_per_coded_sample);
if (id == AV_CODEC_ID_NONE) {
id = ff_codec_get_id(nuv_audio_tags, ast->codec->codec_tag);
if (id == AV_CODEC_ID_PCM_S16LE)
id = ff_get_pcm_codec_id(ast->codec->bits_per_coded_sample,
0, 0, ~1);
}
ast->codec->codec_id = id;
ast->need_parsing = AVSTREAM_PARSE_FULL;
} else
avio_skip(pb, 4 * 4);
size -= 6 * 4;
avio_skip(pb, size);
return 1;
case NUV_SEEKP:
size = 11;
break;
default:
avio_skip(pb, 7);
size = PKTSIZE(avio_rl32(pb));
break;
}
avio_skip(pb, size);
}
return 0;
}
| true | FFmpeg | ab87d9b6677c5757d467f532e681b056d3e77e6b |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.