static int rd_frame(CinepakEncContext *s, const AVFrame *frame, int isakeyframe, unsigned char *buf, int buf_size) { int num_strips, strip, i, y, nexty, size, temp_size, best_size; AVPicture last_pict, pict, scratch_pict; int64_t best_score = 0, score, score_temp; #ifdef CINEPAK_REPORT_SERR int64_t best_serr = 0, serr, serr_temp; #endif int best_nstrips; if(s->pix_fmt == AV_PIX_FMT_RGB24) { int x; // build a copy of the given frame in the correct colorspace for(y = 0; y < s->h; y += 2) { for(x = 0; x < s->w; x += 2) { uint8_t *ir[2]; int32_t r, g, b, rr, gg, bb; ir[0] = ((AVPicture*)frame)->data[0] + x*3 + y*((AVPicture*)frame)->linesize[0]; ir[1] = ir[0] + ((AVPicture*)frame)->linesize[0]; get_sub_picture(s, x, y, (AVPicture*)s->input_frame, &scratch_pict); r = g = b = 0; for(i=0; i<4; ++i) { int i1, i2; i1 = (i&1); i2 = (i>=2); rr = ir[i2][i1*3+0]; gg = ir[i2][i1*3+1]; bb = ir[i2][i1*3+2]; r += rr; g += gg; b += bb; // using fixed point arithmetic for portable repeatability, scaling by 2^23 // "Y" // rr = 0.2857*rr + 0.5714*gg + 0.1429*bb; rr = (2396625*rr + 4793251*gg + 1198732*bb) >> 23; if( rr < 0) rr = 0; else if (rr > 255) rr = 255; scratch_pict.data[0][i1 + i2*scratch_pict.linesize[0]] = rr; } // let us scale down as late as possible // r /= 4; g /= 4; b /= 4; // "U" // rr = -0.1429*r - 0.2857*g + 0.4286*b; rr = (-299683*r - 599156*g + 898839*b) >> 23; if( rr < -128) rr = -128; else if (rr > 127) rr = 127; scratch_pict.data[1][0] = rr + 128; // quantize needs unsigned // "V" // rr = 0.3571*r - 0.2857*g - 0.0714*b; rr = (748893*r - 599156*g - 149737*b) >> 23; if( rr < -128) rr = -128; else if (rr > 127) rr = 127; scratch_pict.data[2][0] = rr + 128; // quantize needs unsigned } } } //would be nice but quite certainly incompatible with vintage players: // support encoding zero strips (meaning skip the whole frame) for(num_strips = s->min_strips; num_strips <= s->max_strips && num_strips <= s->h / MB_SIZE; num_strips++) { score = 0; size = 0; #ifdef CINEPAK_REPORT_SERR serr = 0; #endif for(y = 0, strip = 1; y < s->h; strip++, y = nexty) { int strip_height; nexty = strip * s->h / num_strips; // <= s->h //make nexty the next multiple of 4 if not already there if(nexty & 3) nexty += 4 - (nexty & 3); strip_height = nexty - y; if(strip_height <= 0) { // can this ever happen? av_log(s->avctx, AV_LOG_INFO, "skipping zero height strip %i of %i\n", strip, num_strips); continue; } if(s->pix_fmt == AV_PIX_FMT_RGB24) get_sub_picture(s, 0, y, (AVPicture*)s->input_frame, &pict); else get_sub_picture(s, 0, y, (AVPicture*)frame, &pict); get_sub_picture(s, 0, y, (AVPicture*)s->last_frame, &last_pict); get_sub_picture(s, 0, y, (AVPicture*)s->scratch_frame, &scratch_pict); if((temp_size = rd_strip(s, y, strip_height, isakeyframe, &last_pict, &pict, &scratch_pict, s->frame_buf + size + CVID_HEADER_SIZE, &score_temp #ifdef CINEPAK_REPORT_SERR , &serr_temp #endif )) < 0) return temp_size; score += score_temp; #ifdef CINEPAK_REPORT_SERR serr += serr_temp; #endif size += temp_size; //av_log(s->avctx, AV_LOG_INFO, "strip %d, isakeyframe=%d", strip, isakeyframe); //av_log(s->avctx, AV_LOG_INFO, "\n"); } if(best_score == 0 || score < best_score) { best_score = score; #ifdef CINEPAK_REPORT_SERR best_serr = serr; #endif best_size = size + write_cvid_header(s, s->frame_buf, num_strips, size, isakeyframe); //av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12lli, %i B\n", num_strips, (long long int)score, best_size); #ifdef CINEPAK_REPORT_SERR av_log(s->avctx, AV_LOG_INFO, "best number of strips so far: %2i, %12lli, %i B\n", num_strips, (long long int)serr, best_size); #endif FFSWAP(AVFrame *, s->best_frame, s->scratch_frame); memcpy(buf, s->frame_buf, best_size); best_nstrips = num_strips; } // avoid trying too many strip numbers without a real reason // (this makes the processing of the very first frame faster) if(num_strips - best_nstrips > 4) break; } // let the number of strips slowly adapt to the changes in the contents, // compared to full bruteforcing every time this will occasionally lead // to some r/d performance loss but makes encoding up to several times faster if(!s->strip_number_delta_range) { if(best_nstrips == s->max_strips) { // let us try to step up s->max_strips = best_nstrips + 1; if(s->max_strips >= s->max_max_strips) s->max_strips = s->max_max_strips; } else { // try to step down s->max_strips = best_nstrips; } s->min_strips = s->max_strips - 1; if(s->min_strips < s->min_min_strips) s->min_strips = s->min_min_strips; } else { s->max_strips = best_nstrips + s->strip_number_delta_range; if(s->max_strips >= s->max_max_strips) s->max_strips = s->max_max_strips; s->min_strips = best_nstrips - s->strip_number_delta_range; if(s->min_strips < s->min_min_strips) s->min_strips = s->min_min_strips; } return best_size; }


static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max) { VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev); int n = 0; while ((n < max) && (dev->out != dev->in)) { buf[n++] = dev->buf[dev->out++ % VTERM_BUFSIZE]; qemu_chr_fe_accept_input(&dev->chardev); return n;


int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev) { S390PCIBusDevice *pbdev; uint32_t fid = data >> ZPCI_MSI_VEC_BITS; uint32_t vec = data & ZPCI_MSI_VEC_MASK; pbdev = s390_pci_find_dev_by_fid(fid); if (!pbdev) { DPRINTF("add_msi_route no dev\n"); return -ENODEV; } pbdev->routes.adapter.ind_offset = vec; route->type = KVM_IRQ_ROUTING_S390_ADAPTER; route->flags = 0; route->u.adapter.summary_addr = pbdev->routes.adapter.summary_addr; route->u.adapter.ind_addr = pbdev->routes.adapter.ind_addr; route->u.adapter.summary_offset = pbdev->routes.adapter.summary_offset; route->u.adapter.ind_offset = pbdev->routes.adapter.ind_offset; route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id; return 0; }


static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(qdev_get_machine()); if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { uint32_t node; if (!smc->dr_lmb_enabled) { error_setg(errp, "Memory hotplug not supported for this machine"); return; } node = object_property_get_int(OBJECT(dev), PC_DIMM_NODE_PROP, errp); if (*errp) { return; } spapr_memory_plug(hotplug_dev, dev, node, errp); } }


void spapr_events_init(sPAPRMachineState *spapr) { QTAILQ_INIT(&spapr->pending_events); spapr->check_exception_irq = xics_alloc(spapr->icp, 0, 0, false); spapr->epow_notifier.notify = spapr_powerdown_req; qemu_register_powerdown_notifier(&spapr->epow_notifier); spapr_rtas_register(RTAS_CHECK_EXCEPTION, "check-exception", check_exception); spapr_rtas_register(RTAS_EVENT_SCAN, "event-scan", event_scan); }


static void test_visitor_in_uint(TestInputVisitorData *data, const void *unused) { Error *err = NULL; uint64_t res = 0; int64_t i64; double dbl; int value = 42; Visitor *v; v = visitor_input_test_init(data, "%d", value); visit_type_uint64(v, NULL, &res, &error_abort); g_assert_cmpuint(res, ==, (uint64_t)value); visit_type_int(v, NULL, &i64, &error_abort); g_assert_cmpint(i64, ==, value); visit_type_number(v, NULL, &dbl, &error_abort); g_assert_cmpfloat(dbl, ==, value); /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */ v = visitor_input_test_init(data, "%d", -value); visit_type_uint64(v, NULL, &res, &error_abort); g_assert_cmpuint(res, ==, (uint64_t)-value); /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */ v = visitor_input_test_init(data, "18446744073709551574"); visit_type_uint64(v, NULL, &res, &err); error_free_or_abort(&err); visit_type_number(v, NULL, &dbl, &error_abort); g_assert_cmpfloat(dbl, ==, 18446744073709552000.0); }


static int kvm_check_many_ioeventfds(void) { /* Userspace can use ioeventfd for io notification. This requires a host * that supports eventfd(2) and an I/O thread; since eventfd does not * support SIGIO it cannot interrupt the vcpu. * * Older kernels have a 6 device limit on the KVM io bus. Find out so we * can avoid creating too many ioeventfds. */ #if defined(CONFIG_EVENTFD) && defined(CONFIG_IOTHREAD) int ioeventfds[7]; int i, ret = 0; for (i = 0; i < ARRAY_SIZE(ioeventfds); i++) { ioeventfds[i] = eventfd(0, EFD_CLOEXEC); if (ioeventfds[i] < 0) { break; } ret = kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, true); if (ret < 0) { close(ioeventfds[i]); break; } } /* Decide whether many devices are supported or not */ ret = i == ARRAY_SIZE(ioeventfds); while (i-- > 0) { kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false); close(ioeventfds[i]); } return ret; #else return 0; #endif }


static int init_common(VC9Context *v) { static int done = 0; int i; v->mv_type_mb_plane = v->direct_mb_plane = v->skip_mb_plane = NULL; v->pq = -1; #if HAS_ADVANCED_PROFILE v->ac_pred_plane = v->over_flags_plane = NULL; v->hrd_rate = v->hrd_buffer = NULL; #endif #if 0 // spec -> actual tables converter for(i=0; i<64; i++){ int code= (vc9_norm6_spec[i][1] << vc9_norm6_spec[i][4]) + vc9_norm6_spec[i][3]; av_log(NULL, AV_LOG_DEBUG, "0x%03X, ", code); if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); } for(i=0; i<64; i++){ int code= vc9_norm6_spec[i][2] + vc9_norm6_spec[i][4]; av_log(NULL, AV_LOG_DEBUG, "%2d, ", code); if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); } #endif if(!done) { done = 1; INIT_VLC(&vc9_bfraction_vlc, VC9_BFRACTION_VLC_BITS, 23, vc9_bfraction_bits, 1, 1, vc9_bfraction_codes, 1, 1, 1); INIT_VLC(&vc9_norm2_vlc, VC9_NORM2_VLC_BITS, 4, vc9_norm2_bits, 1, 1, vc9_norm2_codes, 1, 1, 1); INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64, vc9_norm6_bits, 1, 1, vc9_norm6_codes, 2, 2, 1); INIT_VLC(&vc9_cbpcy_i_vlc, VC9_CBPCY_I_VLC_BITS, 64, vc9_cbpcy_i_bits, 1, 1, vc9_cbpcy_i_codes, 2, 2, 1); INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7, vc9_imode_bits, 1, 1, vc9_imode_codes, 1, 1, 1); for(i=0; i<3; i++) { INIT_VLC(&vc9_4mv_block_pattern_vlc[i], VC9_4MV_BLOCK_PATTERN_VLC_BITS, 16, vc9_4mv_block_pattern_bits[i], 1, 1, vc9_4mv_block_pattern_codes[i], 1, 1, 1); INIT_VLC(&vc9_cbpcy_p_vlc[i], VC9_CBPCY_P_VLC_BITS, 64, vc9_cbpcy_p_bits[i], 1, 1, vc9_cbpcy_p_codes[i], 2, 2, 1); } for (i=0; i<2; i++) { INIT_VLC(&vc9_mv_diff_vlc[i], VC9_MV_DIFF_VLC_BITS, 73, vc9_mv_diff_bits[i], 1, 1, vc9_mv_diff_codes[i], 2, 2, 1); INIT_VLC(&vc9_luma_dc_vlc[i], VC9_LUMA_DC_VLC_BITS, 120, vc9_luma_dc_bits[i], 1, 1, vc9_luma_dc_codes[i], 4, 4, 1); INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16, vc9_ttmb_bits[i], 1, 1, vc9_ttmb_codes[i], 2, 2, 1); } } return 0; }


static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[pkt->stream_index]; AVIOContext *pb = s->pb; AVFrame *frame; int* first_pkt = s->priv_data; int width, height, h_chroma_shift, v_chroma_shift; int i; char buf2[Y4M_LINE_MAX + 1]; uint8_t *ptr, *ptr1, *ptr2; frame = (AVFrame *)pkt->data; /* for the first packet we have to output the header as well */ if (*first_pkt) { *first_pkt = 0; if (yuv4_generate_header(s, buf2) < 0) { av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n"); return AVERROR(EIO); } else { avio_write(pb, buf2, strlen(buf2)); } } /* construct frame header */ avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC); width = st->codecpar->width; height = st->codecpar->height; ptr = frame->data[0]; switch (st->codecpar->format) { case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_YUV411P: case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV444P: break; case AV_PIX_FMT_GRAY16: case AV_PIX_FMT_YUV420P9: case AV_PIX_FMT_YUV422P9: case AV_PIX_FMT_YUV444P9: case AV_PIX_FMT_YUV420P10: case AV_PIX_FMT_YUV422P10: case AV_PIX_FMT_YUV444P10: case AV_PIX_FMT_YUV420P12: case AV_PIX_FMT_YUV422P12: case AV_PIX_FMT_YUV444P12: case AV_PIX_FMT_YUV420P14: case AV_PIX_FMT_YUV422P14: case AV_PIX_FMT_YUV444P14: case AV_PIX_FMT_YUV420P16: case AV_PIX_FMT_YUV422P16: case AV_PIX_FMT_YUV444P16: width *= 2; break; default: av_log(s, AV_LOG_ERROR, "The pixel format '%s' is not supported.\n", av_get_pix_fmt_name(st->codecpar->format)); return AVERROR(EINVAL); } for (i = 0; i < height; i++) { avio_write(pb, ptr, width); ptr += frame->linesize[0]; } if (st->codecpar->format != AV_PIX_FMT_GRAY8 && st->codecpar->format != AV_PIX_FMT_GRAY16) { // Adjust for smaller Cb and Cr planes av_pix_fmt_get_chroma_sub_sample(st->codecpar->format, &h_chroma_shift, &v_chroma_shift); // Shift right, rounding up width = AV_CEIL_RSHIFT(width, h_chroma_shift); height = AV_CEIL_RSHIFT(height, v_chroma_shift); ptr1 = frame->data[1]; ptr2 = frame->data[2]; for (i = 0; i < height; i++) { /* Cb */ avio_write(pb, ptr1, width); ptr1 += frame->linesize[1]; } for (i = 0; i < height; i++) { /* Cr */ avio_write(pb, ptr2, width); ptr2 += frame->linesize[2]; } } return 0; }


static void FUNC(transquant_bypass4x4)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t stride) { int x, y; pixel *dst = (pixel *)_dst; stride /= sizeof(pixel); for (y = 0; y < 4; y++) { for (x = 0; x < 4; x++) { dst[x] += *coeffs; coeffs++; } dst += stride; } }


static int RENAME(epzs_motion_search4)(MpegEncContext * s, int *mx_ptr, int *my_ptr, int P[10][2], int pred_x, int pred_y, uint8_t *src_data[3], uint8_t *ref_data[3], int stride, int uvstride, int16_t (*last_mv)[2], int ref_mv_scale, uint8_t * const mv_penalty) { int best[2]={0, 0}; int d, dmin; const int shift= 1+s->quarter_sample; uint32_t *map= s->me.map; int map_generation; const int penalty_factor= s->me.penalty_factor; const int size=1; const int h=8; const int ref_mv_stride= s->mb_stride; const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride; me_cmp_func cmp, chroma_cmp; LOAD_COMMON cmp= s->dsp.me_cmp[size]; chroma_cmp= s->dsp.me_cmp[size+1]; map_generation= update_map_generation(s); dmin = 1000000; //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); /* first line */ if (s->first_slice_line) { CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift) }else{ CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift) //FIXME try some early stop if(dmin>64*2){ CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift) CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift) CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift) CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift) CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16) } } if(dmin>64*4){ CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16) if(s->end_mb_y == s->mb_height || s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) } if(s->me.dia_size==-1) dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, pred_x, pred_y, penalty_factor, shift, map, map_generation, size, h, mv_penalty); else if(s->me.dia_size<-1) dmin= RENAME(sab_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, pred_x, pred_y, penalty_factor, shift, map, map_generation, size, h, mv_penalty); else if(s->me.dia_size<2) dmin= RENAME(small_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, pred_x, pred_y, penalty_factor, shift, map, map_generation, size, h, mv_penalty); else dmin= RENAME(var_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride, pred_x, pred_y, penalty_factor, shift, map, map_generation, size, h, mv_penalty); *mx_ptr= best[0]; *my_ptr= best[1]; // printf("%d %d %d \n", best[0], best[1], dmin); return dmin; }


static int ftp_passive_mode(FTPContext *s) { char *res = NULL, *start, *end; int i; const char *command = "PASV\r\n"; const int pasv_codes[] = {227, 0}; if (!ftp_send_command(s, command, pasv_codes, &res)) goto fail; start = NULL; for (i = 0; i < strlen(res); ++i) { if (res[i] == '(') { start = res + i + 1; } else if (res[i] == ')') { end = res + i; break; } } if (!start || !end) goto fail; *end = '\0'; /* skip ip */ if (!av_strtok(start, ",", &end)) goto fail; if (!av_strtok(end, ",", &end)) goto fail; if (!av_strtok(end, ",", &end)) goto fail; if (!av_strtok(end, ",", &end)) goto fail; /* parse port number */ start = av_strtok(end, ",", &end); if (!start) goto fail; s->server_data_port = atoi(start) * 256; start = av_strtok(end, ",", &end); if (!start) goto fail; s->server_data_port += atoi(start); av_dlog(s, "Server data port: %d\n", s->server_data_port); av_free(res); return 0; fail: av_free(res); s->server_data_port = -1; return AVERROR(EIO); }


void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk, VirtIOBlockDataPlane **dataplane, Error **errp) { VirtIOBlockDataPlane *s; Error *local_err = NULL; *dataplane = NULL; if (!blk->data_plane) { return; } if (blk->scsi) { error_setg(errp, "device is incompatible with x-data-plane, use scsi=off"); return; } if (blk->config_wce) { error_setg(errp, "device is incompatible with x-data-plane, " "use config-wce=off"); return; } /* If dataplane is (re-)enabled while the guest is running there could be * block jobs that can conflict. */ if (bdrv_op_is_blocked(blk->conf.bs, BLOCK_OP_TYPE_DATAPLANE, &local_err)) { error_report("cannot start dataplane thread: %s", error_get_pretty(local_err)); error_free(local_err); return; } s = g_new0(VirtIOBlockDataPlane, 1); s->vdev = vdev; s->blk = blk; if (blk->iothread) { s->iothread = blk->iothread; object_ref(OBJECT(s->iothread)); } else { /* Create per-device IOThread if none specified. This is for * x-data-plane option compatibility. If x-data-plane is removed we * can drop this. */ object_initialize(&s->internal_iothread_obj, sizeof(s->internal_iothread_obj), TYPE_IOTHREAD); user_creatable_complete(OBJECT(&s->internal_iothread_obj), &error_abort); s->iothread = &s->internal_iothread_obj; } s->ctx = iothread_get_aio_context(s->iothread); error_setg(&s->blocker, "block device is in use by data plane"); bdrv_op_block_all(blk->conf.bs, s->blocker); *dataplane = s; }


static Suite *QList_suite(void) { Suite *s; TCase *qlist_public_tcase; s = suite_create("QList suite"); qlist_public_tcase = tcase_create("Public Interface"); suite_add_tcase(s, qlist_public_tcase); tcase_add_test(qlist_public_tcase, qlist_new_test); tcase_add_test(qlist_public_tcase, qlist_append_test); tcase_add_test(qlist_public_tcase, qobject_to_qlist_test); tcase_add_test(qlist_public_tcase, qlist_destroy_test); tcase_add_test(qlist_public_tcase, qlist_iter_test); return s; }


static void spr_write_decr (DisasContext *ctx, int sprn, int gprn) { if (use_icount) { gen_io_start(); } gen_helper_store_decr(cpu_env, cpu_gpr[gprn]); if (use_icount) { gen_io_end(); gen_stop_exception(ctx); } }


static inline void IRQ_resetbit(IRQQueue *q, int n_IRQ) { reset_bit(q->queue, n_IRQ); }


static void rtas_write_pci_config(sPAPREnvironment *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { uint32_t val, size, addr; PCIDevice *dev = find_dev(spapr, 0, rtas_ld(args, 0)); if (!dev) { rtas_st(rets, 0, -1); return; } val = rtas_ld(args, 2); size = rtas_ld(args, 1); addr = rtas_pci_cfgaddr(rtas_ld(args, 0)); pci_host_config_write_common(dev, addr, pci_config_size(dev), val, size); rtas_st(rets, 0, 0); }


static void virtio_mmio_device_plugged(DeviceState *opaque) { VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque); proxy->host_features |= (0x1 << VIRTIO_F_NOTIFY_ON_EMPTY); proxy->host_features = virtio_bus_get_vdev_features(&proxy->bus, proxy->host_features); }


static void virtio_serial_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->init = virtio_serial_init_pci; k->exit = virtio_serial_exit_pci; k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE; k->revision = VIRTIO_PCI_ABI_VERSION; k->class_id = PCI_CLASS_COMMUNICATION_OTHER; dc->alias = "virtio-serial"; dc->reset = virtio_pci_reset; dc->props = virtio_serial_properties; }


static VncServerInfo *vnc_server_info_get(VncDisplay *vd) { VncServerInfo *info; Error *err = NULL; info = g_malloc(sizeof(*info)); info->base = g_malloc(sizeof(*info->base)); vnc_init_basic_info_from_server_addr(vd->lsock, info->base, &err); info->has_auth = true; info->auth = g_strdup(vnc_auth_name(vd)); if (err) { qapi_free_VncServerInfo(info); info = NULL; error_free(err); } return info; }


static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict) { const char *codec_string = encoder ? "encoder" : "decoder"; AVCodec *codec; if(!name) return CODEC_ID_NONE; codec = encoder ? avcodec_find_encoder_by_name(name) : avcodec_find_decoder_by_name(name); if(!codec) { fprintf(stderr, "Unknown %s '%s'\n", codec_string, name); ffmpeg_exit(1); } if(codec->type != type) { fprintf(stderr, "Invalid %s type '%s'\n", codec_string, name); ffmpeg_exit(1); } if(codec->capabilities & CODEC_CAP_EXPERIMENTAL && strict > FF_COMPLIANCE_EXPERIMENTAL) { fprintf(stderr, "%s '%s' is experimental and might produce bad " "results.\nAdd '-strict experimental' if you want to use it.\n", codec_string, codec->name); codec = encoder ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id); if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL)) fprintf(stderr, "Or use the non experimental %s '%s'.\n", codec_string, codec->name); ffmpeg_exit(1); } return codec->id; }


static void xen_ram_init(ram_addr_t ram_size) { RAMBlock *new_block; ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; new_block = qemu_mallocz(sizeof (*new_block)); pstrcpy(new_block->idstr, sizeof (new_block->idstr), "xen.ram"); new_block->host = NULL; new_block->offset = 0; new_block->length = ram_size; QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty, new_block->length >> TARGET_PAGE_BITS); memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), 0xff, new_block->length >> TARGET_PAGE_BITS); if (ram_size >= 0xe0000000 ) { above_4g_mem_size = ram_size - 0xe0000000; below_4g_mem_size = 0xe0000000; } else { below_4g_mem_size = ram_size; } cpu_register_physical_memory(0, below_4g_mem_size, new_block->offset); #if TARGET_PHYS_ADDR_BITS > 32 if (above_4g_mem_size > 0) { cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size, new_block->offset + below_4g_mem_size); } #endif }


static int tight_init_stream(VncState *vs, int stream_id, int level, int strategy) { z_streamp zstream = &vs->tight_stream[stream_id]; if (zstream->opaque == NULL) { int err; VNC_DEBUG("VNC: TIGHT: initializing zlib stream %d\n", stream_id); VNC_DEBUG("VNC: TIGHT: opaque = %p | vs = %p\n", zstream->opaque, vs); zstream->zalloc = vnc_zlib_zalloc; zstream->zfree = vnc_zlib_zfree; err = deflateInit2(zstream, level, Z_DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, strategy); if (err != Z_OK) { fprintf(stderr, "VNC: error initializing zlib\n"); return -1; } vs->tight_levels[stream_id] = level; zstream->opaque = vs; } if (vs->tight_levels[stream_id] != level) { if (deflateParams(zstream, level, strategy) != Z_OK) { return -1; } vs->tight_levels[stream_id] = level; } return 0; }


static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) { ReadInfo *read_info = (ReadInfo *) sccb; MachineState *machine = MACHINE(qdev_get_machine()); sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev(); CPUState *cpu; int cpu_count = 0; int rnsize, rnmax; int slots = MIN(machine->ram_slots, s390_get_memslot_count(kvm_state)); IplParameterBlock *ipib = s390_ipl_get_iplb(); CPU_FOREACH(cpu) { cpu_count++; } /* CPU information */ read_info->entries_cpu = cpu_to_be16(cpu_count); read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries)); read_info->highest_cpu = cpu_to_be16(max_cpus); read_info->ibc_val = cpu_to_be32(s390_get_ibc_val()); /* Configuration Characteristic (Extension) */ s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR, read_info->conf_char); s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, read_info->conf_char_ext); prepare_cpu_entries(sclp, read_info->entries, cpu_count); read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO | SCLP_HAS_PCI_RECONFIG); /* Memory Hotplug is only supported for the ccw machine type */ if (mhd) { mhd->standby_subregion_size = MEM_SECTION_SIZE; /* Deduct the memory slot already used for core */ if (slots > 0) { while ((mhd->standby_subregion_size * (slots - 1) < mhd->standby_mem_size)) { mhd->standby_subregion_size = mhd->standby_subregion_size << 1; } } /* * Initialize mapping of guest standby memory sections indicating which * are and are not online. Assume all standby memory begins offline. */ if (mhd->standby_state_map == 0) { if (mhd->standby_mem_size % mhd->standby_subregion_size) { mhd->standby_state_map = g_malloc0((mhd->standby_mem_size / mhd->standby_subregion_size + 1) * (mhd->standby_subregion_size / MEM_SECTION_SIZE)); } else { mhd->standby_state_map = g_malloc0(mhd->standby_mem_size / MEM_SECTION_SIZE); } } mhd->padded_ram_size = ram_size + mhd->pad_size; mhd->rzm = 1 << mhd->increment_size; read_info->facilities |= cpu_to_be64(SCLP_FC_ASSIGN_ATTACH_READ_STOR); } read_info->mha_pow = s390_get_mha_pow(); read_info->hmfai = cpu_to_be32(s390_get_hmfai()); rnsize = 1 << (sclp->increment_size - 20); if (rnsize <= 128) { read_info->rnsize = rnsize; } else { read_info->rnsize = 0; read_info->rnsize2 = cpu_to_be32(rnsize); } rnmax = machine->maxram_size >> sclp->increment_size; if (rnmax < 0x10000) { read_info->rnmax = cpu_to_be16(rnmax); } else { read_info->rnmax = cpu_to_be16(0); read_info->rnmax2 = cpu_to_be64(rnmax); } if (ipib && ipib->flags & DIAG308_FLAGS_LP_VALID) { memcpy(&read_info->loadparm, &ipib->loadparm, sizeof(read_info->loadparm)); } else { s390_ipl_set_loadparm(read_info->loadparm); } sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION); }


static void init_proc_970GX (CPUPPCState *env) { gen_spr_ne_601(env); gen_spr_7xx(env); /* Time base */ gen_tbl(env); /* Hardware implementation registers */ /* XXX : not implemented */ spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_clear, 0x60000000); /* XXX : not implemented */ spr_register(env, SPR_HID1, "HID1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_750_HID2, "HID2", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_970_HID5, "HID5", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* Memory management */ /* XXX: not correct */ gen_low_BATs(env); #if 0 // TODO env->slb_nr = 32; #endif init_excp_970(env); env->dcache_line_size = 128; env->icache_line_size = 128; /* Allocate hardware IRQ controller */ ppc970_irq_init(env); #if !defined(CONFIG_USER_ONLY) /* Hardware reset vector */ env->hreset_vector = 0x0000000000000100ULL; #endif }


static void QEMU_NORETURN force_sig(int sig) { int host_sig; host_sig = target_to_host_signal(sig); fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n", sig, strsignal(host_sig)); #if 1 gdb_signalled(thread_env, sig); _exit(-host_sig); #else { struct sigaction act; sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = SIG_DFL; sigaction(SIGABRT, &act, NULL); abort(); } #endif }


static void sd_close(BlockDriverState *bs) { Error *local_err = NULL; BDRVSheepdogState *s = bs->opaque; SheepdogVdiReq hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; unsigned int wlen, rlen = 0; int fd, ret; DPRINTF("%s\n", s->name); fd = connect_to_sdog(s, &local_err); if (fd < 0) { error_report_err(local_err); return; } memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_RELEASE_VDI; hdr.type = LOCK_TYPE_NORMAL; hdr.base_vdi_id = s->inode.vdi_id; wlen = strlen(s->name) + 1; hdr.data_length = wlen; hdr.flags = SD_FLAG_CMD_WRITE; ret = do_req(fd, s->bs, (SheepdogReq *)&hdr, s->name, &wlen, &rlen); closesocket(fd); if (!ret && rsp->result != SD_RES_SUCCESS && rsp->result != SD_RES_VDI_NOT_LOCKED) { error_report("%s, %s", sd_strerror(rsp->result), s->name); } aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd, false, NULL, NULL, NULL, NULL); closesocket(s->fd); qapi_free_SocketAddressLegacy(s->addr); }


static uint64_t malta_fpga_read(void *opaque, hwaddr addr, unsigned size) { MaltaFPGAState *s = opaque; uint32_t val = 0; uint32_t saddr; saddr = (addr & 0xfffff); switch (saddr) { /* SWITCH Register */ case 0x00200: val = 0x00000000; /* All switches closed */ break; /* STATUS Register */ case 0x00208: #ifdef TARGET_WORDS_BIGENDIAN val = 0x00000012; #else val = 0x00000010; #endif break; /* JMPRS Register */ case 0x00210: val = 0x00; break; /* LEDBAR Register */ case 0x00408: val = s->leds; break; /* BRKRES Register */ case 0x00508: val = s->brk; break; /* UART Registers are handled directly by the serial device */ /* GPOUT Register */ case 0x00a00: val = s->gpout; break; /* XXX: implement a real I2C controller */ /* GPINP Register */ case 0x00a08: /* IN = OUT until a real I2C control is implemented */ if (s->i2csel) val = s->i2cout; else val = 0x00; break; /* I2CINP Register */ case 0x00b00: val = ((s->i2cin & ~1) | eeprom24c0x_read()); break; /* I2COE Register */ case 0x00b08: val = s->i2coe; break; /* I2COUT Register */ case 0x00b10: val = s->i2cout; break; /* I2CSEL Register */ case 0x00b18: val = s->i2csel; break; default: #if 0 printf ("malta_fpga_read: Bad register offset 0x" TARGET_FMT_lx "\n", addr); #endif break; } return val; }


static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb) { MpegEncContext *s = &ctx->m; int time_incr, time_increment; int64_t pts; s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */ if (s->pict_type == AV_PICTURE_TYPE_B && s->low_delay && ctx->vol_control_parameters == 0 && !(s->flags & CODEC_FLAG_LOW_DELAY)) { av_log(s->avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n"); s->low_delay = 0; } s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B; if (s->partitioned_frame) s->decode_mb = mpeg4_decode_partitioned_mb; else s->decode_mb = mpeg4_decode_mb; time_incr = 0; while (get_bits1(gb) != 0) time_incr++; check_marker(gb, "before time_increment"); if (ctx->time_increment_bits == 0 || !(show_bits(gb, ctx->time_increment_bits + 1) & 1)) { av_log(s->avctx, AV_LOG_WARNING, "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", ctx->time_increment_bits); for (ctx->time_increment_bits = 1; ctx->time_increment_bits < 16; ctx->time_increment_bits++) { if (s->pict_type == AV_PICTURE_TYPE_P || (s->pict_type == AV_PICTURE_TYPE_S && ctx->vol_sprite_usage == GMC_SPRITE)) { if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30) break; } else if ((show_bits(gb, ctx->time_increment_bits + 5) & 0x1F) == 0x18) break; } av_log(s->avctx, AV_LOG_WARNING, "time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits); if (s->avctx->framerate.num && 4*s->avctx->framerate.num < 1<<ctx->time_increment_bits) { s->avctx->framerate.num = 1<<ctx->time_increment_bits; s->avctx->time_base = av_inv_q(av_mul_q(s->avctx->framerate, (AVRational){s->avctx->ticks_per_frame, 1})); } } if (IS_3IV1) time_increment = get_bits1(gb); // FIXME investigate further else time_increment = get_bits(gb, ctx->time_increment_bits); if (s->pict_type != AV_PICTURE_TYPE_B) { s->last_time_base = s->time_base; s->time_base += time_incr; s->time = s->time_base * s->avctx->framerate.num + time_increment; if (s->workaround_bugs & FF_BUG_UMP4) { if (s->time < s->last_non_b_time) { /* header is not mpeg-4-compatible, broken encoder, * trying to workaround */ s->time_base++; s->time += s->avctx->framerate.num; } } s->pp_time = s->time - s->last_non_b_time; s->last_non_b_time = s->time; } else { s->time = (s->last_time_base + time_incr) * s->avctx->framerate.num + time_increment; s->pb_time = s->pp_time - (s->last_non_b_time - s->time); if (s->pp_time <= s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time <= 0) { /* messed up order, maybe after seeking? skipping current b-frame */ return FRAME_SKIPPED; } ff_mpeg4_init_direct_mv(s); if (ctx->t_frame == 0) ctx->t_frame = s->pb_time; if (ctx->t_frame == 0) ctx->t_frame = 1; // 1/0 protection s->pp_field_time = (ROUNDED_DIV(s->last_non_b_time, ctx->t_frame) - ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; s->pb_field_time = (ROUNDED_DIV(s->time, ctx->t_frame) - ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2; if (s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) { s->pb_field_time = 2; s->pp_field_time = 4; if (!s->progressive_sequence) return FRAME_SKIPPED; } } if (s->avctx->framerate.den) pts = ROUNDED_DIV(s->time, s->avctx->framerate.den); else pts = AV_NOPTS_VALUE; if (s->avctx->debug&FF_DEBUG_PTS) av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", pts); check_marker(gb, "before vop_coded"); /* vop coded */ if (get_bits1(gb) != 1) { if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); return FRAME_SKIPPED; } if (ctx->new_pred) decode_new_pred(ctx, gb); if (ctx->shape != BIN_ONLY_SHAPE && (s->pict_type == AV_PICTURE_TYPE_P || (s->pict_type == AV_PICTURE_TYPE_S && ctx->vol_sprite_usage == GMC_SPRITE))) { /* rounding type for motion estimation */ s->no_rounding = get_bits1(gb); } else { s->no_rounding = 0; } // FIXME reduced res stuff if (ctx->shape != RECT_SHAPE) { if (ctx->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) { skip_bits(gb, 13); /* width */ skip_bits1(gb); /* marker */ skip_bits(gb, 13); /* height */ skip_bits1(gb); /* marker */ skip_bits(gb, 13); /* hor_spat_ref */ skip_bits1(gb); /* marker */ skip_bits(gb, 13); /* ver_spat_ref */ } skip_bits1(gb); /* change_CR_disable */ if (get_bits1(gb) != 0) skip_bits(gb, 8); /* constant_alpha_value */ } // FIXME complexity estimation stuff if (ctx->shape != BIN_ONLY_SHAPE) { skip_bits_long(gb, ctx->cplx_estimation_trash_i); if (s->pict_type != AV_PICTURE_TYPE_I) skip_bits_long(gb, ctx->cplx_estimation_trash_p); if (s->pict_type == AV_PICTURE_TYPE_B) skip_bits_long(gb, ctx->cplx_estimation_trash_b); if (get_bits_left(gb) < 3) { av_log(s->avctx, AV_LOG_ERROR, "Header truncated\n"); return AVERROR_INVALIDDATA; } ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)]; if (!s->progressive_sequence) { s->top_field_first = get_bits1(gb); s->alternate_scan = get_bits1(gb); } else s->alternate_scan = 0; } if (s->alternate_scan) { ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan); ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan); ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan); ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); } else { ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct); ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct); ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); } if (s->pict_type == AV_PICTURE_TYPE_S && (ctx->vol_sprite_usage == STATIC_SPRITE || ctx->vol_sprite_usage == GMC_SPRITE)) { if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0) return AVERROR_INVALIDDATA; if (ctx->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n"); if (ctx->vol_sprite_usage == STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); } if (ctx->shape != BIN_ONLY_SHAPE) { s->chroma_qscale = s->qscale = get_bits(gb, s->quant_precision); if (s->qscale == 0) { av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n"); return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then } if (s->pict_type != AV_PICTURE_TYPE_I) { s->f_code = get_bits(gb, 3); /* fcode_for */ if (s->f_code == 0) { av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n"); s->f_code = 1; return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then } } else s->f_code = 1; if (s->pict_type == AV_PICTURE_TYPE_B) { s->b_code = get_bits(gb, 3); if (s->b_code == 0) { av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (b_code=0)\n"); s->b_code=1; return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly } } else s->b_code = 1; if (s->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n", s->qscale, s->f_code, s->b_code, s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")), gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first, s->quarter_sample ? "q" : "h", s->data_partitioning, ctx->resync_marker, ctx->num_sprite_warping_points, s->sprite_warping_accuracy, 1 - s->no_rounding, s->vo_type, ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold, ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p, ctx->cplx_estimation_trash_b, s->time, time_increment ); } if (!ctx->scalability) { if (ctx->shape != RECT_SHAPE && s->pict_type != AV_PICTURE_TYPE_I) skip_bits1(gb); // vop shape coding type } else { if (ctx->enhancement_type) { int load_backward_shape = get_bits1(gb); if (load_backward_shape) av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n"); } skip_bits(gb, 2); // ref_select_code } } /* detect buggy encoders which don't set the low_delay flag * (divx4/xvid/opendivx). Note we cannot detect divx5 without b-frames * easily (although it's buggy too) */ if (s->vo_type == 0 && ctx->vol_control_parameters == 0 && ctx->divx_version == -1 && s->picture_number == 0) { av_log(s->avctx, AV_LOG_WARNING, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); s->low_delay = 1; } s->picture_number++; // better than pic number==0 always ;) // FIXME add short header support s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table; s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table; if (s->workaround_bugs & FF_BUG_EDGE) { s->h_edge_pos = s->width; s->v_edge_pos = s->height; } return 0; }


static void event_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->bus_type = TYPE_SCLP_EVENTS_BUS; dc->unplug = qdev_simple_unplug_cb; dc->init = event_qdev_init; dc->exit = event_qdev_exit; }


static int dvvideo_init(AVCodecContext *avctx) { DVVideoContext *s = avctx->priv_data; DSPContext dsp; static int done=0; int i, j; if (!done) { VLC dv_vlc; uint16_t new_dv_vlc_bits[NB_DV_VLC*2]; uint8_t new_dv_vlc_len[NB_DV_VLC*2]; uint8_t new_dv_vlc_run[NB_DV_VLC*2]; int16_t new_dv_vlc_level[NB_DV_VLC*2]; done = 1; dv_vlc_map = av_mallocz(DV_VLC_MAP_LEV_SIZE*DV_VLC_MAP_RUN_SIZE*sizeof(struct dv_vlc_pair)); if (!dv_vlc_map) return -ENOMEM; /* dv_anchor lets each thread know its Id */ dv_anchor = av_malloc(12*27*sizeof(void*)); if (!dv_anchor) { av_free(dv_vlc_map); return -ENOMEM; } for (i=0; i<12*27; i++) dv_anchor[i] = (void*)(size_t)i; /* it's faster to include sign bit in a generic VLC parsing scheme */ for (i=0, j=0; i<NB_DV_VLC; i++, j++) { new_dv_vlc_bits[j] = dv_vlc_bits[i]; new_dv_vlc_len[j] = dv_vlc_len[i]; new_dv_vlc_run[j] = dv_vlc_run[i]; new_dv_vlc_level[j] = dv_vlc_level[i]; if (dv_vlc_level[i]) { new_dv_vlc_bits[j] <<= 1; new_dv_vlc_len[j]++; j++; new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1; new_dv_vlc_len[j] = dv_vlc_len[i] + 1; new_dv_vlc_run[j] = dv_vlc_run[i]; new_dv_vlc_level[j] = -dv_vlc_level[i]; } } /* NOTE: as a trick, we use the fact the no codes are unused to accelerate the parsing of partial codes */ init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2); dv_rl_vlc = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM)); if (!dv_rl_vlc) { av_free(dv_anchor); av_free(dv_vlc_map); return -ENOMEM; } for(i = 0; i < dv_vlc.table_size; i++){ int code= dv_vlc.table[i][0]; int len = dv_vlc.table[i][1]; int level, run; if(len<0){ //more bits needed run= 0; level= code; } else { run= new_dv_vlc_run[code] + 1; level= new_dv_vlc_level[code]; } dv_rl_vlc[i].len = len; dv_rl_vlc[i].level = level; dv_rl_vlc[i].run = run; } free_vlc(&dv_vlc); for (i = 0; i < NB_DV_VLC - 1; i++) { if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE || dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE) continue; if (dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size != 0) continue; dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].vlc = dv_vlc_bits[i] << (!!dv_vlc_level[i]); dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size = dv_vlc_len[i] + (!!dv_vlc_level[i]); } for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) { #ifdef DV_CODEC_TINY_TARGET for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) { if (dv_vlc_map[i][j].size == 0) { dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + dv_vlc_map[0][j].size; } } #else for (j = 1; j < DV_VLC_MAP_LEV_SIZE/2; j++) { if (dv_vlc_map[i][j].size == 0) { dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + dv_vlc_map[0][j].size; } dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc = dv_vlc_map[i][j].vlc | 1; dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size = dv_vlc_map[i][j].size; } #endif } } /* Generic DSP setup */ dsputil_init(&dsp, avctx); s->get_pixels = dsp.get_pixels; /* 88DCT setup */ s->fdct[0] = dsp.fdct; s->idct_put[0] = dsp.idct_put; for (i=0; i<64; i++) s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]]; /* 248DCT setup */ s->fdct[1] = dsp.fdct248; s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64); /* XXX: do it only for constant case */ dv_build_unquantize_tables(s, dsp.idct_permutation); /* FIXME: I really don't think this should be here */ if (dv_codec_profile(avctx)) avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt; avctx->coded_frame = &s->picture; return 0; }


static int wv_read_header(AVFormatContext *s) { AVIOContext *pb = s->pb; WVContext *wc = s->priv_data; AVStream *st; int ret; wc->block_parsed = 0; for (;;) { if ((ret = wv_read_block_header(s, pb, 0)) < 0) return ret; if (!AV_RN32(wc->extra)) avio_skip(pb, wc->blksize - 24); else break; } /* now we are ready: build format streams */ st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = AV_CODEC_ID_WAVPACK; st->codec->channels = wc->chan; st->codec->channel_layout = wc->chmask; st->codec->sample_rate = wc->rate; st->codec->bits_per_coded_sample = wc->bpp; avpriv_set_pts_info(st, 64, 1, wc->rate); st->start_time = 0; st->duration = wc->samples; if (s->pb->seekable) { int64_t cur = avio_tell(s->pb); wc->apetag_start = ff_ape_parse_tag(s); if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) ff_id3v1_read(s); avio_seek(s->pb, cur, SEEK_SET); } return 0; }


static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr, uint64_t asc, target_ulong *raddr, int *flags, int rw, bool exc) { uint64_t asce = 0; int level; int r; switch (asc) { case PSW_ASC_PRIMARY: PTE_DPRINTF("%s: asc=primary\n", __func__); asce = env->cregs[1]; break; case PSW_ASC_SECONDARY: PTE_DPRINTF("%s: asc=secondary\n", __func__); asce = env->cregs[7]; break; case PSW_ASC_HOME: PTE_DPRINTF("%s: asc=home\n", __func__); asce = env->cregs[13]; break; } if (asce & _ASCE_REAL_SPACE) { /* direct mapping */ *raddr = vaddr; return 0; } level = asce & _ASCE_TYPE_MASK; switch (level) { case _ASCE_TYPE_REGION1: if ((vaddr >> 62) > (asce & _ASCE_TABLE_LENGTH)) { trigger_page_fault(env, vaddr, PGM_REG_FIRST_TRANS, asc, rw, exc); return -1; } break; case _ASCE_TYPE_REGION2: if (vaddr & 0xffe0000000000000ULL) { DPRINTF("%s: vaddr doesn't fit 0x%16" PRIx64 " 0xffe0000000000000ULL\n", __func__, vaddr); trigger_page_fault(env, vaddr, PGM_TRANS_SPEC, asc, rw, exc); return -1; } if ((vaddr >> 51 & 3) > (asce & _ASCE_TABLE_LENGTH)) { trigger_page_fault(env, vaddr, PGM_REG_SEC_TRANS, asc, rw, exc); return -1; } break; case _ASCE_TYPE_REGION3: if (vaddr & 0xfffffc0000000000ULL) { DPRINTF("%s: vaddr doesn't fit 0x%16" PRIx64 " 0xfffffc0000000000ULL\n", __func__, vaddr); trigger_page_fault(env, vaddr, PGM_TRANS_SPEC, asc, rw, exc); return -1; } if ((vaddr >> 40 & 3) > (asce & _ASCE_TABLE_LENGTH)) { trigger_page_fault(env, vaddr, PGM_REG_THIRD_TRANS, asc, rw, exc); return -1; } break; case _ASCE_TYPE_SEGMENT: if (vaddr & 0xffffffff80000000ULL) { DPRINTF("%s: vaddr doesn't fit 0x%16" PRIx64 " 0xffffffff80000000ULL\n", __func__, vaddr); trigger_page_fault(env, vaddr, PGM_TRANS_SPEC, asc, rw, exc); return -1; } if ((vaddr >> 29 & 3) > (asce & _ASCE_TABLE_LENGTH)) { trigger_page_fault(env, vaddr, PGM_SEGMENT_TRANS, asc, rw, exc); return -1; } break; } r = mmu_translate_region(env, vaddr, asc, asce, level, raddr, flags, rw, exc); if ((rw == 1) && !(*flags & PAGE_WRITE)) { trigger_prot_fault(env, vaddr, asc, rw, exc); return -1; } return r; }


void helper_check_tlb_flush(CPUPPCState *env) { check_tlb_flush(env); }


void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner, int *size, unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function) { char name[32], rom_file[64]; FILE *fp; uint8_t val; struct stat st; void *ptr = NULL; /* If loading ROM from file, pci handles it */ if (dev->romfile || !dev->rom_bar) { return NULL; } snprintf(rom_file, sizeof(rom_file), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom", domain, bus, slot, function); if (stat(rom_file, &st)) { return NULL; } if (access(rom_file, F_OK)) { error_report("pci-assign: Insufficient privileges for %s", rom_file); return NULL; } /* Write "1" to the ROM file to enable it */ fp = fopen(rom_file, "r+"); if (fp == NULL) { return NULL; } val = 1; if (fwrite(&val, 1, 1, fp) != 1) { goto close_rom; } fseek(fp, 0, SEEK_SET); snprintf(name, sizeof(name), "%s.rom", object_get_typename(owner)); memory_region_init_ram(&dev->rom, owner, name, st.st_size, &error_abort); vmstate_register_ram(&dev->rom, &dev->qdev); ptr = memory_region_get_ram_ptr(&dev->rom); memset(ptr, 0xff, st.st_size); if (!fread(ptr, 1, st.st_size, fp)) { error_report("pci-assign: Cannot read from host %s", rom_file); error_printf("Device option ROM contents are probably invalid " "(check dmesg).\nSkip option ROM probe with rombar=0, " "or load from file with romfile=\n"); goto close_rom; } pci_register_bar(dev, PCI_ROM_SLOT, 0, &dev->rom); dev->has_rom = true; *size = st.st_size; close_rom: /* Write "0" to disable ROM */ fseek(fp, 0, SEEK_SET); val = 0; if (!fwrite(&val, 1, 1, fp)) { DEBUG("%s\n", "Failed to disable pci-sysfs rom file"); } fclose(fp); return ptr; }


static void nbd_reply_ready(void *opaque) { BDRVNBDState *s = opaque; uint64_t i; if (s->reply.handle == 0) { /* No reply already in flight. Fetch a header. */ if (nbd_receive_reply(s->sock, &s->reply) < 0) { s->reply.handle = 0; goto fail; } } /* There's no need for a mutex on the receive side, because the * handler acts as a synchronization point and ensures that only * one coroutine is called until the reply finishes. */ i = HANDLE_TO_INDEX(s, s->reply.handle); if (i >= MAX_NBD_REQUESTS) { goto fail; } if (s->recv_coroutine[i]) { qemu_coroutine_enter(s->recv_coroutine[i], NULL); return; } fail: for (i = 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i]) { qemu_coroutine_enter(s->recv_coroutine[i], NULL); } } }


static void quantize_and_encode_band_cost_UPAIR12_mips(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, const float ROUNDING) { const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; int i; int qc1, qc2, qc3, qc4; uint8_t *p_bits = (uint8_t*) ff_aac_spectral_bits[cb-1]; uint16_t *p_codes = (uint16_t*)ff_aac_spectral_codes[cb-1]; float *p_vec = (float *)ff_aac_codebook_vectors[cb-1]; abs_pow34_v(s->scoefs, in, size); scaled = s->scoefs; for (i = 0; i < size; i += 4) { int curidx1, curidx2, sign1, count1, sign2, count2; int *in_int = (int *)&in[i]; uint8_t v_bits; unsigned int v_codes; int t0, t1, t2, t3, t4; const float *vec1, *vec2; qc1 = scaled[i ] * Q34 + ROUND_STANDARD; qc2 = scaled[i+1] * Q34 + ROUND_STANDARD; qc3 = scaled[i+2] * Q34 + ROUND_STANDARD; qc4 = scaled[i+3] * Q34 + ROUND_STANDARD; __asm__ volatile ( ".set push \n\t" ".set noreorder \n\t" "ori %[t4], $zero, 12 \n\t" "ori %[sign1], $zero, 0 \n\t" "ori %[sign2], $zero, 0 \n\t" "slt %[t0], %[t4], %[qc1] \n\t" "slt %[t1], %[t4], %[qc2] \n\t" "slt %[t2], %[t4], %[qc3] \n\t" "slt %[t3], %[t4], %[qc4] \n\t" "movn %[qc1], %[t4], %[t0] \n\t" "movn %[qc2], %[t4], %[t1] \n\t" "movn %[qc3], %[t4], %[t2] \n\t" "movn %[qc4], %[t4], %[t3] \n\t" "lw %[t0], 0(%[in_int]) \n\t" "lw %[t1], 4(%[in_int]) \n\t" "lw %[t2], 8(%[in_int]) \n\t" "lw %[t3], 12(%[in_int]) \n\t" "slt %[t0], %[t0], $zero \n\t" "movn %[sign1], %[t0], %[qc1] \n\t" "slt %[t2], %[t2], $zero \n\t" "movn %[sign2], %[t2], %[qc3] \n\t" "slt %[t1], %[t1], $zero \n\t" "sll %[t0], %[sign1], 1 \n\t" "or %[t0], %[t0], %[t1] \n\t" "movn %[sign1], %[t0], %[qc2] \n\t" "slt %[t3], %[t3], $zero \n\t" "sll %[t0], %[sign2], 1 \n\t" "or %[t0], %[t0], %[t3] \n\t" "movn %[sign2], %[t0], %[qc4] \n\t" "slt %[count1], $zero, %[qc1] \n\t" "slt %[t1], $zero, %[qc2] \n\t" "slt %[count2], $zero, %[qc3] \n\t" "slt %[t2], $zero, %[qc4] \n\t" "addu %[count1], %[count1], %[t1] \n\t" "addu %[count2], %[count2], %[t2] \n\t" ".set pop \n\t" : [qc1]"+r"(qc1), [qc2]"+r"(qc2), [qc3]"+r"(qc3), [qc4]"+r"(qc4), [sign1]"=&r"(sign1), [count1]"=&r"(count1), [sign2]"=&r"(sign2), [count2]"=&r"(count2), [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3), [t4]"=&r"(t4) : [in_int]"r"(in_int) : "memory" ); curidx1 = 13 * qc1; curidx1 += qc2; v_codes = (p_codes[curidx1] << count1) | sign1; v_bits = p_bits[curidx1] + count1; put_bits(pb, v_bits, v_codes); curidx2 = 13 * qc3; curidx2 += qc4; v_codes = (p_codes[curidx2] << count2) | sign2; v_bits = p_bits[curidx2] + count2; put_bits(pb, v_bits, v_codes); if (out) { vec1 = &p_vec[curidx1*2]; vec2 = &p_vec[curidx2*2]; out[i+0] = copysignf(vec1[0] * IQ, in[i+0]); out[i+1] = copysignf(vec1[1] * IQ, in[i+1]); out[i+2] = copysignf(vec2[0] * IQ, in[i+2]); out[i+3] = copysignf(vec2[1] * IQ, in[i+3]); } } }


static int ast_probe(AVProbeData *p) { if (AV_RL32(p->buf) == MKTAG('S','T','R','M') && AV_RB16(p->buf + 10) && AV_RB16(p->buf + 12) && AV_RB32(p->buf + 16)) return AVPROBE_SCORE_MAX / 3 * 2; return 0; }


target_ulong helper_rdhwr_ccres(CPUMIPSState *env) { check_hwrena(env, 3); return env->CCRes; }


void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list) { RAMBlock *block; QTAILQ_FOREACH(block, &ram_list.blocks, next) { create_new_memory_mapping(list, block->offset, 0, block->length); } }


static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) { RPLContext *rpl = s->priv_data; AVIOContext *pb = s->pb; AVStream* stream; AVIndexEntry* index_entry; uint32_t ret; if (rpl->chunk_part == s->nb_streams) { rpl->chunk_number++; rpl->chunk_part = 0; } stream = s->streams[rpl->chunk_part]; if (rpl->chunk_number >= stream->nb_index_entries) return AVERROR_EOF; index_entry = &stream->index_entries[rpl->chunk_number]; if (rpl->frame_in_part == 0) if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) return AVERROR(EIO); if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO && stream->codec->codec_tag == 124) { // We have to split Escape 124 frames because there are // multiple frames per chunk in Escape 124 samples. uint32_t frame_size; avio_skip(pb, 4); /* flags */ frame_size = avio_rl32(pb); if (avio_seek(pb, -8, SEEK_CUR) < 0) return AVERROR(EIO); ret = av_get_packet(pb, pkt, frame_size); if (ret != frame_size) { av_free_packet(pkt); return AVERROR(EIO); } pkt->duration = 1; pkt->pts = index_entry->timestamp + rpl->frame_in_part; pkt->stream_index = rpl->chunk_part; rpl->frame_in_part++; if (rpl->frame_in_part == rpl->frames_per_chunk) { rpl->frame_in_part = 0; rpl->chunk_part++; } } else { ret = av_get_packet(pb, pkt, index_entry->size); if (ret != index_entry->size) { av_free_packet(pkt); return AVERROR(EIO); } if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) { // frames_per_chunk should always be one here; the header // parsing will warn if it isn't. pkt->duration = rpl->frames_per_chunk; } else { // All the audio codecs supported in this container // (at least so far) are constant-bitrate. pkt->duration = ret * 8; } pkt->pts = index_entry->timestamp; pkt->stream_index = rpl->chunk_part; rpl->chunk_part++; } // None of the Escape formats have keyframes, and the ADPCM // format used doesn't have keyframes. if (rpl->chunk_number == 0 && rpl->frame_in_part == 0) pkt->flags |= AV_PKT_FLAG_KEY; return ret; }


static void acpi_set_pci_info(void) { PCIBus *bus = find_i440fx(); /* TODO: Q35 support */ unsigned bsel_alloc = 0; if (bus) { /* Scan all PCI buses. Set property to enable acpi based hotplug. */ pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc); } }


static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; qpci_io_writel(dev->pdev, dev->addr + VIRTIO_PCI_GUEST_FEATURES, features); }


static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer) { XHCITRB *trb_setup, *trb_status; uint8_t bmRequestType, bRequest; uint16_t wValue, wLength, wIndex; XHCIPort *port; USBDevice *dev; int ret; DPRINTF("xhci_fire_ctl_transfer(slot=%d)\n", xfer->slotid); trb_setup = &xfer->trbs[0]; trb_status = &xfer->trbs[xfer->trb_count-1]; /* at most one Event Data TRB allowed after STATUS */ if (TRB_TYPE(*trb_status) == TR_EVDATA && xfer->trb_count > 2) { trb_status--; } /* do some sanity checks */ if (TRB_TYPE(*trb_setup) != TR_SETUP) { fprintf(stderr, "xhci: ep0 first TD not SETUP: %d\n", TRB_TYPE(*trb_setup)); return -1; } if (TRB_TYPE(*trb_status) != TR_STATUS) { fprintf(stderr, "xhci: ep0 last TD not STATUS: %d\n", TRB_TYPE(*trb_status)); return -1; } if (!(trb_setup->control & TRB_TR_IDT)) { fprintf(stderr, "xhci: Setup TRB doesn't have IDT set\n"); return -1; } if ((trb_setup->status & 0x1ffff) != 8) { fprintf(stderr, "xhci: Setup TRB has bad length (%d)\n", (trb_setup->status & 0x1ffff)); return -1; } bmRequestType = trb_setup->parameter; bRequest = trb_setup->parameter >> 8; wValue = trb_setup->parameter >> 16; wIndex = trb_setup->parameter >> 32; wLength = trb_setup->parameter >> 48; if (xfer->data && xfer->data_alloced < wLength) { xfer->data_alloced = 0; g_free(xfer->data); xfer->data = NULL; } if (!xfer->data) { DPRINTF("xhci: alloc %d bytes data\n", wLength); xfer->data = g_malloc(wLength+1); xfer->data_alloced = wLength; } xfer->data_length = wLength; port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1]; dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr); if (!dev) { fprintf(stderr, "xhci: slot %d port %d has no device\n", xfer->slotid, xhci->slots[xfer->slotid-1].port); return -1; } xfer->in_xfer = bmRequestType & USB_DIR_IN; xfer->iso_xfer = false; xhci_setup_packet(xfer, dev); if (!xfer->in_xfer) { xhci_xfer_data(xfer, xfer->data, wLength, 0, 1, 0); } ret = usb_device_handle_control(dev, &xfer->packet, (bmRequestType << 8) | bRequest, wValue, wIndex, wLength, xfer->data); xhci_complete_packet(xfer, ret); if (!xfer->running_async && !xfer->running_retry) { xhci_kick_ep(xhci, xfer->slotid, xfer->epid); } return 0; }


static int combine_residual_frame(DCAXllDecoder *s, DCAXllChSet *c) { DCAContext *dca = s->avctx->priv_data; int ch, nsamples = s->nframesamples; DCAXllChSet *o; // Verify that core is compatible if (!(dca->packet & DCA_PACKET_CORE)) { av_log(s->avctx, AV_LOG_ERROR, "Residual encoded channels are present without core\n"); return AVERROR(EINVAL); } if (c->freq != dca->core.output_rate) { av_log(s->avctx, AV_LOG_WARNING, "Sample rate mismatch between core (%d Hz) and XLL (%d Hz)\n", dca->core.output_rate, c->freq); return AVERROR_INVALIDDATA; } if (nsamples != dca->core.npcmsamples) { av_log(s->avctx, AV_LOG_WARNING, "Number of samples per frame mismatch between core (%d) and XLL (%d)\n", dca->core.npcmsamples, nsamples); return AVERROR_INVALIDDATA; } // See if this channel set is downmixed and find the next channel set in // hierarchy. If downmixed, undo core pre-scaling before combining with // residual (residual is not scaled). o = find_next_hier_dmix_chset(s, c); // Reduce core bit width and combine with residual for (ch = 0; ch < c->nchannels; ch++) { int n, spkr, shift, round; int32_t *src, *dst; if (c->residual_encode & (1 << ch)) continue; // Map this channel to core speaker spkr = ff_dca_core_map_spkr(&dca->core, c->ch_remap[ch]); if (spkr < 0) { av_log(s->avctx, AV_LOG_WARNING, "Residual encoded channel (%d) references unavailable core channel\n", c->ch_remap[ch]); return AVERROR_INVALIDDATA; } // Account for LSB width shift = 24 - c->pcm_bit_res + chs_get_lsb_width(s, c, 0, ch); if (shift > 24) { av_log(s->avctx, AV_LOG_WARNING, "Invalid core shift (%d bits)\n", shift); return AVERROR_INVALIDDATA; } round = shift > 0 ? 1 << (shift - 1) : 0; src = dca->core.output_samples[spkr]; dst = c->bands[0].msb_sample_buffer[ch]; if (o) { // Undo embedded core downmix pre-scaling int scale_inv = o->dmix_scale_inv[c->hier_ofs + ch]; for (n = 0; n < nsamples; n++) dst[n] += (SUINT)clip23((mul16(src[n], scale_inv) + round) >> shift); } else { // No downmix scaling for (n = 0; n < nsamples; n++) dst[n] += (src[n] + round) >> shift; } } return 0; }


static void boston_mach_class_init(MachineClass *mc) { mc->desc = "MIPS Boston"; mc->init = boston_mach_init; mc->block_default_type = IF_IDE; mc->default_ram_size = 2 * G_BYTE; mc->max_cpus = 16; }


static av_cold void mdct_end(AC3MDCTContext *mdct) { mdct->nbits = 0; av_freep(&mdct->costab); av_freep(&mdct->sintab); av_freep(&mdct->xcos1); av_freep(&mdct->xsin1); av_freep(&mdct->rot_tmp); av_freep(&mdct->cplx_tmp); }


static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, int * posts, float * floor, int samples) { int range = 255 / fc->multiplier + 1; int coded[fc->values]; // first 2 values are unused int i, counter; int lx, ly; put_bits(pb, 1, 1); // non zero put_bits(pb, ilog(range - 1), posts[0]); put_bits(pb, ilog(range - 1), posts[1]); for (i = 2; i < fc->values; i++) { int predicted = render_point(fc->list[fc->list[i].low].x, posts[fc->list[i].low], fc->list[fc->list[i].high].x, posts[fc->list[i].high], fc->list[i].x); int highroom = range - predicted; int lowroom = predicted; int room = FFMIN(highroom, lowroom); if (predicted == posts[i]) { coded[i] = 0; // must be used later as flag! continue; } else { if (!coded[fc->list[i].low]) coded[fc->list[i].low] = -1; if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1; } if (posts[i] > predicted) { if (posts[i] - predicted > room) coded[i] = posts[i] - predicted + lowroom; else coded[i] = (posts[i] - predicted) << 1; } else { if (predicted - posts[i] > room) coded[i] = predicted - posts[i] + highroom - 1; else coded[i] = ((predicted - posts[i]) << 1) - 1; } } counter = 2; for (i = 0; i < fc->partitions; i++) { floor_class_t * c = &fc->classes[fc->partition_to_class[i]]; int k, cval = 0, csub = 1<<c->subclass; if (c->subclass) { codebook_t * book = &venc->codebooks[c->masterbook]; int cshift = 0; for (k = 0; k < c->dim; k++) { int l; for (l = 0; l < csub; l++) { int maxval = 1; if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries; // coded could be -1, but this still works, cause thats 0 if (coded[counter + k] < maxval) break; } assert(l != csub); cval |= l << cshift; cshift += c->subclass; } assert(cval < book->nentries); put_bits(pb, book->entries[cval].len, book->entries[cval].codeword); } for (k = 0; k < c->dim; k++) { int book = c->books[cval & (csub-1)]; int entry = coded[counter++]; cval >>= c->subclass; if (book == -1) continue; if (entry == -1) entry = 0; assert(entry < venc->codebooks[book].nentries); assert(entry >= 0); put_bits(pb, venc->codebooks[book].entries[entry].len, venc->codebooks[book].entries[entry].codeword); } } lx = 0; ly = posts[0] * fc->multiplier; // sorted 0 is still 0 coded[0] = coded[1] = 1; for (i = 1; i < fc->values; i++) { int pos = fc->list[i].sort; if (coded[pos]) { render_line(lx, ly, fc->list[pos].x, posts[pos] * fc->multiplier, floor, samples); lx = fc->list[pos].x; ly = posts[pos] * fc->multiplier; } if (lx >= samples) break; } if (lx < samples) render_line(lx, ly, samples, ly, floor, samples); }


dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, IPin *pin, int *pformat_set) { struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; int format_set = 0; void *caps = NULL; int i, n, size; if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) return; if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK) goto end; caps = av_malloc(size); if (!caps) goto end; for (i = 0; i < n && !format_set; i++) { IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); #if DSHOWDEBUG ff_print_AM_MEDIA_TYPE(type); #endif if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { VIDEOINFOHEADER2 *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; } else { goto next; } if (!pformat_set) { enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); if (pix_fmt == AV_PIX_FMT_NONE) { enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression); AVCodec *codec = avcodec_find_decoder(codec_id); if (codec_id == AV_CODEC_ID_NONE || !codec) { av_log(avctx, AV_LOG_INFO, " unknown compression type 0x%X", (int) bih->biCompression); } else { av_log(avctx, AV_LOG_INFO, " vcodec=%s", codec->name); } } else { av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); } av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); continue; } if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { if (ctx->video_codec_id != av_codec_get_id(tags, bih->biCompression)) goto next; } if (ctx->pixel_format != AV_PIX_FMT_NONE && ctx->pixel_format != dshow_pixfmt(bih->biCompression, bih->biBitCount)) { goto next; } if (ctx->framerate) { int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) / ctx->requested_framerate.num; if (framerate > vcaps->MaxFrameInterval || framerate < vcaps->MinFrameInterval) goto next; *fr = framerate; } if (ctx->requested_width && ctx->requested_height) { if (ctx->requested_width > vcaps->MaxOutputSize.cx || ctx->requested_width < vcaps->MinOutputSize.cx || ctx->requested_height > vcaps->MaxOutputSize.cy || ctx->requested_height < vcaps->MinOutputSize.cy) goto next; bih->biWidth = ctx->requested_width; bih->biHeight = ctx->requested_height; } } else { AUDIO_STREAM_CONFIG_CAPS *acaps = caps; WAVEFORMATEX *fx; #if DSHOWDEBUG ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { fx = (void *) type->pbFormat; } else { goto next; } if (!pformat_set) { av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n", acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency, acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); continue; } if (ctx->sample_rate) { if (ctx->sample_rate > acaps->MaximumSampleFrequency || ctx->sample_rate < acaps->MinimumSampleFrequency) goto next; fx->nSamplesPerSec = ctx->sample_rate; } if (ctx->sample_size) { if (ctx->sample_size > acaps->MaximumBitsPerSample || ctx->sample_size < acaps->MinimumBitsPerSample) goto next; fx->wBitsPerSample = ctx->sample_size; } if (ctx->channels) { if (ctx->channels > acaps->MaximumChannels || ctx->channels < acaps->MinimumChannels) goto next; fx->nChannels = ctx->channels; } } if (IAMStreamConfig_SetFormat(config, type) != S_OK) goto next; format_set = 1; next: if (type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } end: IAMStreamConfig_Release(config); if (caps) av_free(caps); if (pformat_set) *pformat_set = format_set; }


static void usbredir_log_data(USBRedirDevice *dev, const char *desc, const uint8_t *data, int len) { int i, j, n; if (dev->debug < usbredirparser_debug_data) { return; } for (i = 0; i < len; i += j) { char buf[128]; n = sprintf(buf, "%s", desc); for (j = 0; j < 8 && i + j < len; j++) { n += sprintf(buf + n, " %02X", data[i + j]); } error_report("%s", buf); } }


static void typhoon_pcihost_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); k->init = typhoon_pcihost_init; dc->no_user = 1; }


static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples, const uint8_t *buf, int buf_size) { int i, nb_frames, ch; OUT_INT *samples_ptr; init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8); /* skip error protection field */ if (s->error_protection) skip_bits(&s->gb, 16); dprintf(s->avctx, "frame %d:\n", s->frame_count); switch(s->layer) { case 1: s->avctx->frame_size = 384; nb_frames = mp_decode_layer1(s); break; case 2: s->avctx->frame_size = 1152; nb_frames = mp_decode_layer2(s); break; case 3: s->avctx->frame_size = s->lsf ? 576 : 1152; default: nb_frames = mp_decode_layer3(s); s->last_buf_size=0; if(s->in_gb.buffer){ align_get_bits(&s->gb); i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; if(i >= 0 && i <= BACKSTEP_SIZE){ memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i); s->last_buf_size=i; }else av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i); s->gb= s->in_gb; s->in_gb.buffer= NULL; } align_get_bits(&s->gb); assert((get_bits_count(&s->gb) & 7) == 0); i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){ av_log(s->avctx, AV_LOG_WARNING, "invalid new backstep %d\n", i); i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE); } assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); s->last_buf_size += i; break; } /* apply the synthesis filter */ for(ch=0;ch<s->nb_channels;ch++) { samples_ptr = samples + ch; for(i=0;i<nb_frames;i++) { ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]), window, &s->dither_state, samples_ptr, s->nb_channels, s->sb_samples[ch][i]); samples_ptr += 32 * s->nb_channels; } } return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels; }


static int encode_dvb_subtitles(DVBSubtitleContext *s, uint8_t *outbuf, const AVSubtitle *h) { uint8_t *q, *pseg_len; int page_id, region_id, clut_id, object_id, i, bpp_index, page_state; q = outbuf; page_id = 1; if (h->num_rects == 0 || h->rects == NULL) return -1; *q++ = 0x00; /* subtitle_stream_id */ /* page composition segment */ *q++ = 0x0f; /* sync_byte */ *q++ = 0x10; /* segment_type */ bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = 30; /* page_timeout (seconds) */ if (s->hide_state) page_state = 0; /* normal case */ else page_state = 2; /* mode change */ /* page_version = 0 + page_state */ *q++ = (s->object_version << 4) | (page_state << 2) | 3; for (region_id = 0; region_id < h->num_rects; region_id++) { *q++ = region_id; *q++ = 0xff; /* reserved */ bytestream_put_be16(&q, h->rects[region_id]->x); /* left pos */ bytestream_put_be16(&q, h->rects[region_id]->y); /* top pos */ } bytestream_put_be16(&pseg_len, q - pseg_len - 2); if (!s->hide_state) { for (clut_id = 0; clut_id < h->num_rects; clut_id++) { /* CLUT segment */ if (h->rects[clut_id]->nb_colors <= 4) { /* 2 bpp, some decoders do not support it correctly */ bpp_index = 0; } else if (h->rects[clut_id]->nb_colors <= 16) { /* 4 bpp, standard encoding */ bpp_index = 1; } else { return -1; } *q++ = 0x0f; /* sync byte */ *q++ = 0x12; /* CLUT definition segment */ bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = clut_id; *q++ = (0 << 4) | 0xf; /* version = 0 */ for(i = 0; i < h->rects[clut_id]->nb_colors; i++) { *q++ = i; /* clut_entry_id */ *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */ { int a, r, g, b; uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i]; a = (x >> 24) & 0xff; r = (x >> 16) & 0xff; g = (x >> 8) & 0xff; b = (x >> 0) & 0xff; *q++ = RGB_TO_Y_CCIR(r, g, b); *q++ = RGB_TO_V_CCIR(r, g, b, 0); *q++ = RGB_TO_U_CCIR(r, g, b, 0); *q++ = 255 - a; } } bytestream_put_be16(&pseg_len, q - pseg_len - 2); } } for (region_id = 0; region_id < h->num_rects; region_id++) { /* region composition segment */ if (h->rects[region_id]->nb_colors <= 4) { /* 2 bpp, some decoders do not support it correctly */ bpp_index = 0; } else if (h->rects[region_id]->nb_colors <= 16) { /* 4 bpp, standard encoding */ bpp_index = 1; } else { return -1; } *q++ = 0x0f; /* sync_byte */ *q++ = 0x11; /* segment_type */ bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = region_id; *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */ bytestream_put_be16(&q, h->rects[region_id]->w); /* region width */ bytestream_put_be16(&q, h->rects[region_id]->h); /* region height */ *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03; *q++ = region_id; /* clut_id == region_id */ *q++ = 0; /* 8 bit fill colors */ *q++ = 0x03; /* 4 bit and 2 bit fill colors */ if (!s->hide_state) { bytestream_put_be16(&q, region_id); /* object_id == region_id */ *q++ = (0 << 6) | (0 << 4); *q++ = 0; *q++ = 0xf0; *q++ = 0; } bytestream_put_be16(&pseg_len, q - pseg_len - 2); } if (!s->hide_state) { for (object_id = 0; object_id < h->num_rects; object_id++) { /* Object Data segment */ if (h->rects[object_id]->nb_colors <= 4) { /* 2 bpp, some decoders do not support it correctly */ bpp_index = 0; } else if (h->rects[object_id]->nb_colors <= 16) { /* 4 bpp, standard encoding */ bpp_index = 1; } else { return -1; } *q++ = 0x0f; /* sync byte */ *q++ = 0x13; bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ bytestream_put_be16(&q, object_id); *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0, onject_coding_method, non_modifying_color_flag */ { uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr; void (*dvb_encode_rle)(uint8_t **pq, const uint8_t *bitmap, int linesize, int w, int h); ptop_field_len = q; q += 2; pbottom_field_len = q; q += 2; if (bpp_index == 0) dvb_encode_rle = dvb_encode_rle2; else dvb_encode_rle = dvb_encode_rle4; top_ptr = q; dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2, h->rects[object_id]->w, h->rects[object_id]->h >> 1); bottom_ptr = q; dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w, h->rects[object_id]->w * 2, h->rects[object_id]->w, h->rects[object_id]->h >> 1); bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr); bytestream_put_be16(&pbottom_field_len, q - bottom_ptr); } bytestream_put_be16(&pseg_len, q - pseg_len - 2); } } /* end of display set segment */ *q++ = 0x0f; /* sync_byte */ *q++ = 0x80; /* segment_type */ bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ bytestream_put_be16(&pseg_len, q - pseg_len - 2); *q++ = 0xff; /* end of PES data */ s->object_version = (s->object_version + 1) & 0xf; s->hide_state = !s->hide_state; return q - outbuf; }


int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) { RTSPState *rt = s->priv_data; AVStream *st = NULL; int reordering_queue_size = rt->reordering_queue_size; if (reordering_queue_size < 0) { if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP || !s->max_delay) reordering_queue_size = 0; else reordering_queue_size = RTP_REORDER_QUEUE_DEFAULT_SIZE; } /* open the RTP context */ if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; if (!st) s->ctx_flags |= AVFMTCTX_NOHEADER; if (CONFIG_RTSP_MUXER && s->oformat) { int ret = ff_rtp_chain_mux_open((AVFormatContext **)&rtsp_st->transport_priv, s, st, rtsp_st->rtp_handle, RTSP_TCP_MAX_PACKET_SIZE, rtsp_st->stream_index); /* Ownership of rtp_handle is passed to the rtp mux context */ rtsp_st->rtp_handle = NULL; if (ret < 0) return ret; st->time_base = ((AVFormatContext*)rtsp_st->transport_priv)->streams[0]->time_base; } else if (rt->transport == RTSP_TRANSPORT_RAW) { return 0; // Don't need to open any parser here } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT) rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, rtsp_st->dynamic_protocol_context, rtsp_st->dynamic_handler); else if (CONFIG_RTPDEC) rtsp_st->transport_priv = ff_rtp_parse_open(s, st, rtsp_st->sdp_payload_type, reordering_queue_size); if (!rtsp_st->transport_priv) { return AVERROR(ENOMEM); } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP) { if (rtsp_st->dynamic_handler) { ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, rtsp_st->dynamic_protocol_context, rtsp_st->dynamic_handler); } if (rtsp_st->crypto_suite[0]) ff_rtp_parse_set_crypto(rtsp_st->transport_priv, rtsp_st->crypto_suite, rtsp_st->crypto_params); } return 0; }


int ff_h264_set_parameter_from_sps(H264Context *h) { if (h->flags & CODEC_FLAG_LOW_DELAY || (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames)) { if (h->avctx->has_b_frames > 1 || h->delayed_pic[0]) av_log(h->avctx, AV_LOG_WARNING, "Delayed frames seen. " "Reenabling low delay requires a codec flush.\n"); else h->low_delay = 1; } if (h->avctx->has_b_frames < 2) h->avctx->has_b_frames = !h->low_delay; if (h->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc) { if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) { h->avctx->bits_per_raw_sample = h->sps.bit_depth_luma; h->cur_chroma_format_idc = h->sps.chroma_format_idc; h->pixel_shift = h->sps.bit_depth_luma > 8; ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc); ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma); ff_h264qpel_init(&h->h264qpel, h->sps.bit_depth_luma); ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc); if (CONFIG_ERROR_RESILIENCE) ff_me_cmp_init(&h->mecc, h->avctx); ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma); } else { av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n", h->sps.bit_depth_luma); return AVERROR_INVALIDDATA; } } return 0; }


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


static av_cold int vaapi_encode_h265_init_constant_bitrate(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH265Context *priv = ctx->priv_data; int hrd_buffer_size; int hrd_initial_buffer_fullness; if (avctx->bit_rate > INT32_MAX) { av_log(avctx, AV_LOG_ERROR, "Target bitrate of 2^31 bps or " "higher is not supported.\n"); return AVERROR(EINVAL); } if (avctx->rc_buffer_size) hrd_buffer_size = avctx->rc_buffer_size; else hrd_buffer_size = avctx->bit_rate; if (avctx->rc_initial_buffer_occupancy) hrd_initial_buffer_fullness = avctx->rc_initial_buffer_occupancy; else hrd_initial_buffer_fullness = hrd_buffer_size * 3 / 4; priv->rc_params.misc.type = VAEncMiscParameterTypeRateControl; priv->rc_params.rc = (VAEncMiscParameterRateControl) { .bits_per_second = avctx->bit_rate, .target_percentage = 66, .window_size = 1000, .initial_qp = (avctx->qmax >= 0 ? avctx->qmax : 40), .min_qp = (avctx->qmin >= 0 ? avctx->qmin : 20), .basic_unit_size = 0, }; ctx->global_params[ctx->nb_global_params] = &priv->rc_params.misc; ctx->global_params_size[ctx->nb_global_params++] = sizeof(priv->rc_params); priv->hrd_params.misc.type = VAEncMiscParameterTypeHRD; priv->hrd_params.hrd = (VAEncMiscParameterHRD) { .initial_buffer_fullness = hrd_initial_buffer_fullness, .buffer_size = hrd_buffer_size, }; ctx->global_params[ctx->nb_global_params] = &priv->hrd_params.misc; ctx->global_params_size[ctx->nb_global_params++] = sizeof(priv->hrd_params); // These still need to be set for pic_init_qp/slice_qp_delta. priv->fixed_qp_idr = 30; priv->fixed_qp_p = 30; priv->fixed_qp_b = 30; av_log(avctx, AV_LOG_DEBUG, "Using constant-bitrate = %"PRId64" bps.\n", avctx->bit_rate); return 0; }


static int filter_query_formats(AVFilterContext *ctx) { int ret, i; AVFilterFormats *formats; AVFilterChannelLayouts *chlayouts; AVFilterFormats *samplerates; enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type : ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type : AVMEDIA_TYPE_VIDEO; if ((ret = ctx->filter->query_formats(ctx)) < 0) { av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n", ctx->name, av_err2str(ret)); return ret; } for (i = 0; i < ctx->nb_inputs; i++) sanitize_channel_layouts(ctx, ctx->inputs[i]->out_channel_layouts); for (i = 0; i < ctx->nb_outputs; i++) sanitize_channel_layouts(ctx, ctx->outputs[i]->in_channel_layouts); formats = ff_all_formats(type); if (!formats) return AVERROR(ENOMEM); ff_set_common_formats(ctx, formats); if (type == AVMEDIA_TYPE_AUDIO) { samplerates = ff_all_samplerates(); if (!samplerates) return AVERROR(ENOMEM); ff_set_common_samplerates(ctx, samplerates); chlayouts = ff_all_channel_layouts(); if (!chlayouts) return AVERROR(ENOMEM); ff_set_common_channel_layouts(ctx, chlayouts); } return 0; }


static int coroutine_fn sd_co_rw_vector(void *p) { SheepdogAIOCB *acb = p; int ret = 0; unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE; unsigned long idx = acb->sector_num * BDRV_SECTOR_SIZE / SD_DATA_OBJ_SIZE; uint64_t oid; uint64_t offset = (acb->sector_num * BDRV_SECTOR_SIZE) % SD_DATA_OBJ_SIZE; BDRVSheepdogState *s = acb->common.bs->opaque; SheepdogInode *inode = &s->inode; AIOReq *aio_req; if (acb->aiocb_type == AIOCB_WRITE_UDATA && s->is_snapshot) { /* * In the case we open the snapshot VDI, Sheepdog creates the * writable VDI when we do a write operation first. */ ret = sd_create_branch(s); if (ret) { acb->ret = -EIO; goto out; } } /* * Make sure we don't free the aiocb before we are done with all requests. * This additional reference is dropped at the end of this function. */ acb->nr_pending++; while (done != total) { uint8_t flags = 0; uint64_t old_oid = 0; bool create = false; oid = vid_to_data_oid(inode->data_vdi_id[idx], idx); len = MIN(total - done, SD_DATA_OBJ_SIZE - offset); switch (acb->aiocb_type) { case AIOCB_READ_UDATA: if (!inode->data_vdi_id[idx]) { qemu_iovec_memset(acb->qiov, done, 0, len); goto done; } break; case AIOCB_WRITE_UDATA: if (!inode->data_vdi_id[idx]) { create = true; } else if (!is_data_obj_writable(inode, idx)) { /* Copy-On-Write */ create = true; old_oid = oid; flags = SD_FLAG_CMD_COW; } break; case AIOCB_DISCARD_OBJ: /* * We discard the object only when the whole object is * 1) allocated 2) trimmed. Otherwise, simply skip it. */ if (len != SD_DATA_OBJ_SIZE || inode->data_vdi_id[idx] == 0) { goto done; } break; default: break; } if (create) { DPRINTF("update ino (%" PRIu32 ") %" PRIu64 " %" PRIu64 " %ld\n", inode->vdi_id, oid, vid_to_data_oid(inode->data_vdi_id[idx], idx), idx); oid = vid_to_data_oid(inode->vdi_id, idx); DPRINTF("new oid %" PRIx64 "\n", oid); } aio_req = alloc_aio_req(s, acb, oid, len, offset, flags, old_oid, done); if (create) { AIOReq *areq; QLIST_FOREACH(areq, &s->inflight_aio_head, aio_siblings) { if (areq->oid == oid) { /* * Sheepdog cannot handle simultaneous create * requests to the same object. So we cannot send * the request until the previous request * finishes. */ aio_req->flags = 0; aio_req->base_oid = 0; QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req, aio_siblings); goto done; } } } QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, create, acb->aiocb_type); done: offset = 0; idx++; done += len; } out: if (!--acb->nr_pending) { return acb->ret; } return 1; }


static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params, MemoryRegion *ccsr, qemu_irq **irqs) { qemu_irq *mpic; DeviceState *dev = NULL; SysBusDevice *s; int i; mpic = g_new0(qemu_irq, 256); if (kvm_enabled()) { Error *err = NULL; if (machine_kernel_irqchip_allowed(machine)) { dev = ppce500_init_mpic_kvm(params, irqs, &err); } if (machine_kernel_irqchip_required(machine) && !dev) { error_reportf_err(err, "kernel_irqchip requested but unavailable: "); exit(1); } } if (!dev) { dev = ppce500_init_mpic_qemu(params, irqs); } for (i = 0; i < 256; i++) { mpic[i] = qdev_get_gpio_in(dev, i); } s = SYS_BUS_DEVICE(dev); memory_region_add_subregion(ccsr, MPC8544_MPIC_REGS_OFFSET, s->mmio[0].memory); return mpic; }


static ExitStatus trans_fop_ded(DisasContext *ctx, uint32_t insn, const DisasInsn *di) { unsigned rt = extract32(insn, 0, 5); unsigned ra = extract32(insn, 21, 5); return do_fop_ded(ctx, rt, ra, di->f_ded); }


static void xhci_xfer_report(XHCITransfer *xfer) { uint32_t edtla = 0; unsigned int left; bool reported = 0; bool shortpkt = 0; XHCIEvent event = {ER_TRANSFER, CC_SUCCESS}; XHCIState *xhci = xfer->xhci; int i; left = xfer->packet.actual_length; for (i = 0; i < xfer->trb_count; i++) { XHCITRB *trb = &xfer->trbs[i]; unsigned int chunk = 0; switch (TRB_TYPE(*trb)) { case TR_DATA: case TR_NORMAL: case TR_ISOCH: chunk = trb->status & 0x1ffff; if (chunk > left) { chunk = left; if (xfer->status == CC_SUCCESS) { shortpkt = 1; } } left -= chunk; edtla += chunk; break; case TR_STATUS: reported = 0; shortpkt = 0; break; } if (!reported && ((trb->control & TRB_TR_IOC) || (shortpkt && (trb->control & TRB_TR_ISP)) || (xfer->status != CC_SUCCESS && left == 0))) { event.slotid = xfer->slotid; event.epid = xfer->epid; event.length = (trb->status & 0x1ffff) - chunk; event.flags = 0; event.ptr = trb->addr; if (xfer->status == CC_SUCCESS) { event.ccode = shortpkt ? CC_SHORT_PACKET : CC_SUCCESS; } else { event.ccode = xfer->status; } if (TRB_TYPE(*trb) == TR_EVDATA) { event.ptr = trb->parameter; event.flags |= TRB_EV_ED; event.length = edtla & 0xffffff; DPRINTF("xhci_xfer_data: EDTLA=%d\n", event.length); edtla = 0; } xhci_event(xhci, &event, TRB_INTR(*trb)); reported = 1; if (xfer->status != CC_SUCCESS) { return; } } } }


static void usb_hid_handle_destroy(USBDevice *dev) { USBHIDState *s = (USBHIDState *)dev; if (s->kind != USB_KEYBOARD) qemu_remove_mouse_event_handler(s->ptr.eh_entry); /* TODO: else */ }


static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub, int64_t pts) { int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i; AVCodecContext *enc; AVPacket pkt; if (pts == AV_NOPTS_VALUE) { av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); if (exit_on_error) exit_program(1); return; } enc = ost->st->codec; if (!subtitle_out) { subtitle_out = av_malloc(subtitle_out_max_size); } /* Note: DVB subtitle need one packet to draw them and one other packet to clear them */ /* XXX: signal it in the codec context ? */ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) nb = 2; else nb = 1; for (i = 0; i < nb; i++) { ost->sync_opts = av_rescale_q(pts, ist->st->time_base, enc->time_base); if (!check_recording_time(ost)) return; sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q); // start_display_time is required to be 0 sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); sub->end_display_time -= sub->start_display_time; sub->start_display_time = 0; subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, subtitle_out_max_size, sub); if (subtitle_out_size < 0) { av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); exit_program(1); } av_init_packet(&pkt); pkt.data = subtitle_out; pkt.size = subtitle_out_size; pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base); pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->st->time_base); if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling it in the codec would be better */ if (i == 0) pkt.pts += 90 * sub->start_display_time; else pkt.pts += 90 * sub->end_display_time; } write_frame(s, &pkt, ost); subtitle_size += pkt.size; } }


static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) { int flags, in = -1, out = -1; flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY; out = qmp_chardev_open_file_source(file->out, flags, errp); if (error_is_set(errp)) { return NULL; } if (file->has_in) { flags = O_RDONLY; in = qmp_chardev_open_file_source(file->in, flags, errp); if (error_is_set(errp)) { qemu_close(out); return NULL; } } return qemu_chr_open_fd(in, out); }


static void gen_advance_ccount_cond(DisasContext *dc) { if (dc->ccount_delta > 0) { TCGv_i32 tmp = tcg_const_i32(dc->ccount_delta); gen_helper_advance_ccount(cpu_env, tmp); tcg_temp_free(tmp); } }


static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2, long dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { int32_t *filterPos = c->hChrFilterPos; int16_t *filter = c->hChrFilter; int canMMX2BeUsed = c->canMMX2BeUsed; void *mmx2FilterCode= c->chrMmx2FilterCode; int i; #if defined(PIC) DECLARE_ALIGNED(8, uint64_t, ebxsave); #endif __asm__ volatile( #if defined(PIC) "mov %%"REG_b", %7 \n\t" #endif "pxor %%mm7, %%mm7 \n\t" "mov %0, %%"REG_c" \n\t" "mov %1, %%"REG_D" \n\t" "mov %2, %%"REG_d" \n\t" "mov %3, %%"REG_b" \n\t" "xor %%"REG_a", %%"REG_a" \n\t" // i PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE "xor %%"REG_a", %%"REG_a" \n\t" // i "mov %5, %%"REG_c" \n\t" // src "mov %6, %%"REG_D" \n\t" // buf2 PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE #if defined(PIC) "mov %7, %%"REG_b" \n\t" #endif :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos), "m" (mmx2FilterCode), "m" (src2), "m"(dst2) #if defined(PIC) ,"m" (ebxsave) #endif : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) ,"%"REG_b #endif ); for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { dst1[i] = src1[srcW-1]*128; dst2[i] = src2[srcW-1]*128; } }


static av_cold int fbdev_read_header(AVFormatContext *avctx) { FBDevContext *fbdev = avctx->priv_data; AVStream *st = NULL; enum AVPixelFormat pix_fmt; int ret, flags = O_RDONLY; if (!(st = avformat_new_stream(avctx, NULL))) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in microseconds */ /* NONBLOCK is ignored by the fbdev driver, only set for consistency */ if (avctx->flags & AVFMT_FLAG_NONBLOCK) flags |= O_NONBLOCK; if ((fbdev->fd = avpriv_open(avctx->filename, flags)) == -1) { ret = AVERROR(errno); av_log(avctx, AV_LOG_ERROR, "Could not open framebuffer device '%s': %s\n", avctx->filename, strerror(ret)); return ret; } if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) { ret = AVERROR(errno); av_log(avctx, AV_LOG_ERROR, "FBIOGET_VSCREENINFO: %s\n", strerror(errno)); goto fail; } if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) { ret = AVERROR(errno); av_log(avctx, AV_LOG_ERROR, "FBIOGET_FSCREENINFO: %s\n", strerror(errno)); goto fail; } pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo); if (pix_fmt == AV_PIX_FMT_NONE) { ret = AVERROR(EINVAL); av_log(avctx, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n"); goto fail; } fbdev->width = fbdev->varinfo.xres; fbdev->height = fbdev->varinfo.yres; fbdev->bytes_per_pixel = (fbdev->varinfo.bits_per_pixel + 7) >> 3; fbdev->frame_linesize = fbdev->width * fbdev->bytes_per_pixel; fbdev->frame_size = fbdev->frame_linesize * fbdev->height; fbdev->time_frame = AV_NOPTS_VALUE; fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->fd, 0); if (fbdev->data == MAP_FAILED) { ret = AVERROR(errno); av_log(avctx, AV_LOG_ERROR, "Error in mmap(): %s\n", strerror(errno)); goto fail; } st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; st->codec->width = fbdev->width; st->codec->height = fbdev->height; st->codec->pix_fmt = pix_fmt; st->codec->time_base = av_inv_q(fbdev->framerate_q); st->codec->bit_rate = fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8; av_log(avctx, AV_LOG_INFO, "w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n", fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel, av_get_pix_fmt_name(pix_fmt), fbdev->framerate_q.num, fbdev->framerate_q.den, st->codec->bit_rate); return 0; fail: close(fbdev->fd); return ret; }


void ff_build_rac_states(RangeCoder *c, int factor, int max_p){ const int64_t one= 1LL<<32; int64_t p; int last_p8, p8, i; memset(c->zero_state, 0, sizeof(c->zero_state)); memset(c-> one_state, 0, sizeof(c-> one_state)); #if 0 for(i=1; i<256; i++){ if(c->one_state[i]) continue; p= (i*one + 128) >> 8; last_p8= i; for(;;){ p+= ((one-p)*factor + one/2) >> 32; p8= (256*p + one/2) >> 32; //FIXME try without the one if(p8 <= last_p8) p8= last_p8+1; if(p8 > max_p) p8= max_p; if(p8 < last_p8) break; c->one_state[last_p8]= p8; if(p8 == last_p8) break; last_p8= p8; } } #endif #if 1 last_p8= 0; p= one/2; for(i=0; i<128; i++){ p8= (256*p + one/2) >> 32; //FIXME try without the one if(p8 <= last_p8) p8= last_p8+1; if(last_p8 && last_p8<256 && p8<=max_p) c->one_state[last_p8]= p8; p+= ((one-p)*factor + one/2) >> 32; last_p8= p8; } #endif for(i=256-max_p; i<=max_p; i++){ if(c->one_state[i]) continue; p= (i*one + 128) >> 8; p+= ((one-p)*factor + one/2) >> 32; p8= (256*p + one/2) >> 32; //FIXME try without the one if(p8 <= i) p8= i+1; if(p8 > max_p) p8= max_p; c->one_state[ i]= p8; } for(i=0; i<256; i++) c->zero_state[i]= 256-c->one_state[256-i]; #if 0 for(i=0; i<256; i++) av_log(NULL, AV_LOG_DEBUG, "%3d %3d\n", i, c->one_state[i]); #endif }


static void test_notify(void) { g_assert(!aio_poll(ctx, false)); aio_notify(ctx); g_assert(!aio_poll(ctx, true)); g_assert(!aio_poll(ctx, false)); }


static int scsi_qdev_init(DeviceState *qdev) { SCSIDevice *dev = SCSI_DEVICE(qdev); SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus); SCSIDevice *d; int rc = -1; if (dev->channel > bus->info->max_channel) { error_report("bad scsi channel id: %d", dev->channel); goto err; } if (dev->id != -1 && dev->id > bus->info->max_target) { error_report("bad scsi device id: %d", dev->id); goto err; } if (dev->id == -1) { int id = -1; if (dev->lun == -1) { dev->lun = 0; } do { d = scsi_device_find(bus, dev->channel, ++id, dev->lun); } while (d && d->lun == dev->lun && id <= bus->info->max_target); if (id > bus->info->max_target) { error_report("no free target"); goto err; } dev->id = id; } else if (dev->lun == -1) { int lun = -1; do { d = scsi_device_find(bus, dev->channel, dev->id, ++lun); } while (d && d->lun == lun && lun < bus->info->max_lun); if (lun > bus->info->max_lun) { error_report("no free lun"); goto err; } dev->lun = lun; } else { d = scsi_device_find(bus, dev->channel, dev->id, dev->lun); if (dev->lun == d->lun && dev != d) { qdev_free(&d->qdev); } } QTAILQ_INIT(&dev->requests); rc = scsi_device_init(dev); if (rc == 0) { dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb, dev); } err: return rc; }


static const char *addr2str(target_phys_addr_t addr) { return nr2str(ehci_mmio_names, ARRAY_SIZE(ehci_mmio_names), addr); }


static int dca_convert_bitstream(uint8_t * src, int src_size, uint8_t * dst, int max_size) { uint32_t mrk; int i, tmp; uint16_t *ssrc = (uint16_t *) src, *sdst = (uint16_t *) dst; PutBitContext pb; mrk = AV_RB32(src); switch (mrk) { case DCA_MARKER_RAW_BE: memcpy(dst, src, FFMIN(src_size, max_size)); return FFMIN(src_size, max_size); case DCA_MARKER_RAW_LE: for (i = 0; i < (FFMIN(src_size, max_size) + 1) >> 1; i++) *sdst++ = bswap_16(*ssrc++); return FFMIN(src_size, max_size); case DCA_MARKER_14B_BE: case DCA_MARKER_14B_LE: init_put_bits(&pb, dst, max_size); for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) { tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF; put_bits(&pb, 14, tmp); } flush_put_bits(&pb); return (put_bits_count(&pb) + 7) >> 3; default: } }