id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
6,333
MemoryRegionSection memory_region_find(MemoryRegion *mr, hwaddr addr, uint64_t size) { MemoryRegionSection ret = { .mr = NULL }; MemoryRegion *root; AddressSpace *as; AddrRange range; FlatView *view; FlatRange *fr; addr += mr->addr; for (root = mr; root->container; ) { root = root->container; addr += root->addr; } as = memory_region_to_address_space(root); if (!as) { return ret; } range = addrrange_make(int128_make64(addr), int128_make64(size)); rcu_read_lock(); view = atomic_rcu_read(&as->current_map); fr = flatview_lookup(view, range); if (!fr) { goto out; } while (fr > view->ranges && addrrange_intersects(fr[-1].addr, range)) { --fr; } ret.mr = fr->mr; ret.address_space = as; range = addrrange_intersection(range, fr->addr); ret.offset_within_region = fr->offset_in_region; ret.offset_within_region += int128_get64(int128_sub(range.start, fr->addr.start)); ret.size = range.size; ret.offset_within_address_space = int128_get64(range.start); ret.readonly = fr->readonly; memory_region_ref(ret.mr); out: rcu_read_unlock(); return ret; }
true
qemu
c6742b14fe7352059cd4954a356a8105757af31b
6,334
static void vnc_colordepth(DisplayState *ds) { int host_big_endian_flag; struct VncState *vs = ds->opaque; #ifdef WORDS_BIGENDIAN host_big_endian_flag = 1; #else host_big_endian_flag = 0; #endif switch (ds_get_bits_per_pixel(ds)) { case 8: vs->depth = 1; vs->server_red_max = 7; vs->server_green_max = 7; vs->server_blue_max = 3; vs->server_red_shift = 5; vs->server_green_shift = 2; vs->server_blue_shift = 0; break; case 16: vs->depth = 2; vs->server_red_max = 31; vs->server_green_max = 63; vs->server_blue_max = 31; vs->server_red_shift = 11; vs->server_green_shift = 5; vs->server_blue_shift = 0; break; case 32: vs->depth = 4; vs->server_red_max = 255; vs->server_green_max = 255; vs->server_blue_max = 255; vs->server_red_shift = 16; vs->server_green_shift = 8; vs->server_blue_shift = 0; break; default: return; } if (vs->csock != -1 && vs->has_WMVi) { /* Sending a WMVi message to notify the client*/ vnc_write_u8(vs, 0); /* msg id */ vnc_write_u8(vs, 0); vnc_write_u16(vs, 1); /* number of rects */ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), 0x574D5669); pixel_format_message(vs); vnc_flush(vs); } else { if (vs->pix_bpp == 4 && vs->depth == 4 && host_big_endian_flag == vs->pix_big_endian && vs->client_red_max == 0xff && vs->client_green_max == 0xff && vs->client_blue_max == 0xff && vs->client_red_shift == 16 && vs->client_green_shift == 8 && vs->client_blue_shift == 0) { vs->write_pixels = vnc_write_pixels_copy; vs->send_hextile_tile = send_hextile_tile_32; } else if (vs->pix_bpp == 2 && vs->depth == 2 && host_big_endian_flag == vs->pix_big_endian && vs->client_red_max == 31 && vs->client_green_max == 63 && vs->client_blue_max == 31 && vs->client_red_shift == 11 && vs->client_green_shift == 5 && vs->client_blue_shift == 0) { vs->write_pixels = vnc_write_pixels_copy; vs->send_hextile_tile = send_hextile_tile_16; } else if (vs->pix_bpp == 1 && vs->depth == 1 && host_big_endian_flag == vs->pix_big_endian && vs->client_red_max == 7 && vs->client_green_max == 7 && vs->client_blue_max == 3 && vs->client_red_shift == 5 && vs->client_green_shift == 2 && vs->client_blue_shift == 0) { vs->write_pixels = vnc_write_pixels_copy; vs->send_hextile_tile = send_hextile_tile_8; } else { if (vs->depth == 4) { vs->send_hextile_tile = send_hextile_tile_generic_32; } else if (vs->depth == 2) { vs->send_hextile_tile = send_hextile_tile_generic_16; } else { vs->send_hextile_tile = send_hextile_tile_generic_8; } vs->write_pixels = vnc_write_pixels_generic; } } }
true
qemu
6cec5487990bf3f1f22b3fcb871978255e92ae0d
6,336
int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { RV34DecContext *r = dst->priv_data, *r1 = src->priv_data; MpegEncContext * const s = &r->s, * const s1 = &r1->s; int err; if (dst == src || !s1->context_initialized) return 0; if (s->height != s1->height || s->width != s1->width) { ff_MPV_common_end(s); s->height = s1->height; s->width = s1->width; if ((err = ff_MPV_common_init(s)) < 0) return err; if ((err = rv34_decoder_realloc(r)) < 0) return err; } if ((err = ff_mpeg_update_thread_context(dst, src))) return err; r->cur_pts = r1->cur_pts; r->last_pts = r1->last_pts; r->next_pts = r1->next_pts; memset(&r->si, 0, sizeof(r->si)); /* necessary since it is it the condition checked for in decode_slice * to call ff_MPV_frame_start. cmp. comment at the end of decode_frame */ s->current_picture_ptr = NULL; return 0; }
true
FFmpeg
73ad4471a48bd02b2c2a55de116161b87e061023
6,337
static av_cold int flac_encode_init(AVCodecContext *avctx) { int freq = avctx->sample_rate; int channels = avctx->channels; FlacEncodeContext *s = avctx->priv_data; int i, level; uint8_t *streaminfo; s->avctx = avctx; dsputil_init(&s->dsp, avctx); if (avctx->sample_fmt != SAMPLE_FMT_S16) return -1; if (channels < 1 || channels > FLAC_MAX_CHANNELS) return -1; s->channels = channels; /* find samplerate in table */ if (freq < 1) return -1; for (i = 4; i < 12; i++) { if (freq == ff_flac_sample_rate_table[i]) { s->samplerate = ff_flac_sample_rate_table[i]; s->sr_code[0] = i; s->sr_code[1] = 0; break; } } /* if not in table, samplerate is non-standard */ if (i == 12) { if (freq % 1000 == 0 && freq < 255000) { s->sr_code[0] = 12; s->sr_code[1] = freq / 1000; } else if (freq % 10 == 0 && freq < 655350) { s->sr_code[0] = 14; s->sr_code[1] = freq / 10; } else if (freq < 65535) { s->sr_code[0] = 13; s->sr_code[1] = freq; } else { return -1; } s->samplerate = freq; } /* set compression option defaults based on avctx->compression_level */ if (avctx->compression_level < 0) s->options.compression_level = 5; else s->options.compression_level = avctx->compression_level; av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", s->options.compression_level); level = s->options.compression_level; if (level > 12) { av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n", s->options.compression_level); return -1; } s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level]; s->options.lpc_type = ((int[]){ AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON})[level]; s->options.min_prediction_order = ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; s->options.max_prediction_order = ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_SEARCH, ORDER_METHOD_LOG, ORDER_METHOD_SEARCH})[level]; s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level]; s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; /* set compression option overrides from AVCodecContext */ #if LIBAVCODEC_VERSION_MAJOR < 53 /* for compatibility with deprecated AVCodecContext.use_lpc */ if (avctx->use_lpc == 0) { s->options.lpc_type = AV_LPC_TYPE_FIXED; } else if (avctx->use_lpc == 1) { s->options.lpc_type = AV_LPC_TYPE_LEVINSON; } else if (avctx->use_lpc > 1) { s->options.lpc_type = AV_LPC_TYPE_CHOLESKY; s->options.lpc_passes = avctx->use_lpc - 1; } #endif if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) { if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) { av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", avctx->lpc_type); return -1; } s->options.lpc_type = avctx->lpc_type; if (s->options.lpc_type == AV_LPC_TYPE_CHOLESKY) { if (avctx->lpc_passes < 0) { // default number of passes for Cholesky s->options.lpc_passes = 2; } else if (avctx->lpc_passes == 0) { av_log(avctx, AV_LOG_ERROR, "invalid number of lpc passes: %d\n", avctx->lpc_passes); return -1; } else { s->options.lpc_passes = avctx->lpc_passes; } } } switch (s->options.lpc_type) { case AV_LPC_TYPE_NONE: av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n"); break; case AV_LPC_TYPE_FIXED: av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n"); break; case AV_LPC_TYPE_LEVINSON: av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n"); break; case AV_LPC_TYPE_CHOLESKY: av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n", s->options.lpc_passes, s->options.lpc_passes==1?"":"es"); break; } if (s->options.lpc_type == AV_LPC_TYPE_NONE) { s->options.min_prediction_order = 0; } else if (avctx->min_prediction_order >= 0) { if (s->options.lpc_type == AV_LPC_TYPE_FIXED) { if (avctx->min_prediction_order > MAX_FIXED_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", avctx->min_prediction_order); return -1; } } else if (avctx->min_prediction_order < MIN_LPC_ORDER || avctx->min_prediction_order > MAX_LPC_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", avctx->min_prediction_order); return -1; } s->options.min_prediction_order = avctx->min_prediction_order; } if (s->options.lpc_type == AV_LPC_TYPE_NONE) { s->options.max_prediction_order = 0; } else if (avctx->max_prediction_order >= 0) { if (s->options.lpc_type == AV_LPC_TYPE_FIXED) { if (avctx->max_prediction_order > MAX_FIXED_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", avctx->max_prediction_order); return -1; } } else if (avctx->max_prediction_order < MIN_LPC_ORDER || avctx->max_prediction_order > MAX_LPC_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", avctx->max_prediction_order); return -1; } s->options.max_prediction_order = avctx->max_prediction_order; } if (s->options.max_prediction_order < s->options.min_prediction_order) { av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", s->options.min_prediction_order, s->options.max_prediction_order); return -1; } av_log(avctx, AV_LOG_DEBUG, " prediction order: %d, %d\n", s->options.min_prediction_order, s->options.max_prediction_order); if (avctx->prediction_order_method >= 0) { if (avctx->prediction_order_method > ORDER_METHOD_LOG) { av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n", avctx->prediction_order_method); return -1; } s->options.prediction_order_method = avctx->prediction_order_method; } switch (s->options.prediction_order_method) { case ORDER_METHOD_EST: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "estimate"); break; case ORDER_METHOD_2LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "2-level"); break; case ORDER_METHOD_4LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "4-level"); break; case ORDER_METHOD_8LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "8-level"); break; case ORDER_METHOD_SEARCH: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "full search"); break; case ORDER_METHOD_LOG: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "log search"); break; } if (avctx->min_partition_order >= 0) { if (avctx->min_partition_order > MAX_PARTITION_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n", avctx->min_partition_order); return -1; } s->options.min_partition_order = avctx->min_partition_order; } if (avctx->max_partition_order >= 0) { if (avctx->max_partition_order > MAX_PARTITION_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid max partition order: %d\n", avctx->max_partition_order); return -1; } s->options.max_partition_order = avctx->max_partition_order; } if (s->options.max_partition_order < s->options.min_partition_order) { av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n", s->options.min_partition_order, s->options.max_partition_order); return -1; } av_log(avctx, AV_LOG_DEBUG, " partition order: %d, %d\n", s->options.min_partition_order, s->options.max_partition_order); if (avctx->frame_size > 0) { if (avctx->frame_size < FLAC_MIN_BLOCKSIZE || avctx->frame_size > FLAC_MAX_BLOCKSIZE) { av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n", avctx->frame_size); return -1; } } else { s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms); } s->max_blocksize = s->avctx->frame_size; av_log(avctx, AV_LOG_DEBUG, " block size: %d\n", s->avctx->frame_size); /* set LPC precision */ if (avctx->lpc_coeff_precision > 0) { if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) { av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n", avctx->lpc_coeff_precision); return -1; } s->options.lpc_coeff_precision = avctx->lpc_coeff_precision; } else { /* default LPC precision */ s->options.lpc_coeff_precision = 15; } av_log(avctx, AV_LOG_DEBUG, " lpc precision: %d\n", s->options.lpc_coeff_precision); /* set maximum encoded frame size in verbatim mode */ s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size, s->channels, 16); /* initialize MD5 context */ s->md5ctx = av_malloc(av_md5_size); if (!s->md5ctx) av_md5_init(s->md5ctx); streaminfo = av_malloc(FLAC_STREAMINFO_SIZE); if (!streaminfo) write_streaminfo(s, streaminfo); avctx->extradata = streaminfo; avctx->extradata_size = FLAC_STREAMINFO_SIZE; s->frame_count = 0; s->min_framesize = s->max_framesize; avctx->coded_frame = avcodec_alloc_frame(); avctx->coded_frame->key_frame = 1; return 0; }
true
FFmpeg
e08ec714801a8f8e72eeee57c2df48b8fbaf2e12
6,338
static void init_mbr(BDRVVVFATState* s) { /* TODO: if the files mbr.img and bootsect.img exist, use them */ mbr_t* real_mbr=(mbr_t*)s->first_sectors; partition_t* partition = &(real_mbr->partition[0]); int lba; memset(s->first_sectors,0,512); /* Win NT Disk Signature */ real_mbr->nt_id= cpu_to_le32(0xbe1afdfa); partition->attributes=0x80; /* bootable */ /* LBA is used when partition is outside the CHS geometry */ lba = sector2CHS(s->bs, &partition->start_CHS, s->first_sectors_number-1); lba|= sector2CHS(s->bs, &partition->end_CHS, s->sector_count); /*LBA partitions are identified only by start/length_sector_long not by CHS*/ partition->start_sector_long =cpu_to_le32(s->first_sectors_number-1); partition->length_sector_long=cpu_to_le32(s->sector_count - s->first_sectors_number+1); /* FAT12/FAT16/FAT32 */ /* DOS uses different types when partition is LBA, probably to prevent older versions from using CHS on them */ partition->fs_type= s->fat_type==12 ? 0x1: s->fat_type==16 ? (lba?0xe:0x06): /*fat_tyoe==32*/ (lba?0xc:0x0b); real_mbr->magic[0]=0x55; real_mbr->magic[1]=0xaa; }
true
qemu
f91cbefe2d0eb3f7b5071bcb1fd3a02970f1a776
6,340
static void set_year_20xx(void) { /* Set BCD mode */ cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) & ~REG_B_DM); cmos_write(RTC_REG_A, 0x76); cmos_write(RTC_YEAR, 0x11); cmos_write(RTC_CENTURY, 0x20); cmos_write(RTC_MONTH, 0x02); cmos_write(RTC_DAY_OF_MONTH, 0x02); cmos_write(RTC_HOURS, 0x02); cmos_write(RTC_MINUTES, 0x04); cmos_write(RTC_SECONDS, 0x58); cmos_write(RTC_REG_A, 0x26); g_assert_cmpint(cmos_read(RTC_HOURS), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MINUTES), ==, 0x04); g_assert_cmpint(cmos_read(RTC_SECONDS), >=, 0x58); g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_YEAR), ==, 0x11); g_assert_cmpint(cmos_read(RTC_CENTURY), ==, 0x20); /* Set a date in 2080 to ensure there is no year-2038 overflow. */ cmos_write(RTC_REG_A, 0x76); cmos_write(RTC_YEAR, 0x80); cmos_write(RTC_REG_A, 0x26); g_assert_cmpint(cmos_read(RTC_HOURS), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MINUTES), ==, 0x04); g_assert_cmpint(cmos_read(RTC_SECONDS), >=, 0x58); g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_YEAR), ==, 0x80); g_assert_cmpint(cmos_read(RTC_CENTURY), ==, 0x20); cmos_write(RTC_REG_A, 0x76); cmos_write(RTC_YEAR, 0x11); cmos_write(RTC_REG_A, 0x26); g_assert_cmpint(cmos_read(RTC_HOURS), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MINUTES), ==, 0x04); g_assert_cmpint(cmos_read(RTC_SECONDS), >=, 0x58); g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_MONTH), ==, 0x02); g_assert_cmpint(cmos_read(RTC_YEAR), ==, 0x11); g_assert_cmpint(cmos_read(RTC_CENTURY), ==, 0x20);
true
qemu
4e45deedf57c6cc7113b588282d0c16f89298aff
6,341
void avfilter_destroy(AVFilterContext *filter) { int i; if(filter->filter->uninit) filter->filter->uninit(filter); for(i = 0; i < filter->input_count; i ++) { if(filter->inputs[i]) { filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL; avfilter_formats_unref(&filter->inputs[i]->in_formats); avfilter_formats_unref(&filter->inputs[i]->out_formats); } av_freep(&filter->inputs[i]); } for(i = 0; i < filter->output_count; i ++) { if(filter->outputs[i]) { if (filter->outputs[i]->dst) filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL; avfilter_formats_unref(&filter->outputs[i]->in_formats); avfilter_formats_unref(&filter->outputs[i]->out_formats); } av_freep(&filter->outputs[i]); } av_freep(&filter->name); av_freep(&filter->input_pads); av_freep(&filter->output_pads); av_freep(&filter->inputs); av_freep(&filter->outputs); av_freep(&filter->priv); av_free(filter); }
true
FFmpeg
0bb7408e557f5d5ee3f8c1d001012e5c204c20b4
6,342
void usb_desc_create_serial(USBDevice *dev) { DeviceState *hcd = dev->qdev.parent_bus->parent; const USBDesc *desc = usb_device_get_usb_desc(dev); int index = desc->id.iSerialNumber; char serial[64]; char *path; int dst; if (dev->serial) { /* 'serial' usb bus property has priority if present */ usb_desc_set_string(dev, index, dev->serial); return; } assert(index != 0 && desc->str[index] != NULL); dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]); path = qdev_get_dev_path(hcd); if (path) { dst += snprintf(serial+dst, sizeof(serial)-dst, "-%s", path); } dst += snprintf(serial+dst, sizeof(serial)-dst, "-%s", dev->port->path); usb_desc_set_string(dev, index, serial); }
true
qemu
9ef617246b629109e2779835b9a3a8400029484d
6,343
const char *qdict_get_str(const QDict *qdict, const char *key) { QObject *obj = qdict_get_obj(qdict, key, QTYPE_QSTRING); return qstring_get_str(qobject_to_qstring(obj)); }
true
qemu
7f0278435df1fa845b3bd9556942f89296d4246b
6,344
static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties) { int compno; if (s->buf_end - s->buf < 2) return AVERROR(EINVAL); compno = bytestream_get_byte(&s->buf); c += compno; c->csty = bytestream_get_byte(&s->buf); get_cox(s, c); properties[compno] |= HAD_COC; return 0; }
true
FFmpeg
ddfa3751c092feaf1e080f66587024689dfe603c
6,345
static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride, int16_t *src2, int height, int denom, int wx0, int wx1, int ox0, int ox1, intptr_t mx, intptr_t my, int width) { int x, y; const int8_t *filter; pixel *src = (pixel*)_src; ptrdiff_t srcstride = _srcstride / sizeof(pixel); pixel *dst = (pixel *)_dst; ptrdiff_t dststride = _dststride / sizeof(pixel); int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE]; int16_t *tmp = tmp_array; int shift = 14 + 1 - BIT_DEPTH; int log2Wd = denom + shift - 1; src -= QPEL_EXTRA_BEFORE * srcstride; filter = ff_hevc_qpel_filters[mx - 1]; for (y = 0; y < height + QPEL_EXTRA; y++) { for (x = 0; x < width; x++) tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8); src += srcstride; tmp += MAX_PB_SIZE; } tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE; filter = ff_hevc_qpel_filters[my - 1]; ox0 = ox0 * (1 << (BIT_DEPTH - 8)); ox1 = ox1 * (1 << (BIT_DEPTH - 8)); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 + ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1)); tmp += MAX_PB_SIZE; dst += dststride; src2 += MAX_PB_SIZE; } }
true
FFmpeg
439fbb9c8b2a90e97c44c7c57245e01ca84c865d
6,347
int bdrv_flush(BlockDriverState *bs) { Coroutine *co; FlushCo flush_co = { .bs = bs, .ret = NOT_DONE, }; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_flush_co_entry(&flush_co); } else { co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co); qemu_coroutine_enter(co); BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE); } return flush_co.ret; }
true
qemu
e92f0e1910f0655a0edd8d87c5a7262d36517a89
6,348
void scsi_req_complete(SCSIRequest *req) { assert(req->status != -1); scsi_req_ref(req); scsi_req_dequeue(req); req->bus->ops->complete(req->bus, SCSI_REASON_DONE, req->tag, req->status); scsi_req_unref(req); }
true
qemu
5c6c0e513600ba57c3e73b7151d3c0664438f7b5
6,349
static void iv_Decode_Chunk(Indeo3DecodeContext *s, uint8_t *cur, uint8_t *ref, int width, int height, const uint8_t *buf1, long cb_offset, const uint8_t *hdr, const uint8_t *buf2, int min_width_160) { uint8_t bit_buf; unsigned long bit_pos, lv, lv1, lv2; long *width_tbl, width_tbl_arr[10]; const signed char *ref_vectors; uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2; uint32_t *cur_lp, *ref_lp; const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2]; uint8_t *correction_type_sp[2]; struct ustr strip_tbl[20], *strip; int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width, rle_v1, rle_v2, rle_v3; unsigned short res; bit_buf = 0; ref_vectors = NULL; width_tbl = width_tbl_arr + 1; i = (width < 0 ? width + 3 : width)/4; for(j = -1; j < 8; j++) width_tbl[j] = i * j; strip = strip_tbl; for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160); strip->ypos = strip->xpos = 0; for(strip->width = min_width_160; width > strip->width; strip->width *= 2); strip->height = height; strip->split_direction = 0; strip->split_flag = 0; strip->usl7 = 0; bit_pos = 0; rle_v1 = rle_v2 = rle_v3 = 0; while(strip >= strip_tbl) { if(bit_pos <= 0) { bit_pos = 8; bit_buf = *buf1++; bit_pos -= 2; cmd = (bit_buf >> bit_pos) & 0x03; if(cmd == 0) { strip++; memcpy(strip, strip-1, sizeof(*strip)); strip->split_flag = 1; strip->split_direction = 0; strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4); continue; } else if(cmd == 1) { strip++; memcpy(strip, strip-1, sizeof(*strip)); strip->split_flag = 1; strip->split_direction = 1; strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4); continue; } else if(cmd == 2) { if(strip->usl7 == 0) { strip->usl7 = 1; ref_vectors = NULL; continue; } else if(cmd == 3) { if(strip->usl7 == 0) { strip->usl7 = 1; ref_vectors = (const signed char*)buf2 + (*buf1 * 2); buf1++; continue; cur_frm_pos = cur + width * strip->ypos + strip->xpos; if((blks_width = strip->width) < 0) blks_width += 3; blks_width >>= 2; blks_height = strip->height; if(ref_vectors != NULL) { ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width + ref_vectors[1] + strip->xpos; } else ref_frm_pos = cur_frm_pos - width_tbl[4]; if(cmd == 2) { if(bit_pos <= 0) { bit_pos = 8; bit_buf = *buf1++; bit_pos -= 2; cmd = (bit_buf >> bit_pos) & 0x03; if(cmd == 0 || ref_vectors != NULL) { for(lp1 = 0; lp1 < blks_width; lp1++) { for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1]) ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; cur_frm_pos += 4; ref_frm_pos += 4; } else if(cmd != 1) return; } else { k = *buf1 >> 4; j = *buf1 & 0x0f; buf1++; lv = j + cb_offset; if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) { cp2 = s->ModPred + ((lv - 8) << 7); cp = ref_frm_pos; for(i = 0; i < blks_width << 2; i++) { int v = *cp >> 1; *(cp++) = cp2[v]; if(k == 1 || k == 4) { lv = (hdr[j] & 0xf) + cb_offset; correction_type_sp[0] = s->corrector_type + (lv << 8); correction_lp[0] = correction + (lv << 8); lv = (hdr[j] >> 4) + cb_offset; correction_lp[1] = correction + (lv << 8); correction_type_sp[1] = s->corrector_type + (lv << 8); } else { correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8); correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8); correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8); correction_lp[0] = correction_lp[1] = correction + (lv << 8); switch(k) { case 1: case 0: /********** CASE 0 **********/ for( ; blks_height > 0; blks_height -= 4) { for(lp1 = 0; lp1 < blks_width; lp1++) { for(lp2 = 0; lp2 < 4; ) { k = *buf1++; cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2]; ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2]; switch(correction_type_sp[0][k]) { case 0: *cur_lp = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; case 1: res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; ((unsigned short *)cur_lp)[0] = le2me_16(res); res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; ((unsigned short *)cur_lp)[1] = le2me_16(res); buf1++; lp2++; case 2: if(lp2 == 0) { for(i = 0, j = 0; i < 2; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 += 2; case 3: if(lp2 < 2) { for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 = 3; case 8: if(lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) if(rle_v1 == 1 || ref_vectors != NULL) { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) } else { rle_v1 = 1; rle_v2 = *buf1 - 1; case 5: LP2_CHECK(buf1,rle_v3,lp2) case 4: for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 = 4; case 7: if(rle_v3 != 0) rle_v3 = 0; else { buf1--; rle_v3 = 1; case 6: if(ref_vectors != NULL) { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 = 4; case 9: lv1 = *buf1++; lv = (lv1 & 0x7F) << 1; lv += (lv << 8); lv += (lv << 16); for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = lv; LV1_CHECK(buf1,rle_v3,lv1,lp2) default: return; cur_frm_pos += 4; ref_frm_pos += 4; cur_frm_pos += ((width - blks_width) * 4); ref_frm_pos += ((width - blks_width) * 4); case 4: case 3: /********** CASE 3 **********/ if(ref_vectors != NULL) return; flag1 = 1; for( ; blks_height > 0; blks_height -= 8) { for(lp1 = 0; lp1 < blks_width; lp1++) { for(lp2 = 0; lp2 < 4; ) { k = *buf1++; cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; switch(correction_type_sp[lp2 & 0x01][k]) { case 0: cur_lp[width_tbl[1]] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; else cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; case 1: res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res); res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res); if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; else cur_lp[0] = cur_lp[width_tbl[1]]; buf1++; lp2++; case 2: if(lp2 == 0) { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = *ref_lp; lp2 += 2; case 3: if(lp2 < 2) { for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) cur_lp[j] = *ref_lp; lp2 = 3; case 6: lp2 = 4; case 7: if(rle_v3 != 0) rle_v3 = 0; else { buf1--; rle_v3 = 1; lp2 = 4; case 8: if(lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) if(rle_v1 == 1) { for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) } else { rle_v2 = (*buf1) - 1; rle_v1 = 1; case 5: LP2_CHECK(buf1,rle_v3,lp2) case 4: for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) cur_lp[j] = *ref_lp; lp2 = 4; case 9: av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); lv1 = *buf1++; lv = (lv1 & 0x7F) << 1; lv += (lv << 8); lv += (lv << 16); for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = lv; LV1_CHECK(buf1,rle_v3,lv1,lp2) default: return; cur_frm_pos += 4; cur_frm_pos += (((width * 2) - blks_width) * 4); flag1 = 0; case 10: /********** CASE 10 **********/ if(ref_vectors == NULL) { flag1 = 1; for( ; blks_height > 0; blks_height -= 8) { for(lp1 = 0; lp1 < blks_width; lp1 += 2) { for(lp2 = 0; lp2 < 4; ) { k = *buf1++; cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; lv1 = ref_lp[0]; lv2 = ref_lp[1]; if(lp2 == 0 && flag1 != 0) { #ifdef WORDS_BIGENDIAN lv1 = lv1 & 0xFF00FF00; lv1 = (lv1 >> 8) | lv1; lv2 = lv2 & 0xFF00FF00; lv2 = (lv2 >> 8) | lv2; #else lv1 = lv1 & 0x00FF00FF; lv1 = (lv1 << 8) | lv1; lv2 = lv2 & 0x00FF00FF; lv2 = (lv2 << 8) | lv2; #endif switch(correction_type_sp[lp2 & 0x01][k]) { case 0: cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1); cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1); if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { cur_lp[0] = cur_lp[width_tbl[1]]; cur_lp[1] = cur_lp[width_tbl[1]+1]; lp2++; case 1: cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1); cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1); if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { cur_lp[0] = cur_lp[width_tbl[1]]; cur_lp[1] = cur_lp[width_tbl[1]+1]; buf1++; lp2++; case 2: if(lp2 == 0) { if(flag1 != 0) { for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; lp2 += 2; case 3: if(lp2 < 2) { if(lp2 == 0 && flag1 != 0) { for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; lp2 = 3; case 8: if(lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) if(rle_v1 == 1) { if(flag1 != 0) { for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) } else { rle_v1 = 1; rle_v2 = (*buf1) - 1; case 5: LP2_CHECK(buf1,rle_v3,lp2) case 4: if(lp2 == 0 && flag1 != 0) { for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; } else { for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { cur_lp[j] = lv1; cur_lp[j+1] = lv2; lp2 = 4; case 6: lp2 = 4; case 7: if(lp2 == 0) { if(rle_v3 != 0) rle_v3 = 0; else { buf1--; rle_v3 = 1; lp2 = 4; case 9: av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); lv1 = *buf1; lv = (lv1 & 0x7F) << 1; lv += (lv << 8); lv += (lv << 16); for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) cur_lp[j] = lv; LV1_CHECK(buf1,rle_v3,lv1,lp2) default: return; cur_frm_pos += 8; cur_frm_pos += (((width * 2) - blks_width) * 4); flag1 = 0; } else { for( ; blks_height > 0; blks_height -= 8) { for(lp1 = 0; lp1 < blks_width; lp1 += 2) { for(lp2 = 0; lp2 < 4; ) { k = *buf1++; cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; switch(correction_type_sp[lp2 & 0x01][k]) { case 0: lv1 = correctionloworder_lp[lp2 & 0x01][k]; lv2 = correctionhighorder_lp[lp2 & 0x01][k]; cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1); cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1); cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); lp2++; case 1: lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++]; lv2 = correctionloworder_lp[lp2 & 0x01][k]; cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1); cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1); cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); lp2++; case 2: if(lp2 == 0) { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { cur_lp[j] = ref_lp[j]; cur_lp[j+1] = ref_lp[j+1]; lp2 += 2; case 3: if(lp2 < 2) { for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { cur_lp[j] = ref_lp[j]; cur_lp[j+1] = ref_lp[j+1]; lp2 = 3; case 8: if(lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1]; RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) } else { rle_v1 = 1; rle_v2 = (*buf1) - 1; case 5: case 7: LP2_CHECK(buf1,rle_v3,lp2) case 6: case 4: for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { cur_lp[j] = ref_lp[j]; cur_lp[j+1] = ref_lp[j+1]; lp2 = 4; case 9: av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); lv1 = *buf1; lv = (lv1 & 0x7F) << 1; lv += (lv << 8); lv += (lv << 16); for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv; LV1_CHECK(buf1,rle_v3,lv1,lp2) default: return; cur_frm_pos += 8; ref_frm_pos += 8; cur_frm_pos += (((width * 2) - blks_width) * 4); ref_frm_pos += (((width * 2) - blks_width) * 4); case 11: /********** CASE 11 **********/ if(ref_vectors == NULL) return; for( ; blks_height > 0; blks_height -= 8) { for(lp1 = 0; lp1 < blks_width; lp1++) { for(lp2 = 0; lp2 < 4; ) { k = *buf1++; cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; switch(correction_type_sp[lp2 & 0x01][k]) { case 0: cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; case 1: lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]); lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]); res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1); ((unsigned short *)cur_lp)[0] = le2me_16(res); res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1); ((unsigned short *)cur_lp)[1] = le2me_16(res); res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1); ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res); res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1); ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res); lp2++; case 2: if(lp2 == 0) { for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 += 2; case 3: if(lp2 < 2) { for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 = 3; case 8: if(lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) } else { rle_v1 = 1; rle_v2 = (*buf1) - 1; case 5: case 7: LP2_CHECK(buf1,rle_v3,lp2) case 4: case 6: for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) cur_lp[j] = ref_lp[j]; lp2 = 4; case 9: av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); lv1 = *buf1++; lv = (lv1 & 0x7F) << 1; lv += (lv << 8); lv += (lv << 16); for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) cur_lp[j] = lv; LV1_CHECK(buf1,rle_v3,lv1,lp2) default: return; cur_frm_pos += 4; ref_frm_pos += 4; cur_frm_pos += (((width * 2) - blks_width) * 4); ref_frm_pos += (((width * 2) - blks_width) * 4); default: return; if(strip < strip_tbl) return; for( ; strip >= strip_tbl; strip--) { if(strip->split_flag != 0) { strip->split_flag = 0; strip->usl7 = (strip-1)->usl7; if(strip->split_direction) { strip->xpos += strip->width; strip->width = (strip-1)->width - strip->width; if(region_160_width <= strip->xpos && width < strip->width + strip->xpos) strip->width = width - strip->xpos; } else { strip->ypos += strip->height; strip->height = (strip-1)->height - strip->height;
true
FFmpeg
a44cb89b0f53d55dd1814138ba6526ecaf985f12
6,350
static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, int *dmv_y, int *pred_flag) { int index, index1; int extend_x = 0, extend_y = 0; GetBitContext *gb = &v->s.gb; int bits, esc; int val, sign; const int* offs_tab; if (v->numref) { bits = VC1_2REF_MVDATA_VLC_BITS; esc = 125; } else { bits = VC1_1REF_MVDATA_VLC_BITS; esc = 71; } switch (v->dmvrange) { case 1: extend_x = 1; break; case 2: extend_y = 1; break; case 3: extend_x = extend_y = 1; break; } index = get_vlc2(gb, v->imv_vlc->table, bits, 3); if (index == esc) { *dmv_x = get_bits(gb, v->k_x); *dmv_y = get_bits(gb, v->k_y); if (v->numref) { *pred_flag = *dmv_y & 1; *dmv_y = (*dmv_y + *pred_flag) >> 1; } } else { if (extend_x) offs_tab = offset_table2; else offs_tab = offset_table1; index1 = (index + 1) % 9; if (index1 != 0) { val = get_bits(gb, index1 + extend_x); sign = 0 -(val & 1); *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign; } else *dmv_x = 0; if (extend_y) offs_tab = offset_table2; else offs_tab = offset_table1; index1 = (index + 1) / 9; if (index1 > v->numref) { val = get_bits(gb, (index1 + (extend_y << v->numref)) >> v->numref); sign = 0 - (val & 1); *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->numref])) - sign; } else *dmv_y = 0; if (v->numref) *pred_flag = index1 & 1; } }
true
FFmpeg
7b8c5b263bc680eff5710bee5994de39d47fc15e
6,351
static int alloc_buffers(AVCodecContext *avctx) { CFHDContext *s = avctx->priv_data; int i, j, k, ret, planes; if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0) return ret; avctx->pix_fmt = s->coded_format; avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); planes = av_pix_fmt_count_planes(avctx->pix_fmt); for (i = 0; i < planes; i++) { int width = i ? avctx->width >> s->chroma_x_shift : avctx->width; int height = i ? avctx->height >> s->chroma_y_shift : avctx->height; int stride = FFALIGN(width / 8, 8) * 8; int w8, h8, w4, h4, w2, h2; height = FFALIGN(height / 8, 2) * 8; s->plane[i].width = width; s->plane[i].height = height; s->plane[i].stride = stride; w8 = FFALIGN(s->plane[i].width / 8, 8); h8 = FFALIGN(s->plane[i].height / 8, 2); w4 = w8 * 2; h4 = h8 * 2; w2 = w4 * 2; h2 = h4 * 2; s->plane[i].idwt_buf = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_buf)); s->plane[i].idwt_tmp = av_malloc_array(height * stride, sizeof(*s->plane[i].idwt_tmp)); if (!s->plane[i].idwt_buf || !s->plane[i].idwt_tmp) { return AVERROR(ENOMEM); } s->plane[i].subband[0] = s->plane[i].idwt_buf; s->plane[i].subband[1] = s->plane[i].idwt_buf + 2 * w8 * h8; s->plane[i].subband[2] = s->plane[i].idwt_buf + 1 * w8 * h8; s->plane[i].subband[3] = s->plane[i].idwt_buf + 3 * w8 * h8; s->plane[i].subband[4] = s->plane[i].idwt_buf + 2 * w4 * h4; s->plane[i].subband[5] = s->plane[i].idwt_buf + 1 * w4 * h4; s->plane[i].subband[6] = s->plane[i].idwt_buf + 3 * w4 * h4; s->plane[i].subband[7] = s->plane[i].idwt_buf + 2 * w2 * h2; s->plane[i].subband[8] = s->plane[i].idwt_buf + 1 * w2 * h2; s->plane[i].subband[9] = s->plane[i].idwt_buf + 3 * w2 * h2; for (j = 0; j < DWT_LEVELS; j++) { for(k = 0; k < 4; k++) { s->plane[i].band[j][k].a_width = w8 << j; s->plane[i].band[j][k].a_height = h8 << j; } } /* ll2 and ll1 commented out because they are done in-place */ s->plane[i].l_h[0] = s->plane[i].idwt_tmp; s->plane[i].l_h[1] = s->plane[i].idwt_tmp + 2 * w8 * h8; //s->plane[i].l_h[2] = ll2; s->plane[i].l_h[3] = s->plane[i].idwt_tmp; s->plane[i].l_h[4] = s->plane[i].idwt_tmp + 2 * w4 * h4; //s->plane[i].l_h[5] = ll1; s->plane[i].l_h[6] = s->plane[i].idwt_tmp; s->plane[i].l_h[7] = s->plane[i].idwt_tmp + 2 * w2 * h2; } s->a_height = s->coded_height; s->a_width = s->coded_width; s->a_format = s->coded_format; return 0; }
true
FFmpeg
5fb6e39dd1c3add4dc5bd7c7f0d8100d5aadad46
6,353
static int frame_start(MpegEncContext *s) { int ret; /* mark & release old frames */ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->f.buf[0]) { ff_mpeg_unref_picture(s, s->last_picture_ptr); } s->current_picture_ptr->f.pict_type = s->pict_type; s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; ff_mpeg_unref_picture(s, &s->current_picture); if ((ret = ff_mpeg_ref_picture(s, &s->current_picture, s->current_picture_ptr)) < 0) return ret; if (s->pict_type != AV_PICTURE_TYPE_B) { s->last_picture_ptr = s->next_picture_ptr; if (!s->droppable) s->next_picture_ptr = s->current_picture_ptr; } if (s->last_picture_ptr) { ff_mpeg_unref_picture(s, &s->last_picture); if (s->last_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->last_picture, s->last_picture_ptr)) < 0) return ret; } if (s->next_picture_ptr) { ff_mpeg_unref_picture(s, &s->next_picture); if (s->next_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->next_picture, s->next_picture_ptr)) < 0) return ret; } if (s->picture_structure!= PICT_FRAME) { int i; for (i = 0; i < 4; i++) { if (s->picture_structure == PICT_BOTTOM_FIELD) { s->current_picture.f.data[i] += s->current_picture.f.linesize[i]; } s->current_picture.f.linesize[i] *= 2; s->last_picture.f.linesize[i] *= 2; s->next_picture.f.linesize[i] *= 2; } } if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { s->dct_unquantize_intra = s->dct_unquantize_h263_intra; s->dct_unquantize_inter = s->dct_unquantize_h263_inter; } else { s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; } if (s->dct_error_sum) { assert(s->avctx->noise_reduction && s->encoding); update_noise_reduction(s); } return 0; }
true
FFmpeg
f6774f905fb3cfdc319523ac640be30b14c1bc55
6,354
static always_inline void mpeg_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], int motion_x, int motion_y, int h) { uint8_t *ptr_y, *ptr_cb, *ptr_cr; int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; #if 0 if(s->quarter_sample) { motion_x>>=1; motion_y>>=1; #endif v_edge_pos = s->v_edge_pos >> field_based; linesize = s->current_picture.linesize[0] << field_based; uvlinesize = s->current_picture.linesize[1] << field_based; dxy = ((motion_y & 1) << 1) | (motion_x & 1); src_x = s->mb_x* 16 + (motion_x >> 1); src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); if (s->out_format == FMT_H263) { if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ mx = (motion_x>>1)|(motion_x&1); my = motion_y >>1; uvdxy = ((my & 1) << 1) | (mx & 1); uvsrc_x = s->mb_x* 8 + (mx >> 1); uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); }else{ uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); uvsrc_x = src_x>>1; uvsrc_y = src_y>>1; }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 mx = motion_x / 4; my = motion_y / 4; uvdxy = 0; uvsrc_x = s->mb_x*8 + mx; uvsrc_y = s->mb_y*8 + my; } else { if(s->chroma_y_shift){ mx = motion_x / 2; my = motion_y / 2; uvdxy = ((my & 1) << 1) | (mx & 1); uvsrc_x = s->mb_x* 8 + (mx >> 1); uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); } else { if(s->chroma_x_shift){ //Chroma422 mx = motion_x / 2; uvdxy = ((motion_y & 1) << 1) | (mx & 1); uvsrc_x = s->mb_x* 8 + (mx >> 1); uvsrc_y = src_y; } else { //Chroma444 uvdxy = dxy; uvsrc_x = src_x; uvsrc_y = src_y; ptr_y = ref_picture[0] + src_y * linesize + src_x; ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MPEG1VIDEO){ av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n"); return ; ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); ptr_y = s->edge_emu_buffer; if(!(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr_cb= uvbuf; ptr_cr= uvbuf+16; if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data dest_y += s->linesize; dest_cb+= s->uvlinesize; dest_cr+= s->uvlinesize; if(field_select){ ptr_y += s->linesize; ptr_cb+= s->uvlinesize; ptr_cr+= s->uvlinesize; pix_op[0][dxy](dest_y, ptr_y, linesize, h); if(!(s->flags&CODEC_FLAG_GRAY)){ pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
true
FFmpeg
5f6c92d40c2003471b005cc05430ec8488000867
6,355
static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ char buf[256]; int i; int e; int ver, build, ver2, ver3; char last; for(i=0; i<255; i++){ if(show_bits(gb, 23) == 0) break; buf[i]= get_bits(gb, 8); } buf[i]=0; /* divx detection */ e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last); if(e<2) e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last); if(e>=2){ s->divx_version= ver; s->divx_build= build; s->divx_packed= e==3 && last=='p'; } /* ffmpeg detection */ e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; if(e!=4) e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); if(e!=4){ e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1; build= (ver<<16) + (ver2<<8) + ver3; } if(e!=4){ if(strcmp(buf, "ffmpeg")==0){ s->lavc_build= 4600; } } if(e==4){ s->lavc_build= build; } /* xvid detection */ e=sscanf(buf, "XviD%d", &build); if(e==1){ s->xvid_build= build; } //printf("User Data: %s\n", buf); return 0; }
true
FFmpeg
63d33cf4390a9280b1ba42ee722f3140cf1cad3e
6,356
static void do_adaptive_prediction(struct G722Band *band, const int cur_diff) { int sg[2], limit, cur_qtzd_reconst; const int cur_part_reconst = band->s_zero + cur_diff < 0; sg[0] = sign_lookup[cur_part_reconst != band->part_reconst_mem[0]]; sg[1] = sign_lookup[cur_part_reconst == band->part_reconst_mem[1]]; band->part_reconst_mem[1] = band->part_reconst_mem[0]; band->part_reconst_mem[0] = cur_part_reconst; band->pole_mem[1] = av_clip((sg[0] * av_clip(band->pole_mem[0], -8191, 8191) >> 5) + (sg[1] << 7) + (band->pole_mem[1] * 127 >> 7), -12288, 12288); limit = 15360 - band->pole_mem[1]; band->pole_mem[0] = av_clip(-192 * sg[0] + (band->pole_mem[0] * 255 >> 8), -limit, limit); s_zero(cur_diff, band); cur_qtzd_reconst = av_clip_int16((band->s_predictor + cur_diff) << 1); band->s_predictor = av_clip_int16(band->s_zero + (band->pole_mem[0] * cur_qtzd_reconst >> 15) + (band->pole_mem[1] * band->prev_qtzd_reconst >> 15)); band->prev_qtzd_reconst = cur_qtzd_reconst; }
true
FFmpeg
f55df62998681c7702f008ce7c12a00b15e33f53
6,357
void helper_done(void) { env->pc = env->tsptr->tpc; env->npc = env->tsptr->tnpc + 4; PUT_CCR(env, env->tsptr->tstate >> 32); env->asi = (env->tsptr->tstate >> 24) & 0xff; change_pstate((env->tsptr->tstate >> 8) & 0xf3f); PUT_CWP64(env, env->tsptr->tstate & 0xff); env->tl--; env->tsptr = &env->ts[env->tl & MAXTL_MASK]; }
true
qemu
8194f35a0c71a3bf169459bf715bea53b7bbc904
6,358
static const AVClass *ff_avio_child_class_next(const AVClass *prev) { return prev ? NULL : &ffurl_context_class; }
true
FFmpeg
ec4c48397641dbaf4ae8df36c32aaa5a311a11bf
6,359
static int decode_band(IVI5DecContext *ctx, int plane_num, IVIBandDesc *band, AVCodecContext *avctx) { int result, i, t, idx1, idx2; IVITile *tile; uint16_t chksum; band->buf = band->bufs[ctx->dst_buf]; band->ref_buf = band->bufs[ctx->ref_buf]; band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3); result = decode_band_hdr(ctx, band, avctx); if (result) { av_log(avctx, AV_LOG_ERROR, "Error while decoding band header: %d\n", result); return -1; } if (band->is_empty) { av_log(avctx, AV_LOG_ERROR, "Empty band encountered!\n"); return -1; } band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel]; /* apply corrections to the selected rvmap table if present */ for (i = 0; i < band->num_corr; i++) { idx1 = band->corr[i*2]; idx2 = band->corr[i*2+1]; FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); } for (t = 0; t < band->num_tiles; t++) { tile = &band->tiles[t]; tile->is_empty = get_bits1(&ctx->gb); if (tile->is_empty) { ff_ivi_process_empty_tile(avctx, band, tile, (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3)); align_get_bits(&ctx->gb); } else { tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb); result = decode_mb_info(ctx, band, tile, avctx); if (result < 0) break; if (band->blk_size == 8) { band->intra_base = &ivi5_base_quant_8x8_intra[band->quant_mat][0]; band->inter_base = &ivi5_base_quant_8x8_inter[band->quant_mat][0]; band->intra_scale = &ivi5_scale_quant_8x8_intra[band->quant_mat][0]; band->inter_scale = &ivi5_scale_quant_8x8_inter[band->quant_mat][0]; } else { band->intra_base = ivi5_base_quant_4x4_intra; band->inter_base = ivi5_base_quant_4x4_inter; band->intra_scale = ivi5_scale_quant_4x4_intra; band->inter_scale = ivi5_scale_quant_4x4_inter; } result = ff_ivi_decode_blocks(&ctx->gb, band, tile); if (result < 0) { av_log(avctx, AV_LOG_ERROR, "Corrupted blocks data encountered!\n"); break; } } } /* restore the selected rvmap table by applying its corrections in reverse order */ for (i = band->num_corr-1; i >= 0; i--) { idx1 = band->corr[i*2]; idx2 = band->corr[i*2+1]; FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); } if (IVI_DEBUG && band->checksum_present) { chksum = ivi_calc_band_checksum(band); if (chksum != band->checksum) { av_log(avctx, AV_LOG_ERROR, "Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n", band->plane, band->band_num, band->checksum, chksum); } } return result; }
true
FFmpeg
f7d649185b62a83ab58514207151f2a8059090fb
6,360
static void test_interface_impl(const char *type) { Object *obj = object_new(type); TestIf *iobj = TEST_IF(obj); TestIfClass *ioc = TEST_IF_GET_CLASS(iobj); g_assert(iobj); g_assert(ioc->test == PATTERN); }
true
qemu
265804b5d755502438b4d42a3682f54e03ea4d32
6,362
uint32_t HELPER(shl_cc)(CPUM68KState *env, uint32_t val, uint32_t shift) { uint64_t result; shift &= 63; result = (uint64_t)val << shift; env->cc_c = (result >> 32) & 1; env->cc_n = result; env->cc_z = result; env->cc_v = 0; env->cc_x = shift ? env->cc_c : env->cc_x; return result; }
true
qemu
367790cce8e14131426f5190dfd7d1bdbf656e4d
6,363
static int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res, uint16_t **refcount_table, int64_t *refcount_table_size, int64_t offset, int64_t size) { BDRVQcowState *s = bs->opaque; uint64_t start, last, cluster_offset, k; int ret; if (size <= 0) { return 0; } start = start_of_cluster(s, offset); last = start_of_cluster(s, offset + size - 1); for(cluster_offset = start; cluster_offset <= last; cluster_offset += s->cluster_size) { k = cluster_offset >> s->cluster_bits; if (k >= *refcount_table_size) { ret = realloc_refcount_array(s, refcount_table, refcount_table_size, k + 1); if (ret < 0) { res->check_errors++; return ret; } } if (++(*refcount_table)[k] == 0) { fprintf(stderr, "ERROR: overflow cluster offset=0x%" PRIx64 "\n", cluster_offset); res->corruptions++; } } return 0; }
true
qemu
7453c96b78c2b09aa72924f933bb9616e5474194
6,364
static void test_server_free(TestServer *server) { int i; qemu_chr_delete(server->chr); for (i = 0; i < server->fds_num; i++) { close(server->fds[i]); } if (server->log_fd != -1) { close(server->log_fd); } unlink(server->socket_path); g_free(server->socket_path); g_free(server->chr_name); g_free(server); }
true
qemu
9732baf67850dac57dfc7dc8980bf408889a8973
6,365
int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors, enum qcow2_discard_type type, bool full_discard) { BDRVQcow2State *s = bs->opaque; uint64_t end_offset; uint64_t nb_clusters; int ret; end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS); /* Round start up and end down */ offset = align_offset(offset, s->cluster_size); end_offset = start_of_cluster(s, end_offset); if (offset > end_offset) { return 0; } nb_clusters = size_to_clusters(s, end_offset - offset); s->cache_discards = true; /* Each L2 table is handled by its own loop iteration */ while (nb_clusters > 0) { ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard); if (ret < 0) { goto fail; } nb_clusters -= ret; offset += (ret * s->cluster_size); } ret = 0; fail: s->cache_discards = false; qcow2_process_discards(bs, ret); return ret; }
true
qemu
0c1bd4692f9a19fb4d4bb3afe45439a09c37ab4c
6,366
static void audio_init(qemu_irq *pic) { struct soundhw *c; int audio_enabled = 0; for (c = soundhw; !audio_enabled && c->name; ++c) { audio_enabled = c->enabled; } if (audio_enabled) { AudioState *s; s = AUD_init(); if (s) { for (c = soundhw; c->name; ++c) { if (c->enabled) { if (c->isa) { c->init.init_isa(s, pic); } } } } } }
true
qemu
0d9acba8fddbf970c7353083e6a60b47017ce3e4
6,367
static int gif_image_write_image(ByteIOContext *pb, int x1, int y1, int width, int height, const uint8_t *buf, int linesize, int pix_fmt) { PutBitContext p; uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */ int i, left, w, v; const uint8_t *ptr; /* image block */ put_byte(pb, 0x2c); put_le16(pb, x1); put_le16(pb, y1); put_le16(pb, width); put_le16(pb, height); put_byte(pb, 0x00); /* flags */ /* no local clut */ put_byte(pb, 0x08); left= width * height; init_put_bits(&p, buffer, 130); /* * the thing here is the bitstream is written as little packets, with a size byte before * but it's still the same bitstream between packets (no flush !) */ ptr = buf; w = width; while(left>0) { gif_put_bits_rev(&p, 9, 0x0100); /* clear code */ for(i=0;i<GIF_CHUNKS;i++) { if (pix_fmt == PIX_FMT_RGB24) { v = gif_clut_index(ptr[0], ptr[1], ptr[2]); ptr+=3; } else { v = *ptr++; } gif_put_bits_rev(&p, 9, v); if (--w == 0) { w = width; buf += linesize; ptr = buf; } } if(left<=GIF_CHUNKS) { gif_put_bits_rev(&p, 9, 0x101); /* end of stream */ gif_flush_put_bits_rev(&p); } if(pbBufPtr(&p) - p.buf > 0) { put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */ put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */ p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */ } if(left<=GIF_CHUNKS) { put_byte(pb, 0x00); /* end of image block */ } left-=GIF_CHUNKS; } return 0; }
true
FFmpeg
f5fc28d23c46d334c809c11d62651d0080f1c325
6,368
int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err) { FILE *fh; int fd; int64_t ret = -1, handle; if (!has_mode) { mode = "r"; } slog("guest-file-open called, filepath: %s, mode: %s", path, mode); fh = fopen(path, mode); if (!fh) { error_setg_errno(err, errno, "failed to open file '%s' (mode: '%s')", path, mode); return -1; } /* set fd non-blocking to avoid common use cases (like reading from a * named pipe) from hanging the agent */ fd = fileno(fh); ret = fcntl(fd, F_GETFL); ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK); if (ret == -1) { error_setg_errno(err, errno, "failed to make file '%s' non-blocking", path); fclose(fh); return -1; } handle = guest_file_handle_add(fh, err); if (error_is_set(err)) { fclose(fh); return -1; } slog("guest-file-open, handle: %d", handle); return handle; }
true
qemu
c689b4f1bac352dcfd6ecb9a1d45337de0f1de67
6,369
static void vp5_parse_coeff_models(VP56Context *s) { VP56RangeCoder *c = &s->c; VP56Model *model = s->modelp; uint8_t def_prob[11]; int node, cg, ctx; int ct; /* code type */ int pt; /* plane type (0 for Y, 1 for U or V) */ memset(def_prob, 0x80, sizeof(def_prob)); for (pt=0; pt<2; pt++) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp5_dccv_pct[pt][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); model->coeff_dccv[pt][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { model->coeff_dccv[pt][node] = def_prob[node]; } for (ct=0; ct<3; ct++) for (pt=0; pt<2; pt++) for (cg=0; cg<6; cg++) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp5_ract_pct[ct][pt][cg][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } /* coeff_dcct is a linear combination of coeff_dccv */ for (pt=0; pt<2; pt++) for (ctx=0; ctx<36; ctx++) for (node=0; node<5; node++) model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254); /* coeff_acct is a linear combination of coeff_ract */ for (ct=0; ct<3; ct++) for (pt=0; pt<2; pt++) for (cg=0; cg<3; cg++) for (ctx=0; ctx<6; ctx++) for (node=0; node<5; node++) model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254); }
false
FFmpeg
7c249d4fbaf4431b20a90a3c942f3370c0039d9e
6,370
static void qmp_input_get_next_type(Visitor *v, int *kind, const int *qobjects, const char *name, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, false); if (!qobj) { error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); return; } *kind = qobjects[qobject_type(qobj)]; }
true
qemu
0426d53c6530606bf7641b83f2b755fe61c280ee
6,371
static void breakpoint_invalidate(CPUArchState *env, target_ulong pc) { tb_invalidate_phys_addr(cpu_get_phys_page_debug(env, pc)); }
true
qemu
9d70c4b7b8a580959cc4f739e7c9a04964d00d46
6,372
static void dump_data(const uint8_t *data, int len) {}
true
qemu
4f4321c11ff6e98583846bfd6f0e81954924b003
6,373
static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; DCTELEM *src, *dst; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; src = block; dst = block; for(i = 0; i < 4; i++){ t1 = 12 * (src[0] + src[4]) + 4; t2 = 12 * (src[0] - src[4]) + 4; t3 = 16 * src[2] + 6 * src[6]; t4 = 6 * src[2] - 16 * src[6]; t5 = t1 + t3; t6 = t2 + t4; t7 = t2 - t4; t8 = t1 - t3; t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7]; t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7]; t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7]; t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7]; dst[0] = (t5 + t1) >> 3; dst[1] = (t6 + t2) >> 3; dst[2] = (t7 + t3) >> 3; dst[3] = (t8 + t4) >> 3; dst[4] = (t8 - t4) >> 3; dst[5] = (t7 - t3) >> 3; dst[6] = (t6 - t2) >> 3; dst[7] = (t5 - t1) >> 3; src += 8; dst += 8; } src = block; for(i = 0; i < 8; i++){ t1 = 17 * (src[ 0] + src[16]) + 64; t2 = 17 * (src[ 0] - src[16]) + 64; t3 = 22 * src[ 8] + 10 * src[24]; t4 = 22 * src[24] - 10 * src[ 8]; dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)]; dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)]; dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)]; dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)]; src ++; dest++; } }
true
FFmpeg
c23acbaed40101c677dfcfbbfe0d2c230a8e8f44
6,375
void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg) { const uint8_t type_code[] = { [GDB_BREAKPOINT_HW] = 0x0, [GDB_WATCHPOINT_WRITE] = 0x1, [GDB_WATCHPOINT_ACCESS] = 0x3 }; const uint8_t len_code[] = { [1] = 0x0, [2] = 0x1, [4] = 0x3, [8] = 0x2 }; int n; if (kvm_sw_breakpoints_active(env)) dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP; if (nb_hw_breakpoint > 0) { dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP; dbg->arch.debugreg[7] = 0x0600; for (n = 0; n < nb_hw_breakpoint; n++) { dbg->arch.debugreg[n] = hw_breakpoint[n].addr; dbg->arch.debugreg[7] |= (2 << (n * 2)) | (type_code[hw_breakpoint[n].type] << (16 + n*4)) | (len_code[hw_breakpoint[n].len] << (18 + n*4)); } } /* Legal xcr0 for loading */ env->xcr0 = 1; }
true
qemu
95c077c91900c1420cd4f0be996ffeea6fb6cec8
6,376
static inline int cris_swap(const int mode, int x) { switch (mode) { case N: asm ("swapn\t%0\n" : "+r" (x) : "0" (x)); break; case W: asm ("swapw\t%0\n" : "+r" (x) : "0" (x)); break; case B: asm ("swapb\t%0\n" : "+r" (x) : "0" (x)); break; case R: asm ("swapr\t%0\n" : "+r" (x) : "0" (x)); break; case B|R: asm ("swapbr\t%0\n" : "+r" (x) : "0" (x)); break; case W|R: asm ("swapwr\t%0\n" : "+r" (x) : "0" (x)); break; case W|B: asm ("swapwb\t%0\n" : "+r" (x) : "0" (x)); break; case W|B|R: asm ("swapwbr\t%0\n" : "+r" (x) : "0" (x)); break; case N|R: asm ("swapnr\t%0\n" : "+r" (x) : "0" (x)); break; case N|B: asm ("swapnb\t%0\n" : "+r" (x) : "0" (x)); break; case N|B|R: asm ("swapnbr\t%0\n" : "+r" (x) : "0" (x)); break; case N|W: asm ("swapnw\t%0\n" : "+r" (x) : "0" (x)); break; default: err(); break; } return x; }
true
qemu
21ce148c7ec71ee32834061355a5ecfd1a11f90f
6,378
static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos, int *outFilterSize, int xInc, int srcW, int dstW, int filterAlign, int one, int flags, int cpu_flags, SwsVector *srcFilter, SwsVector *dstFilter, double param[2], int srcPos, int dstPos) { int i; int filterSize; int filter2Size; int minFilterSize; int64_t *filter = NULL; int64_t *filter2 = NULL; const int64_t fone = 1LL << (54 - FFMIN(av_log2(srcW/dstW), 8)); int ret = -1; emms_c(); // FIXME should not be required but IS (even for non-MMX versions) // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail); if (FFABS(xInc - 0x10000) < 10 && srcPos == dstPos) { // unscaled int i; filterSize = 1; FF_ALLOCZ_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); for (i = 0; i < dstW; i++) { filter[i * filterSize] = fone; (*filterPos)[i] = i; } else if (flags & SWS_POINT) { // lame looking point sampling mode int i; int64_t xDstInSrc; filterSize = 1; FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7); for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16; (*filterPos)[i] = xx; filter[i] = fone; xDstInSrc += xInc; } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) || (flags & SWS_FAST_BILINEAR)) { // bilinear upscale int i; int64_t xDstInSrc; filterSize = 2; FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7); for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16; int j; (*filterPos)[i] = xx; // bilinear upscale / linear interpolate / area averaging for (j = 0; j < filterSize; j++) { int64_t coeff= fone - FFABS(((int64_t)xx<<16) - xDstInSrc)*(fone>>16); if (coeff < 0) coeff = 0; filter[i * filterSize + j] = coeff; xx++; xDstInSrc += xInc; } else { int64_t xDstInSrc; int sizeFactor; if (flags & SWS_BICUBIC) sizeFactor = 4; else if (flags & SWS_X) sizeFactor = 8; else if (flags & SWS_AREA) sizeFactor = 1; // downscale only, for upscale it is bilinear else if (flags & SWS_GAUSS) sizeFactor = 8; // infinite ;) else if (flags & SWS_LANCZOS) sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6; else if (flags & SWS_SINC) sizeFactor = 20; // infinite ;) else if (flags & SWS_SPLINE) sizeFactor = 20; // infinite ;) else if (flags & SWS_BILINEAR) sizeFactor = 2; else { av_assert0(0); if (xInc <= 1 << 16) filterSize = 1 + sizeFactor; // upscale else filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW; filterSize = FFMIN(filterSize, srcW - 2); filterSize = FFMAX(filterSize, 1); FF_ALLOC_OR_GOTO(NULL, filter, dstW * sizeof(*filter) * filterSize, fail); xDstInSrc = ((dstPos*(int64_t)xInc)>>7) - ((srcPos*0x10000LL)>>7); for (i = 0; i < dstW; i++) { int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17); int j; (*filterPos)[i] = xx; for (j = 0; j < filterSize; j++) { int64_t d = (FFABS(((int64_t)xx << 17) - xDstInSrc)) << 13; double floatd; int64_t coeff; if (xInc > 1 << 16) d = d * dstW / srcW; floatd = d * (1.0 / (1 << 30)); if (flags & SWS_BICUBIC) { int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24); int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24); if (d >= 1LL << 31) { coeff = 0.0; } else { int64_t dd = (d * d) >> 30; int64_t ddd = (dd * d) >> 30; if (d < 1LL << 30) coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd + (-18 * (1 << 24) + 12 * B + 6 * C) * dd + (6 * (1 << 24) - 2 * B) * (1 << 30); else coeff = (-B - 6 * C) * ddd + (6 * B + 30 * C) * dd + (-12 * B - 48 * C) * d + (8 * B + 24 * C) * (1 << 30); coeff /= (1LL<<54)/fone; #if 0 else if (flags & SWS_X) { double p = param ? param * 0.01 : 0.3; coeff = d ? sin(d * M_PI) / (d * M_PI) : 1.0; coeff *= pow(2.0, -p * d * d); #endif else if (flags & SWS_X) { double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; double c; if (floatd < 1.0) c = cos(floatd * M_PI); else c = -1.0; if (c < 0.0) c = -pow(-c, A); else c = pow(c, A); coeff = (c * 0.5 + 0.5) * fone; } else if (flags & SWS_AREA) { int64_t d2 = d - (1 << 29); if (d2 * xInc < -(1LL << (29 + 16))) coeff = 1.0 * (1LL << (30 + 16)); else if (d2 * xInc < (1LL << (29 + 16))) coeff = -d2 * xInc + (1LL << (29 + 16)); else coeff = 0.0; coeff *= fone >> (30 + 16); } else if (flags & SWS_GAUSS) { double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (pow(2.0, -p * floatd * floatd)) * fone; } else if (flags & SWS_SINC) { coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone; } else if (flags & SWS_LANCZOS) { double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) / (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone; if (floatd > p) coeff = 0; } else if (flags & SWS_BILINEAR) { coeff = (1 << 30) - d; if (coeff < 0) coeff = 0; coeff *= fone >> 30; } else if (flags & SWS_SPLINE) { double p = -2.196152422706632; coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone; } else { av_assert0(0); filter[i * filterSize + j] = coeff; xx++; xDstInSrc += 2 * xInc; /* apply src & dst Filter to filter -> filter2 * av_free(filter); */ av_assert0(filterSize > 0); filter2Size = filterSize; if (srcFilter) filter2Size += srcFilter->length - 1; if (dstFilter) filter2Size += dstFilter->length - 1; av_assert0(filter2Size > 0); FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size * dstW * sizeof(*filter2), fail); for (i = 0; i < dstW; i++) { int j, k; if (srcFilter) { for (k = 0; k < srcFilter->length; k++) { for (j = 0; j < filterSize; j++) filter2[i * filter2Size + k + j] += srcFilter->coeff[k] * filter[i * filterSize + j]; } else { for (j = 0; j < filterSize; j++) filter2[i * filter2Size + j] = filter[i * filterSize + j]; // FIXME dstFilter (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2; av_freep(&filter); /* try to reduce the filter-size (step1 find size and shift left) */ // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not). minFilterSize = 0; for (i = dstW - 1; i >= 0; i--) { int min = filter2Size; int j; int64_t cutOff = 0.0; /* get rid of near zero elements on the left by shifting left */ for (j = 0; j < filter2Size; j++) { int k; cutOff += FFABS(filter2[i * filter2Size]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone) break; /* preserve monotonicity because the core can't handle the * filter otherwise */ if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1]) break; // move filter coefficients left for (k = 1; k < filter2Size; k++) filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k]; filter2[i * filter2Size + k - 1] = 0; (*filterPos)[i]++; cutOff = 0; /* count near zeros on the right */ for (j = filter2Size - 1; j > 0; j--) { cutOff += FFABS(filter2[i * filter2Size + j]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone) break; min--; if (min > minFilterSize) minFilterSize = min; if (PPC_ALTIVEC(cpu_flags)) { // we can handle the special case 4, so we don't want to go the full 8 if (minFilterSize < 5) filterAlign = 4; /* We really don't want to waste our time doing useless computation, so * fall back on the scalar C code for very small filters. * Vectorizing is worth it only if you have a decent-sized vector. */ if (minFilterSize < 3) filterAlign = 1; if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { // special case for unscaled vertical filtering if (minFilterSize == 1 && filterAlign == 2) filterAlign = 1; av_assert0(minFilterSize > 0); filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1)); av_assert0(filterSize > 0); filter = av_malloc(filterSize * dstW * sizeof(*filter)); if (filterSize >= MAX_FILTER_SIZE * 16 / ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) { av_log(NULL, AV_LOG_ERROR, "sws: filterSize %d is too large, try less extreem scaling or increase MAX_FILTER_SIZE and recompile\n", filterSize); goto fail; *outFilterSize = filterSize; if (flags & SWS_PRINT_INFO) av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); /* try to reduce the filter-size (step2 reduce it) */ for (i = 0; i < dstW; i++) { int j; for (j = 0; j < filterSize; j++) { if (j >= filter2Size) filter[i * filterSize + j] = 0; else filter[i * filterSize + j] = filter2[i * filter2Size + j]; if ((flags & SWS_BITEXACT) && j >= minFilterSize) filter[i * filterSize + j] = 0; // FIXME try to align filterPos if possible // fix borders for (i = 0; i < dstW; i++) { int j; if ((*filterPos)[i] < 0) { // move filter coefficients left to compensate for filterPos for (j = 1; j < filterSize; j++) { int left = FFMAX(j + (*filterPos)[i], 0); filter[i * filterSize + left] += filter[i * filterSize + j]; filter[i * filterSize + j] = 0; (*filterPos)[i]= 0; if ((*filterPos)[i] + filterSize > srcW) { int shift = (*filterPos)[i] + filterSize - srcW; // move filter coefficients right to compensate for filterPos for (j = filterSize - 2; j >= 0; j--) { int right = FFMIN(j + shift, filterSize - 1); filter[i * filterSize + right] += filter[i * filterSize + j]; filter[i * filterSize + j] = 0; (*filterPos)[i]= srcW - filterSize; // Note the +1 is for the MMX scaler which reads over the end /* align at 16 for AltiVec (needed by hScale_altivec_real) */ FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize * (dstW + 3) * sizeof(int16_t), fail); /* normalize & store in outFilter */ for (i = 0; i < dstW; i++) { int j; int64_t error = 0; int64_t sum = 0; for (j = 0; j < filterSize; j++) { sum += filter[i * filterSize + j]; sum = (sum + one / 2) / one; for (j = 0; j < *outFilterSize; j++) { int64_t v = filter[i * filterSize + j] + error; int intV = ROUNDED_DIV(v, sum); (*outFilter)[i * (*outFilterSize) + j] = intV; error = v - intV * sum; (*filterPos)[dstW + 0] = (*filterPos)[dstW + 1] = (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will * read over the end */ for (i = 0; i < *outFilterSize; i++) { int k = (dstW - 1) * (*outFilterSize) + i; (*outFilter)[k + 1 * (*outFilterSize)] = (*outFilter)[k + 2 * (*outFilterSize)] = (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k]; ret = 0; fail: if(ret < 0) av_log(NULL, AV_LOG_ERROR, "sws: initFilter failed\n"); av_free(filter); av_free(filter2); return ret;
true
FFmpeg
2e2a2d8801b045b3dd58a4e49e8e040b559bc84a
6,379
static uint64_t hb_count_between(HBitmap *hb, uint64_t start, uint64_t last) { HBitmapIter hbi; uint64_t count = 0; uint64_t end = last + 1; unsigned long cur; size_t pos; hbitmap_iter_init(&hbi, hb, start << hb->granularity); for (;;) { pos = hbitmap_iter_next_word(&hbi, &cur); if (pos >= (end >> BITS_PER_LEVEL)) { break; } count += popcountl(cur); } if (pos == (end >> BITS_PER_LEVEL)) { /* Drop bits representing the END-th and subsequent items. */ int bit = end & (BITS_PER_LONG - 1); cur &= (1UL << bit) - 1; count += popcountl(cur); } return count; }
true
qemu
591b320ad046b2780c1b2841b836b50ba8192f02
6,380
static int img_convert(int argc, char **argv) { int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size, cluster_sectors; int progress = 0, flags; const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename; BlockDriver *drv, *proto_drv; BlockDriverState **bs = NULL, *out_bs = NULL; int64_t total_sectors, nb_sectors, sector_num, bs_offset; uint64_t bs_sectors; uint8_t * buf = NULL; const uint8_t *buf1; BlockDriverInfo bdi; QEMUOptionParameter *param = NULL, *create_options = NULL; QEMUOptionParameter *out_baseimg_param; char *options = NULL; const char *snapshot_name = NULL; float local_progress; int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */ fmt = NULL; out_fmt = "raw"; cache = "unsafe"; out_baseimg = NULL; compress = 0; for(;;) { c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:"); if (c == -1) { break; } switch(c) { case '?': case 'h': help(); break; case 'f': fmt = optarg; break; case 'O': out_fmt = optarg; break; case 'B': out_baseimg = optarg; break; case 'c': compress = 1; break; case 'e': error_report("option -e is deprecated, please use \'-o " "encryption\' instead!"); return 1; case '6': error_report("option -6 is deprecated, please use \'-o " "compat6\' instead!"); return 1; case 'o': options = optarg; break; case 's': snapshot_name = optarg; break; case 'S': { int64_t sval; char *end; sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B); if (sval < 0 || *end) { error_report("Invalid minimum zero buffer size for sparse output specified"); return 1; } min_sparse = sval / BDRV_SECTOR_SIZE; break; } case 'p': progress = 1; break; case 't': cache = optarg; break; } } bs_n = argc - optind - 1; if (bs_n < 1) { help(); } out_filename = argv[argc - 1]; /* Initialize before goto out */ qemu_progress_init(progress, 2.0); if (options && !strcmp(options, "?")) { ret = print_block_option_help(out_filename, out_fmt); goto out; } if (bs_n > 1 && out_baseimg) { error_report("-B makes no sense when concatenating multiple input " "images"); ret = -1; goto out; } qemu_progress_print(0, 100); bs = g_malloc0(bs_n * sizeof(BlockDriverState *)); total_sectors = 0; for (bs_i = 0; bs_i < bs_n; bs_i++) { bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS); if (!bs[bs_i]) { error_report("Could not open '%s'", argv[optind + bs_i]); ret = -1; goto out; } bdrv_get_geometry(bs[bs_i], &bs_sectors); total_sectors += bs_sectors; } if (snapshot_name != NULL) { if (bs_n > 1) { error_report("No support for concatenating multiple snapshot"); ret = -1; goto out; } if (bdrv_snapshot_load_tmp(bs[0], snapshot_name) < 0) { error_report("Failed to load snapshot"); ret = -1; goto out; } } /* Find driver and parse its options */ drv = bdrv_find_format(out_fmt); if (!drv) { error_report("Unknown file format '%s'", out_fmt); ret = -1; goto out; } proto_drv = bdrv_find_protocol(out_filename); if (!proto_drv) { error_report("Unknown protocol '%s'", out_filename); ret = -1; goto out; } create_options = append_option_parameters(create_options, drv->create_options); create_options = append_option_parameters(create_options, proto_drv->create_options); if (options) { param = parse_option_parameters(options, create_options, param); if (param == NULL) { error_report("Invalid options for file format '%s'.", out_fmt); ret = -1; goto out; } } else { param = parse_option_parameters("", create_options, param); } set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512); ret = add_old_style_options(out_fmt, param, out_baseimg, NULL); if (ret < 0) { goto out; } /* Get backing file name if -o backing_file was used */ out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); if (out_baseimg_param) { out_baseimg = out_baseimg_param->value.s; } /* Check if compression is supported */ if (compress) { QEMUOptionParameter *encryption = get_option_parameter(param, BLOCK_OPT_ENCRYPT); QEMUOptionParameter *preallocation = get_option_parameter(param, BLOCK_OPT_PREALLOC); if (!drv->bdrv_write_compressed) { error_report("Compression not supported for this file format"); ret = -1; goto out; } if (encryption && encryption->value.n) { error_report("Compression and encryption not supported at " "the same time"); ret = -1; goto out; } if (preallocation && preallocation->value.s && strcmp(preallocation->value.s, "off")) { error_report("Compression and preallocation not supported at " "the same time"); ret = -1; goto out; } } /* Create the new image */ ret = bdrv_create(drv, out_filename, param); if (ret < 0) { if (ret == -ENOTSUP) { error_report("Formatting not supported for file format '%s'", out_fmt); } else if (ret == -EFBIG) { error_report("The image size is too large for file format '%s'", out_fmt); } else { error_report("%s: error while converting %s: %s", out_filename, out_fmt, strerror(-ret)); } goto out; } flags = BDRV_O_RDWR; ret = bdrv_parse_cache_flags(cache, &flags); if (ret < 0) { error_report("Invalid cache option: %s", cache); return -1; } out_bs = bdrv_new_open(out_filename, out_fmt, flags); if (!out_bs) { ret = -1; goto out; } bs_i = 0; bs_offset = 0; bdrv_get_geometry(bs[0], &bs_sectors); buf = qemu_blockalign(out_bs, IO_BUF_SIZE); if (compress) { ret = bdrv_get_info(out_bs, &bdi); if (ret < 0) { error_report("could not get block driver info"); goto out; } cluster_size = bdi.cluster_size; if (cluster_size <= 0 || cluster_size > IO_BUF_SIZE) { error_report("invalid cluster size"); ret = -1; goto out; } cluster_sectors = cluster_size >> 9; sector_num = 0; nb_sectors = total_sectors; local_progress = (float)100 / (nb_sectors / MIN(nb_sectors, cluster_sectors)); for(;;) { int64_t bs_num; int remainder; uint8_t *buf2; nb_sectors = total_sectors - sector_num; if (nb_sectors <= 0) break; if (nb_sectors >= cluster_sectors) n = cluster_sectors; else n = nb_sectors; bs_num = sector_num - bs_offset; assert (bs_num >= 0); remainder = n; buf2 = buf; while (remainder > 0) { int nlow; while (bs_num == bs_sectors) { bs_i++; assert (bs_i < bs_n); bs_offset += bs_sectors; bdrv_get_geometry(bs[bs_i], &bs_sectors); bs_num = 0; /* printf("changing part: sector_num=%" PRId64 ", " "bs_i=%d, bs_offset=%" PRId64 ", bs_sectors=%" PRId64 "\n", sector_num, bs_i, bs_offset, bs_sectors); */ } assert (bs_num < bs_sectors); nlow = (remainder > bs_sectors - bs_num) ? bs_sectors - bs_num : remainder; ret = bdrv_read(bs[bs_i], bs_num, buf2, nlow); if (ret < 0) { error_report("error while reading sector %" PRId64 ": %s", bs_num, strerror(-ret)); goto out; } buf2 += nlow * 512; bs_num += nlow; remainder -= nlow; } assert (remainder == 0); if (n < cluster_sectors) { memset(buf + n * 512, 0, cluster_size - n * 512); } if (!buffer_is_zero(buf, cluster_size)) { ret = bdrv_write_compressed(out_bs, sector_num, buf, cluster_sectors); if (ret != 0) { error_report("error while compressing sector %" PRId64 ": %s", sector_num, strerror(-ret)); goto out; } } sector_num += n; qemu_progress_print(local_progress, 100); } /* signal EOF to align */ bdrv_write_compressed(out_bs, 0, NULL, 0); } else { int has_zero_init = bdrv_has_zero_init(out_bs); sector_num = 0; // total number of sectors converted so far nb_sectors = total_sectors - sector_num; local_progress = (float)100 / (nb_sectors / MIN(nb_sectors, IO_BUF_SIZE / 512)); for(;;) { nb_sectors = total_sectors - sector_num; if (nb_sectors <= 0) { break; } if (nb_sectors >= (IO_BUF_SIZE / 512)) { n = (IO_BUF_SIZE / 512); } else { n = nb_sectors; } while (sector_num - bs_offset >= bs_sectors) { bs_i ++; assert (bs_i < bs_n); bs_offset += bs_sectors; bdrv_get_geometry(bs[bs_i], &bs_sectors); /* printf("changing part: sector_num=%" PRId64 ", bs_i=%d, " "bs_offset=%" PRId64 ", bs_sectors=%" PRId64 "\n", sector_num, bs_i, bs_offset, bs_sectors); */ } if (n > bs_offset + bs_sectors - sector_num) { n = bs_offset + bs_sectors - sector_num; } if (has_zero_init) { /* If the output image is being created as a copy on write image, assume that sectors which are unallocated in the input image are present in both the output's and input's base images (no need to copy them). */ if (out_baseimg) { if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, n, &n1)) { sector_num += n1; continue; } /* The next 'n1' sectors are allocated in the input image. Copy only those as they may be followed by unallocated sectors. */ n = n1; } } else { n1 = n; } ret = bdrv_read(bs[bs_i], sector_num - bs_offset, buf, n); if (ret < 0) { error_report("error while reading sector %" PRId64 ": %s", sector_num - bs_offset, strerror(-ret)); goto out; } /* NOTE: at the same time we convert, we do not write zero sectors to have a chance to compress the image. Ideally, we should add a specific call to have the info to go faster */ buf1 = buf; while (n > 0) { /* If the output image is being created as a copy on write image, copy all sectors even the ones containing only NUL bytes, because they may differ from the sectors in the base image. If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ if (!has_zero_init || out_baseimg || is_allocated_sectors_min(buf1, n, &n1, min_sparse)) { ret = bdrv_write(out_bs, sector_num, buf1, n1); if (ret < 0) { error_report("error while writing sector %" PRId64 ": %s", sector_num, strerror(-ret)); goto out; } } sector_num += n1; n -= n1; buf1 += n1 * 512; } qemu_progress_print(local_progress, 100); } } out: qemu_progress_end(); free_option_parameters(create_options); free_option_parameters(param); qemu_vfree(buf); if (out_bs) { bdrv_delete(out_bs); } if (bs) { for (bs_i = 0; bs_i < bs_n; bs_i++) { if (bs[bs_i]) { bdrv_delete(bs[bs_i]); } } g_free(bs); } if (ret) { return 1; } return 0; }
true
qemu
c8057f951d64de93bfd01569c0a725baa9f94372
6,381
static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVIContext *avi = s->priv_data; ByteIOContext *pb = &s->pb; uint32_t tag, tag1, handler; int codec_type, stream_index, frame_period, bit_rate, scale, rate; unsigned int size, nb_frames; int i, n; AVStream *st; AVIStream *ast; int xan_video = 0; /* hack to support Xan A/V */ if (get_riff(avi, pb) < 0) return -1; /* first list tag */ stream_index = -1; codec_type = -1; frame_period = 0; for(;;) { if (url_feof(pb)) goto fail; tag = get_le32(pb); size = get_le32(pb); #ifdef DEBUG print_tag("tag", tag, size); #endif switch(tag) { case MKTAG('L', 'I', 'S', 'T'): /* ignored, except when start of video packets */ tag1 = get_le32(pb); #ifdef DEBUG print_tag("list", tag1, 0); #endif if (tag1 == MKTAG('m', 'o', 'v', 'i')) { avi->movi_list = url_ftell(pb) - 4; if(size) avi->movi_end = avi->movi_list + size; else avi->movi_end = url_filesize(url_fileno(pb)); #ifdef DEBUG printf("movi end=%Lx\n", avi->movi_end); #endif goto end_of_header; } break; case MKTAG('d', 'm', 'l', 'h'): avi->is_odml = 1; url_fskip(pb, size + (size & 1)); break; case MKTAG('a', 'v', 'i', 'h'): /* avi header */ /* using frame_period is bad idea */ frame_period = get_le32(pb); bit_rate = get_le32(pb) * 8; url_fskip(pb, 4 * 4); n = get_le32(pb); for(i=0;i<n;i++) { AVIStream *ast; st = av_new_stream(s, i); if (!st) goto fail; ast = av_mallocz(sizeof(AVIStream)); if (!ast) goto fail; st->priv_data = ast; } url_fskip(pb, size - 7 * 4); break; case MKTAG('s', 't', 'r', 'h'): /* stream header */ stream_index++; tag1 = get_le32(pb); handler = get_le32(pb); /* codec tag */ #ifdef DEBUG print_tag("strh", tag1, -1); #endif switch(tag1) { case MKTAG('i', 'a', 'v', 's'): case MKTAG('i', 'v', 'a', 's'): /* * After some consideration -- I don't think we * have to support anything but DV in a type1 AVIs. */ if (s->nb_streams != 1) goto fail; if (handler != MKTAG('d', 'v', 's', 'd') && handler != MKTAG('d', 'v', 'h', 'd') && handler != MKTAG('d', 'v', 's', 'l')) goto fail; ast = s->streams[0]->priv_data; av_freep(&s->streams[0]->codec.extradata); av_freep(&s->streams[0]); s->nb_streams = 0; avi->dv_demux = dv_init_demux(s); if (!avi->dv_demux) goto fail; s->streams[0]->priv_data = ast; url_fskip(pb, 3 * 4); ast->scale = get_le32(pb); ast->rate = get_le32(pb); stream_index = s->nb_streams - 1; url_fskip(pb, size - 7*4); break; case MKTAG('v', 'i', 'd', 's'): codec_type = CODEC_TYPE_VIDEO; if (stream_index >= s->nb_streams) { url_fskip(pb, size - 8); break; } st = s->streams[stream_index]; ast = st->priv_data; st->codec.stream_codec_tag= handler; get_le32(pb); /* flags */ get_le16(pb); /* priority */ get_le16(pb); /* language */ get_le32(pb); /* XXX: initial frame ? */ scale = get_le32(pb); /* scale */ rate = get_le32(pb); /* rate */ if(scale && rate){ }else if(frame_period){ rate = 1000000; scale = frame_period; }else{ rate = 25; scale = 1; } ast->rate = rate; ast->scale = scale; av_set_pts_info(st, 64, scale, rate); st->codec.frame_rate = rate; st->codec.frame_rate_base = scale; get_le32(pb); /* start */ nb_frames = get_le32(pb); st->start_time = 0; st->duration = av_rescale(nb_frames, st->codec.frame_rate_base * AV_TIME_BASE, st->codec.frame_rate); url_fskip(pb, size - 9 * 4); break; case MKTAG('a', 'u', 'd', 's'): { unsigned int length; codec_type = CODEC_TYPE_AUDIO; if (stream_index >= s->nb_streams) { url_fskip(pb, size - 8); break; } st = s->streams[stream_index]; ast = st->priv_data; get_le32(pb); /* flags */ get_le16(pb); /* priority */ get_le16(pb); /* language */ get_le32(pb); /* initial frame */ ast->scale = get_le32(pb); /* scale */ ast->rate = get_le32(pb); if(!ast->rate) ast->rate= 1; //wrong but better then 1/0 if(!ast->scale) ast->scale= 1; //wrong but better then 1/0 av_set_pts_info(st, 64, ast->scale, ast->rate); ast->start= get_le32(pb); /* start */ length = get_le32(pb); /* length, in samples or bytes */ get_le32(pb); /* buffer size */ get_le32(pb); /* quality */ ast->sample_size = get_le32(pb); /* sample ssize */ //av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d\n", ast->scale, ast->rate, ast->sample_size, ast->start); st->start_time = 0; if (ast->rate != 0) st->duration = (int64_t)length * AV_TIME_BASE / ast->rate; url_fskip(pb, size - 12 * 4); } break; case MKTAG('t', 'x', 't', 's'): //FIXME codec_type = CODEC_TYPE_DATA; //CODEC_TYPE_SUB ? FIXME url_fskip(pb, size - 8); break; case MKTAG('p', 'a', 'd', 's'): codec_type = CODEC_TYPE_UNKNOWN; url_fskip(pb, size - 8); stream_index--; break; default: av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1); goto fail; } break; case MKTAG('s', 't', 'r', 'f'): /* stream header */ if (stream_index >= s->nb_streams || avi->dv_demux) { url_fskip(pb, size); } else { st = s->streams[stream_index]; switch(codec_type) { case CODEC_TYPE_VIDEO: get_le32(pb); /* size */ st->codec.width = get_le32(pb); st->codec.height = get_le32(pb); get_le16(pb); /* panes */ st->codec.bits_per_sample= get_le16(pb); /* depth */ tag1 = get_le32(pb); get_le32(pb); /* ImageSize */ get_le32(pb); /* XPelsPerMeter */ get_le32(pb); /* YPelsPerMeter */ get_le32(pb); /* ClrUsed */ get_le32(pb); /* ClrImportant */ if(size > 10*4 && size<(1<<30)){ st->codec.extradata_size= size - 10*4; st->codec.extradata= av_malloc(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); get_buffer(pb, st->codec.extradata, st->codec.extradata_size); } if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly get_byte(pb); /* Extract palette from extradata if bpp <= 8 */ /* This code assumes that extradata contains only palette */ /* This is true for all paletted codecs implemented in ffmpeg */ if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) { st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl)); #ifdef WORDS_BIGENDIAN for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++) st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]); #else memcpy(st->codec.palctrl->palette, st->codec.extradata, FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)); #endif st->codec.palctrl->palette_changed = 1; } #ifdef DEBUG print_tag("video", tag1, 0); #endif st->codec.codec_type = CODEC_TYPE_VIDEO; st->codec.codec_tag = tag1; st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); if (st->codec.codec_id == CODEC_ID_XAN_WC4) xan_video = 1; // url_fskip(pb, size - 5 * 4); break; case CODEC_TYPE_AUDIO: get_wav_header(pb, &st->codec, size); if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ url_fskip(pb, 1); /* special case time: To support Xan DPCM, hardcode * the format if Xxan is the video codec */ st->need_parsing = 1; /* force parsing as several audio frames can be in one packet */ if (xan_video) st->codec.codec_id = CODEC_ID_XAN_DPCM; break; default: st->codec.codec_type = CODEC_TYPE_DATA; st->codec.codec_id= CODEC_ID_NONE; st->codec.codec_tag= 0; url_fskip(pb, size); break; } } break; default: /* skip tag */ size += (size & 1); url_fskip(pb, size); break; } } end_of_header: /* check stream number */ if (stream_index != s->nb_streams - 1) { fail: for(i=0;i<s->nb_streams;i++) { av_freep(&s->streams[i]->codec.extradata); av_freep(&s->streams[i]); } return -1; } assert(!avi->index_loaded); avi_load_index(s); avi->index_loaded = 1; return 0; }
true
FFmpeg
8d65750ef1089561f0257fa1719b3094f341d16f
6,382
static void test_io(void) { #ifndef _WIN32 /* socketpair(PF_UNIX) which does not exist on windows */ int sv[2]; int r; unsigned i, j, k, s, t; fd_set fds; unsigned niov; struct iovec *iov, *siov; unsigned char *buf; size_t sz; iov_random(&iov, &niov); sz = iov_size(iov, niov); buf = g_malloc(sz); for (i = 0; i < sz; ++i) { buf[i] = i & 255; } iov_from_buf(iov, niov, 0, buf, sz); siov = g_malloc(sizeof(*iov) * niov); memcpy(siov, iov, sizeof(*iov) * niov); if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) < 0) { perror("socketpair"); exit(1); } FD_ZERO(&fds); t = 0; if (fork() == 0) { /* writer */ close(sv[0]); FD_SET(sv[1], &fds); fcntl(sv[1], F_SETFL, O_RDWR|O_NONBLOCK); r = g_test_rand_int_range(sz / 2, sz); setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &r, sizeof(r)); for (i = 0; i <= sz; ++i) { for (j = i; j <= sz; ++j) { k = i; do { s = g_test_rand_int_range(0, j - k + 1); r = iov_send(sv[1], iov, niov, k, s); g_assert(memcmp(iov, siov, sizeof(*iov)*niov) == 0); if (r >= 0) { k += r; t += r; usleep(g_test_rand_int_range(0, 30)); } else if (errno == EAGAIN) { select(sv[1]+1, NULL, &fds, NULL, NULL); continue; } else { perror("send"); exit(1); } } while(k < j); } } exit(0); } else { /* reader & verifier */ close(sv[1]); FD_SET(sv[0], &fds); fcntl(sv[0], F_SETFL, O_RDWR|O_NONBLOCK); r = g_test_rand_int_range(sz / 2, sz); setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &r, sizeof(r)); usleep(500000); for (i = 0; i <= sz; ++i) { for (j = i; j <= sz; ++j) { k = i; iov_memset(iov, niov, 0, 0xff, -1); do { s = g_test_rand_int_range(0, j - k + 1); r = iov_recv(sv[0], iov, niov, k, s); g_assert(memcmp(iov, siov, sizeof(*iov)*niov) == 0); if (r > 0) { k += r; t += r; } else if (!r) { if (s) { break; } } else if (errno == EAGAIN) { select(sv[0]+1, &fds, NULL, NULL, NULL); continue; } else { perror("recv"); exit(1); } } while(k < j); test_iov_bytes(iov, niov, i, j - i); } } } #endif }
true
qemu
d55f295b2b5477528da601dba57880b0d5f24cb1
6,383
static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { Jpeg2000DecoderContext *s = avctx->priv_data; ThreadFrame frame = { .f = data }; AVFrame *picture = data; int tileno, ret; s->avctx = avctx; s->buf = s->buf_start = avpkt->data; s->buf_end = s->buf_start + avpkt->size; s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles // reduction factor, i.e number of resolution levels to skip s->reduction_factor = s->lowres; if (s->buf_end - s->buf < 2) return AVERROR_INVALIDDATA; // check if the image is in jp2 format if ((AV_RB32(s->buf) == 12) && (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) && (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) { if (!jp2_find_codestream(s)) { av_log(avctx, AV_LOG_ERROR, "Could not find Jpeg2000 codestream atom.\n"); return AVERROR_INVALIDDATA; } } if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) { av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n"); return AVERROR_INVALIDDATA; } if (ret = jpeg2000_read_main_headers(s)) goto end; /* get picture buffer */ if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\n"); goto end; } picture->pict_type = AV_PICTURE_TYPE_I; picture->key_frame = 1; if (ret = jpeg2000_read_bitstream_packets(s)) goto end; for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture)) goto end; *got_frame = 1; end: jpeg2000_dec_cleanup(s); return ret ? ret : s->buf - s->buf_start; }
true
FFmpeg
1a3598aae768465a8efc8475b6df5a8261bc62fc
6,384
static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine) { int i; HotpluggableCPUList *head = NULL; sPAPRMachineState *spapr = SPAPR_MACHINE(machine); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine); int spapr_max_cores = max_cpus / smp_threads; g_assert(smc->dr_cpu_enabled); for (i = 0; i < spapr_max_cores; i++) { HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1); HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1); CpuInstanceProperties *cpu_props = g_new0(typeof(*cpu_props), 1); cpu_item->type = spapr_get_cpu_core_type(machine->cpu_model); cpu_item->vcpus_count = smp_threads; cpu_props->has_core_id = true; cpu_props->core_id = i * smp_threads; /* TODO: add 'has_node/node' here to describe to which node core belongs */ cpu_item->props = cpu_props; if (spapr->cores[i]) { cpu_item->has_qom_path = true; cpu_item->qom_path = object_get_canonical_path(spapr->cores[i]); } list_item->value = cpu_item; list_item->next = head; head = list_item; } return head; }
true
qemu
3c0c47e3464f3c54bd3f1cc6d4da2cbf7465e295
6,386
static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska, uint8_t *data, uint32_t size, uint64_t *num) { ByteIOContext pb; init_put_byte(&pb, data, size, 0, NULL, NULL, NULL, NULL); return ebml_read_num(matroska, &pb, 8, num); }
true
FFmpeg
465c28b6b43be2563e0b644ec22cf641fe374d8d
6,387
static int check(AVIOContext *pb, int64_t pos) { int64_t ret = avio_seek(pb, pos, SEEK_SET); unsigned header; MPADecodeHeader sd; if (ret < 0) return ret; header = avio_rb32(pb); if (ff_mpa_check_header(header) < 0) return -1; if (avpriv_mpegaudio_decode_header(&sd, header) == 1) return -1; return sd.frame_size; }
false
FFmpeg
de1b1a7da9e6ddf42447271e519099a88b389e4a
6,388
static void slavio_timer_get_out(SLAVIO_TIMERState *s) { uint64_t count; count = s->limit - PERIODS_TO_LIMIT(ptimer_get_count(s->timer)); DPRINTF("get_out: limit %" PRIx64 " count %x%08x\n", s->limit, s->counthigh, s->count); s->count = count & TIMER_COUNT_MASK32; s->counthigh = count >> 32; }
false
qemu
bd7e2875fe99ca9621c02666e11389602b512f4b
6,389
void acpi_pm1_cnt_reset(ACPIREGS *ar) { ar->pm1.cnt.cnt = 0; if (ar->pm1.cnt.cmos_s3) { qemu_irq_lower(ar->pm1.cnt.cmos_s3); } }
false
qemu
da98c8eb4c35225049cad8cf767647eb39788b5d
6,390
static uint16_t pci_req_id_cache_extract(PCIReqIDCache *cache) { uint8_t bus_n; uint16_t result; switch (cache->type) { case PCI_REQ_ID_BDF: result = pci_get_bdf(cache->dev); break; case PCI_REQ_ID_SECONDARY_BUS: bus_n = pci_bus_num(cache->dev->bus); result = PCI_BUILD_BDF(bus_n, 0); break; default: error_printf("Invalid PCI requester ID cache type: %d\n", cache->type); exit(1); break; } return result; }
false
qemu
fd56e0612b6454a282fa6a953fdb09281a98c589
6,391
int qio_channel_readv_all(QIOChannel *ioc, const struct iovec *iov, size_t niov, Error **errp) { int ret = -1; struct iovec *local_iov = g_new(struct iovec, niov); struct iovec *local_iov_head = local_iov; unsigned int nlocal_iov = niov; nlocal_iov = iov_copy(local_iov, nlocal_iov, iov, niov, 0, iov_size(iov, niov)); while (nlocal_iov > 0) { ssize_t len; len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp); if (len == QIO_CHANNEL_ERR_BLOCK) { qio_channel_wait(ioc, G_IO_IN); continue; } else if (len < 0) { goto cleanup; } else if (len == 0) { error_setg(errp, "Unexpected end-of-file before all bytes were read"); goto cleanup; } iov_discard_front(&local_iov, &nlocal_iov, len); } ret = 0; cleanup: g_free(local_iov_head); return ret; }
false
qemu
9ffb8270205a274a18ee4f8a735e2fccaf957246
6,392
static void ioreq_unmap(struct ioreq *ioreq) { int gnt = ioreq->blkdev->xendev.gnttabdev; int i; if (ioreq->v.niov == 0) { return; } if (batch_maps) { if (!ioreq->pages) { return; } if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0) { xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n", strerror(errno)); } ioreq->blkdev->cnt_map -= ioreq->v.niov; ioreq->pages = NULL; } else { for (i = 0; i < ioreq->v.niov; i++) { if (!ioreq->page[i]) { continue; } if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) { xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n", strerror(errno)); } ioreq->blkdev->cnt_map--; ioreq->page[i] = NULL; } } }
false
qemu
d5b93ddfefe63d5869a8eb97ea3474867d3b105b
6,393
static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory, target_phys_addr_t base, qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup, omap_clk clk) { struct omap_mpuio_s *s = (struct omap_mpuio_s *) g_malloc0(sizeof(struct omap_mpuio_s)); s->irq = gpio_int; s->kbd_irq = kbd_int; s->wakeup = wakeup; s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16); omap_mpuio_reset(s); memory_region_init_io(&s->iomem, &omap_mpuio_ops, s, "omap-mpuio", 0x800); memory_region_add_subregion(memory, base, &s->iomem); omap_clk_adduser(clk, qemu_allocate_irqs(omap_mpuio_onoff, s, 1)[0]); return s; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
6,394
static target_ulong h_read(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUPPCState *env = &cpu->env; target_ulong flags = args[0]; target_ulong ptex = args[1]; uint8_t *hpte; int i, ridx, n_entries = 1; if (!valid_ptex(cpu, ptex)) { return H_PARAMETER; } if (flags & H_READ_4) { /* Clear the two low order bits */ ptex &= ~(3ULL); n_entries = 4; } hpte = env->external_htab + (ptex * HASH_PTE_SIZE_64); for (i = 0, ridx = 0; i < n_entries; i++) { args[ridx++] = ldq_p(hpte); args[ridx++] = ldq_p(hpte + (HASH_PTE_SIZE_64/2)); hpte += HASH_PTE_SIZE_64; } return H_SUCCESS; }
false
qemu
e57ca75ce3b2bd33102573a8c0555d62e1bcfceb
6,395
static void dec_pattern(DisasContext *dc) { unsigned int mode; int l1; if ((dc->tb_flags & MSR_EE_FLAG) && !(dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) && !((dc->env->pvr.regs[2] & PVR2_USE_PCMP_INSTR))) { tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); t_gen_raise_exception(dc, EXCP_HW_EXCP); } mode = dc->opcode & 3; switch (mode) { case 0: /* pcmpbf. */ LOG_DIS("pcmpbf r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); if (dc->rd) gen_helper_pcmpbf(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); break; case 2: LOG_DIS("pcmpeq r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); if (dc->rd) { TCGv t0 = tcg_temp_local_new(); l1 = gen_new_label(); tcg_gen_movi_tl(t0, 1); tcg_gen_brcond_tl(TCG_COND_EQ, cpu_R[dc->ra], cpu_R[dc->rb], l1); tcg_gen_movi_tl(t0, 0); gen_set_label(l1); tcg_gen_mov_tl(cpu_R[dc->rd], t0); tcg_temp_free(t0); } break; case 3: LOG_DIS("pcmpne r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); l1 = gen_new_label(); if (dc->rd) { TCGv t0 = tcg_temp_local_new(); tcg_gen_movi_tl(t0, 1); tcg_gen_brcond_tl(TCG_COND_NE, cpu_R[dc->ra], cpu_R[dc->rb], l1); tcg_gen_movi_tl(t0, 0); gen_set_label(l1); tcg_gen_mov_tl(cpu_R[dc->rd], t0); tcg_temp_free(t0); } break; default: cpu_abort(dc->env, "unsupported pattern insn opcode=%x\n", dc->opcode); break; } }
false
qemu
97f90cbfe810bb153fc44bde732d9639610783bb
6,396
static MemoryRegionSection phys_page_find(target_phys_addr_t index) { uint16_t *p = phys_page_find_alloc(index, 0); uint16_t s_index = phys_section_unassigned; MemoryRegionSection section; target_phys_addr_t delta; if (p) { s_index = *p; } section = phys_sections[s_index]; index <<= TARGET_PAGE_BITS; assert(section.offset_within_address_space <= index && index <= section.offset_within_address_space + section.size-1); delta = index - section.offset_within_address_space; section.offset_within_address_space += delta; section.offset_within_region += delta; section.size -= delta; return section; }
false
qemu
31ab2b4a46eb9761feae9457387eb5ee523f5afd
6,397
static void qmp_output_end_struct(Visitor *v, Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_pop(qov); }
false
qemu
56a6f02b8ce1fe41a2a9077593e46eca7d98267d
6,398
static av_cold int MP3lame_encode_init(AVCodecContext *avctx) { Mp3AudioContext *s = avctx->priv_data; if (avctx->channels > 2) return -1; s->stereo = avctx->channels > 1 ? 1 : 0; if ((s->gfp = lame_init()) == NULL) goto err; lame_set_in_samplerate(s->gfp, avctx->sample_rate); lame_set_out_samplerate(s->gfp, avctx->sample_rate); lame_set_num_channels(s->gfp, avctx->channels); if(avctx->compression_level == FF_COMPRESSION_DEFAULT) { lame_set_quality(s->gfp, 5); } else { lame_set_quality(s->gfp, avctx->compression_level); } lame_set_mode(s->gfp, s->stereo ? JOINT_STEREO : MONO); lame_set_brate(s->gfp, avctx->bit_rate/1000); if(avctx->flags & CODEC_FLAG_QSCALE) { lame_set_brate(s->gfp, 0); lame_set_VBR(s->gfp, vbr_default); lame_set_VBR_quality(s->gfp, avctx->global_quality/(float)FF_QP2LAMBDA); } lame_set_bWriteVbrTag(s->gfp,0); #if FF_API_LAME_GLOBAL_OPTS s->reservoir = avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR; #endif lame_set_disable_reservoir(s->gfp, !s->reservoir); if (lame_init_params(s->gfp) < 0) goto err_close; avctx->frame_size = lame_get_framesize(s->gfp); if(!(avctx->coded_frame= avcodec_alloc_frame())) { lame_close(s->gfp); return AVERROR(ENOMEM); } avctx->coded_frame->key_frame= 1; if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) { int nelem = 2 * avctx->frame_size; if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) { av_freep(&avctx->coded_frame); lame_close(s->gfp); return AVERROR(ENOMEM); } s->s32_data.right = s->s32_data.left + avctx->frame_size; } return 0; err_close: lame_close(s->gfp); err: return -1; }
false
FFmpeg
5b1a06b1c9c596b3c406ea632a252dcccbee25ed
6,399
static void string_cleanup(void *datap) { StringSerializeData *d = datap; visit_free(string_output_get_visitor(d->sov)); visit_free(d->siv); g_free(d->string); g_free(d); }
false
qemu
3b098d56979d2f7fd707c5be85555d114353a28d
6,400
static int n8x0_atag_setup(void *p, int model) { uint8_t *b; uint16_t *w; uint32_t *l; struct omap_gpiosw_info_s *gpiosw; struct omap_partition_info_s *partition; const char *tag; w = p; stw_p(w++, OMAP_TAG_UART); /* u16 tag */ stw_p(w++, 4); /* u16 len */ stw_p(w++, (1 << 2) | (1 << 1) | (1 << 0)); /* uint enabled_uarts */ w++; #if 0 stw_p(w++, OMAP_TAG_SERIAL_CONSOLE); /* u16 tag */ stw_p(w++, 4); /* u16 len */ stw_p(w++, XLDR_LL_UART + 1); /* u8 console_uart */ stw_p(w++, 115200); /* u32 console_speed */ #endif stw_p(w++, OMAP_TAG_LCD); /* u16 tag */ stw_p(w++, 36); /* u16 len */ strcpy((void *) w, "QEMU LCD panel"); /* char panel_name[16] */ w += 8; strcpy((void *) w, "blizzard"); /* char ctrl_name[16] */ w += 8; stw_p(w++, N810_BLIZZARD_RESET_GPIO); /* TODO: n800 s16 nreset_gpio */ stw_p(w++, 24); /* u8 data_lines */ stw_p(w++, OMAP_TAG_CBUS); /* u16 tag */ stw_p(w++, 8); /* u16 len */ stw_p(w++, N8X0_CBUS_CLK_GPIO); /* s16 clk_gpio */ stw_p(w++, N8X0_CBUS_DAT_GPIO); /* s16 dat_gpio */ stw_p(w++, N8X0_CBUS_SEL_GPIO); /* s16 sel_gpio */ w++; stw_p(w++, OMAP_TAG_EM_ASIC_BB5); /* u16 tag */ stw_p(w++, 4); /* u16 len */ stw_p(w++, N8X0_RETU_GPIO); /* s16 retu_irq_gpio */ stw_p(w++, N8X0_TAHVO_GPIO); /* s16 tahvo_irq_gpio */ gpiosw = (model == 810) ? n810_gpiosw_info : n800_gpiosw_info; for (; gpiosw->name; gpiosw++) { stw_p(w++, OMAP_TAG_GPIO_SWITCH); /* u16 tag */ stw_p(w++, 20); /* u16 len */ strcpy((void *) w, gpiosw->name); /* char name[12] */ w += 6; stw_p(w++, gpiosw->line); /* u16 gpio */ stw_p(w++, gpiosw->type); stw_p(w++, 0); stw_p(w++, 0); } stw_p(w++, OMAP_TAG_NOKIA_BT); /* u16 tag */ stw_p(w++, 12); /* u16 len */ b = (void *) w; stb_p(b++, 0x01); /* u8 chip_type (CSR) */ stb_p(b++, N8X0_BT_WKUP_GPIO); /* u8 bt_wakeup_gpio */ stb_p(b++, N8X0_BT_HOST_WKUP_GPIO); /* u8 host_wakeup_gpio */ stb_p(b++, N8X0_BT_RESET_GPIO); /* u8 reset_gpio */ stb_p(b++, BT_UART + 1); /* u8 bt_uart */ memcpy(b, &n8x0_bd_addr, 6); /* u8 bd_addr[6] */ b += 6; stb_p(b++, 0x02); /* u8 bt_sysclk (38.4) */ w = (void *) b; stw_p(w++, OMAP_TAG_WLAN_CX3110X); /* u16 tag */ stw_p(w++, 8); /* u16 len */ stw_p(w++, 0x25); /* u8 chip_type */ stw_p(w++, N8X0_WLAN_PWR_GPIO); /* s16 power_gpio */ stw_p(w++, N8X0_WLAN_IRQ_GPIO); /* s16 irq_gpio */ stw_p(w++, -1); /* s16 spi_cs_gpio */ stw_p(w++, OMAP_TAG_MMC); /* u16 tag */ stw_p(w++, 16); /* u16 len */ if (model == 810) { stw_p(w++, 0x23f); /* unsigned flags */ stw_p(w++, -1); /* s16 power_pin */ stw_p(w++, -1); /* s16 switch_pin */ stw_p(w++, -1); /* s16 wp_pin */ stw_p(w++, 0x240); /* unsigned flags */ stw_p(w++, 0xc000); /* s16 power_pin */ stw_p(w++, 0x0248); /* s16 switch_pin */ stw_p(w++, 0xc000); /* s16 wp_pin */ } else { stw_p(w++, 0xf); /* unsigned flags */ stw_p(w++, -1); /* s16 power_pin */ stw_p(w++, -1); /* s16 switch_pin */ stw_p(w++, -1); /* s16 wp_pin */ stw_p(w++, 0); /* unsigned flags */ stw_p(w++, 0); /* s16 power_pin */ stw_p(w++, 0); /* s16 switch_pin */ stw_p(w++, 0); /* s16 wp_pin */ } stw_p(w++, OMAP_TAG_TEA5761); /* u16 tag */ stw_p(w++, 4); /* u16 len */ stw_p(w++, N8X0_TEA5761_CS_GPIO); /* u16 enable_gpio */ w++; partition = (model == 810) ? n810_part_info : n800_part_info; for (; partition->name; partition++) { stw_p(w++, OMAP_TAG_PARTITION); /* u16 tag */ stw_p(w++, 28); /* u16 len */ strcpy((void *) w, partition->name); /* char name[16] */ l = (void *) (w + 8); stl_p(l++, partition->size); /* unsigned int size */ stl_p(l++, partition->offset); /* unsigned int offset */ stl_p(l++, partition->mask); /* unsigned int mask_flags */ w = (void *) l; } stw_p(w++, OMAP_TAG_BOOT_REASON); /* u16 tag */ stw_p(w++, 12); /* u16 len */ #if 0 strcpy((void *) w, "por"); /* char reason_str[12] */ strcpy((void *) w, "charger"); /* char reason_str[12] */ strcpy((void *) w, "32wd_to"); /* char reason_str[12] */ strcpy((void *) w, "sw_rst"); /* char reason_str[12] */ strcpy((void *) w, "mbus"); /* char reason_str[12] */ strcpy((void *) w, "unknown"); /* char reason_str[12] */ strcpy((void *) w, "swdg_to"); /* char reason_str[12] */ strcpy((void *) w, "sec_vio"); /* char reason_str[12] */ strcpy((void *) w, "pwr_key"); /* char reason_str[12] */ strcpy((void *) w, "rtc_alarm"); /* char reason_str[12] */ #else strcpy((void *) w, "pwr_key"); /* char reason_str[12] */ #endif w += 6; tag = (model == 810) ? "RX-44" : "RX-34"; stw_p(w++, OMAP_TAG_VERSION_STR); /* u16 tag */ stw_p(w++, 24); /* u16 len */ strcpy((void *) w, "product"); /* char component[12] */ w += 6; strcpy((void *) w, tag); /* char version[12] */ w += 6; stw_p(w++, OMAP_TAG_VERSION_STR); /* u16 tag */ stw_p(w++, 24); /* u16 len */ strcpy((void *) w, "hw-build"); /* char component[12] */ w += 6; strcpy((void *) w, "QEMU "); pstrcat((void *) w, 12, qemu_get_version()); /* char version[12] */ w += 6; tag = (model == 810) ? "1.1.10-qemu" : "1.1.6-qemu"; stw_p(w++, OMAP_TAG_VERSION_STR); /* u16 tag */ stw_p(w++, 24); /* u16 len */ strcpy((void *) w, "nolo"); /* char component[12] */ w += 6; strcpy((void *) w, tag); /* char version[12] */ w += 6; return (void *) w - p; }
false
qemu
35c2c8dc8c0899882a8e0d349d93bd657772f1e7
6,402
vdi_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BDRVVdiState *s = bs->opaque; QEMUIOVector local_qiov; uint32_t bmap_entry; uint32_t block_index; uint32_t offset_in_block; uint32_t n_bytes; uint64_t bytes_done = 0; int ret = 0; logout("\n"); qemu_iovec_init(&local_qiov, qiov->niov); while (ret >= 0 && bytes > 0) { block_index = offset / s->block_size; offset_in_block = offset % s->block_size; n_bytes = MIN(bytes, s->block_size - offset_in_block); logout("will read %u bytes starting at offset %" PRIu64 "\n", n_bytes, offset); /* prepare next AIO request */ bmap_entry = le32_to_cpu(s->bmap[block_index]); if (!VDI_IS_ALLOCATED(bmap_entry)) { /* Block not allocated, return zeros, no need to wait. */ qemu_iovec_memset(qiov, bytes_done, 0, n_bytes); ret = 0; } else { uint64_t data_offset = s->header.offset_data + (uint64_t)bmap_entry * s->block_size + offset_in_block; qemu_iovec_reset(&local_qiov); qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes); ret = bdrv_co_preadv(bs->file->bs, data_offset, n_bytes, &local_qiov, 0); } logout("%u bytes read\n", n_bytes); bytes -= n_bytes; offset += n_bytes; bytes_done += n_bytes; } qemu_iovec_destroy(&local_qiov); return ret; }
false
qemu
a03ef88f77af045a2eb9629b5ce774a3fb973c5e
6,403
static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); MachineClass *mc = MACHINE_GET_CLASS(spapr); sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc); sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc = CPU_CORE(dev); CPUState *cs = CPU(core->threads); sPAPRDRConnector *drc; Error *local_err = NULL; void *fdt = NULL; int fdt_offset = 0; int smt = kvmppc_smt_threads(); CPUArchId *core_slot; int index; core_slot = spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index); if (!core_slot) { error_setg(errp, "Unable to find CPU core with core-id: %d", cc->core_id); return; } drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index * smt); g_assert(drc || !mc->has_hotpluggable_cpus); /* * Setup CPU DT entries only for hotplugged CPUs. For boot time or * coldplugged CPUs DT entries are setup in spapr_build_fdt(). */ if (dev->hotplugged) { fdt = spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr); } if (drc) { spapr_drc_attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err); if (local_err) { g_free(fdt); error_propagate(errp, local_err); return; } } if (dev->hotplugged) { /* * Send hotplug notification interrupt to the guest only in case * of hotplugged CPUs. */ spapr_hotplug_req_add_by_index(drc); } else { /* * Set the right DRC states for cold plugged CPU. */ if (drc) { sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE); drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOLATED); } } core_slot->cpu = OBJECT(dev); if (smc->pre_2_10_has_unused_icps) { sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(OBJECT(cc)); const char *typename = object_class_get_name(scc->cpu_class); size_t size = object_type_get_instance_size(typename); int i; for (i = 0; i < cc->nr_threads; i++) { sPAPRCPUCore *sc = SPAPR_CPU_CORE(dev); void *obj = sc->threads + i * size; cs = CPU(obj); pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); } } }
false
qemu
4f9242fc931ab5e5b1b753c8e5a76c50c0b0612e
6,405
static void bt_dummy_lmp_acl_resp(struct bt_link_s *link, const uint8_t *data, int start, int len) { fprintf(stderr, "%s: stray ACL response PDU, fixme\n", __FUNCTION__); exit(-1); }
false
qemu
a89f364ae8740dfc31b321eed9ee454e996dc3c1
6,406
static bool msix_vector_masked(PCIDevice *dev, int vector, bool fmask) { unsigned offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL; return fmask || dev->msix_table[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT; }
false
qemu
70f8ee395afda6d96b15cb9a5b311af7720dded0
6,407
static void virtio_blk_dma_restart_bh(void *opaque) { VirtIOBlock *s = opaque; VirtIOBlockReq *req = s->rq; MultiReqBuffer mrb = { .num_writes = 0, }; qemu_bh_delete(s->bh); s->bh = NULL; s->rq = NULL; while (req) { virtio_blk_handle_request(req, &mrb); req = req->next; } if (mrb.num_writes > 0) { do_multiwrite(s->bs, mrb.blkreq, mrb.num_writes); } }
false
qemu
c20fd872257fb9abd2ce99741937c0f65aa162b7
6,410
iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque) { IscsiLun *iscsilun = bs->opaque; struct iscsi_context *iscsi = iscsilun->iscsi; IscsiAIOCB *acb; size_t qemu_read_size; int i; uint64_t lba; uint32_t num_sectors; qemu_read_size = BDRV_SECTOR_SIZE * (size_t)nb_sectors; acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque); trace_iscsi_aio_readv(iscsi, sector_num, nb_sectors, opaque, acb); acb->iscsilun = iscsilun; acb->qiov = qiov; acb->canceled = 0; acb->bh = NULL; acb->status = -EINPROGRESS; acb->read_size = qemu_read_size; acb->buf = NULL; /* If LUN blocksize is bigger than BDRV_BLOCK_SIZE a read from QEMU * may be misaligned to the LUN, so we may need to read some extra * data. */ acb->read_offset = 0; if (iscsilun->block_size > BDRV_SECTOR_SIZE) { uint64_t bdrv_offset = BDRV_SECTOR_SIZE * sector_num; acb->read_offset = bdrv_offset % iscsilun->block_size; } num_sectors = (qemu_read_size + iscsilun->block_size + acb->read_offset - 1) / iscsilun->block_size; acb->task = malloc(sizeof(struct scsi_task)); if (acb->task == NULL) { error_report("iSCSI: Failed to allocate task for scsi READ16 " "command. %s", iscsi_get_error(iscsi)); qemu_aio_release(acb); return NULL; } memset(acb->task, 0, sizeof(struct scsi_task)); acb->task->xfer_dir = SCSI_XFER_READ; lba = sector_qemu2lun(sector_num, iscsilun); acb->task->expxferlen = qemu_read_size; switch (iscsilun->type) { case TYPE_DISK: acb->task->cdb_size = 16; acb->task->cdb[0] = 0x88; *(uint32_t *)&acb->task->cdb[2] = htonl(lba >> 32); *(uint32_t *)&acb->task->cdb[6] = htonl(lba & 0xffffffff); *(uint32_t *)&acb->task->cdb[10] = htonl(num_sectors); break; default: acb->task->cdb_size = 10; acb->task->cdb[0] = 0x28; *(uint32_t *)&acb->task->cdb[2] = htonl(lba); *(uint16_t *)&acb->task->cdb[7] = htons(num_sectors); break; } if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, iscsi_aio_read16_cb, NULL, acb) != 0) { scsi_free_scsi_task(acb->task); qemu_aio_release(acb); return NULL; } for (i = 0; i < acb->qiov->niov; i++) { scsi_task_add_data_in_buffer(acb->task, acb->qiov->iov[i].iov_len, acb->qiov->iov[i].iov_base); } iscsi_set_events(iscsilun); return &acb->common; }
true
qemu
e829b0bb054ed3389e5b22dad61875e51674e629
6,411
static void vmsvga_reset(struct vmsvga_state_s *s) { s->index = 0; s->enable = 0; s->config = 0; s->width = -1; s->height = -1; s->svgaid = SVGA_ID; s->depth = 24; s->bypp = (s->depth + 7) >> 3; s->cursor.on = 0; s->redraw_fifo_first = 0; s->redraw_fifo_last = 0; switch (s->depth) { case 8: s->wred = 0x00000007; s->wgreen = 0x00000038; s->wblue = 0x000000c0; break; case 15: s->wred = 0x0000001f; s->wgreen = 0x000003e0; s->wblue = 0x00007c00; break; case 16: s->wred = 0x0000001f; s->wgreen = 0x000007e0; s->wblue = 0x0000f800; break; case 24: s->wred = 0x00ff0000; s->wgreen = 0x0000ff00; s->wblue = 0x000000ff; break; case 32: s->wred = 0x00ff0000; s->wgreen = 0x0000ff00; s->wblue = 0x000000ff; break; } s->syncing = 0; }
true
qemu
a6109ff1b5d7184a9d490c4ff94f175940232ebd
6,412
static MpegTSService *mpegts_add_service(MpegTSWrite *ts, int sid, const char *provider_name, const char *name) { MpegTSService *service; service = av_mallocz(sizeof(MpegTSService)); if (!service) return NULL; service->pmt.pid = ts->pmt_start_pid + ts->nb_services; service->sid = sid; service->provider_name = av_strdup(provider_name); service->name = av_strdup(name); service->pcr_pid = 0x1fff; dynarray_add(&ts->services, &ts->nb_services, service); return service; }
true
FFmpeg
5b220e1e19c17b202d83d9be0868d152109ae8f0
6,413
static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf, int buf_size) { int frequency[512] = { 0 }; uint8_t flag[512]; int up[512]; uint8_t len_tab[257]; int bits_tab[257]; int start, end; const uint8_t *ptr = buf; const uint8_t *ptr_end = buf + buf_size; int j; memset(up, -1, sizeof(up)); start = *ptr++; end = *ptr++; for (;;) { int i; if (start <= end && ptr_end - ptr < end - start + 1 + 1) return NULL; for (i = start; i <= end; i++) frequency[i] = *ptr++; start = *ptr++; if (start == 0) break; end = *ptr++; } frequency[256] = 1; while ((ptr - buf) & 3) ptr++; // 4byte align for (j = 257; j < 512; j++) { int min_freq[2] = { 256 * 256, 256 * 256 }; int smallest[2] = { 0, 0 }; int i; for (i = 0; i < j; i++) { if (frequency[i] == 0) continue; if (frequency[i] < min_freq[1]) { if (frequency[i] < min_freq[0]) { min_freq[1] = min_freq[0]; smallest[1] = smallest[0]; min_freq[0] = frequency[i]; smallest[0] = i; } else { min_freq[1] = frequency[i]; smallest[1] = i; } } } if (min_freq[1] == 256 * 256) break; frequency[j] = min_freq[0] + min_freq[1]; flag[smallest[0]] = 0; flag[smallest[1]] = 1; up[smallest[0]] = up[smallest[1]] = j; frequency[smallest[0]] = frequency[smallest[1]] = 0; } for (j = 0; j < 257; j++) { int node, len = 0, bits = 0; for (node = j; up[node] != -1; node = up[node]) { bits += flag[node] << len; len++; if (len > 31) // can this happen at all ? av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); } bits_tab[j] = bits; len_tab[j] = len; } if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1, bits_tab, 4, 4, 0)) return NULL; return ptr; }
true
FFmpeg
53a3fdbfc56da54b2c0a44eb1f956ec9d67d1425
6,414
static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_len, int buf_len) { const uint8_t *buf = start + 1; int start_trim_flag, end_trim_flag, control_extension_flag, control_extension_length; uint8_t flags; GetByteContext gb; bytestream2_init(&gb, buf, buf_len); flags = bytestream2_get_byte(&gb); start_trim_flag = (flags >> 4) & 1; end_trim_flag = (flags >> 3) & 1; control_extension_flag = (flags >> 2) & 1; *payload_len = 0; while (bytestream2_peek_byte(&gb) == 0xff) *payload_len += bytestream2_get_byte(&gb); *payload_len += bytestream2_get_byte(&gb); if (start_trim_flag) bytestream2_skip(&gb, 2); if (end_trim_flag) bytestream2_skip(&gb, 2); if (control_extension_flag) { control_extension_length = bytestream2_get_byte(&gb); bytestream2_skip(&gb, control_extension_length); } return buf + bytestream2_tell(&gb); }
true
FFmpeg
1bcd7fefcb3c1ec47978fdc64a9e8dfb9512ae62
6,415
void qemu_cpu_kick(void *env) { }
true
qemu
12d4536f7d911b6d87a766ad7300482ea663cea2
6,416
int qemu_file_rate_limit(QEMUFile *f) { if (qemu_file_get_error(f)) { return 1; } if (f->xfer_limit > 0 && f->bytes_xfer > f->xfer_limit) { return 1; } return 0; }
true
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
6,417
GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp) { if (!error_is_set(errp)) { return v->next_list(v, list, errp); } return 0; }
true
qemu
297a3646c2947ee64a6d42ca264039732c6218e0
6,418
static int handle_ping(URLContext *s, RTMPPacket *pkt) { RTMPContext *rt = s->priv_data; int t, ret; if (pkt->data_size < 2) { av_log(s, AV_LOG_ERROR, "Too short ping packet (%d)\n", pkt->data_size); return AVERROR_INVALIDDATA; t = AV_RB16(pkt->data); if (t == 6) { if ((ret = gen_pong(s, rt, pkt)) < 0) return 0;
true
FFmpeg
635ac8e1be91e941908f85642e4bbb609e48193f
6,419
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; AVFilterBufferRef *outpicref = outlink->out_buf; OverlayContext *over = ctx->priv; if (over->overpicref && !(over->x >= outpicref->video->w || over->y >= outpicref->video->h || y+h < over->y || y >= over->y + over->overpicref->video->h)) { blend_slice(ctx, outpicref, over->overpicref, over->x, over->y, over->overpicref->video->w, over->overpicref->video->h, y, outpicref->video->w, h); } avfilter_draw_slice(outlink, y, h, slice_dir); }
true
FFmpeg
06bf6d3bc04979bd39ecdc7311d0daf8aee7e10f
6,420
static void handle_sys(DisasContext *s, uint32_t insn, bool isread, unsigned int op0, unsigned int op1, unsigned int op2, unsigned int crn, unsigned int crm, unsigned int rt) { const ARMCPRegInfo *ri; TCGv_i64 tcg_rt; ri = get_arm_cp_reginfo(s->cp_regs, ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)); if (!ri) { /* Unknown register; this might be a guest error or a QEMU * unimplemented feature. qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 " "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n", isread ? "read" : "write", op0, op1, crn, crm, op2); unallocated_encoding(s); return; /* Check access permissions */ if (!cp_access_ok(s->current_pl, ri, isread)) { unallocated_encoding(s); return; /* Handle special cases first */ switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) { case ARM_CP_NOP: return; case ARM_CP_NZCV: tcg_rt = cpu_reg(s, rt); if (isread) { gen_get_nzcv(tcg_rt); } else { gen_set_nzcv(tcg_rt); return; default: break; if (use_icount && (ri->type & ARM_CP_IO)) { gen_io_start(); tcg_rt = cpu_reg(s, rt); if (isread) { if (ri->type & ARM_CP_CONST) { tcg_gen_movi_i64(tcg_rt, ri->resetvalue); } else if (ri->readfn) { gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr); } else { tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset); } else { if (ri->type & ARM_CP_CONST) { /* If not forbidden by access permissions, treat as WI */ return; } else if (ri->writefn) { gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt); } else { tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset); if (use_icount && (ri->type & ARM_CP_IO)) { /* I/O operations must end the TB here (whether read or write) */ gen_io_end(); s->is_jmp = DISAS_UPDATE; } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { /* We default to ending the TB on a coprocessor register write, * but allow this to be suppressed by the register definition * (usually only necessary to work around guest bugs). s->is_jmp = DISAS_UPDATE;
true
qemu
f59df3f2354982ee0381b87d1ce561f1eb0ed505
6,421
static void gic_cpu_write(gic_state *s, int cpu, int offset, uint32_t value) { switch (offset) { case 0x00: /* Control */ s->cpu_enabled[cpu] = (value & 1); DPRINTF("CPU %d %sabled\n", cpu, s->cpu_enabled ? "En" : "Dis"); break; case 0x04: /* Priority mask */ s->priority_mask[cpu] = (value & 0xff); break; case 0x08: /* Binary Point */ /* ??? Not implemented. */ break; case 0x10: /* End Of Interrupt */ return gic_complete_irq(s, cpu, value & 0x3ff); default: hw_error("gic_cpu_write: Bad offset %x\n", (int)offset); return; } gic_update(s); }
true
qemu
9ab1b6053f03d58ba8e7accc8f19c882fbffb66f
6,422
int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height) { AVPicture dummy_pict; if(av_image_check_size(width, height, 0, NULL)) return -1; switch (pix_fmt) { case PIX_FMT_RGB8: case PIX_FMT_BGR8: case PIX_FMT_RGB4_BYTE: case PIX_FMT_BGR4_BYTE: case PIX_FMT_GRAY8: // do not include palette for these pseudo-paletted formats return width * height; } return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height); }
true
FFmpeg
38d553322891c8e47182f05199d19888422167dc
6,423
static void qemu_rdma_cleanup(RDMAContext *rdma) { struct rdma_cm_event *cm_event; int ret, idx; if (rdma->cm_id && rdma->connected) { if (rdma->error_state) { RDMAControlHeader head = { .len = 0, .type = RDMA_CONTROL_ERROR, .repeat = 1, }; error_report("Early error. Sending error."); qemu_rdma_post_send_control(rdma, NULL, &head); } ret = rdma_disconnect(rdma->cm_id); if (!ret) { trace_qemu_rdma_cleanup_waiting_for_disconnect(); ret = rdma_get_cm_event(rdma->channel, &cm_event); if (!ret) { rdma_ack_cm_event(cm_event); } } trace_qemu_rdma_cleanup_disconnect(); rdma->connected = false; } g_free(rdma->block); rdma->block = NULL; for (idx = 0; idx < RDMA_WRID_MAX; idx++) { if (rdma->wr_data[idx].control_mr) { rdma->total_registrations--; ibv_dereg_mr(rdma->wr_data[idx].control_mr); } rdma->wr_data[idx].control_mr = NULL; } if (rdma->local_ram_blocks.block) { while (rdma->local_ram_blocks.nb_blocks) { rdma_delete_block(rdma, rdma->local_ram_blocks.block->offset); } } if (rdma->cq) { ibv_destroy_cq(rdma->cq); rdma->cq = NULL; } if (rdma->comp_channel) { ibv_destroy_comp_channel(rdma->comp_channel); rdma->comp_channel = NULL; } if (rdma->pd) { ibv_dealloc_pd(rdma->pd); rdma->pd = NULL; } if (rdma->listen_id) { rdma_destroy_id(rdma->listen_id); rdma->listen_id = NULL; } if (rdma->cm_id) { if (rdma->qp) { rdma_destroy_qp(rdma->cm_id); rdma->qp = NULL; } rdma_destroy_id(rdma->cm_id); rdma->cm_id = NULL; } if (rdma->channel) { rdma_destroy_event_channel(rdma->channel); rdma->channel = NULL; } g_free(rdma->host); rdma->host = NULL; }
true
qemu
80b262e1439a22708e1c535b75363d4b90c3b41d
6,424
static void write_picture(AVFormatContext *s, int index, AVPicture *picture, int pix_fmt, int w, int h) { UINT8 *buf, *src, *dest; int size, j, i; size = avpicture_get_size(pix_fmt, w, h); buf = malloc(size); if (!buf) return; /* XXX: not efficient, should add test if we can take directly the AVPicture */ switch(pix_fmt) { case PIX_FMT_YUV420P: dest = buf; for(i=0;i<3;i++) { if (i == 1) { w >>= 1; h >>= 1; } src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV422P: size = (w * h) * 2; buf = malloc(size); dest = buf; for(i=0;i<3;i++) { if (i == 1) { w >>= 1; } src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV444P: size = (w * h) * 3; buf = malloc(size); dest = buf; for(i=0;i<3;i++) { src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV422: size = (w * h) * 2; buf = malloc(size); dest = buf; src = picture->data[0]; for(j=0;j<h;j++) { memcpy(dest, src, w * 2); dest += w * 2; src += picture->linesize[0]; } break; case PIX_FMT_RGB24: case PIX_FMT_BGR24: size = (w * h) * 3; buf = malloc(size); dest = buf; src = picture->data[0]; for(j=0;j<h;j++) { memcpy(dest, src, w * 3); dest += w * 3; src += picture->linesize[0]; } break; default: return; } s->format->write_packet(s, index, buf, size); free(buf); }
true
FFmpeg
5b0ad91b996506632708dcefc22d2835d04a4dba
6,426
static int drawgrid_filter_frame(AVFilterLink *inlink, AVFrame *frame) { DrawBoxContext *drawgrid = inlink->dst->priv; int plane, x, y; uint8_t *row[4]; if (drawgrid->have_alpha) { for (y = 0; y < frame->height; y++) { row[0] = frame->data[0] + y * frame->linesize[0]; row[3] = frame->data[3] + y * frame->linesize[3]; for (plane = 1; plane < 3; plane++) row[plane] = frame->data[plane] + frame->linesize[plane] * (y >> drawgrid->vsub); if (drawgrid->invert_color) { for (x = 0; x < frame->width; x++) if (pixel_belongs_to_grid(drawgrid, x, y)) row[0][x] = 0xff - row[0][x]; } else { for (x = 0; x < frame->width; x++) { if (pixel_belongs_to_grid(drawgrid, x, y)) { row[0][x ] = drawgrid->yuv_color[Y]; row[1][x >> drawgrid->hsub] = drawgrid->yuv_color[U]; row[2][x >> drawgrid->hsub] = drawgrid->yuv_color[V]; row[3][x ] = drawgrid->yuv_color[A]; } } } } } else { for (y = 0; y < frame->height; y++) { row[0] = frame->data[0] + y * frame->linesize[0]; for (plane = 1; plane < 3; plane++) row[plane] = frame->data[plane] + frame->linesize[plane] * (y >> drawgrid->vsub); if (drawgrid->invert_color) { for (x = 0; x < frame->width; x++) if (pixel_belongs_to_grid(drawgrid, x, y)) row[0][x] = 0xff - row[0][x]; } else { for (x = 0; x < frame->width; x++) { double alpha = (double)drawgrid->yuv_color[A] / 255; if (pixel_belongs_to_grid(drawgrid, x, y)) { row[0][x ] = (1 - alpha) * row[0][x ] + alpha * drawgrid->yuv_color[Y]; row[1][x >> drawgrid->hsub] = (1 - alpha) * row[1][x >> drawgrid->hsub] + alpha * drawgrid->yuv_color[U]; row[2][x >> drawgrid->hsub] = (1 - alpha) * row[2][x >> drawgrid->hsub] + alpha * drawgrid->yuv_color[V]; } } } } } return ff_filter_frame(inlink->dst->outputs[0], frame); }
true
FFmpeg
1c76134fe37ac20695627e3f5ce1f2bbf1245fcc
6,427
void backup_start(const char *job_id, BlockDriverState *bs, BlockDriverState *target, int64_t speed, MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap, BlockdevOnError on_source_error, BlockdevOnError on_target_error, BlockCompletionFunc *cb, void *opaque, BlockJobTxn *txn, Error **errp) { int64_t len; BlockDriverInfo bdi; BackupBlockJob *job = NULL; int ret; assert(bs); assert(target); if (bs == target) { error_setg(errp, "Source and target cannot be the same"); return; } if (!bdrv_is_inserted(bs)) { error_setg(errp, "Device is not inserted: %s", bdrv_get_device_name(bs)); return; } if (!bdrv_is_inserted(target)) { error_setg(errp, "Device is not inserted: %s", bdrv_get_device_name(target)); return; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { return; } if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) { return; } if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { if (!sync_bitmap) { error_setg(errp, "must provide a valid bitmap name for " "\"incremental\" sync mode"); return; } /* Create a new bitmap, and freeze/disable this one. */ if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) { return; } } else if (sync_bitmap) { error_setg(errp, "a sync_bitmap was provided to backup_run, " "but received an incompatible sync_mode (%s)", MirrorSyncMode_lookup[sync_mode]); return; } len = bdrv_getlength(bs); if (len < 0) { error_setg_errno(errp, -len, "unable to get length for '%s'", bdrv_get_device_name(bs)); goto error; } job = block_job_create(job_id, &backup_job_driver, bs, speed, cb, opaque, errp); if (!job) { goto error; } job->target = blk_new(); blk_insert_bs(job->target, target); job->on_source_error = on_source_error; job->on_target_error = on_target_error; job->sync_mode = sync_mode; job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ? sync_bitmap : NULL; /* If there is no backing file on the target, we cannot rely on COW if our * backup cluster size is smaller than the target cluster size. Even for * targets with a backing file, try to avoid COW if possible. */ ret = bdrv_get_info(target, &bdi); if (ret < 0 && !target->backing) { error_setg_errno(errp, -ret, "Couldn't determine the cluster size of the target image, " "which has no backing file"); error_append_hint(errp, "Aborting, since this may create an unusable destination image\n"); goto error; } else if (ret < 0 && target->backing) { /* Not fatal; just trudge on ahead. */ job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; } else { job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size); } bdrv_op_block_all(target, job->common.blocker); job->common.len = len; job->common.co = qemu_coroutine_create(backup_run); block_job_txn_add_job(txn, &job->common); qemu_coroutine_enter(job->common.co, job); return; error: if (sync_bitmap) { bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL); } if (job) { blk_unref(job->target); block_job_unref(&job->common); } }
true
qemu
0b8b8753e4d94901627b3e86431230f2319215c4
6,428
void OPPROTO op_POWER_srea (void) { T1 &= 0x1FUL; env->spr[SPR_MQ] = T0 >> T1; T0 = Ts0 >> T1; RETURN(); }
true
qemu
d9bce9d99f4656ae0b0127f7472db9067b8f84ab
6,429
void qmp_memchar_write(const char *device, const char *data, bool has_format, enum DataFormat format, Error **errp) { CharDriverState *chr; const uint8_t *write_data; int ret; size_t write_count; chr = qemu_chr_find(device); if (!chr) { error_setg(errp, "Device '%s' not found", device); return; if (qemu_is_chr(chr, "memory")) { error_setg(errp,"%s is not memory char device", device); return; if (has_format && (format == DATA_FORMAT_BASE64)) { write_data = g_base64_decode(data, &write_count); } else { write_data = (uint8_t *)data; write_count = strlen(data); ret = cirmem_chr_write(chr, write_data, write_count); if (ret < 0) { error_setg(errp, "Failed to write to device %s", device); return;
true
qemu
13289fb5a716e06fb06febb880e5e116d485f82b
6,430
static void avc_biwgt_16width_msa(uint8_t *src, int32_t src_stride, uint8_t *dst, int32_t dst_stride, int32_t height, int32_t log2_denom, int32_t src_weight, int32_t dst_weight, int32_t offset_in) { uint8_t cnt; v16i8 src_wgt, dst_wgt, wgt; v16i8 src0, src1, src2, src3; v16i8 dst0, dst1, dst2, dst3; v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; v8i16 temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; v8i16 denom, offset, add_val; int32_t val = 128 * (src_weight + dst_weight); offset_in = ((offset_in + 1) | 1) << log2_denom; src_wgt = __msa_fill_b(src_weight); dst_wgt = __msa_fill_b(dst_weight); offset = __msa_fill_h(offset_in); denom = __msa_fill_h(log2_denom + 1); add_val = __msa_fill_h(val); offset += add_val; wgt = __msa_ilvev_b(dst_wgt, src_wgt); for (cnt = height / 4; cnt--;) { LOAD_4VECS_SB(src, src_stride, src0, src1, src2, src3); src += (4 * src_stride); LOAD_4VECS_SB(dst, dst_stride, dst0, dst1, dst2, dst3); XORI_B_4VECS_SB(src0, src1, src2, src3, src0, src1, src2, src3, 128); XORI_B_4VECS_SB(dst0, dst1, dst2, dst3, dst0, dst1, dst2, dst3, 128); ILV_B_LRLR_SB(src0, dst0, src1, dst1, vec1, vec0, vec3, vec2); ILV_B_LRLR_SB(src2, dst2, src3, dst3, vec5, vec4, vec7, vec6); temp0 = __msa_dpadd_s_h(offset, wgt, vec0); temp1 = __msa_dpadd_s_h(offset, wgt, vec1); temp2 = __msa_dpadd_s_h(offset, wgt, vec2); temp3 = __msa_dpadd_s_h(offset, wgt, vec3); temp4 = __msa_dpadd_s_h(offset, wgt, vec4); temp5 = __msa_dpadd_s_h(offset, wgt, vec5); temp6 = __msa_dpadd_s_h(offset, wgt, vec6); temp7 = __msa_dpadd_s_h(offset, wgt, vec7); SRA_4VECS(temp0, temp1, temp2, temp3, temp0, temp1, temp2, temp3, denom); SRA_4VECS(temp4, temp5, temp6, temp7, temp4, temp5, temp6, temp7, denom); temp0 = CLIP_UNSIGNED_CHAR_H(temp0); temp1 = CLIP_UNSIGNED_CHAR_H(temp1); temp2 = CLIP_UNSIGNED_CHAR_H(temp2); temp3 = CLIP_UNSIGNED_CHAR_H(temp3); temp4 = CLIP_UNSIGNED_CHAR_H(temp4); temp5 = CLIP_UNSIGNED_CHAR_H(temp5); temp6 = CLIP_UNSIGNED_CHAR_H(temp6); temp7 = CLIP_UNSIGNED_CHAR_H(temp7); PCKEV_B_4VECS_SB(temp1, temp3, temp5, temp7, temp0, temp2, temp4, temp6, dst0, dst1, dst2, dst3); STORE_4VECS_SB(dst, dst_stride, dst0, dst1, dst2, dst3); dst += 4 * dst_stride; } }
false
FFmpeg
bcd7bf7eeb09a395cc01698842d1b8be9af483fc
6,433
int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { /* FIXME error_setg(errp, ...) on failure */ int len; const char *file; char def_file[128]; const NetdevDumpOptions *dump; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); dump = opts->dump; assert(peer); if (dump->has_file) { file = dump->file; } else { int id; int ret; ret = net_hub_id_for_client(peer, &id); assert(ret == 0); /* peer must be on a hub */ snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", id); file = def_file; } if (dump->has_len) { if (dump->len > INT_MAX) { error_report("invalid length: %"PRIu64, dump->len); return -1; } len = dump->len; } else { len = 65536; } return net_dump_init(peer, "dump", name, file, len); }
true
qemu
3791f83ca999edc2d11eb2006ccc1091cd712c15
6,434
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) { if (*spec <= '9' && *spec >= '0') /* opt:index */ return strtol(spec, NULL, 0) == st->index; else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') { /* opt:[vasdt] */ enum AVMediaType type; switch (*spec++) { case 'v': type = AVMEDIA_TYPE_VIDEO; break; case 'a': type = AVMEDIA_TYPE_AUDIO; break; case 's': type = AVMEDIA_TYPE_SUBTITLE; break; case 'd': type = AVMEDIA_TYPE_DATA; break; case 't': type = AVMEDIA_TYPE_ATTACHMENT; break; } if (type != st->codec->codec_type) return 0; if (*spec++ == ':') { /* possibly followed by :index */ int i, index = strtol(spec, NULL, 0); for (i = 0; i < s->nb_streams; i++) if (s->streams[i]->codec->codec_type == type && index-- == 0) return i == st->index; return 0; } return 1; } else if (*spec == 'p' && *(spec + 1) == ':') { int prog_id, i, j; char *endptr; spec += 2; prog_id = strtol(spec, &endptr, 0); for (i = 0; i < s->nb_programs; i++) { if (s->programs[i]->id != prog_id) continue; if (*endptr++ == ':') { int stream_idx = strtol(endptr, NULL, 0); return stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes && st->index == s->programs[i]->stream_index[stream_idx]; } for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) if (st->index == s->programs[i]->stream_index[j]) return 1; } return 0; } else if (!*spec) /* empty specifier, matches everything */ return 1; av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec); return AVERROR(EINVAL); }
true
FFmpeg
7cf78b3476d77888caa059398078640fb821170e
6,435
static void rm_read_metadata(AVFormatContext *s, int wide) { char buf[1024]; int i; for (i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) { int len = wide ? avio_rb16(s->pb) : avio_r8(s->pb); get_strl(s->pb, buf, sizeof(buf), len); av_dict_set(&s->metadata, ff_rm_metadata[i], buf, 0); } }
true
FFmpeg
bf87908cd8da31e8f8fe75c06577170928ea70a8
6,436
void qmp_migrate(const char *uri, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, Error **errp) { Error *local_err = NULL; MigrationState *s = migrate_get_current(); MigrationParams params; const char *p; params.blk = has_blk && blk; params.shared = has_inc && inc; if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP || s->state == MIG_STATE_CANCELLING) { error_set(errp, QERR_MIGRATION_ACTIVE); if (qemu_savevm_state_blocked(errp)) { if (migration_blockers) { *errp = error_copy(migration_blockers->data); s = migrate_init(&params); if (strstart(uri, "tcp:", &p)) { tcp_start_outgoing_migration(s, p, &local_err); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { rdma_start_outgoing_migration(s, p, &local_err); #endif #if !defined(WIN32) } else if (strstart(uri, "exec:", &p)) { exec_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "unix:", &p)) { unix_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); #endif } else { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); s->state = MIG_STATE_ERROR; if (local_err) { migrate_fd_error(s); error_propagate(errp, local_err);
true
qemu
ca99993adc9205c905dba5dc1bb819959ada7200
6,437
static void stm32f2xx_timer_write(void *opaque, hwaddr offset, uint64_t val64, unsigned size) { STM32F2XXTimerState *s = opaque; uint32_t value = val64; int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); uint32_t timer_val = 0; DB_PRINT("Write 0x%x, 0x%"HWADDR_PRIx"\n", value, offset); switch (offset) { case TIM_CR1: s->tim_cr1 = value; return; case TIM_CR2: s->tim_cr2 = value; return; case TIM_SMCR: s->tim_smcr = value; return; case TIM_DIER: s->tim_dier = value; return; case TIM_SR: /* This is set by hardware and cleared by software */ s->tim_sr &= value; return; case TIM_EGR: s->tim_egr = value; if (s->tim_egr & TIM_EGR_UG) { timer_val = 0; break; } return; case TIM_CCMR1: s->tim_ccmr1 = value; return; case TIM_CCMR2: s->tim_ccmr2 = value; return; case TIM_CCER: s->tim_ccer = value; return; case TIM_PSC: timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset; s->tim_psc = value; value = timer_val; break; case TIM_CNT: timer_val = value; break; case TIM_ARR: s->tim_arr = value; stm32f2xx_timer_set_alarm(s, now); return; case TIM_CCR1: s->tim_ccr1 = value; return; case TIM_CCR2: s->tim_ccr2 = value; return; case TIM_CCR3: s->tim_ccr3 = value; return; case TIM_CCR4: s->tim_ccr4 = value; return; case TIM_DCR: s->tim_dcr = value; return; case TIM_DMAR: s->tim_dmar = value; return; case TIM_OR: s->tim_or = value; return; default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, offset); return; } /* This means that a register write has affected the timer in a way that * requires a refresh of both tick_offset and the alarm. */ s->tick_offset = stm32f2xx_ns_to_ticks(s, now) - timer_val; stm32f2xx_timer_set_alarm(s, now); }
true
qemu
84da15169b45f7080e4b1b32f70e68e726e02740
6,438
av_cold void ff_vp8dsp_init(VP8DSPContext *dsp) { dsp->vp8_luma_dc_wht = vp8_luma_dc_wht_c; dsp->vp8_luma_dc_wht_dc = vp8_luma_dc_wht_dc_c; dsp->vp8_idct_add = vp8_idct_add_c; dsp->vp8_idct_dc_add = vp8_idct_dc_add_c; dsp->vp8_idct_dc_add4y = vp8_idct_dc_add4y_c; dsp->vp8_idct_dc_add4uv = vp8_idct_dc_add4uv_c; dsp->vp8_v_loop_filter16y = vp8_v_loop_filter16_c; dsp->vp8_h_loop_filter16y = vp8_h_loop_filter16_c; dsp->vp8_v_loop_filter8uv = vp8_v_loop_filter8uv_c; dsp->vp8_h_loop_filter8uv = vp8_h_loop_filter8uv_c; dsp->vp8_v_loop_filter16y_inner = vp8_v_loop_filter16_inner_c; dsp->vp8_h_loop_filter16y_inner = vp8_h_loop_filter16_inner_c; dsp->vp8_v_loop_filter8uv_inner = vp8_v_loop_filter8uv_inner_c; dsp->vp8_h_loop_filter8uv_inner = vp8_h_loop_filter8uv_inner_c; dsp->vp8_v_loop_filter_simple = vp8_v_loop_filter_simple_c; dsp->vp8_h_loop_filter_simple = vp8_h_loop_filter_simple_c; VP8_MC_FUNC(0, 16); VP8_MC_FUNC(1, 8); VP8_MC_FUNC(2, 4); VP8_BILINEAR_MC_FUNC(0, 16); VP8_BILINEAR_MC_FUNC(1, 8); VP8_BILINEAR_MC_FUNC(2, 4); if (ARCH_ARM) ff_vp8dsp_init_arm(dsp); if (ARCH_PPC) ff_vp8dsp_init_ppc(dsp); if (ARCH_X86) ff_vp8dsp_init_x86(dsp); }
true
FFmpeg
ac4b32df71bd932838043a4838b86d11e169707f
6,439
static void test_qga_file_ops(gconstpointer fix) { const TestFixture *fixture = fix; const unsigned char helloworld[] = "Hello World!\n"; const char *b64; gchar *cmd, *path, *enc; unsigned char *dec; QDict *ret, *val; int64_t id, eof; gsize count; FILE *f; char tmp[100]; /* open */ ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," " 'arguments': { 'path': 'foo', 'mode': 'w+' } }"); g_assert_nonnull(ret); qmp_assert_no_error(ret); id = qdict_get_int(ret, "return"); QDECREF(ret); enc = g_base64_encode(helloworld, sizeof(helloworld)); /* write */ cmd = g_strdup_printf("{'execute': 'guest-file-write'," " 'arguments': { 'handle': %" PRId64 "," " 'buf-b64': '%s' } }", id, enc); ret = qmp_fd(fixture->fd, cmd); g_assert_nonnull(ret); qmp_assert_no_error(ret); val = qdict_get_qdict(ret, "return"); count = qdict_get_int(val, "count"); eof = qdict_get_bool(val, "eof"); g_assert_cmpint(count, ==, sizeof(helloworld)); g_assert_cmpint(eof, ==, 0); QDECREF(ret); g_free(cmd); /* flush */ cmd = g_strdup_printf("{'execute': 'guest-file-flush'," " 'arguments': {'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); QDECREF(ret); g_free(cmd); /* close */ cmd = g_strdup_printf("{'execute': 'guest-file-close'," " 'arguments': {'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); QDECREF(ret); g_free(cmd); /* check content */ path = g_build_filename(fixture->test_dir, "foo", NULL); f = fopen(path, "r"); g_assert_nonnull(f); count = fread(tmp, 1, sizeof(tmp), f); g_assert_cmpint(count, ==, sizeof(helloworld)); tmp[count] = 0; g_assert_cmpstr(tmp, ==, (char *)helloworld); fclose(f); /* open */ ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," " 'arguments': { 'path': 'foo', 'mode': 'r' } }"); g_assert_nonnull(ret); qmp_assert_no_error(ret); id = qdict_get_int(ret, "return"); QDECREF(ret); /* read */ cmd = g_strdup_printf("{'execute': 'guest-file-read'," " 'arguments': { 'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); val = qdict_get_qdict(ret, "return"); count = qdict_get_int(val, "count"); eof = qdict_get_bool(val, "eof"); b64 = qdict_get_str(val, "buf-b64"); g_assert_cmpint(count, ==, sizeof(helloworld)); g_assert(eof); g_assert_cmpstr(b64, ==, enc); QDECREF(ret); g_free(cmd); g_free(enc); /* read eof */ cmd = g_strdup_printf("{'execute': 'guest-file-read'," " 'arguments': { 'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); val = qdict_get_qdict(ret, "return"); count = qdict_get_int(val, "count"); eof = qdict_get_bool(val, "eof"); b64 = qdict_get_str(val, "buf-b64"); g_assert_cmpint(count, ==, 0); g_assert(eof); g_assert_cmpstr(b64, ==, ""); QDECREF(ret); g_free(cmd); /* seek */ cmd = g_strdup_printf("{'execute': 'guest-file-seek'," " 'arguments': { 'handle': %" PRId64 ", " " 'offset': %d, 'whence': '%s' } }", id, 6, "set"); ret = qmp_fd(fixture->fd, cmd); qmp_assert_no_error(ret); val = qdict_get_qdict(ret, "return"); count = qdict_get_int(val, "position"); eof = qdict_get_bool(val, "eof"); g_assert_cmpint(count, ==, 6); g_assert(!eof); QDECREF(ret); g_free(cmd); /* partial read */ cmd = g_strdup_printf("{'execute': 'guest-file-read'," " 'arguments': { 'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); val = qdict_get_qdict(ret, "return"); count = qdict_get_int(val, "count"); eof = qdict_get_bool(val, "eof"); b64 = qdict_get_str(val, "buf-b64"); g_assert_cmpint(count, ==, sizeof(helloworld) - 6); g_assert(eof); dec = g_base64_decode(b64, &count); g_assert_cmpint(count, ==, sizeof(helloworld) - 6); g_assert_cmpmem(dec, count, helloworld + 6, sizeof(helloworld) - 6); g_free(dec); QDECREF(ret); g_free(cmd); /* close */ cmd = g_strdup_printf("{'execute': 'guest-file-close'," " 'arguments': {'handle': %" PRId64 "} }", id); ret = qmp_fd(fixture->fd, cmd); QDECREF(ret); g_free(cmd); }
true
qemu
1e2713384c58037ad44f716c31c08daca18862c5
6,441
static bool vexpress_cfgctrl_write(arm_sysctl_state *s, unsigned int dcc, unsigned int function, unsigned int site, unsigned int position, unsigned int device, uint32_t val) { /* We don't support anything other than DCC 0, board stack position 0 * or sites other than motherboard/daughterboard: */ if (dcc != 0 || position != 0 || (site != SYS_CFG_SITE_MB && site != SYS_CFG_SITE_DB1)) { goto cfgctrl_unimp; } switch (function) { case SYS_CFG_OSC: if (site == SYS_CFG_SITE_MB && device < sizeof(s->mb_clock)) { /* motherboard clock */ s->mb_clock[device] = val; return true; } if (site == SYS_CFG_SITE_DB1 && device < s->db_num_clocks) { /* daughterboard clock */ s->db_clock[device] = val; return true; } break; case SYS_CFG_MUXFPGA: if (site == SYS_CFG_SITE_MB && device == 0) { /* Select whether video output comes from motherboard * or daughterboard: log and ignore as QEMU doesn't * support this. */ qemu_log_mask(LOG_UNIMP, "arm_sysctl: selection of video output " "not supported, ignoring\n"); return true; } break; case SYS_CFG_SHUTDOWN: if (site == SYS_CFG_SITE_MB && device == 0) { qemu_system_shutdown_request(); return true; } break; case SYS_CFG_REBOOT: if (site == SYS_CFG_SITE_MB && device == 0) { qemu_system_reset_request(); return true; } break; case SYS_CFG_DVIMODE: if (site == SYS_CFG_SITE_MB && device == 0) { /* Selecting DVI mode is meaningless for QEMU: we will * always display the output correctly according to the * pixel height/width programmed into the CLCD controller. */ return true; } default: break; } cfgctrl_unimp: qemu_log_mask(LOG_UNIMP, "arm_sysctl: Unimplemented SYS_CFGCTRL write of function " "0x%x DCC 0x%x site 0x%x position 0x%x device 0x%x\n", function, dcc, site, position, device); return false; }
true
qemu
ec1efab95767312ff4afb816d0d4b548e093b031
6,442
pci_ebus_init1(PCIDevice *s) { isa_bus_new(&s->qdev); s->config[0x04] = 0x06; // command = bus master, pci mem s->config[0x05] = 0x00; s->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error s->config[0x07] = 0x03; // status = medium devsel s->config[0x09] = 0x00; // programming i/f s->config[0x0D] = 0x0a; // latency_timer pci_register_bar(s, 0, 0x1000000, PCI_BASE_ADDRESS_SPACE_MEMORY, ebus_mmio_mapfunc); pci_register_bar(s, 1, 0x800000, PCI_BASE_ADDRESS_SPACE_MEMORY, ebus_mmio_mapfunc); return 0; }
true
qemu
c5e6fb7e4ac6e7083682e7f45d27d1e73b3a1a97
6,443
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative) { x++; y++; t1->flags[y][x] |= JPEG2000_T1_SIG; if (negative) { t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W; t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E; t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N; t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S; } else { t1->flags[y][x + 1] |= JPEG2000_T1_SIG_W; t1->flags[y][x - 1] |= JPEG2000_T1_SIG_E; t1->flags[y + 1][x] |= JPEG2000_T1_SIG_N; t1->flags[y - 1][x] |= JPEG2000_T1_SIG_S; } t1->flags[y + 1][x + 1] |= JPEG2000_T1_SIG_NW; t1->flags[y + 1][x - 1] |= JPEG2000_T1_SIG_NE; t1->flags[y - 1][x + 1] |= JPEG2000_T1_SIG_SW; t1->flags[y - 1][x - 1] |= JPEG2000_T1_SIG_SE; }
false
FFmpeg
f1e173049ecc9de03817385ba8962d14cba779db
6,444
static int print_uint32(DeviceState *dev, Property *prop, char *dest, size_t len) { uint32_t *ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "%" PRIu32, *ptr); }
true
qemu
5cb9b56acfc0b50acf7ccd2d044ab4991c47fdde
6,446
static inline int pic_is_unused(H264Context *h, Picture *pic) { if (pic->f.data[0] == NULL) return 1; if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF)) return 1; return 0; }
false
FFmpeg
a553c6a347d3d28d7ee44c3df3d5c4ee780dba23
6,447
static int vdpau_alloc(AVCodecContext *s) { InputStream *ist = s->opaque; int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; AVVDPAUContext *vdpau_ctx; VDPAUContext *ctx; const char *display, *vendor; VdpStatus err; int i; ctx = av_mallocz(sizeof(*ctx)); if (!ctx) return AVERROR(ENOMEM); ist->hwaccel_ctx = ctx; ist->hwaccel_uninit = vdpau_uninit; ist->hwaccel_get_buffer = vdpau_get_buffer; ist->hwaccel_retrieve_data = vdpau_retrieve_data; ctx->tmp_frame = av_frame_alloc(); if (!ctx->tmp_frame) goto fail; ctx->dpy = XOpenDisplay(ist->hwaccel_device); if (!ctx->dpy) { av_log(NULL, loglevel, "Cannot open the X11 display %s.\n", XDisplayName(ist->hwaccel_device)); goto fail; } display = XDisplayString(ctx->dpy); err = vdp_device_create_x11(ctx->dpy, XDefaultScreen(ctx->dpy), &ctx->device, &ctx->get_proc_address); if (err != VDP_STATUS_OK) { av_log(NULL, loglevel, "VDPAU device creation on X11 display %s failed.\n", display); goto fail; } #define GET_CALLBACK(id, result) \ do { \ void *tmp; \ err = ctx->get_proc_address(ctx->device, id, &tmp); \ if (err != VDP_STATUS_OK) { \ av_log(NULL, loglevel, "Error getting the " #id " callback.\n"); \ goto fail; \ } \ ctx->result = tmp; \ } while (0) GET_CALLBACK(VDP_FUNC_ID_GET_ERROR_STRING, get_error_string); GET_CALLBACK(VDP_FUNC_ID_GET_INFORMATION_STRING, get_information_string); GET_CALLBACK(VDP_FUNC_ID_DEVICE_DESTROY, device_destroy); if (vdpau_api_ver == 1) { GET_CALLBACK(VDP_FUNC_ID_DECODER_CREATE, decoder_create); GET_CALLBACK(VDP_FUNC_ID_DECODER_DESTROY, decoder_destroy); GET_CALLBACK(VDP_FUNC_ID_DECODER_RENDER, decoder_render); } GET_CALLBACK(VDP_FUNC_ID_VIDEO_SURFACE_CREATE, video_surface_create); GET_CALLBACK(VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, video_surface_destroy); GET_CALLBACK(VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR, video_surface_get_bits); GET_CALLBACK(VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS, video_surface_get_parameters); GET_CALLBACK(VDP_FUNC_ID_VIDEO_SURFACE_QUERY_GET_PUT_BITS_Y_CB_CR_CAPABILITIES, video_surface_query); for (i = 0; i < FF_ARRAY_ELEMS(vdpau_formats); i++) { VdpBool supported; err = ctx->video_surface_query(ctx->device, VDP_CHROMA_TYPE_420, vdpau_formats[i][0], &supported); if (err != VDP_STATUS_OK) { av_log(NULL, loglevel, "Error querying VDPAU surface capabilities: %s\n", ctx->get_error_string(err)); goto fail; } if (supported) break; } if (i == FF_ARRAY_ELEMS(vdpau_formats)) { av_log(NULL, loglevel, "No supported VDPAU format for retrieving the data.\n"); return AVERROR(EINVAL); } ctx->vdpau_format = vdpau_formats[i][0]; ctx->pix_fmt = vdpau_formats[i][1]; if (vdpau_api_ver == 1) { vdpau_ctx = av_vdpau_alloc_context(); if (!vdpau_ctx) goto fail; vdpau_ctx->render = ctx->decoder_render; s->hwaccel_context = vdpau_ctx; } else if (av_vdpau_bind_context(s, ctx->device, ctx->get_proc_address, 0)) goto fail; ctx->get_information_string(&vendor); av_log(NULL, AV_LOG_VERBOSE, "Using VDPAU -- %s -- on X11 display %s, " "to decode input stream #%d:%d.\n", vendor, display, ist->file_index, ist->st->index); return 0; fail: av_log(NULL, loglevel, "VDPAU init failed for stream #%d:%d.\n", ist->file_index, ist->st->index); vdpau_uninit(s); return AVERROR(EINVAL); }
false
FFmpeg
d3eb317b862c3f5653f0ae8dfcb22edf1713ab5b
6,448
void ff_h263_encode_mb(MpegEncContext * s, int16_t block[6][64], int motion_x, int motion_y) { int cbpc, cbpy, i, cbp, pred_x, pred_y; int16_t pred_dc; int16_t rec_intradc[6]; int16_t *dc_ptr[6]; const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1); if (!s->mb_intra) { /* compute cbp */ cbp= get_p_cbp(s, block, motion_x, motion_y); if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) { /* skip macroblock */ put_bits(&s->pb, 1, 1); if(interleaved_stats){ s->misc_bits++; s->last_bits++; } s->skip_count++; return; } put_bits(&s->pb, 1, 0); /* mb coded */ cbpc = cbp & 3; cbpy = cbp >> 2; if(s->alt_inter_vlc==0 || cbpc!=3) cbpy ^= 0xF; if(s->dquant) cbpc+= 8; if(s->mv_type==MV_TYPE_16X16){ put_bits(&s->pb, ff_h263_inter_MCBPC_bits[cbpc], ff_h263_inter_MCBPC_code[cbpc]); put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); if(s->dquant) put_bits(&s->pb, 2, dquant_code[s->dquant+2]); if(interleaved_stats){ s->misc_bits+= get_bits_diff(s); } /* motion vectors: 16x16 mode */ ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (!s->umvplus) { ff_h263_encode_motion_vector(s, motion_x - pred_x, motion_y - pred_y, 1); } else { h263p_encode_umotion(s, motion_x - pred_x); h263p_encode_umotion(s, motion_y - pred_y); if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) /* To prevent Start Code emulation */ put_bits(&s->pb,1,1); } }else{ put_bits(&s->pb, ff_h263_inter_MCBPC_bits[cbpc+16], ff_h263_inter_MCBPC_code[cbpc+16]); put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); if(s->dquant) put_bits(&s->pb, 2, dquant_code[s->dquant+2]); if(interleaved_stats){ s->misc_bits+= get_bits_diff(s); } for(i=0; i<4; i++){ /* motion vectors: 8x8 mode*/ ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); motion_x = s->current_picture.motion_val[0][s->block_index[i]][0]; motion_y = s->current_picture.motion_val[0][s->block_index[i]][1]; if (!s->umvplus) { ff_h263_encode_motion_vector(s, motion_x - pred_x, motion_y - pred_y, 1); } else { h263p_encode_umotion(s, motion_x - pred_x); h263p_encode_umotion(s, motion_y - pred_y); if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) /* To prevent Start Code emulation */ put_bits(&s->pb,1,1); } } } if(interleaved_stats){ s->mv_bits+= get_bits_diff(s); } } else { assert(s->mb_intra); cbp = 0; if (s->h263_aic) { /* Predict DC */ for(i=0; i<6; i++) { int16_t level = block[i][0]; int scale; if(i<4) scale= s->y_dc_scale; else scale= s->c_dc_scale; pred_dc = ff_h263_pred_dc(s, i, &dc_ptr[i]); level -= pred_dc; /* Quant */ if (level >= 0) level = (level + (scale>>1))/scale; else level = (level - (scale>>1))/scale; /* AIC can change CBP */ if (level == 0 && s->block_last_index[i] == 0) s->block_last_index[i] = -1; if(!s->modified_quant){ if (level < -127) level = -127; else if (level > 127) level = 127; } block[i][0] = level; /* Reconstruction */ rec_intradc[i] = scale*level + pred_dc; /* Oddify */ rec_intradc[i] |= 1; //if ((rec_intradc[i] % 2) == 0) // rec_intradc[i]++; /* Clipping */ if (rec_intradc[i] < 0) rec_intradc[i] = 0; else if (rec_intradc[i] > 2047) rec_intradc[i] = 2047; /* Update AC/DC tables */ *dc_ptr[i] = rec_intradc[i]; if (s->block_last_index[i] >= 0) cbp |= 1 << (5 - i); } }else{ for(i=0; i<6; i++) { /* compute cbp */ if (s->block_last_index[i] >= 1) cbp |= 1 << (5 - i); } } cbpc = cbp & 3; if (s->pict_type == AV_PICTURE_TYPE_I) { if(s->dquant) cbpc+=4; put_bits(&s->pb, ff_h263_intra_MCBPC_bits[cbpc], ff_h263_intra_MCBPC_code[cbpc]); } else { if(s->dquant) cbpc+=8; put_bits(&s->pb, 1, 0); /* mb coded */ put_bits(&s->pb, ff_h263_inter_MCBPC_bits[cbpc + 4], ff_h263_inter_MCBPC_code[cbpc + 4]); } if (s->h263_aic) { /* XXX: currently, we do not try to use ac prediction */ put_bits(&s->pb, 1, 0); /* no AC prediction */ } cbpy = cbp >> 2; put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); if(s->dquant) put_bits(&s->pb, 2, dquant_code[s->dquant+2]); if(interleaved_stats){ s->misc_bits+= get_bits_diff(s); } } for(i=0; i<6; i++) { /* encode each block */ h263_encode_block(s, block[i], i); /* Update INTRADC for decoding */ if (s->h263_aic && s->mb_intra) { block[i][0] = rec_intradc[i]; } } if(interleaved_stats){ if (!s->mb_intra) { s->p_tex_bits+= get_bits_diff(s); s->f_count++; }else{ s->i_tex_bits+= get_bits_diff(s); s->i_count++; } } }
false
FFmpeg
cd62c04d009b3baf7582556866a7029291b54573
6,449
static int hls_mux_init(AVFormatContext *s) { HLSContext *hls = s->priv_data; AVFormatContext *oc; AVFormatContext *vtt_oc; int i, ret; ret = avformat_alloc_output_context2(&hls->avf, hls->oformat, NULL, NULL); if (ret < 0) return ret; oc = hls->avf; oc->oformat = hls->oformat; oc->interrupt_callback = s->interrupt_callback; oc->max_delay = s->max_delay; av_dict_copy(&oc->metadata, s->metadata, 0); if(hls->vtt_oformat) { ret = avformat_alloc_output_context2(&hls->vtt_avf, hls->vtt_oformat, NULL, NULL); if (ret < 0) return ret; vtt_oc = hls->vtt_avf; vtt_oc->oformat = hls->vtt_oformat; av_dict_copy(&vtt_oc->metadata, s->metadata, 0); } for (i = 0; i < s->nb_streams; i++) { AVStream *st; AVFormatContext *loc; if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) loc = vtt_oc; else loc = oc; if (!(st = avformat_new_stream(loc, NULL))) return AVERROR(ENOMEM); avcodec_copy_context(st->codec, s->streams[i]->codec); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } hls->start_pos = 0; return 0; }
false
FFmpeg
e3d8504fd043bdc2535525128b158fbc1fb18c67