project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
FFmpeg | 0b42631641d998e509cde6fa344edc6ab5cb4ac8 | 0 | static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
uint8_t *properties)
{
int compno;
if (s->buf_end - s->buf < 1)
return AVERROR(EINVAL);
compno = bytestream_get_byte(&s->buf);
properties[compno] |= HAD_QCC;
return get_qcx(s, n - 1, q + compno);
}
| 11,575 |
FFmpeg | eabbc64728c2fdb74f565aededec2ab023d20699 | 0 | static int mkv_write_tracks(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *dyn_cp, *pb = s->pb;
ebml_master tracks;
int i, ret, default_stream_exists = 0;
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));
if (ret < 0)
return ret;
ret = start_ebml_master_crc32(pb, &dyn_cp, &tracks, MATROSKA_ID_TRACKS, 0);
if (ret < 0)
return ret;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
}
for (i = 0; i < s->nb_streams; i++) {
ret = mkv_write_track(s, mkv, i, dyn_cp, default_stream_exists);
if (ret < 0)
return ret;
}
end_ebml_master_crc32(pb, &dyn_cp, mkv, tracks);
return 0;
}
| 11,576 |
qemu | c572f23a3e7180dbeab5e86583e43ea2afed6271 | 1 | static void v9fs_stat(void *opaque)
{
int32_t fid;
V9fsStat v9stat;
ssize_t err = 0;
size_t offset = 7;
struct stat stbuf;
V9fsFidState *fidp;
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
pdu_unmarshal(pdu, offset, "d", &fid);
fidp = get_fid(pdu, fid);
if (fidp == NULL) {
err = -ENOENT;
goto out_nofid;
}
err = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
if (err < 0) {
goto out;
}
err = stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat);
if (err < 0) {
goto out;
}
offset += pdu_marshal(pdu, offset, "wS", 0, &v9stat);
err = offset;
v9fs_stat_free(&v9stat);
out:
put_fid(pdu, fidp);
out_nofid:
trace_v9fs_stat_return(pdu->tag, pdu->id, v9stat.mode,
v9stat.atime, v9stat.mtime, v9stat.length);
complete_pdu(s, pdu, err);
} | 11,577 |
FFmpeg | b711aaa2d8035b8a14bbdf0315cf2cea48dee890 | 1 | static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al){
int i, mb_x, mb_y;
uint8_t* data[MAX_COMPONENTS];
int linesize[MAX_COMPONENTS];
for(i=0; i < nb_components; i++) {
int c = s->comp_index[i];
data[c] = s->picture.data[c];
linesize[c]=s->linesize[c];
s->coefs_finished[c] |= 1;
if(s->flipped) {
//picture should be flipped upside-down for this codec
assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE));
data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 ));
linesize[c] *= -1;
}
}
for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
if (s->restart_interval && !s->restart_count)
s->restart_count = s->restart_interval;
for(i=0;i<nb_components;i++) {
uint8_t *ptr;
int n, h, v, x, y, c, j;
n = s->nb_blocks[i];
c = s->comp_index[i];
h = s->h_scount[i];
v = s->v_scount[i];
x = 0;
y = 0;
for(j=0;j<n;j++) {
ptr = data[c] +
(((linesize[c] * (v * mb_y + y) * 8) +
(h * mb_x + x) * 8) >> s->avctx->lowres);
if(s->interlaced && s->bottom_field)
ptr += linesize[c] >> 1;
if(!s->progressive) {
s->dsp.clear_block(s->block);
if(decode_block(s, s->block, i,
s->dc_index[i], s->ac_index[i],
s->quant_matrixes[ s->quant_index[c] ]) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
return -1;
}
s->dsp.idct_put(ptr, linesize[c], s->block);
} else {
int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x);
DCTELEM *block = s->blocks[c][block_idx];
if(Ah)
block[0] += get_bits1(&s->gb) * s->quant_matrixes[ s->quant_index[c] ][0] << Al;
else if(decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[ s->quant_index[c] ], Al) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
return -1;
}
}
// av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x);
//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
if (++x == h) {
x = 0;
y++;
}
}
}
if (s->restart_interval && !--s->restart_count) {
align_get_bits(&s->gb);
skip_bits(&s->gb, 16); /* skip RSTn */
for (i=0; i<nb_components; i++) /* reset dc */
s->last_dc[i] = 1024;
}
}
}
return 0;
}
| 11,578 |
FFmpeg | d2101bffa0f2221586e3e7eacfecf47d5c29f2c4 | 0 | static double eval_expr(Parser *p, AVExpr *e)
{
switch (e->type) {
case e_value: return e->value;
case e_const: return e->value * p->const_values[e->a.const_index];
case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0]));
case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);
case e_if: return e->value * ( eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
case e_ifnot: return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
case e_random:{
int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
r= r*1664525+1013904223;
p->var[idx]= r;
return e->value * (r * (1.0/UINT64_MAX));
}
case e_while: {
double d = NAN;
while (eval_expr(p, e->param[0]))
d=eval_expr(p, e->param[1]);
return d;
}
case e_taylor: {
double t = 1, d = 0, v;
double x = eval_expr(p, e->param[1]);
int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, VARS-1) : 0;
int i;
double var0 = p->var[id];
for(i=0; i<1000; i++) {
double ld = d;
p->var[id] = i;
v = eval_expr(p, e->param[0]);
d += t*v;
if(ld==d && v)
break;
t *= x / (i+1);
}
p->var[id] = var0;
return d;
}
case e_root: {
int i;
double low = -1, high = -1, v, low_v = -DBL_MAX, high_v = DBL_MAX;
double var0 = p->var[0];
double x_max = eval_expr(p, e->param[1]);
for(i=-1; i<1024; i++) {
if(i<255) {
p->var[0] = av_reverse[i&255]*x_max/255;
} else {
p->var[0] = x_max*pow(0.9, i-255);
if (i&1) p->var[0] *= -1;
if (i&2) p->var[0] += low;
else p->var[0] += high;
}
v = eval_expr(p, e->param[0]);
if (v<=0 && v>low_v) {
low = p->var[0];
low_v = v;
}
if (v>=0 && v<high_v) {
high = p->var[0];
high_v = v;
}
if (low>=0 && high>=0){
while (1) {
p->var[0] = (low+high)*0.5;
if (low == p->var[0] || high == p->var[0])
break;
v = eval_expr(p, e->param[0]);
if (v<=0) low = p->var[0];
if (v>=0) high= p->var[0];
if (isnan(v)) {
low = high = v;
break;
}
}
break;
}
}
p->var[0] = var0;
return -low_v<high_v ? low : high;
}
default: {
double d = eval_expr(p, e->param[0]);
double d2 = eval_expr(p, e->param[1]);
switch (e->type) {
case e_mod: return e->value * (d - floor(d/d2)*d2);
case e_gcd: return e->value * av_gcd(d,d2);
case e_max: return e->value * (d > d2 ? d : d2);
case e_min: return e->value * (d < d2 ? d : d2);
case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
case e_pow: return e->value * pow(d, d2);
case e_mul: return e->value * (d * d2);
case e_div: return e->value * (d / d2);
case e_add: return e->value * (d + d2);
case e_last:return e->value * d2;
case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
case e_hypot:return e->value * (sqrt(d*d + d2*d2));
}
}
}
return NAN;
}
| 11,579 |
FFmpeg | 9b26bf7e2a3904d0e4b80f8d771223d3045013db | 1 | static int deband_16_coupling_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
DebandContext *s = ctx->priv;
ThreadData *td = arg;
AVFrame *in = td->in;
AVFrame *out = td->out;
const int start = (s->planeheight[0] * jobnr ) / nb_jobs;
const int end = (s->planeheight[0] * (jobnr+1)) / nb_jobs;
int x, y, p, z;
for (y = start; y < end; y++) {
const int pos = y * s->planewidth[0];
for (x = 0; x < s->planewidth[p]; x++) {
const int x_pos = s->x_pos[pos + x];
const int y_pos = s->y_pos[pos + x];
int avg[4], cmp[4] = { 0 }, src[4];
for (p = 0; p < s->nb_components; p++) {
const uint16_t *src_ptr = (const uint16_t *)in->data[p];
const int src_linesize = in->linesize[p] / 2;
const int thr = s->thr[p];
const int w = s->planewidth[p] - 1;
const int h = s->planeheight[p] - 1;
const int ref0 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)];
const int ref1 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + x_pos, 0, w)];
const int ref2 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)];
const int ref3 = src_ptr[av_clip(y + y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)];
const int src0 = src_ptr[y * src_linesize + x];
src[p] = src0;
avg[p] = get_avg(ref0, ref1, ref2, ref3);
if (s->blur) {
cmp[p] = FFABS(src0 - avg[p]) < thr;
} else {
cmp[p] = (FFABS(src0 - ref0) < thr) &&
(FFABS(src0 - ref1) < thr) &&
(FFABS(src0 - ref2) < thr) &&
(FFABS(src0 - ref3) < thr);
}
}
for (z = 0; z < s->nb_components; z++)
if (!cmp[z])
break;
if (z == s->nb_components) {
for (p = 0; p < s->nb_components; p++) {
const int dst_linesize = out->linesize[p] / 2;
uint16_t *dst = (uint16_t *)out->data[p] + y * dst_linesize + x;
dst[0] = avg[p];
}
} else {
for (p = 0; p < s->nb_components; p++) {
const int dst_linesize = out->linesize[p] / 2;
uint16_t *dst = (uint16_t *)out->data[p] + y * dst_linesize + x;
dst[0] = src[p];
}
}
}
}
return 0;
}
| 11,580 |
FFmpeg | edcc51fb8e15b704955d742559215697598927bb | 1 | static int tiff_decode_tag(TiffContext *s)
{
unsigned tag, type, count, off, value = 0;
int i, j, k, pos, start;
int ret;
uint32_t *pal;
double *dp;
tag = tget_short(&s->gb, s->le);
type = tget_short(&s->gb, s->le);
count = tget_long(&s->gb, s->le);
off = tget_long(&s->gb, s->le);
start = bytestream2_tell(&s->gb);
if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
type);
return 0;
}
if (count == 1) {
switch (type) {
case TIFF_BYTE:
case TIFF_SHORT:
bytestream2_seek(&s->gb, -4, SEEK_CUR);
value = tget(&s->gb, type, s->le);
break;
case TIFF_LONG:
value = off;
break;
case TIFF_STRING:
if (count <= 4) {
bytestream2_seek(&s->gb, -4, SEEK_CUR);
break;
}
default:
value = UINT_MAX;
bytestream2_seek(&s->gb, off, SEEK_SET);
}
} else {
if (count <= 4 && type_sizes[type] * count <= 4) {
bytestream2_seek(&s->gb, -4, SEEK_CUR);
} else {
bytestream2_seek(&s->gb, off, SEEK_SET);
}
}
switch (tag) {
case TIFF_WIDTH:
s->width = value;
break;
case TIFF_HEIGHT:
s->height = value;
break;
case TIFF_BPP:
s->bppcount = count;
if (count > 4) {
av_log(s->avctx, AV_LOG_ERROR,
"This format is not supported (bpp=%d, %d components)\n",
s->bpp, count);
return AVERROR_INVALIDDATA;
}
if (count == 1)
s->bpp = value;
else {
switch (type) {
case TIFF_BYTE:
s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
break;
case TIFF_SHORT:
case TIFF_LONG:
s->bpp = 0;
if (bytestream2_get_bytes_left(&s->gb) < type_sizes[type] * count)
return AVERROR_INVALIDDATA;
for (i = 0; i < count; i++)
s->bpp += tget(&s->gb, type, s->le);
break;
default:
s->bpp = -1;
}
}
break;
case TIFF_SAMPLES_PER_PIXEL:
if (count != 1) {
av_log(s->avctx, AV_LOG_ERROR,
"Samples per pixel requires a single value, many provided\n");
return AVERROR_INVALIDDATA;
}
if (value > 4U) {
av_log(s->avctx, AV_LOG_ERROR,
"Samples per pixel %d is too large\n", value);
return AVERROR_INVALIDDATA;
}
if (s->bppcount == 1)
s->bpp *= value;
s->bppcount = value;
break;
case TIFF_COMPR:
s->compr = value;
s->predictor = 0;
switch (s->compr) {
case TIFF_RAW:
case TIFF_PACKBITS:
case TIFF_LZW:
case TIFF_CCITT_RLE:
break;
case TIFF_G3:
case TIFF_G4:
s->fax_opts = 0;
break;
case TIFF_DEFLATE:
case TIFF_ADOBE_DEFLATE:
#if CONFIG_ZLIB
break;
#else
av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
return AVERROR(ENOSYS);
#endif
case TIFF_JPEG:
case TIFF_NEWJPEG:
av_log(s->avctx, AV_LOG_ERROR,
"JPEG compression is not supported\n");
return AVERROR_PATCHWELCOME;
default:
av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
s->compr);
return AVERROR_INVALIDDATA;
}
break;
case TIFF_ROWSPERSTRIP:
if (type == TIFF_LONG && value == UINT_MAX)
value = s->height;
if (value < 1) {
av_log(s->avctx, AV_LOG_ERROR,
"Incorrect value of rows per strip\n");
return AVERROR_INVALIDDATA;
}
s->rps = value;
break;
case TIFF_STRIP_OFFS:
if (count == 1) {
s->strippos = 0;
s->stripoff = value;
} else
s->strippos = off;
s->strips = count;
if (s->strips == 1)
s->rps = s->height;
s->sot = type;
if (s->strippos > bytestream2_size(&s->gb)) {
av_log(s->avctx, AV_LOG_ERROR,
"Tag referencing position outside the image\n");
return AVERROR_INVALIDDATA;
}
break;
case TIFF_STRIP_SIZE:
if (count == 1) {
s->stripsizesoff = 0;
s->stripsize = value;
s->strips = 1;
} else {
s->stripsizesoff = off;
}
s->strips = count;
s->sstype = type;
if (s->stripsizesoff > bytestream2_size(&s->gb)) {
av_log(s->avctx, AV_LOG_ERROR,
"Tag referencing position outside the image\n");
return AVERROR_INVALIDDATA;
}
break;
case TIFF_TILE_BYTE_COUNTS:
case TIFF_TILE_LENGTH:
case TIFF_TILE_OFFSETS:
case TIFF_TILE_WIDTH:
av_log(s->avctx, AV_LOG_ERROR, "Tiled images are not supported\n");
return AVERROR_PATCHWELCOME;
break;
case TIFF_PREDICTOR:
s->predictor = value;
break;
case TIFF_INVERT:
switch (value) {
case 0:
s->invert = 1;
break;
case 1:
s->invert = 0;
break;
case 2:
case 3:
break;
default:
av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
value);
return AVERROR_INVALIDDATA;
}
break;
case TIFF_FILL_ORDER:
if (value < 1 || value > 2) {
av_log(s->avctx, AV_LOG_ERROR,
"Unknown FillOrder value %d, trying default one\n", value);
value = 1;
}
s->fill_order = value - 1;
break;
case TIFF_PAL:
pal = (uint32_t *) s->palette;
off = type_sizes[type];
if (count / 3 > 256 || bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
return AVERROR_INVALIDDATA;
off = (type_sizes[type] - 1) << 3;
for (k = 2; k >= 0; k--) {
for (i = 0; i < count / 3; i++) {
if (k == 2)
pal[i] = 0xFFU << 24;
j = (tget(&s->gb, type, s->le) >> off) << (k * 8);
pal[i] |= j;
}
}
s->palette_is_set = 1;
break;
case TIFF_PLANAR:
if (value == 2) {
av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
return AVERROR_PATCHWELCOME;
}
break;
case TIFF_T4OPTIONS:
if (s->compr == TIFF_G3)
s->fax_opts = value;
break;
case TIFF_T6OPTIONS:
if (s->compr == TIFF_G4)
s->fax_opts = value;
break;
#define ADD_METADATA(count, name, sep)\
if ((ret = add_metadata(count, type, name, sep, s)) < 0) {\
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
return ret;\
}
case TIFF_MODEL_PIXEL_SCALE:
ADD_METADATA(count, "ModelPixelScaleTag", NULL);
break;
case TIFF_MODEL_TRANSFORMATION:
ADD_METADATA(count, "ModelTransformationTag", NULL);
break;
case TIFF_MODEL_TIEPOINT:
ADD_METADATA(count, "ModelTiepointTag", NULL);
break;
case TIFF_GEO_KEY_DIRECTORY:
ADD_METADATA(1, "GeoTIFF_Version", NULL);
ADD_METADATA(2, "GeoTIFF_Key_Revision", ".");
s->geotag_count = tget_short(&s->gb, s->le);
if (s->geotag_count > count / 4 - 1) {
s->geotag_count = count / 4 - 1;
av_log(s->avctx, AV_LOG_WARNING, "GeoTIFF key directory buffer shorter than specified\n");
}
if (bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4) {
s->geotag_count = 0;
return -1;
}
s->geotags = av_mallocz(sizeof(TiffGeoTag) * s->geotag_count);
if (!s->geotags) {
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
s->geotag_count = 0;
return AVERROR(ENOMEM);
}
for (i = 0; i < s->geotag_count; i++) {
s->geotags[i].key = tget_short(&s->gb, s->le);
s->geotags[i].type = tget_short(&s->gb, s->le);
s->geotags[i].count = tget_short(&s->gb, s->le);
if (!s->geotags[i].type)
s->geotags[i].val = get_geokey_val(s->geotags[i].key, tget_short(&s->gb, s->le));
else
s->geotags[i].offset = tget_short(&s->gb, s->le);
}
break;
case TIFF_GEO_DOUBLE_PARAMS:
if (count >= INT_MAX / sizeof(int64_t))
return AVERROR_INVALIDDATA;
if (bytestream2_get_bytes_left(&s->gb) < count * sizeof(int64_t))
return AVERROR_INVALIDDATA;
dp = av_malloc(count * sizeof(double));
if (!dp) {
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
return AVERROR(ENOMEM);
}
for (i = 0; i < count; i++)
dp[i] = tget_double(&s->gb, s->le);
for (i = 0; i < s->geotag_count; i++) {
if (s->geotags[i].type == TIFF_GEO_DOUBLE_PARAMS) {
if (s->geotags[i].count == 0
|| s->geotags[i].offset + s->geotags[i].count > count) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
} else {
char *ap = doubles2str(&dp[s->geotags[i].offset], s->geotags[i].count, ", ");
if (!ap) {
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
av_freep(&dp);
return AVERROR(ENOMEM);
}
s->geotags[i].val = ap;
}
}
}
av_freep(&dp);
break;
case TIFF_GEO_ASCII_PARAMS:
pos = bytestream2_tell(&s->gb);
for (i = 0; i < s->geotag_count; i++) {
if (s->geotags[i].type == TIFF_GEO_ASCII_PARAMS) {
if (s->geotags[i].count == 0
|| s->geotags[i].offset + s->geotags[i].count > count) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
} else {
char *ap;
bytestream2_seek(&s->gb, pos + s->geotags[i].offset, SEEK_SET);
if (bytestream2_get_bytes_left(&s->gb) < s->geotags[i].count)
return AVERROR_INVALIDDATA;
ap = av_malloc(s->geotags[i].count);
if (!ap) {
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
return AVERROR(ENOMEM);
}
bytestream2_get_bufferu(&s->gb, ap, s->geotags[i].count);
ap[s->geotags[i].count - 1] = '\0'; //replace the "|" delimiter with a 0 byte
s->geotags[i].val = ap;
}
}
}
break;
case TIFF_ARTIST:
ADD_METADATA(count, "artist", NULL);
break;
case TIFF_COPYRIGHT:
ADD_METADATA(count, "copyright", NULL);
break;
case TIFF_DATE:
ADD_METADATA(count, "date", NULL);
break;
case TIFF_DOCUMENT_NAME:
ADD_METADATA(count, "document_name", NULL);
break;
case TIFF_HOST_COMPUTER:
ADD_METADATA(count, "computer", NULL);
break;
case TIFF_IMAGE_DESCRIPTION:
ADD_METADATA(count, "description", NULL);
break;
case TIFF_MAKE:
ADD_METADATA(count, "make", NULL);
break;
case TIFF_MODEL:
ADD_METADATA(count, "model", NULL);
break;
case TIFF_PAGE_NAME:
ADD_METADATA(count, "page_name", NULL);
break;
case TIFF_PAGE_NUMBER:
ADD_METADATA(count, "page_number", " / ");
break;
case TIFF_SOFTWARE_NAME:
ADD_METADATA(count, "software", NULL);
break;
default:
av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
tag, tag);
}
bytestream2_seek(&s->gb, start, SEEK_SET);
return 0;
}
| 11,581 |
FFmpeg | 7d88586e4728e97349f98e07ff782bb168ab96c3 | 1 | static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
int16_t *src2,
int height, int denom, int wx0, int wx1,
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
{
int x, y;
pixel *src = (pixel *)_src;
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
const int8_t *filter = ff_hevc_epel_filters[my - 1];
pixel *dst = (pixel *)_dst;
ptrdiff_t dststride = _dststride / sizeof(pixel);
int shift = 14 + 1 - BIT_DEPTH;
int log2Wd = denom + shift - 1;
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++)
dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
src += srcstride;
dst += dststride;
src2 += MAX_PB_SIZE;
}
}
| 11,582 |
qemu | 8be7e7e4c72c048b90e3482557954a24bba43ba7 | 1 | DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
{
const char *buf;
const char *file = NULL;
char devname[128];
const char *serial;
const char *mediastr = "";
BlockInterfaceType type;
enum { MEDIA_DISK, MEDIA_CDROM } media;
int bus_id, unit_id;
int cyls, heads, secs, translation;
BlockDriver *drv = NULL;
int max_devs;
int index;
int ro = 0;
int bdrv_flags = 0;
int on_read_error, on_write_error;
const char *devaddr;
DriveInfo *dinfo;
BlockIOLimit io_limits;
int snapshot = 0;
bool copy_on_read;
int ret;
translation = BIOS_ATA_TRANSLATION_AUTO;
media = MEDIA_DISK;
/* extract parameters */
bus_id = qemu_opt_get_number(opts, "bus", 0);
unit_id = qemu_opt_get_number(opts, "unit", -1);
index = qemu_opt_get_number(opts, "index", -1);
cyls = qemu_opt_get_number(opts, "cyls", 0);
heads = qemu_opt_get_number(opts, "heads", 0);
secs = qemu_opt_get_number(opts, "secs", 0);
snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
ro = qemu_opt_get_bool(opts, "readonly", 0);
copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
file = qemu_opt_get(opts, "file");
serial = qemu_opt_get(opts, "serial");
if ((buf = qemu_opt_get(opts, "if")) != NULL) {
pstrcpy(devname, sizeof(devname), buf);
for (type = 0; type < IF_COUNT && strcmp(buf, if_name[type]); type++)
;
if (type == IF_COUNT) {
error_report("unsupported bus type '%s'", buf);
return NULL;
}
} else {
type = default_to_scsi ? IF_SCSI : IF_IDE;
pstrcpy(devname, sizeof(devname), if_name[type]);
}
max_devs = if_max_devs[type];
if (cyls || heads || secs) {
if (cyls < 1 || (type == IF_IDE && cyls > 16383)) {
error_report("invalid physical cyls number");
return NULL;
}
if (heads < 1 || (type == IF_IDE && heads > 16)) {
error_report("invalid physical heads number");
return NULL;
}
if (secs < 1 || (type == IF_IDE && secs > 63)) {
error_report("invalid physical secs number");
return NULL;
}
}
if ((buf = qemu_opt_get(opts, "trans")) != NULL) {
if (!cyls) {
error_report("'%s' trans must be used with cyls, heads and secs",
buf);
return NULL;
}
if (!strcmp(buf, "none"))
translation = BIOS_ATA_TRANSLATION_NONE;
else if (!strcmp(buf, "lba"))
translation = BIOS_ATA_TRANSLATION_LBA;
else if (!strcmp(buf, "auto"))
translation = BIOS_ATA_TRANSLATION_AUTO;
else {
error_report("'%s' invalid translation type", buf);
return NULL;
}
}
if ((buf = qemu_opt_get(opts, "media")) != NULL) {
if (!strcmp(buf, "disk")) {
media = MEDIA_DISK;
} else if (!strcmp(buf, "cdrom")) {
if (cyls || secs || heads) {
error_report("CHS can't be set with media=%s", buf);
return NULL;
}
media = MEDIA_CDROM;
} else {
error_report("'%s' invalid media", buf);
return NULL;
}
}
if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
if (bdrv_parse_cache_flags(buf, &bdrv_flags) != 0) {
error_report("invalid cache option");
return NULL;
}
}
#ifdef CONFIG_LINUX_AIO
if ((buf = qemu_opt_get(opts, "aio")) != NULL) {
if (!strcmp(buf, "native")) {
bdrv_flags |= BDRV_O_NATIVE_AIO;
} else if (!strcmp(buf, "threads")) {
/* this is the default */
} else {
error_report("invalid aio option");
return NULL;
}
}
#endif
if ((buf = qemu_opt_get(opts, "format")) != NULL) {
if (strcmp(buf, "?") == 0) {
error_printf("Supported formats:");
bdrv_iterate_format(bdrv_format_print, NULL);
error_printf("\n");
return NULL;
}
drv = bdrv_find_whitelisted_format(buf);
if (!drv) {
error_report("'%s' invalid format", buf);
return NULL;
}
}
/* disk I/O throttling */
io_limits.bps[BLOCK_IO_LIMIT_TOTAL] =
qemu_opt_get_number(opts, "bps", 0);
io_limits.bps[BLOCK_IO_LIMIT_READ] =
qemu_opt_get_number(opts, "bps_rd", 0);
io_limits.bps[BLOCK_IO_LIMIT_WRITE] =
qemu_opt_get_number(opts, "bps_wr", 0);
io_limits.iops[BLOCK_IO_LIMIT_TOTAL] =
qemu_opt_get_number(opts, "iops", 0);
io_limits.iops[BLOCK_IO_LIMIT_READ] =
qemu_opt_get_number(opts, "iops_rd", 0);
io_limits.iops[BLOCK_IO_LIMIT_WRITE] =
qemu_opt_get_number(opts, "iops_wr", 0);
if (!do_check_io_limits(&io_limits)) {
error_report("bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
"cannot be used at the same time");
return NULL;
}
on_write_error = BLOCK_ERR_STOP_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) {
error_report("werror is not supported by this bus type");
return NULL;
}
on_write_error = parse_block_error_action(buf, 0);
if (on_write_error < 0) {
return NULL;
}
}
on_read_error = BLOCK_ERR_REPORT;
if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type != IF_NONE) {
error_report("rerror is not supported by this bus type");
return NULL;
}
on_read_error = parse_block_error_action(buf, 1);
if (on_read_error < 0) {
return NULL;
}
}
if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) {
if (type != IF_VIRTIO) {
error_report("addr is not supported by this bus type");
return NULL;
}
}
/* compute bus and unit according index */
if (index != -1) {
if (bus_id != 0 || unit_id != -1) {
error_report("index cannot be used with bus and unit");
return NULL;
}
bus_id = drive_index_to_bus_id(type, index);
unit_id = drive_index_to_unit_id(type, index);
}
/* if user doesn't specify a unit_id,
* try to find the first free
*/
if (unit_id == -1) {
unit_id = 0;
while (drive_get(type, bus_id, unit_id) != NULL) {
unit_id++;
if (max_devs && unit_id >= max_devs) {
unit_id -= max_devs;
bus_id++;
}
}
}
/* check unit id */
if (max_devs && unit_id >= max_devs) {
error_report("unit %d too big (max is %d)",
unit_id, max_devs - 1);
return NULL;
}
/*
* catch multiple definitions
*/
if (drive_get(type, bus_id, unit_id) != NULL) {
error_report("drive with bus=%d, unit=%d (index=%d) exists",
bus_id, unit_id, index);
return NULL;
}
/* init */
dinfo = g_malloc0(sizeof(*dinfo));
if ((buf = qemu_opts_id(opts)) != NULL) {
dinfo->id = g_strdup(buf);
} else {
/* no id supplied -> create one */
dinfo->id = g_malloc0(32);
if (type == IF_IDE || type == IF_SCSI)
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
if (max_devs)
snprintf(dinfo->id, 32, "%s%i%s%i",
devname, bus_id, mediastr, unit_id);
else
snprintf(dinfo->id, 32, "%s%s%i",
devname, mediastr, unit_id);
}
dinfo->bdrv = bdrv_new(dinfo->id);
dinfo->devaddr = devaddr;
dinfo->type = type;
dinfo->bus = bus_id;
dinfo->unit = unit_id;
dinfo->opts = opts;
dinfo->refcount = 1;
if (serial) {
pstrcpy(dinfo->serial, sizeof(dinfo->serial), serial);
}
QTAILQ_INSERT_TAIL(&drives, dinfo, next);
bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error);
/* disk I/O throttling */
bdrv_set_io_limits(dinfo->bdrv, &io_limits);
switch(type) {
case IF_IDE:
case IF_SCSI:
case IF_XEN:
case IF_NONE:
switch(media) {
case MEDIA_DISK:
if (cyls != 0) {
bdrv_set_geometry_hint(dinfo->bdrv, cyls, heads, secs);
bdrv_set_translation_hint(dinfo->bdrv, translation);
}
break;
case MEDIA_CDROM:
dinfo->media_cd = 1;
break;
}
break;
case IF_SD:
case IF_FLOPPY:
case IF_PFLASH:
case IF_MTD:
break;
case IF_VIRTIO:
/* add virtio block device */
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
if (arch_type == QEMU_ARCH_S390X) {
qemu_opt_set(opts, "driver", "virtio-blk-s390");
} else {
qemu_opt_set(opts, "driver", "virtio-blk-pci");
}
qemu_opt_set(opts, "drive", dinfo->id);
if (devaddr)
qemu_opt_set(opts, "addr", devaddr);
break;
default:
abort();
}
if (!file || !*file) {
return dinfo;
}
if (snapshot) {
/* always use cache=unsafe with snapshot */
bdrv_flags &= ~BDRV_O_CACHE_MASK;
bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH);
}
if (copy_on_read) {
bdrv_flags |= BDRV_O_COPY_ON_READ;
}
if (runstate_check(RUN_STATE_INMIGRATE)) {
bdrv_flags |= BDRV_O_INCOMING;
}
if (media == MEDIA_CDROM) {
/* CDROM is fine for any interface, don't check. */
ro = 1;
} else if (ro == 1) {
if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
type != IF_NONE && type != IF_PFLASH) {
error_report("readonly not supported by this bus type");
goto err;
}
}
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
ret = bdrv_open(dinfo->bdrv, file, bdrv_flags, drv);
if (ret < 0) {
error_report("could not open disk image %s: %s",
file, strerror(-ret));
goto err;
}
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
return dinfo;
err:
bdrv_delete(dinfo->bdrv);
g_free(dinfo->id);
QTAILQ_REMOVE(&drives, dinfo, next);
g_free(dinfo);
return NULL;
}
| 11,583 |
qemu | 1e7398a140f7a6bd9f5a438e7ad0f1ef50990e25 | 1 | bool vhost_net_query(VHostNetState *net, VirtIODevice *dev)
{
return false;
}
| 11,584 |
FFmpeg | bb99ae3ae924c942a634bec7711ec7ee11c38eb9 | 1 | static int init_input(AVFormatContext *s, const char *filename)
{
int ret;
AVProbeData pd = {filename, NULL, 0};
if (s->pb) {
s->flags |= AVFMT_FLAG_CUSTOM_IO;
if (!s->iformat)
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
else if (s->iformat->flags & AVFMT_NOFILE)
av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
"will be ignored with AVFMT_NOFILE format.\n");
}
if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
(!s->iformat && (s->iformat = av_probe_input_format(&pd, 0))))
if ((ret = avio_open(&s->pb, filename, AVIO_FLAG_READ)) < 0)
return ret;
if (s->iformat)
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
} | 11,585 |
qemu | b946a1533209f61a93e34898aebb5b43154b99c3 | 1 | void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
qemu_irq *irq, target_phys_addr_t base, int phyaddr)
{
struct etraxfs_dma_client *dma = NULL;
struct fs_eth *eth = NULL;
qemu_check_nic_model(nd, "fseth");
dma = qemu_mallocz(sizeof *dma * 2);
eth = qemu_mallocz(sizeof *eth);
dma[0].client.push = eth_tx_push;
dma[0].client.opaque = eth;
dma[1].client.opaque = eth;
dma[1].client.pull = NULL;
eth->env = env;
eth->irq = irq;
eth->dma_out = dma;
eth->dma_in = dma + 1;
/* Connect the phy. */
eth->phyaddr = phyaddr & 0x1f;
tdk_init(ð->phy);
mdio_attach(ð->mdio_bus, ð->phy, eth->phyaddr);
eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
cpu_register_physical_memory (base, 0x5c, eth->ethregs);
eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
eth_receive, eth_can_receive, eth);
eth->vc->opaque = eth;
eth->vc->link_status_changed = eth_set_link;
return dma;
}
| 11,586 |
FFmpeg | 0b54f3c0878a3acaa9142e4f24942e762d97e350 | 1 | static int gif_read_extension(GifState *s)
{
ByteIOContext *f = s->f;
int ext_code, ext_len, i, gce_flags, gce_transparent_index;
/* extension */
ext_code = get_byte(f);
ext_len = get_byte(f);
#ifdef DEBUG
printf("gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
#endif
switch(ext_code) {
case 0xf9:
if (ext_len != 4)
goto discard_ext;
s->transparent_color_index = -1;
gce_flags = get_byte(f);
s->gce_delay = get_le16(f);
gce_transparent_index = get_byte(f);
if (gce_flags & 0x01)
s->transparent_color_index = gce_transparent_index;
else
s->transparent_color_index = -1;
s->gce_disposal = (gce_flags >> 2) & 0x7;
#ifdef DEBUG
printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
gce_flags, s->gce_delay,
s->transparent_color_index, s->gce_disposal);
#endif
ext_len = get_byte(f);
break;
}
/* NOTE: many extension blocks can come after */
discard_ext:
while (ext_len != 0) {
for (i = 0; i < ext_len; i++)
get_byte(f);
ext_len = get_byte(f);
#ifdef DEBUG
printf("gif: ext_len1=%d\n", ext_len);
#endif
}
return 0;
}
| 11,587 |
FFmpeg | 6e42e6c4b410dbef8b593c2d796a5dad95f89ee4 | 1 | altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) {
register int i;
vector unsigned int altivec_vectorShiftInt19 =
vec_add(vec_splat_u32(10),vec_splat_u32(9));
if ((unsigned long)dest % 16) {
/* badly aligned store, we force store alignement */
/* and will handle load misalignement on val w/ vec_perm */
vector unsigned char perm1;
vector signed int v1;
for (i = 0 ; (i < dstW) &&
(((unsigned long)dest + i) % 16) ; i++) {
int t = val[i] >> 19;
dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
}
perm1 = vec_lvsl(i << 2, val);
v1 = vec_ld(i << 2, val);
for ( ; i < (dstW - 15); i+=16) {
int offset = i << 2;
vector signed int v2 = vec_ld(offset + 16, val);
vector signed int v3 = vec_ld(offset + 32, val);
vector signed int v4 = vec_ld(offset + 48, val);
vector signed int v5 = vec_ld(offset + 64, val);
vector signed int v12 = vec_perm(v1,v2,perm1);
vector signed int v23 = vec_perm(v2,v3,perm1);
vector signed int v34 = vec_perm(v3,v4,perm1);
vector signed int v45 = vec_perm(v4,v5,perm1);
vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19);
vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19);
vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19);
vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19);
vector unsigned short vs1 = vec_packsu(vA, vB);
vector unsigned short vs2 = vec_packsu(vC, vD);
vector unsigned char vf = vec_packsu(vs1, vs2);
vec_st(vf, i, dest);
v1 = v5;
}
} else { // dest is properly aligned, great
for (i = 0; i < (dstW - 15); i+=16) {
int offset = i << 2;
vector signed int v1 = vec_ld(offset, val);
vector signed int v2 = vec_ld(offset + 16, val);
vector signed int v3 = vec_ld(offset + 32, val);
vector signed int v4 = vec_ld(offset + 48, val);
vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19);
vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19);
vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19);
vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19);
vector unsigned short vs1 = vec_packsu(v5, v6);
vector unsigned short vs2 = vec_packsu(v7, v8);
vector unsigned char vf = vec_packsu(vs1, vs2);
vec_st(vf, i, dest);
}
}
for ( ; i < dstW ; i++) {
int t = val[i] >> 19;
dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
}
}
| 11,588 |
qemu | 0560b0e97df3da43651158c799c6d889f27529c3 | 1 | static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
{
VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
/*
* virtio pci bar layout used by default.
* subclasses can re-arrange things if needed.
*
* region 0 -- virtio legacy io bar
* region 1 -- msi-x bar
* region 4+5 -- virtio modern memory (64bit) bar
*
*/
proxy->legacy_io_bar = 0;
proxy->msix_bar = 1;
proxy->modern_io_bar = 2;
proxy->modern_mem_bar = 4;
proxy->common.offset = 0x0;
proxy->common.size = 0x1000;
proxy->common.type = VIRTIO_PCI_CAP_COMMON_CFG;
proxy->isr.offset = 0x1000;
proxy->isr.size = 0x1000;
proxy->isr.type = VIRTIO_PCI_CAP_ISR_CFG;
proxy->device.offset = 0x2000;
proxy->device.size = 0x1000;
proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG;
proxy->notify.offset = 0x3000;
proxy->notify.size =
QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX;
proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
proxy->notify_pio.offset = 0x0;
proxy->notify_pio.size = 0x4;
proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
/* subclasses can enforce modern, so do this unconditionally */
memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",
2 * QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
VIRTIO_QUEUE_MAX);
memory_region_init_alias(&proxy->modern_cfg,
OBJECT(proxy),
"virtio-pci-cfg",
&proxy->modern_bar,
0,
memory_region_size(&proxy->modern_bar));
address_space_init(&proxy->modern_as, &proxy->modern_cfg, "virtio-pci-cfg-as");
if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE)
&& !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN)
&& pci_bus_is_express(pci_dev->bus)
&& !pci_bus_is_root(pci_dev->bus)) {
int pos;
pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
pos = pcie_endpoint_cap_init(pci_dev, 0);
assert(pos > 0);
pos = pci_add_capability(pci_dev, PCI_CAP_ID_PM, 0, PCI_PM_SIZEOF);
assert(pos > 0);
/*
* Indicates that this function complies with revision 1.2 of the
* PCI Power Management Interface Specification.
*/
pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);
}
virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy);
if (k->realize) {
k->realize(proxy, errp);
}
}
| 11,589 |
FFmpeg | 6ba5cbc699e77cae66bb719354fa142114b64eab | 0 | static HTTPContext *find_rtp_session_with_url(const char *url,
const char *session_id)
{
HTTPContext *rtp_c;
char path1[1024];
const char *path;
char buf[1024];
int s;
rtp_c = find_rtp_session(session_id);
if (!rtp_c)
return NULL;
/* find which url is asked */
url_split(NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);
path = path1;
if (*path == '/')
path++;
if(!strcmp(path, rtp_c->stream->filename)) return rtp_c;
for(s=0; s<rtp_c->stream->nb_streams; ++s) {
snprintf(buf, sizeof(buf), "%s/streamid=%d",
rtp_c->stream->filename, s);
if(!strncmp(path, buf, sizeof(buf))) {
// XXX: Should we reply with RTSP_STATUS_ONLY_AGGREGATE if nb_streams>1?
return rtp_c;
}
}
return NULL;
}
| 11,590 |
FFmpeg | 4bb1070c154e49d35805fbcdac9c9e92f702ef96 | 0 | static void write_header(FFV1Context *f)
{
uint8_t state[CONTEXT_SIZE];
int i, j;
RangeCoder *const c = &f->slice_context[0]->c;
memset(state, 128, sizeof(state));
if (f->version < 2) {
put_symbol(c, state, f->version, 0);
put_symbol(c, state, f->ac, 0);
if (f->ac > 1) {
for (i = 1; i < 256; i++)
put_symbol(c, state,
f->state_transition[i] - c->one_state[i], 1);
}
put_symbol(c, state, f->colorspace, 0); // YUV cs type
if (f->version > 0)
put_symbol(c, state, f->bits_per_raw_sample, 0);
put_rac(c, state, f->chroma_planes);
put_symbol(c, state, f->chroma_h_shift, 0);
put_symbol(c, state, f->chroma_v_shift, 0);
put_rac(c, state, f->transparency);
write_quant_tables(c, f->quant_table);
} else if (f->version < 3) {
put_symbol(c, state, f->slice_count, 0);
for (i = 0; i < f->slice_count; i++) {
FFV1Context *fs = f->slice_context[i];
put_symbol(c, state,
(fs->slice_x + 1) * f->num_h_slices / f->width, 0);
put_symbol(c, state,
(fs->slice_y + 1) * f->num_v_slices / f->height, 0);
put_symbol(c, state,
(fs->slice_width + 1) * f->num_h_slices / f->width - 1,
0);
put_symbol(c, state,
(fs->slice_height + 1) * f->num_v_slices / f->height - 1,
0);
for (j = 0; j < f->plane_count; j++) {
put_symbol(c, state, f->plane[j].quant_table_index, 0);
av_assert0(f->plane[j].quant_table_index == f->avctx->context_model);
}
}
}
}
| 11,591 |
qemu | d34e8f6e9d3a396c3327aa9807c83f9e1f4a7bd7 | 0 | static void __attribute__((constructor)) init_main_loop(void)
{
init_clocks();
init_timer_alarm();
qemu_clock_enable(vm_clock, false);
}
| 11,593 |
FFmpeg | 1ec83d9a9e472f485897ac92bad9631d551a8c5b | 0 | static unsigned tget_long(const uint8_t **p, int le)
{
unsigned v = le ? AV_RL32(*p) : AV_RB32(*p);
*p += 4;
return v;
}
| 11,594 |
qemu | b5a87d26e848945eb891f4d7e4a7f2be514e08d5 | 0 | tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
{
struct ip save_ip, *ip;
register struct tcpiphdr *ti;
caddr_t optp = NULL;
int optlen = 0;
int len, tlen, off;
register struct tcpcb *tp = NULL;
register int tiflags;
struct socket *so = NULL;
int todrop, acked, ourfinisacked, needoutput = 0;
int iss = 0;
u_long tiwin;
int ret;
struct ex_list *ex_ptr;
Slirp *slirp;
DEBUG_CALL("tcp_input");
DEBUG_ARGS((dfd, " m = %8lx iphlen = %2d inso = %lx\n",
(long )m, iphlen, (long )inso ));
/*
* If called with m == 0, then we're continuing the connect
*/
if (m == NULL) {
so = inso;
slirp = so->slirp;
/* Re-set a few variables */
tp = sototcpcb(so);
m = so->so_m;
so->so_m = NULL;
ti = so->so_ti;
tiwin = ti->ti_win;
tiflags = ti->ti_flags;
goto cont_conn;
}
slirp = m->slirp;
/*
* Get IP and TCP header together in first mbuf.
* Note: IP leaves IP header in first mbuf.
*/
ti = mtod(m, struct tcpiphdr *);
if (iphlen > sizeof(struct ip )) {
ip_stripoptions(m, (struct mbuf *)0);
iphlen=sizeof(struct ip );
}
/* XXX Check if too short */
/*
* Save a copy of the IP header in case we want restore it
* for sending an ICMP error message in response.
*/
ip=mtod(m, struct ip *);
save_ip = *ip;
save_ip.ip_len+= iphlen;
/*
* Checksum extended TCP header and data.
*/
tlen = ((struct ip *)ti)->ip_len;
tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL;
memset(&ti->ti_i.ih_mbuf, 0 , sizeof(struct mbuf_ptr));
ti->ti_x1 = 0;
ti->ti_len = htons((uint16_t)tlen);
len = sizeof(struct ip ) + tlen;
if(cksum(m, len)) {
goto drop;
}
/*
* Check that TCP offset makes sense,
* pull out TCP options and adjust length. XXX
*/
off = ti->ti_off << 2;
if (off < sizeof (struct tcphdr) || off > tlen) {
goto drop;
}
tlen -= off;
ti->ti_len = tlen;
if (off > sizeof (struct tcphdr)) {
optlen = off - sizeof (struct tcphdr);
optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
}
tiflags = ti->ti_flags;
/*
* Convert TCP protocol specific fields to host format.
*/
NTOHL(ti->ti_seq);
NTOHL(ti->ti_ack);
NTOHS(ti->ti_win);
NTOHS(ti->ti_urp);
/*
* Drop TCP, IP headers and TCP options.
*/
m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
if (slirp->restricted) {
for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
if (ex_ptr->ex_fport == ti->ti_dport &&
ti->ti_dst.s_addr == ex_ptr->ex_addr.s_addr) {
break;
}
}
if (!ex_ptr)
goto drop;
}
/*
* Locate pcb for segment.
*/
findso:
so = slirp->tcp_last_so;
if (so->so_fport != ti->ti_dport ||
so->so_lport != ti->ti_sport ||
so->so_laddr.s_addr != ti->ti_src.s_addr ||
so->so_faddr.s_addr != ti->ti_dst.s_addr) {
so = solookup(&slirp->tcb, ti->ti_src, ti->ti_sport,
ti->ti_dst, ti->ti_dport);
if (so)
slirp->tcp_last_so = so;
}
/*
* If the state is CLOSED (i.e., TCB does not exist) then
* all data in the incoming segment is discarded.
* If the TCB exists but is in CLOSED state, it is embryonic,
* but should either do a listen or a connect soon.
*
* state == CLOSED means we've done socreate() but haven't
* attached it to a protocol yet...
*
* XXX If a TCB does not exist, and the TH_SYN flag is
* the only flag set, then create a session, mark it
* as if it was LISTENING, and continue...
*/
if (so == NULL) {
if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN)
goto dropwithreset;
if ((so = socreate(slirp)) == NULL)
goto dropwithreset;
if (tcp_attach(so) < 0) {
free(so); /* Not sofree (if it failed, it's not insqued) */
goto dropwithreset;
}
sbreserve(&so->so_snd, TCP_SNDSPACE);
sbreserve(&so->so_rcv, TCP_RCVSPACE);
so->so_laddr = ti->ti_src;
so->so_lport = ti->ti_sport;
so->so_faddr = ti->ti_dst;
so->so_fport = ti->ti_dport;
if ((so->so_iptos = tcp_tos(so)) == 0)
so->so_iptos = ((struct ip *)ti)->ip_tos;
tp = sototcpcb(so);
tp->t_state = TCPS_LISTEN;
}
/*
* If this is a still-connecting socket, this probably
* a retransmit of the SYN. Whether it's a retransmit SYN
* or something else, we nuke it.
*/
if (so->so_state & SS_ISFCONNECTING)
goto drop;
tp = sototcpcb(so);
/* XXX Should never fail */
if (tp == NULL)
goto dropwithreset;
if (tp->t_state == TCPS_CLOSED)
goto drop;
tiwin = ti->ti_win;
/*
* Segment received on connection.
* Reset idle time and keep-alive timer.
*/
tp->t_idle = 0;
if (SO_OPTIONS)
tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL;
else
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE;
/*
* Process options if not in LISTEN state,
* else do it below (after getting remote address).
*/
if (optp && tp->t_state != TCPS_LISTEN)
tcp_dooptions(tp, (u_char *)optp, optlen, ti);
/*
* Header prediction: check for the two common cases
* of a uni-directional data xfer. If the packet has
* no control flags, is in-sequence, the window didn't
* change and we're not retransmitting, it's a
* candidate. If the length is zero and the ack moved
* forward, we're the sender side of the xfer. Just
* free the data acked & wake any higher level process
* that was blocked waiting for space. If the length
* is non-zero and the ack didn't move, we're the
* receiver side. If we're getting packets in-order
* (the reassembly queue is empty), add the data to
* the socket buffer and note that we need a delayed ack.
*
* XXX Some of these tests are not needed
* eg: the tiwin == tp->snd_wnd prevents many more
* predictions.. with no *real* advantage..
*/
if (tp->t_state == TCPS_ESTABLISHED &&
(tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK &&
ti->ti_seq == tp->rcv_nxt &&
tiwin && tiwin == tp->snd_wnd &&
tp->snd_nxt == tp->snd_max) {
if (ti->ti_len == 0) {
if (SEQ_GT(ti->ti_ack, tp->snd_una) &&
SEQ_LEQ(ti->ti_ack, tp->snd_max) &&
tp->snd_cwnd >= tp->snd_wnd) {
/*
* this is a pure ack for outstanding data.
*/
if (tp->t_rtt &&
SEQ_GT(ti->ti_ack, tp->t_rtseq))
tcp_xmit_timer(tp, tp->t_rtt);
acked = ti->ti_ack - tp->snd_una;
sbdrop(&so->so_snd, acked);
tp->snd_una = ti->ti_ack;
m_free(m);
/*
* If all outstanding data are acked, stop
* retransmit timer, otherwise restart timer
* using current (possibly backed-off) value.
* If process is waiting for space,
* wakeup/selwakeup/signal. If data
* are ready to send, let tcp_output
* decide between more output or persist.
*/
if (tp->snd_una == tp->snd_max)
tp->t_timer[TCPT_REXMT] = 0;
else if (tp->t_timer[TCPT_PERSIST] == 0)
tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
/*
* This is called because sowwakeup might have
* put data into so_snd. Since we don't so sowwakeup,
* we don't need this.. XXX???
*/
if (so->so_snd.sb_cc)
(void) tcp_output(tp);
return;
}
} else if (ti->ti_ack == tp->snd_una &&
tcpfrag_list_empty(tp) &&
ti->ti_len <= sbspace(&so->so_rcv)) {
/*
* this is a pure, in-sequence data packet
* with nothing on the reassembly queue and
* we have enough buffer space to take it.
*/
tp->rcv_nxt += ti->ti_len;
/*
* Add data to socket buffer.
*/
if (so->so_emu) {
if (tcp_emu(so,m)) sbappend(so, m);
} else
sbappend(so, m);
/*
* If this is a short packet, then ACK now - with Nagel
* congestion avoidance sender won't send more until
* he gets an ACK.
*
* It is better to not delay acks at all to maximize
* TCP throughput. See RFC 2581.
*/
tp->t_flags |= TF_ACKNOW;
tcp_output(tp);
return;
}
} /* header prediction */
/*
* Calculate amount of space in receive window,
* and then do TCP input processing.
* Receive window is amount of space in rcv queue,
* but not less than advertised window.
*/
{ int win;
win = sbspace(&so->so_rcv);
if (win < 0)
win = 0;
tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
}
switch (tp->t_state) {
/*
* If the state is LISTEN then ignore segment if it contains an RST.
* If the segment contains an ACK then it is bad and send a RST.
* If it does not contain a SYN then it is not interesting; drop it.
* Don't bother responding if the destination was a broadcast.
* Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
* tp->iss, and send a segment:
* <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
* Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
* Fill in remote peer address fields if not previously specified.
* Enter SYN_RECEIVED state, and process any other fields of this
* segment in this state.
*/
case TCPS_LISTEN: {
if (tiflags & TH_RST)
goto drop;
if (tiflags & TH_ACK)
goto dropwithreset;
if ((tiflags & TH_SYN) == 0)
goto drop;
/*
* This has way too many gotos...
* But a bit of spaghetti code never hurt anybody :)
*/
/*
* If this is destined for the control address, then flag to
* tcp_ctl once connected, otherwise connect
*/
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
slirp->vnetwork_addr.s_addr) {
if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr &&
so->so_faddr.s_addr != slirp->vnameserver_addr.s_addr) {
/* May be an add exec */
for (ex_ptr = slirp->exec_list; ex_ptr;
ex_ptr = ex_ptr->ex_next) {
if(ex_ptr->ex_fport == so->so_fport &&
so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) {
so->so_state |= SS_CTL;
break;
}
}
if (so->so_state & SS_CTL) {
goto cont_input;
}
}
/* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */
}
if (so->so_emu & EMU_NOCONNECT) {
so->so_emu &= ~EMU_NOCONNECT;
goto cont_input;
}
if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
u_char code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n",
errno,strerror(errno)));
if(errno == ECONNREFUSED) {
/* ACK the SYN, send RST to refuse the connection */
tcp_respond(tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
TH_RST|TH_ACK);
} else {
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
HTONL(ti->ti_seq); /* restore tcp header */
HTONL(ti->ti_ack);
HTONS(ti->ti_win);
HTONS(ti->ti_urp);
m->m_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
m->m_len += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
*ip=save_ip;
icmp_error(m, ICMP_UNREACH,code, 0,strerror(errno));
}
tcp_close(tp);
m_free(m);
} else {
/*
* Haven't connected yet, save the current mbuf
* and ti, and return
* XXX Some OS's don't tell us whether the connect()
* succeeded or not. So we must time it out.
*/
so->so_m = m;
so->so_ti = ti;
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
tp->t_state = TCPS_SYN_RECEIVED;
tcp_template(tp);
}
return;
cont_conn:
/* m==NULL
* Check if the connect succeeded
*/
if (so->so_state & SS_NOFDREF) {
tp = tcp_close(tp);
goto dropwithreset;
}
cont_input:
tcp_template(tp);
if (optp)
tcp_dooptions(tp, (u_char *)optp, optlen, ti);
if (iss)
tp->iss = iss;
else
tp->iss = slirp->tcp_iss;
slirp->tcp_iss += TCP_ISSINCR/2;
tp->irs = ti->ti_seq;
tcp_sendseqinit(tp);
tcp_rcvseqinit(tp);
tp->t_flags |= TF_ACKNOW;
tp->t_state = TCPS_SYN_RECEIVED;
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
goto trimthenstep6;
} /* case TCPS_LISTEN */
/*
* If the state is SYN_SENT:
* if seg contains an ACK, but not for our SYN, drop the input.
* if seg contains a RST, then drop the connection.
* if seg does not contain SYN, then drop it.
* Otherwise this is an acceptable SYN segment
* initialize tp->rcv_nxt and tp->irs
* if seg contains ack then advance tp->snd_una
* if SYN has been acked change to ESTABLISHED else SYN_RCVD state
* arrange for segment to be acked (eventually)
* continue processing rest of data/controls, beginning with URG
*/
case TCPS_SYN_SENT:
if ((tiflags & TH_ACK) &&
(SEQ_LEQ(ti->ti_ack, tp->iss) ||
SEQ_GT(ti->ti_ack, tp->snd_max)))
goto dropwithreset;
if (tiflags & TH_RST) {
if (tiflags & TH_ACK) {
tcp_drop(tp, 0); /* XXX Check t_softerror! */
}
goto drop;
}
if ((tiflags & TH_SYN) == 0)
goto drop;
if (tiflags & TH_ACK) {
tp->snd_una = ti->ti_ack;
if (SEQ_LT(tp->snd_nxt, tp->snd_una))
tp->snd_nxt = tp->snd_una;
}
tp->t_timer[TCPT_REXMT] = 0;
tp->irs = ti->ti_seq;
tcp_rcvseqinit(tp);
tp->t_flags |= TF_ACKNOW;
if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) {
soisfconnected(so);
tp->t_state = TCPS_ESTABLISHED;
(void) tcp_reass(tp, (struct tcpiphdr *)0,
(struct mbuf *)0);
/*
* if we didn't have to retransmit the SYN,
* use its rtt as our initial srtt & rtt var.
*/
if (tp->t_rtt)
tcp_xmit_timer(tp, tp->t_rtt);
} else
tp->t_state = TCPS_SYN_RECEIVED;
trimthenstep6:
/*
* Advance ti->ti_seq to correspond to first data byte.
* If data, trim to stay within window,
* dropping FIN if necessary.
*/
ti->ti_seq++;
if (ti->ti_len > tp->rcv_wnd) {
todrop = ti->ti_len - tp->rcv_wnd;
m_adj(m, -todrop);
ti->ti_len = tp->rcv_wnd;
tiflags &= ~TH_FIN;
}
tp->snd_wl1 = ti->ti_seq - 1;
tp->rcv_up = ti->ti_seq;
goto step6;
} /* switch tp->t_state */
/*
* States other than LISTEN or SYN_SENT.
* Check that at least some bytes of segment are within
* receive window. If segment begins before rcv_nxt,
* drop leading data (and SYN); if nothing left, just ack.
*/
todrop = tp->rcv_nxt - ti->ti_seq;
if (todrop > 0) {
if (tiflags & TH_SYN) {
tiflags &= ~TH_SYN;
ti->ti_seq++;
if (ti->ti_urp > 1)
ti->ti_urp--;
else
tiflags &= ~TH_URG;
todrop--;
}
/*
* Following if statement from Stevens, vol. 2, p. 960.
*/
if (todrop > ti->ti_len
|| (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) {
/*
* Any valid FIN must be to the left of the window.
* At this point the FIN must be a duplicate or out
* of sequence; drop it.
*/
tiflags &= ~TH_FIN;
/*
* Send an ACK to resynchronize and drop any data.
* But keep on processing for RST or ACK.
*/
tp->t_flags |= TF_ACKNOW;
todrop = ti->ti_len;
}
m_adj(m, todrop);
ti->ti_seq += todrop;
ti->ti_len -= todrop;
if (ti->ti_urp > todrop)
ti->ti_urp -= todrop;
else {
tiflags &= ~TH_URG;
ti->ti_urp = 0;
}
}
/*
* If new data are received on a connection after the
* user processes are gone, then RST the other end.
*/
if ((so->so_state & SS_NOFDREF) &&
tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
tp = tcp_close(tp);
goto dropwithreset;
}
/*
* If segment ends after window, drop trailing data
* (and PUSH and FIN); if nothing left, just ACK.
*/
todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
if (todrop > 0) {
if (todrop >= ti->ti_len) {
/*
* If a new connection request is received
* while in TIME_WAIT, drop the old connection
* and start over if the sequence numbers
* are above the previous ones.
*/
if (tiflags & TH_SYN &&
tp->t_state == TCPS_TIME_WAIT &&
SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
iss = tp->rcv_nxt + TCP_ISSINCR;
tp = tcp_close(tp);
goto findso;
}
/*
* If window is closed can only take segments at
* window edge, and have to drop data and PUSH from
* incoming segments. Continue processing, but
* remember to ack. Otherwise, drop segment
* and ack.
*/
if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) {
tp->t_flags |= TF_ACKNOW;
} else {
goto dropafterack;
}
}
m_adj(m, -todrop);
ti->ti_len -= todrop;
tiflags &= ~(TH_PUSH|TH_FIN);
}
/*
* If the RST bit is set examine the state:
* SYN_RECEIVED STATE:
* If passive open, return to LISTEN state.
* If active open, inform user that connection was refused.
* ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
* Inform user that connection was reset, and close tcb.
* CLOSING, LAST_ACK, TIME_WAIT STATES
* Close the tcb.
*/
if (tiflags&TH_RST) switch (tp->t_state) {
case TCPS_SYN_RECEIVED:
case TCPS_ESTABLISHED:
case TCPS_FIN_WAIT_1:
case TCPS_FIN_WAIT_2:
case TCPS_CLOSE_WAIT:
tp->t_state = TCPS_CLOSED;
tcp_close(tp);
goto drop;
case TCPS_CLOSING:
case TCPS_LAST_ACK:
case TCPS_TIME_WAIT:
tcp_close(tp);
goto drop;
}
/*
* If a SYN is in the window, then this is an
* error and we send an RST and drop the connection.
*/
if (tiflags & TH_SYN) {
tp = tcp_drop(tp,0);
goto dropwithreset;
}
/*
* If the ACK bit is off we drop the segment and return.
*/
if ((tiflags & TH_ACK) == 0) goto drop;
/*
* Ack processing.
*/
switch (tp->t_state) {
/*
* In SYN_RECEIVED state if the ack ACKs our SYN then enter
* ESTABLISHED state and continue processing, otherwise
* send an RST. una<=ack<=max
*/
case TCPS_SYN_RECEIVED:
if (SEQ_GT(tp->snd_una, ti->ti_ack) ||
SEQ_GT(ti->ti_ack, tp->snd_max))
goto dropwithreset;
tp->t_state = TCPS_ESTABLISHED;
/*
* The sent SYN is ack'ed with our sequence number +1
* The first data byte already in the buffer will get
* lost if no correction is made. This is only needed for
* SS_CTL since the buffer is empty otherwise.
* tp->snd_una++; or:
*/
tp->snd_una=ti->ti_ack;
if (so->so_state & SS_CTL) {
/* So tcp_ctl reports the right state */
ret = tcp_ctl(so);
if (ret == 1) {
soisfconnected(so);
so->so_state &= ~SS_CTL; /* success XXX */
} else if (ret == 2) {
so->so_state &= SS_PERSISTENT_MASK;
so->so_state |= SS_NOFDREF; /* CTL_CMD */
} else {
needoutput = 1;
tp->t_state = TCPS_FIN_WAIT_1;
}
} else {
soisfconnected(so);
}
(void) tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0);
tp->snd_wl1 = ti->ti_seq - 1;
/* Avoid ack processing; snd_una==ti_ack => dup ack */
goto synrx_to_est;
/* fall into ... */
/*
* In ESTABLISHED state: drop duplicate ACKs; ACK out of range
* ACKs. If the ack is in the range
* tp->snd_una < ti->ti_ack <= tp->snd_max
* then advance tp->snd_una to ti->ti_ack and drop
* data from the retransmission queue. If this ACK reflects
* more up to date window information we update our window information.
*/
case TCPS_ESTABLISHED:
case TCPS_FIN_WAIT_1:
case TCPS_FIN_WAIT_2:
case TCPS_CLOSE_WAIT:
case TCPS_CLOSING:
case TCPS_LAST_ACK:
case TCPS_TIME_WAIT:
if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
DEBUG_MISC((dfd, " dup ack m = %lx so = %lx\n",
(long )m, (long )so));
/*
* If we have outstanding data (other than
* a window probe), this is a completely
* duplicate ack (ie, window info didn't
* change), the ack is the biggest we've
* seen and we've seen exactly our rexmt
* threshold of them, assume a packet
* has been dropped and retransmit it.
* Kludge snd_nxt & the congestion
* window so we send only this one
* packet.
*
* We know we're losing at the current
* window size so do congestion avoidance
* (set ssthresh to half the current window
* and pull our congestion window back to
* the new ssthresh).
*
* Dup acks mean that packets have left the
* network (they're now cached at the receiver)
* so bump cwnd by the amount in the receiver
* to keep a constant cwnd packets in the
* network.
*/
if (tp->t_timer[TCPT_REXMT] == 0 ||
ti->ti_ack != tp->snd_una)
tp->t_dupacks = 0;
else if (++tp->t_dupacks == TCPREXMTTHRESH) {
tcp_seq onxt = tp->snd_nxt;
u_int win =
min(tp->snd_wnd, tp->snd_cwnd) / 2 /
tp->t_maxseg;
if (win < 2)
win = 2;
tp->snd_ssthresh = win * tp->t_maxseg;
tp->t_timer[TCPT_REXMT] = 0;
tp->t_rtt = 0;
tp->snd_nxt = ti->ti_ack;
tp->snd_cwnd = tp->t_maxseg;
(void) tcp_output(tp);
tp->snd_cwnd = tp->snd_ssthresh +
tp->t_maxseg * tp->t_dupacks;
if (SEQ_GT(onxt, tp->snd_nxt))
tp->snd_nxt = onxt;
goto drop;
} else if (tp->t_dupacks > TCPREXMTTHRESH) {
tp->snd_cwnd += tp->t_maxseg;
(void) tcp_output(tp);
goto drop;
}
} else
tp->t_dupacks = 0;
break;
}
synrx_to_est:
/*
* If the congestion window was inflated to account
* for the other side's cached packets, retract it.
*/
if (tp->t_dupacks > TCPREXMTTHRESH &&
tp->snd_cwnd > tp->snd_ssthresh)
tp->snd_cwnd = tp->snd_ssthresh;
tp->t_dupacks = 0;
if (SEQ_GT(ti->ti_ack, tp->snd_max)) {
goto dropafterack;
}
acked = ti->ti_ack - tp->snd_una;
/*
* If transmit timer is running and timed sequence
* number was acked, update smoothed round trip time.
* Since we now have an rtt measurement, cancel the
* timer backoff (cf., Phil Karn's retransmit alg.).
* Recompute the initial retransmit timer.
*/
if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
tcp_xmit_timer(tp,tp->t_rtt);
/*
* If all outstanding data is acked, stop retransmit
* timer and remember to restart (more output or persist).
* If there is more data to be acked, restart retransmit
* timer, using current (possibly backed-off) value.
*/
if (ti->ti_ack == tp->snd_max) {
tp->t_timer[TCPT_REXMT] = 0;
needoutput = 1;
} else if (tp->t_timer[TCPT_PERSIST] == 0)
tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
/*
* When new data is acked, open the congestion window.
* If the window gives us less than ssthresh packets
* in flight, open exponentially (maxseg per packet).
* Otherwise open linearly: maxseg per window
* (maxseg^2 / cwnd per packet).
*/
{
register u_int cw = tp->snd_cwnd;
register u_int incr = tp->t_maxseg;
if (cw > tp->snd_ssthresh)
incr = incr * incr / cw;
tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
}
if (acked > so->so_snd.sb_cc) {
tp->snd_wnd -= so->so_snd.sb_cc;
sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
ourfinisacked = 1;
} else {
sbdrop(&so->so_snd, acked);
tp->snd_wnd -= acked;
ourfinisacked = 0;
}
tp->snd_una = ti->ti_ack;
if (SEQ_LT(tp->snd_nxt, tp->snd_una))
tp->snd_nxt = tp->snd_una;
switch (tp->t_state) {
/*
* In FIN_WAIT_1 STATE in addition to the processing
* for the ESTABLISHED state if our FIN is now acknowledged
* then enter FIN_WAIT_2.
*/
case TCPS_FIN_WAIT_1:
if (ourfinisacked) {
/*
* If we can't receive any more
* data, then closing user can proceed.
* Starting the timer is contrary to the
* specification, but if we don't get a FIN
* we'll hang forever.
*/
if (so->so_state & SS_FCANTRCVMORE) {
tp->t_timer[TCPT_2MSL] = TCP_MAXIDLE;
}
tp->t_state = TCPS_FIN_WAIT_2;
}
break;
/*
* In CLOSING STATE in addition to the processing for
* the ESTABLISHED state if the ACK acknowledges our FIN
* then enter the TIME-WAIT state, otherwise ignore
* the segment.
*/
case TCPS_CLOSING:
if (ourfinisacked) {
tp->t_state = TCPS_TIME_WAIT;
tcp_canceltimers(tp);
tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
}
break;
/*
* In LAST_ACK, we may still be waiting for data to drain
* and/or to be acked, as well as for the ack of our FIN.
* If our FIN is now acknowledged, delete the TCB,
* enter the closed state and return.
*/
case TCPS_LAST_ACK:
if (ourfinisacked) {
tcp_close(tp);
goto drop;
}
break;
/*
* In TIME_WAIT state the only thing that should arrive
* is a retransmission of the remote FIN. Acknowledge
* it and restart the finack timer.
*/
case TCPS_TIME_WAIT:
tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
goto dropafterack;
}
} /* switch(tp->t_state) */
step6:
/*
* Update window information.
* Don't look at window if no ACK: TAC's send garbage on first SYN.
*/
if ((tiflags & TH_ACK) &&
(SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
(tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
(tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
tp->snd_wnd = tiwin;
tp->snd_wl1 = ti->ti_seq;
tp->snd_wl2 = ti->ti_ack;
if (tp->snd_wnd > tp->max_sndwnd)
tp->max_sndwnd = tp->snd_wnd;
needoutput = 1;
}
/*
* Process segments with URG.
*/
if ((tiflags & TH_URG) && ti->ti_urp &&
TCPS_HAVERCVDFIN(tp->t_state) == 0) {
/*
* This is a kludge, but if we receive and accept
* random urgent pointers, we'll crash in
* soreceive. It's hard to imagine someone
* actually wanting to send this much urgent data.
*/
if (ti->ti_urp + so->so_rcv.sb_cc > so->so_rcv.sb_datalen) {
ti->ti_urp = 0;
tiflags &= ~TH_URG;
goto dodata;
}
/*
* If this segment advances the known urgent pointer,
* then mark the data stream. This should not happen
* in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
* a FIN has been received from the remote side.
* In these states we ignore the URG.
*
* According to RFC961 (Assigned Protocols),
* the urgent pointer points to the last octet
* of urgent data. We continue, however,
* to consider it to indicate the first octet
* of data past the urgent section as the original
* spec states (in one of two places).
*/
if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) {
tp->rcv_up = ti->ti_seq + ti->ti_urp;
so->so_urgc = so->so_rcv.sb_cc +
(tp->rcv_up - tp->rcv_nxt); /* -1; */
tp->rcv_up = ti->ti_seq + ti->ti_urp;
}
} else
/*
* If no out of band data is expected,
* pull receive urgent pointer along
* with the receive window.
*/
if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
tp->rcv_up = tp->rcv_nxt;
dodata:
/*
* If this is a small packet, then ACK now - with Nagel
* congestion avoidance sender won't send more until
* he gets an ACK.
*/
if (ti->ti_len && (unsigned)ti->ti_len <= 5 &&
((struct tcpiphdr_2 *)ti)->first_char == (char)27) {
tp->t_flags |= TF_ACKNOW;
}
/*
* Process the segment text, merging it into the TCP sequencing queue,
* and arranging for acknowledgment of receipt if necessary.
* This process logically involves adjusting tp->rcv_wnd as data
* is presented to the user (this happens in tcp_usrreq.c,
* case PRU_RCVD). If a FIN has already been received on this
* connection then we just ignore the text.
*/
if ((ti->ti_len || (tiflags&TH_FIN)) &&
TCPS_HAVERCVDFIN(tp->t_state) == 0) {
TCP_REASS(tp, ti, m, so, tiflags);
} else {
m_free(m);
tiflags &= ~TH_FIN;
}
/*
* If FIN is received ACK the FIN and let the user know
* that the connection is closing.
*/
if (tiflags & TH_FIN) {
if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
/*
* If we receive a FIN we can't send more data,
* set it SS_FDRAIN
* Shutdown the socket if there is no rx data in the
* buffer.
* soread() is called on completion of shutdown() and
* will got to TCPS_LAST_ACK, and use tcp_output()
* to send the FIN.
*/
sofwdrain(so);
tp->t_flags |= TF_ACKNOW;
tp->rcv_nxt++;
}
switch (tp->t_state) {
/*
* In SYN_RECEIVED and ESTABLISHED STATES
* enter the CLOSE_WAIT state.
*/
case TCPS_SYN_RECEIVED:
case TCPS_ESTABLISHED:
if(so->so_emu == EMU_CTL) /* no shutdown on socket */
tp->t_state = TCPS_LAST_ACK;
else
tp->t_state = TCPS_CLOSE_WAIT;
break;
/*
* If still in FIN_WAIT_1 STATE FIN has not been acked so
* enter the CLOSING state.
*/
case TCPS_FIN_WAIT_1:
tp->t_state = TCPS_CLOSING;
break;
/*
* In FIN_WAIT_2 state enter the TIME_WAIT state,
* starting the time-wait timer, turning off the other
* standard timers.
*/
case TCPS_FIN_WAIT_2:
tp->t_state = TCPS_TIME_WAIT;
tcp_canceltimers(tp);
tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
break;
/*
* In TIME_WAIT state restart the 2 MSL time_wait timer.
*/
case TCPS_TIME_WAIT:
tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
break;
}
}
/*
* Return any desired output.
*/
if (needoutput || (tp->t_flags & TF_ACKNOW)) {
(void) tcp_output(tp);
}
return;
dropafterack:
/*
* Generate an ACK dropping incoming segment if it occupies
* sequence space, where the ACK reflects our state.
*/
if (tiflags & TH_RST)
goto drop;
m_free(m);
tp->t_flags |= TF_ACKNOW;
(void) tcp_output(tp);
return;
dropwithreset:
/* reuses m if m!=NULL, m_free() unnecessary */
if (tiflags & TH_ACK)
tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
else {
if (tiflags & TH_SYN) ti->ti_len++;
tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
TH_RST|TH_ACK);
}
return;
drop:
/*
* Drop space held by incoming segment and return.
*/
m_free(m);
}
| 11,596 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static bool cmd_identify(IDEState *s, uint8_t cmd)
{
if (s->bs && s->drive_kind != IDE_CD) {
if (s->drive_kind != IDE_CFATA) {
ide_identify(s);
} else {
ide_cfata_identify(s);
}
s->status = READY_STAT | SEEK_STAT;
ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
ide_set_irq(s->bus);
return false;
} else {
if (s->drive_kind == IDE_CD) {
ide_set_signature(s);
}
ide_abort_command(s);
}
return true;
}
| 11,598 |
qemu | 3edf1e73d568c646202e9faa6224df4fee1bd0e6 | 0 | static coroutine_fn int dmg_co_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
int ret;
BDRVDMGState *s = bs->opaque;
qemu_co_mutex_lock(&s->lock);
ret = dmg_read(bs, sector_num, buf, nb_sectors);
qemu_co_mutex_unlock(&s->lock);
return ret;
}
| 11,599 |
qemu | 7a2c4b82340d621bff462672b29c88d2020d68c1 | 0 | static void cmd_read_cdvd_capacity(IDEState *s, uint8_t* buf)
{
uint64_t total_sectors = s->nb_sectors >> 2;
if (total_sectors == 0) {
ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
return;
}
/* NOTE: it is really the number of sectors minus 1 */
cpu_to_ube32(buf, total_sectors - 1);
cpu_to_ube32(buf + 4, 2048);
ide_atapi_cmd_reply(s, 8, 8);
}
| 11,600 |
qemu | f090c9d4ad5812fb92843d6470a1111c15190c4c | 0 | int64 float32_to_int64_round_to_zero( float32 a STATUS_PARAM )
{
flag aSign;
int16 aExp, shiftCount;
bits32 aSig;
bits64 aSig64;
int64 z;
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
shiftCount = aExp - 0xBE;
if ( 0 <= shiftCount ) {
if ( a != 0xDF000000 ) {
float_raise( float_flag_invalid STATUS_VAR);
if ( ! aSign || ( ( aExp == 0xFF ) && aSig ) ) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
return (sbits64) LIT64( 0x8000000000000000 );
}
else if ( aExp <= 0x7E ) {
if ( aExp | aSig ) STATUS(float_exception_flags) |= float_flag_inexact;
return 0;
}
aSig64 = aSig | 0x00800000;
aSig64 <<= 40;
z = aSig64>>( - shiftCount );
if ( (bits64) ( aSig64<<( shiftCount & 63 ) ) ) {
STATUS(float_exception_flags) |= float_flag_inexact;
}
if ( aSign ) z = - z;
return z;
}
| 11,601 |
qemu | c6a6a5e3bb7120e1eb33eca6364a290229c1e72e | 0 | putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse)
{
if (cse && cse < n)
n = cse + 1;
if (sloc < n-1)
cpu_to_be16wu((uint16_t *)(data + sloc),
do_cksum(data + css, data + n));
}
| 11,602 |
qemu | 5d7fd045cafeac1831c1999cb9e1251b7906c6b2 | 0 | uint32_t HELPER(lcxbr)(CPUS390XState *env, uint32_t f1, uint32_t f2)
{
CPU_QuadU x1, x2;
x2.ll.upper = env->fregs[f2].ll;
x2.ll.lower = env->fregs[f2 + 2].ll;
x1.q = float128_chs(x2.q);
env->fregs[f1].ll = x1.ll.upper;
env->fregs[f1 + 2].ll = x1.ll.lower;
return set_cc_nz_f128(x1.q);
}
| 11,603 |
qemu | 5fe79386ba3cdc86fd808dde301bfc5bb7e9bded | 0 | static void pc_machine_set_nvdimm(Object *obj, bool value, Error **errp)
{
PCMachineState *pcms = PC_MACHINE(obj);
pcms->nvdimm = value;
}
| 11,604 |
FFmpeg | d5d2d6c3b8cff61eb26c18bbd977881cf6d5524a | 0 | static int dca_exss_parse_asset_header(DCAContext *s)
{
int header_pos = get_bits_count(&s->gb);
int header_size;
int channels;
int embedded_stereo = 0;
int embedded_6ch = 0;
int drc_code_present;
int extensions_mask;
int i, j;
if (get_bits_left(&s->gb) < 16)
return -1;
/* We will parse just enough to get to the extensions bitmask with which
* we can set the profile value. */
header_size = get_bits(&s->gb, 9) + 1;
skip_bits(&s->gb, 3); // asset index
if (s->static_fields) {
if (get_bits1(&s->gb))
skip_bits(&s->gb, 4); // asset type descriptor
if (get_bits1(&s->gb))
skip_bits_long(&s->gb, 24); // language descriptor
if (get_bits1(&s->gb)) {
/* How can one fit 1024 bytes of text here if the maximum value
* for the asset header size field above was 512 bytes? */
int text_length = get_bits(&s->gb, 10) + 1;
if (get_bits_left(&s->gb) < text_length * 8)
return -1;
skip_bits_long(&s->gb, text_length * 8); // info text
}
skip_bits(&s->gb, 5); // bit resolution - 1
skip_bits(&s->gb, 4); // max sample rate code
channels = get_bits(&s->gb, 8) + 1;
if (get_bits1(&s->gb)) { // 1-to-1 channels to speakers
int spkr_remap_sets;
int spkr_mask_size = 16;
int num_spkrs[7];
if (channels > 2)
embedded_stereo = get_bits1(&s->gb);
if (channels > 6)
embedded_6ch = get_bits1(&s->gb);
if (get_bits1(&s->gb)) {
spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2;
skip_bits(&s->gb, spkr_mask_size); // spkr activity mask
}
spkr_remap_sets = get_bits(&s->gb, 3);
for (i = 0; i < spkr_remap_sets; i++) {
/* std layout mask for each remap set */
num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size));
}
for (i = 0; i < spkr_remap_sets; i++) {
int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1;
if (get_bits_left(&s->gb) < 0)
return -1;
for (j = 0; j < num_spkrs[i]; j++) {
int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps);
int num_dec_ch = av_popcount(remap_dec_ch_mask);
skip_bits_long(&s->gb, num_dec_ch * 5); // remap codes
}
}
} else {
skip_bits(&s->gb, 3); // representation type
}
}
drc_code_present = get_bits1(&s->gb);
if (drc_code_present)
get_bits(&s->gb, 8); // drc code
if (get_bits1(&s->gb))
skip_bits(&s->gb, 5); // dialog normalization code
if (drc_code_present && embedded_stereo)
get_bits(&s->gb, 8); // drc stereo code
if (s->mix_metadata && get_bits1(&s->gb)) {
skip_bits(&s->gb, 1); // external mix
skip_bits(&s->gb, 6); // post mix gain code
if (get_bits(&s->gb, 2) != 3) // mixer drc code
skip_bits(&s->gb, 3); // drc limit
else
skip_bits(&s->gb, 8); // custom drc code
if (get_bits1(&s->gb)) // channel specific scaling
for (i = 0; i < s->num_mix_configs; i++)
skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); // scale codes
else
skip_bits_long(&s->gb, s->num_mix_configs * 6); // scale codes
for (i = 0; i < s->num_mix_configs; i++) {
if (get_bits_left(&s->gb) < 0)
return -1;
dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]);
if (embedded_6ch)
dca_exss_skip_mix_coeffs(&s->gb, 6, s->mix_config_num_ch[i]);
if (embedded_stereo)
dca_exss_skip_mix_coeffs(&s->gb, 2, s->mix_config_num_ch[i]);
}
}
switch (get_bits(&s->gb, 2)) {
case 0:
extensions_mask = get_bits(&s->gb, 12);
break;
case 1:
extensions_mask = DCA_EXT_EXSS_XLL;
break;
case 2:
extensions_mask = DCA_EXT_EXSS_LBR;
break;
case 3:
extensions_mask = 0; /* aux coding */
break;
}
/* not parsed further, we were only interested in the extensions mask */
if (get_bits_left(&s->gb) < 0)
return -1;
if (get_bits_count(&s->gb) - header_pos > header_size * 8) {
av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");
return -1;
}
skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb));
if (extensions_mask & DCA_EXT_EXSS_XLL)
s->profile = FF_PROFILE_DTS_HD_MA;
else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |
DCA_EXT_EXSS_XXCH))
s->profile = FF_PROFILE_DTS_HD_HRA;
if (!(extensions_mask & DCA_EXT_CORE))
av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");
if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)
av_log(s->avctx, AV_LOG_WARNING,
"DTS extensions detection mismatch (%d, %d)\n",
extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);
return 0;
}
| 11,605 |
qemu | 54f254f973a1b2ed0f3571390f4de060adfe23e8 | 0 | static int uhci_broadcast_packet(UHCIState *s, USBPacket *p)
{
UHCIPort *port;
USBDevice *dev;
int i, ret;
#ifdef DEBUG_PACKET
{
const char *pidstr;
switch(p->pid) {
case USB_TOKEN_SETUP: pidstr = "SETUP"; break;
case USB_TOKEN_IN: pidstr = "IN"; break;
case USB_TOKEN_OUT: pidstr = "OUT"; break;
default: pidstr = "?"; break;
}
printf("frame %d: pid=%s addr=0x%02x ep=%d len=%d\n",
s->frnum, pidstr, p->devaddr, p->devep, p->len);
if (p->pid != USB_TOKEN_IN) {
printf(" data_out=");
for(i = 0; i < p->len; i++) {
printf(" %02x", p->data[i]);
}
printf("\n");
}
}
#endif
for(i = 0; i < NB_PORTS; i++) {
port = &s->ports[i];
dev = port->port.dev;
if (dev && (port->ctrl & UHCI_PORT_EN)) {
ret = dev->handle_packet(dev, p);
if (ret != USB_RET_NODEV) {
#ifdef DEBUG_PACKET
if (ret == USB_RET_ASYNC) {
printf("usb-uhci: Async packet\n");
} else {
printf(" ret=%d ", ret);
if (p->pid == USB_TOKEN_IN && ret > 0) {
printf("data_in=");
for(i = 0; i < ret; i++) {
printf(" %02x", p->data[i]);
}
}
printf("\n");
}
#endif
return ret;
}
}
}
return USB_RET_NODEV;
}
| 11,606 |
qemu | fb1c2cd7d9a9955a98eb7c874a74122f1e964811 | 0 | static inline PageDesc *page_find_alloc(target_ulong index)
{
PageDesc **lp, *p;
lp = page_l1_map(index);
if (!lp)
return NULL;
p = *lp;
if (!p) {
/* allocate if not found */
#if defined(CONFIG_USER_ONLY)
unsigned long addr;
size_t len = sizeof(PageDesc) * L2_SIZE;
/* Don't use qemu_malloc because it may recurse. */
p = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
*lp = p;
addr = h2g(p);
if (addr == (target_ulong)addr) {
page_set_flags(addr & TARGET_PAGE_MASK,
TARGET_PAGE_ALIGN(addr + len),
PAGE_RESERVED);
}
#else
p = qemu_mallocz(sizeof(PageDesc) * L2_SIZE);
*lp = p;
#endif
}
return p + (index & (L2_SIZE - 1));
}
| 11,607 |
qemu | 46232aaacb66733d3e16dcbd0d26c32ec388801d | 0 | static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
{
DeviceState *dev = DEVICE(cpu);
APICCommonState *apic;
const char *apic_type = "apic";
if (kvm_irqchip_in_kernel()) {
apic_type = "kvm-apic";
} else if (xen_enabled()) {
apic_type = "xen-apic";
}
cpu->apic_state = qdev_try_create(qdev_get_parent_bus(dev), apic_type);
if (cpu->apic_state == NULL) {
error_setg(errp, "APIC device '%s' could not be created", apic_type);
return;
}
object_property_add_child(OBJECT(cpu), "apic",
OBJECT(cpu->apic_state), NULL);
qdev_prop_set_uint8(cpu->apic_state, "id", cpu->apic_id);
/* TODO: convert to link<> */
apic = APIC_COMMON(cpu->apic_state);
apic->cpu = cpu;
apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE;
}
| 11,609 |
qemu | f0df84c6c46cb632dac2d9fae5fdbe6001527c3b | 0 | int select_watchdog_action(const char *p)
{
int action;
char *qapi_value;
qapi_value = g_ascii_strdown(p, -1);
action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, NULL);
g_free(qapi_value);
if (action < 0)
return -1;
watchdog_action = action;
return 0;
}
| 11,610 |
qemu | 9bd7854e1e5d6f4cfe4558090bbd9493c12bf846 | 0 | static void pty_chr_read(void *opaque)
{
CharDriverState *chr = opaque;
PtyCharDriver *s = chr->opaque;
int size, len;
uint8_t buf[1024];
len = sizeof(buf);
if (len > s->read_bytes)
len = s->read_bytes;
if (len == 0)
return;
size = read(s->fd, buf, len);
if ((size == -1 && errno == EIO) ||
(size == 0)) {
pty_chr_state(chr, 0);
return;
}
if (size > 0) {
pty_chr_state(chr, 1);
qemu_chr_read(chr, buf, size);
}
}
| 11,614 |
qemu | ca6b6e1e68ac44b2e8895da10dd1c80dc03d08b7 | 0 | static void test_visitor_out_struct(TestOutputVisitorData *data,
const void *unused)
{
TestStruct test_struct = { .integer = 42,
.boolean = false,
.string = (char *) "foo"};
TestStruct *p = &test_struct;
QObject *obj;
QDict *qdict;
visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QDICT);
qdict = qobject_to_qdict(obj);
g_assert_cmpint(qdict_size(qdict), ==, 3);
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");
}
| 11,615 |
qemu | 0fbf5238203041f734c51b49778223686f14366b | 0 | static inline int check_ap(CPUARMState *env, ARMMMUIdx mmu_idx,
int ap, int domain_prot,
int access_type)
{
int prot_ro;
bool is_user = regime_is_user(env, mmu_idx);
if (domain_prot == 3) {
return PAGE_READ | PAGE_WRITE;
}
if (access_type == 1) {
prot_ro = 0;
} else {
prot_ro = PAGE_READ;
}
switch (ap) {
case 0:
if (arm_feature(env, ARM_FEATURE_V7)) {
return 0;
}
if (access_type == 1) {
return 0;
}
switch (regime_sctlr(env, mmu_idx) & (SCTLR_S | SCTLR_R)) {
case SCTLR_S:
return is_user ? 0 : PAGE_READ;
case SCTLR_R:
return PAGE_READ;
default:
return 0;
}
case 1:
return is_user ? 0 : PAGE_READ | PAGE_WRITE;
case 2:
if (is_user) {
return prot_ro;
} else {
return PAGE_READ | PAGE_WRITE;
}
case 3:
return PAGE_READ | PAGE_WRITE;
case 4: /* Reserved. */
return 0;
case 5:
return is_user ? 0 : prot_ro;
case 6:
return prot_ro;
case 7:
if (!arm_feature(env, ARM_FEATURE_V6K)) {
return 0;
}
return prot_ro;
default:
abort();
}
}
| 11,617 |
qemu | 9ef91a677110ec200d7b2904fc4bcae5a77329ad | 0 | static int posix_aio_flush(void *opaque)
{
PosixAioState *s = opaque;
return !!s->first_aio;
}
| 11,618 |
qemu | 729633c2bc30496073431584eb6e304776b4ebd4 | 0 | static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
hwaddr addr,
bool resolve_subpage)
{
MemoryRegionSection *section;
subpage_t *subpage;
section = phys_page_find(d->phys_map, addr, d->map.nodes, d->map.sections);
if (resolve_subpage && section->mr->subpage) {
subpage = container_of(section->mr, subpage_t, iomem);
section = &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr)]];
}
return section;
}
| 11,619 |
qemu | 46c5874e9cd752ed8ded31af03472edd8fc3efc1 | 0 | static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
uint32_t addr, uint32_t size,
target_ulong rets)
{
PCIDevice *pci_dev;
uint32_t val;
if ((size != 1) && (size != 2) && (size != 4)) {
/* access must be 1, 2 or 4 bytes */
rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
return;
}
pci_dev = find_dev(spapr, buid, addr);
addr = rtas_pci_cfgaddr(addr);
if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
/* Access must be to a valid device, within bounds and
* naturally aligned */
rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
return;
}
val = pci_host_config_read_common(pci_dev, addr,
pci_config_size(pci_dev), size);
rtas_st(rets, 0, RTAS_OUT_SUCCESS);
rtas_st(rets, 1, val);
}
| 11,620 |
FFmpeg | d1adad3cca407f493c3637e20ecd4f7124e69212 | 0 | static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dest,
long width, long height, long src1Stride,
long src2Stride, long dstStride)
{
long h;
for (h=0; h < height; h++) {
long w;
#if COMPILE_TEMPLATE_MMX
#if COMPILE_TEMPLATE_SSE2
__asm__(
"xor %%"REG_a", %%"REG_a" \n\t"
"1: \n\t"
PREFETCH" 64(%1, %%"REG_a") \n\t"
PREFETCH" 64(%2, %%"REG_a") \n\t"
"movdqa (%1, %%"REG_a"), %%xmm0 \n\t"
"movdqa (%1, %%"REG_a"), %%xmm1 \n\t"
"movdqa (%2, %%"REG_a"), %%xmm2 \n\t"
"punpcklbw %%xmm2, %%xmm0 \n\t"
"punpckhbw %%xmm2, %%xmm1 \n\t"
"movntdq %%xmm0, (%0, %%"REG_a", 2) \n\t"
"movntdq %%xmm1, 16(%0, %%"REG_a", 2) \n\t"
"add $16, %%"REG_a" \n\t"
"cmp %3, %%"REG_a" \n\t"
" jb 1b \n\t"
::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
: "memory", "%"REG_a""
);
#else
__asm__(
"xor %%"REG_a", %%"REG_a" \n\t"
"1: \n\t"
PREFETCH" 64(%1, %%"REG_a") \n\t"
PREFETCH" 64(%2, %%"REG_a") \n\t"
"movq (%1, %%"REG_a"), %%mm0 \n\t"
"movq 8(%1, %%"REG_a"), %%mm2 \n\t"
"movq %%mm0, %%mm1 \n\t"
"movq %%mm2, %%mm3 \n\t"
"movq (%2, %%"REG_a"), %%mm4 \n\t"
"movq 8(%2, %%"REG_a"), %%mm5 \n\t"
"punpcklbw %%mm4, %%mm0 \n\t"
"punpckhbw %%mm4, %%mm1 \n\t"
"punpcklbw %%mm5, %%mm2 \n\t"
"punpckhbw %%mm5, %%mm3 \n\t"
MOVNTQ" %%mm0, (%0, %%"REG_a", 2) \n\t"
MOVNTQ" %%mm1, 8(%0, %%"REG_a", 2) \n\t"
MOVNTQ" %%mm2, 16(%0, %%"REG_a", 2) \n\t"
MOVNTQ" %%mm3, 24(%0, %%"REG_a", 2) \n\t"
"add $16, %%"REG_a" \n\t"
"cmp %3, %%"REG_a" \n\t"
" jb 1b \n\t"
::"r"(dest), "r"(src1), "r"(src2), "r" ((x86_reg)width-15)
: "memory", "%"REG_a
);
#endif
for (w= (width&(~15)); w < width; w++) {
dest[2*w+0] = src1[w];
dest[2*w+1] = src2[w];
}
#else
for (w=0; w < width; w++) {
dest[2*w+0] = src1[w];
dest[2*w+1] = src2[w];
}
#endif
dest += dstStride;
src1 += src1Stride;
src2 += src2Stride;
}
#if COMPILE_TEMPLATE_MMX
__asm__(
EMMS" \n\t"
SFENCE" \n\t"
::: "memory"
);
#endif
}
| 11,621 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static int spapr_nvram_init(VIOsPAPRDevice *dev)
{
sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(dev);
if (nvram->drive) {
nvram->size = bdrv_getlength(nvram->drive);
} else {
nvram->size = DEFAULT_NVRAM_SIZE;
nvram->buf = g_malloc0(nvram->size);
}
if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {
fprintf(stderr, "spapr-nvram must be between %d and %d bytes in size\n",
MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);
return -1;
}
spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch);
spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store);
return 0;
}
| 11,622 |
qemu | dfd100f242370886bb6732f70f1f7cbd8eb9fedc | 0 | static void test_io_channel_setup_async(SocketAddress *listen_addr,
SocketAddress *connect_addr,
QIOChannel **src,
QIOChannel **dst)
{
QIOChannelSocket *lioc;
struct TestIOChannelData data;
data.loop = g_main_loop_new(g_main_context_default(),
TRUE);
lioc = qio_channel_socket_new();
qio_channel_socket_listen_async(
lioc, listen_addr,
test_io_channel_complete, &data, NULL);
g_main_loop_run(data.loop);
g_main_context_iteration(g_main_context_default(), FALSE);
g_assert(!data.err);
if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
g_free(connect_addr->u.inet.data->port);
connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
qapi_free_SocketAddress(laddr);
}
*src = QIO_CHANNEL(qio_channel_socket_new());
qio_channel_socket_connect_async(
QIO_CHANNEL_SOCKET(*src), connect_addr,
test_io_channel_complete, &data, NULL);
g_main_loop_run(data.loop);
g_main_context_iteration(g_main_context_default(), FALSE);
g_assert(!data.err);
qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN);
*dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort));
g_assert(*dst);
qio_channel_set_delay(*src, false);
test_io_channel_set_socket_bufs(*src, *dst);
object_unref(OBJECT(lioc));
g_main_loop_unref(data.loop);
}
| 11,623 |
qemu | d045c466d9e62b4321fadf586d024d54ddfd8bd4 | 0 | iscsi_process_read(void *arg)
{
IscsiLun *iscsilun = arg;
struct iscsi_context *iscsi = iscsilun->iscsi;
aio_context_acquire(iscsilun->aio_context);
iscsi_service(iscsi, POLLIN);
iscsi_set_events(iscsilun);
aio_context_release(iscsilun->aio_context);
}
| 11,625 |
qemu | 4750a96f6baf8949cc04a0c5b7167606544a4401 | 0 | static int local_open2(FsContext *ctx, const char *path, int flags, mode_t mode)
{
return open(rpath(ctx, path), flags, mode);
}
| 11,626 |
qemu | 3098dba01c7daab60762b6f6624ea88c0d6cb65a | 0 | static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
{
CPUState *env = opaque;
if (version_id != CPU_COMMON_SAVE_VERSION)
return -EINVAL;
qemu_get_be32s(f, &env->halted);
qemu_get_be32s(f, &env->interrupt_request);
env->interrupt_request &= ~CPU_INTERRUPT_EXIT;
tlb_flush(env, 1);
return 0;
}
| 11,627 |
qemu | dad5b9ea0895c227bc9d48b7f0a6fa51eaaa8661 | 0 | static void xhci_port_reset(XHCIPort *port)
{
trace_usb_xhci_port_reset(port->portnr);
if (!xhci_port_have_device(port)) {
return;
}
usb_device_reset(port->uport->dev);
switch (port->uport->dev->speed) {
case USB_SPEED_LOW:
case USB_SPEED_FULL:
case USB_SPEED_HIGH:
set_field(&port->portsc, PLS_U0, PORTSC_PLS);
trace_usb_xhci_port_link(port->portnr, PLS_U0);
port->portsc |= PORTSC_PED;
break;
}
port->portsc &= ~PORTSC_PR;
xhci_port_notify(port, PORTSC_PRC);
}
| 11,629 |
qemu | 306a06e5f766acaf26b71397a5692c65b65a61c7 | 0 | static int block_crypto_create_generic(QCryptoBlockFormat format,
const char *filename,
QemuOpts *opts,
Error **errp)
{
int ret = -EINVAL;
QCryptoBlockCreateOptions *create_opts = NULL;
QCryptoBlock *crypto = NULL;
struct BlockCryptoCreateData data = {
.size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
BDRV_SECTOR_SIZE),
.opts = opts,
.filename = filename,
};
create_opts = block_crypto_create_opts_init(format, opts, errp);
if (!create_opts) {
return -1;
}
crypto = qcrypto_block_create(create_opts,
block_crypto_init_func,
block_crypto_write_func,
&data,
errp);
if (!crypto) {
ret = -EIO;
goto cleanup;
}
ret = 0;
cleanup:
qcrypto_block_free(crypto);
blk_unref(data.blk);
qapi_free_QCryptoBlockCreateOptions(create_opts);
return ret;
}
| 11,630 |
FFmpeg | ee408eadbadbc629c9ef06f62ddf63643defe541 | 0 | static void vertical_filter(unsigned char *first_pixel, int stride,
int *bounding_values)
{
int i;
int filter_value;
for (i = 0; i < 8; i++, first_pixel++) {
filter_value =
(first_pixel[-(2 * stride)] * 1) -
(first_pixel[-(1 * stride)] * 3) +
(first_pixel[ (0 )] * 3) -
(first_pixel[ (1 * stride)] * 1);
filter_value = bounding_values[(filter_value + 4) >> 3];
first_pixel[-(1 * stride)] = SATURATE_U8(first_pixel[-(1 * stride)] + filter_value);
first_pixel[0] = SATURATE_U8(first_pixel[0] - filter_value);
}
}
| 11,632 |
qemu | 8cd2ce7aaa3c3fadc561f40045d4d53ff72e94ef | 0 | POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
dc->fw_name = "PowerPC,POWER8";
dc->desc = "POWER8";
dc->props = powerpc_servercpu_properties;
pcc->pvr_match = ppc_pvr_match_power8;
pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
pcc->init_proc = init_proc_POWER8;
pcc->check_pow = check_pow_nocheck;
pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
PPC_FLOAT_FRSQRTES |
PPC_FLOAT_STFIWX |
PPC_FLOAT_EXT |
PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
PPC_MEM_SYNC | PPC_MEM_EIEIO |
PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |
PPC_SEGMENT_64B | PPC_SLBI |
PPC_POPCNTB | PPC_POPCNTWD;
pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
PPC2_TM;
pcc->msr_mask = (1ull << MSR_SF) |
(1ull << MSR_SHV) |
(1ull << MSR_TM) |
(1ull << MSR_VR) |
(1ull << MSR_VSX) |
(1ull << MSR_EE) |
(1ull << MSR_PR) |
(1ull << MSR_FP) |
(1ull << MSR_ME) |
(1ull << MSR_FE0) |
(1ull << MSR_SE) |
(1ull << MSR_DE) |
(1ull << MSR_FE1) |
(1ull << MSR_IR) |
(1ull << MSR_DR) |
(1ull << MSR_PMM) |
(1ull << MSR_RI) |
(1ull << MSR_LE);
pcc->mmu_model = POWERPC_MMU_2_07;
#if defined(CONFIG_SOFTMMU)
pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;
pcc->sps = &POWER7_POWER8_sps;
#endif
pcc->excp_model = POWERPC_EXCP_POWER8;
pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
pcc->bfd_mach = bfd_mach_ppc64;
pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
POWERPC_FLAG_VSX | POWERPC_FLAG_TM;
pcc->l1_dcache_size = 0x8000;
pcc->l1_icache_size = 0x8000;
pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;
}
| 11,633 |
qemu | 82cbbdc6a0958b49c77639a60906e30d02e6bb7b | 0 | void qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
void *opaque)
{
aio_set_fd_handler(qemu_aio_context, fd, io_read, io_write, io_flush,
opaque);
qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
}
| 11,634 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static void apb_pci_config_write(void *opaque, target_phys_addr_t addr,
uint64_t val, unsigned size)
{
APBState *s = opaque;
val = qemu_bswap_len(val, size);
APB_DPRINTF("%s: addr " TARGET_FMT_lx " val %" PRIx64 "\n", __func__, addr, val);
pci_data_write(s->bus, addr, val, size);
}
| 11,636 |
qemu | e389be1673052b538534643165111725a79e5afd | 0 | static inline bool extended_addresses_enabled(CPUARMState *env)
{
return arm_el_is_aa64(env, 1)
|| ((arm_feature(env, ARM_FEATURE_LPAE)
&& (env->cp15.c2_control & (1U << 31))));
}
| 11,637 |
qemu | 3d948cdf3760b52238038626a7ffa7d30913060b | 0 | void qmp_block_job_pause(const char *device, Error **errp)
{
BlockJob *job = find_block_job(device);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
return;
}
trace_qmp_block_job_pause(job);
block_job_pause(job);
}
| 11,638 |
qemu | d918f23efaf486293b96418fe5deaff8a5583304 | 0 | void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
{
struct socket *so, *so_next;
int ret;
global_readfds = readfds;
global_writefds = writefds;
global_xfds = xfds;
/* Update time */
updtime();
/*
* See if anything has timed out
*/
if (link_up) {
if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
tcp_fasttimo();
time_fasttimo = 0;
}
if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
ip_slowtimo();
tcp_slowtimo();
last_slowtimo = curtime;
}
}
/*
* Check sockets
*/
if (link_up) {
/*
* Check TCP sockets
*/
for (so = tcb.so_next; so != &tcb; so = so_next) {
so_next = so->so_next;
/*
* FD_ISSET is meaningless on these sockets
* (and they can crash the program)
*/
if (so->so_state & SS_NOFDREF || so->s == -1)
continue;
/*
* Check for URG data
* This will soread as well, so no need to
* test for readfds below if this succeeds
*/
if (FD_ISSET(so->s, xfds))
sorecvoob(so);
/*
* Check sockets for reading
*/
else if (FD_ISSET(so->s, readfds)) {
/*
* Check for incoming connections
*/
if (so->so_state & SS_FACCEPTCONN) {
tcp_connect(so);
continue;
} /* else */
ret = soread(so);
/* Output it if we read something */
if (ret > 0)
tcp_output(sototcpcb(so));
}
/*
* Check sockets for writing
*/
if (FD_ISSET(so->s, writefds)) {
/*
* Check for non-blocking, still-connecting sockets
*/
if (so->so_state & SS_ISFCONNECTING) {
/* Connected */
so->so_state &= ~SS_ISFCONNECTING;
ret = send(so->s, (const void *) &ret, 0, 0);
if (ret < 0) {
/* XXXXX Must fix, zero bytes is a NOP */
if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue;
/* else failed */
so->so_state &= SS_PERSISTENT_MASK;
so->so_state |= SS_NOFDREF;
}
/* else so->so_state &= ~SS_ISFCONNECTING; */
/*
* Continue tcp_input
*/
tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);
/* continue; */
} else
ret = sowrite(so);
/*
* XXXXX If we wrote something (a lot), there
* could be a need for a window update.
* In the worst case, the remote will send
* a window probe to get things going again
*/
}
/*
* Probe a still-connecting, non-blocking socket
* to check if it's still alive
*/
#ifdef PROBE_CONN
if (so->so_state & SS_ISFCONNECTING) {
ret = recv(so->s, (char *)&ret, 0,0);
if (ret < 0) {
/* XXX */
if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue; /* Still connecting, continue */
/* else failed */
so->so_state &= SS_PERSISTENT_MASK;
so->so_state |= SS_NOFDREF;
/* tcp_input will take care of it */
} else {
ret = send(so->s, &ret, 0,0);
if (ret < 0) {
/* XXX */
if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue;
/* else failed */
so->so_state &= SS_PERSISTENT_MASK;
so->so_state |= SS_NOFDREF;
} else
so->so_state &= ~SS_ISFCONNECTING;
}
tcp_input((struct mbuf *)NULL, sizeof(struct ip),so);
} /* SS_ISFCONNECTING */
#endif
}
/*
* Now UDP sockets.
* Incoming packets are sent straight away, they're not buffered.
* Incoming UDP data isn't buffered either.
*/
for (so = udb.so_next; so != &udb; so = so_next) {
so_next = so->so_next;
if (so->s != -1 && FD_ISSET(so->s, readfds)) {
sorecvfrom(so);
}
}
}
/*
* See if we can start outputting
*/
if (if_queued && link_up)
if_start();
/* clear global file descriptor sets.
* these reside on the stack in vl.c
* so they're unusable if we're not in
* slirp_select_fill or slirp_select_poll.
*/
global_readfds = NULL;
global_writefds = NULL;
global_xfds = NULL;
}
| 11,639 |
qemu | aea14095ea91f792ee43ee52fe6032cd8cdd7190 | 0 | static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
int rw, int tlb_error)
{
CPUState *cs = CPU(mips_env_get_cpu(env));
int exception = 0, error_code = 0;
switch (tlb_error) {
default:
case TLBRET_BADADDR:
/* Reference to kernel address from user mode or supervisor mode */
/* Reference to supervisor address from user mode */
if (rw == MMU_DATA_STORE) {
exception = EXCP_AdES;
} else {
exception = EXCP_AdEL;
}
break;
case TLBRET_NOMATCH:
/* No TLB match for a mapped address */
if (rw == MMU_DATA_STORE) {
exception = EXCP_TLBS;
} else {
exception = EXCP_TLBL;
}
error_code = 1;
break;
case TLBRET_INVALID:
/* TLB match with no valid bit */
if (rw == MMU_DATA_STORE) {
exception = EXCP_TLBS;
} else {
exception = EXCP_TLBL;
}
break;
case TLBRET_DIRTY:
/* TLB match but 'D' bit is cleared */
exception = EXCP_LTLBL;
break;
case TLBRET_XI:
/* Execute-Inhibit Exception */
if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
exception = EXCP_TLBXI;
} else {
exception = EXCP_TLBL;
}
break;
case TLBRET_RI:
/* Read-Inhibit Exception */
if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {
exception = EXCP_TLBRI;
} else {
exception = EXCP_TLBL;
}
break;
}
/* Raise exception */
env->CP0_BadVAddr = address;
env->CP0_Context = (env->CP0_Context & ~0x007fffff) |
((address >> 9) & 0x007ffff0);
env->CP0_EntryHi =
(env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
#if defined(TARGET_MIPS64)
env->CP0_EntryHi &= env->SEGMask;
env->CP0_XContext = (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
((address & 0xC00000000000ULL) >> (55 - env->SEGBITS)) |
((address & ((1ULL << env->SEGBITS) - 1) & 0xFFFFFFFFFFFFE000ULL) >> 9);
#endif
cs->exception_index = exception;
env->error_code = error_code;
}
| 11,640 |
FFmpeg | 6796a1dd8c14843b77925cb83a3ef88706ae1dd0 | 0 | void ff_put_h264_qpel4_mc20_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_hz_4w_msa(src - 2, stride, dst, stride, 4);
}
| 11,643 |
FFmpeg | 95e2317ed85502dd8d96bcd9b12084dbfb8f9e8e | 0 | static int roq_encode_video(RoqContext *enc)
{
RoqTempdata *tempData = enc->tmpData;
int i, ret;
memset(tempData, 0, sizeof(*tempData));
ret = create_cel_evals(enc, tempData);
if (ret < 0)
return ret;
ret = generate_new_codebooks(enc, tempData);
if (ret < 0)
return ret;
if (enc->framesSinceKeyframe >= 1) {
motion_search(enc, 8);
motion_search(enc, 4);
}
retry_encode:
for (i=0; i<enc->width*enc->height/64; i++)
gather_data_for_cel(tempData->cel_evals + i, enc, tempData);
/* Quake 3 can't handle chunks bigger than 65535 bytes */
if (tempData->mainChunkSize/8 > 65535) {
av_log(enc->avctx, AV_LOG_ERROR,
"Warning, generated a frame too big (%d > 65535), "
"try using a smaller qscale value.\n",
tempData->mainChunkSize/8);
enc->lambda *= 1.5;
tempData->mainChunkSize = 0;
memset(tempData->used_option, 0, sizeof(tempData->used_option));
memset(tempData->codebooks.usedCB4, 0,
sizeof(tempData->codebooks.usedCB4));
memset(tempData->codebooks.usedCB2, 0,
sizeof(tempData->codebooks.usedCB2));
goto retry_encode;
}
remap_codebooks(enc, tempData);
write_codebooks(enc, tempData);
reconstruct_and_encode_image(enc, tempData, enc->width, enc->height,
enc->width*enc->height/64);
enc->avctx->coded_frame = enc->current_frame;
/* Rotate frame history */
FFSWAP(AVFrame *, enc->current_frame, enc->last_frame);
FFSWAP(motion_vect *, enc->last_motion4, enc->this_motion4);
FFSWAP(motion_vect *, enc->last_motion8, enc->this_motion8);
av_free(tempData->cel_evals);
av_free(tempData->closest_cb2);
enc->framesSinceKeyframe++;
return 0;
}
| 11,644 |
FFmpeg | 4977e467a50a690a46af5988d568eaab2e5933c7 | 0 | static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
{
TAKDemuxContext *tc = s->priv_data;
int ret;
if (tc->mlast_frame) {
AVIOContext *pb = s->pb;
int64_t size, left;
left = tc->data_end - avio_tell(s->pb);
size = FFMIN(left, 1024);
if (size <= 0)
return AVERROR_EOF;
ret = av_get_packet(pb, pkt, size);
if (ret < 0)
return ret;
pkt->stream_index = 0;
} else {
ret = ff_raw_read_partial_packet(s, pkt);
}
return ret;
}
| 11,645 |
qemu | 2958620f67dcfd11476e62b4ca704dae0b978ea3 | 1 | uint64_t helper_mullv (uint64_t op1, uint64_t op2)
{
int64_t res = (int64_t)op1 * (int64_t)op2;
if (unlikely((int32_t)res != res)) {
arith_excp(env, GETPC(), EXC_M_IOV, 0);
}
return (int64_t)((int32_t)res);
}
| 11,647 |
qemu | 27bb0b2d6f80f058bdb6fcc8fcdfa69b0c8a6d71 | 1 | uint32_t hpet_in_legacy_mode(void)
{
if (hpet_statep)
return hpet_statep->config & HPET_CFG_LEGACY;
else
return 0;
}
| 11,648 |
FFmpeg | eee2cbff77d957e19c8e7d4407a27a5f42fef5f6 | 1 | make_setup_request (AVFormatContext *s, const char *host, int port,
int lower_transport, const char *real_challenge)
{
RTSPState *rt = s->priv_data;
int j, i, err;
RTSPStream *rtsp_st;
RTSPHeader reply1, *reply = &reply1;
char cmd[2048];
const char *trans_pref;
if (rt->server_type == RTSP_SERVER_REAL)
trans_pref = "x-pn-tng";
else
trans_pref = "RTP/AVP";
/* for each stream, make the setup request */
/* XXX: we assume the same server is used for the control of each
RTSP stream */
for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
char transport[2048];
rtsp_st = rt->rtsp_streams[i];
/* RTP/UDP */
if (lower_transport == RTSP_LOWER_TRANSPORT_UDP) {
char buf[256];
/* first try in specified port range */
if (RTSP_RTP_PORT_MIN != 0) {
while(j <= RTSP_RTP_PORT_MAX) {
snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j);
j += 2; /* we will use two port by rtp stream (rtp and rtcp) */
if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) {
goto rtp_opened;
}
}
}
/* then try on any port
** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) {
** err = AVERROR_INVALIDDATA;
** goto fail;
** }
*/
rtp_opened:
port = rtp_get_local_port(rtsp_st->rtp_handle);
snprintf(transport, sizeof(transport) - 1,
"%s/UDP;unicast;client_port=%d",
trans_pref, port);
if (rt->server_type == RTSP_SERVER_RTP)
av_strlcatf(transport, sizeof(transport), "-%d", port + 1);
}
/* RTP/TCP */
else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) {
snprintf(transport, sizeof(transport) - 1,
"%s/TCP", trans_pref);
}
else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) {
snprintf(transport, sizeof(transport) - 1,
"%s/UDP;multicast", trans_pref);
}
if (rt->server_type == RTSP_SERVER_REAL)
av_strlcat(transport, ";mode=play", sizeof(transport));
snprintf(cmd, sizeof(cmd),
"SETUP %s RTSP/1.0\r\n"
"Transport: %s\r\n",
rtsp_st->control_url, transport);
if (i == 0 && rt->server_type == RTSP_SERVER_REAL) {
char real_res[41], real_csum[9];
ff_rdt_calc_response_and_checksum(real_res, real_csum,
real_challenge);
av_strlcatf(cmd, sizeof(cmd),
"If-Match: %s\r\n"
"RealChallenge2: %s, sd=%s\r\n",
rt->session_id, real_res, real_csum);
}
rtsp_send_cmd(s, cmd, reply, NULL);
if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) {
err = 1;
goto fail;
} else if (reply->status_code != RTSP_STATUS_OK ||
reply->nb_transports != 1) {
err = AVERROR_INVALIDDATA;
goto fail;
}
/* XXX: same protocol for all streams is required */
if (i > 0) {
if (reply->transports[0].lower_transport != rt->lower_transport) {
err = AVERROR_INVALIDDATA;
goto fail;
}
} else {
rt->lower_transport = reply->transports[0].lower_transport;
}
/* close RTP connection if not choosen */
if (reply->transports[0].lower_transport != RTSP_LOWER_TRANSPORT_UDP &&
(lower_transport == RTSP_LOWER_TRANSPORT_UDP)) {
url_close(rtsp_st->rtp_handle);
rtsp_st->rtp_handle = NULL;
}
switch(reply->transports[0].lower_transport) {
case RTSP_LOWER_TRANSPORT_TCP:
rtsp_st->interleaved_min = reply->transports[0].interleaved_min;
rtsp_st->interleaved_max = reply->transports[0].interleaved_max;
break;
case RTSP_LOWER_TRANSPORT_UDP:
{
char url[1024];
/* XXX: also use address if specified */
snprintf(url, sizeof(url), "rtp://%s:%d",
host, reply->transports[0].server_port_min);
if (rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
}
break;
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
{
char url[1024];
struct in_addr in;
in.s_addr = htonl(reply->transports[0].destination);
snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d",
inet_ntoa(in),
reply->transports[0].port_min,
reply->transports[0].ttl);
if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
}
break;
}
if ((err = rtsp_open_transport_ctx(s, rtsp_st)))
goto fail;
}
if (rt->server_type == RTSP_SERVER_REAL)
rt->need_subscription = 1;
return 0;
fail:
for (i=0; i<rt->nb_rtsp_streams; i++) {
if (rt->rtsp_streams[i]->rtp_handle) {
url_close(rt->rtsp_streams[i]->rtp_handle);
rt->rtsp_streams[i]->rtp_handle = NULL;
}
}
return err;
}
| 11,649 |
FFmpeg | f1baafac7129c3bb8d4abaaa899988c7a51ca5cd | 1 | static int ipvideo_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
IpvideoContext *s = avctx->priv_data;
AVFrame *frame = data;
int ret;
int send_buffer;
int frame_format;
int video_data_size;
if (av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, NULL)) {
av_frame_unref(s->last_frame);
av_frame_unref(s->second_last_frame);
if (buf_size < 8)
return AVERROR_INVALIDDATA;
frame_format = AV_RL8(buf);
send_buffer = AV_RL8(buf + 1);
video_data_size = AV_RL16(buf + 2);
s->decoding_map_size = AV_RL16(buf + 4);
s->skip_map_size = AV_RL16(buf + 6);
switch(frame_format) {
case 0x06:
if (s->decoding_map_size) {
av_log(avctx, AV_LOG_ERROR, "Decoding map for format 0x06\n");
return AVERROR_INVALIDDATA;
if (s->skip_map_size) {
av_log(avctx, AV_LOG_ERROR, "Skip map for format 0x06\n");
return AVERROR_INVALIDDATA;
if (s->is_16bpp) {
av_log(avctx, AV_LOG_ERROR, "Video format 0x06 does not support 16bpp movies\n");
return AVERROR_INVALIDDATA;
/* Decoding map for 0x06 frame format is at the top of pixeldata */
s->decoding_map_size = ((s->avctx->width / 8) * (s->avctx->height / 8)) * 2;
s->decoding_map = buf + 8 + 14; /* 14 bits of op data */
video_data_size -= s->decoding_map_size + 14;
if (video_data_size <= 0)
return AVERROR_INVALIDDATA;
if (buf_size < 8 + s->decoding_map_size + 14 + video_data_size)
return AVERROR_INVALIDDATA;
bytestream2_init(&s->stream_ptr, buf + 8 + s->decoding_map_size + 14, video_data_size);
break;
case 0x10:
if (! s->decoding_map_size) {
av_log(avctx, AV_LOG_ERROR, "Empty decoding map for format 0x10\n");
return AVERROR_INVALIDDATA;
if (! s->skip_map_size) {
av_log(avctx, AV_LOG_ERROR, "Empty skip map for format 0x10\n");
return AVERROR_INVALIDDATA;
if (s->is_16bpp) {
av_log(avctx, AV_LOG_ERROR, "Video format 0x10 does not support 16bpp movies\n");
return AVERROR_INVALIDDATA;
if (buf_size < 8 + video_data_size + s->decoding_map_size + s->skip_map_size)
return AVERROR_INVALIDDATA;
bytestream2_init(&s->stream_ptr, buf + 8, video_data_size);
s->decoding_map = buf + 8 + video_data_size;
s->skip_map = buf + 8 + video_data_size + s->decoding_map_size;
break;
case 0x11:
if (! s->decoding_map_size) {
av_log(avctx, AV_LOG_ERROR, "Empty decoding map for format 0x11\n");
return AVERROR_INVALIDDATA;
if (s->skip_map_size) {
av_log(avctx, AV_LOG_ERROR, "Skip map for format 0x11\n");
return AVERROR_INVALIDDATA;
if (buf_size < 8 + video_data_size + s->decoding_map_size)
return AVERROR_INVALIDDATA;
bytestream2_init(&s->stream_ptr, buf + 8, video_data_size);
s->decoding_map = buf + 8 + video_data_size;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Frame type 0x%02X unsupported\n", frame_format);
/* ensure we can't overread the packet */
if (buf_size < 8 + s->decoding_map_size + video_data_size + s->skip_map_size) {
av_log(avctx, AV_LOG_ERROR, "Invalid IP packet size\n");
return AVERROR_INVALIDDATA;
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
if (!s->is_16bpp) {
int size;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
if (pal && size == AVPALETTE_SIZE) {
frame->palette_has_changed = 1;
memcpy(s->pal, pal, AVPALETTE_SIZE);
} else if (pal) {
av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
switch(frame_format) {
case 0x06:
ipvideo_decode_format_06_opcodes(s, frame);
break;
case 0x10:
ipvideo_decode_format_10_opcodes(s, frame);
break;
case 0x11:
ipvideo_decode_format_11_opcodes(s, frame);
break;
*got_frame = send_buffer;
/* shuffle frames */
av_frame_unref(s->second_last_frame);
FFSWAP(AVFrame*, s->second_last_frame, s->last_frame);
if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
/* report that the buffer was completely consumed */
return buf_size; | 11,650 |
qemu | f69a8bde29354493ff8aea64cc9cb3b531d16337 | 1 | static int qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
char *buffer,
Error **errp)
{
QIOChannelWebsockHTTPHeader hdrs[32];
size_t nhdrs = G_N_ELEMENTS(hdrs);
const char *protocols = NULL, *version = NULL, *key = NULL,
*host = NULL, *connection = NULL, *upgrade = NULL;
nhdrs = qio_channel_websock_extract_headers(buffer, hdrs, nhdrs, errp);
if (!nhdrs) {
return -1;
}
protocols = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_PROTOCOL);
if (!protocols) {
error_setg(errp, "Missing websocket protocol header data");
return -1;
}
version = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_VERSION);
if (!version) {
error_setg(errp, "Missing websocket version header data");
return -1;
}
key = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_KEY);
if (!key) {
error_setg(errp, "Missing websocket key header data");
return -1;
}
host = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_HOST);
if (!host) {
error_setg(errp, "Missing websocket host header data");
return -1;
}
connection = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_CONNECTION);
if (!connection) {
error_setg(errp, "Missing websocket connection header data");
return -1;
}
upgrade = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_UPGRADE);
if (!upgrade) {
error_setg(errp, "Missing websocket upgrade header data");
return -1;
}
if (!g_strrstr(protocols, QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY)) {
error_setg(errp, "No '%s' protocol is supported by client '%s'",
QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY, protocols);
return -1;
}
if (!g_str_equal(version, QIO_CHANNEL_WEBSOCK_SUPPORTED_VERSION)) {
error_setg(errp, "Version '%s' is not supported by client '%s'",
QIO_CHANNEL_WEBSOCK_SUPPORTED_VERSION, version);
return -1;
}
if (strlen(key) != QIO_CHANNEL_WEBSOCK_CLIENT_KEY_LEN) {
error_setg(errp, "Key length '%zu' was not as expected '%d'",
strlen(key), QIO_CHANNEL_WEBSOCK_CLIENT_KEY_LEN);
return -1;
}
if (!g_strrstr(connection, QIO_CHANNEL_WEBSOCK_CONNECTION_UPGRADE)) {
error_setg(errp, "No connection upgrade requested '%s'", connection);
return -1;
}
if (!g_str_equal(upgrade, QIO_CHANNEL_WEBSOCK_UPGRADE_WEBSOCKET)) {
error_setg(errp, "Incorrect upgrade method '%s'", upgrade);
return -1;
}
return qio_channel_websock_handshake_send_response(ioc, key, errp);
}
| 11,651 |
FFmpeg | 6d1270a0f9ededd37ed14bde52b8ee69b99e8a7f | 0 | int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
int *frame_size_ptr,
AVPacket *avpkt)
{
AVFrame frame;
int ret, got_frame = 0;
if (avctx->get_buffer != avcodec_default_get_buffer) {
av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
"avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
av_log(avctx, AV_LOG_ERROR, "Please port your application to "
"avcodec_decode_audio4()\n");
avctx->get_buffer = avcodec_default_get_buffer;
}
ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
if (ret >= 0 && got_frame) {
int ch, plane_size;
int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
frame.nb_samples,
avctx->sample_fmt, 1);
if (*frame_size_ptr < data_size) {
av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
"the current frame (%d < %d)\n", *frame_size_ptr, data_size);
return AVERROR(EINVAL);
}
memcpy(samples, frame.extended_data[0], plane_size);
if (planar && avctx->channels > 1) {
uint8_t *out = ((uint8_t *)samples) + plane_size;
for (ch = 1; ch < avctx->channels; ch++) {
memcpy(out, frame.extended_data[ch], plane_size);
out += plane_size;
}
}
*frame_size_ptr = data_size;
} else {
*frame_size_ptr = 0;
}
return ret;
}
| 11,652 |
FFmpeg | 662234a9a22f1cd0f0ac83b8bb1ffadedca90c0a | 0 | void ff_put_h264_qpel16_mc02_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
avc_luma_vt_16w_msa(src - (stride * 2), stride, dst, stride, 16);
}
| 11,653 |
FFmpeg | 7e7e59409294af9caa63808e56c5cc824c98b4fc | 0 | int img_convert(AVPicture *dst, int dst_pix_fmt,
AVPicture *src, int src_pix_fmt,
int src_width, int src_height)
{
static int inited;
int i, ret, dst_width, dst_height, int_pix_fmt;
PixFmtInfo *src_pix, *dst_pix;
ConvertEntry *ce;
AVPicture tmp1, *tmp = &tmp1;
if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB ||
dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB)
return -1;
if (src_width <= 0 || src_height <= 0)
return 0;
if (!inited) {
inited = 1;
img_convert_init();
}
dst_width = src_width;
dst_height = src_height;
dst_pix = &pix_fmt_info[dst_pix_fmt];
src_pix = &pix_fmt_info[src_pix_fmt];
if (src_pix_fmt == dst_pix_fmt) {
/* XXX: incorrect */
/* same format: just copy */
for(i = 0; i < dst_pix->nb_components; i++) {
int w, h;
w = dst_width;
h = dst_height;
if (is_yuv_planar(dst_pix) && (i == 1 || i == 2)) {
w >>= dst_pix->x_chroma_shift;
h >>= dst_pix->y_chroma_shift;
}
img_copy(dst->data[i], dst->linesize[i],
src->data[i], src->linesize[i],
w, h);
}
return 0;
}
ce = &convert_table[src_pix_fmt][dst_pix_fmt];
if (ce->convert) {
/* specific convertion routine */
ce->convert(dst, src, dst_width, dst_height);
return 0;
}
/* gray to YUV */
if (is_yuv_planar(dst_pix) &&
src_pix_fmt == PIX_FMT_GRAY8) {
int w, h, y;
uint8_t *d;
if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
img_copy(dst->data[0], dst->linesize[0],
src->data[0], src->linesize[0],
dst_width, dst_height);
} else {
img_apply_table(dst->data[0], dst->linesize[0],
src->data[0], src->linesize[0],
dst_width, dst_height,
y_jpeg_to_ccir);
}
/* fill U and V with 128 */
w = dst_width;
h = dst_height;
w >>= dst_pix->x_chroma_shift;
h >>= dst_pix->y_chroma_shift;
for(i = 1; i <= 2; i++) {
d = dst->data[i];
for(y = 0; y< h; y++) {
memset(d, 128, w);
d += dst->linesize[i];
}
}
return 0;
}
/* YUV to gray */
if (is_yuv_planar(src_pix) &&
dst_pix_fmt == PIX_FMT_GRAY8) {
if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
img_copy(dst->data[0], dst->linesize[0],
src->data[0], src->linesize[0],
dst_width, dst_height);
} else {
img_apply_table(dst->data[0], dst->linesize[0],
src->data[0], src->linesize[0],
dst_width, dst_height,
y_ccir_to_jpeg);
}
return 0;
}
/* YUV to YUV planar */
if (is_yuv_planar(dst_pix) && is_yuv_planar(src_pix)) {
int x_shift, y_shift, w, h;
void (*resize_func)(uint8_t *dst, int dst_wrap,
uint8_t *src, int src_wrap,
int width, int height);
/* compute chroma size of the smallest dimensions */
w = dst_width;
h = dst_height;
if (dst_pix->x_chroma_shift >= src_pix->x_chroma_shift)
w >>= dst_pix->x_chroma_shift;
else
w >>= src_pix->x_chroma_shift;
if (dst_pix->y_chroma_shift >= src_pix->y_chroma_shift)
h >>= dst_pix->y_chroma_shift;
else
h >>= src_pix->y_chroma_shift;
x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
if (x_shift == 0 && y_shift == 0) {
resize_func = img_copy;
} else if (x_shift == 0 && y_shift == 1) {
resize_func = shrink2;
} else if (x_shift == 1 && y_shift == 1) {
resize_func = shrink22;
} else if (x_shift == -1 && y_shift == -1) {
resize_func = grow22;
} else if (x_shift == -1 && y_shift == 1) {
resize_func = conv411;
} else {
/* currently not handled */
return -1;
}
img_copy(dst->data[0], dst->linesize[0],
src->data[0], src->linesize[0],
dst_width, dst_height);
for(i = 1;i <= 2; i++)
resize_func(dst->data[i], dst->linesize[i],
src->data[i], src->linesize[i],
dst_width>>dst_pix->x_chroma_shift, dst_height>>dst_pix->y_chroma_shift);
/* if yuv color space conversion is needed, we do it here on
the destination image */
if (dst_pix->color_type != src_pix->color_type) {
const uint8_t *y_table, *c_table;
if (dst_pix->color_type == FF_COLOR_YUV) {
y_table = y_jpeg_to_ccir;
c_table = c_jpeg_to_ccir;
} else {
y_table = y_ccir_to_jpeg;
c_table = c_ccir_to_jpeg;
}
img_apply_table(dst->data[0], dst->linesize[0],
dst->data[0], dst->linesize[0],
dst_width, dst_height,
y_table);
for(i = 1;i <= 2; i++)
img_apply_table(dst->data[i], dst->linesize[i],
dst->data[i], dst->linesize[i],
dst_width>>dst_pix->x_chroma_shift,
dst_height>>dst_pix->y_chroma_shift,
c_table);
}
return 0;
}
/* try to use an intermediate format */
if (src_pix_fmt == PIX_FMT_YUV422 ||
dst_pix_fmt == PIX_FMT_YUV422) {
/* specific case: convert to YUV422P first */
int_pix_fmt = PIX_FMT_YUV422P;
} else if ((src_pix->color_type == FF_COLOR_GRAY &&
src_pix_fmt != PIX_FMT_GRAY8) ||
(dst_pix->color_type == FF_COLOR_GRAY &&
dst_pix_fmt != PIX_FMT_GRAY8)) {
/* gray8 is the normalized format */
int_pix_fmt = PIX_FMT_GRAY8;
} else if ((is_yuv_planar(src_pix) &&
src_pix_fmt != PIX_FMT_YUV444P &&
src_pix_fmt != PIX_FMT_YUVJ444P)) {
/* yuv444 is the normalized format */
if (src_pix->color_type == FF_COLOR_YUV_JPEG)
int_pix_fmt = PIX_FMT_YUVJ444P;
else
int_pix_fmt = PIX_FMT_YUV444P;
} else if ((is_yuv_planar(dst_pix) &&
dst_pix_fmt != PIX_FMT_YUV444P &&
dst_pix_fmt != PIX_FMT_YUVJ444P)) {
/* yuv444 is the normalized format */
if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
int_pix_fmt = PIX_FMT_YUVJ444P;
else
int_pix_fmt = PIX_FMT_YUV444P;
} else {
/* the two formats are rgb or gray8 or yuv[j]444p */
if (src_pix->is_alpha && dst_pix->is_alpha)
int_pix_fmt = PIX_FMT_RGBA32;
else
int_pix_fmt = PIX_FMT_RGB24;
}
if (avpicture_alloc(tmp, int_pix_fmt, dst_width, dst_height) < 0)
return -1;
ret = -1;
if (img_convert(tmp, int_pix_fmt,
src, src_pix_fmt, src_width, src_height) < 0)
goto fail1;
if (img_convert(dst, dst_pix_fmt,
tmp, int_pix_fmt, dst_width, dst_height) < 0)
goto fail1;
ret = 0;
fail1:
avpicture_free(tmp);
return ret;
}
| 11,654 |
FFmpeg | 61873c4a4436f2c516e14d6a00a2b856fa93f818 | 1 | static void render_fragments(Vp3DecodeContext *s,
int first_fragment,
int fragment_width,
int fragment_height,
int plane /* 0 = Y, 1 = U, 2 = V */)
{
int x, y;
int m, n;
int i = first_fragment;
int j;
int16_t *dequantizer;
DCTELEM dequant_block[64];
unsigned char *output_plane;
unsigned char *last_plane;
unsigned char *golden_plane;
int stride;
debug_vp3(" vp3: rendering final fragments for %s\n",
(plane == 0) ? "Y plane" : (plane == 1) ? "U plane" : "V plane");
/* set up plane-specific parameters */
if (plane == 0) {
dequantizer = s->intra_y_dequant;
output_plane = s->current_frame.data[0];
last_plane = s->current_frame.data[0];
golden_plane = s->current_frame.data[0];
stride = -s->current_frame.linesize[0];
} else if (plane == 1) {
dequantizer = s->intra_c_dequant;
output_plane = s->current_frame.data[1];
last_plane = s->current_frame.data[1];
golden_plane = s->current_frame.data[1];
stride = -s->current_frame.linesize[1];
} else {
dequantizer = s->intra_c_dequant;
output_plane = s->current_frame.data[2];
last_plane = s->current_frame.data[2];
golden_plane = s->current_frame.data[2];
stride = -s->current_frame.linesize[2];
}
/* for each fragment row... */
for (y = 0; y < fragment_height; y++) {
/* for each fragment in a row... */
for (x = 0; x < fragment_width; x++, i++) {
/* transform if this block was coded */
if (s->all_fragments[i].coding_method == MODE_INTRA) {
/* dequantize the DCT coefficients */
for (j = 0; j < 64; j++)
dequant_block[dequant_index[j]] =
s->all_fragments[i].coeffs[j] *
dequantizer[j];
dequant_block[0] += 1024;
debug_idct("fragment %d:\n", i);
debug_idct("dequantized block:\n");
for (m = 0; m < 8; m++) {
for (n = 0; n < 8; n++) {
debug_idct(" %5d", dequant_block[m * 8 + n]);
}
debug_idct("\n");
}
debug_idct("\n");
/* invert DCT and place in final output */
s->dsp.idct_put(
output_plane + s->all_fragments[i].first_pixel,
stride, dequant_block);
/*
debug_idct("idct block:\n");
for (m = 0; m < 8; m++) {
for (n = 0; n < 8; n++) {
debug_idct(" %3d", pixels[m * 8 + n]);
}
debug_idct("\n");
}
debug_idct("\n");
*/
} else if (s->all_fragments[i].coding_method == MODE_COPY) {
/* copy directly from the previous frame */
for (m = 0; m < 8; m++)
memcpy(
output_plane + s->all_fragments[i].first_pixel + stride * m,
last_plane + s->all_fragments[i].first_pixel + stride * m,
8);
} else {
/* carry out the motion compensation */
}
}
}
emms_c();
}
| 11,655 |
qemu | c3ca988d2b0ee94dc8d53eff4b1c2de4ac06a270 | 1 | static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags)
{
BDRVRBDState *s = bs->opaque;
char pool[RBD_MAX_POOL_NAME_SIZE];
char snap_buf[RBD_MAX_SNAP_NAME_SIZE];
char conf[RBD_MAX_CONF_SIZE];
char clientname_buf[RBD_MAX_CONF_SIZE];
char *clientname;
QemuOpts *opts;
Error *local_err = NULL;
const char *filename;
int r;
opts = qemu_opts_create_nofail(&runtime_opts);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
qemu_opts_del(opts);
return -EINVAL;
}
filename = qemu_opt_get(opts, "filename");
qemu_opts_del(opts);
if (qemu_rbd_parsename(filename, pool, sizeof(pool),
snap_buf, sizeof(snap_buf),
s->name, sizeof(s->name),
conf, sizeof(conf)) < 0) {
return -EINVAL;
}
clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
r = rados_create(&s->cluster, clientname);
if (r < 0) {
error_report("error initializing");
return r;
}
s->snap = NULL;
if (snap_buf[0] != '\0') {
s->snap = g_strdup(snap_buf);
}
/*
* Fallback to more conservative semantics if setting cache
* options fails. Ignore errors from setting rbd_cache because the
* only possible error is that the option does not exist, and
* librbd defaults to no caching. If write through caching cannot
* be set up, fall back to no caching.
*/
if (flags & BDRV_O_NOCACHE) {
rados_conf_set(s->cluster, "rbd_cache", "false");
} else {
rados_conf_set(s->cluster, "rbd_cache", "true");
}
if (strstr(conf, "conf=") == NULL) {
/* try default location, but ignore failure */
rados_conf_read_file(s->cluster, NULL);
}
if (conf[0] != '\0') {
r = qemu_rbd_set_conf(s->cluster, conf);
if (r < 0) {
error_report("error setting config options");
goto failed_shutdown;
}
}
r = rados_connect(s->cluster);
if (r < 0) {
error_report("error connecting");
goto failed_shutdown;
}
r = rados_ioctx_create(s->cluster, pool, &s->io_ctx);
if (r < 0) {
error_report("error opening pool %s", pool);
goto failed_shutdown;
}
r = rbd_open(s->io_ctx, s->name, &s->image, s->snap);
if (r < 0) {
error_report("error reading header from %s", s->name);
goto failed_open;
}
bs->read_only = (s->snap != NULL);
s->event_reader_pos = 0;
r = qemu_pipe(s->fds);
if (r < 0) {
error_report("error opening eventfd");
goto failed;
}
fcntl(s->fds[0], F_SETFL, O_NONBLOCK);
fcntl(s->fds[1], F_SETFL, O_NONBLOCK);
qemu_aio_set_fd_handler(s->fds[RBD_FD_READ], qemu_rbd_aio_event_reader,
NULL, qemu_rbd_aio_flush_cb, s);
return 0;
failed:
rbd_close(s->image);
failed_open:
rados_ioctx_destroy(s->io_ctx);
failed_shutdown:
rados_shutdown(s->cluster);
g_free(s->snap);
return r;
}
| 11,656 |
qemu | ea697449884d83b83fefbc9cd87bdde0c94b49d6 | 1 | static void vnc_client_read(VncState *vs)
{
ssize_t ret;
#ifdef CONFIG_VNC_SASL
if (vs->sasl.conn && vs->sasl.runSSF)
ret = vnc_client_read_sasl(vs);
else
#endif /* CONFIG_VNC_SASL */
ret = vnc_client_read_plain(vs);
if (!ret) {
if (vs->disconnecting) {
vnc_disconnect_finish(vs);
}
return;
}
while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) {
size_t len = vs->read_handler_expect;
int ret;
ret = vs->read_handler(vs, vs->input.buffer, len);
if (vs->disconnecting) {
vnc_disconnect_finish(vs);
return;
}
if (!ret) {
buffer_advance(&vs->input, len);
} else {
vs->read_handler_expect = ret;
}
}
}
| 11,658 |
FFmpeg | 2a91038e13a00897fde89ad65a36012985687793 | 1 | static int wav_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
int64_t left;
AVStream *st;
WAVDemuxContext *wav = s->priv_data;
if (CONFIG_SPDIF_DEMUXER && wav->spdif == 0 &&
s->streams[0]->codec->codec_tag == 1) {
enum AVCodecID codec;
ret = ff_spdif_probe(s->pb->buffer, s->pb->buf_end - s->pb->buffer,
&codec);
if (ret > AVPROBE_SCORE_EXTENSION) {
s->streams[0]->codec->codec_id = codec;
wav->spdif = 1;
} else {
wav->spdif = -1;
}
}
if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)
return ff_spdif_read_packet(s, pkt);
if (wav->smv_data_ofs > 0) {
int64_t audio_dts, video_dts;
smv_retry:
audio_dts = s->streams[0]->cur_dts;
video_dts = s->streams[1]->cur_dts;
if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) {
audio_dts = av_rescale_q(audio_dts, s->streams[0]->time_base, AV_TIME_BASE_Q);
video_dts = av_rescale_q(video_dts, s->streams[1]->time_base, AV_TIME_BASE_Q);
/*We always return a video frame first to get the pixel format first*/
wav->smv_last_stream = wav->smv_given_first ? video_dts > audio_dts : 0;
wav->smv_given_first = 1;
}
wav->smv_last_stream = !wav->smv_last_stream;
wav->smv_last_stream |= wav->audio_eof;
wav->smv_last_stream &= !wav->smv_eof;
if (wav->smv_last_stream) {
uint64_t old_pos = avio_tell(s->pb);
uint64_t new_pos = wav->smv_data_ofs +
wav->smv_block * wav->smv_block_size;
if (avio_seek(s->pb, new_pos, SEEK_SET) < 0) {
ret = AVERROR_EOF;
goto smv_out;
}
size = avio_rl24(s->pb);
ret = av_get_packet(s->pb, pkt, size);
if (ret < 0)
goto smv_out;
pkt->pos -= 3;
pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt;
wav->smv_cur_pt++;
if (wav->smv_frames_per_jpeg > 0)
wav->smv_cur_pt %= wav->smv_frames_per_jpeg;
if (!wav->smv_cur_pt)
wav->smv_block++;
pkt->stream_index = 1;
smv_out:
avio_seek(s->pb, old_pos, SEEK_SET);
if (ret == AVERROR_EOF) {
wav->smv_eof = 1;
goto smv_retry;
}
return ret;
}
}
st = s->streams[0];
left = wav->data_end - avio_tell(s->pb);
if (wav->ignore_length)
left = INT_MAX;
if (left <= 0) {
if (CONFIG_W64_DEMUXER && wav->w64)
left = find_guid(s->pb, ff_w64_guid_data) - 24;
else
left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
if (left < 0) {
wav->audio_eof = 1;
if (wav->smv_data_ofs > 0 && !wav->smv_eof)
goto smv_retry;
return AVERROR_EOF;
}
wav->data_end = avio_tell(s->pb) + left;
}
size = MAX_SIZE;
if (st->codec->block_align > 1) {
if (size < st->codec->block_align)
size = st->codec->block_align;
size = (size / st->codec->block_align) * st->codec->block_align;
}
size = FFMIN(size, left);
ret = av_get_packet(s->pb, pkt, size);
if (ret < 0)
return ret;
pkt->stream_index = 0;
return ret;
}
| 11,659 |
qemu | d17008bc2914d62fd0af6a8f313604ae9f9a102c | 1 | static uint32_t hpet_time_after(uint64_t a, uint64_t b)
{
return ((int32_t)(b) - (int32_t)(a) < 0);
}
| 11,660 |
qemu | e0cb42ae4bc4438ba4ec0760df2d830b8759b255 | 1 | static int xenfb_map_fb(struct XenFB *xenfb)
{
struct xenfb_page *page = xenfb->c.page;
char *protocol = xenfb->c.xendev.protocol;
int n_fbdirs;
xen_pfn_t *pgmfns = NULL;
xen_pfn_t *fbmfns = NULL;
void *map, *pd;
int mode, ret = -1;
/* default to native */
pd = page->pd;
mode = sizeof(unsigned long) * 8;
if (!protocol) {
/*
* Undefined protocol, some guesswork needed.
*
* Old frontends which don't set the protocol use
* one page directory only, thus pd[1] must be zero.
* pd[1] of the 32bit struct layout and the lower
* 32 bits of pd[0] of the 64bit struct layout have
* the same location, so we can check that ...
*/
uint32_t *ptr32 = NULL;
uint32_t *ptr64 = NULL;
#if defined(__i386__)
ptr32 = (void*)page->pd;
ptr64 = ((void*)page->pd) + 4;
#elif defined(__x86_64__)
ptr32 = ((void*)page->pd) - 4;
ptr64 = (void*)page->pd;
#endif
if (ptr32) {
if (ptr32[1] == 0) {
mode = 32;
pd = ptr32;
} else {
mode = 64;
pd = ptr64;
}
}
#if defined(__x86_64__)
} else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {
/* 64bit dom0, 32bit domU */
mode = 32;
pd = ((void*)page->pd) - 4;
#elif defined(__i386__)
} else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {
/* 32bit dom0, 64bit domU */
mode = 64;
pd = ((void*)page->pd) + 4;
#endif
}
if (xenfb->pixels) {
munmap(xenfb->pixels, xenfb->fbpages * XC_PAGE_SIZE);
xenfb->pixels = NULL;
}
xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
n_fbdirs = xenfb->fbpages * mode / 8;
n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
PROT_READ, pgmfns, n_fbdirs);
if (map == NULL)
goto out;
xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
munmap(map, n_fbdirs * XC_PAGE_SIZE);
xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
PROT_READ, fbmfns, xenfb->fbpages);
if (xenfb->pixels == NULL)
goto out;
ret = 0; /* all is fine */
out:
g_free(pgmfns);
g_free(fbmfns);
return ret;
}
| 11,661 |
FFmpeg | fbf1b88589c7d3914ed396011121077412358b5d | 0 | static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
{
VideoPicture *vp;
int dst_pix_fmt;
AVPicture pict;
static struct SwsContext *img_convert_ctx;
/* wait until we have space to put a new picture */
SDL_LockMutex(is->pictq_mutex);
while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
!is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
}
SDL_UnlockMutex(is->pictq_mutex);
if (is->videoq.abort_request)
return -1;
vp = &is->pictq[is->pictq_windex];
/* alloc or resize hardware picture buffer */
if (!vp->bmp ||
vp->width != is->video_st->codec->width ||
vp->height != is->video_st->codec->height) {
SDL_Event event;
vp->allocated = 0;
/* the allocation must be done in the main thread to avoid
locking problems */
event.type = FF_ALLOC_EVENT;
event.user.data1 = is;
SDL_PushEvent(&event);
/* wait until the picture is allocated */
SDL_LockMutex(is->pictq_mutex);
while (!vp->allocated && !is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
}
SDL_UnlockMutex(is->pictq_mutex);
if (is->videoq.abort_request)
return -1;
}
/* if the frame is not skipped, then display it */
if (vp->bmp) {
/* get a pointer on the bitmap */
SDL_LockYUVOverlay (vp->bmp);
dst_pix_fmt = PIX_FMT_YUV420P;
pict.data[0] = vp->bmp->pixels[0];
pict.data[1] = vp->bmp->pixels[2];
pict.data[2] = vp->bmp->pixels[1];
pict.linesize[0] = vp->bmp->pitches[0];
pict.linesize[1] = vp->bmp->pitches[2];
pict.linesize[2] = vp->bmp->pitches[1];
sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
img_convert_ctx = sws_getCachedContext(img_convert_ctx,
is->video_st->codec->width, is->video_st->codec->height,
is->video_st->codec->pix_fmt,
is->video_st->codec->width, is->video_st->codec->height,
dst_pix_fmt, sws_flags, NULL, NULL, NULL);
if (img_convert_ctx == NULL) {
fprintf(stderr, "Cannot initialize the conversion context\n");
exit(1);
}
sws_scale(img_convert_ctx, src_frame->data, src_frame->linesize,
0, is->video_st->codec->height, pict.data, pict.linesize);
/* update the bitmap content */
SDL_UnlockYUVOverlay(vp->bmp);
vp->pts = pts;
/* now we can update the picture count */
if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
is->pictq_windex = 0;
SDL_LockMutex(is->pictq_mutex);
is->pictq_size++;
SDL_UnlockMutex(is->pictq_mutex);
}
return 0;
}
| 11,663 |
FFmpeg | 60b433d905c582ed3656c120b3ffffd0119d5377 | 0 | static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track)
{
int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "wave");
if (track->enc->codec_id != AV_CODEC_ID_QDM2) {
avio_wb32(pb, 12); /* size */
ffio_wfourcc(pb, "frma");
avio_wl32(pb, track->tag);
}
if (track->enc->codec_id == AV_CODEC_ID_AAC) {
/* useless atom needed by mplayer, ipod, not needed by quicktime */
avio_wb32(pb, 12); /* size */
ffio_wfourcc(pb, "mp4a");
avio_wb32(pb, 0);
mov_write_esds_tag(pb, track);
} else if (mov_pcm_le_gt16(track->enc->codec_id)) {
mov_write_enda_tag(pb);
} else if (track->enc->codec_id == AV_CODEC_ID_AMR_NB) {
mov_write_amr_tag(pb, track);
} else if (track->enc->codec_id == AV_CODEC_ID_AC3) {
mov_write_ac3_tag(pb, track);
} else if (track->enc->codec_id == AV_CODEC_ID_ALAC ||
track->enc->codec_id == AV_CODEC_ID_QDM2) {
mov_write_extradata_tag(pb, track);
} else if (track->enc->codec_id == AV_CODEC_ID_ADPCM_MS ||
track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
mov_write_ms_tag(pb, track);
}
avio_wb32(pb, 8); /* size */
avio_wb32(pb, 0); /* null tag */
return update_size(pb, pos);
}
| 11,664 |
FFmpeg | d584533cf38141172e20bae5436629ee17c8ce50 | 0 | int av_read_frame(AVFormatContext *s, AVPacket *pkt)
{
const int genpts = s->flags & AVFMT_FLAG_GENPTS;
int eof = 0;
if (!genpts)
return s->internal->packet_buffer
? read_from_packet_buffer(&s->internal->packet_buffer,
&s->internal->packet_buffer_end, pkt)
: read_frame_internal(s, pkt);
for (;;) {
int ret;
AVPacketList *pktl = s->internal->packet_buffer;
if (pktl) {
AVPacket *next_pkt = &pktl->pkt;
if (next_pkt->dts != AV_NOPTS_VALUE) {
int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;
while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {
if (pktl->pkt.stream_index == next_pkt->stream_index &&
(av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) &&
av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) {
// not B-frame
next_pkt->pts = pktl->pkt.dts;
}
pktl = pktl->next;
}
pktl = s->internal->packet_buffer;
}
/* read packet from packet buffer, if there is data */
if (!(next_pkt->pts == AV_NOPTS_VALUE &&
next_pkt->dts != AV_NOPTS_VALUE && !eof))
return read_from_packet_buffer(&s->internal->packet_buffer,
&s->internal->packet_buffer_end, pkt);
}
ret = read_frame_internal(s, pkt);
if (ret < 0) {
if (pktl && ret != AVERROR(EAGAIN)) {
eof = 1;
continue;
} else
return ret;
}
if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,
&s->internal->packet_buffer_end)) < 0)
return AVERROR(ENOMEM);
}
}
| 11,666 |
qemu | aa92d6c4609e174fc6884e4b7b87367fac33cbe9 | 0 | static int coroutine_fn nfs_co_flush(BlockDriverState *bs)
{
NFSClient *client = bs->opaque;
NFSRPC task;
nfs_co_init_task(client, &task);
if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb,
&task) != 0) {
return -ENOMEM;
}
while (!task.complete) {
nfs_set_events(client);
qemu_coroutine_yield();
}
return task.ret;
}
| 11,667 |
qemu | 82f20e8547ce665e9bb23fdb55374840b846c143 | 0 | static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
{
Error *local_err = NULL;
int64_t bytes = 0;
int64_t objsize;
int obj_order = 0;
const char *pool, *name, *conf, *clientname, *keypairs;
const char *secretid;
rados_t cluster;
rados_ioctx_t io_ctx;
QDict *options = NULL;
QemuOpts *rbd_opts = NULL;
int ret = 0;
secretid = qemu_opt_get(opts, "password-secret");
/* Read out options */
bytes = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
BDRV_SECTOR_SIZE);
objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
if (objsize) {
if ((objsize - 1) & objsize) { /* not a power of 2? */
error_setg(errp, "obj size needs to be power of 2");
ret = -EINVAL;
goto exit;
}
if (objsize < 4096) {
error_setg(errp, "obj size too small");
ret = -EINVAL;
goto exit;
}
obj_order = ctz32(objsize);
}
options = qdict_new();
qemu_rbd_parse_filename(filename, options, &local_err);
if (local_err) {
ret = -EINVAL;
error_propagate(errp, local_err);
goto exit;
}
rbd_opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(rbd_opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto exit;
}
pool = qemu_opt_get(rbd_opts, "pool");
conf = qemu_opt_get(rbd_opts, "conf");
clientname = qemu_opt_get(rbd_opts, "user");
name = qemu_opt_get(rbd_opts, "image");
keypairs = qemu_opt_get(rbd_opts, "keyvalue-pairs");
ret = rados_create(&cluster, clientname);
if (ret < 0) {
error_setg_errno(errp, -ret, "error initializing");
goto exit;
}
/* try default location when conf=NULL, but ignore failure */
ret = rados_conf_read_file(cluster, conf);
if (conf && ret < 0) {
error_setg_errno(errp, -ret, "error reading conf file %s", conf);
ret = -EIO;
goto shutdown;
}
ret = qemu_rbd_set_keypairs(cluster, keypairs, errp);
if (ret < 0) {
ret = -EIO;
goto shutdown;
}
if (qemu_rbd_set_auth(cluster, secretid, errp) < 0) {
ret = -EIO;
goto shutdown;
}
ret = rados_connect(cluster);
if (ret < 0) {
error_setg_errno(errp, -ret, "error connecting");
goto shutdown;
}
ret = rados_ioctx_create(cluster, pool, &io_ctx);
if (ret < 0) {
error_setg_errno(errp, -ret, "error opening pool %s", pool);
goto shutdown;
}
ret = rbd_create(io_ctx, name, bytes, &obj_order);
if (ret < 0) {
error_setg_errno(errp, -ret, "error rbd create");
}
rados_ioctx_destroy(io_ctx);
shutdown:
rados_shutdown(cluster);
exit:
QDECREF(options);
qemu_opts_del(rbd_opts);
return ret;
}
| 11,668 |
qemu | d812b3d68ddf0efe91a088ecc8b177865b0bab8d | 0 | static void port92_init(ISADevice *dev, qemu_irq *a20_out)
{
Port92State *s = PORT92(dev);
s->a20_out = a20_out;
}
| 11,669 |
qemu | a7812ae412311d7d47f8aa85656faadac9d64b56 | 0 | static TCGv gen_mulu_i64_i32(TCGv a, TCGv b)
{
TCGv tmp1 = tcg_temp_new(TCG_TYPE_I64);
TCGv tmp2 = tcg_temp_new(TCG_TYPE_I64);
tcg_gen_extu_i32_i64(tmp1, a);
dead_tmp(a);
tcg_gen_extu_i32_i64(tmp2, b);
dead_tmp(b);
tcg_gen_mul_i64(tmp1, tmp1, tmp2);
return tmp1;
}
| 11,670 |
qemu | 7bd427d801e1e3293a634d3c83beadaa90ffb911 | 0 | static void pxa2xx_rtc_piupdate(PXA2xxRTCState *s)
{
int64_t rt = qemu_get_clock(rt_clock);
if (s->rtsr & (1 << 15))
s->last_swcr += rt - s->last_pi;
s->last_pi = rt;
}
| 11,671 |
qemu | 71ed827abd57dc7947ce3316118d0e601e70fac9 | 0 | int ioinst_handle_ssch(CPUS390XState *env, uint64_t reg1, uint32_t ipb)
{
int cssid, ssid, schid, m;
SubchDev *sch;
ORB *orig_orb, orb;
uint64_t addr;
int ret = -ENODEV;
int cc;
hwaddr len = sizeof(*orig_orb);
if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) {
program_interrupt(env, PGM_OPERAND, 2);
return -EIO;
}
trace_ioinst_sch_id("ssch", cssid, ssid, schid);
addr = decode_basedisp_s(env, ipb);
if (addr & 3) {
program_interrupt(env, PGM_SPECIFICATION, 2);
return -EIO;
}
orig_orb = s390_cpu_physical_memory_map(env, addr, &len, 0);
if (!orig_orb || len != sizeof(*orig_orb)) {
program_interrupt(env, PGM_ADDRESSING, 2);
cc = -EIO;
goto out;
}
copy_orb_from_guest(&orb, orig_orb);
if (!ioinst_orb_valid(&orb)) {
program_interrupt(env, PGM_OPERAND, 2);
cc = -EIO;
goto out;
}
sch = css_find_subch(m, cssid, ssid, schid);
if (sch && css_subch_visible(sch)) {
ret = css_do_ssch(sch, &orb);
}
switch (ret) {
case -ENODEV:
cc = 3;
break;
case -EBUSY:
cc = 2;
break;
case 0:
cc = 0;
break;
default:
cc = 1;
break;
}
out:
s390_cpu_physical_memory_unmap(env, orig_orb, len, 0);
return cc;
}
| 11,672 |
qemu | 7e01376daea75e888c370aab521a7d4aeaf2ffd1 | 0 | int ioinst_handle_tpi(S390CPU *cpu, uint32_t ipb)
{
CPUS390XState *env = &cpu->env;
uint64_t addr;
int lowcore;
IOIntCode int_code;
hwaddr len;
int ret;
uint8_t ar;
trace_ioinst("tpi");
addr = decode_basedisp_s(env, ipb, &ar);
if (addr & 3) {
program_interrupt(env, PGM_SPECIFICATION, 2);
return -EIO;
}
lowcore = addr ? 0 : 1;
len = lowcore ? 8 /* two words */ : 12 /* three words */;
ret = css_do_tpi(&int_code, lowcore);
if (ret == 1) {
s390_cpu_virt_mem_write(cpu, lowcore ? 184 : addr, ar, &int_code, len);
}
return ret;
}
| 11,673 |
qemu | 0e8d2b5575938b8876a3c4bb66ee13c5d306fb6d | 0 | static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
exit(0);
return 0;
}
| 11,675 |
qemu | ba801af429aaa68f6cc03842c8b6be81a6ede65a | 0 | void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt)
{
switch (fs) {
case 1:
/* UFR Alias - Reset Status FR */
if (!((env->active_fpu.fcr0 & (1 << FCR0_UFRP)) && (rt == 0))) {
return;
}
if (env->CP0_Config5 & (1 << CP0C5_UFR)) {
env->CP0_Status &= ~(1 << CP0St_FR);
compute_hflags(env);
} else {
helper_raise_exception(env, EXCP_RI);
}
break;
case 4:
/* UNFR Alias - Set Status FR */
if (!((env->active_fpu.fcr0 & (1 << FCR0_UFRP)) && (rt == 0))) {
return;
}
if (env->CP0_Config5 & (1 << CP0C5_UFR)) {
env->CP0_Status |= (1 << CP0St_FR);
compute_hflags(env);
} else {
helper_raise_exception(env, EXCP_RI);
}
break;
case 25:
if (arg1 & 0xffffff00)
return;
env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0x017fffff) | ((arg1 & 0xfe) << 24) |
((arg1 & 0x1) << 23);
break;
case 26:
if (arg1 & 0x007c0000)
return;
env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfffc0f83) | (arg1 & 0x0003f07c);
break;
case 28:
if (arg1 & 0x007c0000)
return;
env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfefff07c) | (arg1 & 0x00000f83) |
((arg1 & 0x4) << 22);
break;
case 31:
if (arg1 & 0x007c0000)
return;
env->active_fpu.fcr31 = arg1;
break;
default:
return;
}
/* set rounding mode */
restore_rounding_mode(env);
/* set flush-to-zero mode */
restore_flush_mode(env);
set_float_exception_flags(0, &env->active_fpu.fp_status);
if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) & GET_FP_CAUSE(env->active_fpu.fcr31))
do_raise_exception(env, EXCP_FPE, GETPC());
}
| 11,676 |
FFmpeg | b164d66e35d349de414e2f0d7365a147aba8a620 | 0 | static void predictor_decode_stereo(APEContext *ctx, int count)
{
APEPredictor *p = &ctx->predictor;
int32_t *decoded0 = ctx->decoded[0];
int32_t *decoded1 = ctx->decoded[1];
while (count--) {
/* Predictor Y */
*decoded0 = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB,
YADAPTCOEFFSA, YADAPTCOEFFSB);
decoded0++;
*decoded1 = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB,
XADAPTCOEFFSA, XADAPTCOEFFSB);
decoded1++;
/* Combined */
p->buf++;
/* Have we filled the history buffer? */
if (p->buf == p->historybuffer + HISTORY_SIZE) {
memmove(p->historybuffer, p->buf,
PREDICTOR_SIZE * sizeof(*p->historybuffer));
p->buf = p->historybuffer;
}
}
}
| 11,677 |
qemu | ffbb1705a33df8e2fb12b24d96663d63b22eaf8b | 0 | static bool rtas_event_log_contains(uint32_t event_mask, bool exception)
{
sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
sPAPREventLogEntry *entry = NULL;
/* we only queue EPOW events atm. */
if ((event_mask & EVENT_MASK_EPOW) == 0) {
return false;
}
QTAILQ_FOREACH(entry, &spapr->pending_events, next) {
if (entry->exception != exception) {
continue;
}
/* EPOW and hotplug events are surfaced in the same manner */
if (entry->log_type == RTAS_LOG_TYPE_EPOW ||
entry->log_type == RTAS_LOG_TYPE_HOTPLUG) {
return true;
}
}
return false;
}
| 11,678 |
qemu | 2374e73edafff0586cbfb67c333c5a7588f81fd5 | 0 | void helper_ldq_raw(uint64_t t0, uint64_t t1)
{
ldq_raw(t1, t0);
}
| 11,679 |
qemu | 384acbf46b70edf0d2c1648aa1a92a90bcf7057d | 0 | void qemu_bh_update_timeout(int *timeout)
{
QEMUBH *bh;
for (bh = async_context->first_bh; bh; bh = bh->next) {
if (!bh->deleted && bh->scheduled) {
if (bh->idle) {
/* idle bottom halves will be polled at least
* every 10ms */
*timeout = MIN(10, *timeout);
} else {
/* non-idle bottom halves will be executed
* immediately */
*timeout = 0;
break;
}
}
}
}
| 11,680 |
qemu | da98c8eb4c35225049cad8cf767647eb39788b5d | 0 | i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
int kvm_enabled)
{
PCIDevice *dev;
PIIX4PMState *s;
dev = pci_create(bus, devfn, "PIIX4_PM");
qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
s = DO_UPCAST(PIIX4PMState, dev, dev);
s->irq = sci_irq;
acpi_pm1_cnt_init(&s->ar, cmos_s3);
s->smi_irq = smi_irq;
s->kvm_enabled = kvm_enabled;
qdev_init_nofail(&dev->qdev);
return s->smb.smbus;
}
| 11,681 |
qemu | 0fbf5238203041f734c51b49778223686f14366b | 0 | static int get_phys_addr_v6(CPUARMState *env, uint32_t address, int access_type,
ARMMMUIdx mmu_idx, hwaddr *phys_ptr,
int *prot, target_ulong *page_size)
{
CPUState *cs = CPU(arm_env_get_cpu(env));
int code;
uint32_t table;
uint32_t desc;
uint32_t xn;
uint32_t pxn = 0;
int type;
int ap;
int domain = 0;
int domain_prot;
hwaddr phys_addr;
uint32_t dacr;
/* Pagetable walk. */
/* Lookup l1 descriptor. */
if (!get_level1_table_address(env, mmu_idx, &table, address)) {
/* Section translation fault if page walk is disabled by PD0 or PD1 */
code = 5;
goto do_fault;
}
desc = ldl_phys(cs->as, table);
type = (desc & 3);
if (type == 0 || (type == 3 && !arm_feature(env, ARM_FEATURE_PXN))) {
/* Section translation fault, or attempt to use the encoding
* which is Reserved on implementations without PXN.
*/
code = 5;
goto do_fault;
}
if ((type == 1) || !(desc & (1 << 18))) {
/* Page or Section. */
domain = (desc >> 5) & 0x0f;
}
if (regime_el(env, mmu_idx) == 1) {
dacr = env->cp15.dacr_ns;
} else {
dacr = env->cp15.dacr_s;
}
domain_prot = (dacr >> (domain * 2)) & 3;
if (domain_prot == 0 || domain_prot == 2) {
if (type != 1) {
code = 9; /* Section domain fault. */
} else {
code = 11; /* Page domain fault. */
}
goto do_fault;
}
if (type != 1) {
if (desc & (1 << 18)) {
/* Supersection. */
phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);
*page_size = 0x1000000;
} else {
/* Section. */
phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
*page_size = 0x100000;
}
ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);
xn = desc & (1 << 4);
pxn = desc & 1;
code = 13;
} else {
if (arm_feature(env, ARM_FEATURE_PXN)) {
pxn = (desc >> 2) & 1;
}
/* Lookup l2 entry. */
table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
desc = ldl_phys(cs->as, table);
ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);
switch (desc & 3) {
case 0: /* Page translation fault. */
code = 7;
goto do_fault;
case 1: /* 64k page. */
phys_addr = (desc & 0xffff0000) | (address & 0xffff);
xn = desc & (1 << 15);
*page_size = 0x10000;
break;
case 2: case 3: /* 4k page. */
phys_addr = (desc & 0xfffff000) | (address & 0xfff);
xn = desc & 1;
*page_size = 0x1000;
break;
default:
/* Never happens, but compiler isn't smart enough to tell. */
abort();
}
code = 15;
}
if (domain_prot == 3) {
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
} else {
if (pxn && !regime_is_user(env, mmu_idx)) {
xn = 1;
}
if (xn && access_type == 2)
goto do_fault;
/* The simplified model uses AP[0] as an access control bit. */
if ((regime_sctlr(env, mmu_idx) & SCTLR_AFE)
&& (ap & 1) == 0) {
/* Access flag fault. */
code = (code == 15) ? 6 : 3;
goto do_fault;
}
*prot = check_ap(env, mmu_idx, ap, domain_prot, access_type);
if (!*prot) {
/* Access permission fault. */
goto do_fault;
}
if (!xn) {
*prot |= PAGE_EXEC;
}
}
*phys_ptr = phys_addr;
return 0;
do_fault:
return code | (domain << 4);
}
| 11,682 |
qemu | fef6070eff233400015cede968b0afe46c80bb0f | 0 | static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
{
uint8_t buf[1024];
VHDFooter *footer = (VHDFooter *) buf;
char *disk_type_param;
int fd, i;
uint16_t cyls = 0;
uint8_t heads = 0;
uint8_t secs_per_cyl = 0;
int64_t total_sectors;
int64_t total_size;
int disk_type;
int ret = -EIO;
bool nocow = false;
/* Read out options */
total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
if (disk_type_param) {
if (!strcmp(disk_type_param, "dynamic")) {
disk_type = VHD_DYNAMIC;
} else if (!strcmp(disk_type_param, "fixed")) {
disk_type = VHD_FIXED;
} else {
ret = -EINVAL;
goto out;
}
} else {
disk_type = VHD_DYNAMIC;
}
nocow = qemu_opt_get_bool_del(opts, BLOCK_OPT_NOCOW, false);
/* Create the file */
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (fd < 0) {
ret = -EIO;
goto out;
}
if (nocow) {
#ifdef __linux__
/* Set NOCOW flag to solve performance issue on fs like btrfs.
* This is an optimisation. The FS_IOC_SETFLAGS ioctl return value will
* be ignored since any failure of this operation should not block the
* left work.
*/
int attr;
if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {
attr |= FS_NOCOW_FL;
ioctl(fd, FS_IOC_SETFLAGS, &attr);
}
#endif
}
/*
* Calculate matching total_size and geometry. Increase the number of
* sectors requested until we get enough (or fail). This ensures that
* qemu-img convert doesn't truncate images, but rather rounds up.
*/
total_sectors = total_size / BDRV_SECTOR_SIZE;
for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
if (calculate_geometry(total_sectors + i, &cyls, &heads,
&secs_per_cyl))
{
ret = -EFBIG;
goto fail;
}
}
total_sectors = (int64_t) cyls * heads * secs_per_cyl;
/* Prepare the Hard Disk Footer */
memset(buf, 0, 1024);
memcpy(footer->creator, "conectix", 8);
/* TODO Check if "qemu" creator_app is ok for VPC */
memcpy(footer->creator_app, "qemu", 4);
memcpy(footer->creator_os, "Wi2k", 4);
footer->features = be32_to_cpu(0x02);
footer->version = be32_to_cpu(0x00010000);
if (disk_type == VHD_DYNAMIC) {
footer->data_offset = be64_to_cpu(HEADER_SIZE);
} else {
footer->data_offset = be64_to_cpu(0xFFFFFFFFFFFFFFFFULL);
}
footer->timestamp = be32_to_cpu(time(NULL) - VHD_TIMESTAMP_BASE);
/* Version of Virtual PC 2007 */
footer->major = be16_to_cpu(0x0005);
footer->minor = be16_to_cpu(0x0003);
if (disk_type == VHD_DYNAMIC) {
footer->orig_size = be64_to_cpu(total_sectors * 512);
footer->size = be64_to_cpu(total_sectors * 512);
} else {
footer->orig_size = be64_to_cpu(total_size);
footer->size = be64_to_cpu(total_size);
}
footer->cyls = be16_to_cpu(cyls);
footer->heads = heads;
footer->secs_per_cyl = secs_per_cyl;
footer->type = be32_to_cpu(disk_type);
#if defined(CONFIG_UUID)
uuid_generate(footer->uuid);
#endif
footer->checksum = be32_to_cpu(vpc_checksum(buf, HEADER_SIZE));
if (disk_type == VHD_DYNAMIC) {
ret = create_dynamic_disk(fd, buf, total_sectors);
} else {
ret = create_fixed_disk(fd, buf, total_size);
}
fail:
qemu_close(fd);
out:
g_free(disk_type_param);
return ret;
}
| 11,684 |
qemu | 74475455442398a64355428b37422d14ccc293cb | 0 | static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
{
int64_t now;
int64_t ticks;
int64_t bytes;
int64_t samples;
now = qemu_get_clock (vm_clock);
ticks = now - rate->start_ticks;
bytes = muldiv64 (ticks, info->bytes_per_second, get_ticks_per_sec ());
samples = (bytes - rate->bytes_sent) >> info->shift;
if (samples < 0 || samples > 65536) {
fprintf (stderr, "Resetting rate control (%" PRId64 " samples)\n", samples);
rate_start (rate);
samples = 0;
}
rate->bytes_sent += samples << info->shift;
return samples;
}
| 11,686 |
qemu | b3db211f3c80bb996a704d665fe275619f728bd4 | 0 | static void test_visitor_out_native_list_uint8(TestOutputVisitorData *data,
const void *unused)
{
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U8);
}
| 11,689 |
qemu | 1ea879e5580f63414693655fcf0328559cdce138 | 0 | static int alsa_run_out (HWVoiceOut *hw)
{
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
int rpos, live, decr;
int samples;
uint8_t *dst;
st_sample_t *src;
snd_pcm_sframes_t avail;
live = audio_pcm_hw_get_live_out (hw);
if (!live) {
return 0;
}
avail = alsa_get_avail (alsa->handle);
if (avail < 0) {
dolog ("Could not get number of available playback frames\n");
return 0;
}
decr = audio_MIN (live, avail);
samples = decr;
rpos = hw->rpos;
while (samples) {
int left_till_end_samples = hw->samples - rpos;
int len = audio_MIN (samples, left_till_end_samples);
snd_pcm_sframes_t written;
src = hw->mix_buf + rpos;
dst = advance (alsa->pcm_buf, rpos << hw->info.shift);
hw->clip (dst, src, len);
while (len) {
written = snd_pcm_writei (alsa->handle, dst, len);
if (written <= 0) {
switch (written) {
case 0:
if (conf.verbose) {
dolog ("Failed to write %d frames (wrote zero)\n", len);
}
goto exit;
case -EPIPE:
if (alsa_recover (alsa->handle)) {
alsa_logerr (written, "Failed to write %d frames\n",
len);
goto exit;
}
if (conf.verbose) {
dolog ("Recovering from playback xrun\n");
}
continue;
case -EAGAIN:
goto exit;
default:
alsa_logerr (written, "Failed to write %d frames to %p\n",
len, dst);
goto exit;
}
}
rpos = (rpos + written) % hw->samples;
samples -= written;
len -= written;
dst = advance (dst, written << hw->info.shift);
src += written;
}
}
exit:
hw->rpos = rpos;
return decr;
}
| 11,690 |
qemu | 879c28133dfa54b780dffbb29e4dcfc6581f6281 | 0 | static int local_symlink(FsContext *ctx, const char *oldpath,
const char *newpath)
{
return symlink(oldpath, rpath(ctx, newpath));
}
| 11,694 |
qemu | 0188fadb7fe460d8c4c743372b1f7b25773e183e | 1 | static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUX86State *env)
{
abi_ulong frame_addr, addr;
struct rt_sigframe *frame;
int i, err = 0;
frame_addr = get_sigframe(ka, env, sizeof(*frame));
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0))
goto give_sigsegv;
__put_user(current_exec_domain_sig(sig), &frame->sig);
addr = frame_addr + offsetof(struct rt_sigframe, info);
__put_user(addr, &frame->pinfo);
addr = frame_addr + offsetof(struct rt_sigframe, uc);
__put_user(addr, &frame->puc);
copy_siginfo_to_user(&frame->info, info);
/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
__put_user(target_sigaltstack_used.ss_sp, &frame->uc.tuc_stack.ss_sp);
__put_user(sas_ss_flags(get_sp_from_cpustate(env)),
&frame->uc.tuc_stack.ss_flags);
__put_user(target_sigaltstack_used.ss_size,
&frame->uc.tuc_stack.ss_size);
setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env,
set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate));
for(i = 0; i < TARGET_NSIG_WORDS; i++) {
if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
goto give_sigsegv;
}
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
if (ka->sa_flags & TARGET_SA_RESTORER) {
__put_user(ka->sa_restorer, &frame->pretcode);
} else {
uint16_t val16;
addr = frame_addr + offsetof(struct rt_sigframe, retcode);
__put_user(addr, &frame->pretcode);
/* This is movl $,%eax ; int $0x80 */
__put_user(0xb8, (char *)(frame->retcode+0));
__put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1));
val16 = 0x80cd;
__put_user(val16, (uint16_t *)(frame->retcode+5));
}
if (err)
goto give_sigsegv;
/* Set up registers for signal handler */
env->regs[R_ESP] = frame_addr;
env->eip = ka->_sa_handler;
cpu_x86_load_seg(env, R_DS, __USER_DS);
cpu_x86_load_seg(env, R_ES, __USER_DS);
cpu_x86_load_seg(env, R_SS, __USER_DS);
cpu_x86_load_seg(env, R_CS, __USER_CS);
env->eflags &= ~TF_MASK;
unlock_user_struct(frame, frame_addr, 1);
return;
give_sigsegv:
unlock_user_struct(frame, frame_addr, 1);
if (sig == TARGET_SIGSEGV)
ka->_sa_handler = TARGET_SIG_DFL;
force_sig(TARGET_SIGSEGV /* , current */);
}
| 11,695 |
FFmpeg | 9458a62decfcaa1313b1ba69276466de536d0768 | 1 | static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
{
FFPsyBand *band;
int w, g, w2, i;
float *PNS = &s->scoefs[0*128], *PNS34 = &s->scoefs[1*128];
float *NOR34 = &s->scoefs[3*128];
const float lambda = s->lambda;
const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f;
const float thr_mult = NOISE_LAMBDA_REPLACE*(100.0f/lambda);
const float spread_threshold = NOISE_SPREAD_THRESHOLD*(lambda/100.f);
if (sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE)
return;
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
for (g = 0; g < sce->ics.num_swb; g++) {
int noise_sfi;
float dist1 = 0.0f, dist2 = 0.0f, noise_amp;
float pns_energy = 0.0f, energy_ratio, dist_thresh;
float sfb_energy = 0.0f, threshold = 0.0f, spread = 0.0f;
const int start = sce->ics.swb_offset[w*16+g];
const float freq = start*freq_mult;
const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f);
if (freq < NOISE_LOW_LIMIT || avctx->cutoff && freq >= avctx->cutoff)
continue;
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
sfb_energy += band->energy;
spread += band->spread;
threshold += band->threshold;
}
/* Ramps down at ~8000Hz and loosens the dist threshold */
dist_thresh = FFMIN(2.5f*NOISE_LOW_LIMIT/freq, 1.27f);
if (sce->zeroes[w*16+g] || spread < spread_threshold ||
sfb_energy > threshold*thr_mult*freq_boost) {
sce->pns_ener[w*16+g] = sfb_energy;
continue;
}
noise_sfi = av_clip(roundf(log2f(sfb_energy)*2), -100, 155); /* Quantize */
noise_amp = -ff_aac_pow2sf_tab[noise_sfi + POW_SF2_ZERO]; /* Dequantize */
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
float band_energy, scale;
const int start_c = sce->ics.swb_offset[(w+w2)*16+g];
band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
for (i = 0; i < sce->ics.swb_sizes[g]; i++)
PNS[i] = s->random_state = lcg_random(s->random_state);
band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]);
scale = noise_amp/sqrtf(band_energy);
s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]);
pns_energy += s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]);
abs_pow34_v(NOR34, &sce->coeffs[start_c], sce->ics.swb_sizes[g]);
abs_pow34_v(PNS34, PNS, sce->ics.swb_sizes[g]);
dist1 += quantize_band_cost(s, &sce->coeffs[start_c],
NOR34,
sce->ics.swb_sizes[g],
sce->sf_idx[(w+w2)*16+g],
sce->band_alt[(w+w2)*16+g],
lambda/band->threshold, INFINITY, NULL, 0);
dist2 += quantize_band_cost(s, PNS,
PNS34,
sce->ics.swb_sizes[g],
noise_sfi,
NOISE_BT,
lambda/band->threshold, INFINITY, NULL, 0);
}
energy_ratio = sfb_energy/pns_energy; /* Compensates for quantization error */
sce->pns_ener[w*16+g] = energy_ratio*sfb_energy;
if (energy_ratio > 0.85f && energy_ratio < 1.25f && dist1/dist2 > dist_thresh) {
sce->band_type[w*16+g] = NOISE_BT;
sce->zeroes[w*16+g] = 0;
if (sce->band_type[w*16+g-1] != NOISE_BT && /* Prevent holes */
sce->band_type[w*16+g-2] == NOISE_BT) {
sce->band_type[w*16+g-1] = NOISE_BT;
sce->zeroes[w*16+g-1] = 0;
}
}
}
}
}
| 11,697 |
FFmpeg | 0843ddcb91cfd11eeeebbd62cfc4bcd340c1e87d | 1 | static inline void dv_decode_video_segment(DVVideoContext *s,
const uint8_t *buf_ptr1,
const uint16_t *mb_pos_ptr)
{
int quant, dc, dct_mode, class1, j;
int mb_index, mb_x, mb_y, v, last_index;
int y_stride, i;
DCTELEM *block, *block1;
int c_offset;
uint8_t *y_ptr;
const uint8_t *buf_ptr;
PutBitContext pb, vs_pb;
GetBitContext gb;
BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1;
DECLARE_ALIGNED_16(DCTELEM, sblock[5*DV_MAX_BPM][64]);
DECLARE_ALIGNED_8(uint8_t, mb_bit_buffer[80 + 4]); /* allow some slack */
DECLARE_ALIGNED_8(uint8_t, vs_bit_buffer[5 * 80 + 4]); /* allow some slack */
const int log2_blocksize= 3-s->avctx->lowres;
int is_field_mode[5];
assert((((int)mb_bit_buffer)&7)==0);
assert((((int)vs_bit_buffer)&7)==0);
memset(sblock, 0, sizeof(sblock));
/* pass 1 : read DC and AC coefficients in blocks */
buf_ptr = buf_ptr1;
block1 = &sblock[0][0];
mb1 = mb_data;
init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
for(mb_index = 0; mb_index < 5; mb_index++, mb1 += s->sys->bpm, block1 += s->sys->bpm * 64) {
/* skip header */
quant = buf_ptr[3] & 0x0f;
buf_ptr += 4;
init_put_bits(&pb, mb_bit_buffer, 80);
mb = mb1;
block = block1;
is_field_mode[mb_index] = 0;
for(j = 0;j < s->sys->bpm; j++) {
last_index = s->sys->block_sizes[j];
init_get_bits(&gb, buf_ptr, last_index);
/* get the dc */
dc = get_sbits(&gb, 9);
dct_mode = get_bits1(&gb);
class1 = get_bits(&gb, 2);
if (DV_PROFILE_IS_HD(s->sys)) {
mb->idct_put = s->idct_put[0];
mb->scan_table = s->dv_zigzag[0];
mb->factor_table = s->dv100_idct_factor[((s->sys->height == 720)<<1)&(j < 4)][class1][quant];
is_field_mode[mb_index] |= !j && dct_mode;
} else {
mb->idct_put = s->idct_put[dct_mode && log2_blocksize==3];
mb->scan_table = s->dv_zigzag[dct_mode];
mb->factor_table = s->dv_idct_factor[class1 == 3][dct_mode]
[quant + dv_quant_offset[class1]];
}
dc = dc << 2;
/* convert to unsigned because 128 is not added in the
standard IDCT */
dc += 1024;
block[0] = dc;
buf_ptr += last_index >> 3;
mb->pos = 0;
mb->partial_bit_count = 0;
#ifdef VLC_DEBUG
printf("MB block: %d, %d ", mb_index, j);
#endif
dv_decode_ac(&gb, mb, block);
/* write the remaining bits in a new buffer only if the
block is finished */
if (mb->pos >= 64)
bit_copy(&pb, &gb);
block += 64;
mb++;
}
/* pass 2 : we can do it just after */
#ifdef VLC_DEBUG
printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index);
#endif
block = block1;
mb = mb1;
init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb));
flush_put_bits(&pb);
for(j = 0;j < s->sys->bpm; j++, block += 64, mb++) {
if (mb->pos < 64 && get_bits_left(&gb) > 0) {
dv_decode_ac(&gb, mb, block);
/* if still not finished, no need to parse other blocks */
if (mb->pos < 64)
break;
}
}
/* all blocks are finished, so the extra bytes can be used at
the video segment level */
if (j >= s->sys->bpm)
bit_copy(&vs_pb, &gb);
}
/* we need a pass other the whole video segment */
#ifdef VLC_DEBUG
printf("***pass 3 size=%d\n", put_bits_count(&vs_pb));
#endif
block = &sblock[0][0];
mb = mb_data;
init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb));
flush_put_bits(&vs_pb);
for(mb_index = 0; mb_index < 5; mb_index++) {
for(j = 0;j < s->sys->bpm; j++) {
if (mb->pos < 64) {
#ifdef VLC_DEBUG
printf("start %d:%d\n", mb_index, j);
#endif
dv_decode_ac(&gb, mb, block);
}
if (mb->pos >= 64 && mb->pos < 127)
av_log(NULL, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos);
block += 64;
mb++;
}
}
/* compute idct and place blocks */
block = &sblock[0][0];
mb = mb_data;
for(mb_index = 0; mb_index < 5; mb_index++) {
v = *mb_pos_ptr++;
mb_x = v & 0xff;
mb_y = v >> 8;
/* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */
if (s->sys->height == 720 && !(s->buf[1]&0x0C)) {
mb_y -= (mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macroblocks */
}
/* idct_put'ting luminance */
if ((s->sys->pix_fmt == PIX_FMT_YUV420P) ||
(s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) ||
(s->sys->height >= 720 && mb_y != 134)) {
y_stride = (s->picture.linesize[0]<<((!is_field_mode[mb_index])*log2_blocksize)) - (2<<log2_blocksize);
} else {
y_stride = 0;
}
y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x)<<log2_blocksize);
for(j = 0; j < 2; j++, y_ptr += y_stride) {
for (i=0; i<2; i++, block += 64, mb++, y_ptr += (1<<log2_blocksize))
if (s->sys->pix_fmt == PIX_FMT_YUV422P && s->sys->width == 720 && i)
y_ptr -= (1<<log2_blocksize);
else
mb->idct_put(y_ptr, s->picture.linesize[0]<<is_field_mode[mb_index], block);
}
/* idct_put'ting chrominance */
c_offset = (((mb_y>>(s->sys->pix_fmt == PIX_FMT_YUV420P)) * s->picture.linesize[1] +
(mb_x>>((s->sys->pix_fmt == PIX_FMT_YUV411P)?2:1)))<<log2_blocksize);
for(j=2; j; j--) {
uint8_t *c_ptr = s->picture.data[j] + c_offset;
if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
uint64_t aligned_pixels[64/8];
uint8_t *pixels = (uint8_t*)aligned_pixels;
uint8_t *c_ptr1, *ptr1;
int x, y;
mb->idct_put(pixels, 8, block);
for(y = 0; y < (1<<log2_blocksize); y++, c_ptr += s->picture.linesize[j], pixels += 8) {
ptr1= pixels + (1<<(log2_blocksize-1));
c_ptr1 = c_ptr + (s->picture.linesize[j]<<log2_blocksize);
for(x=0; x < (1<<(log2_blocksize-1)); x++) {
c_ptr[x]= pixels[x];
c_ptr1[x]= ptr1[x];
}
}
block += 64; mb++;
} else {
y_stride = (mb_y == 134) ? (1<<log2_blocksize) :
s->picture.linesize[j]<<((!is_field_mode[mb_index])*log2_blocksize);
for (i=0; i<(1<<(s->sys->bpm==8)); i++, block += 64, mb++, c_ptr += y_stride)
mb->idct_put(c_ptr, s->picture.linesize[j]<<is_field_mode[mb_index], block);
}
}
}
}
| 11,698 |
qemu | 73d60fa5fae60c8e07e1f295d8c7fd5d04320160 | 1 | static void set_sensor_evt_enable(IPMIBmcSim *ibs,
uint8_t *cmd, unsigned int cmd_len,
uint8_t *rsp, unsigned int *rsp_len,
unsigned int max_rsp_len)
{
IPMISensor *sens;
IPMI_CHECK_CMD_LEN(4);
if ((cmd[2] > MAX_SENSORS) ||
!IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
return;
}
sens = ibs->sensors + cmd[2];
switch ((cmd[3] >> 4) & 0x3) {
case 0: /* Do not change */
break;
case 1: /* Enable bits */
if (cmd_len > 4) {
sens->assert_enable |= cmd[4];
}
if (cmd_len > 5) {
sens->assert_enable |= cmd[5] << 8;
}
if (cmd_len > 6) {
sens->deassert_enable |= cmd[6];
}
if (cmd_len > 7) {
sens->deassert_enable |= cmd[7] << 8;
}
break;
case 2: /* Disable bits */
if (cmd_len > 4) {
sens->assert_enable &= ~cmd[4];
}
if (cmd_len > 5) {
sens->assert_enable &= ~(cmd[5] << 8);
}
if (cmd_len > 6) {
sens->deassert_enable &= ~cmd[6];
}
if (cmd_len > 7) {
sens->deassert_enable &= ~(cmd[7] << 8);
}
break;
case 3:
rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
return;
}
IPMI_SENSOR_SET_RET_STATUS(sens, cmd[3]);
}
| 11,699 |
qemu | 0be839a2701369f669532ea5884c15bead1c6e08 | 1 | static inline void *host_from_stream_offset(QEMUFile *f,
ram_addr_t offset,
int flags)
{
static RAMBlock *block = NULL;
char id[256];
uint8_t len;
if (flags & RAM_SAVE_FLAG_CONTINUE) {
if (!block) {
error_report("Ack, bad migration stream!");
return NULL;
}
return memory_region_get_ram_ptr(block->mr) + offset;
}
len = qemu_get_byte(f);
qemu_get_buffer(f, (uint8_t *)id, len);
id[len] = 0;
QTAILQ_FOREACH(block, &ram_list.blocks, next) {
if (!strncmp(id, block->idstr, sizeof(id)))
return memory_region_get_ram_ptr(block->mr) + offset;
}
error_report("Can't find block %s!", id);
return NULL;
}
| 11,700 |
FFmpeg | c43485f70765cb488bfdf95dc783bb9b14eb1179 | 1 | static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
{
int i;
DiracContext *s = avctx->priv_data;
DiracSlice *slices = ((DiracSlice *)arg) + s->num_x*jobnr;
for (i = 0; i < s->num_x; i++)
decode_hq_slice(avctx, &slices[i]);
return 0;
}
| 11,701 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.