yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes) { const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0]; int i; int A1 = 0xffff<<14, A2= 0xffff<<14; if (uvalpha < 2048) { for (i = 0; i < ((dstW + 1) >> 1); i++) { int Y1 = (buf0[i * 2] ) >> 2; int Y2 = (buf0[i * 2 + 1]) >> 2; int U = (ubuf0[i] + (-128 << 11)) >> 2; int V = (vbuf0[i] + (-128 << 11)) >> 2; int R, G, B; Y1 -= c->yuv2rgb_y_offset; Y2 -= c->yuv2rgb_y_offset; Y1 *= c->yuv2rgb_y_coeff; Y2 *= c->yuv2rgb_y_coeff; Y1 += 1 << 13; Y2 += 1 << 13; if (hasAlpha) { A1 = abuf0[i * 2 ] << 11; A2 = abuf0[i * 2 + 1] << 11; A1 += 1 << 13; A2 += 1 << 13; } R = V * c->yuv2rgb_v2r_coeff; G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); dest += 6; } } } else { const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; int A1 = 0xffff<<14, A2 = 0xffff<<14; for (i = 0; i < ((dstW + 1) >> 1); i++) { int Y1 = (buf0[i * 2] ) >> 2; int Y2 = (buf0[i * 2 + 1]) >> 2; int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3; int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3; int R, G, B; Y1 -= c->yuv2rgb_y_offset; Y2 -= c->yuv2rgb_y_offset; Y1 *= c->yuv2rgb_y_coeff; Y2 *= c->yuv2rgb_y_coeff; Y1 += 1 << 13; Y2 += 1 << 13; if (hasAlpha) { A1 = abuf0[i * 2 ] << 11; A2 = abuf0[i * 2 + 1] << 11; A1 += 1 << 13; A2 += 1 << 13; } R = V * c->yuv2rgb_v2r_coeff; G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); dest += 6; } } } }


void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) { if (!error_is_set(errp)) { v->type_int(v, obj, name, errp); } }


static void avc_luma_mid_8w_msa(const uint8_t *src, int32_t src_stride, uint8_t *dst, int32_t dst_stride, int32_t height) { uint32_t loop_cnt; v16i8 src0, src1, src2, src3, src4; v16i8 mask0, mask1, mask2; v8i16 hz_out0, hz_out1, hz_out2, hz_out3; v8i16 hz_out4, hz_out5, hz_out6, hz_out7, hz_out8; v8i16 dst0, dst1, dst2, dst3; v16u8 out0, out1; LD_SB3(&luma_mask_arr[0], 16, mask0, mask1, mask2); LD_SB5(src, src_stride, src0, src1, src2, src3, src4); XORI_B5_128_SB(src0, src1, src2, src3, src4); src += (5 * src_stride); hz_out0 = AVC_HORZ_FILTER_SH(src0, src0, mask0, mask1, mask2); hz_out1 = AVC_HORZ_FILTER_SH(src1, src1, mask0, mask1, mask2); hz_out2 = AVC_HORZ_FILTER_SH(src2, src2, mask0, mask1, mask2); hz_out3 = AVC_HORZ_FILTER_SH(src3, src3, mask0, mask1, mask2); hz_out4 = AVC_HORZ_FILTER_SH(src4, src4, mask0, mask1, mask2); for (loop_cnt = (height >> 2); loop_cnt--;) { LD_SB4(src, src_stride, src0, src1, src2, src3); XORI_B4_128_SB(src0, src1, src2, src3); src += (4 * src_stride); hz_out5 = AVC_HORZ_FILTER_SH(src0, src0, mask0, mask1, mask2); hz_out6 = AVC_HORZ_FILTER_SH(src1, src1, mask0, mask1, mask2); hz_out7 = AVC_HORZ_FILTER_SH(src2, src2, mask0, mask1, mask2); hz_out8 = AVC_HORZ_FILTER_SH(src3, src3, mask0, mask1, mask2); dst0 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5); dst1 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6); dst2 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out2, hz_out3, hz_out4, hz_out5, hz_out6, hz_out7); dst3 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out3, hz_out4, hz_out5, hz_out6, hz_out7, hz_out8); out0 = PCKEV_XORI128_UB(dst0, dst1); out1 = PCKEV_XORI128_UB(dst2, dst3); ST8x4_UB(out0, out1, dst, dst_stride); dst += (4 * dst_stride); hz_out3 = hz_out7; hz_out1 = hz_out5; hz_out5 = hz_out4; hz_out4 = hz_out8; hz_out2 = hz_out6; hz_out0 = hz_out5; } }


static av_cold int pam_encode_close(AVCodecContext *avctx) { av_frame_free(&avctx->coded_frame); return 0; }


static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) { OggVorbisContext *context = avccontext->priv_data; double cfreq; if (avccontext->flags & CODEC_FLAG_QSCALE) { /* variable bitrate */ if (vorbis_encode_setup_vbr(vi, avccontext->channels, avccontext->sample_rate, avccontext->global_quality / (float)FF_QP2LAMBDA / 10.0)) return -1; } else { int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1; int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1; /* constant bitrate */ if (vorbis_encode_setup_managed(vi, avccontext->channels, avccontext->sample_rate, minrate, avccontext->bit_rate, maxrate)) return -1; /* variable bitrate by estimate, disable slow rate management */ if (minrate == -1 && maxrate == -1) if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) return -1; } /* cutoff frequency */ if (avccontext->cutoff > 0) { cfreq = avccontext->cutoff / 1000.0; if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) return -1; } if (context->iblock) { vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock); } return vorbis_encode_setup_init(vi); }


static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { NellyMoserEncodeContext *s = avctx->priv_data; int ret; if (s->last_frame) return 0; memcpy(s->buf, s->buf + NELLY_SAMPLES, NELLY_BUF_LEN * sizeof(*s->buf)); if (frame) { memcpy(s->buf + NELLY_BUF_LEN, frame->data[0], frame->nb_samples * sizeof(*s->buf)); if (frame->nb_samples < NELLY_SAMPLES) { memset(s->buf + NELLY_BUF_LEN + avctx->frame_size, 0, (NELLY_SAMPLES - frame->nb_samples) * sizeof(*s->buf)); if (frame->nb_samples >= NELLY_BUF_LEN) s->last_frame = 1; } if ((ret = ff_af_queue_add(&s->afq, frame) < 0)) return ret; } else { memset(s->buf + NELLY_BUF_LEN, 0, NELLY_SAMPLES * sizeof(*s->buf)); s->last_frame = 1; } if ((ret = ff_alloc_packet(avpkt, NELLY_BLOCK_LEN))) { av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); return ret; } encode_block(s, avpkt->data, avpkt->size); /* Get the next frame pts/duration */ ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); *got_packet_ptr = 1; return 0; }


static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce, float bias) { IndividualChannelStream *ics = &sce->ics; float *in = sce->coeffs; float *out = sce->ret; float *saved = sce->saved; const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; float *buf = ac->buf_mdct; float *temp = ac->temp; int i; // imdct if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { if (ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) av_log(ac->avctx, AV_LOG_WARNING, "Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. " "If you heard an audible artifact, please submit the sample to the FFmpeg developers.\n"); for (i = 0; i < 1024; i += 128) ff_imdct_half(&ac->mdct_small, buf + i, in + i); } else ff_imdct_half(&ac->mdct, buf, in); /* window overlapping * NOTE: To simplify the overlapping code, all 'meaningless' short to long * and long to short transitions are considered to be short to short * transitions. This leaves just two cases (long to long and short to short) * with a little special sauce for EIGHT_SHORT_SEQUENCE. */ if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, bias, 512); } else { for (i = 0; i < 448; i++) out[i] = saved[i] + bias; if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, bias, 64); ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, bias, 64); ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, bias, 64); ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, bias, 64); ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, bias, 64); memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); } else { ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, bias, 64); for (i = 576; i < 1024; i++) out[i] = buf[i-512] + bias; } } // buffer update if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { for (i = 0; i < 64; i++) saved[i] = temp[64 + i] - bias; ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0, 64); ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0, 64); ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0, 64); memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { memcpy( saved, buf + 512, 448 * sizeof(float)); memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); } else { // LONG_STOP or ONLY_LONG memcpy( saved, buf + 512, 512 * sizeof(float)); } }


void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx) { const int high_bit_depth = avctx->bits_per_raw_sample > 8; if (!high_bit_depth) { c->put_pixels_tab[0][0] = put_pixels16_axp_asm; c->put_pixels_tab[0][1] = put_pixels16_x2_axp; c->put_pixels_tab[0][2] = put_pixels16_y2_axp; c->put_pixels_tab[0][3] = put_pixels16_xy2_axp; c->put_no_rnd_pixels_tab[0][0] = put_pixels16_axp_asm; c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_axp; c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_axp; c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_axp; c->avg_pixels_tab[0][0] = avg_pixels16_axp; c->avg_pixels_tab[0][1] = avg_pixels16_x2_axp; c->avg_pixels_tab[0][2] = avg_pixels16_y2_axp; c->avg_pixels_tab[0][3] = avg_pixels16_xy2_axp; c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_axp; c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_axp; c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_axp; c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_axp; c->put_pixels_tab[1][0] = put_pixels_axp_asm; c->put_pixels_tab[1][1] = put_pixels_x2_axp; c->put_pixels_tab[1][2] = put_pixels_y2_axp; c->put_pixels_tab[1][3] = put_pixels_xy2_axp; c->put_no_rnd_pixels_tab[1][0] = put_pixels_axp_asm; c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels_x2_axp; c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels_y2_axp; c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels_xy2_axp; c->avg_pixels_tab[1][0] = avg_pixels_axp; c->avg_pixels_tab[1][1] = avg_pixels_x2_axp; c->avg_pixels_tab[1][2] = avg_pixels_y2_axp; c->avg_pixels_tab[1][3] = avg_pixels_xy2_axp; c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels_axp; c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels_x2_axp; c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels_y2_axp; c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp; c->clear_blocks = clear_blocks_axp; } /* amask clears all bits that correspond to present features. */ if (amask(AMASK_MVI) == 0) { c->put_pixels_clamped = put_pixels_clamped_mvi_asm; c->add_pixels_clamped = add_pixels_clamped_mvi_asm; if (!high_bit_depth) c->get_pixels = get_pixels_mvi; c->diff_pixels = diff_pixels_mvi; c->sad[0] = pix_abs16x16_mvi_asm; c->sad[1] = pix_abs8x8_mvi; c->pix_abs[0][0] = pix_abs16x16_mvi_asm; c->pix_abs[1][0] = pix_abs8x8_mvi; c->pix_abs[0][1] = pix_abs16x16_x2_mvi; c->pix_abs[0][2] = pix_abs16x16_y2_mvi; c->pix_abs[0][3] = pix_abs16x16_xy2_mvi; } put_pixels_clamped_axp_p = c->put_pixels_clamped; add_pixels_clamped_axp_p = c->add_pixels_clamped; if (avctx->bits_per_raw_sample <= 8 && (avctx->idct_algo == FF_IDCT_AUTO || avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) { c->idct_put = ff_simple_idct_put_axp; c->idct_add = ff_simple_idct_add_axp; c->idct = ff_simple_idct_axp; } }


static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ long i; #if !HAVE_FAST_UNALIGNED if((long)src2 & (sizeof(long)-1)){ for(i=0; i+7<w; i+=8){ dst[i+0] = src1[i+0]-src2[i+0]; dst[i+1] = src1[i+1]-src2[i+1]; dst[i+2] = src1[i+2]-src2[i+2]; dst[i+3] = src1[i+3]-src2[i+3]; dst[i+4] = src1[i+4]-src2[i+4]; dst[i+5] = src1[i+5]-src2[i+5]; dst[i+6] = src1[i+6]-src2[i+6]; dst[i+7] = src1[i+7]-src2[i+7]; } }else #endif for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ long a = *(long*)(src1+i); long b = *(long*)(src2+i); *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80); } for(; i<w; i++) dst[i+0] = src1[i+0]-src2[i+0]; }


static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; DPXContext *const s = avctx->priv_data; AVFrame *picture = data; AVFrame *const p = &s->picture; uint8_t *ptr[AV_NUM_DATA_POINTERS]; unsigned int offset; int magic_num, endian; int x, y, i, ret; int w, h, bits_per_color, descriptor, elements, packing, total_size; unsigned int rgbBuffer = 0; int n_datum = 0; if (avpkt->size <= 1634) { av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n"); return AVERROR_INVALIDDATA; } magic_num = AV_RB32(buf); buf += 4; /* Check if the files "magic number" is "SDPX" which means it uses * big-endian or XPDS which is for little-endian files */ if (magic_num == AV_RL32("SDPX")) { endian = 0; } else if (magic_num == AV_RB32("SDPX")) { endian = 1; } else { av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); return AVERROR_INVALIDDATA; } offset = read32(&buf, endian); if (avpkt->size <= offset) { av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n"); return AVERROR_INVALIDDATA; } // Need to end in 0x304 offset from start of file buf = avpkt->data + 0x304; w = read32(&buf, endian); h = read32(&buf, endian); if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) return ret; if (w != avctx->width || h != avctx->height) avcodec_set_dimensions(avctx, w, h); // Need to end in 0x320 to read the descriptor buf += 20; descriptor = buf[0]; // Need to end in 0x323 to read the bits per color buf += 3; avctx->bits_per_raw_sample = bits_per_color = buf[0]; buf++; packing = *((uint16_t*)buf); buf += 824; avctx->sample_aspect_ratio.num = read32(&buf, endian); avctx->sample_aspect_ratio.den = read32(&buf, endian); if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 0x10000); else avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; switch (descriptor) { case 51: // RGBA elements = 4; break; case 50: // RGB elements = 3; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor); return AVERROR_INVALIDDATA; } switch (bits_per_color) { case 8: if (elements == 4) { avctx->pix_fmt = AV_PIX_FMT_RGBA; } else { avctx->pix_fmt = AV_PIX_FMT_RGB24; } total_size = avctx->width * avctx->height * elements; break; case 10: if (!packing) { av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n"); return -1; } avctx->pix_fmt = AV_PIX_FMT_GBRP10; total_size = (avctx->width * avctx->height * elements + 2) / 3 * 4; break; case 12: if (!packing) { av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n"); return -1; } if (endian) { avctx->pix_fmt = AV_PIX_FMT_GBRP12BE; } else { avctx->pix_fmt = AV_PIX_FMT_GBRP12LE; } total_size = 2 * avctx->width * avctx->height * elements; break; case 16: if (endian) { avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGB48BE; } else { avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGB48LE; } total_size = 2 * avctx->width * avctx->height * elements; break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color); return AVERROR_INVALIDDATA; } if (s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } // Move pointer to offset from start of file buf = avpkt->data + offset; for (i=0; i<AV_NUM_DATA_POINTERS; i++) ptr[i] = p->data[i]; if (total_size > avpkt->size) { av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); return AVERROR_INVALIDDATA; } switch (bits_per_color) { case 10: for (x = 0; x < avctx->height; x++) { uint16_t *dst[3] = {(uint16_t*)ptr[0], (uint16_t*)ptr[1], (uint16_t*)ptr[2]}; for (y = 0; y < avctx->width; y++) { *dst[2]++ = read10in32(&buf, &rgbBuffer, &n_datum, endian); *dst[0]++ = read10in32(&buf, &rgbBuffer, &n_datum, endian); *dst[1]++ = read10in32(&buf, &rgbBuffer, &n_datum, endian); // For 10 bit, ignore alpha if (elements == 4) read10in32(&buf, &rgbBuffer, &n_datum, endian); } for (i = 0; i < 3; i++) ptr[i] += p->linesize[i]; } break; case 12: for (x = 0; x < avctx->height; x++) { uint16_t *dst[3] = {(uint16_t*)ptr[0], (uint16_t*)ptr[1], (uint16_t*)ptr[2]}; for (y = 0; y < avctx->width; y++) { *dst[2] = *((uint16_t*)buf); *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12); dst[2]++; buf += 2; *dst[0] = *((uint16_t*)buf); *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12); dst[0]++; buf += 2; *dst[1] = *((uint16_t*)buf); *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12); dst[1]++; buf += 2; // For 12 bit, ignore alpha if (elements == 4) buf += 2; } for (i = 0; i < 3; i++) ptr[i] += p->linesize[i]; } break; case 16: elements *= 2; case 8: for (x = 0; x < avctx->height; x++) { memcpy(ptr[0], buf, elements*avctx->width); ptr[0] += p->linesize[0]; buf += elements*avctx->width; } break; } *picture = s->picture; *got_frame = 1; return buf_size; }


static void gen_pool16c_insn(DisasContext *ctx, int *is_branch) { int rd = mmreg((ctx->opcode >> 3) & 0x7); int rs = mmreg(ctx->opcode & 0x7); int opc; switch (((ctx->opcode) >> 4) & 0x3f) { case NOT16 + 0: case NOT16 + 1: case NOT16 + 2: case NOT16 + 3: gen_logic(ctx, OPC_NOR, rd, rs, 0); break; case XOR16 + 0: case XOR16 + 1: case XOR16 + 2: case XOR16 + 3: gen_logic(ctx, OPC_XOR, rd, rd, rs); break; case AND16 + 0: case AND16 + 1: case AND16 + 2: case AND16 + 3: gen_logic(ctx, OPC_AND, rd, rd, rs); break; case OR16 + 0: case OR16 + 1: case OR16 + 2: case OR16 + 3: gen_logic(ctx, OPC_OR, rd, rd, rs); break; case LWM16 + 0: case LWM16 + 1: case LWM16 + 2: case LWM16 + 3: { static const int lwm_convert[] = { 0x11, 0x12, 0x13, 0x14 }; int offset = ZIMM(ctx->opcode, 0, 4); gen_ldst_multiple(ctx, LWM32, lwm_convert[(ctx->opcode >> 4) & 0x3], 29, offset << 2); } break; case SWM16 + 0: case SWM16 + 1: case SWM16 + 2: case SWM16 + 3: { static const int swm_convert[] = { 0x11, 0x12, 0x13, 0x14 }; int offset = ZIMM(ctx->opcode, 0, 4); gen_ldst_multiple(ctx, SWM32, swm_convert[(ctx->opcode >> 4) & 0x3], 29, offset << 2); } break; case JR16 + 0: case JR16 + 1: { int reg = ctx->opcode & 0x1f; gen_compute_branch(ctx, OPC_JR, 2, reg, 0, 0); } *is_branch = 1; break; case JRC16 + 0: case JRC16 + 1: { int reg = ctx->opcode & 0x1f; gen_compute_branch(ctx, OPC_JR, 2, reg, 0, 0); /* Let normal delay slot handling in our caller take us to the branch target. */ } break; case JALR16 + 0: case JALR16 + 1: opc = OPC_JALR; goto do_jalr; case JALR16S + 0: case JALR16S + 1: opc = OPC_JALRS; do_jalr: { int reg = ctx->opcode & 0x1f; gen_compute_branch(ctx, opc, 2, reg, 31, 0); } *is_branch = 1; break; case MFHI16 + 0: case MFHI16 + 1: gen_HILO(ctx, OPC_MFHI, 0, uMIPS_RS5(ctx->opcode)); break; case MFLO16 + 0: case MFLO16 + 1: gen_HILO(ctx, OPC_MFLO, 0, uMIPS_RS5(ctx->opcode)); break; case BREAK16: generate_exception(ctx, EXCP_BREAK); break; case SDBBP16: /* XXX: not clear which exception should be raised * when in debug mode... */ check_insn(ctx, ISA_MIPS32); if (!(ctx->hflags & MIPS_HFLAG_DM)) { generate_exception(ctx, EXCP_DBp); } else { generate_exception(ctx, EXCP_DBp); } break; case JRADDIUSP + 0: case JRADDIUSP + 1: { int imm = ZIMM(ctx->opcode, 0, 5); gen_compute_branch(ctx, OPC_JR, 2, 31, 0, 0); gen_arith_imm(ctx, OPC_ADDIU, 29, 29, imm << 2); /* Let normal delay slot handling in our caller take us to the branch target. */ } break; default: generate_exception(ctx, EXCP_RI); break; } }


int ff_filter_frame(AVFilterLink *link, AVFrame *frame) { int (*filter_frame)(AVFilterLink *, AVFrame *); AVFilterPad *dst = link->dstpad; AVFrame *out; FF_DPRINTF_START(NULL, filter_frame); ff_dlog_link(NULL, link, 1); if (!(filter_frame = dst->filter_frame)) filter_frame = default_filter_frame; /* copy the frame if needed */ if (dst->needs_writable && !av_frame_is_writable(frame)) { av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n"); switch (link->type) { case AVMEDIA_TYPE_VIDEO: out = ff_get_video_buffer(link, link->w, link->h); break; case AVMEDIA_TYPE_AUDIO: out = ff_get_audio_buffer(link, frame->nb_samples); break; default: return AVERROR(EINVAL); } if (!out) { av_frame_free(&frame); return AVERROR(ENOMEM); } av_frame_copy_props(out, frame); switch (link->type) { case AVMEDIA_TYPE_VIDEO: av_image_copy(out->data, out->linesize, frame->data, frame->linesize, frame->format, frame->width, frame->height); break; case AVMEDIA_TYPE_AUDIO: av_samples_copy(out->extended_data, frame->extended_data, 0, 0, frame->nb_samples, av_get_channel_layout_nb_channels(frame->channel_layout), frame->format); break; default: return AVERROR(EINVAL); } av_frame_free(&frame); } else out = frame; return filter_frame(link, out); }


static ssize_t vnc_tls_push(gnutls_transport_ptr_t transport, const void *data, size_t len) { VncState *vs = (VncState *)transport; int ret; retry: ret = send(vs->csock, data, len, 0); if (ret < 0) { if (errno == EINTR) goto retry; return -1; } return ret; }


static void property_set_enum(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { EnumProperty *prop = opaque; int value; visit_type_enum(v, &value, prop->strings, NULL, name, errp); prop->set(obj, value, errp); }


void ff_h264_filter_mb_fast(const H264Context *h, H264SliceContext *sl, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { assert(!FRAME_MBAFF(h)); if(!h->h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) { ff_h264_filter_mb(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); return; } #if CONFIG_SMALL h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift); #else if(h->pixel_shift){ h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1); }else{ h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0); } #endif }


void qmp_eject(const char *device, bool has_force, bool force, Error **errp) { Error *local_err = NULL; int rc; if (!has_force) { force = false; } rc = do_open_tray(device, force, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (rc == EINPROGRESS) { error_setg(errp, "Device '%s' is locked and force was not specified, " "wait for tray to open and try again", device); return; } qmp_x_blockdev_remove_medium(device, errp); }


int check_prot(int prot, int rw, int access_type) { int ret; if (access_type == ACCESS_CODE) { if (prot & PAGE_EXEC) { ret = 0; } else { ret = -2; } } else if (rw) { if (prot & PAGE_WRITE) { ret = 0; } else { ret = -2; } } else { if (prot & PAGE_READ) { ret = 0; } else { ret = -2; } } return ret; }


static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, uint64_t qiov_offset, uint64_t n_bytes, uint64_t offset) { int ret; VmdkGrainMarker *data = NULL; uLongf buf_len; QEMUIOVector local_qiov; struct iovec iov; int64_t write_offset; int64_t write_end_sector; if (extent->compressed) { void *compressed_data; if (!extent->has_marker) { ret = -EINVAL; goto out; } buf_len = (extent->cluster_sectors << 9) * 2; data = g_malloc(buf_len + sizeof(VmdkGrainMarker)); compressed_data = g_malloc(n_bytes); qemu_iovec_to_buf(qiov, qiov_offset, compressed_data, n_bytes); ret = compress(data->data, &buf_len, compressed_data, n_bytes); g_free(compressed_data); if (ret != Z_OK || buf_len == 0) { ret = -EINVAL; goto out; } data->lba = offset >> BDRV_SECTOR_BITS; data->size = buf_len; n_bytes = buf_len + sizeof(VmdkGrainMarker); iov = (struct iovec) { .iov_base = data, .iov_len = n_bytes, }; qemu_iovec_init_external(&local_qiov, &iov, 1); } else { qemu_iovec_init(&local_qiov, qiov->niov); qemu_iovec_concat(&local_qiov, qiov, qiov_offset, n_bytes); } write_offset = cluster_offset + offset_in_cluster, ret = bdrv_co_pwritev(extent->file, write_offset, n_bytes, &local_qiov, 0); write_end_sector = DIV_ROUND_UP(write_offset + n_bytes, BDRV_SECTOR_SIZE); if (extent->compressed) { extent->next_cluster_sector = write_end_sector; } else { extent->next_cluster_sector = MAX(extent->next_cluster_sector, write_end_sector); } if (ret < 0) { goto out; } ret = 0; out: g_free(data); if (!extent->compressed) { qemu_iovec_destroy(&local_qiov); } return ret; }


static int http_server(void) { int server_fd, ret, rtsp_server_fd, delay, delay1; struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry; HTTPContext *c, *c_next; server_fd = socket_open_listen(&my_http_addr); if (server_fd < 0) return -1; rtsp_server_fd = socket_open_listen(&my_rtsp_addr); if (rtsp_server_fd < 0) return -1; http_log("ffserver started.\n"); start_children(first_feed); first_http_ctx = NULL; nb_connections = 0; first_http_ctx = NULL; start_multicast(); for(;;) { poll_entry = poll_table; poll_entry->fd = server_fd; poll_entry->events = POLLIN; poll_entry++; poll_entry->fd = rtsp_server_fd; poll_entry->events = POLLIN; poll_entry++; /* wait for events on each HTTP handle */ c = first_http_ctx; delay = 1000; while (c != NULL) { int fd; fd = c->fd; switch(c->state) { case HTTPSTATE_SEND_HEADER: case RTSPSTATE_SEND_REPLY: case RTSPSTATE_SEND_PACKET: c->poll_entry = poll_entry; poll_entry->fd = fd; poll_entry->events = POLLOUT; poll_entry++; break; case HTTPSTATE_SEND_DATA_HEADER: case HTTPSTATE_SEND_DATA: case HTTPSTATE_SEND_DATA_TRAILER: if (!c->is_packetized) { /* for TCP, we output as much as we can (may need to put a limit) */ c->poll_entry = poll_entry; poll_entry->fd = fd; poll_entry->events = POLLOUT; poll_entry++; } else { /* not strictly correct, but currently cannot add more than one fd in poll entry */ delay = 0; } break; case HTTPSTATE_WAIT_REQUEST: case HTTPSTATE_RECEIVE_DATA: case HTTPSTATE_WAIT_FEED: case RTSPSTATE_WAIT_REQUEST: /* need to catch errors */ c->poll_entry = poll_entry; poll_entry->fd = fd; poll_entry->events = POLLIN;/* Maybe this will work */ poll_entry++; break; case HTTPSTATE_WAIT: c->poll_entry = NULL; delay1 = compute_send_delay(c); if (delay1 < delay) delay = delay1; break; case HTTPSTATE_WAIT_SHORT: c->poll_entry = NULL; delay1 = 10; /* one tick wait XXX: 10 ms assumed */ if (delay1 < delay) delay = delay1; break; default: c->poll_entry = NULL; break; } c = c->next; } /* wait for an event on one connection. We poll at least every second to handle timeouts */ do { ret = poll(poll_table, poll_entry - poll_table, delay); } while (ret == -1); cur_time = gettime_ms(); if (need_to_start_children) { need_to_start_children = 0; start_children(first_feed); } /* now handle the events */ for(c = first_http_ctx; c != NULL; c = c_next) { c_next = c->next; if (handle_connection(c) < 0) { /* close and free the connection */ log_connection(c); close_connection(c); } } poll_entry = poll_table; /* new HTTP connection request ? */ if (poll_entry->revents & POLLIN) { new_connection(server_fd, 0); } poll_entry++; /* new RTSP connection request ? */ if (poll_entry->revents & POLLIN) { new_connection(rtsp_server_fd, 1); } } }


static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, const uint8_t *buf, int buf_size, int first_field) { static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 }; int i, cid, ret; if (buf_size < 0x280) return AVERROR_INVALIDDATA; if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5)) { av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n"); return AVERROR_INVALIDDATA; } if (buf[5] & 2) { /* interlaced */ ctx->cur_field = buf[5] & 1; frame->interlaced_frame = 1; frame->top_field_first = first_field ^ ctx->cur_field; av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field); } ctx->height = AV_RB16(buf + 0x18); ctx->width = AV_RB16(buf + 0x1a); av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height); ctx->is_444 = 0; if (buf[0x4] == 0x2) { ctx->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; ctx->avctx->bits_per_raw_sample = 10; if (ctx->bit_depth != 10) { ff_blockdsp_init(&ctx->bdsp, ctx->avctx); ff_idctdsp_init(&ctx->idsp, ctx->avctx); ctx->bit_depth = 10; ctx->decode_dct_block = dnxhd_decode_dct_block_10_444; } ctx->is_444 = 1; } else if (buf[0x21] & 0x40) { ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; ctx->avctx->bits_per_raw_sample = 10; if (ctx->bit_depth != 10) { ff_blockdsp_init(&ctx->bdsp, ctx->avctx); ff_idctdsp_init(&ctx->idsp, ctx->avctx); ctx->bit_depth = 10; ctx->decode_dct_block = dnxhd_decode_dct_block_10; } } else { ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P; ctx->avctx->bits_per_raw_sample = 8; if (ctx->bit_depth != 8) { ff_blockdsp_init(&ctx->bdsp, ctx->avctx); ff_idctdsp_init(&ctx->idsp, ctx->avctx); ctx->bit_depth = 8; ctx->decode_dct_block = dnxhd_decode_dct_block_8; } } cid = AV_RB32(buf + 0x28); av_dlog(ctx->avctx, "compression id %d\n", cid); if ((ret = dnxhd_init_vlc(ctx, cid)) < 0) return ret; if (buf_size < ctx->cid_table->coding_unit_size) { av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n"); return AVERROR_INVALIDDATA; } ctx->mb_width = ctx->width >> 4; ctx->mb_height = buf[0x16d]; av_dlog(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height); if ((ctx->height + 15) >> 4 == ctx->mb_height && frame->interlaced_frame) ctx->height <<= 1; if (ctx->mb_height > 68 || (ctx->mb_height << frame->interlaced_frame) > (ctx->height + 15) >> 4) { av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height); return AVERROR_INVALIDDATA; } for (i = 0; i < ctx->mb_height; i++) { ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i << 2)); av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); if (buf_size < ctx->mb_scan_index[i] + 0x280LL) { av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); return AVERROR_INVALIDDATA; } } return 0; }


static int get_monitor_def(target_long *pval, const char *name) { const MonitorDef *md; void *ptr; for(md = monitor_defs; md->name != NULL; md++) { if (compare_cmd(name, md->name)) { if (md->get_value) { *pval = md->get_value(md, md->offset); } else { CPUState *env = mon_get_cpu(); if (!env) return -2; ptr = (uint8_t *)env + md->offset; switch(md->type) { case MD_I32: *pval = *(int32_t *)ptr; break; case MD_TLONG: *pval = *(target_long *)ptr; break; default: *pval = 0; break; } } return 0; } } return -1; }


static int do_sigframe_return_v2(CPUState *env, target_ulong frame_addr, struct target_ucontext_v2 *uc) { sigset_t host_set; abi_ulong *regspace; target_to_host_sigset(&host_set, &uc->tuc_sigmask); sigprocmask(SIG_SETMASK, &host_set, NULL); if (restore_sigcontext(env, &uc->tuc_mcontext)) if (do_sigaltstack(frame_addr + offsetof(struct target_ucontext_v2, tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) #if 0 /* Send SIGTRAP if we're single-stepping */ if (ptrace_cancel_bpt(current)) send_sig(SIGTRAP, current, 1); #endif return 0;


FWCfgState *pc_memory_init(MemoryRegion *system_memory, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *rom_memory, MemoryRegion **ram_memory, PcGuestInfo *guest_info) { int linux_boot, i; MemoryRegion *ram, *option_rom_mr; MemoryRegion *ram_below_4g, *ram_above_4g; FWCfgState *fw_cfg; linux_boot = (kernel_filename != NULL); /* Allocate RAM. We allocate it as a single memory region and use * aliases to address portions of it, mostly for backwards compatibility * with older qemus that used qemu_ram_alloc(). */ ram = g_malloc(sizeof(*ram)); memory_region_init_ram(ram, NULL, "pc.ram", below_4g_mem_size + above_4g_mem_size); vmstate_register_ram_global(ram); *ram_memory = ram; ram_below_4g = g_malloc(sizeof(*ram_below_4g)); memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", ram, 0, below_4g_mem_size); memory_region_add_subregion(system_memory, 0, ram_below_4g); e820_add_entry(0, below_4g_mem_size, E820_RAM); if (above_4g_mem_size > 0) { ram_above_4g = g_malloc(sizeof(*ram_above_4g)); memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", ram, below_4g_mem_size, above_4g_mem_size); memory_region_add_subregion(system_memory, 0x100000000ULL, ram_above_4g); e820_add_entry(0x100000000ULL, above_4g_mem_size, E820_RAM); } /* Initialize PC system firmware */ pc_system_firmware_init(rom_memory, guest_info->isapc_ram_fw); option_rom_mr = g_malloc(sizeof(*option_rom_mr)); memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE); vmstate_register_ram_global(option_rom_mr); memory_region_add_subregion_overlap(rom_memory, PC_ROM_MIN_VGA, option_rom_mr, 1); fw_cfg = bochs_bios_init(); rom_set_fw(fw_cfg); if (linux_boot) { load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size); } for (i = 0; i < nb_option_roms; i++) { rom_add_option(option_rom[i].name, option_rom[i].bootindex); } guest_info->fw_cfg = fw_cfg; return fw_cfg; }


static void press_key(VncState *vs, int keysym) { int keycode = keysym2scancode(vs->vd->kbd_layout, keysym) & SCANCODE_KEYMASK; qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, true); qemu_input_event_send_key_delay(0); qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false); qemu_input_event_send_key_delay(0); }


static void s390_virtio_device_sync(VirtIOS390Device *dev) { VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus); ram_addr_t cur_offs; uint8_t num_vq; int i; virtio_reset(dev->vdev); /* Sync dev space */ stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id); stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, s390_virtio_device_num_vq(dev)); stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len); stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len); num_vq = s390_virtio_device_num_vq(dev); stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq); /* Sync virtqueues */ for (i = 0; i < num_vq; i++) { ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) + (i * VIRTIO_VQCONFIG_LEN); ram_addr_t vring; vring = s390_virtio_next_ring(bus); virtio_queue_set_addr(dev->vdev, i, vring); virtio_queue_set_vector(dev->vdev, i, i); stq_phys(vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring); stw_phys(vq + VIRTIO_VQCONFIG_OFFS_NUM, virtio_queue_get_num(dev->vdev, i)); } cur_offs = dev->dev_offs; cur_offs += VIRTIO_DEV_OFFS_CONFIG; cur_offs += num_vq * VIRTIO_VQCONFIG_LEN; /* Sync feature bitmap */ if (dev->vdev->get_features) { stl_phys(cur_offs, dev->vdev->get_features(dev->vdev)); } dev->feat_offs = cur_offs + dev->feat_len; cur_offs += dev->feat_len * 2; /* Sync config space */ if (dev->vdev->get_config) { dev->vdev->get_config(dev->vdev, dev->vdev->config); } cpu_physical_memory_rw(cur_offs, dev->vdev->config, dev->vdev->config_len, 1); cur_offs += dev->vdev->config_len; }


static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){ int i; int dc0, dc2; pixel4 dc0splat, dc2splat; pixel *src = (pixel*)_src; stride /= sizeof(pixel); dc0=dc2=0; for(i=0;i<4; i++){ dc0+= src[-1+i*stride]; dc2+= src[-1+(i+4)*stride]; } dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2); dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2); for(i=0; i<4; i++){ ((pixel4*)(src+i*stride))[0]= ((pixel4*)(src+i*stride))[1]= dc0splat; } for(i=4; i<8; i++){ ((pixel4*)(src+i*stride))[0]= ((pixel4*)(src+i*stride))[1]= dc2splat; } }


static void alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size, const uint8_t *sps_pps, uint32_t sps_pps_size, const uint8_t *in, uint32_t in_size) { uint32_t offset = *poutbuf_size; uint8_t nal_header_size = offset ? 3 : 4; *poutbuf_size += sps_pps_size+in_size+nal_header_size; *poutbuf = av_realloc(*poutbuf, *poutbuf_size); if (sps_pps) memcpy(*poutbuf+offset, sps_pps, sps_pps_size); memcpy(*poutbuf+sps_pps_size+nal_header_size+offset, in, in_size); if (!offset) AV_WB32(*poutbuf+sps_pps_size, 1); else { (*poutbuf+offset)[0] = (*poutbuf+offset)[1] = 0; (*poutbuf+offset)[2] = 1; } }


void aio_set_event_notifier(AioContext *ctx, EventNotifier *e, EventNotifierHandler *io_notify, AioFlushEventNotifierHandler *io_flush) { AioHandler *node; QLIST_FOREACH(node, &ctx->aio_handlers, node) { if (node->e == e && !node->deleted) { break; } } /* Are we deleting the fd handler? */ if (!io_notify) { if (node) { g_source_remove_poll(&ctx->source, &node->pfd); /* If the lock is held, just mark the node as deleted */ if (ctx->walking_handlers) { node->deleted = 1; node->pfd.revents = 0; } else { /* Otherwise, delete it for real. We can't just mark it as * deleted because deleted nodes are only cleaned up after * releasing the walking_handlers lock. */ QLIST_REMOVE(node, node); g_free(node); } } } else { if (node == NULL) { /* Alloc and insert if it's not already there */ node = g_malloc0(sizeof(AioHandler)); node->e = e; node->pfd.fd = (uintptr_t)event_notifier_get_handle(e); node->pfd.events = G_IO_IN; QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node); g_source_add_poll(&ctx->source, &node->pfd); } /* Update handler with latest information */ node->io_notify = io_notify; node->io_flush = io_flush; } aio_notify(ctx); }


int float_near_ulp(float a, float b, unsigned max_ulp) { union av_intfloat32 x, y; x.f = a; y.f = b; if (is_negative(x) != is_negative(y)) { // handle -0.0 == +0.0 return a == b; } if (abs(x.i - y.i) <= max_ulp) return 1; return 0; }


static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) { ROQDPCMContext *context = avctx->priv_data; if (avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); return -1; } if (avctx->sample_rate != 22050) { av_log(avctx, AV_LOG_ERROR, "Audio must be 22050 Hz\n"); return -1; } if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) { av_log(avctx, AV_LOG_ERROR, "Audio must be signed 16-bit\n"); return -1; } avctx->frame_size = ROQ_FIRST_FRAME_SIZE; context->lastSample[0] = context->lastSample[1] = 0; avctx->coded_frame= avcodec_alloc_frame(); return 0; }


static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset, sPAPRMachineState *spapr) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); int index = ppc_get_vcpu_dt_id(cpu); uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), 0xffffffff, 0xffffffff}; uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : SPAPR_TIMEBASE_FREQ; uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000; uint32_t page_sizes_prop[64]; size_t page_sizes_prop_size; uint32_t vcpus_per_socket = smp_threads * smp_cores; uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)}; int compat_smt = MIN(smp_threads, ppc_compat_max_threads(cpu)); sPAPRDRConnector *drc; sPAPRDRConnectorClass *drck; int drc_index; uint32_t radix_AP_encodings[PPC_PAGE_SIZES_MAX_SZ]; int i; drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index); if (drc) { drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); drc_index = drck->get_index(drc); _FDT((fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index))); } _FDT((fdt_setprop_cell(fdt, offset, "reg", index))); _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu"))); _FDT((fdt_setprop_cell(fdt, offset, "cpu-version", env->spr[SPR_PVR]))); _FDT((fdt_setprop_cell(fdt, offset, "d-cache-block-size", env->dcache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "d-cache-line-size", env->dcache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "i-cache-block-size", env->icache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "i-cache-line-size", env->icache_line_size))); if (pcc->l1_dcache_size) { _FDT((fdt_setprop_cell(fdt, offset, "d-cache-size", pcc->l1_dcache_size))); } else { error_report("Warning: Unknown L1 dcache size for cpu"); } if (pcc->l1_icache_size) { _FDT((fdt_setprop_cell(fdt, offset, "i-cache-size", pcc->l1_icache_size))); } else { error_report("Warning: Unknown L1 icache size for cpu"); } _FDT((fdt_setprop_cell(fdt, offset, "timebase-frequency", tbfreq))); _FDT((fdt_setprop_cell(fdt, offset, "clock-frequency", cpufreq))); _FDT((fdt_setprop_cell(fdt, offset, "slb-size", env->slb_nr))); _FDT((fdt_setprop_cell(fdt, offset, "ibm,slb-size", env->slb_nr))); _FDT((fdt_setprop_string(fdt, offset, "status", "okay"))); _FDT((fdt_setprop(fdt, offset, "64-bit", NULL, 0))); if (env->spr_cb[SPR_PURR].oea_read) { _FDT((fdt_setprop(fdt, offset, "ibm,purr", NULL, 0))); } if (env->mmu_model & POWERPC_MMU_1TSEG) { _FDT((fdt_setprop(fdt, offset, "ibm,processor-segment-sizes", segs, sizeof(segs)))); } /* Advertise VMX/VSX (vector extensions) if available * 0 / no property == no vector extensions * 1 == VMX / Altivec available * 2 == VSX available */ if (env->insns_flags & PPC_ALTIVEC) { uint32_t vmx = (env->insns_flags2 & PPC2_VSX) ? 2 : 1; _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", vmx))); } /* Advertise DFP (Decimal Floating Point) if available * 0 / no property == no DFP * 1 == DFP available */ if (env->insns_flags2 & PPC2_DFP) { _FDT((fdt_setprop_cell(fdt, offset, "ibm,dfp", 1))); } page_sizes_prop_size = ppc_create_page_sizes_prop(env, page_sizes_prop, sizeof(page_sizes_prop)); if (page_sizes_prop_size) { _FDT((fdt_setprop(fdt, offset, "ibm,segment-page-sizes", page_sizes_prop, page_sizes_prop_size))); } spapr_populate_pa_features(env, fdt, offset); _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id", cs->cpu_index / vcpus_per_socket))); _FDT((fdt_setprop(fdt, offset, "ibm,pft-size", pft_size_prop, sizeof(pft_size_prop)))); _FDT(spapr_fixup_cpu_numa_dt(fdt, offset, cs)); _FDT(spapr_fixup_cpu_smt_dt(fdt, offset, cpu, compat_smt)); if (pcc->radix_page_info) { for (i = 0; i < pcc->radix_page_info->count; i++) { radix_AP_encodings[i] = cpu_to_be32(pcc->radix_page_info->entries[i]); } _FDT((fdt_setprop(fdt, offset, "ibm,processor-radix-AP-encodings", radix_AP_encodings, pcc->radix_page_info->count * sizeof(radix_AP_encodings[0])))); } }


static void test_function(const TestStruct test_sample) { int ret, i; void **output_data = NULL; AVAudioFifo *afifo = av_audio_fifo_alloc(test_sample.format, test_sample.nb_ch, test_sample.nb_samples_pch); if (!afifo) { ERROR("ERROR: av_audio_fifo_alloc returned NULL!"); } ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample.nb_samples_pch, 0); if (ret < 0){ ERROR("ERROR: av_audio_fifo_write failed!"); } printf("written: %d\n", ret); ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample.nb_samples_pch, 0); if (ret < 0){ ERROR("ERROR: av_audio_fifo_write failed!"); } printf("written: %d\n", ret); printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo)); ret = read_samples_from_audio_fifo(afifo, &output_data, test_sample.nb_samples_pch); if (ret < 0){ ERROR("ERROR: av_audio_fifo_read failed!"); } printf("read: %d\n", ret); print_audio_bytes(&test_sample, output_data, ret); printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo)); /* test av_audio_fifo_peek */ ret = av_audio_fifo_peek(afifo, output_data, afifo->nb_samples); if (ret < 0){ ERROR("ERROR: av_audio_fifo_peek failed!"); } printf("peek:\n"); print_audio_bytes(&test_sample, output_data, ret); printf("\n"); /* test av_audio_fifo_peek_at */ printf("peek_at:\n"); for (i = 0; i < afifo->nb_samples; ++i){ ret = av_audio_fifo_peek_at(afifo, output_data, 1, i); if (ret < 0){ ERROR("ERROR: av_audio_fifo_peek_at failed!"); } printf("%d:\n", i); print_audio_bytes(&test_sample, output_data, ret); } printf("\n"); /* test av_audio_fifo_drain */ ret = av_audio_fifo_drain(afifo, afifo->nb_samples); if (ret < 0){ ERROR("ERROR: av_audio_fifo_drain failed!"); } if (afifo->nb_samples){ ERROR("drain failed to flush all samples in audio_fifo!"); } /* deallocate */ for (i = 0; i < afifo->nb_buffers; ++i){ av_freep(&output_data[i]); } av_freep(&output_data); av_audio_fifo_free(afifo); }


static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block) { ff_wmv2_idct_c(block); put_pixels_clamped_c(block, dest, line_size); }


static void decode_interframe_v4(AVCodecContext *avctx, uint8_t *src, uint32_t size) { Hnm4VideoContext *hnm = avctx->priv_data; GetByteContext gb; uint32_t writeoffset = 0, count, left, offset; uint8_t tag, previous, backline, backward, swap; bytestream2_init(&gb, src, size); while (bytestream2_tell(&gb) < size) { count = bytestream2_peek_byte(&gb) & 0x1F; if (count == 0) { tag = bytestream2_get_byte(&gb) & 0xE0; tag = tag >> 5; if (tag == 0) { hnm->current[writeoffset++] = bytestream2_get_byte(&gb); hnm->current[writeoffset++] = bytestream2_get_byte(&gb); } else if (tag == 1) { writeoffset += bytestream2_get_byte(&gb) * 2; } else if (tag == 2) { count = bytestream2_get_le16(&gb); count *= 2; writeoffset += count; } else if (tag == 3) { count = bytestream2_get_byte(&gb) * 2; while (count > 0) { hnm->current[writeoffset++] = bytestream2_peek_byte(&gb); count--; } bytestream2_skip(&gb, 1); } else { break; } } else { previous = bytestream2_peek_byte(&gb) & 0x20; backline = bytestream2_peek_byte(&gb) & 0x40; backward = bytestream2_peek_byte(&gb) & 0x80; bytestream2_skip(&gb, 1); swap = bytestream2_peek_byte(&gb) & 0x01; offset = bytestream2_get_le16(&gb); offset = (offset >> 1) & 0x7FFF; offset = writeoffset + (offset * 2) - 0x8000; left = count; if (!backward && offset + count >= hnm->width * hnm->height) { av_log(avctx, AV_LOG_ERROR, "Attempting to read out of bounds"); break; } else if (backward && offset >= hnm->width * hnm->height) { av_log(avctx, AV_LOG_ERROR, "Attempting to read out of bounds"); break; } else if (writeoffset + count >= hnm->width * hnm->height) { av_log(avctx, AV_LOG_ERROR, "Attempting to write out of bounds"); break; } if (previous) { while (left > 0) { if (backline) { hnm->current[writeoffset++] = hnm->previous[offset - (2 * hnm->width) + 1]; hnm->current[writeoffset++] = hnm->previous[offset++]; offset++; } else { hnm->current[writeoffset++] = hnm->previous[offset++]; hnm->current[writeoffset++] = hnm->previous[offset++]; } if (backward) offset -= 4; left--; } } else { while (left > 0) { if (backline) { hnm->current[writeoffset++] = hnm->current[offset - (2 * hnm->width) + 1]; hnm->current[writeoffset++] = hnm->current[offset++]; offset++; } else { hnm->current[writeoffset++] = hnm->current[offset++]; hnm->current[writeoffset++] = hnm->current[offset++]; } if (backward) offset -= 4; left--; } } if (swap) { left = count; writeoffset -= count * 2; while (left > 0) { swap = hnm->current[writeoffset]; hnm->current[writeoffset] = hnm->current[writeoffset + 1]; hnm->current[writeoffset + 1] = swap; left--; writeoffset += 2; } } } } }


static void setup_frame(int sig, struct emulated_sigaction *ka, target_sigset_t *set, CPUX86State *env) { struct sigframe *frame; int err = 0; frame = get_sigframe(ka, env, sizeof(*frame)); #if 0 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) goto give_sigsegv; #endif err |= __put_user((/*current->exec_domain && current->exec_domain->signal_invmap && sig < 32 ? current->exec_domain->signal_invmap[sig] : */ sig), &frame->sig); if (err) goto give_sigsegv; setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0]); if (err) goto give_sigsegv; if (TARGET_NSIG_WORDS > 1) { err |= __copy_to_user(frame->extramask, &set->sig[1], sizeof(frame->extramask)); } if (err) goto give_sigsegv; /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags & TARGET_SA_RESTORER) { err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); } else { err |= __put_user(frame->retcode, &frame->pretcode); /* This is popl %eax ; movl $,%eax ; int $0x80 */ err |= __put_user(0xb858, (short *)(frame->retcode+0)); err |= __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); err |= __put_user(0x80cd, (short *)(frame->retcode+6)); } if (err) goto give_sigsegv; /* Set up registers for signal handler */ env->regs[R_ESP] = (unsigned long) frame; env->eip = (unsigned long) ka->sa._sa_handler; cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); cpu_x86_load_seg(env, R_SS, __USER_DS); cpu_x86_load_seg(env, R_CS, __USER_CS); env->eflags &= ~TF_MASK; return; give_sigsegv: if (sig == TARGET_SIGSEGV) ka->sa._sa_handler = TARGET_SIG_DFL; force_sig(TARGET_SIGSEGV /* , current */); }


static void write_target_close(BlockDriverState *bs) { BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque); bdrv_delete(s->qcow); free(s->qcow_filename); }


static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[0]; AIFFInputContext *aiff = s->priv_data; int64_t max_size; int res, size; /* calculate size of remaining data */ max_size = aiff->data_end - avio_tell(s->pb); if (max_size <= 0) return AVERROR_EOF; /* Now for that packet */ switch (st->codecpar->codec_id) { case AV_CODEC_ID_ADPCM_IMA_QT: case AV_CODEC_ID_GSM: case AV_CODEC_ID_QDM2: case AV_CODEC_ID_QCELP: size = st->codecpar->block_align; break; default: size = st->codecpar->block_align ? (MAX_SIZE / st->codecpar->block_align) * st->codecpar->block_align : MAX_SIZE; size = FFMIN(max_size, size); res = av_get_packet(s->pb, pkt, size); if (res < 0) return res; if (size >= st->codecpar->block_align) pkt->flags &= ~AV_PKT_FLAG_CORRUPT; /* Only one stream in an AIFF file */ pkt->stream_index = 0; pkt->duration = (res / st->codecpar->block_align) * aiff->block_duration; return 0;


uint64_t helper_fnmsub (uint64_t arg1, uint64_t arg2, uint64_t arg3) { CPU_DoubleU farg1, farg2, farg3; farg1.ll = arg1; farg2.ll = arg2; farg3.ll = arg3; if (unlikely(float64_is_signaling_nan(farg1.d) || float64_is_signaling_nan(farg2.d) || float64_is_signaling_nan(farg3.d))) { /* sNaN operation */ farg1.ll = fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); } else if (unlikely((float64_is_infinity(farg1.d) && float64_is_zero(farg2.d)) || (float64_is_zero(farg1.d) && float64_is_infinity(farg2.d)))) { /* Multiplication of zero by infinity */ farg1.ll = fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ); } else { #if USE_PRECISE_EMULATION #ifdef FLOAT128 /* This is the way the PowerPC specification defines it */ float128 ft0_128, ft1_128; ft0_128 = float64_to_float128(farg1.d, &env->fp_status); ft1_128 = float64_to_float128(farg2.d, &env->fp_status); ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); if (unlikely(float128_is_infinity(ft0_128) && float64_is_infinity(farg3.d) && float128_is_neg(ft0_128) == float64_is_neg(farg3.d))) { /* Magnitude subtraction of infinities */ farg1.ll = fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI); } else { ft1_128 = float64_to_float128(farg3.d, &env->fp_status); ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status); farg1.d = float128_to_float64(ft0_128, &env->fp_status); } #else /* This is OK on x86 hosts */ farg1.d = (farg1.d * farg2.d) - farg3.d; #endif #else farg1.d = float64_mul(farg1.d, farg2.d, &env->fp_status); farg1.d = float64_sub(farg1.d, farg3.d, &env->fp_status); #endif if (likely(!float64_is_nan(farg1.d))) farg1.d = float64_chs(farg1.d); } return farg1.ll; }


static void dec_modu(DisasContext *dc) { int l1; LOG_DIS("modu r%d, r%d, %d\n", dc->r2, dc->r0, dc->r1); if (!(dc->features & LM32_FEATURE_DIVIDE)) { qemu_log_mask(LOG_GUEST_ERROR, "hardware divider is not available\n"); t_gen_illegal_insn(dc); return; } l1 = gen_new_label(); tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[dc->r1], 0, l1); tcg_gen_movi_tl(cpu_pc, dc->pc); t_gen_raise_exception(dc, EXCP_DIVIDE_BY_ZERO); gen_set_label(l1); tcg_gen_remu_tl(cpu_R[dc->r2], cpu_R[dc->r0], cpu_R[dc->r1]); }


static void omap_l4_io_writeb(void *opaque, target_phys_addr_t addr, uint32_t value) { unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS; return omap_l4_io_writeb_fn[i](omap_l4_io_opaque[i], addr, value); }


static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) { if (err == 0 || errno != ENOENT) { err = -errno; goto out; } if (vs->perm & P9_STAT_MODE_DIR) { err = v9fs_do_mkdir(s, vs); v9fs_create_post_mkdir(s, vs, err); } else if (vs->perm & P9_STAT_MODE_SYMLINK) { err = v9fs_do_symlink(s, vs); v9fs_create_post_perms(s, vs, err); } else if (vs->perm & P9_STAT_MODE_LINK) { int32_t nfid = atoi(vs->extension.data); V9fsFidState *nfidp = lookup_fid(s, nfid); if (nfidp == NULL) { err = -errno; v9fs_post_create(s, vs, err); } err = v9fs_do_link(s, &nfidp->path, &vs->fullname); v9fs_create_post_perms(s, vs, err); } else if (vs->perm & P9_STAT_MODE_DEVICE) { char ctype; uint32_t major, minor; mode_t nmode = 0; if (sscanf(vs->extension.data, "%c %u %u", &ctype, &major, &minor) != 3) { err = -errno; v9fs_post_create(s, vs, err); } switch (ctype) { case 'c': nmode = S_IFCHR; break; case 'b': nmode = S_IFBLK; break; default: err = -EIO; v9fs_post_create(s, vs, err); } nmode |= vs->perm & 0777; err = v9fs_do_mknod(s, vs, nmode, makedev(major, minor)); v9fs_create_post_perms(s, vs, err); } else if (vs->perm & P9_STAT_MODE_NAMED_PIPE) { err = v9fs_do_mknod(s, vs, S_IFIFO | (vs->perm & 0777), 0); v9fs_post_create(s, vs, err); } else if (vs->perm & P9_STAT_MODE_SOCKET) { err = v9fs_do_mksock(s, &vs->fullname); v9fs_create_post_mksock(s, vs, err); } else { vs->fidp->fd = v9fs_do_open2(s, vs); v9fs_create_post_open2(s, vs, err); } return; out: v9fs_post_create(s, vs, err); }


target_ulong spapr_rtas_call(sPAPREnvironment *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { if ((token >= TOKEN_BASE) && ((token - TOKEN_BASE) < TOKEN_MAX)) { struct rtas_call *call = rtas_table + (token - TOKEN_BASE); if (call->fn) { call->fn(spapr, token, nargs, args, nret, rets); return H_SUCCESS; } } /* HACK: Some Linux early debug code uses RTAS display-character, * but assumes the token value is 0xa (which it is on some real * machines) without looking it up in the device tree. This * special case makes this work */ if (token == 0xa) { rtas_display_character(spapr, 0xa, nargs, args, nret, rets); return H_SUCCESS; } hcall_dprintf("Unknown RTAS token 0x%x\n", token); rtas_st(rets, 0, -3); return H_PARAMETER; }


static void apply_tns_filter(float *out, float *in, int order, int direction, float *tns_coefs, int ltp_used, int w, int filt, int start_i, int len) { int i, j, inc, start = start_i; float tmp[TNS_MAX_ORDER+1]; if (direction) { inc = -1; start = (start + len) - 1; } else { inc = 1; } if (!ltp_used) { /* AR filter */ for (i = 0; i < len; i++, start += inc) out[i] = in[start]; for (j = 1; j <= FFMIN(i, order); j++) out[i] += tns_coefs[j]*in[start - j*inc]; } else { /* MA filter */ for (i = 0; i < len; i++, start += inc) { tmp[0] = out[i] = in[start]; for (j = 1; j <= FFMIN(i, order); j++) out[i] += tmp[j]*tns_coefs[j]; for (j = order; j > 0; j--) tmp[j] = tmp[j - 1]; } } }


static int mkv_write_ass_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; int i, layer = 0, max_duration = 0, size, line_size, data_size = pkt->size; uint8_t *start, *end, *data = pkt->data; ebml_master blockgroup; char buffer[2048]; while (data_size) { int duration = ass_get_duration(data); max_duration = FFMAX(duration, max_duration); end = memchr(data, '\n', data_size); size = line_size = end ? end - data + 1 : data_size; size -= end ? (end[-1] == '\r') + 1 : 0; start = data; for (i = 0; i < 3; i++, start++) if (!(start = memchr(start, ',', size - (start - data)))) return max_duration; size -= start - data; sscanf(data, "Dialogue: %d,", &layer); i = snprintf(buffer, sizeof(buffer), "%" PRId64 ",%d,", s->streams[pkt->stream_index]->nb_frames, layer); size = FFMIN(i + size, sizeof(buffer)); memcpy(buffer + i, start, size - i); av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " "pts %" PRId64 ", duration %d\n", avio_tell(pb), size, pkt->pts, duration); blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(size)); put_ebml_id(pb, MATROSKA_ID_BLOCK); put_ebml_num(pb, size + 4, 0); // this assumes stream_index is less than 126 avio_w8(pb, 0x80 | (pkt->stream_index + 1)); avio_wb16(pb, pkt->pts - mkv->cluster_pts); avio_w8(pb, 0); avio_write(pb, buffer, size); put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, duration); end_ebml_master(pb, blockgroup); data += line_size; data_size -= line_size; } return max_duration; }


static int ram_block_enable_notify(const char *block_name, void *host_addr, ram_addr_t offset, ram_addr_t length, void *opaque) { MigrationIncomingState *mis = opaque; struct uffdio_register reg_struct; reg_struct.range.start = (uintptr_t)host_addr; reg_struct.range.len = length; reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING; /* Now tell our userfault_fd that it's responsible for this area */ if (ioctl(mis->userfault_fd, UFFDIO_REGISTER, &reg_struct)) { error_report("%s userfault register: %s", __func__, strerror(errno)); return 0;


static void draw_bar_yuv(AVFrame *out, const float *h, const float *rcp_h, const ColorFloat *c, int bar_h) { int x, y, yh, w = out->width; float mul, ht, rcp_bar_h = 1.0f / bar_h; uint8_t *vy = out->data[0], *vu = out->data[1], *vv = out->data[2]; uint8_t *lpy, *lpu, *lpv; int lsy = out->linesize[0], lsu = out->linesize[1], lsv = out->linesize[2]; int fmt = out->format; for (y = 0; y < bar_h; y += 2) { yh = (fmt == AV_PIX_FMT_YUV420P) ? y / 2 : y; ht = (bar_h - y) * rcp_bar_h; lpy = vy + y * lsy; lpu = vu + yh * lsu; lpv = vv + yh * lsv; for (x = 0; x < w; x += 2) { if (h[x] <= ht) { *lpy++ = 16; *lpu++ = 128; *lpv++ = 128; } else { mul = (h[x] - ht) * rcp_h[x]; *lpy++ = mul * c[x].yuv.y + (1.0f - mul) * 16.0f + 0.5f; *lpu++ = mul * c[x].yuv.u + (1.0f - mul) * 128.0f + 0.5f; *lpv++ = mul * c[x].yuv.v + (1.0f - mul) * 128.0f + 0.5f; } /* u and v are skipped on yuv422p and yuv420p */ if (fmt == AV_PIX_FMT_YUV444P) { if (h[x+1] <= ht) { *lpy++ = 16; *lpu++ = 128; *lpv++ = 128; } else { mul = (h[x+1] - ht) * rcp_h[x+1]; *lpy++ = mul * c[x+1].yuv.y + (1.0f - mul) * 16.0f + 0.5f; *lpu++ = mul * c[x+1].yuv.u + (1.0f - mul) * 128.0f + 0.5f; *lpv++ = mul * c[x+1].yuv.v + (1.0f - mul) * 128.0f + 0.5f; } } else { if (h[x+1] <= ht) { *lpy++ = 16; } else { mul = (h[x+1] - ht) * rcp_h[x+1]; *lpy++ = mul * c[x+1].yuv.y + (1.0f - mul) * 16.0f + 0.5f; } } } ht = (bar_h - (y+1)) * rcp_bar_h; lpy = vy + (y+1) * lsy; lpu = vu + (y+1) * lsu; lpv = vv + (y+1) * lsv; for (x = 0; x < w; x += 2) { /* u and v are skipped on yuv420p */ if (fmt != AV_PIX_FMT_YUV420P) { if (h[x] <= ht) { *lpy++ = 16; *lpu++ = 128; *lpv++ = 128; } else { mul = (h[x] - ht) * rcp_h[x]; *lpy++ = mul * c[x].yuv.y + (1.0f - mul) * 16.0f + 0.5f; *lpu++ = mul * c[x].yuv.u + (1.0f - mul) * 128.0f + 0.5f; *lpv++ = mul * c[x].yuv.v + (1.0f - mul) * 128.0f + 0.5f; } } else { if (h[x] <= ht) { *lpy++ = 16; } else { mul = (h[x] - ht) * rcp_h[x]; *lpy++ = mul * c[x].yuv.y + (1.0f - mul) * 16.0f + 0.5f; } } /* u and v are skipped on yuv422p and yuv420p */ if (out->format == AV_PIX_FMT_YUV444P) { if (h[x+1] <= ht) { *lpy++ = 16; *lpu++ = 128; *lpv++ = 128; } else { mul = (h[x+1] - ht) * rcp_h[x+1]; *lpy++ = mul * c[x+1].yuv.y + (1.0f - mul) * 16.0f + 0.5f; *lpu++ = mul * c[x+1].yuv.u + (1.0f - mul) * 128.0f + 0.5f; *lpv++ = mul * c[x+1].yuv.v + (1.0f - mul) * 128.0f + 0.5f; } } else { if (h[x+1] <= ht) { *lpy++ = 16; } else { mul = (h[x+1] - ht) * rcp_h[x+1]; *lpy++ = mul * c[x+1].yuv.y + (1.0f - mul) * 16.0f + 0.5f; } } } } }


static int qemu_chr_open_win_file_out(QemuOpts *opts, CharDriverState **_chr) { const char *file_out = qemu_opt_get(opts, "path"); HANDLE fd_out; fd_out = CreateFile(file_out, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (fd_out == INVALID_HANDLE_VALUE) { return -EIO; } return qemu_chr_open_win_file(fd_out, _chr); }


int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl) { int i, len; if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { H264Picture *sorted[32]; int cur_poc, list; int lens[2]; if (FIELD_PICTURE(h)) cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; else cur_poc = h->cur_pic_ptr->poc; for (list = 0; list < 2; list++) { len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list); len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list); av_assert0(len <= 32); len = build_def_list(h->default_ref_list[list], FF_ARRAY_ELEMS(h->default_ref_list[0]), sorted, len, 0, h->picture_structure); len += build_def_list(h->default_ref_list[list] + len, FF_ARRAY_ELEMS(h->default_ref_list[0]) - len, h->long_ref, 16, 1, h->picture_structure); av_assert0(len <= 32); if (len < sl->ref_count[list]) memset(&h->default_ref_list[list][len], 0, sizeof(H264Ref) * (sl->ref_count[list] - len)); lens[list] = len; } if (lens[0] == lens[1] && lens[1] > 1) { for (i = 0; i < lens[0] && h->default_ref_list[0][i].parent->f.buf[0]->buffer == h->default_ref_list[1][i].parent->f.buf[0]->buffer; i++); if (i == lens[0]) { FFSWAP(H264Ref, h->default_ref_list[1][0], h->default_ref_list[1][1]); } } } else { len = build_def_list(h->default_ref_list[0], FF_ARRAY_ELEMS(h->default_ref_list[0]), h->short_ref, h->short_ref_count, 0, h->picture_structure); len += build_def_list(h->default_ref_list[0] + len, FF_ARRAY_ELEMS(h->default_ref_list[0]) - len, h-> long_ref, 16, 1, h->picture_structure); av_assert0(len <= 32); if (len < sl->ref_count[0]) memset(&h->default_ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len)); } #ifdef TRACE for (i = 0; i < sl->ref_count[0]; i++) { tprintf(h->avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].parent->long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].parent->f.data[0]); } if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { for (i = 0; i < sl->ref_count[1]; i++) { tprintf(h->avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].parent->long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].parent->f.data[0]); } } #endif return 0; }


static void vtd_init(IntelIOMMUState *s) { X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s); memset(s->csr, 0, DMAR_REG_SIZE); memset(s->wmask, 0, DMAR_REG_SIZE); memset(s->w1cmask, 0, DMAR_REG_SIZE); memset(s->womask, 0, DMAR_REG_SIZE); s->iommu_ops.translate = vtd_iommu_translate; s->iommu_ops.notify_started = vtd_iommu_notify_started; s->root = 0; s->root_extended = false; s->dmar_enabled = false; s->iq_head = 0; s->iq_tail = 0; s->iq = 0; s->iq_size = 0; s->qi_enabled = false; s->iq_last_desc_type = VTD_INV_DESC_NONE; s->next_frcd_reg = 0; s->cap = VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | VTD_CAP_MGAW | VTD_CAP_SAGAW | VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS; s->ecap = VTD_ECAP_QI | VTD_ECAP_IRO; if (x86_iommu->intr_supported) { s->ecap |= VTD_ECAP_IR | VTD_ECAP_EIM; } vtd_reset_context_cache(s); vtd_reset_iotlb(s); /* Define registers with default values and bit semantics */ vtd_define_long(s, DMAR_VER_REG, 0x10UL, 0, 0); vtd_define_quad(s, DMAR_CAP_REG, s->cap, 0, 0); vtd_define_quad(s, DMAR_ECAP_REG, s->ecap, 0, 0); vtd_define_long(s, DMAR_GCMD_REG, 0, 0xff800000UL, 0); vtd_define_long_wo(s, DMAR_GCMD_REG, 0xff800000UL); vtd_define_long(s, DMAR_GSTS_REG, 0, 0, 0); vtd_define_quad(s, DMAR_RTADDR_REG, 0, 0xfffffffffffff000ULL, 0); vtd_define_quad(s, DMAR_CCMD_REG, 0, 0xe0000003ffffffffULL, 0); vtd_define_quad_wo(s, DMAR_CCMD_REG, 0x3ffff0000ULL); /* Advanced Fault Logging not supported */ vtd_define_long(s, DMAR_FSTS_REG, 0, 0, 0x11UL); vtd_define_long(s, DMAR_FECTL_REG, 0x80000000UL, 0x80000000UL, 0); vtd_define_long(s, DMAR_FEDATA_REG, 0, 0x0000ffffUL, 0); vtd_define_long(s, DMAR_FEADDR_REG, 0, 0xfffffffcUL, 0); /* Treated as RsvdZ when EIM in ECAP_REG is not supported * vtd_define_long(s, DMAR_FEUADDR_REG, 0, 0xffffffffUL, 0); */ vtd_define_long(s, DMAR_FEUADDR_REG, 0, 0, 0); /* Treated as RO for implementations that PLMR and PHMR fields reported * as Clear in the CAP_REG. * vtd_define_long(s, DMAR_PMEN_REG, 0, 0x80000000UL, 0); */ vtd_define_long(s, DMAR_PMEN_REG, 0, 0, 0); vtd_define_quad(s, DMAR_IQH_REG, 0, 0, 0); vtd_define_quad(s, DMAR_IQT_REG, 0, 0x7fff0ULL, 0); vtd_define_quad(s, DMAR_IQA_REG, 0, 0xfffffffffffff007ULL, 0); vtd_define_long(s, DMAR_ICS_REG, 0, 0, 0x1UL); vtd_define_long(s, DMAR_IECTL_REG, 0x80000000UL, 0x80000000UL, 0); vtd_define_long(s, DMAR_IEDATA_REG, 0, 0xffffffffUL, 0); vtd_define_long(s, DMAR_IEADDR_REG, 0, 0xfffffffcUL, 0); /* Treadted as RsvdZ when EIM in ECAP_REG is not supported */ vtd_define_long(s, DMAR_IEUADDR_REG, 0, 0, 0); /* IOTLB registers */ vtd_define_quad(s, DMAR_IOTLB_REG, 0, 0Xb003ffff00000000ULL, 0); vtd_define_quad(s, DMAR_IVA_REG, 0, 0xfffffffffffff07fULL, 0); vtd_define_quad_wo(s, DMAR_IVA_REG, 0xfffffffffffff07fULL); /* Fault Recording Registers, 128-bit */ vtd_define_quad(s, DMAR_FRCD_REG_0_0, 0, 0, 0); vtd_define_quad(s, DMAR_FRCD_REG_0_2, 0, 0, 0x8000000000000000ULL); /* * Interrupt remapping registers. */ vtd_define_quad(s, DMAR_IRTA_REG, 0, 0xfffffffffffff80fULL, 0); }


const uint8_t *ff_h263_find_resync_marker(const uint8_t *av_restrict p, const uint8_t *av_restrict end) { av_assert2(p < end); end-=2; p++; for(;p<end; p+=2){ if(!*p){ if (!p[-1] && p[1]) return p - 1; else if(!p[ 1] && p[2]) return p; } } return end+2; }


void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t reg) { switch(reg) { case 25: if (arg1 & 0xffffff00) return; env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0x017fffff) | ((arg1 & 0xfe) << 24) | ((arg1 & 0x1) << 23); break; case 26: if (arg1 & 0x007c0000) return; env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfffc0f83) | (arg1 & 0x0003f07c); break; case 28: if (arg1 & 0x007c0000) return; env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfefff07c) | (arg1 & 0x00000f83) | ((arg1 & 0x4) << 22); break; case 31: if (arg1 & 0x007c0000) return; env->active_fpu.fcr31 = arg1; break; default: return; } /* set rounding mode */ restore_rounding_mode(env); /* set flush-to-zero mode */ restore_flush_mode(env); set_float_exception_flags(0, &env->active_fpu.fp_status); if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) & GET_FP_CAUSE(env->active_fpu.fcr31)) do_raise_exception(env, EXCP_FPE, GETPC()); }


static void cpu_set_irq(void *opaque, int irq, int level) { CPUState *env = opaque; if (level) { CPUIRQ_DPRINTF("Raise CPU IRQ %d\n", irq); env->halted = 0; env->pil_in |= 1 << irq; cpu_check_irqs(env); } else { CPUIRQ_DPRINTF("Lower CPU IRQ %d\n", irq); env->pil_in &= ~(1 << irq); cpu_check_irqs(env); } }


static int get_stream_blocksize(BlockDriverState *bdrv) { uint8_t cmd[6]; uint8_t buf[12]; uint8_t sensebuf[8]; sg_io_hdr_t io_header; int ret; memset(cmd, 0, sizeof(cmd)); memset(buf, 0, sizeof(buf)); cmd[0] = MODE_SENSE; cmd[4] = sizeof(buf); memset(&io_header, 0, sizeof(io_header)); io_header.interface_id = 'S'; io_header.dxfer_direction = SG_DXFER_FROM_DEV; io_header.dxfer_len = sizeof(buf); io_header.dxferp = buf; io_header.cmdp = cmd; io_header.cmd_len = sizeof(cmd); io_header.mx_sb_len = sizeof(sensebuf); io_header.sbp = sensebuf; io_header.timeout = 6000; /* XXX */ ret = bdrv_ioctl(bdrv, SG_IO, &io_header); if (ret < 0 || io_header.driver_status || io_header.host_status) { return -1; } return (buf[9] << 16) | (buf[10] << 8) | buf[11]; }


int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset, int64_t size) { int ret = qcow2_check_metadata_overlap(bs, ign, offset, size); if (ret < 0) { return ret; } else if (ret > 0) { int metadata_ol_bitnr = ffs(ret) - 1; assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR); qcow2_signal_corruption(bs, true, offset, size, "Preventing invalid " "write on metadata (overlaps with %s)", metadata_ol_names[metadata_ol_bitnr]); return -EIO; } return 0; }


int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) { int i, ret; Picture *pic; s->mb_skipped = 0; if (!ff_thread_can_start_frame(avctx)) { av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); return -1; } /* mark & release old frames */ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->f.buf[0]) { ff_mpeg_unref_picture(s, s->last_picture_ptr); } /* release forgotten pictures */ /* if (mpeg124/h263) */ for (i = 0; i < MAX_PICTURE_COUNT; i++) { if (&s->picture[i] != s->last_picture_ptr && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference && !s->picture[i].needs_realloc) { if (!(avctx->active_thread_type & FF_THREAD_FRAME)) av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n"); ff_mpeg_unref_picture(s, &s->picture[i]); } } ff_mpeg_unref_picture(s, &s->current_picture); release_unused_pictures(s); if (s->current_picture_ptr && s->current_picture_ptr->f.buf[0] == NULL) { // we already have a unused image // (maybe it was set before reading the header) pic = s->current_picture_ptr; } else { i = ff_find_unused_picture(s, 0); if (i < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return i; } pic = &s->picture[i]; } pic->reference = 0; if (!s->droppable) { if (s->pict_type != AV_PICTURE_TYPE_B) pic->reference = 3; } pic->f.coded_picture_number = s->coded_picture_number++; if (ff_alloc_picture(s, pic, 0) < 0) return -1; s->current_picture_ptr = pic; // FIXME use only the vars from current_pic s->current_picture_ptr->f.top_field_first = s->top_field_first; if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { if (s->picture_structure != PICT_FRAME) s->current_picture_ptr->f.top_field_first = (s->picture_structure == PICT_TOP_FIELD) == s->first_field; } s->current_picture_ptr->f.interlaced_frame = !s->progressive_frame && !s->progressive_sequence; s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME; s->current_picture_ptr->f.pict_type = s->pict_type; // if (s->flags && CODEC_FLAG_QSCALE) // s->current_picture_ptr->quality = s->new_picture_ptr->quality; s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; if ((ret = ff_mpeg_ref_picture(s, &s->current_picture, s->current_picture_ptr)) < 0) return ret; if (s->pict_type != AV_PICTURE_TYPE_B) { s->last_picture_ptr = s->next_picture_ptr; if (!s->droppable) s->next_picture_ptr = s->current_picture_ptr; } av_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr, s->last_picture_ptr ? s->last_picture_ptr->f.data[0] : NULL, s->next_picture_ptr ? s->next_picture_ptr->f.data[0] : NULL, s->current_picture_ptr ? s->current_picture_ptr->f.data[0] : NULL, s->pict_type, s->droppable); if ((s->last_picture_ptr == NULL || s->last_picture_ptr->f.buf[0] == NULL) && (s->pict_type != AV_PICTURE_TYPE_I || s->picture_structure != PICT_FRAME)) { int h_chroma_shift, v_chroma_shift; av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f.buf[0]) av_log(avctx, AV_LOG_DEBUG, "allocating dummy last picture for B frame\n"); else if (s->pict_type != AV_PICTURE_TYPE_I) av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); else if (s->picture_structure != PICT_FRAME) av_log(avctx, AV_LOG_DEBUG, "allocate dummy last picture for field based first keyframe\n"); /* Allocate a dummy frame */ i = ff_find_unused_picture(s, 0); if (i < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return i; } s->last_picture_ptr = &s->picture[i]; s->last_picture_ptr->reference = 3; s->last_picture_ptr->f.key_frame = 0; s->last_picture_ptr->f.pict_type = AV_PICTURE_TYPE_P; if (ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) { s->last_picture_ptr = NULL; return -1; } memset(s->last_picture_ptr->f.data[0], 0x80, avctx->height * s->last_picture_ptr->f.linesize[0]); memset(s->last_picture_ptr->f.data[1], 0x80, (avctx->height >> v_chroma_shift) * s->last_picture_ptr->f.linesize[1]); memset(s->last_picture_ptr->f.data[2], 0x80, (avctx->height >> v_chroma_shift) * s->last_picture_ptr->f.linesize[2]); if(s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263){ for(i=0; i<avctx->height; i++) memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width); } ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1); } if ((s->next_picture_ptr == NULL || s->next_picture_ptr->f.buf[0] == NULL) && s->pict_type == AV_PICTURE_TYPE_B) { /* Allocate a dummy frame */ i = ff_find_unused_picture(s, 0); if (i < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return i; } s->next_picture_ptr = &s->picture[i]; s->next_picture_ptr->reference = 3; s->next_picture_ptr->f.key_frame = 0; s->next_picture_ptr->f.pict_type = AV_PICTURE_TYPE_P; if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) { s->next_picture_ptr = NULL; return -1; } ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1); } #if 0 // BUFREF-FIXME memset(s->last_picture.f.data, 0, sizeof(s->last_picture.f.data)); memset(s->next_picture.f.data, 0, sizeof(s->next_picture.f.data)); #endif if (s->last_picture_ptr) { ff_mpeg_unref_picture(s, &s->last_picture); if (s->last_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->last_picture, s->last_picture_ptr)) < 0) return ret; } if (s->next_picture_ptr) { ff_mpeg_unref_picture(s, &s->next_picture); if (s->next_picture_ptr->f.buf[0] && (ret = ff_mpeg_ref_picture(s, &s->next_picture, s->next_picture_ptr)) < 0) return ret; } av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && s->last_picture_ptr->f.buf[0])); if (s->picture_structure!= PICT_FRAME) { int i; for (i = 0; i < 4; i++) { if (s->picture_structure == PICT_BOTTOM_FIELD) { s->current_picture.f.data[i] += s->current_picture.f.linesize[i]; } s->current_picture.f.linesize[i] *= 2; s->last_picture.f.linesize[i] *= 2; s->next_picture.f.linesize[i] *= 2; } } s->err_recognition = avctx->err_recognition; /* set dequantizer, we can't do it during init as * it might change for mpeg4 and we can't do it in the header * decode as init is not called for mpeg4 there yet */ if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { s->dct_unquantize_intra = s->dct_unquantize_h263_intra; s->dct_unquantize_inter = s->dct_unquantize_h263_inter; } else { s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; } return 0; }


static void co_write_request(void *opaque) { BDRVSheepdogState *s = opaque; qemu_coroutine_enter(s->co_send, NULL); }


static int decode_frame_ilbm(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { IffContext *s = avctx->priv_data; const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL; const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0; const uint8_t *buf_end = buf+buf_size; int y, plane, res; if ((res = extract_header(avctx, avpkt)) < 0) return res; if (s->init) { if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return res; } } else if ((res = avctx->get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } else if (avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != PIX_FMT_GRAY8) { if ((res = ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0) return res; } s->init = 1; if (avctx->codec_tag == MKTAG('A','C','B','M')) { if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { memset(s->frame.data[0], 0, avctx->height * s->frame.linesize[0]); for (plane = 0; plane < s->bpp; plane++) { for(y = 0; y < avctx->height && buf < buf_end; y++ ) { uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane); buf += s->planesize; } } } else if (s->ham) { // HAM to PIX_FMT_BGR32 memset(s->frame.data[0], 0, avctx->height * s->frame.linesize[0]); for(y = 0; y < avctx->height; y++) { uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; memset(s->ham_buf, 0, s->planesize * 8); for (plane = 0; plane < s->bpp; plane++) { const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize; if (start >= buf_end) break; decodeplane8(s->ham_buf, start, FFMIN(s->planesize, buf_end - start), plane); } decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); } } } else if (avctx->codec_tag == MKTAG('D','E','E','P')) { int raw_width = avctx->width * (av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]) >> 3); int x; for(y = 0; y < avctx->height && buf < buf_end; y++ ) { uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; memcpy(row, buf, FFMIN(raw_width, buf_end - buf)); buf += raw_width; if (avctx->pix_fmt == PIX_FMT_BGR32) { for(x = 0; x < avctx->width; x++) row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4); } } } else if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { for(y = 0; y < avctx->height; y++ ) { uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; memset(row, 0, avctx->width); for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane); buf += s->planesize; } } } else if (s->ham) { // HAM to PIX_FMT_BGR32 for (y = 0; y < avctx->height; y++) { uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; memset(s->ham_buf, 0, s->planesize * 8); for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), plane); buf += s->planesize; } decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); } } else { // PIX_FMT_BGR32 for(y = 0; y < avctx->height; y++ ) { uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; memset(row, 0, avctx->width << 2); for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { decodeplane32((uint32_t *) row, buf, FFMIN(s->planesize, buf_end - buf), plane); buf += s->planesize; } } } } else if (avctx->codec_tag == MKTAG('P','B','M',' ')) { // IFF-PBM if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { for(y = 0; y < avctx->height; y++ ) { uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; memcpy(row, buf, FFMIN(avctx->width, buf_end - buf)); buf += avctx->width + (avctx->width % 2); // padding if odd } } else if (s->ham) { // IFF-PBM: HAM to PIX_FMT_BGR32 for (y = 0; y < avctx->height; y++) { uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf)); buf += avctx->width + (avctx->width & 1); // padding if odd decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); } } else { av_log_ask_for_sample(avctx, "unsupported bpp\n"); return AVERROR_INVALIDDATA; } } *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; return buf_size; }


udp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags) { struct sockaddr_in addr; struct socket *so; socklen_t addrlen = sizeof(struct sockaddr_in), opt = 1; so = socreate(slirp); if (!so) { return NULL; } so->s = socket(AF_INET,SOCK_DGRAM,0); so->so_expire = curtime + SO_EXPIRE; insque(so, &slirp->udb); addr.sin_family = AF_INET; addr.sin_addr.s_addr = haddr; addr.sin_port = hport; if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) { udp_detach(so); return NULL; } setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); getsockname(so->s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port; if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) { so->so_faddr = slirp->vhost_addr; } else { so->so_faddr = addr.sin_addr; } so->so_lport = lport; so->so_laddr.s_addr = laddr; if (flags != SS_FACCEPTONCE) so->so_expire = 0; so->so_state &= SS_PERSISTENT_MASK; so->so_state |= SS_ISFCONNECTED | flags; return so; }


static uint32_t grlib_irqmp_readl(void *opaque, target_phys_addr_t addr) { IRQMP *irqmp = opaque; IRQMPState *state; assert(irqmp != NULL); state = irqmp->state; assert(state != NULL); addr &= 0xff; /* global registers */ switch (addr) { case LEVEL_OFFSET: return state->level; case PENDING_OFFSET: return state->pending; case FORCE0_OFFSET: /* This register is an "alias" for the force register of CPU 0 */ return state->force[0]; case CLEAR_OFFSET: case MP_STATUS_OFFSET: /* Always read as 0 */ return 0; case BROADCAST_OFFSET: return state->broadcast; default: break; } /* mask registers */ if (addr >= MASK_OFFSET && addr < FORCE_OFFSET) { int cpu = (addr - MASK_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->mask[cpu]; } /* force registers */ if (addr >= FORCE_OFFSET && addr < EXTENDED_OFFSET) { int cpu = (addr - FORCE_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->force[cpu]; } /* extended (not supported) */ if (addr >= EXTENDED_OFFSET && addr < IRQMP_REG_SIZE) { int cpu = (addr - EXTENDED_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->extended[cpu]; } trace_grlib_irqmp_unknown_register("read", addr); return 0; }


void qemu_sglist_destroy(QEMUSGList *qsg) { g_free(qsg->sg); }


static int virtio_9p_device_init(VirtIODevice *vdev) { V9fsState *s = VIRTIO_9P(vdev); int i, len; struct stat stat; FsDriverEntry *fse; V9fsPath path; virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P, sizeof(struct virtio_9p_config) + MAX_TAG_LEN); /* initialize pdu allocator */ QLIST_INIT(&s->free_list); QLIST_INIT(&s->active_list); for (i = 0; i < (MAX_REQ - 1); i++) { QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next); } s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output); fse = get_fsdev_fsentry(s->fsconf.fsdev_id); if (!fse) { /* We don't have a fsdev identified by fsdev_id */ fprintf(stderr, "Virtio-9p device couldn't find fsdev with the " "id = %s\n", s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL"); goto out; } if (!s->fsconf.tag) { /* we haven't specified a mount_tag */ fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n", s->fsconf.fsdev_id); goto out; } s->ctx.export_flags = fse->export_flags; s->ctx.fs_root = g_strdup(fse->path); s->ctx.exops.get_st_gen = NULL; len = strlen(s->fsconf.tag); if (len > MAX_TAG_LEN - 1) { fprintf(stderr, "mount tag '%s' (%d bytes) is longer than " "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1); goto out; } s->tag = g_strdup(s->fsconf.tag); s->ctx.uid = -1; s->ops = fse->ops; s->config_size = sizeof(struct virtio_9p_config) + len; s->fid_list = NULL; qemu_co_rwlock_init(&s->rename_lock); if (s->ops->init(&s->ctx) < 0) { fprintf(stderr, "Virtio-9p Failed to initialize fs-driver with id:%s" " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.fs_root); goto out; } if (v9fs_init_worker_threads() < 0) { fprintf(stderr, "worker thread initialization failed\n"); goto out; } /* * Check details of export path, We need to use fs driver * call back to do that. Since we are in the init path, we don't * use co-routines here. */ v9fs_path_init(&path); if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) { fprintf(stderr, "error in converting name to path %s", strerror(errno)); goto out; } if (s->ops->lstat(&s->ctx, &path, &stat)) { fprintf(stderr, "share path %s does not exist\n", fse->path); goto out; } else if (!S_ISDIR(stat.st_mode)) { fprintf(stderr, "share path %s is not a directory\n", fse->path); goto out; } v9fs_path_free(&path); return 0; out: g_free(s->ctx.fs_root); g_free(s->tag); virtio_cleanup(vdev); v9fs_path_free(&path); return -1; }


static int v9fs_request(V9fsProxy *proxy, int type, void *response, const char *fmt, ...) { dev_t rdev; va_list ap; int size = 0; int retval = 0; uint64_t offset; ProxyHeader header = { 0, 0}; struct timespec spec[2]; int flags, mode, uid, gid; V9fsString *name, *value; V9fsString *path, *oldpath; struct iovec *iovec = NULL, *reply = NULL; qemu_mutex_lock(&proxy->mutex); if (proxy->sockfd == -1) { retval = -EIO; goto err_out; } iovec = &proxy->out_iovec; reply = &proxy->in_iovec; va_start(ap, fmt); switch (type) { case T_OPEN: path = va_arg(ap, V9fsString *); flags = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, flags); if (retval > 0) { header.size = retval; header.type = T_OPEN; } break; case T_CREATE: path = va_arg(ap, V9fsString *); flags = va_arg(ap, int); mode = va_arg(ap, int); uid = va_arg(ap, int); gid = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sdddd", path, flags, mode, uid, gid); if (retval > 0) { header.size = retval; header.type = T_CREATE; } break; case T_MKNOD: path = va_arg(ap, V9fsString *); mode = va_arg(ap, int); rdev = va_arg(ap, long int); uid = va_arg(ap, int); gid = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddsdq", uid, gid, path, mode, rdev); if (retval > 0) { header.size = retval; header.type = T_MKNOD; } break; case T_MKDIR: path = va_arg(ap, V9fsString *); mode = va_arg(ap, int); uid = va_arg(ap, int); gid = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddsd", uid, gid, path, mode); if (retval > 0) { header.size = retval; header.type = T_MKDIR; } break; case T_SYMLINK: oldpath = va_arg(ap, V9fsString *); path = va_arg(ap, V9fsString *); uid = va_arg(ap, int); gid = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddss", uid, gid, oldpath, path); if (retval > 0) { header.size = retval; header.type = T_SYMLINK; } break; case T_LINK: oldpath = va_arg(ap, V9fsString *); path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", oldpath, path); if (retval > 0) { header.size = retval; header.type = T_LINK; } break; case T_LSTAT: path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); if (retval > 0) { header.size = retval; header.type = T_LSTAT; } break; case T_READLINK: path = va_arg(ap, V9fsString *); size = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, size); if (retval > 0) { header.size = retval; header.type = T_READLINK; } break; case T_STATFS: path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); if (retval > 0) { header.size = retval; header.type = T_STATFS; } break; case T_CHMOD: path = va_arg(ap, V9fsString *); mode = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, mode); if (retval > 0) { header.size = retval; header.type = T_CHMOD; } break; case T_CHOWN: path = va_arg(ap, V9fsString *); uid = va_arg(ap, int); gid = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sdd", path, uid, gid); if (retval > 0) { header.size = retval; header.type = T_CHOWN; } break; case T_TRUNCATE: path = va_arg(ap, V9fsString *); offset = va_arg(ap, uint64_t); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sq", path, offset); if (retval > 0) { header.size = retval; header.type = T_TRUNCATE; } break; case T_UTIME: path = va_arg(ap, V9fsString *); spec[0].tv_sec = va_arg(ap, long); spec[0].tv_nsec = va_arg(ap, long); spec[1].tv_sec = va_arg(ap, long); spec[1].tv_nsec = va_arg(ap, long); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sqqqq", path, spec[0].tv_sec, spec[1].tv_nsec, spec[1].tv_sec, spec[1].tv_nsec); if (retval > 0) { header.size = retval; header.type = T_UTIME; } break; case T_RENAME: oldpath = va_arg(ap, V9fsString *); path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", oldpath, path); if (retval > 0) { header.size = retval; header.type = T_RENAME; } break; case T_REMOVE: path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); if (retval > 0) { header.size = retval; header.type = T_REMOVE; } break; case T_LGETXATTR: size = va_arg(ap, int); path = va_arg(ap, V9fsString *); name = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "dss", size, path, name); if (retval > 0) { header.size = retval; header.type = T_LGETXATTR; } break; case T_LLISTXATTR: size = va_arg(ap, int); path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ds", size, path); if (retval > 0) { header.size = retval; header.type = T_LLISTXATTR; } break; case T_LSETXATTR: path = va_arg(ap, V9fsString *); name = va_arg(ap, V9fsString *); value = va_arg(ap, V9fsString *); size = va_arg(ap, int); flags = va_arg(ap, int); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sssdd", path, name, value, size, flags); if (retval > 0) { header.size = retval; header.type = T_LSETXATTR; } break; case T_LREMOVEXATTR: path = va_arg(ap, V9fsString *); name = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", path, name); if (retval > 0) { header.size = retval; header.type = T_LREMOVEXATTR; } break; case T_GETVERSION: path = va_arg(ap, V9fsString *); retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); if (retval > 0) { header.size = retval; header.type = T_GETVERSION; } break; default: error_report("Invalid type %d", type); retval = -EINVAL; break; } va_end(ap); if (retval < 0) { goto err_out; } /* marshal the header details */ proxy_marshal(iovec, 0, "dd", header.type, header.size); header.size += PROXY_HDR_SZ; retval = qemu_write_full(proxy->sockfd, iovec->iov_base, header.size); if (retval != header.size) { goto close_error; } switch (type) { case T_OPEN: case T_CREATE: /* * A file descriptor is returned as response for * T_OPEN,T_CREATE on success */ if (v9fs_receivefd(proxy->sockfd, &retval) < 0) { goto close_error; } break; case T_MKNOD: case T_MKDIR: case T_SYMLINK: case T_LINK: case T_CHMOD: case T_CHOWN: case T_RENAME: case T_TRUNCATE: case T_UTIME: case T_REMOVE: case T_LSETXATTR: case T_LREMOVEXATTR: if (v9fs_receive_status(proxy, reply, &retval) < 0) { goto close_error; } break; case T_LSTAT: case T_READLINK: case T_STATFS: case T_GETVERSION: if (v9fs_receive_response(proxy, type, &retval, response) < 0) { goto close_error; } break; case T_LGETXATTR: case T_LLISTXATTR: if (!size) { if (v9fs_receive_status(proxy, reply, &retval) < 0) { goto close_error; } } else { if (v9fs_receive_response(proxy, type, &retval, response) < 0) { goto close_error; } } break; } err_out: qemu_mutex_unlock(&proxy->mutex); return retval; close_error: close(proxy->sockfd); proxy->sockfd = -1; qemu_mutex_unlock(&proxy->mutex); return -EIO; }


static void scsi_req_set_status(SCSIDiskReq *r, int status, int sense_code) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); r->req.status = status; scsi_disk_set_sense(s, sense_code); }


static inline void sdhci_blkgap_write(SDHCIState *s, uint8_t value) { if ((value & SDHC_STOP_AT_GAP_REQ) && (s->blkgap & SDHC_STOP_AT_GAP_REQ)) { return; } s->blkgap = value & SDHC_STOP_AT_GAP_REQ; if ((value & SDHC_CONTINUE_REQ) && s->stopped_state && (s->blkgap & SDHC_STOP_AT_GAP_REQ) == 0) { if (s->stopped_state == sdhc_gap_read) { s->prnsts |= SDHC_DAT_LINE_ACTIVE | SDHC_DOING_READ; SDHCI_GET_CLASS(s)->read_block_from_card(s); } else { s->prnsts |= SDHC_DAT_LINE_ACTIVE | SDHC_DOING_WRITE; SDHCI_GET_CLASS(s)->write_block_to_card(s); } s->stopped_state = sdhc_not_stopped; } else if (!s->stopped_state && (value & SDHC_STOP_AT_GAP_REQ)) { if (s->prnsts & SDHC_DOING_READ) { s->stopped_state = sdhc_gap_read; } else if (s->prnsts & SDHC_DOING_WRITE) { s->stopped_state = sdhc_gap_write; } } }


static void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp) { int val; backend->vc = g_new0(ChardevVC, 1); val = qemu_opt_get_number(opts, "width", 0); if (val != 0) { backend->vc->has_width = true; backend->vc->width = val; } val = qemu_opt_get_number(opts, "height", 0); if (val != 0) { backend->vc->has_height = true; backend->vc->height = val; } val = qemu_opt_get_number(opts, "cols", 0); if (val != 0) { backend->vc->has_cols = true; backend->vc->cols = val; } val = qemu_opt_get_number(opts, "rows", 0); if (val != 0) { backend->vc->has_rows = true; backend->vc->rows = val; } }


static unsigned int find_best(struct vf_instance *vf){ int is_format_okay = vf->next->query_format(vf->next, IMGFMT_YV12); if ((is_format_okay & VFCAP_CSP_SUPPORTED_BY_HW) || (is_format_okay & VFCAP_CSP_SUPPORTED)) return IMGFMT_YV12; else return 0; }


void helper_idivl_EAX_T0(void) { int den, q, r; int64_t num; num = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32); den = T0; if (den == 0) { raise_exception(EXCP00_DIVZ); } #ifdef BUGGY_GCC_DIV64 r = idiv32(&q, num, den); #else q = (num / den); r = (num % den); #endif EAX = (uint32_t)q; EDX = (uint32_t)r; }


static int fourxm_probe(AVProbeData *p) { if (p->buf_size < 12) return 0; if ((AV_RL32(&p->buf[0]) != RIFF_TAG) || (AV_RL32(&p->buf[8]) != _4XMV_TAG)) return 0; return AVPROBE_SCORE_MAX; }


static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, ScanTable *intra_scantable, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], int hsample[3]) { int i, j, size; uint8_t *ptr; MpegEncContext *s = avctx->priv_data; if (avctx->codec_id != AV_CODEC_ID_LJPEG) { int matrix_count = 1 + !!memcmp(luma_intra_matrix, chroma_intra_matrix, sizeof(luma_intra_matrix[0]) * 64); if (s->force_duplicated_matrix) matrix_count = 2; /* quant matrixes */ put_marker(p, DQT); put_bits(p, 16, 2 + matrix_count * (1 + 64)); put_bits(p, 4, 0); /* 8 bit precision */ put_bits(p, 4, 0); /* table 0 */ for(i=0;i<64;i++) { j = intra_scantable->permutated[i]; put_bits(p, 8, luma_intra_matrix[j]); } if (matrix_count > 1) { put_bits(p, 4, 0); /* 8 bit precision */ put_bits(p, 4, 1); /* table 1 */ for(i=0;i<64;i++) { j = intra_scantable->permutated[i]; put_bits(p, 8, chroma_intra_matrix[j]); } } } if(avctx->active_thread_type & FF_THREAD_SLICE){ put_marker(p, DRI); put_bits(p, 16, 4); put_bits(p, 16, (avctx->width-1)/(8*hsample[0]) + 1); } /* huffman table */ put_marker(p, DHT); flush_put_bits(p); ptr = put_bits_ptr(p); put_bits(p, 16, 0); /* patched later */ size = 2; // Only MJPEG can have a variable Huffman variable. All other // formats use the default Huffman table. if (s->out_format == FMT_MJPEG && s->huffman == HUFFMAN_TABLE_OPTIMAL) { size += put_huffman_table(p, 0, 0, s->mjpeg_ctx->bits_dc_luminance, s->mjpeg_ctx->val_dc_luminance); size += put_huffman_table(p, 0, 1, s->mjpeg_ctx->bits_dc_chrominance, s->mjpeg_ctx->val_dc_chrominance); size += put_huffman_table(p, 1, 0, s->mjpeg_ctx->bits_ac_luminance, s->mjpeg_ctx->val_ac_luminance); size += put_huffman_table(p, 1, 1, s->mjpeg_ctx->bits_ac_chrominance, s->mjpeg_ctx->val_ac_chrominance); } else { size += put_huffman_table(p, 0, 0, avpriv_mjpeg_bits_dc_luminance, avpriv_mjpeg_val_dc); size += put_huffman_table(p, 0, 1, avpriv_mjpeg_bits_dc_chrominance, avpriv_mjpeg_val_dc); size += put_huffman_table(p, 1, 0, avpriv_mjpeg_bits_ac_luminance, avpriv_mjpeg_val_ac_luminance); size += put_huffman_table(p, 1, 1, avpriv_mjpeg_bits_ac_chrominance, avpriv_mjpeg_val_ac_chrominance); } AV_WB16(ptr, size); }