project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
qemu
a5cf8262e4eb9c4646434e2c6211ef8608db3233
0
char* qdev_get_fw_dev_path(DeviceState *dev) { char path[128]; int l; l = qdev_get_fw_dev_path_helper(dev, path, 128); path[l-1] = '\0'; return strdup(path); }
21,494
qemu
a5068244b4f0c994791303b6186b6f732adab6c2
0
static ssize_t drop_sync(QIOChannel *ioc, size_t size) { ssize_t ret, dropped = size; char small[1024]; char *buffer; buffer = sizeof(small) < size ? small : g_malloc(MIN(65536, size)); while (size > 0) { ret = read_sync(ioc, buffer, MIN(65536, size)); if (ret < 0) { goto cleanup; } assert(ret <= size); size -= ret; } ret = dropped; cleanup: if (buffer != small) { g_free(buffer); } return ret; }
21,495
qemu
61007b316cd71ee7333ff7a0a749a8949527575f
0
static BlockAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockCompletionFunc *cb, void *opaque) { return bdrv_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque, 0); }
21,496
FFmpeg
36a60fad6215db39e9cd9523e3425f64464046c7
0
static int seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { int index; int64_t ret; AVStream *st; AVIndexEntry *ie; st = s->streams[stream_index]; index = av_index_search_timestamp(st, timestamp, flags); if(index < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) return -1; if(index < 0 || index==st->nb_index_entries-1){ AVPacket pkt; int nonkey=0; if(st->nb_index_entries){ assert(st->index_entries); ie= &st->index_entries[st->nb_index_entries-1]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); }else{ if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0) return ret; } for (;;) { int read_status; do{ read_status = av_read_frame(s, &pkt); } while (read_status == AVERROR(EAGAIN)); if (read_status < 0) break; av_free_packet(&pkt); if(stream_index == pkt.stream_index && pkt.dts > timestamp){ if(pkt.flags & AV_PKT_FLAG_KEY) break; if(nonkey++ > 1000){ av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey); break; } } } index = av_index_search_timestamp(st, timestamp, flags); } if (index < 0) return -1; ff_read_frame_flush(s); AV_NOWARN_DEPRECATED( if (s->iformat->read_seek){ if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) return 0; } ) ie = &st->index_entries[index]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); return 0; }
21,497
FFmpeg
607ad990d31e6be52980970e5ce8cd25ab3de812
0
static void dvbsub_parse_page_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { DVBSubContext *ctx = avctx->priv_data; DVBSubRegionDisplay *display; DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; const uint8_t *buf_end = buf + buf_size; int region_id; int page_state; if (buf_size < 1) return; ctx->time_out = *buf++; page_state = ((*buf++) >> 2) & 3; av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state); if (page_state == 2) { delete_state(ctx); } tmp_display_list = ctx->display_list; ctx->display_list = NULL; ctx->display_list_size = 0; while (buf + 5 < buf_end) { region_id = *buf++; buf += 1; display = tmp_display_list; tmp_ptr = &tmp_display_list; while (display && display->region_id != region_id) { tmp_ptr = &display->next; display = display->next; } if (!display) display = av_mallocz(sizeof(DVBSubRegionDisplay)); display->region_id = region_id; display->x_pos = AV_RB16(buf); buf += 2; display->y_pos = AV_RB16(buf); buf += 2; *tmp_ptr = display->next; display->next = ctx->display_list; ctx->display_list = display; ctx->display_list_size++; av_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos); } while (tmp_display_list) { display = tmp_display_list; tmp_display_list = display->next; av_free(display); } }
21,498
qemu
bc7c08a2c375acb7ae4d433054415588b176d34c
0
static void test_qemu_strtoul_negative(void) { const char *str = " \t -321"; char f = 'X'; const char *endptr = &f; unsigned long res = 999; int err; err = qemu_strtoul(str, &endptr, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, -321ul); g_assert(endptr == str + strlen(str)); }
21,499
qemu
4a1418e07bdcfaa3177739e04707ecaec75d89e1
0
static int is_cpuid_supported(void) { return 1; }
21,500
qemu
8e9b0d24fb986d4241ae3b77752eca5dab4cb486
0
void vnc_display_init(const char *id) { VncDisplay *vs; if (vnc_display_find(id) != NULL) { return; } vs = g_malloc0(sizeof(*vs)); vs->id = strdup(id); QTAILQ_INSERT_TAIL(&vnc_displays, vs, next); vs->lsock = -1; #ifdef CONFIG_VNC_WS vs->lwebsock = -1; #endif QTAILQ_INIT(&vs->clients); vs->expires = TIME_MAX; if (keyboard_layout) { trace_vnc_key_map_init(keyboard_layout); vs->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout); } else { vs->kbd_layout = init_keyboard_layout(name2keysym, "en-us"); } if (!vs->kbd_layout) exit(1); qemu_mutex_init(&vs->mutex); vnc_start_worker_thread(); vs->dcl.ops = &dcl_ops; register_displaychangelistener(&vs->dcl); }
21,501
FFmpeg
e021eeb9f06f4f4d83690d07b47cdcc4172a61e1
0
static int get_key(const char **ropts, const char *delim, char *key, unsigned key_size) { unsigned key_pos = 0; const char *opts = *ropts; opts += strspn(opts, WHITESPACES); while (is_key_char(*opts)) { key[key_pos++] = *opts; if (key_pos == key_size) key_pos--; (opts)++; } opts += strspn(opts, WHITESPACES); if (!*opts || !strchr(delim, *opts)) return AVERROR(EINVAL); opts++; key[key_pos++] = 0; if (key_pos == key_size) key[key_pos - 4] = key[key_pos - 3] = key[key_pos - 2] = '.'; *ropts = opts; return 0; }
21,502
FFmpeg
dbefbb61b785cd77810c032f5cdb499d2a92df07
0
static void expand_timestamps(void *log, struct sbg_script *s) { int i, nb_rel = 0; int64_t now, cur_ts, delta = 0; for (i = 0; i < s->nb_tseq; i++) nb_rel += s->tseq[i].ts.type == 'N'; if (nb_rel == s->nb_tseq) { /* All ts are relative to NOW: consider NOW = 0 */ now = 0; if (s->start_ts != AV_NOPTS_VALUE) av_log(log, AV_LOG_WARNING, "Start time ignored in a purely relative script.\n"); } else if (nb_rel == 0 && s->start_ts != AV_NOPTS_VALUE || s->opt_start_at_first) { /* All ts are absolute and start time is specified */ if (s->start_ts == AV_NOPTS_VALUE) s->start_ts = s->tseq[0].ts.t; now = s->start_ts; } else { /* Mixed relative/absolute ts: expand */ time_t now0; struct tm *tm, tmpbuf; av_log(log, AV_LOG_WARNING, "Scripts with mixed absolute and relative timestamps can give " "unexpected results (pause, seeking, time zone change).\n"); #undef time time(&now0); tm = localtime_r(&now0, &tmpbuf); now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec : now0 % DAY; av_log(log, AV_LOG_INFO, "Using %02d:%02d:%02d as NOW.\n", (int)(now / 3600), (int)(now / 60) % 60, (int)now % 60); now *= AV_TIME_BASE; for (i = 0; i < s->nb_tseq; i++) { if (s->tseq[i].ts.type == 'N') { s->tseq[i].ts.t += now; s->tseq[i].ts.type = 'T'; /* not necessary */ } } } if (s->start_ts == AV_NOPTS_VALUE) s->start_ts = s->opt_start_at_first ? s->tseq[0].ts.t : now; s->end_ts = s->opt_duration ? s->start_ts + s->opt_duration : AV_NOPTS_VALUE; /* may be overridden later by -E option */ cur_ts = now; for (i = 0; i < s->nb_tseq; i++) { if (s->tseq[i].ts.t + delta < cur_ts) delta += DAY_TS; cur_ts = s->tseq[i].ts.t += delta; } }
21,503
FFmpeg
2bf4aa2e937737deb781706673f806d4388cf796
0
static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){ heap_elem_t h[size]; int up[2*size]; int len[2*size]; int offset, i, next; for(offset=1; ; offset<<=1){ for(i=0; i<size; i++){ h[i].name = i; h[i].val = (stats[i] << 8) + offset; } for(i=size/2-1; i>=0; i--) heap_sift(h, i, size); for(next=size; next<size*2-1; next++){ // merge the two smallest entries, and put it back in the heap uint64_t min1v = h[0].val; up[h[0].name] = next; h[0].val = INT64_MAX; heap_sift(h, 0, size); up[h[0].name] = next; h[0].name = next; h[0].val += min1v; heap_sift(h, 0, size); } len[2*size-2] = 0; for(i=2*size-3; i>=size; i--) len[i] = len[up[i]] + 1; for(i=0; i<size; i++) { dst[i] = len[up[i]] + 1; if(dst[i] > 32) break; } if(i==size) break; } }
21,504
FFmpeg
bdf7610eb266fd3de650040c97328791868abd82
0
static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) { AVFilterContext *avctx = inlink->dst; AVFilterLink *outlink = avctx->outputs[0]; ScaleVAAPIContext *ctx = avctx->priv; AVFrame *output_frame = NULL; VASurfaceID input_surface, output_surface; VAProcPipelineParameterBuffer params; VABufferID params_id; VAStatus vas; int err; av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n", av_get_pix_fmt_name(input_frame->format), input_frame->width, input_frame->height, input_frame->pts); if (ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3]; av_log(ctx, AV_LOG_DEBUG, "Using surface %#x for scale input.\n", input_surface); output_frame = av_frame_alloc(); if (!output_frame) { av_log(ctx, AV_LOG_ERROR, "Failed to allocate output frame."); err = AVERROR(ENOMEM); goto fail; } err = av_hwframe_get_buffer(ctx->output_frames_ref, output_frame, 0); if (err < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to get surface for " "output: %d\n.", err); } output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; av_log(ctx, AV_LOG_DEBUG, "Using surface %#x for scale output.\n", output_surface); memset(&params, 0, sizeof(params)); params.surface = input_surface; params.surface_region = 0; params.surface_color_standard = vaapi_proc_colour_standard(input_frame->colorspace); params.output_region = 0; params.output_background_color = 0xff000000; params.output_color_standard = params.surface_color_standard; params.pipeline_flags = 0; params.filter_flags = VA_FILTER_SCALING_HQ; vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context, output_surface); if (vas != VA_STATUS_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Failed to attach new picture: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail; } vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, VAProcPipelineParameterBufferType, sizeof(params), 1, &params, &params_id); if (vas != VA_STATUS_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Failed to create parameter buffer: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail_after_begin; } av_log(ctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n", params_id); vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, &params_id, 1); if (vas != VA_STATUS_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Failed to render parameter buffer: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail_after_begin; } vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); if (vas != VA_STATUS_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Failed to start picture processing: " "%d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); goto fail_after_render; } if (ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { vas = vaDestroyBuffer(ctx->hwctx->display, params_id); if (vas != VA_STATUS_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Failed to free parameter buffer: " "%d (%s).\n", vas, vaErrorStr(vas)); // And ignore. } } av_frame_copy_props(output_frame, input_frame); av_frame_free(&input_frame); av_log(ctx, AV_LOG_DEBUG, "Filter output: %s, %ux%u (%"PRId64").\n", av_get_pix_fmt_name(output_frame->format), output_frame->width, output_frame->height, output_frame->pts); return ff_filter_frame(outlink, output_frame); // We want to make sure that if vaBeginPicture has been called, we also // call vaRenderPicture and vaEndPicture. These calls may well fail or // do something else nasty, but once we're in this failure case there // isn't much else we can do. fail_after_begin: vaRenderPicture(ctx->hwctx->display, ctx->va_context, &params_id, 1); fail_after_render: vaEndPicture(ctx->hwctx->display, ctx->va_context); fail: av_frame_free(&input_frame); av_frame_free(&output_frame); return err; }
21,505
FFmpeg
0849a0ebb2c94856c3a94cb114a1412e44904c28
1
static int get_packet(URLContext *s, int for_header) { RTMPContext *rt = s->priv_data; int ret; uint8_t *p; const uint8_t *next; uint32_t data_size; uint32_t ts, cts, pts=0; if (rt->state == STATE_STOPPED) return AVERROR_EOF; for (;;) { RTMPPacket rpkt = { 0 }; if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt, rt->chunk_size, rt->prev_pkt[0])) <= 0) { if (ret == 0) { return AVERROR(EAGAIN); } else { return AVERROR(EIO); } } rt->bytes_read += ret; if (rt->bytes_read > rt->last_bytes_read + rt->client_report_size) { av_log(s, AV_LOG_DEBUG, "Sending bytes read report\n"); gen_bytes_read(s, rt, rpkt.timestamp + 1); rt->last_bytes_read = rt->bytes_read; } ret = rtmp_parse_result(s, rt, &rpkt); if (ret < 0) {//serious error in current packet ff_rtmp_packet_destroy(&rpkt); return -1; } if (rt->state == STATE_STOPPED) { ff_rtmp_packet_destroy(&rpkt); return AVERROR_EOF; } if (for_header && (rt->state == STATE_PLAYING || rt->state == STATE_PUBLISHING)) { ff_rtmp_packet_destroy(&rpkt); return 0; } if (!rpkt.data_size || !rt->is_input) { ff_rtmp_packet_destroy(&rpkt); continue; } if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO || (rpkt.type == RTMP_PT_NOTIFY && !memcmp("\002\000\012onMetaData", rpkt.data, 13))) { ts = rpkt.timestamp; // generate packet header and put data into buffer for FLV demuxer rt->flv_off = 0; rt->flv_size = rpkt.data_size + 15; rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size); bytestream_put_byte(&p, rpkt.type); bytestream_put_be24(&p, rpkt.data_size); bytestream_put_be24(&p, ts); bytestream_put_byte(&p, ts >> 24); bytestream_put_be24(&p, 0); bytestream_put_buffer(&p, rpkt.data, rpkt.data_size); bytestream_put_be32(&p, 0); ff_rtmp_packet_destroy(&rpkt); return 0; } else if (rpkt.type == RTMP_PT_METADATA) { // we got raw FLV data, make it available for FLV demuxer rt->flv_off = 0; rt->flv_size = rpkt.data_size; rt->flv_data = av_realloc(rt->flv_data, rt->flv_size); /* rewrite timestamps */ next = rpkt.data; ts = rpkt.timestamp; while (next - rpkt.data < rpkt.data_size - 11) { next++; data_size = bytestream_get_be24(&next); p=next; cts = bytestream_get_be24(&next); cts |= bytestream_get_byte(&next) << 24; if (pts==0) pts=cts; ts += cts - pts; pts = cts; bytestream_put_be24(&p, ts); bytestream_put_byte(&p, ts >> 24); next += data_size + 3 + 4; } memcpy(rt->flv_data, rpkt.data, rpkt.data_size); ff_rtmp_packet_destroy(&rpkt); return 0; } ff_rtmp_packet_destroy(&rpkt); } }
21,506
FFmpeg
8de0990e9f22d7f728f70d5a03f3e78fc958f658
1
static void save_display_set(DVBSubContext *ctx) { DVBSubRegion *region; DVBSubRegionDisplay *display; DVBSubCLUT *clut; uint32_t *clut_table; int x_pos, y_pos, width, height; int x, y, y_off, x_off; uint32_t *pbuf; char filename[32]; static int fileno_index = 0; x_pos = -1; y_pos = -1; width = 0; height = 0; for (display = ctx->display_list; display; display = display->next) { region = get_region(ctx, display->region_id); if (x_pos == -1) { x_pos = display->x_pos; y_pos = display->y_pos; width = region->width; height = region->height; } else { if (display->x_pos < x_pos) { width += (x_pos - display->x_pos); x_pos = display->x_pos; } if (display->y_pos < y_pos) { height += (y_pos - display->y_pos); y_pos = display->y_pos; } if (display->x_pos + region->width > x_pos + width) { width = display->x_pos + region->width - x_pos; } if (display->y_pos + region->height > y_pos + height) { height = display->y_pos + region->height - y_pos; } } } if (x_pos >= 0) { pbuf = av_malloc(width * height * 4); for (display = ctx->display_list; display; display = display->next) { region = get_region(ctx, display->region_id); x_off = display->x_pos - x_pos; y_off = display->y_pos - y_pos; clut = get_clut(ctx, region->clut); if (!clut) clut = &default_clut; switch (region->depth) { case 2: clut_table = clut->clut4; break; case 8: clut_table = clut->clut256; break; case 4: default: clut_table = clut->clut16; break; } for (y = 0; y < region->height; y++) { for (x = 0; x < region->width; x++) { pbuf[((y + y_off) * width) + x_off + x] = clut_table[region->pbuf[y * region->width + x]]; } } } snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index); png_save2(filename, pbuf, width, height); av_freep(&pbuf); } fileno_index++; }
21,507
FFmpeg
2b336df3cb9d9bcc12c4b398ea1dbdfe224d152e
1
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx) { char *tail, color_string2[128]; const ColorEntry *entry; int len, hex_offset = 0; if (color_string[0] == '#') { hex_offset = 1; } else if (!strncmp(color_string, "0x", 2)) hex_offset = 2; if (slen < 0) slen = strlen(color_string); av_strlcpy(color_string2, color_string + hex_offset, FFMIN(slen-hex_offset+1, sizeof(color_string2))); if ((tail = strchr(color_string2, ALPHA_SEP))) *tail++ = 0; len = strlen(color_string2); rgba_color[3] = 255; if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) { int rgba = av_get_random_seed(); rgba_color[0] = rgba >> 24; rgba_color[1] = rgba >> 16; rgba_color[2] = rgba >> 8; rgba_color[3] = rgba; } else if (hex_offset || strspn(color_string2, "0123456789ABCDEFabcdef") == len) { char *tail; unsigned int rgba = strtoul(color_string2, &tail, 16); if (*tail || (len != 6 && len != 8)) { av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2); return AVERROR(EINVAL); } if (len == 8) { rgba_color[3] = rgba; rgba >>= 8; } rgba_color[0] = rgba >> 16; rgba_color[1] = rgba >> 8; rgba_color[2] = rgba; } else { entry = bsearch(color_string2, color_table, FF_ARRAY_ELEMS(color_table), sizeof(ColorEntry), color_table_compare); if (!entry) { av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2); return AVERROR(EINVAL); } memcpy(rgba_color, entry->rgb_color, 3); } if (tail) { unsigned long int alpha; const char *alpha_string = tail; if (!strncmp(alpha_string, "0x", 2)) { alpha = strtoul(alpha_string, &tail, 16); } else { alpha = 255 * strtod(alpha_string, &tail); } if (tail == alpha_string || *tail || alpha > 255) { av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n", alpha_string, color_string); return AVERROR(EINVAL); } rgba_color[3] = alpha; } return 0; }
21,509
qemu
71ae65e552fc6e03572e430009b98b80b40f1c4d
1
int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv) { BusChild *kid; I2CSlaveClass *sc; I2CNode *node; if (address == 0x00) { /* * This is a broadcast, the current_devs will be all the devices of the * bus. */ bus->broadcast = true; } QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { DeviceState *qdev = kid->child; I2CSlave *candidate = I2C_SLAVE(qdev); if ((candidate->address == address) || (bus->broadcast)) { node = g_malloc(sizeof(struct I2CNode)); node->elt = candidate; QLIST_INSERT_HEAD(&bus->current_devs, node, next); if (!bus->broadcast) { break; } } } if (QLIST_EMPTY(&bus->current_devs)) { return 1; } QLIST_FOREACH(node, &bus->current_devs, next) { sc = I2C_SLAVE_GET_CLASS(node->elt); /* If the bus is already busy, assume this is a repeated start condition. */ if (sc->event) { sc->event(node->elt, recv ? I2C_START_RECV : I2C_START_SEND); } } return 0; }
21,510
FFmpeg
e0c6cce44729d94e2a5507a4b6d031f23e8bd7b6
0
void ff_MPV_encode_init_x86(MpegEncContext *s) { int mm_flags = av_get_cpu_flags(); const int dct_algo = s->avctx->dct_algo; if (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX) { #if HAVE_MMX_INLINE if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) s->dct_quantize = dct_quantize_MMX; #endif #if HAVE_MMXEXT_INLINE if (mm_flags & AV_CPU_FLAG_MMXEXT && HAVE_MMXEXT) s->dct_quantize = dct_quantize_MMX2; #endif #if HAVE_SSE2_INLINE if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE2) s->dct_quantize = dct_quantize_SSE2; #endif #if HAVE_SSSE3_INLINE if (mm_flags & AV_CPU_FLAG_SSSE3) s->dct_quantize = dct_quantize_SSSE3; #endif } }
21,512
qemu
9c5ce8db2e5c2769ed2fd3d91928dd1853b5ce7c
0
static void smbios_build_type_1_fields(void) { smbios_maybe_add_str(1, offsetof(struct smbios_type_1, manufacturer_str), type1.manufacturer); smbios_maybe_add_str(1, offsetof(struct smbios_type_1, product_name_str), type1.product); smbios_maybe_add_str(1, offsetof(struct smbios_type_1, version_str), type1.version); smbios_maybe_add_str(1, offsetof(struct smbios_type_1, serial_number_str), type1.serial); smbios_maybe_add_str(1, offsetof(struct smbios_type_1, sku_number_str), type1.sku); smbios_maybe_add_str(1, offsetof(struct smbios_type_1, family_str), type1.family); if (qemu_uuid_set) { /* We don't encode the UUID in the "wire format" here because this * function is for legacy mode and needs to keep the guest ABI, and * because we don't know what's the SMBIOS version advertised by the * BIOS. */ smbios_add_field(1, offsetof(struct smbios_type_1, uuid), qemu_uuid, 16); } }
21,514
qemu
fb2ef7919bd7b125a2ff6cb70689a7ab93b9d05a
0
static inline int mirror_clip_sectors(MirrorBlockJob *s, int64_t sector_num, int nb_sectors) { return MIN(nb_sectors, s->bdev_length / BDRV_SECTOR_SIZE - sector_num); }
21,515
qemu
f0afa73164778570083504a185d7498884c68d65
0
static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) { uint32_t tag; uint32_t bufsize; uint32_t tot_len; size_t resplen; uint32_t tmp; value &= ~0xf; s->addr = value; tot_len = ldl_phys(&s->dma_as, value); /* @(addr + 4) : Buffer response code */ value = s->addr + 8; while (value + 8 <= s->addr + tot_len) { tag = ldl_phys(&s->dma_as, value); bufsize = ldl_phys(&s->dma_as, value + 4); /* @(value + 8) : Request/response indicator */ resplen = 0; switch (tag) { case 0x00000000: /* End tag */ break; case 0x00000001: /* Get firmware revision */ stl_phys(&s->dma_as, value + 12, 346337); resplen = 4; break; case 0x00010001: /* Get board model */ qemu_log_mask(LOG_UNIMP, "bcm2835_property: %x get board model NYI\n", tag); resplen = 4; break; case 0x00010002: /* Get board revision */ qemu_log_mask(LOG_UNIMP, "bcm2835_property: %x get board revision NYI\n", tag); resplen = 4; break; case 0x00010003: /* Get board MAC address */ resplen = sizeof(s->macaddr.a); dma_memory_write(&s->dma_as, value + 12, s->macaddr.a, resplen); break; case 0x00010004: /* Get board serial */ qemu_log_mask(LOG_UNIMP, "bcm2835_property: %x get board serial NYI\n", tag); resplen = 8; break; case 0x00010005: /* Get ARM memory */ /* base */ stl_phys(&s->dma_as, value + 12, 0); /* size */ stl_phys(&s->dma_as, value + 16, s->ram_size); resplen = 8; break; case 0x00028001: /* Set power state */ /* Assume that whatever device they asked for exists, * and we'll just claim we set it to the desired state */ tmp = ldl_phys(&s->dma_as, value + 16); stl_phys(&s->dma_as, value + 16, (tmp & 1)); resplen = 8; break; /* Clocks */ case 0x00030001: /* Get clock state */ stl_phys(&s->dma_as, value + 16, 0x1); resplen = 8; break; case 0x00038001: /* Set clock state */ qemu_log_mask(LOG_UNIMP, "bcm2835_property: %x set clock state NYI\n", tag); resplen = 8; break; case 0x00030002: /* Get clock rate */ case 0x00030004: /* Get max clock rate */ case 0x00030007: /* Get min clock rate */ switch (ldl_phys(&s->dma_as, value + 12)) { case 1: /* EMMC */ stl_phys(&s->dma_as, value + 16, 50000000); break; case 2: /* UART */ stl_phys(&s->dma_as, value + 16, 3000000); break; default: stl_phys(&s->dma_as, value + 16, 700000000); break; } resplen = 8; break; case 0x00038002: /* Set clock rate */ case 0x00038004: /* Set max clock rate */ case 0x00038007: /* Set min clock rate */ qemu_log_mask(LOG_UNIMP, "bcm2835_property: %x set clock rates NYI\n", tag); resplen = 8; break; /* Temperature */ case 0x00030006: /* Get temperature */ stl_phys(&s->dma_as, value + 16, 25000); resplen = 8; break; case 0x0003000A: /* Get max temperature */ stl_phys(&s->dma_as, value + 16, 99000); resplen = 8; break; case 0x00060001: /* Get DMA channels */ /* channels 2-5 */ stl_phys(&s->dma_as, value + 12, 0x003C); resplen = 4; break; case 0x00050001: /* Get command line */ resplen = 0; break; default: qemu_log_mask(LOG_GUEST_ERROR, "bcm2835_property: unhandled tag %08x\n", tag); break; } if (tag == 0) { break; } stl_phys(&s->dma_as, value + 8, (1 << 31) | resplen); value += bufsize + 12; } /* Buffer response code */ stl_phys(&s->dma_as, s->addr + 4, (1 << 31)); }
21,516
qemu
00e2ceae6c55bef40f5128a3e606f5c44351e0f9
0
ObjectClass *object_class_dynamic_cast(ObjectClass *class, const char *typename) { TypeImpl *target_type = type_get_by_name(typename); TypeImpl *type = class->type; ObjectClass *ret = NULL; if (type->num_interfaces && type_is_ancestor(target_type, type_interface)) { int found = 0; GSList *i; for (i = class->interfaces; i; i = i->next) { ObjectClass *target_class = i->data; if (type_is_ancestor(target_class->type, target_type)) { ret = target_class; found++; } } /* The match was ambiguous, don't allow a cast */ if (found > 1) { ret = NULL; } } else if (type_is_ancestor(type, target_type)) { ret = class; } return ret; }
21,517
qemu
d368ba4376b2c1c24175c74b3733b8fe64dbe8a6
0
static void sdhci_send_command(SDHCIState *s) { SDRequest request; uint8_t response[16]; int rlen; s->errintsts = 0; s->acmd12errsts = 0; request.cmd = s->cmdreg >> 8; request.arg = s->argument; DPRINT_L1("sending CMD%u ARG[0x%08x]\n", request.cmd, request.arg); rlen = sd_do_command(s->card, &request, response); if (s->cmdreg & SDHC_CMD_RESPONSE) { if (rlen == 4) { s->rspreg[0] = (response[0] << 24) | (response[1] << 16) | (response[2] << 8) | response[3]; s->rspreg[1] = s->rspreg[2] = s->rspreg[3] = 0; DPRINT_L1("Response: RSPREG[31..0]=0x%08x\n", s->rspreg[0]); } else if (rlen == 16) { s->rspreg[0] = (response[11] << 24) | (response[12] << 16) | (response[13] << 8) | response[14]; s->rspreg[1] = (response[7] << 24) | (response[8] << 16) | (response[9] << 8) | response[10]; s->rspreg[2] = (response[3] << 24) | (response[4] << 16) | (response[5] << 8) | response[6]; s->rspreg[3] = (response[0] << 16) | (response[1] << 8) | response[2]; DPRINT_L1("Response received:\n RSPREG[127..96]=0x%08x, RSPREG[95.." "64]=0x%08x,\n RSPREG[63..32]=0x%08x, RSPREG[31..0]=0x%08x\n", s->rspreg[3], s->rspreg[2], s->rspreg[1], s->rspreg[0]); } else { ERRPRINT("Timeout waiting for command response\n"); if (s->errintstsen & SDHC_EISEN_CMDTIMEOUT) { s->errintsts |= SDHC_EIS_CMDTIMEOUT; s->norintsts |= SDHC_NIS_ERR; } } if ((s->norintstsen & SDHC_NISEN_TRSCMP) && (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { s->norintsts |= SDHC_NIS_TRSCMP; } } else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |= SDHC_EIS_CMDIDX; s->norintsts |= SDHC_NIS_ERR; } if (s->norintstsen & SDHC_NISEN_CMDCMP) { s->norintsts |= SDHC_NIS_CMDCMP; } sdhci_update_irq(s); if (s->blksize && (s->cmdreg & SDHC_CMD_DATA_PRESENT)) { s->data_count = 0; sdhci_do_data_transfer(s); } }
21,518
qemu
4edebb0e8e14a5b934114b5ff74cb86437bb2532
0
static void ss5_init(int ram_size, int vga_ram_size, int boot_device, DisplayState *ds, const char **fd_filename, int snapshot, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { if (cpu_model == NULL) cpu_model = "Fujitsu MB86904"; sun4m_common_init(ram_size, boot_device, ds, kernel_filename, kernel_cmdline, initrd_filename, cpu_model, 0); }
21,519
qemu
435db4cf29b88b6612e30acda01cd18788dff458
0
const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); if (!opt) { const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name); if (desc && desc->def_value_str) { return desc->def_value_str; } } return opt ? opt->str : NULL; }
21,520
qemu
cd48d7e8f322cdb05692b023b168816ed6306fc4
0
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) { QEMUTimer **pt, *t; qemu_del_timer(ts); /* add the timer in the sorted list */ /* NOTE: this code must be signal safe because qemu_timer_expired() can be called from a signal. */ pt = &active_timers[ts->clock->type]; for(;;) { t = *pt; if (!t) break; if (t->expire_time > expire_time) break; pt = &t->next; } ts->expire_time = expire_time; ts->next = *pt; *pt = ts; /* Rearm if necessary */ if (pt == &active_timers[ts->clock->type]) { if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0) { qemu_rearm_alarm_timer(alarm_timer); } /* Interrupt execution to force deadline recalculation. */ if (use_icount) qemu_notify_event(); } }
21,521
qemu
9abc62f6445795522d1bf5bf17f642e44eaf032d
0
static void qemu_system_suspend(void) { pause_all_vcpus(); notifier_list_notify(&suspend_notifiers, NULL); runstate_set(RUN_STATE_SUSPENDED); monitor_protocol_event(QEVENT_SUSPEND, NULL); is_suspended = true; }
21,522
FFmpeg
13a099799e89a76eb921ca452e1b04a7a28a9855
0
static void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, const uint16_t *ubuf0, const uint16_t *ubuf1, const uint16_t *vbuf0, const uint16_t *vbuf1, const uint16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" "paddusb "RED_DITHER"(%5), %%mm5 \n\t" #endif WRITERGB16(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1b(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" "paddusb "RED_DITHER"(%5), %%mm5 \n\t" #endif WRITERGB16(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither) ); } }
21,523
qemu
c881e20eed4911ab6f8c674f2b1bf225a2cdde71
0
static void numa_node_parse_cpus(int nodenr, const char *cpus) { char *endptr; unsigned long long value, endvalue; value = strtoull(cpus, &endptr, 10); if (*endptr == '-') { endvalue = strtoull(endptr+1, &endptr, 10); } else { endvalue = value; } if (!(endvalue < MAX_CPUMASK_BITS)) { endvalue = MAX_CPUMASK_BITS - 1; fprintf(stderr, "A max of %d CPUs are supported in a guest\n", MAX_CPUMASK_BITS); } bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); }
21,524
qemu
e76d1798faa6d29f54c0930a034b67f3ecdb947d
0
static void icount_dummy_timer(void *opaque) { (void)opaque; }
21,525
qemu
d6478bc7e92db4669fac701d7bb8c51756b61d8a
0
static int gdb_set_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n) { if (n < 32) { env->fpr[n] = ldfq_p(mem_buf); return 8; } if (n == 32) { /* FPSCR not implemented */ return 4; } return 0; }
21,526
qemu
a5086f95421e43c7b9e1b28a111aae0be4848117
0
static inline void decode(DisasContext *dc) { uint32_t ir; int i; if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) { tcg_gen_debug_insn_start(dc->pc); } dc->ir = ir = ldl_code(dc->pc); LOG_DIS("%8.8x\t", dc->ir); /* try guessing 'empty' instruction memory, although it may be a valid * instruction sequence (eg. srui r0, r0, 0) */ if (dc->ir) { dc->nr_nops = 0; } else { LOG_DIS("nr_nops=%d\t", dc->nr_nops); dc->nr_nops++; if (dc->nr_nops > 4) { cpu_abort(dc->env, "fetching nop sequence\n"); } } dc->opcode = EXTRACT_FIELD(ir, 26, 31); dc->imm5 = EXTRACT_FIELD(ir, 0, 4); dc->imm16 = EXTRACT_FIELD(ir, 0, 15); dc->imm26 = EXTRACT_FIELD(ir, 0, 25); dc->csr = EXTRACT_FIELD(ir, 21, 25); dc->r0 = EXTRACT_FIELD(ir, 21, 25); dc->r1 = EXTRACT_FIELD(ir, 16, 20); dc->r2 = EXTRACT_FIELD(ir, 11, 15); /* bit 31 seems to indicate insn type. */ if (ir & (1 << 31)) { dc->format = OP_FMT_RR; } else { dc->format = OP_FMT_RI; } /* Large switch for all insns. */ for (i = 0; i < ARRAY_SIZE(decinfo); i++) { if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits) { decinfo[i].dec(dc); return; } } cpu_abort(dc->env, "unknown opcode 0x%02x\n", dc->opcode); }
21,527
qemu
cdb3081269347fd9271fd1b7a9df312e2953bdd9
0
void memory_region_init_iommu(MemoryRegion *mr, Object *owner, const MemoryRegionIOMMUOps *ops, const char *name, uint64_t size) { memory_region_init(mr, owner, name, size); mr->iommu_ops = ops, mr->terminates = true; /* then re-forwards */ notifier_list_init(&mr->iommu_notify); }
21,528
qemu
d0052339236072bbf08c1d600c0906126b1ab258
0
void helper_movl_drN_T0(CPUX86State *env, int reg, target_ulong t0) { #ifndef CONFIG_USER_ONLY if (reg < 4) { if (hw_breakpoint_enabled(env->dr[7], reg) && hw_breakpoint_type(env->dr[7], reg) != DR7_TYPE_IO_RW) { hw_breakpoint_remove(env, reg); env->dr[reg] = t0; hw_breakpoint_insert(env, reg); } else { env->dr[reg] = t0; } } else if (reg == 7) { cpu_x86_update_dr7(env, t0); } else { env->dr[reg] = t0; } #endif }
21,529
qemu
55e1819c509b3d9c10a54678b9c585bbda13889e
0
QDict *qdict_new(void) { QDict *qdict; qdict = g_malloc0(sizeof(*qdict)); QOBJECT_INIT(qdict, &qdict_type); return qdict; }
21,530
qemu
4341df8a83d6a528a1e2855735f87fc3aab42b70
0
int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *cluster_offset) { BDRVQcow2State *s = bs->opaque; unsigned int l2_index; uint64_t l1_index, l2_offset, *l2_table; int l1_bits, c; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; int ret; offset_in_cluster = offset_into_cluster(s, offset); bytes_needed = (uint64_t) *bytes + offset_in_cluster; l1_bits = s->l2_bits + s->cluster_bits; /* compute how many bytes there are between the start of the cluster * containing offset and the end of the l1 entry */ bytes_available = (1ULL << l1_bits) - (offset & ((1ULL << l1_bits) - 1)) + offset_in_cluster; if (bytes_needed > bytes_available) { bytes_needed = bytes_available; } *cluster_offset = 0; /* seek to the l2 offset in the l1 table */ l1_index = offset >> l1_bits; if (l1_index >= s->l1_size) { ret = QCOW2_CLUSTER_UNALLOCATED; goto out; } l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK; if (!l2_offset) { ret = QCOW2_CLUSTER_UNALLOCATED; goto out; } if (offset_into_cluster(s, l2_offset)) { qcow2_signal_corruption(bs, true, -1, -1, "L2 table offset %#" PRIx64 " unaligned (L1 index: %#" PRIx64 ")", l2_offset, l1_index); return -EIO; } /* load the l2 table in memory */ ret = l2_load(bs, l2_offset, &l2_table); if (ret < 0) { return ret; } /* find the cluster offset for the given disk offset */ l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1); *cluster_offset = be64_to_cpu(l2_table[l2_index]); nb_clusters = size_to_clusters(s, bytes_needed); /* bytes_needed <= *bytes + offset_in_cluster, both of which are unsigned * integers; the minimum cluster size is 512, so this assertion is always * true */ assert(nb_clusters <= INT_MAX); ret = qcow2_get_cluster_type(*cluster_offset); switch (ret) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters can only be processed one by one */ c = 1; *cluster_offset &= L2E_COMPRESSED_OFFSET_SIZE_MASK; break; case QCOW2_CLUSTER_ZERO: if (s->qcow_version < 3) { qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found" " in pre-v3 image (L2 offset: %#" PRIx64 ", L2 index: %#x)", l2_offset, l2_index); ret = -EIO; goto fail; } c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index], QCOW2_CLUSTER_ZERO); *cluster_offset = 0; break; case QCOW2_CLUSTER_UNALLOCATED: /* how many empty clusters ? */ c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index], QCOW2_CLUSTER_UNALLOCATED); *cluster_offset = 0; break; case QCOW2_CLUSTER_NORMAL: /* how many allocated clusters ? */ c = count_contiguous_clusters(nb_clusters, s->cluster_size, &l2_table[l2_index], QCOW_OFLAG_ZERO); *cluster_offset &= L2E_OFFSET_MASK; if (offset_into_cluster(s, *cluster_offset)) { qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset %#" PRIx64 " unaligned (L2 offset: %#" PRIx64 ", L2 index: %#x)", *cluster_offset, l2_offset, l2_index); ret = -EIO; goto fail; } break; default: abort(); } qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); bytes_available = (int64_t)c * s->cluster_size; out: if (bytes_available > bytes_needed) { bytes_available = bytes_needed; } /* bytes_available <= bytes_needed <= *bytes + offset_in_cluster; * subtracting offset_in_cluster will therefore definitely yield something * not exceeding UINT_MAX */ assert(bytes_available - offset_in_cluster <= UINT_MAX); *bytes = bytes_available - offset_in_cluster; return ret; fail: qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table); return ret; }
21,532
qemu
0ae18ceeaaa2c1749e742c4b112f6c3bf0896408
0
mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { char buf[1024]; unsigned long bios_offset; CPUState *env; int bios_size; /* Init CPUs. */ if (cpu_model == NULL) { #ifdef TARGET_MIPS64 cpu_model = "5Kf"; #else cpu_model = "24Kf"; #endif } env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } qemu_register_reset(main_cpu_reset, env); /* Allocate RAM. */ cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); /* Load a BIOS / boot exception handler image. */ bios_offset = ram_size + vga_ram_size; if (bios_name == NULL) bios_name = BIOS_FILENAME; snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); bios_size = load_image(buf, phys_ram_base + bios_offset); if ((bios_size < 0 || bios_size > BIOS_SIZE) && !kernel_filename) { /* Bail out if we have neither a kernel image nor boot vector code. */ fprintf(stderr, "qemu: Could not load MIPS bios '%s', and no -kernel argument was specified\n", buf); exit(1); } else { /* Map the BIOS / boot exception handler. */ cpu_register_physical_memory(0x1fc00000LL, bios_size, bios_offset | IO_MEM_ROM); /* We have a boot vector start address. */ env->active_tc.PC = (target_long)(int32_t)0xbfc00000; } if (kernel_filename) { loaderparams.ram_size = ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename; load_kernel(env); } /* Init CPU internal devices. */ cpu_mips_irq_init_cpu(env); cpu_mips_clock_init(env); /* Register 64 KB of ISA IO space at 0x1fd00000. */ isa_mmio_init(0x1fd00000, 0x00010000); /* A single 16450 sits at offset 0x3f8. It is attached to MIPS CPU INT2, which is interrupt 4. */ if (serial_hds[0]) serial_init(0x3f8, env->irq[4], 115200, serial_hds[0]); if (nd_table[0].vlan) { if (nd_table[0].model == NULL || strcmp(nd_table[0].model, "mipsnet") == 0) { /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ mipsnet_init(0x4200, env->irq[2], &nd_table[0]); } else if (strcmp(nd_table[0].model, "?") == 0) { fprintf(stderr, "qemu: Supported NICs: mipsnet\n"); exit (1); } else { fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model); exit (1); } } }
21,533
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
0
static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) { #if COMPILE_TEMPLATE_MMX __asm__ volatile( "mov %0, %%"REG_a" \n\t" "1: \n\t" "movq (%1, %%"REG_a",2), %%mm0 \n\t" "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" "movq (%2, %%"REG_a",2), %%mm2 \n\t" "movq 8(%2, %%"REG_a",2), %%mm3 \n\t" "psrlw $8, %%mm0 \n\t" "psrlw $8, %%mm1 \n\t" "psrlw $8, %%mm2 \n\t" "psrlw $8, %%mm3 \n\t" "packuswb %%mm1, %%mm0 \n\t" "packuswb %%mm3, %%mm2 \n\t" "movq %%mm0, (%3, %%"REG_a") \n\t" "movq %%mm2, (%4, %%"REG_a") \n\t" "add $8, %%"REG_a" \n\t" " js 1b \n\t" : : "g" ((x86_reg)-width), "r" (src1+width*2), "r" (src2+width*2), "r" (dstU+width), "r" (dstV+width) : "%"REG_a ); #else int i; // FIXME I don't think this code is right for YUV444/422, since then h is not subsampled so // we need to skip each second pixel. Same for BEToUV. for (i=0; i<width; i++) { dstU[i]= src1[2*i + 1]; dstV[i]= src2[2*i + 1]; } #endif }
21,534
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static target_phys_addr_t intel_hda_addr(uint32_t lbase, uint32_t ubase) { target_phys_addr_t addr; addr = ((uint64_t)ubase << 32) | lbase; return addr; }
21,535
qemu
298a1665a2800f7264e483c2dd1f551574243a2f
0
static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs, Error **errp) { Error *local_err = NULL; BlockMeasureInfo *info; uint64_t required = 0; /* bytes that contribute to required size */ uint64_t virtual_size; /* disk size as seen by guest */ uint64_t refcount_bits; uint64_t l2_tables; size_t cluster_size; int version; char *optstr; PreallocMode prealloc; bool has_backing_file; /* Parse image creation options */ cluster_size = qcow2_opt_get_cluster_size_del(opts, &local_err); if (local_err) { goto err; } version = qcow2_opt_get_version_del(opts, &local_err); if (local_err) { goto err; } refcount_bits = qcow2_opt_get_refcount_bits_del(opts, version, &local_err); if (local_err) { goto err; } optstr = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); prealloc = qapi_enum_parse(&PreallocMode_lookup, optstr, PREALLOC_MODE_OFF, &local_err); g_free(optstr); if (local_err) { goto err; } optstr = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); has_backing_file = !!optstr; g_free(optstr); virtual_size = align_offset(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), cluster_size); /* Check that virtual disk size is valid */ l2_tables = DIV_ROUND_UP(virtual_size / cluster_size, cluster_size / sizeof(uint64_t)); if (l2_tables * sizeof(uint64_t) > QCOW_MAX_L1_SIZE) { error_setg(&local_err, "The image size is too large " "(try using a larger cluster size)"); goto err; } /* Account for input image */ if (in_bs) { int64_t ssize = bdrv_getlength(in_bs); if (ssize < 0) { error_setg_errno(&local_err, -ssize, "Unable to get image virtual_size"); goto err; } virtual_size = align_offset(ssize, cluster_size); if (has_backing_file) { /* We don't how much of the backing chain is shared by the input * image and the new image file. In the worst case the new image's * backing file has nothing in common with the input image. Be * conservative and assume all clusters need to be written. */ required = virtual_size; } else { int64_t offset; int pnum = 0; for (offset = 0; offset < ssize; offset += pnum * BDRV_SECTOR_SIZE) { int nb_sectors = MIN(ssize - offset, BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR_SIZE; BlockDriverState *file; int64_t ret; ret = bdrv_get_block_status_above(in_bs, NULL, offset >> BDRV_SECTOR_BITS, nb_sectors, &pnum, &file); if (ret < 0) { error_setg_errno(&local_err, -ret, "Unable to get block status"); goto err; } if (ret & BDRV_BLOCK_ZERO) { /* Skip zero regions (safe with no backing file) */ } else if ((ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) == (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) { /* Extend pnum to end of cluster for next iteration */ pnum = (ROUND_UP(offset + pnum * BDRV_SECTOR_SIZE, cluster_size) - offset) >> BDRV_SECTOR_BITS; /* Count clusters we've seen */ required += offset % cluster_size + pnum * BDRV_SECTOR_SIZE; } } } } /* Take into account preallocation. Nothing special is needed for * PREALLOC_MODE_METADATA since metadata is always counted. */ if (prealloc == PREALLOC_MODE_FULL || prealloc == PREALLOC_MODE_FALLOC) { required = virtual_size; } info = g_new(BlockMeasureInfo, 1); info->fully_allocated = qcow2_calc_prealloc_size(virtual_size, cluster_size, ctz32(refcount_bits)); /* Remove data clusters that are not required. This overestimates the * required size because metadata needed for the fully allocated file is * still counted. */ info->required = info->fully_allocated - virtual_size + required; return info; err: error_propagate(errp, local_err); return NULL; }
21,536
qemu
3c529d935923a70519557d420db1d5a09a65086a
0
static void raw_aio_cancel(BlockDriverAIOCB *blockacb) { int ret; RawAIOCB *acb = (RawAIOCB *)blockacb; RawAIOCB **pacb; ret = aio_cancel(acb->aiocb.aio_fildes, &acb->aiocb); if (ret == AIO_NOTCANCELED) { /* fail safe: if the aio could not be canceled, we wait for it */ while (aio_error(&acb->aiocb) == EINPROGRESS); } /* remove the callback from the queue */ pacb = &posix_aio_state->first_aio; for(;;) { if (*pacb == NULL) { break; } else if (*pacb == acb) { *pacb = acb->next; raw_fd_pool_put(acb); qemu_aio_release(acb); break; } pacb = &acb->next; } }
21,537
qemu
64c7b9d8e07936383db181876b59c597d6a1ff69
0
void check_file_fixed_eof_mmaps(void) { char *addr; char *cp; unsigned int *p1; uintptr_t p; int i; /* Find a suitable address to start with. */ addr = mmap(NULL, pagesize * 44, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); fprintf (stderr, "%s addr=%p", __func__, (void *)addr); fail_unless (addr != MAP_FAILED); for (i = 0; i < 0x10; i++) { /* Create submaps within our unfixed map. */ p1 = mmap(addr, pagesize, PROT_READ, MAP_PRIVATE | MAP_FIXED, test_fd, (test_fsize - sizeof *p1) & ~pagemask); fail_unless (p1 != MAP_FAILED); /* Make sure we get pages aligned with the pagesize. The target expects this. */ p = (uintptr_t) p1; fail_unless ((p & pagemask) == 0); /* Verify that the file maps was made correctly. */ fail_unless (p1[(test_fsize & pagemask) / sizeof *p1 - 1] == ((test_fsize - sizeof *p1) / sizeof *p1)); /* Verify that the end of page is accessable and zeroed. */ cp = (void *)p1; fail_unless (cp[pagesize - 4] == 0); munmap (p1, pagesize); addr += pagesize; } fprintf (stderr, " passed\n"); }
21,539
qemu
f53a829bb9ef14be800556cbc02d8b20fc1050a7
0
static void nbd_attach_aio_context(BlockDriverState *bs, AioContext *new_context) { BDRVNBDState *s = bs->opaque; nbd_client_session_attach_aio_context(&s->client, new_context); }
21,540
qemu
2860e3eb9695d7596507e82b98074937fbd7fa18
0
void bmdma_cmd_writeb(void *opaque, uint32_t addr, uint32_t val) { BMDMAState *bm = opaque; #ifdef DEBUG_IDE printf("%s: 0x%08x\n", __func__, val); #endif /* Ignore writes to SSBM if it keeps the old value */ if ((val & BM_CMD_START) != (bm->cmd & BM_CMD_START)) { if (!(val & BM_CMD_START)) { /* * We can't cancel Scatter Gather DMA in the middle of the * operation or a partial (not full) DMA transfer would reach * the storage so we wait for completion instead (we beahve * like if the DMA was completed by the time the guest trying * to cancel dma with bmdma_cmd_writeb with BM_CMD_START not * set). * * In the future we'll be able to safely cancel the I/O if the * whole DMA operation will be submitted to disk with a single * aio operation with preadv/pwritev. */ if (bm->bus->dma->aiocb) { qemu_aio_flush(); #ifdef DEBUG_IDE if (bm->bus->dma->aiocb) printf("ide_dma_cancel: aiocb still pending\n"); if (bm->status & BM_STATUS_DMAING) printf("ide_dma_cancel: BM_STATUS_DMAING still pending\n"); #endif } } else { bm->cur_addr = bm->addr; if (!(bm->status & BM_STATUS_DMAING)) { bm->status |= BM_STATUS_DMAING; /* start dma transfer if possible */ if (bm->dma_cb) bm->dma_cb(bmdma_active_if(bm), 0); } } } bm->cmd = val & 0x09; }
21,541
qemu
909a196d2754388d3b15a34b688095c655792124
0
uint32_t qemu_devtree_get_phandle(void *fdt, const char *path) { uint32_t r; r = fdt_get_phandle(fdt, findnode_nofail(fdt, path)); if (r <= 0) { fprintf(stderr, "%s: Couldn't get phandle for %s: %s\n", __func__, path, fdt_strerror(r)); exit(1); } return r; }
21,542
qemu
bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884
0
static char *SocketAddress_to_str(const char *prefix, SocketAddressLegacy *addr, bool is_listen, bool is_telnet) { switch (addr->type) { case SOCKET_ADDRESS_LEGACY_KIND_INET: return g_strdup_printf("%s%s:%s:%s%s", prefix, is_telnet ? "telnet" : "tcp", addr->u.inet.data->host, addr->u.inet.data->port, is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_LEGACY_KIND_UNIX: return g_strdup_printf("%sunix:%s%s", prefix, addr->u.q_unix.data->path, is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_LEGACY_KIND_FD: return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.data->str, is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: return g_strdup_printf("%svsock:%s:%s", prefix, addr->u.vsock.data->cid, addr->u.vsock.data->port); default: abort(); } }
21,543
qemu
3ebcc707d20643e9fefa24a4396de577b1163755
0
void handle_vm86_fault(CPUX86State *env) { TaskState *ts = env->opaque; uint8_t *csp, *pc, *ssp; unsigned int ip, sp, newflags, newip, newcs, opcode, intno; int data32, pref_done; csp = (uint8_t *)(env->segs[R_CS] << 4); ip = env->eip & 0xffff; pc = csp + ip; ssp = (uint8_t *)(env->segs[R_SS] << 4); sp = env->regs[R_ESP] & 0xffff; #if defined(DEBUG_VM86) fprintf(logfile, "VM86 exception %04x:%08x %02x %02x\n", env->segs[R_CS], env->eip, pc[0], pc[1]); #endif data32 = 0; pref_done = 0; do { opcode = csp[ip]; ADD16(ip, 1); switch (opcode) { case 0x66: /* 32-bit data */ data32=1; break; case 0x67: /* 32-bit address */ break; case 0x2e: /* CS */ break; case 0x3e: /* DS */ break; case 0x26: /* ES */ break; case 0x36: /* SS */ break; case 0x65: /* GS */ break; case 0x64: /* FS */ break; case 0xf2: /* repnz */ break; case 0xf3: /* rep */ break; default: pref_done = 1; } } while (!pref_done); /* VM86 mode */ switch(opcode) { case 0x9c: /* pushf */ ADD16(env->eip, 2); if (data32) { vm_putl(ssp, sp - 4, get_vflags(env)); ADD16(env->regs[R_ESP], -4); } else { vm_putw(ssp, sp - 2, get_vflags(env)); ADD16(env->regs[R_ESP], -2); } env->eip = ip; VM86_FAULT_RETURN; case 0x9d: /* popf */ if (data32) { newflags = vm_getl(ssp, sp); ADD16(env->regs[R_ESP], 4); } else { newflags = vm_getw(ssp, sp); ADD16(env->regs[R_ESP], 2); } env->eip = ip; CHECK_IF_IN_TRAP(); if (data32) { if (set_vflags_long(newflags, env)) return; } else { if (set_vflags_short(newflags, env)) return; } VM86_FAULT_RETURN; case 0xcd: /* int */ intno = csp[ip]; ADD16(ip, 1); env->eip = ip; if (ts->vm86plus.vm86plus.flags & TARGET_vm86dbg_active) { if ( (ts->vm86plus.vm86plus.vm86dbg_intxxtab[intno >> 3] >> (intno &7)) & 1) { return_to_32bit(env, TARGET_VM86_INTx + (intno << 8)); return; } } do_int(env, intno); break; case 0xcf: /* iret */ if (data32) { newip = vm_getl(ssp, sp) & 0xffff; newcs = vm_getl(ssp, sp + 4) & 0xffff; newflags = vm_getl(ssp, sp + 8); ADD16(env->regs[R_ESP], 12); } else { newip = vm_getw(ssp, sp); newcs = vm_getw(ssp, sp + 2); newflags = vm_getw(ssp, sp + 4); ADD16(env->regs[R_ESP], 6); } env->eip = newip; cpu_x86_load_seg(env, R_CS, newcs); CHECK_IF_IN_TRAP(); if (data32) { if (set_vflags_long(newflags, env)) return; } else { if (set_vflags_short(newflags, env)) return; } VM86_FAULT_RETURN; case 0xfa: /* cli */ env->eip = ip; clear_IF(env); VM86_FAULT_RETURN; case 0xfb: /* sti */ env->eip = ip; if (set_IF(env)) return; VM86_FAULT_RETURN; default: /* real VM86 GPF exception */ return_to_32bit(env, TARGET_VM86_UNKNOWN); break; } }
21,544
qemu
8150847061f8d2606101bfff77cc6ec86b081ab0
0
static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value, MemTxAttrs attrs) { switch (offset) { case 0x00: /* Control */ gic_set_cpu_control(s, cpu, value, attrs); break; case 0x04: /* Priority mask */ s->priority_mask[cpu] = (value & 0xff); break; case 0x08: /* Binary Point */ if (s->security_extn && !attrs.secure) { s->abpr[cpu] = MAX(value & 0x7, GIC_MIN_ABPR); } else { s->bpr[cpu] = MAX(value & 0x7, GIC_MIN_BPR); } break; case 0x10: /* End Of Interrupt */ gic_complete_irq(s, cpu, value & 0x3ff); return MEMTX_OK; case 0x1c: /* Aliased Binary Point */ if (!gic_has_groups(s) || (s->security_extn && !attrs.secure)) { /* unimplemented, or NS access: RAZ/WI */ return MEMTX_OK; } else { s->abpr[cpu] = MAX(value & 0x7, GIC_MIN_ABPR); } break; case 0xd0: case 0xd4: case 0xd8: case 0xdc: qemu_log_mask(LOG_UNIMP, "Writing APR not implemented\n"); break; default: qemu_log_mask(LOG_GUEST_ERROR, "gic_cpu_write: Bad offset %x\n", (int)offset); return MEMTX_ERROR; } gic_update(s); return MEMTX_OK; }
21,545
qemu
25c4d9cc845fb58f624dae8c0f690e20c70e7a1d
0
static int op_to_movi(int op) { switch (op_bits(op)) { case 32: return INDEX_op_movi_i32; #if TCG_TARGET_REG_BITS == 64 case 64: return INDEX_op_movi_i64; #endif default: fprintf(stderr, "op_to_movi: unexpected return value of " "function op_bits.\n"); tcg_abort(); } }
21,546
qemu
ad674e53b5cce265fadafbde2c6a4f190345cd00
0
static void dbdma_end(DBDMA_io *io) { DBDMA_channel *ch = io->channel; dbdma_cmd *current = &ch->current; if (conditional_wait(ch)) goto wait; current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS])); current->res_count = cpu_to_le16(be32_to_cpu(io->len)); dbdma_cmdptr_save(ch); if (io->is_last) ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH); conditional_interrupt(ch); conditional_branch(ch); wait: ch->processing = 0; if ((ch->regs[DBDMA_STATUS] & cpu_to_be32(RUN)) && (ch->regs[DBDMA_STATUS] & cpu_to_be32(ACTIVE))) channel_run(ch); }
21,547
qemu
37d1e4d9bfac846a1331375aab3d13b54a048c01
0
static void nfs_process_read(void *arg) { NFSClient *client = arg; aio_context_acquire(client->aio_context); nfs_service(client->context, POLLIN); nfs_set_events(client); aio_context_release(client->aio_context); }
21,548
qemu
fa7d1867578b6a1afc39d4ece8629a1e92baddd7
0
int qemu_init_main_loop(void) { int ret; qemu_init_sigbus(); ret = qemu_signal_init(); if (ret) { return ret; } /* Note eventfd must be drained before signalfd handlers run */ ret = qemu_event_init(); if (ret) { return ret; } qemu_cond_init(&qemu_cpu_cond); qemu_cond_init(&qemu_system_cond); qemu_cond_init(&qemu_pause_cond); qemu_cond_init(&qemu_work_cond); qemu_cond_init(&qemu_io_proceeded_cond); qemu_mutex_init(&qemu_global_mutex); qemu_mutex_lock(&qemu_global_mutex); qemu_thread_get_self(&io_thread); return 0; }
21,550
qemu
5858dd1801883309bdd208d72ddb81c4e9fee30c
0
static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only) { /* should be the case, see cirrus_bitblt_start */ assert(s->cirrus_blt_width > 0); assert(s->cirrus_blt_height > 0); if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) { return true; } if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch, s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) { return true; } if (dst_only) { return false; } if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch, s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) { return true; } return false; }
21,551
qemu
6acbe4c6f18e7de00481ff30574262b58526de45
0
static void virtio_pci_register_devices(void) { type_register_static(&virtio_blk_info); type_register_static_alias(&virtio_blk_info, "virtio-blk"); type_register_static(&virtio_net_info); type_register_static_alias(&virtio_net_info, "virtio-net"); type_register_static(&virtio_serial_info); type_register_static_alias(&virtio_serial_info, "virtio-serial"); type_register_static(&virtio_balloon_info); type_register_static_alias(&virtio_balloon_info, "virtio-balloon"); }
21,552
qemu
45db7ba681ede57113a67499840e69ee586bcdf2
0
static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr, uint64_t *data, unsigned size, MemTxAttrs attrs) { NVICState *s = (NVICState *)opaque; uint32_t offset = addr; unsigned i, startvec, end; uint32_t val; if (attrs.user && !nvic_user_access_ok(s, addr)) { /* Generate BusFault for unprivileged accesses */ return MEMTX_ERROR; } switch (offset) { /* reads of set and clear both return the status */ case 0x100 ... 0x13f: /* NVIC Set enable */ offset += 0x80; /* fall through */ case 0x180 ... 0x1bf: /* NVIC Clear enable */ val = 0; startvec = offset - 0x180 + NVIC_FIRST_IRQ; /* vector # */ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { if (s->vectors[startvec + i].enabled) { val |= (1 << i); } } break; case 0x200 ... 0x23f: /* NVIC Set pend */ offset += 0x80; /* fall through */ case 0x280 ... 0x2bf: /* NVIC Clear pend */ val = 0; startvec = offset - 0x280 + NVIC_FIRST_IRQ; /* vector # */ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { if (s->vectors[startvec + i].pending) { val |= (1 << i); } } break; case 0x300 ... 0x33f: /* NVIC Active */ val = 0; startvec = offset - 0x300 + NVIC_FIRST_IRQ; /* vector # */ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { if (s->vectors[startvec + i].active) { val |= (1 << i); } } break; case 0x400 ... 0x5ef: /* NVIC Priority */ val = 0; startvec = offset - 0x400 + NVIC_FIRST_IRQ; /* vector # */ for (i = 0; i < size && startvec + i < s->num_irq; i++) { val |= s->vectors[startvec + i].prio << (8 * i); } break; case 0xd18 ... 0xd23: /* System Handler Priority. */ val = 0; for (i = 0; i < size; i++) { val |= s->vectors[(offset - 0xd14) + i].prio << (i * 8); } break; case 0xfe0 ... 0xfff: /* ID. */ if (offset & 3) { val = 0; } else { val = nvic_id[(offset - 0xfe0) >> 2]; } break; default: if (size == 4) { val = nvic_readl(s, offset); } else { qemu_log_mask(LOG_GUEST_ERROR, "NVIC: Bad read of size %d at offset 0x%x\n", size, offset); val = 0; } } trace_nvic_sysreg_read(addr, val, size); *data = val; return MEMTX_OK; }
21,553
qemu
d045c466d9e62b4321fadf586d024d54ddfd8bd4
0
coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) { IscsiLun *iscsilun = bs->opaque; struct IscsiTask iTask; struct unmap_list list; if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { return -ENOTSUP; } if (!iscsilun->lbp.lbpu) { /* UNMAP is not supported by the target */ return 0; } list.lba = offset / iscsilun->block_size; list.num = count / iscsilun->block_size; iscsi_co_init_iscsitask(iscsilun, &iTask); retry: if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1, iscsi_co_generic_cb, &iTask) == NULL) { return -ENOMEM; } while (!iTask.complete) { iscsi_set_events(iscsilun); qemu_coroutine_yield(); } if (iTask.task != NULL) { scsi_free_scsi_task(iTask.task); iTask.task = NULL; } if (iTask.do_retry) { iTask.complete = 0; goto retry; } if (iTask.status == SCSI_STATUS_CHECK_CONDITION) { /* the target might fail with a check condition if it is not happy with the alignment of the UNMAP request we silently fail in this case */ return 0; } if (iTask.status != SCSI_STATUS_GOOD) { return iTask.err_code; } iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, count >> BDRV_SECTOR_BITS); return 0; }
21,554
qemu
30fd3e27907dfd1c0c66cc1339657af1a2ce1d4b
0
static ssize_t qio_channel_command_writev(QIOChannel *ioc, const struct iovec *iov, size_t niov, int *fds, size_t nfds, Error **errp) { QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); ssize_t ret; retry: ret = writev(cioc->writefd, iov, niov); if (ret <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { return QIO_CHANNEL_ERR_BLOCK; } if (errno == EINTR) { goto retry; } error_setg_errno(errp, errno, "%s", "Unable to write to command"); return -1; } return ret; }
21,556
qemu
364031f17932814484657e5551ba12957d993d7e
0
static void v9fs_synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf) { stbuf->st_dev = 0; stbuf->st_ino = node->attr->inode; stbuf->st_mode = node->attr->mode; stbuf->st_nlink = node->attr->nlink; stbuf->st_uid = 0; stbuf->st_gid = 0; stbuf->st_rdev = 0; stbuf->st_size = 0; stbuf->st_blksize = 0; stbuf->st_blocks = 0; stbuf->st_atime = 0; stbuf->st_mtime = 0; stbuf->st_ctime = 0; }
21,557
qemu
72cf2d4f0e181d0d3a3122e04129c58a95da713e
0
void cpu_exec_init(CPUState *env) { CPUState **penv; int cpu_index; #if defined(CONFIG_USER_ONLY) cpu_list_lock(); #endif env->next_cpu = NULL; penv = &first_cpu; cpu_index = 0; while (*penv != NULL) { penv = &(*penv)->next_cpu; cpu_index++; } env->cpu_index = cpu_index; env->numa_node = 0; TAILQ_INIT(&env->breakpoints); TAILQ_INIT(&env->watchpoints); *penv = env; #if defined(CONFIG_USER_ONLY) cpu_list_unlock(); #endif #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY) vmstate_register(cpu_index, &vmstate_cpu_common, env); register_savevm("cpu", cpu_index, CPU_SAVE_VERSION, cpu_save, cpu_load, env); #endif }
21,558
qemu
d368ba4376b2c1c24175c74b3733b8fe64dbe8a6
0
static void sdhci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); SDHCIClass *k = SDHCI_CLASS(klass); dc->vmsd = &sdhci_vmstate; dc->props = sdhci_properties; dc->reset = sdhci_generic_reset; dc->realize = sdhci_realize; k->reset = sdhci_reset; k->mem_read = sdhci_read; k->mem_write = sdhci_write; k->send_command = sdhci_send_command; k->can_issue_command = sdhci_can_issue_command; k->data_transfer = sdhci_data_transfer; k->end_data_transfer = sdhci_end_transfer; k->do_sdma_single = sdhci_sdma_transfer_single_block; k->do_sdma_multi = sdhci_sdma_transfer_multi_blocks; k->do_adma = sdhci_do_adma; k->read_block_from_card = sdhci_read_block_from_card; k->write_block_to_card = sdhci_write_block_to_card; k->bdata_read = sdhci_read_dataport; k->bdata_write = sdhci_write_dataport; }
21,559
qemu
caae6c961107c4c55731a86572f9a1f53837636b
0
static void ppc_heathrow_init(MachineState *machine) { ram_addr_t ram_size = machine->ram_size; const char *cpu_model = machine->cpu_model; const char *kernel_filename = machine->kernel_filename; const char *kernel_cmdline = machine->kernel_cmdline; const char *initrd_filename = machine->initrd_filename; const char *boot_device = machine->boot_order; MemoryRegion *sysmem = get_system_memory(); PowerPCCPU *cpu = NULL; CPUPPCState *env = NULL; char *filename; qemu_irq *pic, **heathrow_irqs; int linux_boot, i; MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *bios = g_new(MemoryRegion, 1); MemoryRegion *isa = g_new(MemoryRegion, 1); uint32_t kernel_base, initrd_base, cmdline_base = 0; int32_t kernel_size, initrd_size; PCIBus *pci_bus; PCIDevice *macio; MACIOIDEState *macio_ide; DeviceState *dev; BusState *adb_bus; int bios_size; MemoryRegion *pic_mem; MemoryRegion *escc_mem, *escc_bar = g_new(MemoryRegion, 1); uint16_t ppc_boot_device; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; void *fw_cfg; linux_boot = (kernel_filename != NULL); /* init CPUs */ if (cpu_model == NULL) cpu_model = "G3"; for (i = 0; i < smp_cpus; i++) { cpu = cpu_ppc_init(cpu_model); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } env = &cpu->env; /* Set time-base frequency to 16.6 Mhz */ cpu_ppc_tb_init(env, TBFREQ); qemu_register_reset(ppc_heathrow_reset, cpu); } /* allocate RAM */ if (ram_size > (2047 << 20)) { fprintf(stderr, "qemu: Too much memory for this machine: %d MB, maximum 2047 MB\n", ((unsigned int)ram_size / (1 << 20))); exit(1); } memory_region_allocate_system_memory(ram, NULL, "ppc_heathrow.ram", ram_size); memory_region_add_subregion(sysmem, 0, ram); /* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE); vmstate_register_ram_global(bios); if (bios_name == NULL) bios_name = PROM_FILENAME; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); memory_region_set_readonly(bios, true); memory_region_add_subregion(sysmem, PROM_ADDR, bios); /* Load OpenBIOS (ELF) */ if (filename) { bios_size = load_elf(filename, 0, NULL, NULL, NULL, NULL, 1, ELF_MACHINE, 0); g_free(filename); } else { bios_size = -1; } if (bios_size < 0 || bios_size > BIOS_SIZE) { hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name); exit(1); } if (linux_boot) { uint64_t lowaddr = 0; int bswap_needed; #ifdef BSWAP_NEEDED bswap_needed = 1; #else bswap_needed = 0; #endif kernel_base = KERNEL_LOAD_ADDR; kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL, NULL, &lowaddr, NULL, 1, ELF_MACHINE, 0); if (kernel_size < 0) kernel_size = load_aout(kernel_filename, kernel_base, ram_size - kernel_base, bswap_needed, TARGET_PAGE_SIZE); if (kernel_size < 0) kernel_size = load_image_targphys(kernel_filename, kernel_base, ram_size - kernel_base); if (kernel_size < 0) { hw_error("qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } /* load initrd */ if (initrd_filename) { initrd_base = round_page(kernel_base + kernel_size + KERNEL_GAP); initrd_size = load_image_targphys(initrd_filename, initrd_base, ram_size - initrd_base); if (initrd_size < 0) { hw_error("qemu: could not load initial ram disk '%s'\n", initrd_filename); exit(1); } cmdline_base = round_page(initrd_base + initrd_size); } else { initrd_base = 0; initrd_size = 0; cmdline_base = round_page(kernel_base + kernel_size + KERNEL_GAP); } ppc_boot_device = 'm'; } else { kernel_base = 0; kernel_size = 0; initrd_base = 0; initrd_size = 0; ppc_boot_device = '\0'; for (i = 0; boot_device[i] != '\0'; i++) { /* TOFIX: for now, the second IDE channel is not properly * used by OHW. The Mac floppy disk are not emulated. * For now, OHW cannot boot from the network. */ #if 0 if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { ppc_boot_device = boot_device[i]; break; } #else if (boot_device[i] >= 'c' && boot_device[i] <= 'd') { ppc_boot_device = boot_device[i]; break; } #endif } if (ppc_boot_device == '\0') { fprintf(stderr, "No valid boot device for G3 Beige machine\n"); exit(1); } } /* Register 2 MB of ISA IO space */ memory_region_init_alias(isa, NULL, "isa_mmio", get_system_io(), 0, 0x00200000); memory_region_add_subregion(sysmem, 0xfe000000, isa); /* XXX: we register only 1 output pin for heathrow PIC */ heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *)); heathrow_irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * 1); /* Connect the heathrow PIC outputs to the 6xx bus */ for (i = 0; i < smp_cpus; i++) { switch (PPC_INPUT(env)) { case PPC_FLAGS_INPUT_6xx: heathrow_irqs[i] = heathrow_irqs[0] + (i * 1); heathrow_irqs[i][0] = ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; break; default: hw_error("Bus model not supported on OldWorld Mac machine\n"); } } /* init basic PC hardware */ if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { hw_error("Only 6xx bus is supported on heathrow machine\n"); } pic = heathrow_pic_init(&pic_mem, 1, heathrow_irqs); pci_bus = pci_grackle_init(0xfec00000, pic, get_system_memory(), get_system_io()); pci_vga_init(pci_bus); escc_mem = escc_init(0, pic[0x0f], pic[0x10], serial_hds[0], serial_hds[1], ESCC_CLOCK, 4); memory_region_init_alias(escc_bar, NULL, "escc-bar", escc_mem, 0, memory_region_size(escc_mem)); for(i = 0; i < nb_nics; i++) pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); ide_drive_get(hd, MAX_IDE_BUS); macio = pci_create(pci_bus, -1, TYPE_OLDWORLD_MACIO); dev = DEVICE(macio); qdev_connect_gpio_out(dev, 0, pic[0x12]); /* CUDA */ qdev_connect_gpio_out(dev, 1, pic[0x0D]); /* IDE-0 */ qdev_connect_gpio_out(dev, 2, pic[0x02]); /* IDE-0 DMA */ qdev_connect_gpio_out(dev, 3, pic[0x0E]); /* IDE-1 */ qdev_connect_gpio_out(dev, 4, pic[0x03]); /* IDE-1 DMA */ macio_init(macio, pic_mem, escc_bar); macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), "ide[0]")); macio_ide_init_drives(macio_ide, hd); macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), "ide[1]")); macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); adb_bus = qdev_get_child_bus(dev, "adb.0"); dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD); qdev_init_nofail(dev); dev = qdev_create(adb_bus, TYPE_ADB_MOUSE); qdev_init_nofail(dev); if (usb_enabled(false)) { pci_create_simple(pci_bus, -1, "pci-ohci"); } if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) graphic_depth = 15; /* No PCI init: the BIOS will do it */ fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2); fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); if (kernel_cmdline) { fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); } else { fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); } fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); if (kvm_enabled()) { #ifdef CONFIG_KVM uint8_t *hypercall; fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq()); hypercall = g_malloc(16); kvmppc_get_hypercall(env, hypercall, 16); fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); #endif } else { fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, TBFREQ); } /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); }
21,560
FFmpeg
b8b13acd70a1c1b6c044f967d78cb82f1a53887b
0
static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, int ctb_addr_ts) { HEVCLocalContext *lc = &s->HEVClc; int ctb_size = 1 << s->ps.sps->log2_ctb_size; int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts]; int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; if (s->ps.pps->entropy_coding_sync_enabled_flag) { if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0) lc->first_qp_group = 1; lc->end_of_tiles_x = s->ps.sps->width; } else if (s->ps.pps->tiles_enabled_flag) { if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) { int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size]; lc->start_of_tiles_x = x_ctb; lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size); lc->first_qp_group = 1; } } else { lc->end_of_tiles_x = s->ps.sps->width; } lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height); lc->boundary_flags = 0; if (s->ps.pps->tiles_enabled_flag) { if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]) lc->boundary_flags |= BOUNDARY_LEFT_TILE; if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1]) lc->boundary_flags |= BOUNDARY_LEFT_SLICE; if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]]) lc->boundary_flags |= BOUNDARY_UPPER_TILE; if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width]) lc->boundary_flags |= BOUNDARY_UPPER_SLICE; } else { if (!ctb_addr_in_slice > 0) lc->boundary_flags |= BOUNDARY_LEFT_SLICE; if (ctb_addr_in_slice < s->ps.sps->ctb_width) lc->boundary_flags |= BOUNDARY_UPPER_SLICE; } lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE)); lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE)); lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]])); lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]])); }
21,562
qemu
fb7b5c0df6e3c501973ce4d57eb2b1d4344a519d
0
static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp) { SCSIDevice *dev = SCSI_DEVICE(qdev); if (dev->vmsentry) { qemu_del_vm_change_state_handler(dev->vmsentry); } scsi_device_unrealize(dev, errp); }
21,563
qemu
3996e85c1822e05c50250f8d2d1e57b6bea1229d
1
static void xen_set_memory(struct MemoryListener *listener, MemoryRegionSection *section, bool add) { XenIOState *state = container_of(listener, XenIOState, memory_listener); hwaddr start_addr = section->offset_within_address_space; ram_addr_t size = int128_get64(section->size); bool log_dirty = memory_region_is_logging(section->mr); hvmmem_type_t mem_type; if (!memory_region_is_ram(section->mr)) { return; } if (!(section->mr != &ram_memory && ( (log_dirty && add) || (!log_dirty && !add)))) { return; } trace_xen_client_set_memory(start_addr, size, log_dirty); start_addr &= TARGET_PAGE_MASK; size = TARGET_PAGE_ALIGN(size); if (add) { if (!memory_region_is_rom(section->mr)) { xen_add_to_physmap(state, start_addr, size, section->mr, section->offset_within_region); } else { mem_type = HVMMEM_ram_ro; if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type, start_addr >> TARGET_PAGE_BITS, size >> TARGET_PAGE_BITS)) { DPRINTF("xc_hvm_set_mem_type error, addr: "TARGET_FMT_plx"\n", start_addr); } } } else { if (xen_remove_from_physmap(state, start_addr, size) < 0) { DPRINTF("physmapping does not exist at "TARGET_FMT_plx"\n", start_addr); } } }
21,565
qemu
21f88d021d0d2b4ecee8f6cd6ca63a943a3ce71d
1
opts_check_list(Visitor *v, Error **errp) { /* * FIXME should set error when unvisited elements remain. Mostly * harmless, as the generated visits always visit all elements. */ }
21,566
FFmpeg
ca4a3f4a08de04344e5cb16b506564969a43ed7e
1
static int vorbis_packet(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct oggvorbis_private *priv = os->private; int duration; /* first packet handling here we parse the duration of each packet in the first page and compare the total duration to the page granule to find the encoder delay and set the first timestamp */ if (!os->lastpts) { int seg; uint8_t *last_pkt = os->buf + os->pstart; uint8_t *next_pkt = last_pkt; int first_duration = 0; avpriv_vorbis_parse_reset(&priv->vp); duration = 0; for (seg = 0; seg < os->nsegs; seg++) { if (os->segments[seg] < 255) { int d = avpriv_vorbis_parse_frame(&priv->vp, last_pkt, 1); if (d < 0) { duration = os->granule; break; } if (!duration) first_duration = d; duration += d; last_pkt = next_pkt + os->segments[seg]; } next_pkt += os->segments[seg]; } os->lastpts = os->lastdts = os->granule - duration; s->streams[idx]->start_time = os->lastpts + first_duration; if (s->streams[idx]->duration) s->streams[idx]->duration -= s->streams[idx]->start_time; s->streams[idx]->cur_dts = AV_NOPTS_VALUE; priv->final_pts = AV_NOPTS_VALUE; avpriv_vorbis_parse_reset(&priv->vp); } /* parse packet duration */ if (os->psize > 0) { duration = avpriv_vorbis_parse_frame(&priv->vp, os->buf + os->pstart, 1); if (duration <= 0) { os->pflags |= AV_PKT_FLAG_CORRUPT; return 0; } os->pduration = duration; } /* final packet handling here we save the pts of the first packet in the final page, sum up all packet durations in the final page except for the last one, and compare to the page granule to find the duration of the final packet */ if (os->flags & OGG_FLAG_EOS) { if (os->lastpts != AV_NOPTS_VALUE) { priv->final_pts = os->lastpts; priv->final_duration = 0; } if (os->segp == os->nsegs) os->pduration = os->granule - priv->final_pts - priv->final_duration; priv->final_duration += os->pduration; } return 0; }
21,568
qemu
96bdbbab55976b106f9db2b61042ebf5f0493e5a
1
static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf) { SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev); int32_t len; uint8_t command; command = buf[0]; if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) { scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); } switch (command) { case READ_6: case READ_10: case READ_12: case READ_16: len = r->req.cmd.xfer / s->qdev.blocksize; DPRINTF("Read (sector %" PRId64 ", count %d)\n", r->req.cmd.lba, len); if (r->req.cmd.buf[1] & 0xe0) { goto illegal_request; } if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); r->sector_count = len * (s->qdev.blocksize / 512); break; case VERIFY_10: case VERIFY_12: case VERIFY_16: case WRITE_6: case WRITE_10: case WRITE_12: case WRITE_16: case WRITE_VERIFY_10: case WRITE_VERIFY_12: case WRITE_VERIFY_16: len = r->req.cmd.xfer / s->qdev.blocksize; DPRINTF("Write %s(sector %" PRId64 ", count %d)\n", (command & 0xe) == 0xe ? "And Verify " : "", r->req.cmd.lba, len); if (r->req.cmd.buf[1] & 0xe0) { goto illegal_request; } if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); r->sector_count = len * (s->qdev.blocksize / 512); break; default: abort(); illegal_lba: scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE)); } if (r->sector_count == 0) { scsi_req_complete(&r->req, GOOD); } assert(r->iov.iov_len == 0); if (r->req.cmd.mode == SCSI_XFER_TO_DEV) { return -r->sector_count * 512; } else { return r->sector_count * 512; } }
21,570
qemu
c4237dfa635900e4d1cdc6038d5efe3507f45f0c
1
static void coroutine_fn mirror_run(void *opaque) { MirrorBlockJob *s = opaque; MirrorExitData *data; BlockDriverState *bs = s->common.bs; int64_t sector_num, end, sectors_per_chunk, length; uint64_t last_pause_ns; BlockDriverInfo bdi; char backing_filename[1024]; int ret = 0; int n; if (block_job_is_cancelled(&s->common)) { goto immediate_exit; } s->bdev_length = bdrv_getlength(bs); if (s->bdev_length < 0) { ret = s->bdev_length; goto immediate_exit; } else if (s->bdev_length == 0) { /* Report BLOCK_JOB_READY and wait for complete. */ block_job_event_ready(&s->common); s->synced = true; while (!block_job_is_cancelled(&s->common) && !s->should_complete) { block_job_yield(&s->common); } s->common.cancelled = false; goto immediate_exit; } length = DIV_ROUND_UP(s->bdev_length, s->granularity); s->in_flight_bitmap = bitmap_new(length); /* If we have no backing file yet in the destination, we cannot let * the destination do COW. Instead, we copy sectors around the * dirty data if needed. We need a bitmap to do that. */ bdrv_get_backing_filename(s->target, backing_filename, sizeof(backing_filename)); if (backing_filename[0] && !s->target->backing_hd) { ret = bdrv_get_info(s->target, &bdi); if (ret < 0) { goto immediate_exit; } if (s->granularity < bdi.cluster_size) { s->buf_size = MAX(s->buf_size, bdi.cluster_size); s->cow_bitmap = bitmap_new(length); } } end = s->bdev_length / BDRV_SECTOR_SIZE; s->buf = qemu_try_blockalign(bs, s->buf_size); if (s->buf == NULL) { ret = -ENOMEM; goto immediate_exit; } sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS; mirror_free_init(s); if (!s->is_none_mode) { /* First part, loop on the sectors and initialize the dirty bitmap. */ BlockDriverState *base = s->base; for (sector_num = 0; sector_num < end; ) { int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1; ret = bdrv_is_allocated_above(bs, base, sector_num, next - sector_num, &n); if (ret < 0) { goto immediate_exit; } assert(n > 0); if (ret == 1) { bdrv_set_dirty(bs, sector_num, n); sector_num = next; } else { sector_num += n; } } } bdrv_dirty_iter_init(bs, s->dirty_bitmap, &s->hbi); last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); for (;;) { uint64_t delay_ns = 0; int64_t cnt; bool should_complete; if (s->ret < 0) { ret = s->ret; goto immediate_exit; } cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap); /* s->common.offset contains the number of bytes already processed so * far, cnt is the number of dirty sectors remaining and * s->sectors_in_flight is the number of sectors currently being * processed; together those are the current total operation length */ s->common.len = s->common.offset + (cnt + s->sectors_in_flight) * BDRV_SECTOR_SIZE; /* Note that even when no rate limit is applied we need to yield * periodically with no pending I/O so that qemu_aio_flush() returns. * We do so every SLICE_TIME nanoseconds, or when there is an error, * or when the source is clean, whichever comes first. */ if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - last_pause_ns < SLICE_TIME && s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight == MAX_IN_FLIGHT || s->buf_free_count == 0 || (cnt == 0 && s->in_flight > 0)) { trace_mirror_yield(s, s->in_flight, s->buf_free_count, cnt); qemu_coroutine_yield(); continue; } else if (cnt != 0) { delay_ns = mirror_iteration(s); if (delay_ns == 0) { continue; } } } should_complete = false; if (s->in_flight == 0 && cnt == 0) { trace_mirror_before_flush(s); ret = bdrv_flush(s->target); if (ret < 0) { if (mirror_error_action(s, false, -ret) == BLOCK_ERROR_ACTION_REPORT) { goto immediate_exit; } } else { /* We're out of the streaming phase. From now on, if the job * is cancelled we will actually complete all pending I/O and * report completion. This way, block-job-cancel will leave * the target in a consistent state. */ if (!s->synced) { block_job_event_ready(&s->common); s->synced = true; } should_complete = s->should_complete || block_job_is_cancelled(&s->common); cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap); } } if (cnt == 0 && should_complete) { /* The dirty bitmap is not updated while operations are pending. * If we're about to exit, wait for pending operations before * calling bdrv_get_dirty_count(bs), or we may exit while the * source has dirty data to copy! * * Note that I/O can be submitted by the guest while * mirror_populate runs. */ trace_mirror_before_drain(s, cnt); bdrv_drain(bs); cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap); } ret = 0; trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); if (!s->synced) { block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, delay_ns); if (block_job_is_cancelled(&s->common)) { break; } } else if (!should_complete) { delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0); block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, delay_ns); } else if (cnt == 0) { /* The two disks are in sync. Exit and report successful * completion. */ assert(QLIST_EMPTY(&bs->tracked_requests)); s->common.cancelled = false; break; } last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } immediate_exit: if (s->in_flight > 0) { /* We get here only if something went wrong. Either the job failed, * or it was cancelled prematurely so that we do not guarantee that * the target is a copy of the source. */ assert(ret < 0 || (!s->synced && block_job_is_cancelled(&s->common))); mirror_drain(s); } assert(s->in_flight == 0); qemu_vfree(s->buf); g_free(s->cow_bitmap); g_free(s->in_flight_bitmap); bdrv_release_dirty_bitmap(bs, s->dirty_bitmap); bdrv_iostatus_disable(s->target); data = g_malloc(sizeof(*data)); data->ret = ret; block_job_defer_to_main_loop(&s->common, mirror_exit, data); }
21,571
qemu
976620ac4018db142d82cd42bb7774f40290ce7e
1
int object_property_get_enum(Object *obj, const char *name, const char *strings[], Error **errp) { StringOutputVisitor *sov; StringInputVisitor *siv; int ret; sov = string_output_visitor_new(false); object_property_get(obj, string_output_get_visitor(sov), name, errp); siv = string_input_visitor_new(string_output_get_string(sov)); string_output_visitor_cleanup(sov); visit_type_enum(string_input_get_visitor(siv), &ret, strings, NULL, name, errp); string_input_visitor_cleanup(siv); return ret; }
21,572
FFmpeg
8813d55fa5978660d9f4e7dbe1f50da9922be08d
0
int ff_vaapi_render_picture(FFVAContext *vactx, VASurfaceID surface) { VABufferID va_buffers[3]; unsigned int n_va_buffers = 0; if (!vactx->pic_param_buf_id) return 0; vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id); va_buffers[n_va_buffers++] = vactx->pic_param_buf_id; if (vactx->iq_matrix_buf_id) { vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id); va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id; } if (vactx->bitplane_buf_id) { vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id); va_buffers[n_va_buffers++] = vactx->bitplane_buf_id; } if (vaBeginPicture(vactx->display, vactx->context_id, surface) != VA_STATUS_SUCCESS) return -1; if (vaRenderPicture(vactx->display, vactx->context_id, va_buffers, n_va_buffers) != VA_STATUS_SUCCESS) return -1; if (vaRenderPicture(vactx->display, vactx->context_id, vactx->slice_buf_ids, vactx->n_slice_buf_ids) != VA_STATUS_SUCCESS) return -1; if (vaEndPicture(vactx->display, vactx->context_id) != VA_STATUS_SUCCESS) return -1; return 0; }
21,573
FFmpeg
aaa995d7f29cba39b1fe05b6f0a807bfc7a09f43
0
static void loop_filter(H264Context *h){ MpegEncContext * const s = &h->s; uint8_t *dest_y, *dest_cb, *dest_cr; int linesize, uvlinesize, mb_x, mb_y; const int end_mb_y= s->mb_y + FRAME_MBAFF; const int old_slice_type= h->slice_type; if(h->deblocking_filter) { for(mb_x= 0; mb_x<s->mb_width; mb_x++){ for(mb_y=end_mb_y - FRAME_MBAFF; mb_y<= end_mb_y; mb_y++){ int list, mb_xy, mb_type; mb_xy = h->mb_xy = mb_x + mb_y*s->mb_stride; h->slice_num= h->slice_table[mb_xy]; mb_type= s->current_picture.mb_type[mb_xy]; h->list_count= h->list_counts[mb_xy]; if(FRAME_MBAFF) h->mb_mbaff = h->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); s->mb_x= mb_x; s->mb_y= mb_y; dest_y = s->current_picture.data[0] + (mb_x + mb_y * s->linesize ) * 16; dest_cb = s->current_picture.data[1] + (mb_x + mb_y * s->uvlinesize) * 8; dest_cr = s->current_picture.data[2] + (mb_x + mb_y * s->uvlinesize) * 8; //FIXME simplify above if (MB_FIELD) { linesize = h->mb_linesize = s->linesize * 2; uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; if(mb_y&1){ //FIXME move out of this function? dest_y -= s->linesize*15; dest_cb-= s->uvlinesize*7; dest_cr-= s->uvlinesize*7; } } else { linesize = h->mb_linesize = s->linesize; uvlinesize = h->mb_uvlinesize = s->uvlinesize; } backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); if(fill_filter_caches(h, mb_type) < 0) continue; h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]); h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]); if (FRAME_MBAFF) { ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); } else { ff_h264_filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); } } } } h->slice_type= old_slice_type; s->mb_x= 0; s->mb_y= end_mb_y - FRAME_MBAFF; }
21,574
FFmpeg
28e6b7b9b4e0a6ec05575cffedd56e1319f8691f
0
static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track, int64_t moof_offset) { int64_t pos = avio_tell(pb); uint32_t flags = MOV_TFHD_DEFAULT_SIZE | MOV_TFHD_DEFAULT_DURATION | MOV_TFHD_BASE_DATA_OFFSET; if (!track->entry) { flags |= MOV_TFHD_DURATION_IS_EMPTY; } else { flags |= MOV_TFHD_DEFAULT_FLAGS; } /* Don't set a default sample size, the silverlight player refuses * to play files with that set. Don't set a default sample duration, * WMP freaks out if it is set. */ if (track->mode == MODE_ISM) flags &= ~(MOV_TFHD_DEFAULT_SIZE | MOV_TFHD_DEFAULT_DURATION); avio_wb32(pb, 0); /* size placeholder */ ffio_wfourcc(pb, "tfhd"); avio_w8(pb, 0); /* version */ avio_wb24(pb, flags); avio_wb32(pb, track->track_id); /* track-id */ if (flags & MOV_TFHD_BASE_DATA_OFFSET) avio_wb64(pb, moof_offset); if (flags & MOV_TFHD_DEFAULT_DURATION) { track->default_duration = get_cluster_duration(track, 0); avio_wb32(pb, track->default_duration); } if (flags & MOV_TFHD_DEFAULT_SIZE) { track->default_size = track->entry ? track->cluster[0].size : 1; avio_wb32(pb, track->default_size); } else track->default_size = -1; if (flags & MOV_TFHD_DEFAULT_FLAGS) { track->default_sample_flags = track->enc->codec_type == AVMEDIA_TYPE_VIDEO ? (MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES | MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC) : MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO; avio_wb32(pb, track->default_sample_flags); } return update_size(pb, pos); }
21,575
FFmpeg
323e6fead07c75f418e4b60704a4f437bb3483b2
1
static int normalize_samples(AC3EncodeContext *s) { int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE); lshift_tab(s->windowed_samples, AC3_WINDOW_SIZE, v); return v - 9; }
21,577
qemu
8d04fb55dec381bc5105cb47f29d918e579e8cbd
1
uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2) { int r = sclp_service_call(env, r1, r2); if (r < 0) { program_interrupt(env, -r, 4); return 0; } return r; }
21,578
qemu
5e39d89d20b17cf6fb7f09d181d34f17b2ae2160
1
static void test_query_cpus(const void *data) { char *cli; QDict *resp; QList *cpus; const QObject *e; cli = make_cli(data, "-smp 8 -numa node,cpus=0-3 -numa node,cpus=4-7"); qtest_start(cli); cpus = get_cpus(&resp); g_assert(cpus); while ((e = qlist_pop(cpus))) { QDict *cpu, *props; int64_t cpu_idx, node; cpu = qobject_to_qdict(e); g_assert(qdict_haskey(cpu, "CPU")); g_assert(qdict_haskey(cpu, "props")); cpu_idx = qdict_get_int(cpu, "CPU"); props = qdict_get_qdict(cpu, "props"); g_assert(qdict_haskey(props, "node-id")); node = qdict_get_int(props, "node-id"); if (cpu_idx >= 0 && cpu_idx < 4) { g_assert_cmpint(node, ==, 0); } else { g_assert_cmpint(node, ==, 1); } } QDECREF(resp); qtest_end(); g_free(cli); }
21,579
qemu
e3c9d76acc984218264bbc6435b0c09f959ed9b8
1
int virtio_scsi_common_exit(VirtIOSCSICommon *vs) { VirtIODevice *vdev = VIRTIO_DEVICE(vs); g_free(vs->cmd_vqs); virtio_cleanup(vdev); return 0; }
21,580
FFmpeg
3d23f7a0969bf76ad6dcdc2c4a5cd3ae884745a8
1
static int decode_subframe_fixed(FLACContext *s, int32_t *decoded, int pred_order, int bps) { const int blocksize = s->blocksize; unsigned av_uninit(a), av_uninit(b), av_uninit(c), av_uninit(d); int i; int ret; /* warm up samples */ for (i = 0; i < pred_order; i++) { decoded[i] = get_sbits_long(&s->gb, bps); } if ((ret = decode_residuals(s, decoded, pred_order)) < 0) return ret; if (pred_order > 0) a = decoded[pred_order-1]; if (pred_order > 1) b = a - decoded[pred_order-2]; if (pred_order > 2) c = b - decoded[pred_order-2] + decoded[pred_order-3]; if (pred_order > 3) d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4]; switch (pred_order) { case 0: break; case 1: for (i = pred_order; i < blocksize; i++) decoded[i] = a += decoded[i]; break; case 2: for (i = pred_order; i < blocksize; i++) decoded[i] = a += b += decoded[i]; break; case 3: for (i = pred_order; i < blocksize; i++) decoded[i] = a += b += c += decoded[i]; break; case 4: for (i = pred_order; i < blocksize; i++) decoded[i] = a += b += c += d += decoded[i]; break; default: av_log(s->avctx, AV_LOG_ERROR, "illegal pred order %d\n", pred_order); return AVERROR_INVALIDDATA; } return 0; }
21,581
FFmpeg
0e3afacd4d8fbe1c21e0bc16bd707809cd87380f
0
static int add_tonal_components(float *spectrum, int num_components, TonalComponent *components) { int i, j, last_pos = -1; float *input, *output; for (i = 0; i < num_components; i++) { last_pos = FFMAX(components[i].pos + components[i].num_coefs, last_pos); input = components[i].coef; output = &spectrum[components[i].pos]; for (j = 0; j < components[i].num_coefs; j++) output[i] += input[i]; } return last_pos; }
21,582
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int qemu_rdma_write_flush(QEMUFile *f, RDMAContext *rdma) { int ret; if (!rdma->current_length) { return 0; } ret = qemu_rdma_write_one(f, rdma, rdma->current_index, rdma->current_addr, rdma->current_length); if (ret < 0) { return ret; } if (ret == 0) { rdma->nb_sent++; DDDPRINTF("sent total: %d\n", rdma->nb_sent); } rdma->current_length = 0; rdma->current_addr = 0; return 0; }
21,588
qemu
1e0228fd20aa46ac1f02cffee946cdd4ffaf8b96
1
Exynos4210State *exynos4210_init(MemoryRegion *system_mem, unsigned long ram_size) { int i, n; Exynos4210State *s = g_new(Exynos4210State, 1); qemu_irq gate_irq[EXYNOS4210_NCPUS][EXYNOS4210_IRQ_GATE_NINPUTS]; unsigned long mem_size; DeviceState *dev; SysBusDevice *busdev; ObjectClass *cpu_oc; cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, "cortex-a9"); assert(cpu_oc); for (n = 0; n < EXYNOS4210_NCPUS; n++) { Object *cpuobj = object_new(object_class_get_name(cpu_oc)); /* By default A9 CPUs have EL3 enabled. This board does not currently * support EL3 so the CPU EL3 property is disabled before realization. */ if (object_property_find(cpuobj, "has_el3", NULL)) { object_property_set_bool(cpuobj, false, "has_el3", &error_fatal); } s->cpu[n] = ARM_CPU(cpuobj); object_property_set_int(cpuobj, EXYNOS4210_SMP_PRIVATE_BASE_ADDR, "reset-cbar", &error_abort); object_property_set_bool(cpuobj, true, "realized", &error_fatal); } /*** IRQs ***/ s->irq_table = exynos4210_init_irq(&s->irqs); /* IRQ Gate */ for (i = 0; i < EXYNOS4210_NCPUS; i++) { dev = qdev_create(NULL, "exynos4210.irq_gate"); qdev_prop_set_uint32(dev, "n_in", EXYNOS4210_IRQ_GATE_NINPUTS); qdev_init_nofail(dev); /* Get IRQ Gate input in gate_irq */ for (n = 0; n < EXYNOS4210_IRQ_GATE_NINPUTS; n++) { gate_irq[i][n] = qdev_get_gpio_in(dev, n); } busdev = SYS_BUS_DEVICE(dev); /* Connect IRQ Gate output to CPU's IRQ line */ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(s->cpu[i]), ARM_CPU_IRQ)); } /* Private memory region and Internal GIC */ dev = qdev_create(NULL, "a9mpcore_priv"); qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); sysbus_mmio_map(busdev, 0, EXYNOS4210_SMP_PRIVATE_BASE_ADDR); for (n = 0; n < EXYNOS4210_NCPUS; n++) { sysbus_connect_irq(busdev, n, gate_irq[n][0]); } for (n = 0; n < EXYNOS4210_INT_GIC_NIRQ; n++) { s->irqs.int_gic_irq[n] = qdev_get_gpio_in(dev, n); } /* Cache controller */ sysbus_create_simple("l2x0", EXYNOS4210_L2X0_BASE_ADDR, NULL); /* External GIC */ dev = qdev_create(NULL, "exynos4210.gic"); qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); /* Map CPU interface */ sysbus_mmio_map(busdev, 0, EXYNOS4210_EXT_GIC_CPU_BASE_ADDR); /* Map Distributer interface */ sysbus_mmio_map(busdev, 1, EXYNOS4210_EXT_GIC_DIST_BASE_ADDR); for (n = 0; n < EXYNOS4210_NCPUS; n++) { sysbus_connect_irq(busdev, n, gate_irq[n][1]); } for (n = 0; n < EXYNOS4210_EXT_GIC_NIRQ; n++) { s->irqs.ext_gic_irq[n] = qdev_get_gpio_in(dev, n); } /* Internal Interrupt Combiner */ dev = qdev_create(NULL, "exynos4210.combiner"); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) { sysbus_connect_irq(busdev, n, s->irqs.int_gic_irq[n]); } exynos4210_combiner_get_gpioin(&s->irqs, dev, 0); sysbus_mmio_map(busdev, 0, EXYNOS4210_INT_COMBINER_BASE_ADDR); /* External Interrupt Combiner */ dev = qdev_create(NULL, "exynos4210.combiner"); qdev_prop_set_uint32(dev, "external", 1); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) { sysbus_connect_irq(busdev, n, s->irqs.ext_gic_irq[n]); } exynos4210_combiner_get_gpioin(&s->irqs, dev, 1); sysbus_mmio_map(busdev, 0, EXYNOS4210_EXT_COMBINER_BASE_ADDR); /* Initialize board IRQs. */ exynos4210_init_board_irqs(&s->irqs); /*** Memory ***/ /* Chip-ID and OMR */ memory_region_init_io(&s->chipid_mem, NULL, &exynos4210_chipid_and_omr_ops, NULL, "exynos4210.chipid", sizeof(chipid_and_omr)); memory_region_add_subregion(system_mem, EXYNOS4210_CHIPID_ADDR, &s->chipid_mem); /* Internal ROM */ memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom", EXYNOS4210_IROM_SIZE, &error_fatal); vmstate_register_ram_global(&s->irom_mem); memory_region_set_readonly(&s->irom_mem, true); memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR, &s->irom_mem); /* mirror of iROM */ memory_region_init_alias(&s->irom_alias_mem, NULL, "exynos4210.irom_alias", &s->irom_mem, 0, EXYNOS4210_IROM_SIZE); memory_region_set_readonly(&s->irom_alias_mem, true); memory_region_add_subregion(system_mem, EXYNOS4210_IROM_MIRROR_BASE_ADDR, &s->irom_alias_mem); /* Internal RAM */ memory_region_init_ram(&s->iram_mem, NULL, "exynos4210.iram", EXYNOS4210_IRAM_SIZE, &error_fatal); vmstate_register_ram_global(&s->iram_mem); memory_region_add_subregion(system_mem, EXYNOS4210_IRAM_BASE_ADDR, &s->iram_mem); /* DRAM */ mem_size = ram_size; if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) { memory_region_init_ram(&s->dram1_mem, NULL, "exynos4210.dram1", mem_size - EXYNOS4210_DRAM_MAX_SIZE, &error_fatal); vmstate_register_ram_global(&s->dram1_mem); memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR, &s->dram1_mem); mem_size = EXYNOS4210_DRAM_MAX_SIZE; } memory_region_init_ram(&s->dram0_mem, NULL, "exynos4210.dram0", mem_size, &error_fatal); vmstate_register_ram_global(&s->dram0_mem); memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR, &s->dram0_mem); /* PMU. * The only reason of existence at the moment is that secondary CPU boot * loader uses PMU INFORM5 register as a holding pen. */ sysbus_create_simple("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL); /* PWM */ sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR, s->irq_table[exynos4210_get_irq(22, 0)], s->irq_table[exynos4210_get_irq(22, 1)], s->irq_table[exynos4210_get_irq(22, 2)], s->irq_table[exynos4210_get_irq(22, 3)], s->irq_table[exynos4210_get_irq(22, 4)], NULL); /* RTC */ sysbus_create_varargs("exynos4210.rtc", EXYNOS4210_RTC_BASE_ADDR, s->irq_table[exynos4210_get_irq(23, 0)], s->irq_table[exynos4210_get_irq(23, 1)], NULL); /* Multi Core Timer */ dev = qdev_create(NULL, "exynos4210.mct"); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); for (n = 0; n < 4; n++) { /* Connect global timer interrupts to Combiner gpio_in */ sysbus_connect_irq(busdev, n, s->irq_table[exynos4210_get_irq(1, 4 + n)]); } /* Connect local timer interrupts to Combiner gpio_in */ sysbus_connect_irq(busdev, 4, s->irq_table[exynos4210_get_irq(51, 0)]); sysbus_connect_irq(busdev, 5, s->irq_table[exynos4210_get_irq(35, 3)]); sysbus_mmio_map(busdev, 0, EXYNOS4210_MCT_BASE_ADDR); /*** I2C ***/ for (n = 0; n < EXYNOS4210_I2C_NUMBER; n++) { uint32_t addr = EXYNOS4210_I2C_BASE_ADDR + EXYNOS4210_I2C_SHIFT * n; qemu_irq i2c_irq; if (n < 8) { i2c_irq = s->irq_table[exynos4210_get_irq(EXYNOS4210_I2C_INTG, n)]; } else { i2c_irq = s->irq_table[exynos4210_get_irq(EXYNOS4210_HDMI_INTG, 1)]; } dev = qdev_create(NULL, "exynos4210.i2c"); qdev_init_nofail(dev); busdev = SYS_BUS_DEVICE(dev); sysbus_connect_irq(busdev, 0, i2c_irq); sysbus_mmio_map(busdev, 0, addr); s->i2c_if[n] = (I2CBus *)qdev_get_child_bus(dev, "i2c"); } /*** UARTs ***/ exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR, EXYNOS4210_UART0_FIFO_SIZE, 0, NULL, s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 0)]); exynos4210_uart_create(EXYNOS4210_UART1_BASE_ADDR, EXYNOS4210_UART1_FIFO_SIZE, 1, NULL, s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 1)]); exynos4210_uart_create(EXYNOS4210_UART2_BASE_ADDR, EXYNOS4210_UART2_FIFO_SIZE, 2, NULL, s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 2)]); exynos4210_uart_create(EXYNOS4210_UART3_BASE_ADDR, EXYNOS4210_UART3_FIFO_SIZE, 3, NULL, s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 3)]); /*** Display controller (FIMD) ***/ sysbus_create_varargs("exynos4210.fimd", EXYNOS4210_FIMD0_BASE_ADDR, s->irq_table[exynos4210_get_irq(11, 0)], s->irq_table[exynos4210_get_irq(11, 1)], s->irq_table[exynos4210_get_irq(11, 2)], NULL); sysbus_create_simple(TYPE_EXYNOS4210_EHCI, EXYNOS4210_EHCI_BASE_ADDR, s->irq_table[exynos4210_get_irq(28, 3)]); return s; }
21,590
qemu
bd88c780e6a17188f7fd676f3a056e5db21500e0
1
static void *clone_func(void *arg) { new_thread_info *info = arg; CPUArchState *env; CPUState *cpu; TaskState *ts; rcu_register_thread(); env = info->env; cpu = ENV_GET_CPU(env); thread_cpu = cpu; ts = (TaskState *)cpu->opaque; info->tid = gettid(); cpu->host_tid = info->tid; task_settid(ts); if (info->child_tidptr) put_user_u32(info->tid, info->child_tidptr); if (info->parent_tidptr) put_user_u32(info->tid, info->parent_tidptr); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ pthread_mutex_lock(&info->mutex); pthread_cond_broadcast(&info->cond); pthread_mutex_unlock(&info->mutex); /* Wait until the parent has finshed initializing the tls state. */ pthread_mutex_lock(&clone_lock); pthread_mutex_unlock(&clone_lock); cpu_loop(env); /* never exits */ return NULL; }
21,591
FFmpeg
009f829dde811af654af7110326aea3a72c05d5e
1
static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0, const uint16_t *ubuf0, const uint16_t *ubuf1, const uint16_t *vbuf0, const uint16_t *vbuf1, const uint16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1(%%REGBP, %5, %6) YSCALEYUV2RGB1_ALPHA(%%REGBP) WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither), "m"(uv_off) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1(%%REGBP, %5, %6) "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither), "m"(uv_off) ); } } else { if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1b(%%REGBP, %5, %6) YSCALEYUV2RGB1_ALPHA(%%REGBP) WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither), "m"(uv_off) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB1b(%%REGBP, %5, %6) "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither), "m"(uv_off) ); } } }
21,592
qemu
fcf73f66a67f5e58c18216f8c8651e38cf4d90af
1
QInt *qobject_to_qint(const QObject *obj) { if (qobject_type(obj) != QTYPE_QINT) return NULL; return container_of(obj, QInt, base); }
21,593
FFmpeg
56706ac0d5723cb549fec2602e798ab1bf6004cd
1
static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image) { int compno; int x; int y; int *image_line; int frame_index; const int numcomps = image->numcomps; for (compno = 0; compno < numcomps; ++compno) { if (image->comps[compno].w > frame->linesize[0] / numcomps) { av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); return 0; } } for (compno = 0; compno < numcomps; ++compno) { for (y = 0; y < avctx->height; ++y) { image_line = image->comps[compno].data + y * image->comps[compno].w; frame_index = y * frame->linesize[0] + compno; for (x = 0; x < avctx->width; ++x) { image_line[x] = frame->data[0][frame_index]; frame_index += numcomps; } for (; x < image->comps[compno].w; ++x) { image_line[x] = image_line[x - 1]; } } for (; y < image->comps[compno].h; ++y) { image_line = image->comps[compno].data + y * image->comps[compno].w; for (x = 0; x < image->comps[compno].w; ++x) { image_line[x] = image_line[x - image->comps[compno].w]; } } } return 1; }
21,594
qemu
9a321e92343891e30f6fe8bfaad40454ae358bfb
1
static int spapr_msicfg_find(sPAPRPHBState *phb, uint32_t config_addr, bool alloc_new) { int i; for (i = 0; i < SPAPR_MSIX_MAX_DEVS; ++i) { if (!phb->msi_table[i].nvec) { break; } if (phb->msi_table[i].config_addr == config_addr) { return i; } } if ((i < SPAPR_MSIX_MAX_DEVS) && alloc_new) { trace_spapr_pci_msi("Allocating new MSI config", i, config_addr); return i; } return -1; }
21,595
qemu
b47b35250fbfa062aedf6ab6e5faab84c4a76f4f
1
static void fdctrl_connect_drives(FDCtrl *fdctrl) { unsigned int i; FDrive *drive; for (i = 0; i < MAX_FD; i++) { drive = &fdctrl->drives[i]; fd_init(drive); fd_revalidate(drive); if (drive->bs) { bdrv_set_removable(drive->bs, 1); } } }
21,596
FFmpeg
dcc39ee10e82833ce24aa57926c00ffeb1948198
0
static av_cold int decode_init(AVCodecContext *avctx) { ASV1Context *const a = avctx->priv_data; const int scale = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2; int i; if (avctx->extradata_size < 1) { av_log(avctx, AV_LOG_ERROR, "No extradata provided\n"); return AVERROR_INVALIDDATA; } ff_asv_common_init(avctx); ff_blockdsp_init(&a->bdsp, avctx); ff_idctdsp_init(&a->idsp, avctx); init_vlcs(a); ff_init_scantable(a->idsp.idct_permutation, &a->scantable, ff_asv_scantab); avctx->pix_fmt = AV_PIX_FMT_YUV420P; a->inv_qscale = avctx->extradata[0]; if (a->inv_qscale == 0) { av_log(avctx, AV_LOG_ERROR, "illegal qscale 0\n"); if (avctx->codec_id == AV_CODEC_ID_ASV1) a->inv_qscale = 6; else a->inv_qscale = 10; } for (i = 0; i < 64; i++) { int index = ff_asv_scantab[i]; a->intra_matrix[i] = 64 * scale * ff_mpeg1_default_intra_matrix[index] / a->inv_qscale; } return 0; }
21,597
FFmpeg
94e86ae15a4328b22f6f103b9fd9b6a9ee0c676c
0
int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, const AVFrame *reference) { int len, nb_components, i, h, v, predictor, point_transform; int index, id, ret; const int block_size = s->lossless ? 1 : 8; int ilv, prev_shift; if (!s->got_picture) { av_log(s->avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n"); return -1; } av_assert0(s->picture_ptr->data[0]); /* XXX: verify len field validity */ len = get_bits(&s->gb, 16); nb_components = get_bits(&s->gb, 8); if (nb_components == 0 || nb_components > MAX_COMPONENTS) { av_log(s->avctx, AV_LOG_ERROR, "decode_sos: nb_components (%d) unsupported\n", nb_components); return AVERROR_PATCHWELCOME; } if (len != 6 + 2 * nb_components) { av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); return AVERROR_INVALIDDATA; } for (i = 0; i < nb_components; i++) { id = get_bits(&s->gb, 8) - 1; av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id); /* find component index */ for (index = 0; index < s->nb_components; index++) if (id == s->component_id[index]) break; if (index == s->nb_components) { av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index); return AVERROR_INVALIDDATA; } /* Metasoft MJPEG codec has Cb and Cr swapped */ if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J') && nb_components == 3 && s->nb_components == 3 && i) index = 3 - i; if(nb_components == 3 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P) index = (i+2)%3; if(nb_components == 1 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P) index = (index+2)%3; s->comp_index[i] = index; s->nb_blocks[i] = s->h_count[index] * s->v_count[index]; s->h_scount[i] = s->h_count[index]; s->v_scount[i] = s->v_count[index]; s->dc_index[i] = get_bits(&s->gb, 4); s->ac_index[i] = get_bits(&s->gb, 4); if (s->dc_index[i] < 0 || s->ac_index[i] < 0 || s->dc_index[i] >= 4 || s->ac_index[i] >= 4) goto out_of_range; if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->vlcs[1][s->ac_index[i]].table)) goto out_of_range; } predictor = get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ ilv = get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ if(s->avctx->codec_tag != AV_RL32("CJPG")){ prev_shift = get_bits(&s->gb, 4); /* Ah */ point_transform = get_bits(&s->gb, 4); /* Al */ }else prev_shift = point_transform = 0; if (nb_components > 1) { /* interleaved stream */ s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size); s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size); } else if (!s->ls) { /* skip this for JPEG-LS */ h = s->h_max / s->h_scount[0]; v = s->v_max / s->v_scount[0]; s->mb_width = (s->width + h * block_size - 1) / (h * block_size); s->mb_height = (s->height + v * block_size - 1) / (v * block_size); s->nb_blocks[0] = 1; s->h_scount[0] = 1; s->v_scount[0] = 1; } if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n", s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "", predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod, s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components); /* mjpeg-b can have padding bytes between sos and image data, skip them */ for (i = s->mjpb_skiptosod; i > 0; i--) skip_bits(&s->gb, 8); next_field: for (i = 0; i < nb_components; i++) s->last_dc[i] = 1024; if (s->lossless) { av_assert0(s->picture_ptr == &s->picture); if (CONFIG_JPEGLS_DECODER && s->ls) { // for () { // reset_ls_coding_parameters(s, 0); if ((ret = ff_jpegls_decode_picture(s, predictor, point_transform, ilv)) < 0) return ret; } else { if (s->rgb) { if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0) return ret; } else { if ((ret = ljpeg_decode_yuv_scan(s, predictor, point_transform, nb_components)) < 0) return ret; } } } else { if (s->progressive && predictor) { av_assert0(s->picture_ptr == &s->picture); if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform)) < 0) return ret; } else { if ((ret = mjpeg_decode_scan(s, nb_components, prev_shift, point_transform, mb_bitmask, reference)) < 0) return ret; } } if (s->interlaced && get_bits_left(&s->gb) > 32 && show_bits(&s->gb, 8) == 0xFF) { GetBitContext bak = s->gb; align_get_bits(&bak); if (show_bits(&bak, 16) == 0xFFD1) { av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n"); s->gb = bak; skip_bits(&s->gb, 16); s->bottom_field ^= 1; goto next_field; } } emms_c(); return 0; out_of_range: av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n"); return AVERROR_INVALIDDATA; }
21,598
FFmpeg
3c895fc098f7637f6d5ec3a9d6766e724a8b9e41
0
static void do_video_out(AVFormatContext *s, AVOutputStream *ost, AVInputStream *ist, AVFrame *in_picture, int *frame_size, AVOutputStream *audio_sync) { int nb_frames, i, ret; AVFrame *final_picture, *formatted_picture; AVFrame picture_format_temp, picture_crop_temp; static uint8_t *video_buffer= NULL; uint8_t *buf = NULL, *buf1 = NULL; AVCodecContext *enc, *dec; enum PixelFormat target_pixfmt; #define VIDEO_BUFFER_SIZE (1024*1024) avcodec_get_frame_defaults(&picture_format_temp); avcodec_get_frame_defaults(&picture_crop_temp); enc = &ost->st->codec; dec = &ist->st->codec; /* by default, we output a single frame */ nb_frames = 1; *frame_size = 0; if(sync_method){ double vdelta; vdelta = ost->sync_ipts * enc->frame_rate / enc->frame_rate_base - ost->sync_opts; //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c if (vdelta < -1.1) nb_frames = 0; else if (vdelta > 1.1) nb_frames = 2; //printf("vdelta:%f, ost->sync_opts:%lld, ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames); } ost->sync_opts+= nb_frames; if (nb_frames <= 0) return; if (!video_buffer) video_buffer = av_malloc(VIDEO_BUFFER_SIZE); if (!video_buffer) return; /* convert pixel format if needed */ target_pixfmt = ost->video_resample || ost->video_pad ? PIX_FMT_YUV420P : enc->pix_fmt; if (dec->pix_fmt != target_pixfmt) { int size; /* create temporary picture */ size = avpicture_get_size(target_pixfmt, dec->width, dec->height); buf = av_malloc(size); if (!buf) return; formatted_picture = &picture_format_temp; avpicture_fill((AVPicture*)formatted_picture, buf, target_pixfmt, dec->width, dec->height); if (img_convert((AVPicture*)formatted_picture, target_pixfmt, (AVPicture *)in_picture, dec->pix_fmt, dec->width, dec->height) < 0) { if (verbose >= 0) fprintf(stderr, "pixel format conversion not handled\n"); goto the_end; } } else { formatted_picture = in_picture; } /* XXX: resampling could be done before raw format conversion in some cases to go faster */ /* XXX: only works for YUV420P */ if (ost->video_resample) { final_picture = &ost->pict_tmp; img_resample(ost->img_resample_ctx, (AVPicture*)final_picture, (AVPicture*)formatted_picture); if (ost->padtop || ost->padbottom || ost->padleft || ost->padright) { fill_pad_region((AVPicture*)final_picture, enc->height, enc->width, ost->padtop, ost->padbottom, ost->padleft, ost->padright, padcolor); } if (enc->pix_fmt != PIX_FMT_YUV420P) { int size; av_free(buf); /* create temporary picture */ size = avpicture_get_size(enc->pix_fmt, enc->width, enc->height); buf = av_malloc(size); if (!buf) return; final_picture = &picture_format_temp; avpicture_fill((AVPicture*)final_picture, buf, enc->pix_fmt, enc->width, enc->height); if (img_convert((AVPicture*)final_picture, enc->pix_fmt, (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P, enc->width, enc->height) < 0) { if (verbose >= 0) fprintf(stderr, "pixel format conversion not handled\n"); goto the_end; } } } else if (ost->video_crop) { picture_crop_temp.data[0] = formatted_picture->data[0] + (ost->topBand * formatted_picture->linesize[0]) + ost->leftBand; picture_crop_temp.data[1] = formatted_picture->data[1] + ((ost->topBand >> 1) * formatted_picture->linesize[1]) + (ost->leftBand >> 1); picture_crop_temp.data[2] = formatted_picture->data[2] + ((ost->topBand >> 1) * formatted_picture->linesize[2]) + (ost->leftBand >> 1); picture_crop_temp.linesize[0] = formatted_picture->linesize[0]; picture_crop_temp.linesize[1] = formatted_picture->linesize[1]; picture_crop_temp.linesize[2] = formatted_picture->linesize[2]; final_picture = &picture_crop_temp; } else if (ost->video_pad) { final_picture = &ost->pict_tmp; for (i = 0; i < 3; i++) { uint8_t *optr, *iptr; int shift = (i == 0) ? 0 : 1; int y, yheight; /* set offset to start writing image into */ optr = final_picture->data[i] + (((final_picture->linesize[i] * ost->padtop) + ost->padleft) >> shift); iptr = formatted_picture->data[i]; yheight = (enc->height - ost->padtop - ost->padbottom) >> shift; for (y = 0; y < yheight; y++) { /* copy unpadded image row into padded image row */ memcpy(optr, iptr, formatted_picture->linesize[i]); optr += final_picture->linesize[i]; iptr += formatted_picture->linesize[i]; } } fill_pad_region((AVPicture*)final_picture, enc->height, enc->width, ost->padtop, ost->padbottom, ost->padleft, ost->padright, padcolor); if (enc->pix_fmt != PIX_FMT_YUV420P) { int size; av_free(buf); /* create temporary picture */ size = avpicture_get_size(enc->pix_fmt, enc->width, enc->height); buf = av_malloc(size); if (!buf) return; final_picture = &picture_format_temp; avpicture_fill((AVPicture*)final_picture, buf, enc->pix_fmt, enc->width, enc->height); if (img_convert((AVPicture*)final_picture, enc->pix_fmt, (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P, enc->width, enc->height) < 0) { if (verbose >= 0) fprintf(stderr, "pixel format conversion not handled\n"); goto the_end; } } } else { final_picture = formatted_picture; } /* duplicates frame if needed */ /* XXX: pb because no interleaving */ for(i=0;i<nb_frames;i++) { AVPacket pkt; av_init_packet(&pkt); pkt.stream_index= ost->index; if (s->oformat->flags & AVFMT_RAWPICTURE) { /* raw pictures are written as AVPicture structure to avoid any copies. We support temorarily the older method. */ AVFrame* old_frame = enc->coded_frame; enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack pkt.data= (uint8_t *)final_picture; pkt.size= sizeof(AVPicture); if(dec->coded_frame) pkt.pts= dec->coded_frame->pts; if(dec->coded_frame && dec->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; av_write_frame(s, &pkt); enc->coded_frame = old_frame; } else { AVFrame big_picture; big_picture= *final_picture; /* better than nothing: use input picture interlaced settings */ big_picture.interlaced_frame = in_picture->interlaced_frame; if(do_interlace_me || do_interlace_dct){ if(top_field_first == -1) big_picture.top_field_first = in_picture->top_field_first; else big_picture.top_field_first = 1; } /* handles sameq here. This is not correct because it may not be a global option */ if (same_quality) { big_picture.quality = ist->st->quality; }else big_picture.quality = ost->st->quality; if(!me_threshold) big_picture.pict_type = 0; big_picture.pts = AV_NOPTS_VALUE; //FIXME ret = avcodec_encode_video(enc, video_buffer, VIDEO_BUFFER_SIZE, &big_picture); //enc->frame_number = enc->real_pict_num; if(ret){ pkt.data= video_buffer; pkt.size= ret; if(enc->coded_frame) pkt.pts= enc->coded_frame->pts; if(enc->coded_frame && enc->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; av_write_frame(s, &pkt); *frame_size = ret; //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d", // enc->frame_number-1, enc->real_pict_num, ret, // enc->pict_type); /* if two pass, output log */ if (ost->logfile && enc->stats_out) { fprintf(ost->logfile, "%s", enc->stats_out); } } } ost->frame_number++; } the_end: av_free(buf); av_free(buf1); }
21,599
FFmpeg
a4f6be86d67ae30d494fbe8a470bc32b715d75a9
0
static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, H264Context *h ) { const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; tc[0] = tc0_table[index_a][bS[0]]+1; tc[1] = tc0_table[index_a][bS[1]]+1; tc[2] = tc0_table[index_a][bS[2]]+1; tc[3] = tc0_table[index_a][bS[3]]+1; h->h264dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta); } }
21,600
FFmpeg
87e302bfd8ffbc6cdb20920029013956b10ace63
0
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MpegEncContext *s = avctx->priv_data; int ret; AVFrame *pict = data; #ifdef PRINT_FRAME_TIME uint64_t time= rdtsc(); #endif #ifdef DEBUG av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size); if(buf_size>0) av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); #endif s->flags= avctx->flags; s->flags2= avctx->flags2; /* no supplementary picture */ if (buf_size == 0) { /* special case for last picture */ if (s->low_delay==0 && s->next_picture_ptr) { *pict= *(AVFrame*)s->next_picture_ptr; s->next_picture_ptr= NULL; *data_size = sizeof(AVFrame); } return 0; } if(s->flags&CODEC_FLAG_TRUNCATED){ int next; if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){ next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size); }else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){ next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size); }else{ av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n"); return -1; } if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; } retry: if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8); }else init_get_bits(&s->gb, buf, buf_size*8); s->bitstream_buffer_size=0; if (!s->context_initialized) { if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix return -1; } /* We need to set current_picture_ptr before reading the header, * otherwise we cannot store anyting in there */ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ int i= ff_find_unused_picture(s, 0); s->current_picture_ptr= &s->picture[i]; } /* let's go :-) */ if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) { ret= ff_wmv2_decode_picture_header(s); } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) { ret = msmpeg4_decode_picture_header(s); } else if (s->h263_pred) { if(s->avctx->extradata_size && s->picture_number==0){ GetBitContext gb; init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8); ret = ff_mpeg4_decode_picture_header(s, &gb); } ret = ff_mpeg4_decode_picture_header(s, &s->gb); } else if (s->codec_id == CODEC_ID_H263I) { ret = intel_h263_decode_picture_header(s); } else if (s->h263_flv) { ret = flv_h263_decode_picture_header(s); } else { ret = h263_decode_picture_header(s); } if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size); /* skip if the header was thrashed */ if (ret < 0){ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); return -1; } avctx->has_b_frames= !s->low_delay; if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){ if(s->stream_codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") || s->codec_tag == AV_RL32("RMP4")) s->xvid_build= -1; #if 0 if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1 && s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc s->xvid_build= -1; #endif } if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){ if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0) s->divx_version= 400; //divx 4 } if(s->xvid_build && s->divx_version){ s->divx_version= s->divx_build= 0; } if(s->workaround_bugs&FF_BUG_AUTODETECT){ if(s->codec_tag == AV_RL32("XVIX")) s->workaround_bugs|= FF_BUG_XVID_ILACE; if(s->codec_tag == AV_RL32("UMP4")){ s->workaround_bugs|= FF_BUG_UMP4; } if(s->divx_version>=500 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA; } if(s->divx_version>502 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA2; } if(s->xvid_build && s->xvid_build<=3) s->padding_bug_score= 256*256*256*64; if(s->xvid_build && s->xvid_build<=1) s->workaround_bugs|= FF_BUG_QPEL_CHROMA; if(s->xvid_build && s->xvid_build<=12) s->workaround_bugs|= FF_BUG_EDGE; if(s->xvid_build && s->xvid_build<=32) s->workaround_bugs|= FF_BUG_DC_CLIP; #define SET_QPEL_FUNC(postfix1, postfix2) \ s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\ s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\ s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2; if(s->lavc_build && s->lavc_build<4653) s->workaround_bugs|= FF_BUG_STD_QPEL; if(s->lavc_build && s->lavc_build<4655) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; if(s->lavc_build && s->lavc_build<4670){ s->workaround_bugs|= FF_BUG_EDGE; } if(s->lavc_build && s->lavc_build<=4712) s->workaround_bugs|= FF_BUG_DC_CLIP; if(s->divx_version) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; //printf("padding_bug_score: %d\n", s->padding_bug_score); if(s->divx_version==501 && s->divx_build==20020416) s->padding_bug_score= 256*256*256*64; if(s->divx_version && s->divx_version<500){ s->workaround_bugs|= FF_BUG_EDGE; } if(s->divx_version) s->workaround_bugs|= FF_BUG_HPEL_CHROMA; #if 0 if(s->divx_version==500) s->padding_bug_score= 256*256*256*64; /* very ugly XVID padding bug detection FIXME/XXX solve this differently * Let us hope this at least works. */ if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0 && s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0) s->workaround_bugs|= FF_BUG_NO_PADDING; if(s->lavc_build && s->lavc_build<4609) //FIXME not sure about the version num but a 4609 file seems ok s->workaround_bugs|= FF_BUG_NO_PADDING; #endif } if(s->workaround_bugs& FF_BUG_STD_QPEL){ SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c) SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c) SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c) } if(avctx->debug & FF_DEBUG_BUGS) av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build, s->divx_packed ? "p" : ""); #if 0 // dump bits per frame / qp / complexity { static FILE *f=NULL; if(!f) f=fopen("rate_qp_cplx.txt", "w"); fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale); } #endif #if HAVE_MMX if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & FF_MM_MMX)){ avctx->idct_algo= FF_IDCT_XVIDMMX; avctx->coded_width= 0; // force reinit // dsputil_init(&s->dsp, avctx); s->picture_number=0; } #endif /* After H263 & mpeg4 header decode we have the height, width,*/ /* and other parameters. So then we could init the picture */ /* FIXME: By the way H263 decoder is evolving it should have */ /* an H263EncContext */ if ( s->width != avctx->coded_width || s->height != avctx->coded_height) { /* H.263 could change picture size any time */ ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat s->parse_context.buffer=0; MPV_common_end(s); s->parse_context= pc; } if (!s->context_initialized) { avcodec_set_dimensions(avctx, s->width, s->height); goto retry; } if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I)) s->gob_index = ff_h263_get_gob_height(s); // for hurry_up==5 s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == FF_I_TYPE; /* skip B-frames if we don't have reference frames */ if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size); /* skip b frames if we are in a hurry */ if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return get_consumed_bytes(s, buf_size); if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) return get_consumed_bytes(s, buf_size); /* skip everything if we are in a hurry>=5 */ if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); if(s->next_p_frame_damaged){ if(s->pict_type==FF_B_TYPE) return get_consumed_bytes(s, buf_size); else s->next_p_frame_damaged=0; } if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==FF_B_TYPE){ s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; }else if((!s->no_rounding) || s->pict_type==FF_B_TYPE){ s->me.qpel_put= s->dsp.put_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; }else{ s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; } if(MPV_frame_start(s, avctx) < 0) return -1; if (avctx->hwaccel) { if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) return -1; } #ifdef DEBUG av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale); #endif ff_er_frame_start(s); //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type //which is not available before MPV_frame_start() if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){ ret = ff_wmv2_decode_secondary_picture_header(s); if(ret<0) return ret; if(ret==1) goto intrax8_decoded; } /* decode each macroblock */ s->mb_x=0; s->mb_y=0; decode_slice(s); while(s->mb_y<s->mb_height){ if(s->msmpeg4_version){ if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits) break; }else{ if(ff_h263_resync(s)<0) break; } if(s->msmpeg4_version<4 && s->h263_pred) ff_mpeg4_clean_buffers(s); decode_slice(s); } if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==FF_I_TYPE) if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){ s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; } /* divx 5.01+ bistream reorder stuff */ if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){ int current_pos= get_bits_count(&s->gb)>>3; int startcode_found=0; if(buf_size - current_pos > 5){ int i; for(i=current_pos; i<buf_size-3; i++){ if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){ startcode_found=1; break; } } } if(s->gb.buffer == s->bitstream_buffer && buf_size>20){ //xvid style startcode_found=1; current_pos=0; } if(startcode_found){ av_fast_malloc( &s->bitstream_buffer, &s->allocated_bitstream_buffer_size, buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE); if (!s->bitstream_buffer) return AVERROR(ENOMEM); memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos); s->bitstream_buffer_size= buf_size - current_pos; } } intrax8_decoded: ff_er_frame_end(s); if (avctx->hwaccel) { if (avctx->hwaccel->end_frame(avctx) < 0) return -1; } MPV_frame_end(s); assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); assert(s->current_picture.pict_type == s->pict_type); if (s->pict_type == FF_B_TYPE || s->low_delay) { *pict= *(AVFrame*)s->current_picture_ptr; } else if (s->last_picture_ptr != NULL) { *pict= *(AVFrame*)s->last_picture_ptr; } if(s->last_picture_ptr || s->low_delay){ *data_size = sizeof(AVFrame); ff_print_debug_info(s, pict); } /* Return the Picture timestamp as the frame number */ /* we subtract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; #ifdef PRINT_FRAME_TIME av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time); #endif return get_consumed_bytes(s, buf_size); }
21,602
FFmpeg
2636e691ce5347756a2c05b3105b0277c1b9acb4
0
static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts) { AVFrame *decoded_frame, *filtered_frame = NULL; void *buffer_to_free = NULL; int i, ret = 0; float quality; #if CONFIG_AVFILTER int frame_available = 1; #endif if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame())) return AVERROR(ENOMEM); else avcodec_get_frame_defaults(ist->decoded_frame); decoded_frame = ist->decoded_frame; pkt->pts = *pkt_pts; pkt->dts = ist->last_dts; *pkt_pts = AV_NOPTS_VALUE; ret = avcodec_decode_video2(ist->st->codec, decoded_frame, got_output, pkt); if (ret < 0) return ret; quality = same_quant ? decoded_frame->quality : 0; if (!*got_output) { /* no picture yet */ return ret; } decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts, decoded_frame->pkt_dts); pkt->size = 0; pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free); rate_emu_sleep(ist); for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = &output_streams[i]; int frame_size, resample_changed; if (!check_output_constraints(ist, ost) || !ost->encoding_needed) continue; #if CONFIG_AVFILTER resample_changed = ost->resample_width != decoded_frame->width || ost->resample_height != decoded_frame->height || ost->resample_pix_fmt != decoded_frame->format; if (resample_changed) { av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", ist->file_index, ist->st->index, ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt), decoded_frame->width, decoded_frame->height, av_get_pix_fmt_name(decoded_frame->format)); avfilter_graph_free(&ost->graph); if (configure_video_filters(ist, ost)) { av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n"); exit_program(1); } ost->resample_width = decoded_frame->width; ost->resample_height = decoded_frame->height; ost->resample_pix_fmt = decoded_frame->format; } if (ist->st->sample_aspect_ratio.num) decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; if (ist->st->codec->codec->capabilities & CODEC_CAP_DR1) { FrameBuffer *buf = decoded_frame->opaque; AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays( decoded_frame->data, decoded_frame->linesize, AV_PERM_READ | AV_PERM_PRESERVE, ist->st->codec->width, ist->st->codec->height, ist->st->codec->pix_fmt); avfilter_copy_frame_props(fb, decoded_frame); fb->buf->priv = buf; fb->buf->free = filter_release_buffer; buf->refcount++; av_buffersrc_buffer(ost->input_video_filter, fb); } else av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, decoded_frame->pts, decoded_frame->sample_aspect_ratio); if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) { av_free(buffer_to_free); return AVERROR(ENOMEM); } else avcodec_get_frame_defaults(ist->filtered_frame); filtered_frame = ist->filtered_frame; frame_available = avfilter_poll_frame(ost->output_video_filter->inputs[0]); while (frame_available) { AVRational ist_pts_tb; if (ost->output_video_filter) get_filtered_video_frame(ost->output_video_filter, filtered_frame, &ost->picref, &ist_pts_tb); if (ost->picref) filtered_frame->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); if (ost->picref->video && !ost->frame_aspect_ratio) ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect; #else filtered_frame = decoded_frame; #endif do_video_out(output_files[ost->file_index].ctx, ost, ist, filtered_frame, &frame_size, same_quant ? quality : ost->st->codec->global_quality); if (vstats_filename && frame_size) do_video_stats(output_files[ost->file_index].ctx, ost, frame_size); #if CONFIG_AVFILTER frame_available = ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]); if (ost->picref) avfilter_unref_buffer(ost->picref); } #endif } av_free(buffer_to_free); return ret; }
21,603
FFmpeg
2875745d354ab0ebc4af1ebaca5c5a8d26ccdc03
0
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags) { if (bps > 64U) return AV_CODEC_ID_NONE; if (flt) { switch (bps) { case 32: return be ? AV_CODEC_ID_PCM_F32BE : AV_CODEC_ID_PCM_F32LE; case 64: return be ? AV_CODEC_ID_PCM_F64BE : AV_CODEC_ID_PCM_F64LE; default: return AV_CODEC_ID_NONE; } } else { bps += 7; bps >>= 3; if (sflags & (1 << (bps - 1))) { switch (bps) { case 1: return AV_CODEC_ID_PCM_S8; case 2: return be ? AV_CODEC_ID_PCM_S16BE : AV_CODEC_ID_PCM_S16LE; case 3: return be ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; case 4: return be ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE; default: return AV_CODEC_ID_NONE; } } else { switch (bps) { case 1: return AV_CODEC_ID_PCM_U8; case 2: return be ? AV_CODEC_ID_PCM_U16BE : AV_CODEC_ID_PCM_U16LE; case 3: return be ? AV_CODEC_ID_PCM_U24BE : AV_CODEC_ID_PCM_U24LE; case 4: return be ? AV_CODEC_ID_PCM_U32BE : AV_CODEC_ID_PCM_U32LE; default: return AV_CODEC_ID_NONE; } } } }
21,604
FFmpeg
fe91becc2dcf32fc4bc56b00b4533d34ec3d27f5
0
static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max) { int sb, j, k, n, ch, run, channels; int joined_stereo, zero_encoding, chs; int type34_first; float type34_div = 0; float type34_predictor; float samples[10], sign_bits[16]; if (length == 0) { // If no data use noise for (sb=sb_min; sb < sb_max; sb++) build_sb_samples_from_noise (q, sb); return 0; } for (sb = sb_min; sb < sb_max; sb++) { FIX_NOISE_IDX(q->noise_idx); channels = q->nb_channels; if (q->nb_channels <= 1 || sb < 12) joined_stereo = 0; else if (sb >= 24) joined_stereo = 1; else joined_stereo = (BITS_LEFT(length,gb) >= 1) ? get_bits1 (gb) : 0; if (joined_stereo) { if (BITS_LEFT(length,gb) >= 16) for (j = 0; j < 16; j++) sign_bits[j] = get_bits1 (gb); for (j = 0; j < 64; j++) if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j]) q->coding_method[0][sb][j] = q->coding_method[1][sb][j]; fix_coding_method_array(sb, q->nb_channels, q->coding_method); channels = 1; } for (ch = 0; ch < channels; ch++) { zero_encoding = (BITS_LEFT(length,gb) >= 1) ? get_bits1(gb) : 0; type34_predictor = 0.0; type34_first = 1; for (j = 0; j < 128; ) { switch (q->coding_method[ch][sb][j / 2]) { case 8: if (BITS_LEFT(length,gb) >= 10) { if (zero_encoding) { for (k = 0; k < 5; k++) { if ((j + 2 * k) >= 128) break; samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0; } } else { n = get_bits(gb, 8); for (k = 0; k < 5; k++) samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]]; } for (k = 0; k < 5; k++) samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx); } else { for (k = 0; k < 10; k++) samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx); } run = 10; break; case 10: if (BITS_LEFT(length,gb) >= 1) { float f = 0.81; if (get_bits1(gb)) f = -f; f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0; samples[0] = f; } else { samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx); } run = 1; break; case 16: if (BITS_LEFT(length,gb) >= 10) { if (zero_encoding) { for (k = 0; k < 5; k++) { if ((j + k) >= 128) break; samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)]; } } else { n = get_bits (gb, 8); for (k = 0; k < 5; k++) samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]]; } } else { for (k = 0; k < 5; k++) samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx); } run = 5; break; case 24: if (BITS_LEFT(length,gb) >= 7) { n = get_bits(gb, 7); for (k = 0; k < 3; k++) samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5; } else { for (k = 0; k < 3; k++) samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx); } run = 3; break; case 30: if (BITS_LEFT(length,gb) >= 4) samples[0] = type30_dequant[qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1)]; else samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx); run = 1; break; case 34: if (BITS_LEFT(length,gb) >= 7) { if (type34_first) { type34_div = (float)(1 << get_bits(gb, 2)); samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0; type34_predictor = samples[0]; type34_first = 0; } else { unsigned v = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1); if (v >= FF_ARRAY_ELEMS(type34_delta)) return AVERROR_INVALIDDATA; samples[0] = type34_delta[v] / type34_div + type34_predictor; type34_predictor = samples[0]; } } else { samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx); } run = 1; break; default: samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx); run = 1; break; } if (joined_stereo) { float tmp[10][MPA_MAX_CHANNELS]; for (k = 0; k < run; k++) { tmp[k][0] = samples[k]; tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k]; } for (chs = 0; chs < q->nb_channels; chs++) for (k = 0; k < run; k++) if ((j + k) < 128) q->sb_samples[chs][j + k][sb] = q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs]; } else { for (k = 0; k < run; k++) if ((j + k) < 128) q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k]; } j += run; } // j loop } // channel loop } // subband loop return 0; }
21,605
FFmpeg
e3331706fcc9888ee85f0b9f763e4d006b178c14
0
static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) { PadContext *pad = inlink->dst->priv; AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0); int plane; inlink->dst->outputs[0]->out_buf = outpicref; for (plane = 0; plane < 4 && outpicref->data[plane]; plane++) { int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0; int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0; outpicref->data[plane] -= (pad->x >> hsub) * pad->line_step[plane] + (pad->y >> vsub) * outpicref->linesize[plane]; } outpicref->video->w = pad->w; outpicref->video->h = pad->h; avfilter_start_frame(inlink->dst->outputs[0], outpicref); }
21,606
FFmpeg
b12d21733975f9001eecb480fc28e5e4473b1327
0
static int thread_init(AVCodecContext *avctx) { int i; ThreadContext *c; int thread_count = avctx->thread_count; if (!thread_count) { int nb_cpus = get_logical_cpus(avctx); // use number of cores + 1 as thread count if there is motre than one if (nb_cpus > 1) thread_count = avctx->thread_count = nb_cpus + 1; } if (thread_count <= 1) { avctx->active_thread_type = 0; return 0; } c = av_mallocz(sizeof(ThreadContext)); if (!c) return -1; c->workers = av_mallocz(sizeof(pthread_t)*thread_count); if (!c->workers) { av_free(c); return -1; } avctx->thread_opaque = c; c->current_job = 0; c->job_count = 0; c->job_size = 0; c->done = 0; pthread_cond_init(&c->current_job_cond, NULL); pthread_cond_init(&c->last_job_cond, NULL); pthread_mutex_init(&c->current_job_lock, NULL); pthread_mutex_lock(&c->current_job_lock); for (i=0; i<thread_count; i++) { if(pthread_create(&c->workers[i], NULL, worker, avctx)) { avctx->thread_count = i; pthread_mutex_unlock(&c->current_job_lock); ff_thread_free(avctx); return -1; } } avcodec_thread_park_workers(c, thread_count); avctx->execute = avcodec_thread_execute; avctx->execute2 = avcodec_thread_execute2; return 0; }
21,608
FFmpeg
dcd3418a35aab7ef283b68ed9997ce4ac204094e
0
static av_cold int vtenc_init(AVCodecContext *avctx) { CFMutableDictionaryRef enc_info; CFMutableDictionaryRef pixel_buffer_info; CMVideoCodecType codec_type; VTEncContext *vtctx = avctx->priv_data; CFStringRef profile_level; CFBooleanRef has_b_frames_cfbool; CFNumberRef gamma_level = NULL; int status; codec_type = get_cm_codec_type(avctx->codec_id); if (!codec_type) { av_log(avctx, AV_LOG_ERROR, "Error: no mapping for AVCodecID %d\n", avctx->codec_id); return AVERROR(EINVAL); } vtctx->has_b_frames = avctx->max_b_frames > 0; if(vtctx->has_b_frames && vtctx->profile == H264_PROF_BASELINE){ av_log(avctx, AV_LOG_WARNING, "Cannot use B-frames with baseline profile. Output will not contain B-frames.\n"); vtctx->has_b_frames = false; } if (vtctx->entropy == VT_CABAC && vtctx->profile == H264_PROF_BASELINE) { av_log(avctx, AV_LOG_WARNING, "CABAC entropy requires 'main' or 'high' profile, but baseline was requested. Encode will not use CABAC entropy.\n"); vtctx->entropy = VT_ENTROPY_NOT_SET; } if (!get_vt_profile_level(avctx, &profile_level)) return AVERROR(EINVAL); vtctx->session = NULL; enc_info = CFDictionaryCreateMutable( kCFAllocatorDefault, 20, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ); if (!enc_info) return AVERROR(ENOMEM); #if !TARGET_OS_IPHONE if (!vtctx->allow_sw) { CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, kCFBooleanTrue); } else { CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, kCFBooleanTrue); } #endif if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) { status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info); if (status) goto init_cleanup; } else { pixel_buffer_info = NULL; } pthread_mutex_init(&vtctx->lock, NULL); pthread_cond_init(&vtctx->cv_sample_sent, NULL); vtctx->dts_delta = vtctx->has_b_frames ? -1 : 0; get_cv_transfer_function(avctx, &vtctx->transfer_function, &gamma_level); get_cv_ycbcr_matrix(avctx, &vtctx->ycbcr_matrix); get_cv_color_primaries(avctx, &vtctx->color_primaries); if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { status = vtenc_populate_extradata(avctx, codec_type, profile_level, gamma_level, enc_info, pixel_buffer_info); if (status) goto init_cleanup; } status = vtenc_create_encoder(avctx, codec_type, profile_level, gamma_level, enc_info, pixel_buffer_info, &vtctx->session); if (status < 0) goto init_cleanup; status = VTSessionCopyProperty(vtctx->session, kVTCompressionPropertyKey_AllowFrameReordering, kCFAllocatorDefault, &has_b_frames_cfbool); if (!status) { //Some devices don't output B-frames for main profile, even if requested. vtctx->has_b_frames = CFBooleanGetValue(has_b_frames_cfbool); CFRelease(has_b_frames_cfbool); } avctx->has_b_frames = vtctx->has_b_frames; init_cleanup: if (gamma_level) CFRelease(gamma_level); if (pixel_buffer_info) CFRelease(pixel_buffer_info); CFRelease(enc_info); return status; }
21,609
FFmpeg
550bda741cfe0e471a70e40529a9ab02d31b7049
1
av_cold void ff_dsputil_init_alpha(DSPContext *c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; /* amask clears all bits that correspond to present features. */ if (amask(AMASK_MVI) == 0) { c->put_pixels_clamped = put_pixels_clamped_mvi_asm; c->add_pixels_clamped = add_pixels_clamped_mvi_asm; if (!high_bit_depth) c->get_pixels = get_pixels_mvi; c->diff_pixels = diff_pixels_mvi; c->sad[0] = pix_abs16x16_mvi_asm; c->sad[1] = pix_abs8x8_mvi; c->pix_abs[0][0] = pix_abs16x16_mvi_asm; c->pix_abs[1][0] = pix_abs8x8_mvi; c->pix_abs[0][1] = pix_abs16x16_x2_mvi; c->pix_abs[0][2] = pix_abs16x16_y2_mvi; c->pix_abs[0][3] = pix_abs16x16_xy2_mvi; } put_pixels_clamped_axp_p = c->put_pixels_clamped; add_pixels_clamped_axp_p = c->add_pixels_clamped; if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 && (avctx->idct_algo == FF_IDCT_AUTO || avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) { c->idct_put = ff_simple_idct_put_axp; c->idct_add = ff_simple_idct_add_axp; c->idct = ff_simple_idct_axp; } }
21,610
FFmpeg
b2be76c0a472b729756ed7a91225c209d0dd1d2e
1
static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx, RowContext *row, int n, int index_bits, int level_bias, int level_shift, int dc_shift) { int i, j, index1, index2, len, flags; int level, component, sign; const int *scale; const uint8_t *weight_matrix; const uint8_t *ac_info = ctx->cid_table->ac_info; int16_t *block = row->blocks[n]; const int eob_index = ctx->cid_table->eob_index; int ret = 0; OPEN_READER(bs, &row->gb); ctx->bdsp.clear_block(block); if (!ctx->is_444) { if (n & 2) { component = 1 + (n & 1); scale = row->chroma_scale; weight_matrix = ctx->cid_table->chroma_weight; } else { component = 0; scale = row->luma_scale; weight_matrix = ctx->cid_table->luma_weight; } } else { component = (n >> 1) % 3; if (component) { scale = row->chroma_scale; weight_matrix = ctx->cid_table->chroma_weight; } else { scale = row->luma_scale; weight_matrix = ctx->cid_table->luma_weight; } } UPDATE_CACHE(bs, &row->gb); GET_VLC(len, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1); if (len) { level = GET_CACHE(bs, &row->gb); LAST_SKIP_BITS(bs, &row->gb, len); sign = ~level >> 31; level = (NEG_USR32(sign ^ level, len) ^ sign) - sign; row->last_dc[component] += level * (1 << dc_shift); } block[0] = row->last_dc[component]; i = 0; UPDATE_CACHE(bs, &row->gb); GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2); while (index1 != eob_index) { level = ac_info[2*index1+0]; flags = ac_info[2*index1+1]; sign = SHOW_SBITS(bs, &row->gb, 1); SKIP_BITS(bs, &row->gb, 1); if (flags & 1) { level += SHOW_UBITS(bs, &row->gb, index_bits) << 7; SKIP_BITS(bs, &row->gb, index_bits); } if (flags & 2) { UPDATE_CACHE(bs, &row->gb); GET_VLC(index2, bs, &row->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2); i += ctx->cid_table->run[index2]; } if (++i > 63) { av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i); ret = -1; break; } j = ctx->scantable.permutated[i]; level *= scale[i]; level += scale[i] >> 1; if (level_bias < 32 || weight_matrix[i] != level_bias) level += level_bias; // 1<<(level_shift-1) level >>= level_shift; block[j] = (level ^ sign) - sign; UPDATE_CACHE(bs, &row->gb); GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2); } CLOSE_READER(bs, &row->gb); return ret; }
21,611
qemu
f5855994fee2f8815dc86b8453e4a63e290aea05
0
static void pci_write(void *opaque, hwaddr addr, uint64_t data, unsigned int size) { AcpiPciHpState *s = opaque; switch (addr) { case PCI_EJ_BASE: if (s->hotplug_select >= ACPI_PCIHP_MAX_HOTPLUG_BUS) { break; } acpi_pcihp_eject_slot(s, s->hotplug_select, data); ACPI_PCIHP_DPRINTF("pciej write %" HWADDR_PRIx " <== %" PRIu64 "\n", addr, data); break; case PCI_SEL_BASE: s->hotplug_select = data; ACPI_PCIHP_DPRINTF("pcisel write %" HWADDR_PRIx " <== %" PRIu64 "\n", addr, data); default: break; } }
21,613
qemu
f17fd4fdf0df3d2f3444399d04c38d22b9a3e1b7
0
int64_t qemu_strtosz(const char *nptr, char **end) { return do_strtosz(nptr, end, 'B', 1024); }
21,614