static int vc1_decode_p_mb_intfi(VC1Context *v) { MpegEncContext *s = &v->s; GetBitContext *gb = &s->gb; int i; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; int cbp = 0; /* cbp decoding stuff */ int mqdiff, mquant; /* MB quantization */ int ttmb = v->ttfrm; /* MB Transform type */ int mb_has_coeffs = 1; /* last_flag */ int dmv_x, dmv_y; /* Differential MV components */ int val; /* temp values */ int first_block = 1; int dst_idx, off; int pred_flag = 0; int block_cbp = 0, pat, block_tt = 0; int idx_mbmode = 0; mquant = v->pq; /* Lossy initialization */ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2); if (idx_mbmode <= 1) { // intra MB v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1. s->mb_intra = 1; s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0; s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0; s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA; GET_MQUANT(); s->current_picture.qscale_table[mb_pos] = mquant; /* Set DC scale - y and c use the same (not sure if necessary here) */ s->y_dc_scale = s->y_dc_scale_table[mquant]; s->c_dc_scale = s->c_dc_scale_table[mquant]; v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb); mb_has_coeffs = idx_mbmode & 1; if (mb_has_coeffs) cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2); dst_idx = 0; for (i = 0; i < 6; i++) { v->a_avail = v->c_avail = 0; v->mb_type[0][s->block_index[i]] = 1; s->dc_val[0][s->block_index[i]] = 0; dst_idx += i >> 2; val = ((cbp >> (5 - i)) & 1); if (i == 2 || i == 3 || !s->first_slice_line) v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i & 4) ? v->codingset2 : v->codingset); if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); s->idsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); // TODO: loop filter } } else { s->mb_intra = v->is_intra[s->mb_x] = 0; s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16; for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0; if (idx_mbmode <= 5) { // 1-MV dmv_x = dmv_y = pred_flag = 0; if (idx_mbmode & 1) { get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag); } ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0); ff_vc1_mc_1mv(v, 0); mb_has_coeffs = !(idx_mbmode & 2); } else { // 4-MV v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1); for (i = 0; i < 6; i++) { if (i < 4) { dmv_x = dmv_y = pred_flag = 0; val = ((v->fourmvbp >> (3 - i)) & 1); if (val) { get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag); } ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0); ff_vc1_mc_4mv_luma(v, i, 0, 0); } else if (i == 4) ff_vc1_mc_4mv_chroma(v, 0); } mb_has_coeffs = idx_mbmode & 1; } if (mb_has_coeffs) cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); if (cbp) { GET_MQUANT(); } s->current_picture.qscale_table[mb_pos] = mquant; if (!v->ttmbf && cbp) { ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); } dst_idx = 0; for (i = 0; i < 6; i++) { s->dc_val[0][s->block_index[i]] = 0; dst_idx += i >> 2; val = ((cbp >> (5 - i)) & 1); off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize; if (val) { pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize, (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt); block_cbp |= pat << (i << 2); if (!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; } } } if (s->mb_x == s->mb_width - 1) memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride); return 0; }


static bool virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOSCSI *s = VIRTIO_SCSI(vdev); assert(s->ctx && s->dataplane_started); return virtio_scsi_handle_ctrl_vq(s, vq); }


static void start_tcg_kick_timer(void) { if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) { tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, kick_tcg_thread, NULL); timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); } }


static void rtc_periodic_timer(void *opaque) { RTCState *s = opaque; rtc_timer_update(s, s->next_periodic_time); #ifdef TARGET_I386 if ((s->cmos_data[RTC_REG_C] & 0xc0) && rtc_td_hack) { s->irq_coalesced++; return; } #endif if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |= 0xc0; rtc_irq_raise(s->irq); } if (s->cmos_data[RTC_REG_B] & REG_B_SQWE) { /* Not square wave at all but we don't want 2048Hz interrupts! Must be seen as a pulse. */ qemu_irq_raise(s->sqw_irq); } }


void do_m68k_semihosting(CPUM68KState *env, int nr) { uint32_t args; void *p; void *q; uint32_t len; uint32_t result; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: gdb_exit(env, env->dregs[0]); exit(env->dregs[0]); case HOSTED_OPEN: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", ARG(0), (int)ARG(1), ARG(2), ARG(3)); return; } else { if (!(p = lock_user_string(ARG(0)))) { /* FIXME - check error code? */ result = -1; } else { result = open(p, translate_openflags(ARG(2)), ARG(3)); unlock_user(p, ARG(0), 0); } } break; case HOSTED_CLOSE: { /* Ignore attempts to close stdin/out/err. */ int fd = ARG(0); if (fd > 2) { if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "close,%x", ARG(0)); return; } else { result = close(fd); } } else { result = 0; } break; } case HOSTED_READ: len = ARG(2); if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x", ARG(0), ARG(1), len); return; } else { if (!(p = lock_user(VERIFY_WRITE, ARG(1), len, 0))) { /* FIXME - check error code? */ result = -1; } else { result = read(ARG(0), p, len); unlock_user(p, ARG(1), len); } } break; case HOSTED_WRITE: len = ARG(2); if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x", ARG(0), ARG(1), len); return; } else { if (!(p = lock_user(VERIFY_READ, ARG(1), len, 1))) { /* FIXME - check error code? */ result = -1; } else { result = write(ARG(0), p, len); unlock_user(p, ARG(0), 0); } } break; case HOSTED_LSEEK: { uint64_t off; off = (uint32_t)ARG(2) | ((uint64_t)ARG(1) << 32); if (use_gdb_syscalls()) { m68k_semi_is_fseek = 1; gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x", ARG(0), off, ARG(3)); } else { off = lseek(ARG(0), off, ARG(3)); /* FIXME - handle put_user() failure */ put_user_u32(off >> 32, args); put_user_u32(off, args + 4); put_user_u32(errno, args + 8); } return; } case HOSTED_RENAME: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "rename,%s,%s", ARG(0), (int)ARG(1), ARG(2), (int)ARG(3)); return; } else { p = lock_user_string(ARG(0)); q = lock_user_string(ARG(2)); if (!p || !q) { /* FIXME - check error code? */ result = -1; } else { result = rename(p, q); } unlock_user(p, ARG(0), 0); unlock_user(q, ARG(2), 0); } break; case HOSTED_UNLINK: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "unlink,%s", ARG(0), (int)ARG(1)); return; } else { if (!(p = lock_user_string(ARG(0)))) { /* FIXME - check error code? */ result = -1; } else { result = unlink(p); unlock_user(p, ARG(0), 0); } } break; case HOSTED_STAT: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "stat,%s,%x", ARG(0), (int)ARG(1), ARG(2)); return; } else { struct stat s; if (!(p = lock_user_string(ARG(0)))) { /* FIXME - check error code? */ result = -1; } else { result = stat(p, &s); unlock_user(p, ARG(0), 0); } if (result == 0) { translate_stat(env, ARG(2), &s); } } break; case HOSTED_FSTAT: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x", ARG(0), ARG(1)); return; } else { struct stat s; result = fstat(ARG(0), &s); if (result == 0) { translate_stat(env, ARG(1), &s); } } break; case HOSTED_GETTIMEOFDAY: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x", ARG(0), ARG(1)); return; } else { qemu_timeval tv; struct gdb_timeval *p; result = qemu_gettimeofday(&tv); if (result != 0) { if (!(p = lock_user(VERIFY_WRITE, ARG(0), sizeof(struct gdb_timeval), 0))) { /* FIXME - check error code? */ result = -1; } else { p->tv_sec = cpu_to_be32(tv.tv_sec); p->tv_usec = cpu_to_be64(tv.tv_usec); unlock_user(p, ARG(0), sizeof(struct gdb_timeval)); } } } break; case HOSTED_ISATTY: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "isatty,%x", ARG(0)); return; } else { result = isatty(ARG(0)); } break; case HOSTED_SYSTEM: if (use_gdb_syscalls()) { gdb_do_syscall(m68k_semi_cb, "system,%s", ARG(0), (int)ARG(1)); return; } else { if (!(p = lock_user_string(ARG(0)))) { /* FIXME - check error code? */ result = -1; } else { result = system(p); unlock_user(p, ARG(0), 0); } } break; case HOSTED_INIT_SIM: #if defined(CONFIG_USER_ONLY) { TaskState *ts = env->opaque; /* Allocate the heap using sbrk. */ if (!ts->heap_limit) { long ret; uint32_t size; uint32_t base; base = do_brk(0); size = SEMIHOSTING_HEAP_SIZE; /* Try a big heap, and reduce the size if that fails. */ for (;;) { ret = do_brk(base + size); if (ret != -1) break; size >>= 1; } ts->heap_limit = base + size; } /* This call may happen before we have writable memory, so return values directly in registers. */ env->dregs[1] = ts->heap_limit; env->aregs[7] = ts->stack_base; } #else /* FIXME: This is wrong for boards where RAM does not start at address zero. */ env->dregs[1] = ram_size; env->aregs[7] = ram_size; #endif return; default: cpu_abort(env, "Unsupported semihosting syscall %d\n", nr); result = 0; } /* FIXME - handle put_user() failure */ put_user_u32(result, args); put_user_u32(errno, args + 4); }


static uint8_t get_tlm(Jpeg2000DecoderContext *s, int n) { uint8_t Stlm, ST, SP, tile_tlm, i; bytestream_get_byte(&s->buf); /* Ztlm: skipped */ Stlm = bytestream_get_byte(&s->buf); // too complex ? ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02); ST = (Stlm >> 4) & 0x03; // TODO: Manage case of ST = 0b11 --> raise error SP = (Stlm >> 6) & 0x01; tile_tlm = (n - 4) / ((SP + 1) * 2 + ST); for (i = 0; i < tile_tlm; i++) { switch (ST) { case 0: break; case 1: bytestream_get_byte(&s->buf); break; case 2: bytestream_get_be16(&s->buf); break; case 3: bytestream_get_be32(&s->buf); break; } if (SP == 0) { bytestream_get_be16(&s->buf); } else { bytestream_get_be32(&s->buf); } } return 0; }


static int decode_seq_header(AVSContext *h) { MpegEncContext *s = &h->s; int frame_rate_code; int width, height; h->profile = get_bits(&s->gb,8); h->level = get_bits(&s->gb,8); skip_bits1(&s->gb); //progressive sequence width = get_bits(&s->gb,14); height = get_bits(&s->gb,14); if ((s->width || s->height) && (s->width != width || s->height != height)) { av_log_missing_feature(s, "Width/height changing in CAVS is", 0); return -1; s->width = width; s->height = height; skip_bits(&s->gb,2); //chroma format skip_bits(&s->gb,3); //sample_precision h->aspect_ratio = get_bits(&s->gb,4); frame_rate_code = get_bits(&s->gb,4); skip_bits(&s->gb,18);//bit_rate_lower skip_bits1(&s->gb); //marker_bit skip_bits(&s->gb,12);//bit_rate_upper s->low_delay = get_bits1(&s->gb); h->mb_width = (s->width + 15) >> 4; h->mb_height = (s->height + 15) >> 4; h->s.avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_code].num; h->s.avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_code].den; h->s.avctx->width = s->width; h->s.avctx->height = s->height; if(!h->top_qp) ff_cavs_init_top_lines(h); return 0;


static int qemu_chr_open_win_pipe(QemuOpts *opts, CharDriverState **_chr) { const char *filename = qemu_opt_get(opts, "path"); CharDriverState *chr; WinCharState *s; chr = g_malloc0(sizeof(CharDriverState)); s = g_malloc0(sizeof(WinCharState)); chr->opaque = s; chr->chr_write = win_chr_write; chr->chr_close = win_chr_close; if (win_chr_pipe_init(chr, filename) < 0) { g_free(s); g_free(chr); return -EIO; } qemu_chr_generic_open(chr); *_chr = chr; return 0; }


SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, bool has_id, const char *id, bool has_name, const char *name, Error **errp) { BlockDriverState *bs = bdrv_find(device); QEMUSnapshotInfo sn; Error *local_err = NULL; SnapshotInfo *info = NULL; int ret; if (!bs) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return NULL; } if (!has_id) { id = NULL; } if (!has_name) { name = NULL; } if (!id && !name) { error_setg(errp, "Name or id must be provided"); return NULL; } ret = bdrv_snapshot_find_by_id_and_name(bs, id, name, &sn, &local_err); if (local_err) { error_propagate(errp, local_err); return NULL; } if (!ret) { error_setg(errp, "Snapshot with id '%s' and name '%s' does not exist on " "device '%s'", STR_OR_NULL(id), STR_OR_NULL(name), device); return NULL; } bdrv_snapshot_delete(bs, id, name, &local_err); if (local_err) { error_propagate(errp, local_err); return NULL; } info = g_malloc0(sizeof(SnapshotInfo)); info->id = g_strdup(sn.id_str); info->name = g_strdup(sn.name); info->date_nsec = sn.date_nsec; info->date_sec = sn.date_sec; info->vm_state_size = sn.vm_state_size; info->vm_clock_nsec = sn.vm_clock_nsec % 1000000000; info->vm_clock_sec = sn.vm_clock_nsec / 1000000000; return info; }


static int proxy_socket(const char *path, uid_t uid, gid_t gid) { int sock, client; struct sockaddr_un proxy, qemu; socklen_t size; /* requested socket already exists, refuse to start */ if (!access(path, F_OK)) { do_log(LOG_CRIT, "socket already exists\n"); return -1; } sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { do_perror("socket"); return -1; } /* mask other part of mode bits */ umask(7); proxy.sun_family = AF_UNIX; strcpy(proxy.sun_path, path); if (bind(sock, (struct sockaddr *)&proxy, sizeof(struct sockaddr_un)) < 0) { do_perror("bind"); goto error; } if (chown(proxy.sun_path, uid, gid) < 0) { do_perror("chown"); goto error; } if (listen(sock, 1) < 0) { do_perror("listen"); goto error; } size = sizeof(qemu); client = accept(sock, (struct sockaddr *)&qemu, &size); if (client < 0) { do_perror("accept"); goto error; } close(sock); return client; error: close(sock); return -1; }


void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) { /* * Note: this always allocates at least one extra page of virtual address * space, even if size is already aligned. */ size_t total = size + align; void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr; void *ptr1; if (ptr == MAP_FAILED) { return NULL; } /* Make sure align is a power of 2 */ assert(!(align & (align - 1))); /* Always align to host page size */ assert(align >= getpagesize()); ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE, MAP_FIXED | (fd == -1 ? MAP_ANONYMOUS : 0) | (shared ? MAP_SHARED : MAP_PRIVATE), fd, 0); if (ptr1 == MAP_FAILED) { munmap(ptr, total); return NULL; } ptr += offset; total -= offset; if (offset > 0) { munmap(ptr - offset, offset); } /* * Leave a single PROT_NONE page allocated after the RAM block, to serve as * a guard page guarding against potential buffer overflows. */ if (total > size + getpagesize()) { munmap(ptr + size + getpagesize(), total - size - getpagesize()); } return ptr; }


start_list(Visitor *v, const char *name, Error **errp) { StringInputVisitor *siv = to_siv(v); parse_str(siv, errp); siv->cur_range = g_list_first(siv->ranges); if (siv->cur_range) { Range *r = siv->cur_range->data; if (r) { siv->cur = r->begin; } } }


void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value) { uint16_t *copy; copy = g_malloc(sizeof(value)); *copy = cpu_to_le16(value); fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value)); }


void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, ptrdiff_t linesize_arg, int block_w, int block_h, int src_x, int src_y, int w, int h) { int x, y; int start_y, start_x, end_y, end_x; emuedge_linesize_type linesize = linesize_arg; if (!w || !h) return; if (src_y >= h) { src -= src_y * linesize; src += (h - 1) * linesize; src_y = h - 1; } else if (src_y <= -block_h) { src -= src_y * linesize; src += (1 - block_h) * linesize; src_y = 1 - block_h; } if (src_x >= w) { src += (w - 1 - src_x) * sizeof(pixel); src_x = w - 1; } else if (src_x <= -block_w) { src += (1 - block_w - src_x) * sizeof(pixel); src_x = 1 - block_w; } start_y = FFMAX(0, -src_y); start_x = FFMAX(0, -src_x); end_y = FFMIN(block_h, h-src_y); end_x = FFMIN(block_w, w-src_x); av_assert2(start_y < end_y && block_h); av_assert2(start_x < end_x && block_w); w = end_x - start_x; src += start_y * linesize + start_x * sizeof(pixel); buf += start_x * sizeof(pixel); // top for (y = 0; y < start_y; y++) { memcpy(buf, src, w * sizeof(pixel)); buf += linesize; } // copy existing part for (; y < end_y; y++) { memcpy(buf, src, w * sizeof(pixel)); src += linesize; buf += linesize; } // bottom src -= linesize; for (; y < block_h; y++) { memcpy(buf, src, w * sizeof(pixel)); buf += linesize; } buf -= block_h * linesize + start_x * sizeof(pixel); while (block_h--) { pixel *bufp = (pixel *) buf; // left for(x = 0; x < start_x; x++) { bufp[x] = bufp[start_x]; } // right for (x = end_x; x < block_w; x++) { bufp[x] = bufp[end_x - 1]; } buf += linesize; } }


static int draw_glyphs(DrawTextContext *s, AVFrame *frame, int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y) { char *text = HAVE_LOCALTIME_R ? s->expanded_text : s->text; uint32_t code = 0; int i; uint8_t *p; Glyph *glyph = NULL; for (i = 0, p = text; *p; i++) { Glyph dummy = { 0 }; GET_UTF8(code, *p++, continue;); /* skip new line chars, just go to new line */ if (code == '\n' || code == '\r' || code == '\t') continue; dummy.code = code; glyph = av_tree_find(s->glyphs, &dummy, (void *)glyph_cmp, NULL); if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) return AVERROR(EINVAL); if (s->is_packed_rgb) { draw_glyph_rgb(frame, &glyph->bitmap, s->positions[i].x+x, s->positions[i].y+y, width, height, s->pixel_step[0], rgbcolor, s->rgba_map, s->alpha); } else { draw_glyph_yuv(frame, &glyph->bitmap, s->positions[i].x+x, s->positions[i].y+y, width, height, yuvcolor, s->hsub, s->vsub, s->alpha); } } return 0; }


static void test_lifecycle(void) { Coroutine *coroutine; bool done = false; /* Create, enter, and return from coroutine */ coroutine = qemu_coroutine_create(set_and_exit); qemu_coroutine_enter(coroutine, &done); g_assert(done); /* expect done to be true (first time) */ /* Repeat to check that no state affects this test */ done = false; coroutine = qemu_coroutine_create(set_and_exit); qemu_coroutine_enter(coroutine, &done); g_assert(done); /* expect done to be true (second time) */ }


static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index, uint8_t *base_lag_int, int subframe, enum Mode mode) { if (subframe == 0 || (subframe == 2 && mode != MODE_6k60)) { if (pitch_index < 116) { *lag_int = (pitch_index + 69) >> 1; *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1; } else { *lag_int = pitch_index - 24; *lag_frac = 0; } // XXX: same problem as before *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0), AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15); } else { *lag_int = (pitch_index + 1) >> 1; *lag_frac = (pitch_index - (*lag_int << 1)) << 1; *lag_int += *base_lag_int; } }


void qpci_io_writel(QPCIDevice *dev, void *data, uint32_t value) { uintptr_t addr = (uintptr_t)data; if (addr < QPCI_PIO_LIMIT) { dev->bus->pio_writel(dev->bus, addr, value); } else { value = cpu_to_le32(value); dev->bus->memwrite(dev->bus, addr, &value, sizeof(value)); } }


void do_store_xer (void) { xer_so = (T0 >> XER_SO) & 0x01; xer_ov = (T0 >> XER_OV) & 0x01; xer_ca = (T0 >> XER_CA) & 0x01; xer_cmp = (T0 >> XER_CMP) & 0xFF; xer_bc = (T0 >> XER_BC) & 0x3F; }


int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options) { int ret = ffurl_alloc(puc, filename, flags, int_cb); if (ret < 0) return ret; if (options && (*puc)->prot->priv_data_class && (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0) goto fail; if ((ret = av_opt_set_dict(*puc, options)) < 0) goto fail; ret = ffurl_connect(*puc, options); if (!ret) return 0; fail: ffurl_close(*puc); *puc = NULL; return ret; }


static int mpeg4_decode_video_packet_header(MpegEncContext *s) { int mb_num_bits= av_log2(s->mb_num - 1) + 1; int header_extension=0, mb_num, len; /* is there enough space left for a video packet + header */ if( get_bits_count(&s->gb) > s->gb.size*8-20) return -1; for(len=0; len<32; len++){ if(get_bits1(&s->gb)) break; } if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){ printf("marker does not match f_code\n"); return -1; } if(s->shape != RECT_SHAPE){ header_extension= get_bits1(&s->gb); //FIXME more stuff here } mb_num= get_bits(&s->gb, mb_num_bits); if(mb_num>=s->mb_num){ fprintf(stderr, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); return -1; } s->mb_x= mb_num % s->mb_width; s->mb_y= mb_num / s->mb_width; if(s->shape != BIN_ONLY_SHAPE){ int qscale= get_bits(&s->gb, s->quant_precision); if(qscale) s->qscale= qscale; } if(s->shape == RECT_SHAPE){ header_extension= get_bits1(&s->gb); } if(header_extension){ int time_increment; int time_incr=0; while (get_bits1(&s->gb) != 0) time_incr++; check_marker(&s->gb, "before time_increment in video packed header"); time_increment= get_bits(&s->gb, s->time_increment_bits); check_marker(&s->gb, "before vop_coding_type in video packed header"); skip_bits(&s->gb, 2); /* vop coding type */ //FIXME not rect stuff here if(s->shape != BIN_ONLY_SHAPE){ skip_bits(&s->gb, 3); /* intra dc vlc threshold */ //FIXME dont just ignore everything if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ mpeg4_decode_sprite_trajectory(s); fprintf(stderr, "untested\n"); } //FIXME reduced res stuff here if (s->pict_type != I_TYPE) { int f_code = get_bits(&s->gb, 3); /* fcode_for */ if(f_code==0){ printf("Error, video packet header damaged (f_code=0)\n"); } } if (s->pict_type == B_TYPE) { int b_code = get_bits(&s->gb, 3); if(b_code==0){ printf("Error, video packet header damaged (b_code=0)\n"); } } } } //FIXME new-pred stuff //printf("parse ok %d %d %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width, get_bits_count(gb), get_bits_count(&s->gb)); return 0; }


int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad) { AVFilterLink *link; if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad || src->outputs[srcpad] || dst->inputs[dstpad]) return -1; if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) { av_log(src, AV_LOG_ERROR, "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n", src->name, srcpad, dst->name, dstpad); return AVERROR(EINVAL); } src->outputs[srcpad] = dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink)); link->src = src; link->dst = dst; link->srcpad = &src->output_pads[srcpad]; link->dstpad = &dst->input_pads[dstpad]; link->type = src->output_pads[srcpad].type; assert(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1); link->format = -1; return 0; }


static void usage(void) { printf("Escape an input string, adopting the av_get_token() escaping logic\n"); printf("usage: ffescape [OPTIONS]\n"); printf("\n" "Options:\n" "-e echo each input line on output\n" "-h print this help\n" "-i INFILE set INFILE as input file, stdin if omitted\n" "-l LEVEL set the number of escaping levels, 1 if omitted\n" "-m ESCAPE_MODE select escape mode between 'full', 'lazy', 'quote', default is 'lazy'\n" "-o OUTFILE set OUTFILE as output file, stdout if omitted\n" "-p PROMPT set output prompt, is '=> ' by default\n" "-s SPECIAL_CHARS set the list of special characters\n"); }


static inline void mpeg_motion(MpegEncContext *s, UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, int dest_offset, UINT8 **ref_picture, int src_offset, int field_based, op_pixels_func *pix_op, int motion_x, int motion_y, int h) { UINT8 *ptr; int dxy, offset, mx, my, src_x, src_y, height, linesize; if(s->quarter_sample) { motion_x>>=1; motion_y>>=1; } dxy = ((motion_y & 1) << 1) | (motion_x & 1); src_x = s->mb_x * 16 + (motion_x >> 1); src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); /* WARNING: do no forget half pels */ height = s->height >> field_based; src_x = clip(src_x, -16, s->width); if (src_x == s->width) dxy &= ~1; src_y = clip(src_y, -16, height); if (src_y == height) dxy &= ~2; linesize = s->linesize << field_based; ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; dest_y += dest_offset; pix_op[dxy](dest_y, ptr, linesize, h); pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); if (s->out_format == FMT_H263) { dxy = 0; if ((motion_x & 3) != 0) dxy |= 1; if ((motion_y & 3) != 0) dxy |= 2; mx = motion_x >> 2; my = motion_y >> 2; } else { mx = motion_x / 2; my = motion_y / 2; dxy = ((my & 1) << 1) | (mx & 1); mx >>= 1; my >>= 1; } src_x = s->mb_x * 8 + mx; src_y = s->mb_y * (8 >> field_based) + my; src_x = clip(src_x, -8, s->width >> 1); if (src_x == (s->width >> 1)) dxy &= ~1; src_y = clip(src_y, -8, height >> 1); if (src_y == (height >> 1)) dxy &= ~2; offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); ptr = ref_picture[1] + offset; pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); ptr = ref_picture[2] + offset; pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); }


av_cold void ff_audio_convert_init_x86(AudioConvert *ac) { int cpu_flags = av_get_cpu_flags(); if (EXTERNAL_MMX(cpu_flags)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx); } if (EXTERNAL_SSE(cpu_flags)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP, 6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, 2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, 2, 16, 4, "SSE", ff_conv_flt_to_fltp_2ch_sse); } if (EXTERNAL_SSE2(cpu_flags)) { if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, 6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP, 6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2); } else { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, 6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow); } ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16, 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32, 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT, 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, 2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P, 2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P, 6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP, 2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 6, 16, 4, "SSE2", ff_conv_s16_to_s16p_6ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, 2, 16, 8, "SSE2", ff_conv_s16_to_fltp_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, 6, 16, 4, "SSE2", ff_conv_s16_to_fltp_6ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT, 2, 16, 8, "SSE2", ff_conv_flt_to_s16p_2ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT, 6, 16, 4, "SSE2", ff_conv_flt_to_s16p_6ch_sse2); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, 6, 16, 4, "SSE2", ff_conv_flt_to_fltp_6ch_sse2); } if (EXTERNAL_SSSE3(cpu_flags)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P, 6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP, 2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 6, 16, 4, "SSSE3", ff_conv_s16_to_s16p_6ch_ssse3); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, 6, 16, 4, "SSSE3", ff_conv_s16_to_fltp_6ch_ssse3); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT, 6, 16, 4, "SSSE3", ff_conv_flt_to_s16p_6ch_ssse3); } if (EXTERNAL_SSE4(cpu_flags)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, 6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4); } if (EXTERNAL_AVX(cpu_flags)) { ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32, 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, 2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, 6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P, 2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P, 6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP, 6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16, 6, 16, 4, "AVX", ff_conv_s16_to_s16p_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, 2, 16, 8, "AVX", ff_conv_s16_to_fltp_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, 6, 16, 4, "AVX", ff_conv_s16_to_fltp_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT, 2, 16, 8, "AVX", ff_conv_flt_to_s16p_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT, 6, 16, 4, "AVX", ff_conv_flt_to_s16p_6ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, 2, 16, 4, "AVX", ff_conv_flt_to_fltp_2ch_avx); ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT, 6, 16, 4, "AVX", ff_conv_flt_to_fltp_6ch_avx); } }


static void virtio_pci_config_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { VirtIOPCIProxy *proxy = opaque; uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); if (addr < config) { virtio_ioport_write(proxy, addr, val); return; } addr -= config; /* * Virtio-PCI is odd. Ioports are LE but config space is target native * endian. */ switch (size) { case 1: virtio_config_writeb(vdev, addr, val); break; case 2: if (virtio_is_big_endian()) { val = bswap16(val); } virtio_config_writew(vdev, addr, val); break; case 4: if (virtio_is_big_endian()) { val = bswap32(val); } virtio_config_writel(vdev, addr, val); break; } }


void *qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr) { QPCIBus *bus = dev->bus; static const int bar_reg_map[] = { PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2, PCI_BASE_ADDRESS_3, PCI_BASE_ADDRESS_4, PCI_BASE_ADDRESS_5, }; int bar_reg; uint32_t addr, size; uint32_t io_type; uint64_t loc; g_assert(barno >= 0 && barno <= 5); bar_reg = bar_reg_map[barno]; qpci_config_writel(dev, bar_reg, 0xFFFFFFFF); addr = qpci_config_readl(dev, bar_reg); io_type = addr & PCI_BASE_ADDRESS_SPACE; if (io_type == PCI_BASE_ADDRESS_SPACE_IO) { addr &= PCI_BASE_ADDRESS_IO_MASK; } else { addr &= PCI_BASE_ADDRESS_MEM_MASK; } g_assert(addr); /* Must have *some* size bits */ size = 1U << ctz32(addr); if (sizeptr) { *sizeptr = size; } if (io_type == PCI_BASE_ADDRESS_SPACE_IO) { loc = QEMU_ALIGN_UP(bus->pio_alloc_ptr, size); g_assert(loc >= bus->pio_alloc_ptr); g_assert(loc + size <= QPCI_PIO_LIMIT); /* Keep PIO below 64kiB */ bus->pio_alloc_ptr = loc + size; qpci_config_writel(dev, bar_reg, loc | PCI_BASE_ADDRESS_SPACE_IO); } else { loc = QEMU_ALIGN_UP(bus->mmio_alloc_ptr, size); /* Check for space */ g_assert(loc >= bus->mmio_alloc_ptr); g_assert(loc + size <= bus->mmio_limit); bus->mmio_alloc_ptr = loc + size; qpci_config_writel(dev, bar_reg, loc); } return (void *)(uintptr_t)loc; }


int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv) { int i, t = 0; uint8_t *zero, *last, *cur; JLSState *state; int off = 0, stride = 1, width, shift, ret = 0; zero = av_mallocz(s->picture_ptr->linesize[0]); if (!zero) return AVERROR(ENOMEM); last = zero; cur = s->picture_ptr->data[0]; state = av_mallocz(sizeof(JLSState)); if (!state) { av_free(zero); return AVERROR(ENOMEM); /* initialize JPEG-LS state from JPEG parameters */ state->near = near; state->bpp = (s->bits < 2) ? 2 : s->bits; state->maxval = s->maxval; state->T1 = s->t1; state->T2 = s->t2; state->T3 = s->t3; state->reset = s->reset; ff_jpegls_reset_coding_parameters(state, 0); ff_jpegls_init_state(state); if (s->bits <= 8) shift = point_transform + (8 - s->bits); else shift = point_transform + (16 - s->bits); if (s->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) " "RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n", s->width, s->height, state->near, state->maxval, state->T1, state->T2, state->T3, state->reset, state->limit, state->qbpp, state->range); av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); if (ilv == 0) { /* separate planes */ if (s->cur_scan > s->nb_components) { stride = (s->nb_components > 1) ? 3 : 1; off = av_clip(s->cur_scan - 1, 0, stride - 1); width = s->width * stride; cur += off; for (i = 0; i < s->height; i++) { if (s->bits <= 8) { ls_decode_line(state, s, last, cur, t, width, stride, off, 8); t = last[0]; } else { ls_decode_line(state, s, last, cur, t, width, stride, off, 16); t = *((uint16_t *)last); last = cur; cur += s->picture_ptr->linesize[0]; if (s->restart_interval && !--s->restart_count) { align_get_bits(&s->gb); skip_bits(&s->gb, 16); /* skip RSTn */ } else if (ilv == 1) { /* line interleaving */ int j; int Rc[3] = { 0, 0, 0 }; stride = (s->nb_components > 1) ? 3 : 1; memset(cur, 0, s->picture_ptr->linesize[0]); width = s->width * stride; for (i = 0; i < s->height; i++) { for (j = 0; j < stride; j++) { ls_decode_line(state, s, last + j, cur + j, Rc[j], width, stride, j, 8); Rc[j] = last[j]; if (s->restart_interval && !--s->restart_count) { align_get_bits(&s->gb); skip_bits(&s->gb, 16); /* skip RSTn */ last = cur; cur += s->picture_ptr->linesize[0]; } else if (ilv == 2) { /* sample interleaving */ avpriv_report_missing_feature(s->avctx, "Sample interleaved images"); ret = AVERROR_PATCHWELCOME; if (s->xfrm && s->nb_components == 3) { int x, w; w = s->width * s->nb_components; if (s->bits <= 8) { uint8_t *src = s->picture_ptr->data[0]; for (i = 0; i < s->height; i++) { switch(s->xfrm) { case 1: for (x = off; x < w; x += 3) { src[x ] += src[x+1] + 128; src[x+2] += src[x+1] + 128; break; case 2: for (x = off; x < w; x += 3) { src[x ] += src[x+1] + 128; src[x+2] += ((src[x ] + src[x+1])>>1) + 128; break; case 3: for (x = off; x < w; x += 3) { int g = src[x+0] - ((src[x+2]+src[x+1])>>2) + 64; src[x+0] = src[x+2] + g + 128; src[x+2] = src[x+1] + g + 128; src[x+1] = g; break; case 4: for (x = off; x < w; x += 3) { int r = src[x+0] - (( 359 * (src[x+2]-128) + 490) >> 8); int g = src[x+0] - (( 88 * (src[x+1]-128) - 183 * (src[x+2]-128) + 30) >> 8); int b = src[x+0] + ((454 * (src[x+1]-128) + 574) >> 8); src[x+0] = av_clip_uint8(r); src[x+1] = av_clip_uint8(g); src[x+2] = av_clip_uint8(b); break; src += s->picture_ptr->linesize[0]; }else avpriv_report_missing_feature(s->avctx, "16bit xfrm"); if (shift) { /* we need to do point transform or normalize samples */ int x, w; w = s->width * s->nb_components; if (s->bits <= 8) { uint8_t *src = s->picture_ptr->data[0]; for (i = 0; i < s->height; i++) { for (x = off; x < w; x += stride) src[x] <<= shift; src += s->picture_ptr->linesize[0]; } else { uint16_t *src = (uint16_t *)s->picture_ptr->data[0]; for (i = 0; i < s->height; i++) { for (x = 0; x < w; x++) src[x] <<= shift; src += s->picture_ptr->linesize[0] / 2; end: av_free(state); av_free(zero); return ret;


void FUNCC(ff_h264_chroma_dc_dequant_idct)(int16_t *_block, int qmul){ const int stride= 16*2; const int xStride= 16; int a,b,c,d,e; dctcoef *block = (dctcoef*)_block; a= block[stride*0 + xStride*0]; b= block[stride*0 + xStride*1]; c= block[stride*1 + xStride*0]; d= block[stride*1 + xStride*1]; e= a-b; a= a+b; b= c-d; c= c+d; block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7; block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7; block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7; block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7; }


static inline int mpeg2_decode_block_intra(MpegEncContext *s, int16_t *block, int n) { int level, dc, diff, i, j, run; int component; RLTable *rl; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale = s->qscale; int mismatch; /* DC coefficient */ if (n < 4) { quant_matrix = s->intra_matrix; component = 0; } else { quant_matrix = s->chroma_intra_matrix; component = (n & 1) + 1; } diff = decode_dc(&s->gb, component); if (diff >= 0xffff) return AVERROR_INVALIDDATA; dc = s->last_dc[component]; dc += diff; s->last_dc[component] = dc; block[0] = dc << (3 - s->intra_dc_precision); ff_tlog(s->avctx, "dc=%d\n", block[0]); mismatch = block[0] ^ 1; i = 0; if (s->intra_vlc_format) rl = &ff_rl_mpeg2; else rl = &ff_rl_mpeg1; { OPEN_READER(re, &s->gb); /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); if (level == 127) { break; } else if (level != 0) { i += run; if (i > MAX_INDEX) break; j = scantable[i]; level = (level * qscale * quant_matrix[j]) >> 4; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); UPDATE_CACHE(re, &s->gb); level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); i += run; if (i > MAX_INDEX) break; j = scantable[i]; if (level < 0) { level = (-level * qscale * quant_matrix[j]) >> 4; level = -level; } else { level = (level * qscale * quant_matrix[j]) >> 4; } } mismatch ^= level; block[j] = level; } CLOSE_READER(re, &s->gb); } block[63] ^= mismatch & 1; check_scantable_index(s, i); s->block_last_index[n] = i; return 0; }


static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) { int i, plane, row, sprite; int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } }; uint8_t* src_h[2][2]; int xoff[2], xadv[2], yoff[2], yadv[2], alpha; int ysub[2]; MpegEncContext *s = &v->s; for (i = 0; i < 2; i++) { xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16); xadv[i] = sd->coefs[i][0]; if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i]) xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width); yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16); yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height); } alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1); for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) { int width = v->output_width>>!!plane; for (row = 0; row < v->output_height>>!!plane; row++) { uint8_t *dst = v->sprite_output_frame.data[plane] + v->sprite_output_frame.linesize[plane] * row; for (sprite = 0; sprite <= v->two_sprites; sprite++) { uint8_t *iplane = s->current_picture.f.data[plane]; int iline = s->current_picture.f.linesize[plane]; int ycoord = yoff[sprite] + yadv[sprite] * row; int yline = ycoord >> 16; ysub[sprite] = ycoord & 0xFFFF; if (sprite) { iplane = s->last_picture.f.data[plane]; iline = s->last_picture.f.linesize[plane]; } if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) { src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline; if (ysub[sprite]) src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + (yline + 1) * iline; } else { if (sr_cache[sprite][0] != yline) { if (sr_cache[sprite][1] == yline) { FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]); FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]); } else { v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width); sr_cache[sprite][0] = yline; } } if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) { v->vc1dsp.sprite_h(v->sr_rows[sprite][1], iplane + (yline + 1) * iline, xoff[sprite], xadv[sprite], width); sr_cache[sprite][1] = yline + 1; } src_h[sprite][0] = v->sr_rows[sprite][0]; src_h[sprite][1] = v->sr_rows[sprite][1]; } } if (!v->two_sprites) { if (ysub[0]) { v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width); } else { memcpy(dst, src_h[0][0], width); } } else { if (ysub[0] && ysub[1]) { v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0], src_h[1][0], src_h[1][1], ysub[1], alpha, width); } else if (ysub[0]) { v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0], src_h[1][0], alpha, width); } else if (ysub[1]) { v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1], src_h[0][0], (1<<16)-1-alpha, width); } else { v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width); } } } if (!plane) { for (i = 0; i < 2; i++) { xoff[i] >>= 1; yoff[i] >>= 1; } } } }


static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s, VHDXLogSequence *logs) { int ret = 0; int i; uint32_t cnt, sectors_read; uint64_t new_file_size; void *data = NULL; VHDXLogDescEntries *desc_entries = NULL; VHDXLogEntryHeader hdr_tmp = { 0 }; cnt = logs->count; data = qemu_blockalign(bs, VHDX_LOG_SECTOR_SIZE); ret = vhdx_user_visible_write(bs, s); if (ret < 0) { goto exit; } /* each iteration represents one log sequence, which may span multiple * sectors */ while (cnt--) { ret = vhdx_log_peek_hdr(bs, &logs->log, &hdr_tmp); if (ret < 0) { goto exit; } /* if the log shows a FlushedFileOffset larger than our current file * size, then that means the file has been truncated / corrupted, and * we must refused to open it / use it */ if (hdr_tmp.flushed_file_offset > bdrv_getlength(bs->file->bs)) { ret = -EINVAL; goto exit; } ret = vhdx_log_read_desc(bs, s, &logs->log, &desc_entries, true); if (ret < 0) { goto exit; } for (i = 0; i < desc_entries->hdr.descriptor_count; i++) { if (desc_entries->desc[i].signature == VHDX_LOG_DESC_SIGNATURE) { /* data sector, so read a sector to flush */ ret = vhdx_log_read_sectors(bs, &logs->log, &sectors_read, data, 1, false); if (ret < 0) { goto exit; } if (sectors_read != 1) { ret = -EINVAL; goto exit; } vhdx_log_data_le_import(data); } ret = vhdx_log_flush_desc(bs, &desc_entries->desc[i], data); if (ret < 0) { goto exit; } } if (bdrv_getlength(bs->file->bs) < desc_entries->hdr.last_file_offset) { new_file_size = desc_entries->hdr.last_file_offset; if (new_file_size % (1024*1024)) { /* round up to nearest 1MB boundary */ new_file_size = ((new_file_size >> 20) + 1) << 20; bdrv_truncate(bs->file, new_file_size, PREALLOC_MODE_OFF, NULL); } } qemu_vfree(desc_entries); desc_entries = NULL; } bdrv_flush(bs); /* once the log is fully flushed, indicate that we have an empty log * now. This also sets the log guid to 0, to indicate an empty log */ vhdx_log_reset(bs, s); exit: qemu_vfree(data); qemu_vfree(desc_entries); return ret; }


static void unterminated_array(void) { QObject *obj = qobject_from_json("[32", NULL); g_assert(obj == NULL); }


static av_cold int xan_decode_init(AVCodecContext *avctx) { XanContext *s = avctx->priv_data; s->avctx = avctx; s->frame_size = 0; if ((avctx->codec->id == CODEC_ID_XAN_WC3) && (s->avctx->palctrl == NULL)) { av_log(avctx, AV_LOG_ERROR, "palette expected\n"); return AVERROR(EINVAL); } avctx->pix_fmt = PIX_FMT_PAL8; s->buffer1_size = avctx->width * avctx->height; s->buffer1 = av_malloc(s->buffer1_size); if (!s->buffer1) return AVERROR(ENOMEM); s->buffer2_size = avctx->width * avctx->height; s->buffer2 = av_malloc(s->buffer2_size + 130); if (!s->buffer2) { av_freep(&s->buffer1); return AVERROR(ENOMEM); } return 0; }


static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){ int i; for(i=0; i<128; i++){ int level= i-64; int run; for(run=0; run<64; run++){ int len, bits, code; int alevel= FFABS(level); int sign= (level>>31)&1; if (alevel > rl->max_level[0][run]) code= 111; /*rl->n*/ else code= rl->index_run[0][run] + alevel - 1; if (code < 111 /* rl->n */) { /* store the vlc & sign at once */ len= rl->table_vlc[code][1]+1; bits= (rl->table_vlc[code][0]<<1) + sign; } else { len= rl->table_vlc[111/*rl->n*/][1]+6; bits= rl->table_vlc[111/*rl->n*/][0]<<6; bits|= run; if (alevel < 128) { bits<<=8; len+=8; bits|= level & 0xff; } else { bits<<=16; len+=16; bits|= level & 0xff; if (level < 0) { bits|= 0x8001 + level + 255; } else { bits|= level & 0xffff; } } } uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len; } } }


int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) { unsigned int i, head, max; target_phys_addr_t desc_pa = vq->vring.desc; if (!virtqueue_num_heads(vq, vq->last_avail_idx)) return 0; /* When we start there are none of either input nor output. */ elem->out_num = elem->in_num = 0; max = vq->vring.num; i = head = virtqueue_get_head(vq, vq->last_avail_idx++); if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) { vring_avail_event(vq, vring_avail_idx(vq)); if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) { if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) { error_report("Invalid size for indirect buffer table"); /* loop over the indirect descriptor table */ max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); desc_pa = vring_desc_addr(desc_pa, i); i = 0; /* Collect all the descriptors */ do { struct iovec *sg; if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) { elem->in_addr[elem->in_num] = vring_desc_addr(desc_pa, i); sg = &elem->in_sg[elem->in_num++]; } else { elem->out_addr[elem->out_num] = vring_desc_addr(desc_pa, i); sg = &elem->out_sg[elem->out_num++]; sg->iov_len = vring_desc_len(desc_pa, i); /* If we've got too many, that implies a descriptor loop. */ if ((elem->in_num + elem->out_num) > max) { error_report("Looped descriptor"); } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max); /* Now map what we have collected */ virtqueue_map_sg(elem->in_sg, elem->in_addr, elem->in_num, 1); virtqueue_map_sg(elem->out_sg, elem->out_addr, elem->out_num, 0); elem->index = head; vq->inuse++; trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num); return elem->in_num + elem->out_num;


void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) { RAMBlock *block; ram_addr_t offset; int flags; void *area, *vaddr; QLIST_FOREACH(block, &ram_list.blocks, next) { offset = addr - block->offset; if (offset < block->length) { vaddr = block->host + offset; if (block->flags & RAM_PREALLOC_MASK) { ; } else { flags = MAP_FIXED; munmap(vaddr, length); if (mem_path) { #if defined(__linux__) && !defined(TARGET_S390X) if (block->fd) { #ifdef MAP_POPULATE flags |= mem_prealloc ? MAP_POPULATE | MAP_SHARED : MAP_PRIVATE; flags |= MAP_PRIVATE; #endif area = mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, block->fd, offset); } else { flags |= MAP_PRIVATE | MAP_ANONYMOUS; area = mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, -1, 0); } #endif } else { #if defined(TARGET_S390X) && defined(CONFIG_KVM) flags |= MAP_SHARED | MAP_ANONYMOUS; area = mmap(vaddr, length, PROT_EXEC|PROT_READ|PROT_WRITE, flags, -1, 0); flags |= MAP_PRIVATE | MAP_ANONYMOUS; area = mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, -1, 0); #endif } if (area != vaddr) { fprintf(stderr, "Could not remap addr: %lx@%lx\n", length, addr); exit(1); } qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE); } return; } } }


static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PnvChipClass *k = PNV_CHIP_CLASS(klass); k->cpu_model = "POWER8"; k->chip_type = PNV_CHIP_POWER8; k->chip_cfam_id = 0x220ea04980000000ull; /* P8 Venice DD2.0 */ k->cores_mask = POWER8_CORE_MASK; k->core_pir = pnv_chip_core_pir_p8; dc->desc = "PowerNV Chip POWER8"; }


static void multiwrite_user_cb(MultiwriteCB *mcb) { int i; for (i = 0; i < mcb->num_callbacks; i++) { mcb->callbacks[i].cb(mcb->callbacks[i].opaque, mcb->error); qemu_free(mcb->callbacks[i].free_qiov); qemu_free(mcb->callbacks[i].free_buf); } }


static void pflash_cfi02_realize(DeviceState *dev, Error **errp) { pflash_t *pfl = CFI_PFLASH02(dev); uint32_t chip_len; int ret; Error *local_err = NULL; chip_len = pfl->sector_len * pfl->nb_blocs; /* XXX: to be fixed */ #if 0 if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) && total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024)) return NULL; #endif memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), pfl->be ? &pflash_cfi02_ops_be : &pflash_cfi02_ops_le, pfl, pfl->name, chip_len, &local_err); if (local_err) { error_propagate(errp, local_err); vmstate_register_ram(&pfl->orig_mem, DEVICE(pfl)); pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem); pfl->chip_len = chip_len; if (pfl->blk) { /* read the initial flash content */ ret = blk_pread(pfl->blk, 0, pfl->storage, chip_len); if (ret < 0) { vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl)); error_setg(errp, "failed to read the initial flash content"); pflash_setup_mappings(pfl); pfl->rom_mode = 1; sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->blk) { pfl->ro = blk_is_read_only(pfl->blk); } else { pfl->ro = 0; pfl->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, pflash_timer, pfl); pfl->wcycle = 0; pfl->cmd = 0; pfl->status = 0; /* Hardcoded CFI table (mostly from SG29 Spansion flash) */ pfl->cfi_len = 0x52; /* Standard "QRY" string */ pfl->cfi_table[0x10] = 'Q'; pfl->cfi_table[0x11] = 'R'; pfl->cfi_table[0x12] = 'Y'; /* Command set (AMD/Fujitsu) */ pfl->cfi_table[0x13] = 0x02; pfl->cfi_table[0x14] = 0x00; /* Primary extended table address */ pfl->cfi_table[0x15] = 0x31; pfl->cfi_table[0x16] = 0x00; /* Alternate command set (none) */ pfl->cfi_table[0x17] = 0x00; pfl->cfi_table[0x18] = 0x00; /* Alternate extended table (none) */ pfl->cfi_table[0x19] = 0x00; pfl->cfi_table[0x1A] = 0x00; /* Vcc min */ pfl->cfi_table[0x1B] = 0x27; /* Vcc max */ pfl->cfi_table[0x1C] = 0x36; /* Vpp min (no Vpp pin) */ pfl->cfi_table[0x1D] = 0x00; /* Vpp max (no Vpp pin) */ pfl->cfi_table[0x1E] = 0x00; /* Reserved */ pfl->cfi_table[0x1F] = 0x07; /* Timeout for min size buffer write (NA) */ pfl->cfi_table[0x20] = 0x00; /* Typical timeout for block erase (512 ms) */ pfl->cfi_table[0x21] = 0x09; /* Typical timeout for full chip erase (4096 ms) */ pfl->cfi_table[0x22] = 0x0C; /* Reserved */ pfl->cfi_table[0x23] = 0x01; /* Max timeout for buffer write (NA) */ pfl->cfi_table[0x24] = 0x00; /* Max timeout for block erase */ pfl->cfi_table[0x25] = 0x0A; /* Max timeout for chip erase */ pfl->cfi_table[0x26] = 0x0D; /* Device size */ pfl->cfi_table[0x27] = ctz32(chip_len); /* Flash device interface (8 & 16 bits) */ pfl->cfi_table[0x28] = 0x02; pfl->cfi_table[0x29] = 0x00; /* Max number of bytes in multi-bytes write */ /* XXX: disable buffered write as it's not supported */ // pfl->cfi_table[0x2A] = 0x05; pfl->cfi_table[0x2A] = 0x00; pfl->cfi_table[0x2B] = 0x00; /* Number of erase block regions (uniform) */ pfl->cfi_table[0x2C] = 0x01; /* Erase block region 1 */ pfl->cfi_table[0x2D] = pfl->nb_blocs - 1; pfl->cfi_table[0x2E] = (pfl->nb_blocs - 1) >> 8; pfl->cfi_table[0x2F] = pfl->sector_len >> 8; pfl->cfi_table[0x30] = pfl->sector_len >> 16; /* Extended */ pfl->cfi_table[0x31] = 'P'; pfl->cfi_table[0x32] = 'R'; pfl->cfi_table[0x33] = 'I'; pfl->cfi_table[0x34] = '1'; pfl->cfi_table[0x35] = '0'; pfl->cfi_table[0x36] = 0x00; pfl->cfi_table[0x37] = 0x00; pfl->cfi_table[0x38] = 0x00; pfl->cfi_table[0x39] = 0x00; pfl->cfi_table[0x3a] = 0x00; pfl->cfi_table[0x3b] = 0x00; pfl->cfi_table[0x3c] = 0x00;


float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) { float q; int qmin, qmax; float br_compensation; double diff; double short_term_q; double fps; int picture_number = s->picture_number; int64_t wanted_bits; RateControlContext *rcc = &s->rc_context; AVCodecContext *a = s->avctx; RateControlEntry local_rce, *rce; double bits; double rate_factor; int var; const int pict_type = s->pict_type; Picture * const pic = &s->current_picture; emms_c(); #if CONFIG_LIBXVID if ((s->flags & CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) return ff_xvid_rate_estimate_qscale(s, dry_run); #endif get_qminmax(&qmin, &qmax, s, pict_type); fps = get_fps(s->avctx); /* update predictors */ if (picture_number > 2 && !dry_run) { const int last_var = s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum; av_assert1(s->frame_bits >= s->stuffing_bits); update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits - s->stuffing_bits); } if (s->flags & CODEC_FLAG_PASS2) { assert(picture_number >= 0); if (picture_number >= rcc->num_entries) { av_log(s, AV_LOG_ERROR, "Input is longer than 2-pass log file\n"); return -1; } rce = &rcc->entry[picture_number]; wanted_bits = rce->expected_bits; } else { Picture *dts_pic; rce = &local_rce; /* FIXME add a dts field to AVFrame and ensure it is set and use it * here instead of reordering but the reordering is simpler for now * until H.264 B-pyramid must be handled. */ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) dts_pic = s->current_picture_ptr; else dts_pic = s->last_picture_ptr; if (!dts_pic || dts_pic->f.pts == AV_NOPTS_VALUE) wanted_bits = (uint64_t)(s->bit_rate * (double)picture_number / fps); else wanted_bits = (uint64_t)(s->bit_rate * (double)dts_pic->f.pts / fps); } diff = s->total_bits - wanted_bits; br_compensation = (a->bit_rate_tolerance - diff) / a->bit_rate_tolerance; if (br_compensation <= 0.0) br_compensation = 0.001; var = pict_type == AV_PICTURE_TYPE_I ? pic->mb_var_sum : pic->mc_mb_var_sum; short_term_q = 0; /* avoid warning */ if (s->flags & CODEC_FLAG_PASS2) { if (pict_type != AV_PICTURE_TYPE_I) assert(pict_type == rce->new_pict_type); q = rce->new_qscale / br_compensation; av_dlog(s, "%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale, br_compensation, s->frame_bits, var, pict_type); } else { rce->pict_type = rce->new_pict_type = pict_type; rce->mc_mb_var_sum = pic->mc_mb_var_sum; rce->mb_var_sum = pic->mb_var_sum; rce->qscale = FF_QP2LAMBDA * 2; rce->f_code = s->f_code; rce->b_code = s->b_code; rce->misc_bits = 1; bits = predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var)); if (pict_type == AV_PICTURE_TYPE_I) { rce->i_count = s->mb_num; rce->i_tex_bits = bits; rce->p_tex_bits = 0; rce->mv_bits = 0; } else { rce->i_count = 0; // FIXME we do know this approx rce->i_tex_bits = 0; rce->p_tex_bits = bits * 0.9; rce->mv_bits = bits * 0.1; } rcc->i_cplx_sum[pict_type] += rce->i_tex_bits * rce->qscale; rcc->p_cplx_sum[pict_type] += rce->p_tex_bits * rce->qscale; rcc->mv_bits_sum[pict_type] += rce->mv_bits; rcc->frame_count[pict_type]++; bits = rce->i_tex_bits + rce->p_tex_bits; rate_factor = rcc->pass1_wanted_bits / rcc->pass1_rc_eq_output_sum * br_compensation; q = get_qscale(s, rce, rate_factor, picture_number); if (q < 0) return -1; assert(q > 0.0); q = get_diff_limited_q(s, rce, q); assert(q > 0.0); // FIXME type dependent blur like in 2-pass if (pict_type == AV_PICTURE_TYPE_P || s->intra_only) { rcc->short_term_qsum *= a->qblur; rcc->short_term_qcount *= a->qblur; rcc->short_term_qsum += q; rcc->short_term_qcount++; q = short_term_q = rcc->short_term_qsum / rcc->short_term_qcount; } assert(q > 0.0); q = modify_qscale(s, rce, q, picture_number); rcc->pass1_wanted_bits += s->bit_rate / fps; assert(q > 0.0); } if (s->avctx->debug & FF_DEBUG_RC) { av_log(s->avctx, AV_LOG_DEBUG, "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f " "size:%d var:%"PRId64"/%"PRId64" br:%d fps:%d\n", av_get_picture_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits / 1000, (int)s->total_bits / 1000, br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate / 1000, (int)fps); } if (q < qmin) q = qmin; else if (q > qmax) q = qmax; if (s->adaptive_quant) adaptive_quantization(s, q); else q = (int)(q + 0.5); if (!dry_run) { rcc->last_qscale = q; rcc->last_mc_mb_var_sum = pic->mc_mb_var_sum; rcc->last_mb_var_sum = pic->mb_var_sum; } return q; }


static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ MpegEncContext * const s = &h->s; int b8_stride = 2; int b4_stride = h->b_stride; int mb_xy = h->mb_xy, mb_y = s->mb_y; int mb_type_col[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int8_t *l1ref0, *l1ref1; const int is_b8x8 = IS_8X8(*mb_type); unsigned int sub_mb_type= MB_TYPE_L0L1; int i8, i4; int ref[2]; int mv[2]; int list; assert(h->ref_list[1][0].f.reference & 3); await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) /* ref = min(neighbors) */ for(list=0; list<2; list++){ int left_ref = h->ref_cache[list][scan8[0] - 1]; int top_ref = h->ref_cache[list][scan8[0] - 8]; int refc = h->ref_cache[list][scan8[0] - 8 + 4]; const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4]; if(refc == PART_NOT_AVAILABLE){ refc = h->ref_cache[list][scan8[0] - 8 - 1]; C = h-> mv_cache[list][scan8[0] - 8 - 1]; ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc); if(ref[list] >= 0){ //this is just pred_motion() but with the cases removed that cannot happen for direct blocks const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]); if(match_count > 1){ //most common mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]), mid_pred(A[1], B[1], C[1]) ); }else { assert(match_count==1); if(left_ref==ref[list]){ mv[list]= AV_RN32A(A); }else if(top_ref==ref[list]){ mv[list]= AV_RN32A(B); }else{ mv[list]= AV_RN32A(C); }else{ int mask= ~(MB_TYPE_L0 << (2*list)); mv[list] = 0; ref[list] = -1; if(!is_b8x8) *mb_type &= mask; sub_mb_type &= mask; if(ref[0] < 0 && ref[1] < 0){ ref[0] = ref[1] = 0; if(!is_b8x8) *mb_type |= MB_TYPE_L0L1; sub_mb_type |= MB_TYPE_L0L1; if(!(is_b8x8|mv[0]|mv[1])){ fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; return; if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL mb_y = (s->mb_y&~1) + h->col_parity; mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; b8_stride = 0; }else{ mb_y += h->col_fieldoff; mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity goto single_col; }else{ // AFL/AFR/FR/FL -> AFR/FR if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR mb_y = s->mb_y&~1; mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; b8_stride = 2+4*s->mb_stride; b4_stride *= 6; sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && !is_b8x8){ *mb_type |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; /* B_16x8 */ }else{ *mb_type |= MB_TYPE_8x8; }else{ // AFR/FR -> AFR/FR single_col: mb_type_col[0] = mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy]; sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){ *mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_16x16 */ }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){ *mb_type |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16)); }else{ if(!h->sps.direct_8x8_inference_flag){ /* FIXME save sub mb types from previous frames (or derive from MVs) * so we know exactly what block size to use */ sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16); /* B_SUB_4x4 */ *mb_type |= MB_TYPE_8x8; await_reference_mb_row(h, &h->ref_list[1][0], mb_y); l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]]; l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]]; l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; if(!b8_stride){ if(s->mb_y&1){ l1ref0 += 2; l1ref1 += 2; l1mv0 += 2*b4_stride; l1mv1 += 2*b4_stride; if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){ int n=0; for(i8=0; i8<4; i8++){ int x8 = i8&1; int y8 = i8>>1; int xy8 = x8+y8*b8_stride; int xy4 = 3*x8+y8*b4_stride; int a,b; if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) continue; h->sub_mb_type[i8] = sub_mb_type; fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1) || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){ a=b=0; if(ref[0] > 0) a= mv[0]; if(ref[1] > 0) b= mv[1]; n++; }else{ a= mv[0]; b= mv[1]; fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4); fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4); if(!is_b8x8 && !(n&3)) *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; }else if(IS_16X16(*mb_type)){ int a,b; fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1) || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1 && h->x264_build>33U))){ a=b=0; if(ref[0] > 0) a= mv[0]; if(ref[1] > 0) b= mv[1]; }else{ a= mv[0]; b= mv[1]; fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); }else{ int n=0; for(i8=0; i8<4; i8++){ const int x8 = i8&1; const int y8 = i8>>1; if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) continue; h->sub_mb_type[i8] = sub_mb_type; fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4); fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4); fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); assert(b8_stride==2); /* col_zero_flag */ if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[i8] == 0 || (l1ref0[i8] < 0 && l1ref1[i8] == 0 && h->x264_build>33U))){ const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1; if(IS_SUB_8X8(sub_mb_type)){ const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride]; if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ if(ref[0] == 0) fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); if(ref[1] == 0) fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); n+=4; }else{ int m=0; for(i4=0; i4<4; i4++){ const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride]; if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ if(ref[0] == 0) AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]); if(ref[1] == 0) AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]); m++; if(!(m&3)) h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8; n+=m; if(!is_b8x8 && !(n&15)) *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;


int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) { if(min_ts > ts || max_ts < ts) return -1; if (s->iformat->read_seek2) { int ret; ff_read_frame_flush(s); if (stream_index == -1 && s->nb_streams == 1) { AVRational time_base = s->streams[0]->time_base; ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base); min_ts = av_rescale_rnd(min_ts, time_base.den, time_base.num * (int64_t)AV_TIME_BASE, AV_ROUND_UP); max_ts = av_rescale_rnd(max_ts, time_base.den, time_base.num * (int64_t)AV_TIME_BASE, AV_ROUND_DOWN); } ret = s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); if (ret >= 0) avformat_queue_attached_pictures(s); return ret; } if(s->iformat->read_timestamp){ //try to seek via read_timestamp() } //Fallback to old API if new is not implemented but old is //Note the old has somewhat different semantics if (s->iformat->read_seek || 1) { int dir = (ts - (uint64_t)min_ts > (uint64_t)max_ts - ts ? AVSEEK_FLAG_BACKWARD : 0); int ret = av_seek_frame(s, stream_index, ts, flags | dir); if (ret<0 && ts != min_ts && max_ts != ts) { ret = av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir); if (ret >= 0) ret = av_seek_frame(s, stream_index, ts, flags | (dir^AVSEEK_FLAG_BACKWARD)); } return ret; } // try some generic seek like seek_frame_generic() but with new ts semantics }


static inline void render_line_unrolled(intptr_t x, uint8_t y, int x1, intptr_t sy, int ady, int adx, float *buf) { int err = -adx; x -= x1 - 1; buf += x1 - 1; while (++x < 0) { err += ady; if (err >= 0) { err += ady - adx; y += sy; buf[x++] = ff_vorbis_floor1_inverse_db_table[y]; } buf[x] = ff_vorbis_floor1_inverse_db_table[y]; } if (x <= 0) { if (err + ady >= 0) y += sy; buf[x] = ff_vorbis_floor1_inverse_db_table[y]; } }


iscsi_connect_cb(struct iscsi_context *iscsi, int status, void *command_data, void *opaque) { struct IscsiTask *itask = opaque; struct scsi_task *task; if (status != 0) { itask->status = 1; itask->complete = 1; return; } task = iscsi_inquiry_task(iscsi, itask->iscsilun->lun, 0, 0, 36, iscsi_inquiry_cb, opaque); if (task == NULL) { error_report("iSCSI: failed to send inquiry command."); itask->status = 1; itask->complete = 1; return; } }


static inline void s_zero(int cur_diff, struct G722Band *band) { int s_zero = 0; #define ACCUM(k, x, d) do { \ int tmp = x; \ band->zero_mem[k] = ((band->zero_mem[k] * 255) >> 8) + \ d*((band->diff_mem[k]^cur_diff) < 0 ? -128 : 128); \ band->diff_mem[k] = tmp; \ s_zero += (tmp * band->zero_mem[k]) >> 15; \ } while (0) if (cur_diff) { ACCUM(5, band->diff_mem[4], 1); ACCUM(4, band->diff_mem[3], 1); ACCUM(3, band->diff_mem[2], 1); ACCUM(2, band->diff_mem[1], 1); ACCUM(1, band->diff_mem[0], 1); ACCUM(0, cur_diff << 1, 1); } else { ACCUM(5, band->diff_mem[4], 0); ACCUM(4, band->diff_mem[3], 0); ACCUM(3, band->diff_mem[2], 0); ACCUM(2, band->diff_mem[1], 0); ACCUM(1, band->diff_mem[0], 0); ACCUM(0, cur_diff << 1, 0); } #undef ACCUM band->s_zero = s_zero; }


static uint32_t qvirtio_pci_get_features(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; return qpci_io_readl(dev->pdev, dev->addr + VIRTIO_PCI_HOST_FEATURES); }


static av_cold int decode_init(AVCodecContext * avctx) { KmvcContext *const c = avctx->priv_data; int i; c->avctx = avctx; if (avctx->width > 320 || avctx->height > 200) { av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n"); return -1; } c->frm0 = av_mallocz(320 * 200); c->frm1 = av_mallocz(320 * 200); c->cur = c->frm0; c->prev = c->frm1; for (i = 0; i < 256; i++) { c->pal[i] = 0xFF << 24 | i * 0x10101; } if (avctx->extradata_size < 12) { av_log(avctx, AV_LOG_WARNING, "Extradata missing, decoding may not work properly...\n"); c->palsize = 127; } else { c->palsize = AV_RL16(avctx->extradata + 10); if (c->palsize >= (unsigned)MAX_PALSIZE) { c->palsize = 127; av_log(avctx, AV_LOG_ERROR, "KMVC palette too large\n"); return AVERROR_INVALIDDATA; } } if (avctx->extradata_size == 1036) { // palette in extradata uint8_t *src = avctx->extradata + 12; for (i = 0; i < 256; i++) { c->pal[i] = AV_RL32(src); src += 4; } c->setpal = 1; } avcodec_get_frame_defaults(&c->pic); avctx->pix_fmt = AV_PIX_FMT_PAL8; return 0; }


static uint8_t lag_calc_zero_run(int8_t x) { return (x << 1) ^ (x >> 7); }


static void patch_reloc(uint8_t *code_ptr, int type, intptr_t value, intptr_t addend) { value += addend; switch(type) { case R_386_PC32: value -= (uintptr_t)code_ptr; if (value != (int32_t)value) { tcg_abort(); } *(uint32_t *)code_ptr = value; break; case R_386_PC8: value -= (uintptr_t)code_ptr; if (value != (int8_t)value) { tcg_abort(); } *(uint8_t *)code_ptr = value; break; default: tcg_abort(); } }


static int nut_write_trailer(AVFormatContext *s) { NUTContext *nut = s->priv_data; ByteIOContext *bc = &s->pb; update_packetheader(nut, bc, 0); #if 0 int i; /* WRITE INDEX */ for (i = 0; s->nb_streams; i++) { put_be64(bc, INDEX_STARTCODE); put_packetheader(nut, bc, 64); put_v(bc, s->streams[i]->id); put_v(bc, ...); put_be32(bc, 0); /* FIXME: checksum */ update_packetheader(nut, bc, 0); } #endif put_flush_packet(bc); av_freep(&nut->stream); return 0; }


static void noise(uint8_t *dst, const uint8_t *src, int dst_linesize, int src_linesize, int width, int start, int end, NoiseContext *n, int comp) { FilterParams *p = &n->param[comp]; int8_t *noise = p->noise; const int flags = p->flags; AVLFG *lfg = &p->lfg; int shift, y; if (!noise) { if (dst != src) av_image_copy_plane(dst, dst_linesize, src, src_linesize, width, end - start); return; } for (y = start; y < end; y++) { if (flags & NOISE_TEMPORAL) shift = av_lfg_get(lfg) & (MAX_SHIFT - 1); else shift = n->rand_shift[y]; if (flags & NOISE_AVERAGED) { n->line_noise_avg(dst, src, width, p->prev_shift[y]); p->prev_shift[y][shift & 3] = noise + shift; } else { n->line_noise(dst, src, noise, width, shift); } dst += dst_linesize; src += src_linesize; } }


void ff_generate_sliding_window_mmcos(H264Context *h) { MpegEncContext * const s = &h->s; assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); h->mmco_index= 0; if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count && !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->reference)) { h->mmco[0].opcode= MMCO_SHORT2UNUSED; h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; h->mmco_index= 1; if (FIELD_PICTURE) { h->mmco[0].short_pic_num *= 2; h->mmco[1].opcode= MMCO_SHORT2UNUSED; h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1; h->mmco_index= 2; } } }


static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; AVCPBProperties *cpb_props; #if CONFIG_LIBX262_ENCODER if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO) { x4->params.b_mpeg2 = 1; x264_param_default_mpeg2(&x4->params); } else #else x264_param_default(&x4->params); #endif x4->params.b_deblocking_filter = avctx->flags & AV_CODEC_FLAG_LOOP_FILTER; if (x4->preset || x4->tune) if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) { av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune); return AVERROR(EINVAL); } if (avctx->level > 0) x4->params.i_level_idc = avctx->level; x4->params.pf_log = X264_log; x4->params.p_log_private = avctx; x4->params.i_log_level = X264_LOG_DEBUG; x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt); if (avctx->bit_rate) { x4->params.rc.i_bitrate = avctx->bit_rate / 1000; x4->params.rc.i_rc_method = X264_RC_ABR; } x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; x4->params.rc.b_stat_write = avctx->flags & AV_CODEC_FLAG_PASS1; if (avctx->flags & AV_CODEC_FLAG_PASS2) { x4->params.rc.b_stat_read = 1; } else { if (x4->crf >= 0) { x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = x4->crf; } else if (x4->cqp >= 0) { x4->params.rc.i_rc_method = X264_RC_CQP; x4->params.rc.i_qp_constant = x4->cqp; } if (x4->crf_max >= 0) x4->params.rc.f_rf_constant_max = x4->crf_max; } if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 && (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { x4->params.rc.f_vbv_buffer_init = (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; } if (avctx->i_quant_factor > 0) x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); x4->params.rc.f_pb_factor = avctx->b_quant_factor; x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; if (avctx->gop_size >= 0) x4->params.i_keyint_max = avctx->gop_size; if (avctx->max_b_frames >= 0) x4->params.i_bframe = avctx->max_b_frames; if (avctx->scenechange_threshold >= 0) x4->params.i_scenecut_threshold = avctx->scenechange_threshold; if (avctx->qmin >= 0) x4->params.rc.i_qp_min = avctx->qmin; if (avctx->qmax >= 0) x4->params.rc.i_qp_max = avctx->qmax; if (avctx->max_qdiff >= 0) x4->params.rc.i_qp_step = avctx->max_qdiff; if (avctx->qblur >= 0) x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ if (avctx->qcompress >= 0) x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ if (avctx->refs >= 0) x4->params.i_frame_reference = avctx->refs; if (avctx->trellis >= 0) x4->params.analyse.i_trellis = avctx->trellis; if (avctx->me_range >= 0) x4->params.analyse.i_me_range = avctx->me_range; if (avctx->noise_reduction >= 0) x4->params.analyse.i_noise_reduction = avctx->noise_reduction; if (avctx->me_subpel_quality >= 0) x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; if (avctx->b_frame_strategy >= 0) x4->params.i_bframe_adaptive = avctx->b_frame_strategy; if (avctx->keyint_min >= 0) x4->params.i_keyint_min = avctx->keyint_min; #if FF_API_CODER_TYPE FF_DISABLE_DEPRECATION_WARNINGS if (avctx->coder_type >= 0) x4->coder = avctx->coder_type == FF_CODER_TYPE_AC; FF_ENABLE_DEPRECATION_WARNINGS #endif if (avctx->me_cmp >= 0) x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; if (x4->aq_mode >= 0) x4->params.rc.i_aq_mode = x4->aq_mode; if (x4->aq_strength >= 0) x4->params.rc.f_aq_strength = x4->aq_strength; PARSE_X264_OPT("psy-rd", psy_rd); PARSE_X264_OPT("deblock", deblock); PARSE_X264_OPT("partitions", partitions); PARSE_X264_OPT("stats", stats); if (x4->psy >= 0) x4->params.analyse.b_psy = x4->psy; if (x4->rc_lookahead >= 0) x4->params.rc.i_lookahead = x4->rc_lookahead; if (x4->weightp >= 0) x4->params.analyse.i_weighted_pred = x4->weightp; if (x4->weightb >= 0) x4->params.analyse.b_weighted_bipred = x4->weightb; if (x4->cplxblur >= 0) x4->params.rc.f_complexity_blur = x4->cplxblur; if (x4->ssim >= 0) x4->params.analyse.b_ssim = x4->ssim; if (x4->intra_refresh >= 0) x4->params.b_intra_refresh = x4->intra_refresh; if (x4->bluray_compat >= 0) { x4->params.b_bluray_compat = x4->bluray_compat; x4->params.b_vfr_input = 0; } if (x4->b_bias != INT_MIN) x4->params.i_bframe_bias = x4->b_bias; if (x4->b_pyramid >= 0) x4->params.i_bframe_pyramid = x4->b_pyramid; if (x4->mixed_refs >= 0) x4->params.analyse.b_mixed_references = x4->mixed_refs; if (x4->dct8x8 >= 0) x4->params.analyse.b_transform_8x8 = x4->dct8x8; if (x4->fast_pskip >= 0) x4->params.analyse.b_fast_pskip = x4->fast_pskip; if (x4->aud >= 0) x4->params.b_aud = x4->aud; if (x4->mbtree >= 0) x4->params.rc.b_mb_tree = x4->mbtree; if (x4->direct_pred >= 0) x4->params.analyse.i_direct_mv_pred = x4->direct_pred; if (x4->slice_max_size >= 0) x4->params.i_slice_max_size = x4->slice_max_size; if (x4->fastfirstpass) x264_param_apply_fastfirstpass(&x4->params); if (x4->nal_hrd >= 0) x4->params.i_nal_hrd = x4->nal_hrd; if (x4->motion_est >= 0) { x4->params.analyse.i_me_method = x4->motion_est; #if FF_API_MOTION_EST FF_DISABLE_DEPRECATION_WARNINGS } else { if (avctx->me_method == ME_EPZS) x4->params.analyse.i_me_method = X264_ME_DIA; else if (avctx->me_method == ME_HEX) x4->params.analyse.i_me_method = X264_ME_HEX; else if (avctx->me_method == ME_UMH) x4->params.analyse.i_me_method = X264_ME_UMH; else if (avctx->me_method == ME_FULL) x4->params.analyse.i_me_method = X264_ME_ESA; else if (avctx->me_method == ME_TESA) x4->params.analyse.i_me_method = X264_ME_TESA; FF_ENABLE_DEPRECATION_WARNINGS #endif } if (x4->coder >= 0) x4->params.b_cabac = x4->coder; if (x4->profile) if (x264_param_apply_profile(&x4->params, x4->profile) < 0) { av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile); return AVERROR(EINVAL); } x4->params.i_width = avctx->width; x4->params.i_height = avctx->height; x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den; x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num; x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR; x4->params.i_threads = avctx->thread_count; if (avctx->thread_type) x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE; x4->params.b_interlaced = avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT; x4->params.b_open_gop = !(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP); x4->params.i_slice_count = avctx->slices; x4->params.vui.b_fullrange = avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->color_range == AVCOL_RANGE_JPEG; // x264 validates the values internally x4->params.vui.i_colorprim = avctx->color_primaries; x4->params.vui.i_transfer = avctx->color_trc; x4->params.vui.i_colmatrix = avctx->colorspace; if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; if (x4->x264_params) { AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; if (!av_dict_parse_string(&dict, x4->x264_params, "=", ":", 0)) { while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { if (x264_param_parse(&x4->params, en->key, en->value) < 0) av_log(avctx, AV_LOG_WARNING, "Error parsing option '%s = %s'.\n", en->key, en->value); } av_dict_free(&dict); } } // update AVCodecContext with x264 parameters avctx->has_b_frames = x4->params.i_bframe ? x4->params.i_bframe_pyramid ? 2 : 1 : 0; if (avctx->max_b_frames < 0) avctx->max_b_frames = 0; avctx->bit_rate = x4->params.rc.i_bitrate*1000; x4->enc = x264_encoder_open(&x4->params); if (!x4->enc) return AVERROR_UNKNOWN; if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { x264_nal_t *nal; uint8_t *p; int nnal, s, i; s = x264_encoder_headers(x4->enc, &nal, &nnal); avctx->extradata = p = av_mallocz(s + AV_INPUT_BUFFER_PADDING_SIZE); if (!p) return AVERROR(ENOMEM); for (i = 0; i < nnal; i++) { /* Don't put the SEI in extradata. */ if (nal[i].i_type == NAL_SEI) { av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25); x4->sei_size = nal[i].i_payload; x4->sei = av_malloc(x4->sei_size); if (!x4->sei) return AVERROR(ENOMEM); memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload); continue; } memcpy(p, nal[i].p_payload, nal[i].i_payload); p += nal[i].i_payload; } avctx->extradata_size = p - avctx->extradata; } cpb_props = ff_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000; cpb_props->max_bitrate = x4->params.rc.i_vbv_max_bitrate * 1000; cpb_props->avg_bitrate = x4->params.rc.i_bitrate * 1000; return 0; }


static void blend_image_rgba_pm(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y) { blend_image_packed_rgb(ctx, dst, src, 1, x, y, 1); }


int ff_h264_frame_start(H264Context *h) { Picture *pic; int i, ret; const int pixel_shift = h->pixel_shift; int c[4] = { 1<<(h->sps.bit_depth_luma-1), 1<<(h->sps.bit_depth_chroma-1), 1<<(h->sps.bit_depth_chroma-1), -1 }; if (!ff_thread_can_start_frame(h->avctx)) { av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); return -1; } release_unused_pictures(h, 1); h->cur_pic_ptr = NULL; i = find_unused_picture(h); if (i < 0) { av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return i; } pic = &h->DPB[i]; pic->f.reference = h->droppable ? 0 : h->picture_structure; pic->f.coded_picture_number = h->coded_picture_number++; pic->field_picture = h->picture_structure != PICT_FRAME; /* * Zero key_frame here; IDR markings per slice in frame or fields are ORed * in later. * See decode_nal_units(). */ pic->f.key_frame = 0; pic->sync = 0; pic->mmco_reset = 0; if ((ret = alloc_picture(h, pic)) < 0) return ret; if(!h->sync && !h->avctx->hwaccel && !(h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) avpriv_color_frame(&pic->f, c); h->cur_pic_ptr = pic; h->cur_pic = *h->cur_pic_ptr; h->cur_pic.f.extended_data = h->cur_pic.f.data; ff_er_frame_start(&h->er); assert(h->linesize && h->uvlinesize); for (i = 0; i < 16; i++) { h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * h->linesize * ((scan8[i] - scan8[0]) >> 3); h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * h->linesize * ((scan8[i] - scan8[0]) >> 3); } for (i = 0; i < 16; i++) { h->block_offset[16 + i] = h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3); h->block_offset[48 + 16 + i] = h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * h->uvlinesize * ((scan8[i] - scan8[0]) >> 3); } /* can't be in alloc_tables because linesize isn't known there. * FIXME: redo bipred weight to not require extra buffer? */ for (i = 0; i < h->slice_context_count; i++) if (h->thread_context[i]) { ret = alloc_scratch_buffers(h->thread_context[i], h->linesize); if (ret < 0) return ret; } /* Some macroblocks can be accessed before they're available in case * of lost slices, MBAFF or threading. */ memset(h->slice_table, -1, (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); // s->decode = (h->flags & CODEC_FLAG_PSNR) || !s->encoding || // h->cur_pic.f.reference /* || h->contains_intra */ || 1; /* We mark the current picture as non-reference after allocating it, so * that if we break out due to an error it can be released automatically * in the next ff_MPV_frame_start(). * SVQ3 as well as most other codecs have only last/next/current and thus * get released even with set reference, besides SVQ3 and others do not * mark frames as reference later "naturally". */ if (h->avctx->codec_id != AV_CODEC_ID_SVQ3) h->cur_pic_ptr->f.reference = 0; h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX; h->next_output_pic = NULL; assert(h->cur_pic_ptr->long_ref == 0); return 0; }


static int probe(AVProbeData *p) { if (p->buf_size < 13) return 0; if (p->buf[0] == 0x01 && p->buf[1] == 0x00 && p->buf[4] == 0x01 + p->buf[2] && p->buf[8] == p->buf[4] + p->buf[6] && p->buf[12] == p->buf[8] + p->buf[10]) return AVPROBE_SCORE_MAX; return 0; }


void ff_weight_h264_pixels8_8_msa(uint8_t *src, int stride, int height, int log2_denom, int weight_src, int offset) { avc_wgt_8width_msa(src, stride, height, log2_denom, weight_src, offset); }


void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove){ int i; s->dts= s->pts= AV_NOPTS_VALUE; s->offset= 0; for(i = 0; i < AV_PARSER_PTS_NB; i++) { if ( s->next_frame_offset + off >= s->cur_frame_offset[i] &&(s-> frame_offset < s->cur_frame_offset[i] || !s->frame_offset) //check is disabled becausue mpeg-ts doesnt send complete PES packets && /*s->next_frame_offset + off <*/ s->cur_frame_end[i]){ s->dts= s->cur_frame_dts[i]; s->pts= s->cur_frame_pts[i]; s->offset = s->next_frame_offset - s->cur_frame_offset[i]; if(remove) s->cur_frame_offset[i]= INT64_MAX; } } }


static void new_video_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *video_enc; enum CodecID codec_id; st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_VIDEO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters; video_bitstream_filters= NULL; avcodec_thread_init(st->codec, thread_count); video_enc = st->codec; if(video_codec_tag) video_enc->codec_tag= video_codec_tag; if( (video_global_header&1) || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){ video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER; } if(video_global_header&2){ video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER; avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER; } if (video_stream_copy) { st->stream_copy = 1; video_enc->codec_type = AVMEDIA_TYPE_VIDEO; video_enc->sample_aspect_ratio = st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); } else { const char *p; int i; AVCodec *codec; AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1}; if (video_codec_name) { codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1); codec = avcodec_find_encoder_by_name(video_codec_name); output_codecs[nb_ocodecs] = codec; } else { codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO); codec = avcodec_find_encoder(codec_id); } video_enc->codec_id = codec_id; set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); if (codec && codec->supported_framerates && !force_fps) fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)]; video_enc->time_base.den = fps.num; video_enc->time_base.num = fps.den; video_enc->width = frame_width + frame_padright + frame_padleft; video_enc->height = frame_height + frame_padtop + frame_padbottom; video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255); video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio; choose_pixel_fmt(st, codec); if (intra_only) video_enc->gop_size = 0; if (video_qscale || same_quality) { video_enc->flags |= CODEC_FLAG_QSCALE; video_enc->global_quality= st->quality = FF_QP2LAMBDA * video_qscale; } if(intra_matrix) video_enc->intra_matrix = intra_matrix; if(inter_matrix) video_enc->inter_matrix = inter_matrix; p= video_rc_override_string; for(i=0; p; i++){ int start, end, q; int e=sscanf(p, "%d,%d,%d", &start, &end, &q); if(e!=3){ fprintf(stderr, "error parsing rc_override\n"); av_exit(1); } video_enc->rc_override= av_realloc(video_enc->rc_override, sizeof(RcOverride)*(i+1)); video_enc->rc_override[i].start_frame= start; video_enc->rc_override[i].end_frame = end; if(q>0){ video_enc->rc_override[i].qscale= q; video_enc->rc_override[i].quality_factor= 1.0; } else{ video_enc->rc_override[i].qscale= 0; video_enc->rc_override[i].quality_factor= -q/100.0; } p= strchr(p, '/'); if(p) p++; } video_enc->rc_override_count=i; if (!video_enc->rc_initial_buffer_occupancy) video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; video_enc->me_threshold= me_threshold; video_enc->intra_dc_precision= intra_dc_precision - 8; if (do_psnr) video_enc->flags|= CODEC_FLAG_PSNR; /* two pass mode */ if (do_pass) { if (do_pass == 1) { video_enc->flags |= CODEC_FLAG_PASS1; } else { video_enc->flags |= CODEC_FLAG_PASS2; } } } nb_ocodecs++; if (video_language) { av_metadata_set2(&st->metadata, "language", video_language, 0); av_freep(&video_language); } /* reset some key parameters */ video_disable = 0; av_freep(&video_codec_name); video_stream_copy = 0; frame_pix_fmt = PIX_FMT_NONE; }


static int opt_debug(void *optctx, const char *opt, const char *arg) { av_log_set_level(99); debug = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); return 0; }


static int pulse_set_volume(PulseData *s, double volume) { pa_operation *op; pa_cvolume cvol; pa_volume_t vol; const pa_sample_spec *ss = pa_stream_get_sample_spec(s->stream); vol = pa_sw_volume_multiply(lround(volume * PA_VOLUME_NORM), s->base_volume); pa_cvolume_set(&cvol, ss->channels, PA_VOLUME_NORM); pa_sw_cvolume_multiply_scalar(&cvol, &cvol, vol); pa_threaded_mainloop_lock(s->mainloop); op = pa_context_set_sink_input_volume(s->ctx, pa_stream_get_index(s->stream), &cvol, pulse_context_result, s); return pulse_finish_context_operation(s, op, "pa_context_set_sink_input_volume"); }


static void handle_port_status_write(EHCIState *s, int port, uint32_t val) { uint32_t *portsc = &s->portsc[port]; USBDevice *dev = s->ports[port].dev; /* Clear rwc bits */ *portsc &= ~(val & PORTSC_RWC_MASK); /* The guest may clear, but not set the PED bit */ *portsc &= val | ~PORTSC_PED; /* POWNER is masked out by RO_MASK as it is RO when we've no companion */ handle_port_owner_write(s, port, val); /* And finally apply RO_MASK */ val &= PORTSC_RO_MASK; if ((val & PORTSC_PRESET) && !(*portsc & PORTSC_PRESET)) { trace_usb_ehci_port_reset(port, 1); } if (!(val & PORTSC_PRESET) &&(*portsc & PORTSC_PRESET)) { trace_usb_ehci_port_reset(port, 0); if (dev && dev->attached) { usb_port_reset(&s->ports[port]); *portsc &= ~PORTSC_CSC; } /* * Table 2.16 Set the enable bit(and enable bit change) to indicate * to SW that this port has a high speed device attached */ if (dev && dev->attached && (dev->speedmask & USB_SPEED_MASK_HIGH)) { val |= PORTSC_PED; } } *portsc &= ~PORTSC_RO_MASK; *portsc |= val; }


static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], const uint8_t *map, unsigned size, VLC *vlc) { Node nodes[2*size], *tmp = &nodes[size]; int a, b, i; /* first compute probabilities from model */ tmp[0].count = 256; for (i=0; i<size-1; i++) { a = tmp[i].count * coeff_model[i] >> 8; b = tmp[i].count * (255 - coeff_model[i]) >> 8; nodes[map[2*i ]].count = a + !a; nodes[map[2*i+1]].count = b + !b; } /* then build the huffman tree accodring to probabilities */ ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, FF_HUFFMAN_FLAG_HNODE_FIRST); }


static void vga_putcharxy(DisplayState *ds, int x, int y, int ch, TextAttributes *t_attrib) { uint8_t *d; const uint8_t *font_ptr; unsigned int font_data, linesize, xorcol, bpp; int i; unsigned int fgcol, bgcol; #ifdef DEBUG_CONSOLE printf("x: %2i y: %2i", x, y); console_print_text_attributes(t_attrib, ch); #endif if (t_attrib->invers) { bgcol = color_table[t_attrib->bold][t_attrib->fgcol]; fgcol = color_table[t_attrib->bold][t_attrib->bgcol]; } else { fgcol = color_table[t_attrib->bold][t_attrib->fgcol]; bgcol = color_table[t_attrib->bold][t_attrib->bgcol]; } bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3; d = ds_get_data(ds) + ds_get_linesize(ds) * y * FONT_HEIGHT + bpp * x * FONT_WIDTH; linesize = ds_get_linesize(ds); font_ptr = vgafont16 + FONT_HEIGHT * ch; xorcol = bgcol ^ fgcol; switch(ds_get_bits_per_pixel(ds)) { case 8: for(i = 0; i < FONT_HEIGHT; i++) { font_data = *font_ptr++; if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) { font_data = 0xFFFF; } ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol; ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol; d += linesize; } break; case 16: case 15: for(i = 0; i < FONT_HEIGHT; i++) { font_data = *font_ptr++; if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) { font_data = 0xFFFF; } ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol; ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol; ((uint32_t *)d)[2] = (dmask4[(font_data >> 2) & 3] & xorcol) ^ bgcol; ((uint32_t *)d)[3] = (dmask4[(font_data >> 0) & 3] & xorcol) ^ bgcol; d += linesize; } break; case 32: for(i = 0; i < FONT_HEIGHT; i++) { font_data = *font_ptr++; if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) { font_data = 0xFFFF; } ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol; ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol; ((uint32_t *)d)[7] = (-((font_data >> 0) & 1) & xorcol) ^ bgcol; d += linesize; } break; } }


static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp) { int ret = 0; int64_t total_size = 0; BlockDriverState *bs; IscsiLun *iscsilun = NULL; QDict *bs_options; bs = bdrv_new("", &error_abort); /* Read out options */ total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; bs->opaque = g_malloc0(sizeof(struct IscsiLun)); iscsilun = bs->opaque; bs_options = qdict_new(); qdict_put(bs_options, "filename", qstring_from_str(filename)); ret = iscsi_open(bs, bs_options, 0, NULL); QDECREF(bs_options); if (ret != 0) { goto out; } iscsi_detach_aio_context(bs); if (iscsilun->type != TYPE_DISK) { ret = -ENODEV; goto out; } if (bs->total_sectors < total_size) { ret = -ENOSPC; goto out; } ret = 0; out: if (iscsilun->iscsi != NULL) { iscsi_destroy_context(iscsilun->iscsi); } g_free(bs->opaque); bs->opaque = NULL; bdrv_unref(bs); return ret; }


static int dvbsub_parse_clut_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { DVBSubContext *ctx = avctx->priv_data; const uint8_t *buf_end = buf + buf_size; int i, clut_id; int version; DVBSubCLUT *clut; int entry_id, depth , full_range; int y, cr, cb, alpha; int r, g, b, r_add, g_add, b_add; av_dlog(avctx, "DVB clut packet:\n"); for (i=0; i < buf_size; i++) { av_dlog(avctx, "%02x ", buf[i]); if (i % 16 == 15) av_dlog(avctx, "\n"); } if (i % 16) av_dlog(avctx, "\n"); clut_id = *buf++; version = ((*buf)>>4)&15; buf += 1; clut = get_clut(ctx, clut_id); if (!clut) { clut = av_malloc(sizeof(DVBSubCLUT)); memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); clut->id = clut_id; clut->version = -1; clut->next = ctx->clut_list; ctx->clut_list = clut; } if (clut->version != version) { clut->version = version; while (buf + 4 < buf_end) { entry_id = *buf++; depth = (*buf) & 0xe0; if (depth == 0) { av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf); return 0; } full_range = (*buf++) & 1; if (full_range) { y = *buf++; cr = *buf++; cb = *buf++; alpha = *buf++; } else { y = buf[0] & 0xfc; cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4; cb = (buf[1] << 2) & 0xf0; alpha = (buf[1] << 6) & 0xc0; buf += 2; } if (y == 0) alpha = 0xff; YUV_TO_RGB1_CCIR(cb, cr); YUV_TO_RGB2_CCIR(r, g, b, y); av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) { av_dlog(avctx, "More than one bit level marked: %x\n", depth); if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL) return AVERROR_INVALIDDATA; } if (depth & 0x80) clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha); else if (depth & 0x40) clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha); else if (depth & 0x20) clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha); } } return 0; }


static void scsi_write_request(SCSIDiskReq *r) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); uint32_t n; /* No data transfer may already be in progress */ assert(r->req.aiocb == NULL); n = r->iov.iov_len / 512; if (n) { qemu_iovec_init_external(&r->qiov, &r->iov, 1); r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->qiov, n, scsi_write_complete, r); if (r->req.aiocb == NULL) { scsi_write_complete(r, -EIO); } } else { /* Invoke completion routine to fetch data from host. */ scsi_write_complete(r, 0); } }


static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt) { DXAContext *c = s->priv_data; int ret; uint32_t size; uint8_t buf[DXA_EXTRA_SIZE], pal[768+4]; int pal_size = 0; if(!c->readvid && c->has_sound && c->bytes_left){ c->readvid = 1; avio_seek(s->pb, c->wavpos, SEEK_SET); size = FFMIN(c->bytes_left, c->bpc); ret = av_get_packet(s->pb, pkt, size); pkt->stream_index = 1; if(ret != size) return AVERROR(EIO); c->bytes_left -= size; c->wavpos = avio_tell(s->pb); return 0; } avio_seek(s->pb, c->vidpos, SEEK_SET); while(!url_feof(s->pb) && c->frames){ avio_read(s->pb, buf, 4); switch(AV_RL32(buf)){ case MKTAG('N', 'U', 'L', 'L'): if(av_new_packet(pkt, 4 + pal_size) < 0) return AVERROR(ENOMEM); pkt->stream_index = 0; if(pal_size) memcpy(pkt->data, pal, pal_size); memcpy(pkt->data + pal_size, buf, 4); c->frames--; c->vidpos = avio_tell(s->pb); c->readvid = 0; return 0; case MKTAG('C', 'M', 'A', 'P'): pal_size = 768+4; memcpy(pal, buf, 4); avio_read(s->pb, pal + 4, 768); break; case MKTAG('F', 'R', 'A', 'M'): avio_read(s->pb, buf + 4, DXA_EXTRA_SIZE - 4); size = AV_RB32(buf + 5); if(size > 0xFFFFFF){ av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size); return AVERROR_INVALIDDATA; } if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0) return AVERROR(ENOMEM); memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE); ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); if(ret != size){ av_free_packet(pkt); return AVERROR(EIO); } if(pal_size) memcpy(pkt->data, pal, pal_size); pkt->stream_index = 0; c->frames--; c->vidpos = avio_tell(s->pb); c->readvid = 0; return 0; default: av_log(s, AV_LOG_ERROR, "Unknown tag %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]); return AVERROR_INVALIDDATA; } } return AVERROR_EOF; }


static int qemu_rdma_post_recv_control(RDMAContext *rdma, int idx) { struct ibv_recv_wr *bad_wr; struct ibv_sge sge = { .addr = (uint64_t)(rdma->wr_data[idx].control), .length = RDMA_CONTROL_MAX_BUFFER, .lkey = rdma->wr_data[idx].control_mr->lkey, }; struct ibv_recv_wr recv_wr = { .wr_id = RDMA_WRID_RECV_CONTROL + idx, .sg_list = &sge, .num_sge = 1, }; if (ibv_post_recv(rdma->qp, &recv_wr, &bad_wr)) { return -1; } return 0; }


static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) { int scale; int i; int s0,s1,s2,d; int max=0; int min=0; int data[32]; s1 = prev->s1; s2 = prev->s2; for(i=0;i<32;i++) { s0 = wav[i]; d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; data[i]=d; if (max<d) max=d; if (min>d) min=d; s2 = s1; s1 = s0; } prev->s1 = s1; prev->s2 = s2; /* -8..+7 */ if (max==0 && min==0) { memset(adx,0,18); return; } if (max/7>-min/8) scale = max/7; else scale = -min/8; if (scale==0) scale=1; adx[0] = scale>>8; adx[1] = scale; for(i=0;i<16;i++) { adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); } }


void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx) { VRingUsedElem uelem; trace_virtqueue_fill(vq, elem, len, idx); virtqueue_unmap_sg(vq, elem, len); idx = (idx + vq->used_idx) % vq->vring.num; uelem.id = elem->index; uelem.len = len; vring_used_write(vq, &uelem, idx);