int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy) { int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1; if (ret=ff_j2k_dwt_init(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform)) return ret; for (i = 0; i < 2; i++) csize *= comp->coord[i][1] - comp->coord[i][0]; comp->data = av_malloc(csize * sizeof(int)); if (!comp->data) return AVERROR(ENOMEM); comp->reslevel = av_malloc(codsty->nreslevels * sizeof(Jpeg2000ResLevel)); if (!comp->reslevel) return AVERROR(ENOMEM); for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) { int declvl = codsty->nreslevels - reslevelno; Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno; for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) reslevel->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], declvl - 1); if (reslevelno == 0) reslevel->nbands = 1; else reslevel->nbands = 3; if (reslevel->coord[0][1] == reslevel->coord[0][0]) reslevel->num_precincts_x = 0; else reslevel->num_precincts_x = ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], codsty->log2_prec_width) - (reslevel->coord[0][0] >> codsty->log2_prec_width); if (reslevel->coord[1][1] == reslevel->coord[1][0]) reslevel->num_precincts_y = 0; else reslevel->num_precincts_y = ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height) - (reslevel->coord[1][0] >> codsty->log2_prec_height); reslevel->band = av_malloc(reslevel->nbands * sizeof(Jpeg2000Band)); if (!reslevel->band) return AVERROR(ENOMEM); for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) { Jpeg2000Band *band = reslevel->band + bandno; int cblkno, precx, precy, precno; int x0, y0, x1, y1; int xi0, yi0, xi1, yi1; int cblkperprecw, cblkperprech; if (qntsty->quantsty != JPEG2000_QSTY_NONE) { static const uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}}; int numbps; numbps = cbps + lut_gain[codsty->transform][bandno + reslevelno>0]; band->stepsize = SHL(2048 + qntsty->mant[gbandno], 2 + numbps - qntsty->expn[gbandno]); } else band->stepsize = 1 << 13; if (reslevelno == 0) { // the same everywhere band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width-1); band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height-1); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) band->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], declvl-1); } else{ band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width); band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) band->coord[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j] - (((bandno+1>>i)&1) << declvl-1), declvl); } band->cblknx = ff_jpeg2000_ceildiv(band->coord[0][1], band->codeblock_width) - band->coord[0][0] / band->codeblock_width; band->cblkny = ff_jpeg2000_ceildiv(band->coord[1][1], band->codeblock_height) - band->coord[1][0] / band->codeblock_height; for (j = 0; j < 2; j++) band->coord[0][j] = ff_jpeg2000_ceildiv(band->coord[0][j], dx); for (j = 0; j < 2; j++) band->coord[1][j] = ff_jpeg2000_ceildiv(band->coord[1][j], dy); band->cblknx = ff_jpeg2000_ceildiv(band->cblknx, dx); band->cblkny = ff_jpeg2000_ceildiv(band->cblkny, dy); band->cblk = av_malloc(sizeof(Jpeg2000Cblk) * band->cblknx * band->cblkny); if (!band->cblk) return AVERROR(ENOMEM); band->prec = av_malloc(sizeof(Jpeg2000Cblk) * reslevel->num_precincts_x * reslevel->num_precincts_y); if (!band->prec) return AVERROR(ENOMEM); for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++) { Jpeg2000Cblk *cblk = band->cblk + cblkno; cblk->zero = 0; cblk->lblock = 3; cblk->length = 0; cblk->lengthinc = 0; cblk->npasses = 0; } y0 = band->coord[1][0]; y1 = ((band->coord[1][0] + (1<<codsty->log2_prec_height)) & ~((1<<codsty->log2_prec_height)-1)) - y0; yi0 = 0; yi1 = ff_jpeg2000_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height; yi1 = FFMIN(yi1, band->cblkny); cblkperprech = 1<<(codsty->log2_prec_height - codsty->log2_cblk_height); for (precy = 0, precno = 0; precy < reslevel->num_precincts_y; precy++) { for (precx = 0; precx < reslevel->num_precincts_x; precx++, precno++) { band->prec[precno].yi0 = yi0; band->prec[precno].yi1 = yi1; } yi1 += cblkperprech; yi0 = yi1 - cblkperprech; yi1 = FFMIN(yi1, band->cblkny); } x0 = band->coord[0][0]; x1 = ((band->coord[0][0] + (1<<codsty->log2_prec_width)) & ~((1<<codsty->log2_prec_width)-1)) - x0; xi0 = 0; xi1 = ff_jpeg2000_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width; xi1 = FFMIN(xi1, band->cblknx); cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width); for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++) { for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0) { Jpeg2000Prec *prec = band->prec + precno; prec->xi0 = xi0; prec->xi1 = xi1; prec->cblkincl = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); prec->zerobits = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); if (!prec->cblkincl || !prec->zerobits) return AVERROR(ENOMEM); } xi1 += cblkperprecw; xi0 = xi1 - cblkperprecw; xi1 = FFMIN(xi1, band->cblknx); } } } return 0; }


static void check_for_pg_role_prefix ( ClusterInfo * cluster ) {
 PGresult * res ;
 PGconn * conn = connectToServer ( cluster , "template1" ) ;
 prep_status ( "Checking for roles starting with 'pg_'" ) ;
 res = executeQueryOrDie ( conn , "SELECT * " "FROM pg_catalog.pg_roles " "WHERE rolname ~ '^pg_'" ) ;
 if ( PQntuples ( res ) != 0 ) pg_fatal ( "The %s cluster contains roles starting with 'pg_'\n" , CLUSTER_NAME ( cluster ) ) ;
 PQclear ( res ) ;
 PQfinish ( conn ) ;
 check_ok ( ) ;
 }


static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) { IlContext *il = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; AVFilterBufferRef *out; int ret; out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); if (!out) { avfilter_unref_bufferp(&inpicref); return AVERROR(ENOMEM); } avfilter_copy_buffer_ref_props(out, inpicref); interleave(out->data[0], inpicref->data[0], il->width, inlink->h, out->linesize[0], inpicref->linesize[0], il->luma_mode, il->luma_swap); if (il->nb_planes > 2) { interleave(out->data[1], inpicref->data[1], il->chroma_width, il->chroma_height, out->linesize[1], inpicref->linesize[1], il->chroma_mode, il->chroma_swap); interleave(out->data[2], inpicref->data[2], il->chroma_width, il->chroma_height, out->linesize[2], inpicref->linesize[2], il->chroma_mode, il->chroma_swap); } if (il->nb_planes == 2 && il->nb_planes == 4) { int comp = il->nb_planes - 1; interleave(out->data[comp], inpicref->data[comp], il->width, inlink->h, out->linesize[comp], inpicref->linesize[comp], il->alpha_mode, il->alpha_swap); } ret = ff_filter_frame(outlink, out); avfilter_unref_bufferp(&inpicref); return ret; }


unsigned long long cpu_clock(int cpu)
{
	unsigned long long prev_cpu_time, time, delta_time;

	prev_cpu_time = per_cpu(prev_cpu_time, cpu);
	time = __cpu_clock(cpu) + per_cpu(time_offset, cpu);
	delta_time = time-prev_cpu_time;

	if (unlikely(delta_time > time_sync_thresh))
		time = __sync_cpu_clock(time, cpu);

	return time;
}


int sched_rt_handler(struct ctl_table *table, int write,
		struct file *filp, void __user *buffer, size_t *lenp,
		loff_t *ppos)
{
	int ret;
	int old_period, old_runtime;
	static DEFINE_MUTEX(mutex);

	mutex_lock(&mutex);
	old_period = sysctl_sched_rt_period;
	old_runtime = sysctl_sched_rt_runtime;

	ret = proc_dointvec(table, write, filp, buffer, lenp, ppos);

	if (!ret && write) {
		ret = sched_rt_global_constraints();
		if (ret) {
			sysctl_sched_rt_period = old_period;
			sysctl_sched_rt_runtime = old_runtime;
		} else {
			def_rt_bandwidth.rt_runtime = global_rt_runtime();
			def_rt_bandwidth.rt_period =
				ns_to_ktime(global_rt_period());
		}
	}
	mutex_unlock(&mutex);

	return ret;
}


static void DecoderUpdateFormatLocked ( decoder_t * p_dec ) {
 decoder_owner_sys_t * p_owner = p_dec -> p_owner ;
 vlc_assert_locked ( & p_owner -> lock ) ;
 p_owner -> b_fmt_description = true ;
 es_format_Clean ( & p_owner -> fmt_description ) ;
 es_format_Copy ( & p_owner -> fmt_description , & p_dec -> fmt_out ) ;
 if ( p_owner -> p_description && p_dec -> p_description ) vlc_meta_Delete ( p_owner -> p_description ) ;
 p_owner -> p_description = p_dec -> p_description ;
 p_dec -> p_description = NULL ;
 }


int main(int argc,char* argv[]){ int i, j; uint64_t sse=0; uint64_t dev; FILE *f[2]; uint8_t buf[2][SIZE]; uint64_t psnr; int len= argc<4 ? 1 : atoi(argv[3]); int64_t max= (1<<(8*len))-1; int shift= argc<5 ? 0 : atoi(argv[4]); int skip_bytes = argc<6 ? 0 : atoi(argv[5]); if(argc<3){ printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n"); printf("For WAV files use the following:\n"); printf("./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\n"); return -1; } f[0]= fopen(argv[1], "rb"); f[1]= fopen(argv[2], "rb"); if(!f[0] || !f[1]){ fprintf(stderr, "Could not open input files.\n"); return -1; } fseek(f[shift<0], shift < 0 ? -shift : shift, SEEK_SET); fseek(f[0],skip_bytes,SEEK_CUR); fseek(f[1],skip_bytes,SEEK_CUR); for(i=0;;){ if( fread(buf[0], SIZE, 1, f[0]) != 1) break; if( fread(buf[1], SIZE, 1, f[1]) != 1) break; for(j=0; j<SIZE; i++,j++){ int64_t a= buf[0][j]; int64_t b= buf[1][j]; if(len==2){ a= (int16_t)(a | (buf[0][++j]<<8)); b= (int16_t)(b | (buf[1][ j]<<8)); } sse += (a-b) * (a-b); } } if(!i) i=1; dev= int_sqrt( ((sse/i)*F*F) + (((sse%i)*F*F) + i/2)/i ); if(sse) psnr= ((2*log16(max<<16) + log16(i) - log16(sse))*284619LL*F + (1<<31)) / (1LL<<32); else psnr= 100*F-1; //floating point free infinity :) printf("stddev:%3d.%02d PSNR:%2d.%02d bytes:%d\n", (int)(dev/F), (int)(dev%F), (int)(psnr/F), (int)(psnr%F), i*len); return 0; }


static int celt_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; struct oggcelt_private *priv = os->private; uint8_t *p = os->buf + os->pstart; if (os->psize == 60 && !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) { /* Main header */ uint32_t version, sample_rate, nb_channels; uint32_t overlap, extra_headers; priv = av_malloc(sizeof(struct oggcelt_private)); if (!priv) return AVERROR(ENOMEM); if (ff_alloc_extradata(st->codecpar, 2 * sizeof(uint32_t)) < 0) { av_free(priv); return AVERROR(ENOMEM); } version = AV_RL32(p + 28); /* unused header size field skipped */ sample_rate = AV_RL32(p + 36); nb_channels = AV_RL32(p + 40); overlap = AV_RL32(p + 48); /* unused bytes per packet field skipped */ extra_headers = AV_RL32(p + 56); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_CELT; st->codecpar->sample_rate = sample_rate; st->codecpar->channels = nb_channels; if (sample_rate) avpriv_set_pts_info(st, 64, 1, sample_rate); priv->extra_headers_left = 1 + extra_headers; av_free(os->private); os->private = priv; AV_WL32(st->codecpar->extradata + 0, overlap); AV_WL32(st->codecpar->extradata + 4, version); return 1; } else if (priv && priv->extra_headers_left) { /* Extra headers (vorbiscomment) */ ff_vorbis_stream_comment(s, st, p, os->psize); priv->extra_headers_left--; return 1; } else { return 0; } }


static uint8_t lut_interp_linear_precache_output ( uint32_t input_value , uint16_t * table , size_t length ) {
 uintptr_t value = ( input_value * ( length - 1 ) ) ;
 uint32_t upper = ( value + PRECACHE_OUTPUT_MAX - 1 ) / PRECACHE_OUTPUT_MAX ;
 uint32_t lower = value / PRECACHE_OUTPUT_MAX ;
 uint32_t interp = value % PRECACHE_OUTPUT_MAX ;
 value = ( table [ upper ] * ( interp ) + table [ lower ] * ( PRECACHE_OUTPUT_MAX - interp ) ) ;
 value += ( PRECACHE_OUTPUT_MAX * 65535 / 255 ) / 2 ;
 value /= ( PRECACHE_OUTPUT_MAX * 65535 / 255 ) ;
 return value ;
 }


static void TestFramePrinting ( WebLocalFrameImpl * frame ) {
 WebPrintParams print_params ;
 WebSize page_size ( 500 , 500 ) ;
 print_params . print_content_area . width = page_size . width ;
 print_params . print_content_area . height = page_size . height ;
 EXPECT_EQ ( 1 , frame -> PrintBegin ( print_params , WebNode ( ) ) ) ;
 PaintRecorder recorder ;
 frame -> PrintPagesForTesting ( recorder . beginRecording ( IntRect ( ) ) , page_size ) ;
 frame -> PrintEnd ( ) ;
 }


static uint64_t pl011_read(void *opaque, target_phys_addr_t offset, unsigned size) { pl011_state *s = (pl011_state *)opaque; uint32_t c; if (offset >= 0xfe0 && offset < 0x1000) { return s->id[(offset - 0xfe0) >> 2]; } switch (offset >> 2) { case 0: /* UARTDR */ s->flags &= ~PL011_FLAG_RXFF; c = s->read_fifo[s->read_pos]; if (s->read_count > 0) { s->read_count--; if (++s->read_pos == 16) s->read_pos = 0; } if (s->read_count == 0) { s->flags |= PL011_FLAG_RXFE; } if (s->read_count == s->read_trigger - 1) s->int_level &= ~ PL011_INT_RX; pl011_update(s); qemu_chr_accept_input(s->chr); return c; case 1: /* UARTCR */ return 0; case 6: /* UARTFR */ return s->flags; case 8: /* UARTILPR */ return s->ilpr; case 9: /* UARTIBRD */ return s->ibrd; case 10: /* UARTFBRD */ return s->fbrd; case 11: /* UARTLCR_H */ return s->lcr; case 12: /* UARTCR */ return s->cr; case 13: /* UARTIFLS */ return s->ifl; case 14: /* UARTIMSC */ return s->int_enabled; case 15: /* UARTRIS */ return s->int_level; case 16: /* UARTMIS */ return s->int_level & s->int_enabled; case 18: /* UARTDMACR */ return s->dmacr; default: hw_error("pl011_read: Bad offset %x\n", (int)offset); return 0; } }


static void icp_pit_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { icp_pit_state *s = (icp_pit_state *)opaque; int n; n = offset >> 8; if (n > 2) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad timer %d\n", __func__, n); } arm_timer_write(s->timer[n], offset & 0xff, value); }


static int aasc_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AascContext *s = avctx->priv_data; int compr, i, stride, psize; s->frame.reference = 3; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (avctx->reget_buffer(avctx, &s->frame)) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; compr = AV_RL32(buf); buf += 4; buf_size -= 4; psize = avctx->bits_per_coded_sample / 8; switch (avctx->codec_tag) { case MKTAG('A', 'A', 'S', '4'): bytestream2_init(&s->gb, buf - 4, buf_size + 4); ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb); break; case MKTAG('A', 'A', 'S', 'C'): switch(compr){ case 0: stride = (avctx->width * psize + psize) & ~psize; for(i = avctx->height - 1; i >= 0; i--){ if(avctx->width * psize > buf_size){ av_log(avctx, AV_LOG_ERROR, "Next line is beyond buffer bounds\n"); break; memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width * psize); buf += stride; buf_size -= stride; break; case 1: bytestream2_init(&s->gb, buf, buf_size); ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr); return -1; break; default: av_log(avctx, AV_LOG_ERROR, "Unknown FourCC: %X\n", avctx->codec_tag); return -1; if (avctx->pix_fmt == AV_PIX_FMT_PAL8) memcpy(s->frame.data[1], s->palette, s->palette_size); *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; /* report that the buffer was completely consumed */ return buf_size;


static void intra_pred_lp_top ( uint8_t * d , uint8_t * top , uint8_t * left , int stride ) {
 int x , y ;
 for ( y = 0 ;
 y < 8 ;
 y ++ ) for ( x = 0 ;
 x < 8 ;
 x ++ ) d [ y * stride + x ] = LOWPASS ( top , x + 1 ) ;
 }


static int dissect_h225_Content ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_choice ( tvb , offset , actx , tree , hf_index , ett_h225_Content , Content_choice , NULL ) ;
 return offset ;
 }


static int proxy_closedir(FsContext *ctx, V9fsFidOpenState *fs) { return closedir(fs->dir); }


static int ne2000_can_receive(void *opaque) { NE2000State *s = opaque; int avail, index, boundary; if (s->cmd & E8390_STOP) return 0; index = s->curpag << 8; boundary = s->boundary << 8; if (index < boundary) avail = boundary - index; else avail = (s->stop - s->start) - (index - boundary); if (avail < (MAX_ETH_FRAME_SIZE + 4)) return 0; return MAX_ETH_FRAME_SIZE; }


void sched_exec(void)
{
	int new_cpu, this_cpu = get_cpu();
	new_cpu = sched_balance_self(this_cpu, SD_BALANCE_EXEC);
	put_cpu();
	if (new_cpu != this_cpu)
		sched_migrate_task(current, new_cpu);
}


static int decode_i_picture_secondary_header(VC9Context *v) { int status; #if HAS_ADVANCED_PROFILE if (v->profile > PROFILE_MAIN) { v->s.ac_pred = get_bits(&v->s.gb, 1); if (v->postprocflag) v->postproc = get_bits(&v->s.gb, 1); /* 7.1.1.34 + 8.5.2 */ if (v->overlap && v->pq<9) { v->condover = get_bits(&v->s.gb, 1); if (v->condover) { v->condover = 2+get_bits(&v->s.gb, 1); if (v->condover == 3) { status = bitplane_decoding(&v->over_flags_plane, v); if (status < 0) return -1; # if TRACE av_log(v->s.avctx, AV_LOG_DEBUG, "Overflags plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); # endif } } } } #endif /* Epilog (AC/DC syntax) should be done in caller */ return 0; }


static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic) { VAAPIEncodeContext *ctx = avctx->priv_data; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params; VAAPIEncodeH264Context *priv = ctx->priv_data; int i; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); vpic->frame_num = 0; priv->next_frame_num = 1; priv->cpb_delay = 0; } else { vpic->frame_num = priv->next_frame_num; if (pic->type != PICTURE_TYPE_B) { // nal_ref_idc != 0 ++priv->next_frame_num; } ++priv->cpb_delay; } priv->dpb_delay = pic->display_order - pic->encode_order + 1; vpic->frame_num = vpic->frame_num & ((1 << (4 + vseq->seq_fields.bits.log2_max_frame_num_minus4)) - 1); vpic->CurrPic.picture_id = pic->recon_surface; vpic->CurrPic.frame_idx = vpic->frame_num; vpic->CurrPic.flags = 0; vpic->CurrPic.TopFieldOrderCnt = pic->display_order; vpic->CurrPic.BottomFieldOrderCnt = pic->display_order; for (i = 0; i < pic->nb_refs; i++) { VAAPIEncodePicture *ref = pic->refs[i]; av_assert0(ref && ref->encode_order < pic->encode_order); vpic->ReferenceFrames[i].picture_id = ref->recon_surface; vpic->ReferenceFrames[i].frame_idx = ref->encode_order; vpic->ReferenceFrames[i].flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; vpic->ReferenceFrames[i].TopFieldOrderCnt = ref->display_order; vpic->ReferenceFrames[i].BottomFieldOrderCnt = ref->display_order; } for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) { vpic->ReferenceFrames[i].picture_id = VA_INVALID_ID; vpic->ReferenceFrames[i].flags = VA_PICTURE_H264_INVALID; } vpic->coded_buf = pic->output_buffer; vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR); vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B); pic->nb_slices = 1; return 0; }


void account_user_time(struct task_struct *p, cputime_t cputime)
{
	struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
	cputime64_t tmp;

	p->utime = cputime_add(p->utime, cputime);

	/* Add user time to cpustat. */
	tmp = cputime_to_cputime64(cputime);
	if (TASK_NICE(p) > 0)
		cpustat->nice = cputime64_add(cpustat->nice, tmp);
	else
		cpustat->user = cputime64_add(cpustat->user, tmp);
}


static int unpack_vlcs ( Vp3DecodeContext * s , GetBitContext * gb , VLC * table , int coeff_index , int plane , int eob_run ) {
 int i , j = 0 ;
 int token ;
 int zero_run = 0 ;
 int16_t coeff = 0 ;
 int bits_to_get ;
 int blocks_ended ;
 int coeff_i = 0 ;
 int num_coeffs = s -> num_coded_frags [ plane ] [ coeff_index ] ;
 int16_t * dct_tokens = s -> dct_tokens [ plane ] [ coeff_index ] ;
 int * coded_fragment_list = s -> coded_fragment_list [ plane ] ;
 Vp3Fragment * all_fragments = s -> all_fragments ;
 VLC_TYPE ( * vlc_table ) [ 2 ] = table -> table ;
 if ( num_coeffs < 0 ) av_log ( s -> avctx , AV_LOG_ERROR , "Invalid number of coefficents at level %d\n" , coeff_index ) ;
 if ( eob_run > num_coeffs ) {
 coeff_i = blocks_ended = num_coeffs ;
 eob_run -= num_coeffs ;
 }
 else {
 coeff_i = blocks_ended = eob_run ;
 eob_run = 0 ;
 }
 if ( blocks_ended ) dct_tokens [ j ++ ] = blocks_ended << 2 ;
 while ( coeff_i < num_coeffs && get_bits_left ( gb ) > 0 ) {
 token = get_vlc2 ( gb , vlc_table , 11 , 3 ) ;
 if ( ( unsigned ) token <= 6U ) {
 eob_run = eob_run_base [ token ] ;
 if ( eob_run_get_bits [ token ] ) eob_run += get_bits ( gb , eob_run_get_bits [ token ] ) ;
 if ( eob_run > num_coeffs - coeff_i ) {
 dct_tokens [ j ++ ] = TOKEN_EOB ( num_coeffs - coeff_i ) ;
 blocks_ended += num_coeffs - coeff_i ;
 eob_run -= num_coeffs - coeff_i ;
 coeff_i = num_coeffs ;
 }
 else {
 dct_tokens [ j ++ ] = TOKEN_EOB ( eob_run ) ;
 blocks_ended += eob_run ;
 coeff_i += eob_run ;
 eob_run = 0 ;
 }
 }
 else if ( token >= 0 ) {
 bits_to_get = coeff_get_bits [ token ] ;
 if ( bits_to_get ) bits_to_get = get_bits ( gb , bits_to_get ) ;
 coeff = coeff_tables [ token ] [ bits_to_get ] ;
 zero_run = zero_run_base [ token ] ;
 if ( zero_run_get_bits [ token ] ) zero_run += get_bits ( gb , zero_run_get_bits [ token ] ) ;
 if ( zero_run ) {
 dct_tokens [ j ++ ] = TOKEN_ZERO_RUN ( coeff , zero_run ) ;
 }
 else {
 if ( ! coeff_index ) all_fragments [ coded_fragment_list [ coeff_i ] ] . dc = coeff ;
 dct_tokens [ j ++ ] = TOKEN_COEFF ( coeff ) ;
 }
 if ( coeff_index + zero_run > 64 ) {
 av_log ( s -> avctx , AV_LOG_DEBUG , "Invalid zero run of %d with" " %d coeffs left\n" , zero_run , 64 - coeff_index ) ;
 zero_run = 64 - coeff_index ;
 }
 for ( i = coeff_index + 1 ;
 i <= coeff_index + zero_run ;
 i ++ ) s -> num_coded_frags [ plane ] [ i ] -- ;
 coeff_i ++ ;
 }
 else {
 av_log ( s -> avctx , AV_LOG_ERROR , "Invalid token %d\n" , token ) ;
 return - 1 ;
 }
 }
 if ( blocks_ended > s -> num_coded_frags [ plane ] [ coeff_index ] ) av_log ( s -> avctx , AV_LOG_ERROR , "More blocks ended than coded!\n" ) ;
 if ( blocks_ended ) for ( i = coeff_index + 1 ;
 i < 64 ;
 i ++ ) s -> num_coded_frags [ plane ] [ i ] -= blocks_ended ;
 if ( plane < 2 ) s -> dct_tokens [ plane + 1 ] [ coeff_index ] = dct_tokens + j ;
 else if ( coeff_index < 63 ) s -> dct_tokens [ 0 ] [ coeff_index + 1 ] = dct_tokens + j ;
 return eob_run ;
 }


static void test_qemu_strtoull_full_empty(void) { const char *str = ""; uint64_t res = 999; int err; err = qemu_strtoull(str, NULL, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, 0); }


static inline void free_fair_sched_group(struct task_group *tg)
{
}


asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
				      unsigned long __user *user_mask_ptr)
{
	int ret;
	cpumask_t mask;

	if (len < sizeof(cpumask_t))
		return -EINVAL;

	ret = sched_getaffinity(pid, &mask);
	if (ret < 0)
		return ret;

	if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t)))
		return -EFAULT;

	return sizeof(cpumask_t);
}


static int32_t u_scanf_hex_handler ( UFILE * input , u_scanf_spec_info * info , ufmt_args * args , const UChar * fmt , int32_t * fmtConsumed , int32_t * argConverted ) {
 int32_t len ;
 int32_t skipped ;
 void * num = ( void * ) ( args [ 0 ] . ptrValue ) ;
 int64_t result ;
 skipped = u_scanf_skip_leading_ws ( input , info -> fPadChar ) ;
 ufile_fill_uchar_buffer ( input ) ;
 len = ( int32_t ) ( input -> str . fLimit - input -> str . fPos ) ;
 if ( info -> fWidth != - 1 ) len = ufmt_min ( len , info -> fWidth ) ;
 if ( * ( input -> str . fPos ) == 0x0030 && ( * ( input -> str . fPos + 1 ) == 0x0078 || * ( input -> str . fPos + 1 ) == 0x0058 ) ) {
 input -> str . fPos += 2 ;
 len -= 2 ;
 }
 result = ufmt_uto64 ( input -> str . fPos , & len , 16 ) ;
 input -> str . fPos += len ;
 if ( ! info -> fSkipArg ) {
 if ( info -> fIsShort ) * ( int16_t * ) num = ( int16_t ) ( UINT16_MAX & result ) ;
 else if ( info -> fIsLongLong ) * ( int64_t * ) num = result ;
 else * ( int32_t * ) num = ( int32_t ) ( UINT32_MAX & result ) ;
 }
 * argConverted = ! info -> fSkipArg ;
 return len + skipped ;
 }


int main ( int argc ATTRIBUTE_UNUSED , char * * argv ATTRIBUTE_UNUSED ) {
 printf ( "%s : SAX1 parsing support not compiled in\n" , argv [ 0 ] ) ;
 return ( 0 ) ;
 }


void aggregate_group_set_shares(struct task_group *tg, struct sched_domain *sd)
{
	unsigned long shares = aggregate(tg, sd)->shares;
	int i;

	for_each_cpu_mask(i, sd->span) {
		struct rq *rq = cpu_rq(i);
		unsigned long flags;

		spin_lock_irqsave(&rq->lock, flags);
		__update_group_shares_cpu(tg, sd, i);
		spin_unlock_irqrestore(&rq->lock, flags);
	}

	aggregate_group_shares(tg, sd);

	/*
	 * ensure we never loose shares due to rounding errors in the
	 * above redistribution.
	 */
	shares -= aggregate(tg, sd)->shares;
	if (shares) {
		tg->cfs_rq[sd->first_cpu]->shares += shares;
		aggregate(tg, sd)->shares += shares;
	}
}


void __sched wait_for_completion(struct completion *x)
{
	wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE);
}


static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt)
{
	int ret;

	if (buf[0] != '0' && buf[0] != '1')
		return -EINVAL;

	if (smt)
		sched_smt_power_savings = (buf[0] == '1');
	else
		sched_mc_power_savings = (buf[0] == '1');

	ret = arch_reinit_sched_domains();

	return ret ? ret : count;
}


static int dvbsub_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { DVBSubParseContext *pc = s->priv_data; uint8_t *p, *p_end; int i, len, buf_pos = 0; av_dlog(avctx, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n", s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); for (i=0; i < buf_size; i++) { av_dlog(avctx, "%02x ", buf[i]); if (i % 16 == 15) av_dlog(avctx, "\n"); } if (i % 16 != 0) av_dlog(avctx, "\n"); *poutbuf = NULL; *poutbuf_size = 0; s->fetch_timestamp = 1; if (s->last_pts != s->pts && s->pts != AV_NOPTS_VALUE) /* Start of a new packet */ { if (pc->packet_index != pc->packet_start) { av_dlog(avctx, "Discarding %d bytes\n", pc->packet_index - pc->packet_start); } pc->packet_start = 0; pc->packet_index = 0; if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { av_dlog(avctx, "Bad packet header\n"); return -1; } buf_pos = 2; pc->in_packet = 1; } else { if (pc->packet_start != 0) { if (pc->packet_index != pc->packet_start) { memmove(pc->packet_buf, pc->packet_buf + pc->packet_start, pc->packet_index - pc->packet_start); pc->packet_index -= pc->packet_start; pc->packet_start = 0; } else { pc->packet_start = 0; pc->packet_index = 0; } } } if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) return -1; /* if not currently in a packet, discard data */ if (pc->in_packet == 0) return buf_size; memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); pc->packet_index += buf_size - buf_pos; p = pc->packet_buf; p_end = pc->packet_buf + pc->packet_index; while (p < p_end) { if (*p == 0x0f) { if (p + 6 <= p_end) { len = AV_RB16(p + 4); if (p + len + 6 <= p_end) { *poutbuf_size += len + 6; p += len + 6; } else break; } else break; } else if (*p == 0xff) { if (p + 1 < p_end) { av_dlog(avctx, "Junk at end of packet\n"); } pc->packet_index = p - pc->packet_buf; pc->in_packet = 0; break; } else { av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); pc->packet_index = p - pc->packet_buf; pc->in_packet = 0; break; } } if (*poutbuf_size > 0) { *poutbuf = pc->packet_buf; pc->packet_start = *poutbuf_size; } if (s->pts == AV_NOPTS_VALUE) s->pts = s->last_pts; return buf_size; }


void sched_clock_idle_sleep_event(void)
{
	struct rq *rq = cpu_rq(smp_processor_id());

	spin_lock(&rq->lock);
	__update_rq_clock(rq);
	spin_unlock(&rq->lock);
	rq->clock_deep_idle_events++;
}


void gdev_x_clear_window ( gx_device_X * xdev ) {
 if ( ! xdev -> ghostview ) {
 if ( xdev -> useBackingPixmap ) {
 if ( xdev -> bpixmap == 0 ) {
 x_error_handler . oldhandler = XSetErrorHandler ( x_catch_alloc ) ;
 x_error_handler . alloc_error = False ;
 xdev -> bpixmap = XCreatePixmap ( xdev -> dpy , xdev -> win , xdev -> width , xdev -> height , xdev -> vinfo -> depth ) ;
 XSync ( xdev -> dpy , False ) ;
 if ( x_error_handler . alloc_error ) {
 xdev -> useBackingPixmap = False ;
 # ifdef DEBUG emprintf ( xdev -> memory , "Warning: Failed to allocated backing pixmap.\n" ) ;
 # endif if ( xdev -> bpixmap ) {
 XFreePixmap ( xdev -> dpy , xdev -> bpixmap ) ;
 xdev -> bpixmap = None ;
 XSync ( xdev -> dpy , False ) ;
 }
 }
 x_error_handler . oldhandler = XSetErrorHandler ( x_error_handler . oldhandler ) ;
 }
 }
 else {
 if ( xdev -> bpixmap != 0 ) {
 XFreePixmap ( xdev -> dpy , xdev -> bpixmap ) ;
 xdev -> bpixmap = ( Pixmap ) 0 ;
 }
 }
 }
 x_set_buffer ( xdev ) ;
 if ( xdev -> dest == ( Pixmap ) 0 ) {
 xdev -> dest = ( xdev -> bpixmap != ( Pixmap ) 0 ? xdev -> bpixmap : ( Pixmap ) xdev -> win ) ;
 }
 if ( xdev -> dest != ( Pixmap ) 0 ) {
 XSetForeground ( xdev -> dpy , xdev -> gc , xdev -> background ) ;
 XFillRectangle ( xdev -> dpy , xdev -> dest , xdev -> gc , 0 , 0 , xdev -> width , xdev -> height ) ;
 }
 if ( xdev -> bpixmap != ( Pixmap ) 0 ) {
 if ( ! xdev -> ghostview ) XSetWindowBackgroundPixmap ( xdev -> dpy , xdev -> win , xdev -> bpixmap ) ;
 XSetForeground ( xdev -> dpy , xdev -> gc , xdev -> background ) ;
 XFillRectangle ( xdev -> dpy , xdev -> bpixmap , xdev -> gc , 0 , 0 , xdev -> width , xdev -> height ) ;
 }
 xdev -> back_color = xdev -> background ;
 XSetBackground ( xdev -> dpy , xdev -> gc , xdev -> background ) ;
 xdev -> fore_color = xdev -> background ;
 XSetForeground ( xdev -> dpy , xdev -> gc , xdev -> background ) ;
 xdev -> colors_or = xdev -> colors_and = xdev -> background ;
 }


static void usb_ohci_init ( OHCIState * ohci , DeviceState * dev , int num_ports , dma_addr_t localmem_base , char * masterbus , uint32_t firstport , AddressSpace * as , Error * * errp ) {
 Error * err = NULL ;
 int i ;
 ohci -> as = as ;
 if ( num_ports > OHCI_MAX_PORTS ) {
 error_setg ( errp , "OHCI num-ports=%d is too big (limit is %d ports)" , num_ports , OHCI_MAX_PORTS ) ;
 return ;
 }
 if ( usb_frame_time == 0 ) {
 # ifdef OHCI_TIME_WARP usb_frame_time = NANOSECONDS_PER_SECOND ;
 usb_bit_time = NANOSECONDS_PER_SECOND / ( USB_HZ / 1000 ) ;
 # else usb_frame_time = NANOSECONDS_PER_SECOND / 1000 ;
 if ( NANOSECONDS_PER_SECOND >= USB_HZ ) {
 usb_bit_time = NANOSECONDS_PER_SECOND / USB_HZ ;
 }
 else {
 usb_bit_time = 1 ;
 }
 # endif trace_usb_ohci_init_time ( usb_frame_time , usb_bit_time ) ;
 }
 ohci -> num_ports = num_ports ;
 if ( masterbus ) {
 USBPort * ports [ OHCI_MAX_PORTS ] ;
 for ( i = 0 ;
 i < num_ports ;
 i ++ ) {
 ports [ i ] = & ohci -> rhport [ i ] . port ;
 }
 usb_register_companion ( masterbus , ports , num_ports , firstport , ohci , & ohci_port_ops , USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL , & err ) ;
 if ( err ) {
 error_propagate ( errp , err ) ;
 return ;
 }
 }
 else {
 usb_bus_new ( & ohci -> bus , sizeof ( ohci -> bus ) , & ohci_bus_ops , dev ) ;
 for ( i = 0 ;
 i < num_ports ;
 i ++ ) {
 usb_register_port ( & ohci -> bus , & ohci -> rhport [ i ] . port , ohci , i , & ohci_port_ops , USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL ) ;
 }
 }
 memory_region_init_io ( & ohci -> mem , OBJECT ( dev ) , & ohci_mem_ops , ohci , "ohci" , 256 ) ;
 ohci -> localmem_base = localmem_base ;
 ohci -> name = object_get_typename ( OBJECT ( dev ) ) ;
 usb_packet_init ( & ohci -> usb_packet ) ;
 ohci -> async_td = 0 ;
 ohci -> eof_timer = timer_new_ns ( QEMU_CLOCK_VIRTUAL , ohci_frame_boundary , ohci ) ;
 }


void __kprobes add_preempt_count(int val)
{
	/*
	 * Underflow?
	 */
	if (DEBUG_LOCKS_WARN_ON((preempt_count() < 0)))
		return;
	preempt_count() += val;
	/*
	 * Spinlock count overflowing soon?
	 */
	DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >=
				PREEMPT_MASK - 10);
}


static int ipvideo_decode_block_opcode_0x8_16 ( IpvideoContext * s ) {
 int x , y ;
 uint16_t P [ 4 ] ;
 unsigned int flags = 0 ;
 uint16_t * pixel_ptr = ( uint16_t * ) s -> pixel_ptr ;
 P [ 0 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 P [ 1 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 if ( ! ( P [ 0 ] & 0x8000 ) ) {
 for ( y = 0 ;
 y < 16 ;
 y ++ ) {
 if ( ! ( y & 3 ) ) {
 if ( y ) {
 P [ 0 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 P [ 1 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 }
 flags = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 }
 for ( x = 0 ;
 x < 4 ;
 x ++ , flags >>= 1 ) * pixel_ptr ++ = P [ flags & 1 ] ;
 pixel_ptr += s -> stride - 4 ;
 if ( y == 7 ) pixel_ptr -= 8 * s -> stride - 4 ;
 }
 }
 else {
 flags = bytestream2_get_le32 ( & s -> stream_ptr ) ;
 P [ 2 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 P [ 3 ] = bytestream2_get_le16 ( & s -> stream_ptr ) ;
 if ( ! ( P [ 2 ] & 0x8000 ) ) {
 for ( y = 0 ;
 y < 16 ;
 y ++ ) {
 for ( x = 0 ;
 x < 4 ;
 x ++ , flags >>= 1 ) * pixel_ptr ++ = P [ flags & 1 ] ;
 pixel_ptr += s -> stride - 4 ;
 if ( y == 7 ) {
 pixel_ptr -= 8 * s -> stride - 4 ;
 P [ 0 ] = P [ 2 ] ;
 P [ 1 ] = P [ 3 ] ;
 flags = bytestream2_get_le32 ( & s -> stream_ptr ) ;
 }
 }
 }
 else {
 for ( y = 0 ;
 y < 8 ;
 y ++ ) {
 if ( y == 4 ) {
 P [ 0 ] = P [ 2 ] ;
 P [ 1 ] = P [ 3 ] ;
 flags = bytestream2_get_le32 ( & s -> stream_ptr ) ;
 }
 for ( x = 0 ;
 x < 8 ;
 x ++ , flags >>= 1 ) * pixel_ptr ++ = P [ flags & 1 ] ;
 pixel_ptr += s -> line_inc ;
 }
 }
 }
 return 0 ;
 }


static int for_neg_int_continue ( i_ctx_t * i_ctx_p ) {
 os_ptr op = osp ;
 register es_ptr ep = esp ;
 int var = ep [ - 3 ] . value . intval ;
 if ( var < ep [ - 1 ] . value . intval ) {
 esp -= 5 ;
 return o_pop_estack ;
 }
 push ( 1 ) ;
 make_int ( op , var ) ;
 ep [ - 3 ] . value . intval = var + ep [ - 2 ] . value . intval ;
 ref_assign ( ep + 2 , ep ) ;
 esp = ep + 2 ;
 return o_push_estack ;
 }


int default_wake_function(wait_queue_t *curr, unsigned mode, int sync,
			  void *key)
{
	return try_to_wake_up(curr->private, mode, sync);
}


void __init migration_init(void)
{
	void *cpu = (void *)(long)smp_processor_id();
	int err;

	/* Start one for the boot CPU: */
	err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
	BUG_ON(err == NOTIFY_BAD);
	migration_call(&migration_notifier, CPU_ONLINE, cpu);
	register_cpu_notifier(&migration_notifier);
}


	__acquires(rq2->lock)
{
	BUG_ON(!irqs_disabled());
	if (rq1 == rq2) {
		spin_lock(&rq1->lock);
		__acquire(rq2->lock);	/* Fake it out ;) */
	} else {
		if (rq1 < rq2) {
			spin_lock(&rq1->lock);
			spin_lock(&rq2->lock);
		} else {
			spin_lock(&rq2->lock);
			spin_lock(&rq1->lock);
		}
	}
	update_rq_clock(rq1);
	update_rq_clock(rq2);
}


static ssize_t cpu_rt_runtime_read(struct cgroup *cgrp, struct cftype *cft,
				   struct file *file,
				   char __user *buf, size_t nbytes,
				   loff_t *ppos)
{
	char tmp[64];
	long val = sched_group_rt_runtime(cgroup_tg(cgrp));
	int len = sprintf(tmp, "%ld\n", val);

	return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
}


static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix, bool *rebuild, uint16_t **refcount_table, int64_t *nb_clusters) { BDRVQcowState *s = bs->opaque; int64_t i, size; int ret; for(i = 0; i < s->refcount_table_size; i++) { uint64_t offset, cluster; offset = s->refcount_table[i]; cluster = offset >> s->cluster_bits; /* Refcount blocks are cluster aligned */ if (offset_into_cluster(s, offset)) { fprintf(stderr, "ERROR refcount block %" PRId64 " is not " "cluster aligned; refcount table entry corrupted\n", i); res->corruptions++; *rebuild = true; continue; } if (cluster >= *nb_clusters) { fprintf(stderr, "%s refcount block %" PRId64 " is outside image\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); if (fix & BDRV_FIX_ERRORS) { int64_t new_nb_clusters; if (offset > INT64_MAX - s->cluster_size) { ret = -EINVAL; goto resize_fail; } ret = bdrv_truncate(bs->file, offset + s->cluster_size); if (ret < 0) { goto resize_fail; } size = bdrv_getlength(bs->file); if (size < 0) { ret = size; goto resize_fail; } new_nb_clusters = size_to_clusters(s, size); assert(new_nb_clusters >= *nb_clusters); ret = realloc_refcount_array(s, refcount_table, nb_clusters, new_nb_clusters); if (ret < 0) { res->check_errors++; return ret; } if (cluster >= *nb_clusters) { ret = -EINVAL; goto resize_fail; } res->corruptions_fixed++; ret = inc_refcounts(bs, res, refcount_table, nb_clusters, offset, s->cluster_size); if (ret < 0) { return ret; } /* No need to check whether the refcount is now greater than 1: * This area was just allocated and zeroed, so it can only be * exactly 1 after inc_refcounts() */ continue; resize_fail: res->corruptions++; *rebuild = true; fprintf(stderr, "ERROR could not resize image: %s\n", strerror(-ret)); } else { res->corruptions++; } continue; } if (offset != 0) { ret = inc_refcounts(bs, res, refcount_table, nb_clusters, offset, s->cluster_size); if (ret < 0) { return ret; } if ((*refcount_table)[cluster] != 1) { fprintf(stderr, "ERROR refcount block %" PRId64 " refcount=%d\n", i, (*refcount_table)[cluster]); res->corruptions++; *rebuild = true; } } } return 0; }


static void virtio_gpu_reset(VirtIODevice *vdev) { VirtIOGPU *g = VIRTIO_GPU(vdev); struct virtio_gpu_simple_resource *res, *tmp; int i; g->enable = 0; QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) { virtio_gpu_resource_destroy(g, res); } for (i = 0; i < g->conf.max_outputs; i++) { #if 0 g->req_state[i].x = 0; g->req_state[i].y = 0; if (i == 0) { g->req_state[0].width = 1024; g->req_state[0].height = 768; } else { g->req_state[i].width = 0; g->req_state[i].height = 0; } #endif g->scanout[i].resource_id = 0; g->scanout[i].width = 0; g->scanout[i].height = 0; g->scanout[i].x = 0; g->scanout[i].y = 0; g->scanout[i].ds = NULL; } g->enabled_output_bitmask = 1; #ifdef CONFIG_VIRGL if (g->use_virgl_renderer) { virtio_gpu_virgl_reset(g); g->use_virgl_renderer = 0; } #endif }


static void adb_mouse_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); ADBDeviceClass *adc = ADB_DEVICE_CLASS(oc); ADBMouseClass *amc = ADB_MOUSE_CLASS(oc); amc->parent_realize = dc->realize; dc->realize = adb_mouse_realizefn; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); adc->devreq = adb_mouse_request; dc->reset = adb_mouse_reset; dc->vmsd = &vmstate_adb_mouse; }


static int rv34_decode_inter_mb_header ( RV34DecContext * r , int8_t * intra_types ) {
 MpegEncContext * s = & r -> s ;
 GetBitContext * gb = & s -> gb ;
 int mb_pos = s -> mb_x + s -> mb_y * s -> mb_stride ;
 int i , t ;
 r -> block_type = r -> decode_mb_info ( r ) ;
 if ( r -> block_type == - 1 ) return - 1 ;
 s -> current_picture_ptr -> f . mb_type [ mb_pos ] = rv34_mb_type_to_lavc [ r -> block_type ] ;
 r -> mb_type [ mb_pos ] = r -> block_type ;
 if ( r -> block_type == RV34_MB_SKIP ) {
 if ( s -> pict_type == AV_PICTURE_TYPE_P ) r -> mb_type [ mb_pos ] = RV34_MB_P_16x16 ;
 if ( s -> pict_type == AV_PICTURE_TYPE_B ) r -> mb_type [ mb_pos ] = RV34_MB_B_DIRECT ;
 }
 r -> is16 = ! ! IS_INTRA16x16 ( s -> current_picture_ptr -> f . mb_type [ mb_pos ] ) ;
 rv34_decode_mv ( r , r -> block_type ) ;
 if ( r -> block_type == RV34_MB_SKIP ) {
 fill_rectangle ( intra_types , 4 , 4 , r -> intra_types_stride , 0 , sizeof ( intra_types [ 0 ] ) ) ;
 return 0 ;
 }
 r -> chroma_vlc = 1 ;
 r -> luma_vlc = 0 ;
 if ( IS_INTRA ( s -> current_picture_ptr -> f . mb_type [ mb_pos ] ) ) {
 if ( r -> is16 ) {
 t = get_bits ( gb , 2 ) ;
 fill_rectangle ( intra_types , 4 , 4 , r -> intra_types_stride , t , sizeof ( intra_types [ 0 ] ) ) ;
 r -> luma_vlc = 2 ;
 }
 else {
 if ( r -> decode_intra_types ( r , gb , intra_types ) < 0 ) return - 1 ;
 r -> luma_vlc = 1 ;
 }
 r -> chroma_vlc = 0 ;
 r -> cur_vlcs = choose_vlc_set ( r -> si . quant , r -> si . vlc_set , 0 ) ;
 }
 else {
 for ( i = 0 ;
 i < 16 ;
 i ++ ) intra_types [ ( i & 3 ) + ( i >> 2 ) * r -> intra_types_stride ] = 0 ;
 r -> cur_vlcs = choose_vlc_set ( r -> si . quant , r -> si . vlc_set , 1 ) ;
 if ( r -> mb_type [ mb_pos ] == RV34_MB_P_MIX16x16 ) {
 r -> is16 = 1 ;
 r -> chroma_vlc = 1 ;
 r -> luma_vlc = 2 ;
 r -> cur_vlcs = choose_vlc_set ( r -> si . quant , r -> si . vlc_set , 0 ) ;
 }
 }
 return rv34_decode_cbp ( gb , r -> cur_vlcs , r -> is16 ) ;
 }


pick_next_task(struct rq *rq, struct task_struct *prev)
{
	const struct sched_class *class;
	struct task_struct *p;

	/*
	 * Optimization: we know that if all tasks are in
	 * the fair class we can call that function directly:
	 */
	if (likely(rq->nr_running == rq->cfs.nr_running)) {
		p = fair_sched_class.pick_next_task(rq);
		if (likely(p))
			return p;
	}

	class = sched_class_highest;
	for ( ; ; ) {
		p = class->pick_next_task(rq);
		if (p)
			return p;
		/*
		 * Will never be NULL as the idle class always
		 * returns a non-NULL p:
		 */
		class = class->next;
	}
}


static void *thread_function(void *data) { GMainLoop *loop; loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(loop); return NULL; }


static int mem_resize ( jas_stream_memobj_t * m , int bufsize ) {
 unsigned char * buf ;
 assert ( m -> buf_ ) ;
 assert ( bufsize >= 0 ) ;
 if ( ! ( buf = jas_realloc2 ( m -> buf_ , bufsize , sizeof ( unsigned char ) ) ) ) {
 return - 1 ;
 }
 m -> buf_ = buf ;
 m -> bufsize_ = bufsize ;
 return 0 ;
 }


int dissect_ber_choice ( asn1_ctx_t * actx , proto_tree * parent_tree , tvbuff_t * tvb , int offset , const ber_choice_t * choice , gint hf_id , gint ett_id , gint * branch_taken ) {
 gint8 ber_class ;
 gboolean pc , ind , imp_tag = FALSE ;
 gint32 tag ;
 guint32 len ;
 proto_tree * tree = parent_tree ;
 proto_item * item = NULL ;
 int end_offset , start_offset , count ;
 int hoffset = offset ;
 gint length ;
 tvbuff_t * next_tvb ;
 gboolean first_pass ;
 header_field_info * hfinfo ;
 const ber_choice_t * ch ;
 # ifdef DEBUG_BER_CHOICE {
 const char * name ;
 if ( hf_id >= 0 ) {
 hfinfo = proto_registrar_get_nth ( hf_id ) ;
 name = hfinfo -> name ;
 }
 else {
 name = "unnamed" ;
 }
 if ( tvb_reported_length_remaining ( tvb , offset ) > 3 ) {
 printf ( "CHOICE dissect_ber_choice(%s) entered offset:%d len:%d %02x:%02x:%02x\n" , name , offset , tvb_reported_length_remaining ( tvb , offset ) , tvb_get_guint8 ( tvb , offset ) , tvb_get_guint8 ( tvb , offset + 1 ) , tvb_get_guint8 ( tvb , offset + 2 ) ) ;
 }
 else {
 printf ( "CHOICE dissect_ber_choice(%s) entered len:%d\n" , name , tvb_reported_length_remaining ( tvb , offset ) ) ;
 }
 }
 # endif start_offset = offset ;
 if ( branch_taken ) {
 * branch_taken = - 1 ;
 }
 if ( tvb_reported_length_remaining ( tvb , offset ) == 0 ) {
 item = proto_tree_add_string_format_value ( parent_tree , hf_ber_error , tvb , offset , 0 , "empty_choice" , "Empty choice was found" ) ;
 expert_add_info ( actx -> pinfo , item , & ei_ber_empty_choice ) ;
 return offset ;
 }
 offset = get_ber_identifier ( tvb , offset , & ber_class , & pc , & tag ) ;
 offset = get_ber_length ( tvb , offset , & len , & ind ) ;
 end_offset = offset + len ;
 if ( hf_id >= 0 ) {
 hfinfo = proto_registrar_get_nth ( hf_id ) ;
 switch ( hfinfo -> type ) {
 case FT_UINT8 : case FT_UINT16 : case FT_UINT24 : case FT_UINT32 : break ;
 default : proto_tree_add_expert_format ( tree , actx -> pinfo , & ei_hf_field_not_integer_type , tvb , offset , len , "dissect_ber_choice(): frame:%u offset:%d Was passed an HF field that was not integer type : %s" , actx -> pinfo -> fd -> num , offset , hfinfo -> abbrev ) ;
 return end_offset ;
 }
 }
 ch = choice ;
 first_pass = TRUE ;
 while ( ch -> func || first_pass ) {
 if ( branch_taken ) {
 ( * branch_taken ) ++ ;
 }
 if ( ! ch -> func ) {
 first_pass = FALSE ;
 ch = choice ;
 if ( branch_taken ) {
 * branch_taken = - 1 ;
 }
 continue ;
 }
 # ifdef DEBUG_BER_CHOICE printf ( "CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:(expected)%d flags:%d\n" , ch , ber_class , ch -> ber_class , tag , ch -> tag , ch -> flags ) ;
 # endif if ( ( first_pass && ( ( ( ch -> ber_class == ber_class ) && ( ch -> tag == tag ) ) || ( ( ch -> ber_class == ber_class ) && ( ch -> tag == - 1 ) && ( ch -> flags & BER_FLAGS_NOOWNTAG ) ) ) ) || ( ! first_pass && ( ( ( ch -> ber_class == BER_CLASS_ANY ) && ( ch -> tag == - 1 ) ) ) ) ) {
 if ( ! ( ch -> flags & BER_FLAGS_NOOWNTAG ) ) {
 hoffset = dissect_ber_identifier ( actx -> pinfo , tree , tvb , start_offset , NULL , NULL , NULL ) ;
 hoffset = dissect_ber_length ( actx -> pinfo , tree , tvb , hoffset , NULL , NULL ) ;
 start_offset = hoffset ;
 if ( ind ) {
 length = len - 2 ;
 }
 else {
 length = len ;
 }
 }
 else {
 length = end_offset - hoffset ;
 }
 if ( hf_id >= 0 ) {
 if ( parent_tree ) {
 item = proto_tree_add_uint ( parent_tree , hf_id , tvb , hoffset , end_offset - hoffset , ch -> value ) ;
 tree = proto_item_add_subtree ( item , ett_id ) ;
 }
 }
 # ifdef REMOVED if ( first_pass ) next_tvb = ber_tvb_new_subset_length ( tvb , hoffset , length ) ;
 else next_tvb = tvb ;
 # endif next_tvb = ber_tvb_new_subset_length ( tvb , hoffset , length ) ;
 # ifdef DEBUG_BER_CHOICE {
 const char * name ;
 if ( hf_id >= 0 ) {
 hfinfo = proto_registrar_get_nth ( hf_id ) ;
 name = hfinfo -> name ;
 }
 else {
 name = "unnamed" ;
 }
 if ( tvb_reported_length_remaining ( next_tvb , 0 ) > 3 ) {
 printf ( "CHOICE dissect_ber_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n" , name , start_offset , offset , tvb_reported_length_remaining ( next_tvb , 0 ) , tvb_get_guint8 ( next_tvb , 0 ) , tvb_get_guint8 ( next_tvb , 1 ) , tvb_get_guint8 ( next_tvb , 2 ) ) ;
 }
 else {
 printf ( "CHOICE dissect_ber_choice(%s) calling subdissector len:%d\n" , name , tvb_reported_length ( next_tvb ) ) ;
 }
 }
 # endif if ( next_tvb == NULL ) {
 THROW ( ReportedBoundsError ) ;
 }
 imp_tag = FALSE ;
 if ( ( ch -> flags & BER_FLAGS_IMPLTAG ) ) imp_tag = TRUE ;
 count = ch -> func ( imp_tag , next_tvb , 0 , actx , tree , * ch -> p_id ) ;
 # ifdef DEBUG_BER_CHOICE {
 const char * name ;
 if ( hf_id >= 0 ) {
 hfinfo = proto_registrar_get_nth ( hf_id ) ;
 name = hfinfo -> name ;
 }
 else {
 name = "unnamed" ;
 }
 printf ( "CHOICE dissect_ber_choice(%s) subdissector ate %d bytes\n" , name , count ) ;
 }
 # endif if ( ( count == 0 ) && ( ( ( ch -> ber_class == ber_class ) && ( ch -> tag == - 1 ) && ( ch -> flags & BER_FLAGS_NOOWNTAG ) ) || ! first_pass ) ) {
 ch ++ ;
 # ifdef DEBUG_BER_CHOICE {
 const char * name ;
 if ( hf_id >= 0 ) {
 hfinfo = proto_registrar_get_nth ( hf_id ) ;
 name = hfinfo -> name ;
 }
 else {
 name = "unnamed" ;
 }
 printf ( "CHOICE dissect_ber_choice(%s) trying again\n" , name ) ;
 }
 # endif continue ;
 }
 if ( ! ( ch -> flags & BER_FLAGS_NOOWNTAG ) ) {
 if ( ind ) {
 if ( show_internal_ber_fields ) {
 proto_tree_add_item ( tree , hf_ber_choice_eoc , tvb , end_offset - 2 , 2 , ENC_NA ) ;
 }
 }
 }
 return end_offset ;
 }
 ch ++ ;
 }
 if ( branch_taken ) {
 * branch_taken = - 1 ;
 }
 # ifdef REMOVED item = proto_tree_add_string_format_value ( tree , hf_ber_error , tvb , offset , len , "missing_choice_field" , "This choice field was not found." ) ;
 expert_add_info ( actx -> pinfo , item , & ei_ber_choice_not_found ) ;
 return end_offset ;
 # endif return start_offset ;
 }


static void register_sched_domain_sysctl(void)
{
	int i, cpu_num = num_online_cpus();
	struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
	char buf[32];

	WARN_ON(sd_ctl_dir[0].child);
	sd_ctl_dir[0].child = entry;

	if (entry == NULL)
		return;

	for_each_online_cpu(i) {
		snprintf(buf, 32, "cpu%d", i);
		entry->procname = kstrdup(buf, GFP_KERNEL);
		entry->mode = 0555;
		entry->child = sd_alloc_ctl_cpu_table(i);
		entry++;
	}

	WARN_ON(sd_sysctl_header);
	sd_sysctl_header = register_sysctl_table(sd_ctl_root);
}


static void remote_ls ( const char * path , int flags , void ( * userFunc ) ( struct remote_ls_ctx * ls ) , void * userData ) {
 char * url = xstrfmt ( "%s%s" , repo -> url , path ) ;
 struct active_request_slot * slot ;
 struct slot_results results ;
 struct strbuf in_buffer = STRBUF_INIT ;
 struct buffer out_buffer = {
 STRBUF_INIT , 0 }
 ;
 struct curl_slist * dav_headers = NULL ;
 struct xml_ctx ctx ;
 struct remote_ls_ctx ls ;
 ls . flags = flags ;
 ls . path = xstrdup ( path ) ;
 ls . dentry_name = NULL ;
 ls . dentry_flags = 0 ;
 ls . userData = userData ;
 ls . userFunc = userFunc ;
 strbuf_addf ( & out_buffer . buf , PROPFIND_ALL_REQUEST ) ;
 dav_headers = curl_slist_append ( dav_headers , "Depth: 1" ) ;
 dav_headers = curl_slist_append ( dav_headers , "Content-Type: text/xml" ) ;
 slot = get_active_slot ( ) ;
 slot -> results = & results ;
 curl_setup_http ( slot -> curl , url , DAV_PROPFIND , & out_buffer , fwrite_buffer ) ;
 curl_easy_setopt ( slot -> curl , CURLOPT_HTTPHEADER , dav_headers ) ;
 curl_easy_setopt ( slot -> curl , CURLOPT_FILE , & in_buffer ) ;
 if ( start_active_slot ( slot ) ) {
 run_active_slot ( slot ) ;
 if ( results . curl_result == CURLE_OK ) {
 XML_Parser parser = XML_ParserCreate ( NULL ) ;
 enum XML_Status result ;
 ctx . name = xcalloc ( 10 , 1 ) ;
 ctx . len = 0 ;
 ctx . cdata = NULL ;
 ctx . userFunc = handle_remote_ls_ctx ;
 ctx . userData = & ls ;
 XML_SetUserData ( parser , & ctx ) ;
 XML_SetElementHandler ( parser , xml_start_tag , xml_end_tag ) ;
 XML_SetCharacterDataHandler ( parser , xml_cdata ) ;
 result = XML_Parse ( parser , in_buffer . buf , in_buffer . len , 1 ) ;
 free ( ctx . name ) ;
 if ( result != XML_STATUS_OK ) {
 fprintf ( stderr , "XML error: %s\n" , XML_ErrorString ( XML_GetErrorCode ( parser ) ) ) ;
 }
 XML_ParserFree ( parser ) ;
 }
 }
 else {
 fprintf ( stderr , "Unable to start PROPFIND request\n" ) ;
 }
 free ( ls . path ) ;
 free ( url ) ;
 strbuf_release ( & out_buffer . buf ) ;
 strbuf_release ( & in_buffer ) ;
 curl_slist_free_all ( dav_headers ) ;
 }


migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
{
	struct task_struct *p;
	int cpu = (long)hcpu;
	unsigned long flags;
	struct rq *rq;

	switch (action) {

	case CPU_UP_PREPARE:
	case CPU_UP_PREPARE_FROZEN:
		p = kthread_create(migration_thread, hcpu, "migration/%d", cpu);
		if (IS_ERR(p))
			return NOTIFY_BAD;
		kthread_bind(p, cpu);
		/* Must be high prio: stop_machine expects to yield to it. */
		rq = task_rq_lock(p, &flags);
		__setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
		task_rq_unlock(rq, &flags);
		cpu_rq(cpu)->migration_thread = p;
		break;

	case CPU_ONLINE:
	case CPU_ONLINE_FROZEN:
		/* Strictly unnecessary, as first user will wake it. */
		wake_up_process(cpu_rq(cpu)->migration_thread);

		/* Update our root-domain */
		rq = cpu_rq(cpu);
		spin_lock_irqsave(&rq->lock, flags);
		if (rq->rd) {
			BUG_ON(!cpu_isset(cpu, rq->rd->span));
			cpu_set(cpu, rq->rd->online);
		}
		spin_unlock_irqrestore(&rq->lock, flags);
		break;

#ifdef CONFIG_HOTPLUG_CPU
	case CPU_UP_CANCELED:
	case CPU_UP_CANCELED_FROZEN:
		if (!cpu_rq(cpu)->migration_thread)
			break;
		/* Unbind it from offline cpu so it can run. Fall thru. */
		kthread_bind(cpu_rq(cpu)->migration_thread,
			     any_online_cpu(cpu_online_map));
		kthread_stop(cpu_rq(cpu)->migration_thread);
		cpu_rq(cpu)->migration_thread = NULL;
		break;

	case CPU_DEAD:
	case CPU_DEAD_FROZEN:
		cpuset_lock(); /* around calls to cpuset_cpus_allowed_lock() */
		migrate_live_tasks(cpu);
		rq = cpu_rq(cpu);
		kthread_stop(rq->migration_thread);
		rq->migration_thread = NULL;
		/* Idle task back to normal (off runqueue, low prio) */
		spin_lock_irq(&rq->lock);
		update_rq_clock(rq);
		deactivate_task(rq, rq->idle, 0);
		rq->idle->static_prio = MAX_PRIO;
		__setscheduler(rq, rq->idle, SCHED_NORMAL, 0);
		rq->idle->sched_class = &idle_sched_class;
		migrate_dead_tasks(cpu);
		spin_unlock_irq(&rq->lock);
		cpuset_unlock();
		migrate_nr_uninterruptible(rq);
		BUG_ON(rq->nr_running != 0);

		/*
		 * No need to migrate the tasks: it was best-effort if
		 * they didn't take sched_hotcpu_mutex. Just wake up
		 * the requestors.
		 */
		spin_lock_irq(&rq->lock);
		while (!list_empty(&rq->migration_queue)) {
			struct migration_req *req;

			req = list_entry(rq->migration_queue.next,
					 struct migration_req, list);
			list_del_init(&req->list);
			complete(&req->done);
		}
		spin_unlock_irq(&rq->lock);
		break;

	case CPU_DYING:
	case CPU_DYING_FROZEN:
		/* Update our root-domain */
		rq = cpu_rq(cpu);
		spin_lock_irqsave(&rq->lock, flags);
		if (rq->rd) {
			BUG_ON(!cpu_isset(cpu, rq->rd->span));
			cpu_clear(cpu, rq->rd->online);
		}
		spin_unlock_irqrestore(&rq->lock, flags);
		break;
#endif
	}
	return NOTIFY_OK;
}


static void qemuMonitorJSONHandleIOError ( qemuMonitorPtr mon , virJSONValuePtr data ) {
 const char * device ;
 const char * action ;
 const char * reason ;
 int actionID ;
 if ( ( action = virJSONValueObjectGetString ( data , "action" ) ) == NULL ) {
 VIR_WARN ( "Missing action in disk io error event" ) ;
 action = "ignore" ;
 }
 if ( ( device = virJSONValueObjectGetString ( data , "device" ) ) == NULL ) {
 VIR_WARN ( "missing device in disk io error event" ) ;
 }
 # if 0 if ( ( reason = virJSONValueObjectGetString ( data , "reason" ) ) == NULL ) {
 VIR_WARN ( "missing reason in disk io error event" ) ;
 reason = "" ;
 }
 # else reason = "" ;
 # endif if ( ( actionID = qemuMonitorIOErrorActionTypeFromString ( action ) ) < 0 ) {
 VIR_WARN ( "unknown disk io error action '%s'" , action ) ;
 actionID = VIR_DOMAIN_EVENT_IO_ERROR_NONE ;
 }
 qemuMonitorEmitIOError ( mon , device , actionID , reason ) ;
 }


static inline void get_strl ( AVIOContext * pb , char * buf , int buf_size , int len ) {
 int i ;
 char * q , r ;
 q = buf ;
 for ( i = 0 ;
 i < len ;
 i ++ ) {
 r = avio_r8 ( pb ) ;
 if ( i < buf_size - 1 ) * q ++ = r ;
 }
 if ( buf_size > 0 ) * q = '\0' ;
 }


static void gxf_write_padding(ByteIOContext *pb, offset_t to_pad) { while (to_pad--) { put_byte(pb, 0); } }


void tb_invalidate_page_range(target_ulong start, target_ulong end) { /* XXX: cannot enable it yet because it yields to MMU exception where NIP != read address on PowerPC */ #if 0 target_ulong phys_addr; phys_addr = get_phys_addr_code(env, start); tb_invalidate_phys_page_range(phys_addr, phys_addr + end - start, 0); #endif }


void aio_set_fd_handler(AioContext *ctx, int fd, IOHandler *io_read, IOHandler *io_write, AioFlushHandler *io_flush, void *opaque) { AioHandler *node; node = find_aio_handler(ctx, fd); /* Are we deleting the fd handler? */ if (!io_read && !io_write) { if (node) { /* If the lock is held, just mark the node as deleted */ if (ctx->walking_handlers) node->deleted = 1; 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->fd = fd; QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node); } /* Update handler with latest information */ node->io_read = io_read; node->io_write = io_write; node->io_flush = io_flush; node->opaque = opaque; } }


static int vc1_decode_intra_block ( VC1Context * v , int16_t block [ 64 ] , int n , int coded , int mquant , int codingset ) {
 GetBitContext * gb = & v -> s . gb ;
 MpegEncContext * s = & v -> s ;
 int dc_pred_dir = 0 ;
 int i ;
 int16_t * dc_val ;
 int16_t * ac_val , * ac_val2 ;
 int dcdiff ;
 int mb_pos = s -> mb_x + s -> mb_y * s -> mb_stride ;
 int a_avail = v -> a_avail , c_avail = v -> c_avail ;
 int use_pred = s -> ac_pred ;
 int scale ;
 int q1 , q2 = 0 ;
 s -> dsp . clear_block ( block ) ;
 mquant = ( mquant < 1 ) ? 0 : ( ( mquant > 31 ) ? 31 : mquant ) ;
 s -> y_dc_scale = s -> y_dc_scale_table [ mquant ] ;
 s -> c_dc_scale = s -> c_dc_scale_table [ mquant ] ;
 if ( n < 4 ) {
 dcdiff = get_vlc2 ( & s -> gb , ff_msmp4_dc_luma_vlc [ s -> dc_table_index ] . table , DC_VLC_BITS , 3 ) ;
 }
 else {
 dcdiff = get_vlc2 ( & s -> gb , ff_msmp4_dc_chroma_vlc [ s -> dc_table_index ] . table , DC_VLC_BITS , 3 ) ;
 }
 if ( dcdiff < 0 ) {
 av_log ( s -> avctx , AV_LOG_ERROR , "Illegal DC VLC\n" ) ;
 return - 1 ;
 }
 if ( dcdiff ) {
 if ( dcdiff == 119 ) {
 if ( mquant == 1 ) dcdiff = get_bits ( gb , 10 ) ;
 else if ( mquant == 2 ) dcdiff = get_bits ( gb , 9 ) ;
 else dcdiff = get_bits ( gb , 8 ) ;
 }
 else {
 if ( mquant == 1 ) dcdiff = ( dcdiff << 2 ) + get_bits ( gb , 2 ) - 3 ;
 else if ( mquant == 2 ) dcdiff = ( dcdiff << 1 ) + get_bits1 ( gb ) - 1 ;
 }
 if ( get_bits1 ( gb ) ) dcdiff = - dcdiff ;
 }
 dcdiff += vc1_pred_dc ( & v -> s , v -> overlap , mquant , n , a_avail , c_avail , & dc_val , & dc_pred_dir ) ;
 * dc_val = dcdiff ;
 if ( n < 4 ) {
 block [ 0 ] = dcdiff * s -> y_dc_scale ;
 }
 else {
 block [ 0 ] = dcdiff * s -> c_dc_scale ;
 }
 i = 1 ;
 if ( ! a_avail ) dc_pred_dir = 1 ;
 if ( ! c_avail ) dc_pred_dir = 0 ;
 if ( ! a_avail && ! c_avail ) use_pred = 0 ;
 ac_val = s -> ac_val [ 0 ] [ 0 ] + s -> block_index [ n ] * 16 ;
 ac_val2 = ac_val ;
 scale = mquant * 2 + v -> halfpq ;
 if ( dc_pred_dir ) ac_val -= 16 ;
 else ac_val -= 16 * s -> block_wrap [ n ] ;
 q1 = s -> current_picture . qscale_table [ mb_pos ] ;
 if ( dc_pred_dir && c_avail && mb_pos ) q2 = s -> current_picture . qscale_table [ mb_pos - 1 ] ;
 if ( ! dc_pred_dir && a_avail && mb_pos >= s -> mb_stride ) q2 = s -> current_picture . qscale_table [ mb_pos - s -> mb_stride ] ;
 if ( dc_pred_dir && n == 1 ) q2 = q1 ;
 if ( ! dc_pred_dir && n == 2 ) q2 = q1 ;
 if ( n == 3 ) q2 = q1 ;
 if ( coded ) {
 int last = 0 , skip , value ;
 int k ;
 while ( ! last ) {
 vc1_decode_ac_coeff ( v , & last , & skip , & value , codingset ) ;
 i += skip ;
 if ( i > 63 ) break ;
 if ( v -> fcm == PROGRESSIVE ) block [ v -> zz_8x8 [ 0 ] [ i ++ ] ] = value ;
 else {
 if ( use_pred && ( v -> fcm == ILACE_FRAME ) ) {
 if ( ! dc_pred_dir ) block [ v -> zz_8x8 [ 2 ] [ i ++ ] ] = value ;
 else block [ v -> zz_8x8 [ 3 ] [ i ++ ] ] = value ;
 }
 else {
 block [ v -> zzi_8x8 [ i ++ ] ] = value ;
 }
 }
 }
 if ( use_pred ) {
 if ( q2 && q1 != q2 ) {
 q1 = q1 * 2 + ( ( q1 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 q2 = q2 * 2 + ( ( q2 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 if ( q1 < 1 ) return AVERROR_INVALIDDATA ;
 if ( dc_pred_dir ) {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) block [ k << v -> left_blk_sh ] += ( ac_val [ k ] * q2 * ff_vc1_dqscale [ q1 - 1 ] + 0x20000 ) >> 18 ;
 }
 else {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) block [ k << v -> top_blk_sh ] += ( ac_val [ k + 8 ] * q2 * ff_vc1_dqscale [ q1 - 1 ] + 0x20000 ) >> 18 ;
 }
 }
 else {
 if ( dc_pred_dir ) {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) block [ k << v -> left_blk_sh ] += ac_val [ k ] ;
 }
 else {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) block [ k << v -> top_blk_sh ] += ac_val [ k + 8 ] ;
 }
 }
 }
 for ( k = 1 ;
 k < 8 ;
 k ++ ) {
 ac_val2 [ k ] = block [ k << v -> left_blk_sh ] ;
 ac_val2 [ k + 8 ] = block [ k << v -> top_blk_sh ] ;
 }
 for ( k = 1 ;
 k < 64 ;
 k ++ ) if ( block [ k ] ) {
 block [ k ] *= scale ;
 if ( ! v -> pquantizer ) block [ k ] += ( block [ k ] < 0 ) ? - mquant : mquant ;
 }
 if ( use_pred ) i = 63 ;
 }
 else {
 int k ;
 memset ( ac_val2 , 0 , 16 * 2 ) ;
 if ( dc_pred_dir ) {
 if ( use_pred ) {
 memcpy ( ac_val2 , ac_val , 8 * 2 ) ;
 if ( q2 && q1 != q2 ) {
 q1 = q1 * 2 + ( ( q1 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 q2 = q2 * 2 + ( ( q2 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 if ( q1 < 1 ) return AVERROR_INVALIDDATA ;
 for ( k = 1 ;
 k < 8 ;
 k ++ ) ac_val2 [ k ] = ( ac_val2 [ k ] * q2 * ff_vc1_dqscale [ q1 - 1 ] + 0x20000 ) >> 18 ;
 }
 }
 }
 else {
 if ( use_pred ) {
 memcpy ( ac_val2 + 8 , ac_val + 8 , 8 * 2 ) ;
 if ( q2 && q1 != q2 ) {
 q1 = q1 * 2 + ( ( q1 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 q2 = q2 * 2 + ( ( q2 == v -> pq ) ? v -> halfpq : 0 ) - 1 ;
 if ( q1 < 1 ) return AVERROR_INVALIDDATA ;
 for ( k = 1 ;
 k < 8 ;
 k ++ ) ac_val2 [ k + 8 ] = ( ac_val2 [ k + 8 ] * q2 * ff_vc1_dqscale [ q1 - 1 ] + 0x20000 ) >> 18 ;
 }
 }
 }
 if ( use_pred ) {
 if ( dc_pred_dir ) {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) {
 block [ k << v -> left_blk_sh ] = ac_val2 [ k ] * scale ;
 if ( ! v -> pquantizer && block [ k << v -> left_blk_sh ] ) block [ k << v -> left_blk_sh ] += ( block [ k << v -> left_blk_sh ] < 0 ) ? - mquant : mquant ;
 }
 }
 else {
 for ( k = 1 ;
 k < 8 ;
 k ++ ) {
 block [ k << v -> top_blk_sh ] = ac_val2 [ k + 8 ] * scale ;
 if ( ! v -> pquantizer && block [ k << v -> top_blk_sh ] ) block [ k << v -> top_blk_sh ] += ( block [ k << v -> top_blk_sh ] < 0 ) ? - mquant : mquant ;
 }
 }
 i = 63 ;
 }
 }
 s -> block_last_index [ n ] = i ;
 return 0 ;
 }


static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu)
{
	int ret;

	local_irq_disable();
	ret = __migrate_task(p, src_cpu, dest_cpu);
	local_irq_enable();
	return ret;
}


static unsigned long to_ratio(u64 period, u64 runtime)
{
	if (runtime == RUNTIME_INF)
		return 1ULL << 16;

	return div64_64(runtime << 16, period);
}


fz_colorspace * fz_device_bgr ( fz_context * ctx ) {
 return ctx -> colorspace -> bgr ;
 }


static int bochs_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { int ret; while (nb_sectors > 0) { int64_t block_offset = seek_to_sector(bs, sector_num); if (block_offset >= 0) { ret = bdrv_pread(bs->file, block_offset, buf, 512); if (ret != 512) { return -1; } } else memset(buf, 0, 512); nb_sectors--; sector_num++; buf += 512; } return 0; }


static void visit_nested_struct_list(Visitor *v, void **native, Error **errp) { visit_type_UserDefNestedList(v, (UserDefNestedList **)native, NULL, errp); }


static void arch_destroy_sched_domains(const cpumask_t *cpu_map,
				       cpumask_t *tmpmask)
{
	free_sched_groups(cpu_map, tmpmask);
}


void account_steal_time(struct task_struct *p, cputime_t steal)
{
	struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
	cputime64_t tmp = cputime_to_cputime64(steal);
	struct rq *rq = this_rq();

	if (p == rq->idle) {
		p->stime = cputime_add(p->stime, steal);
		if (atomic_read(&rq->nr_iowait) > 0)
			cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
		else
			cpustat->idle = cputime64_add(cpustat->idle, tmp);
	} else
		cpustat->steal = cputime64_add(cpustat->steal, tmp);
}


static inline void softusb_read_pmem(MilkymistSoftUsbState *s, uint32_t offset, uint8_t *buf, uint32_t len) { if (offset + len >= s->pmem_size) { error_report("milkymist_softusb: read pmem out of bounds " "at offset 0x%x, len %d", offset, len); return; } memcpy(buf, s->pmem_ptr + offset, len); }


static gboolean lacks_deep_count ( NautilusFile * file ) {
 return file -> details -> deep_counts_status != NAUTILUS_REQUEST_DONE ;
 }


static struct task_struct *load_balance_start_fair(void *arg)
{
	struct cfs_rq *cfs_rq = arg;

	return __load_balance_iterator(cfs_rq, cfs_rq->tasks.next);
}


static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
{
}


static inline void schedule_debug(struct task_struct *prev)
{
	/*
	 * Test if we are atomic. Since do_exit() needs to call into
	 * schedule() atomically, we ignore that path for now.
	 * Otherwise, whine if we are scheduling when we should not be.
	 */
	if (unlikely(in_atomic_preempt_off()) && unlikely(!prev->exit_state))
		__schedule_bug(prev);

	profile_hit(SCHED_PROFILING, __builtin_return_address(0));

	schedstat_inc(this_rq(), sched_count);
#ifdef CONFIG_SCHEDSTATS
	if (unlikely(prev->lock_depth >= 0)) {
		schedstat_inc(this_rq(), bkl_count);
		schedstat_inc(prev, sched_info.bkl_count);
	}
#endif
}


static void xhci_init_epctx ( XHCIEPContext * epctx , dma_addr_t pctx , uint32_t * ctx ) {
 dma_addr_t dequeue ;
 dequeue = xhci_addr64 ( ctx [ 2 ] & ~ 0xf , ctx [ 3 ] ) ;
 epctx -> type = ( ctx [ 1 ] >> EP_TYPE_SHIFT ) & EP_TYPE_MASK ;
 epctx -> pctx = pctx ;
 epctx -> max_psize = ctx [ 1 ] >> 16 ;
 epctx -> max_psize *= 1 + ( ( ctx [ 1 ] >> 8 ) & 0xff ) ;
 epctx -> max_pstreams = ( ctx [ 0 ] >> 10 ) & epctx -> xhci -> max_pstreams_mask ;
 epctx -> lsa = ( ctx [ 0 ] >> 15 ) & 1 ;
 if ( epctx -> max_pstreams ) {
 xhci_alloc_streams ( epctx , dequeue ) ;
 }
 else {
 xhci_ring_init ( epctx -> xhci , & epctx -> ring , dequeue ) ;
 epctx -> ring . ccs = ctx [ 2 ] & 1 ;
 }
 epctx -> interval = 1 << ( ( ctx [ 0 ] >> 16 ) & 0xff ) ;
 }


static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num, uint8_t devfn, VTDContextEntry *ce) { VTDRootEntry re; int ret_fr; X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s); ret_fr = vtd_get_root_entry(s, bus_num, &re); if (ret_fr) { return ret_fr; } if (!vtd_root_entry_present(&re)) { /* Not error - it's okay we don't have root entry. */ trace_vtd_re_not_present(bus_num); return -VTD_FR_ROOT_ENTRY_P; } if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD(VTD_HOST_ADDRESS_WIDTH))) { trace_vtd_re_invalid(re.rsvd, re.val); return -VTD_FR_ROOT_ENTRY_RSVD; } ret_fr = vtd_get_context_entry_from_root(&re, devfn, ce); if (ret_fr) { return ret_fr; } if (!vtd_ce_present(ce)) { /* Not error - it's okay we don't have context entry. */ trace_vtd_ce_not_present(bus_num, devfn); return -VTD_FR_CONTEXT_ENTRY_P; } if ((ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI) || (ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO(VTD_HOST_ADDRESS_WIDTH))) { trace_vtd_ce_invalid(ce->hi, ce->lo); return -VTD_FR_CONTEXT_ENTRY_RSVD; } /* Check if the programming of context-entry is valid */ if (!vtd_is_level_supported(s, vtd_ce_get_level(ce))) { trace_vtd_ce_invalid(ce->hi, ce->lo); return -VTD_FR_CONTEXT_ENTRY_INV; } /* Do translation type check */ if (!vtd_ce_type_check(x86_iommu, ce)) { trace_vtd_ce_invalid(ce->hi, ce->lo); return -VTD_FR_CONTEXT_ENTRY_INV; } return 0; }


gnutls_handshake_get_last_out (gnutls_session_t session)
{
  return session->internals.last_handshake_out;
}


void exsltSaxonRegister ( void ) {
 xsltRegisterExtModule ( SAXON_NAMESPACE , ( xsltExtInitFunction ) exsltSaxonInit , ( xsltExtShutdownFunction ) exsltSaxonShutdown ) ;
 xsltRegisterExtModuleFunction ( ( const xmlChar * ) "expression" , SAXON_NAMESPACE , exsltSaxonExpressionFunction ) ;
 xsltRegisterExtModuleFunction ( ( const xmlChar * ) "eval" , SAXON_NAMESPACE , exsltSaxonEvalFunction ) ;
 xsltRegisterExtModuleFunction ( ( const xmlChar * ) "evaluate" , SAXON_NAMESPACE , exsltSaxonEvaluateFunction ) ;
 xsltRegisterExtModuleFunction ( ( const xmlChar * ) "line-number" , SAXON_NAMESPACE , exsltSaxonLineNumberFunction ) ;
 }


static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; a0 = col[8*0]; a1 = col[8*1]; a2 = col[8*2]; a3 = col[8*3]; c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1)); c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)]; }


void bdrv_detach_aio_context(BlockDriverState *bs) { BdrvAioNotifier *baf; BdrvChild *child; if (!bs->drv) { return; } QLIST_FOREACH(baf, &bs->aio_notifiers, list) { baf->detach_aio_context(baf->opaque); } if (bs->drv->bdrv_detach_aio_context) { bs->drv->bdrv_detach_aio_context(bs); } QLIST_FOREACH(child, &bs->children, next) { bdrv_detach_aio_context(child->bs); } bs->aio_context = NULL; }


static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, bool is_listen, bool is_telnet, bool is_waitconnect, Error **errp) { CharDriverState *chr = NULL; TCPCharDriver *s = NULL; char host[NI_MAXHOST], serv[NI_MAXSERV]; const char *left = "", *right = ""; struct sockaddr_storage ss; socklen_t ss_len = sizeof(ss); memset(&ss, 0, ss_len); if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) != 0) { error_setg_errno(errp, errno, "getsockname"); return NULL; } chr = g_malloc0(sizeof(CharDriverState)); s = g_malloc0(sizeof(TCPCharDriver)); s->connected = 0; s->fd = -1; s->listen_fd = -1; s->read_msgfds = 0; s->read_msgfds_num = 0; s->write_msgfds = 0; s->write_msgfds_num = 0; chr->filename = g_malloc(256); switch (ss.ss_family) { #ifndef _WIN32 case AF_UNIX: s->is_unix = 1; snprintf(chr->filename, 256, "unix:%s%s", ((struct sockaddr_un *)(&ss))->sun_path, is_listen ? ",server" : ""); break; #endif case AF_INET6: left = "["; right = "]"; /* fall through */ case AF_INET: s->do_nodelay = do_nodelay; getnameinfo((struct sockaddr *) &ss, ss_len, host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV); snprintf(chr->filename, 256, "%s:%s%s%s:%s%s", is_telnet ? "telnet" : "tcp", left, host, right, serv, is_listen ? ",server" : ""); break; } chr->opaque = s; chr->chr_write = tcp_chr_write; chr->chr_sync_read = tcp_chr_sync_read; chr->chr_close = tcp_chr_close; chr->get_msgfds = tcp_get_msgfds; chr->set_msgfds = tcp_set_msgfds; chr->chr_add_client = tcp_chr_add_client; chr->chr_add_watch = tcp_chr_add_watch; chr->chr_update_read_handler = tcp_chr_update_read_handler; /* be isn't opened until we get a connection */ chr->explicit_be_open = true; if (is_listen) { s->listen_fd = fd; s->listen_chan = io_channel_from_socket(s->listen_fd); s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN, tcp_chr_accept, chr); if (is_telnet) { s->do_telnetopt = 1; } } else { s->connected = 1; s->fd = fd; socket_set_nodelay(fd); s->chan = io_channel_from_socket(s->fd); tcp_chr_connect(chr); } if (is_listen && is_waitconnect) { fprintf(stderr, "QEMU waiting for connection on: %s\n", chr->filename); tcp_chr_accept(s->listen_chan, G_IO_IN, chr); qemu_set_nonblock(s->listen_fd); } return chr; }


static void dhcp_decode(const struct bootp_t *bp, int *pmsg_type, const struct in_addr **preq_addr) { const uint8_t *p, *p_end; int len, tag; *pmsg_type = 0; *preq_addr = NULL; p = bp->bp_vend; p_end = p + DHCP_OPT_LEN; if (memcmp(p, rfc1533_cookie, 4) != 0) return; p += 4; while (p < p_end) { tag = p[0]; if (tag == RFC1533_PAD) { p++; } else if (tag == RFC1533_END) { break; } else { p++; if (p >= p_end) break; len = *p++; DPRINTF("dhcp: tag=%d len=%d\n", tag, len); switch(tag) { case RFC2132_MSG_TYPE: if (len >= 1) *pmsg_type = p[0]; break; case RFC2132_REQ_ADDR: if (len >= 4) *preq_addr = (struct in_addr *)p; break; default: break; } p += len; } } if (*pmsg_type == DHCPREQUEST && !*preq_addr && bp->bp_ciaddr.s_addr) { *preq_addr = &bp->bp_ciaddr; } }


av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { ff_rv34dsp_init(c, dsp); c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0]; c->put_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c; c->put_pixels_tab[0][ 2] = dsp->put_h264_qpel_pixels_tab[0][2]; c->put_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c; c->put_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c; c->put_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c; c->put_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c; c->put_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c; c->put_pixels_tab[0][ 8] = dsp->put_h264_qpel_pixels_tab[0][8]; c->put_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c; c->put_pixels_tab[0][10] = put_rv40_qpel16_mc22_c; c->put_pixels_tab[0][11] = put_rv40_qpel16_mc32_c; c->put_pixels_tab[0][12] = put_rv40_qpel16_mc03_c; c->put_pixels_tab[0][13] = put_rv40_qpel16_mc13_c; c->put_pixels_tab[0][14] = put_rv40_qpel16_mc23_c; c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_c; c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0]; c->avg_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c; c->avg_pixels_tab[0][ 2] = dsp->avg_h264_qpel_pixels_tab[0][2]; c->avg_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c; c->avg_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c; c->avg_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c; c->avg_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c; c->avg_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c; c->avg_pixels_tab[0][ 8] = dsp->avg_h264_qpel_pixels_tab[0][8]; c->avg_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c; c->avg_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c; c->avg_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c; c->avg_pixels_tab[0][12] = avg_rv40_qpel16_mc03_c; c->avg_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c; c->avg_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c; c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_c; c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0]; c->put_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c; c->put_pixels_tab[1][ 2] = dsp->put_h264_qpel_pixels_tab[1][2]; c->put_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c; c->put_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c; c->put_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c; c->put_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c; c->put_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c; c->put_pixels_tab[1][ 8] = dsp->put_h264_qpel_pixels_tab[1][8]; c->put_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c; c->put_pixels_tab[1][10] = put_rv40_qpel8_mc22_c; c->put_pixels_tab[1][11] = put_rv40_qpel8_mc32_c; c->put_pixels_tab[1][12] = put_rv40_qpel8_mc03_c; c->put_pixels_tab[1][13] = put_rv40_qpel8_mc13_c; c->put_pixels_tab[1][14] = put_rv40_qpel8_mc23_c; c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_c; c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0]; c->avg_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c; c->avg_pixels_tab[1][ 2] = dsp->avg_h264_qpel_pixels_tab[1][2]; c->avg_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c; c->avg_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c; c->avg_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c; c->avg_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c; c->avg_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c; c->avg_pixels_tab[1][ 8] = dsp->avg_h264_qpel_pixels_tab[1][8]; c->avg_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c; c->avg_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c; c->avg_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c; c->avg_pixels_tab[1][12] = avg_rv40_qpel8_mc03_c; c->avg_pixels_tab[1][13] = avg_rv40_qpel8_mc13_c; c->avg_pixels_tab[1][14] = avg_rv40_qpel8_mc23_c; c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_c; c->put_chroma_pixels_tab[0] = put_rv40_chroma_mc8_c; c->put_chroma_pixels_tab[1] = put_rv40_chroma_mc4_c; c->avg_chroma_pixels_tab[0] = avg_rv40_chroma_mc8_c; c->avg_chroma_pixels_tab[1] = avg_rv40_chroma_mc4_c; c->rv40_weight_pixels_tab[0][0] = rv40_weight_func_rnd_16; c->rv40_weight_pixels_tab[0][1] = rv40_weight_func_rnd_8; c->rv40_weight_pixels_tab[1][0] = rv40_weight_func_nornd_16; c->rv40_weight_pixels_tab[1][1] = rv40_weight_func_nornd_8; c->rv40_weak_loop_filter[0] = rv40_h_weak_loop_filter; c->rv40_weak_loop_filter[1] = rv40_v_weak_loop_filter; c->rv40_strong_loop_filter[0] = rv40_h_strong_loop_filter; c->rv40_strong_loop_filter[1] = rv40_v_strong_loop_filter; c->rv40_loop_filter_strength[0] = rv40_h_loop_filter_strength; c->rv40_loop_filter_strength[1] = rv40_v_loop_filter_strength; if (ARCH_X86) ff_rv40dsp_init_x86(c, dsp); if (HAVE_NEON) ff_rv40dsp_init_neon(c, dsp); }


_gnutls_send_handshake_final (gnutls_session_t session, int init)
{
  int ret = 0;

  /* Send the CHANGE CIPHER SPEC PACKET */

  switch (STATE)
    {
    case STATE0:
    case STATE20:
      ret = _gnutls_send_change_cipher_spec (session, AGAIN (STATE20));
      STATE = STATE20;
      if (ret < 0)
	{
	  ERR ("send ChangeCipherSpec", ret);
	  gnutls_assert ();
	  return ret;
	}

      /* Initialize the connection session (start encryption) - in case of client
       */
      if (init == TRUE)
	{
	  ret = _gnutls_connection_state_init (session);
	  if (ret < 0)
	    {
	      gnutls_assert ();
	      return ret;
	    }
	}

      ret = _gnutls_write_connection_state_init (session);
      if (ret < 0)
	{
	  gnutls_assert ();
	  return ret;
	}

    case STATE21:
      /* send the finished message */
      ret = _gnutls_send_finished (session, AGAIN (STATE21));
      STATE = STATE21;
      if (ret < 0)
	{
	  ERR ("send Finished", ret);
	  gnutls_assert ();
	  return ret;
	}

      STATE = STATE0;
    default:
      break;
    }

  return 0;
}


void SFDefaultOS2Info ( struct pfminfo * pfminfo , SplineFont * sf , char * fontname ) {
 int samewid = - 1 ;
 char * weight = sf -> cidmaster == NULL ? sf -> weight : sf -> cidmaster -> weight ;
 if ( sf -> pfminfo . pfmset ) {
 if ( pfminfo != & sf -> pfminfo ) * pfminfo = sf -> pfminfo ;
 if ( ! pfminfo -> panose_set ) {
 struct pfminfo info ;
 memset ( & info , 0 , sizeof ( info ) ) ;
 sf -> pfminfo . pfmset = false ;
 SFDefaultOS2Info ( & info , sf , fontname ) ;
 sf -> pfminfo . pfmset = true ;
 memcpy ( pfminfo -> panose , info . panose , sizeof ( info . panose ) ) ;
 }
 }
 else {
 struct pfminfo hold ;
 if ( pfminfo -> hheadset || pfminfo -> vheadset ) hold = * pfminfo ;
 else hold . hheadset = hold . vheadset = false ;
 memset ( pfminfo , '\0' , sizeof ( * pfminfo ) ) ;
 SFDefaultOS2Simple ( pfminfo , sf ) ;
 samewid = CIDOneWidth ( sf ) ;
 pfminfo -> pfmfamily = 0x10 ;
 if ( samewid > 0 ) {
 pfminfo -> pfmfamily = 0x30 ;
 }
 else if ( strstrmatch ( fontname , "sans" ) != NULL ) pfminfo -> pfmfamily = 0x20 ;
 else if ( strstrmatch ( fontname , "script" ) != NULL ) {
 pfminfo -> pfmfamily = 0x40 ;
 pfminfo -> panose [ 0 ] = 3 ;
 }
 if ( samewid == - 1 ) pfminfo -> pfmfamily |= 0x1 ;
 if ( weight != NULL ) OS2WeightCheck ( pfminfo , weight ) ;
 OS2WeightCheck ( pfminfo , fontname ) ;
 if ( strstrmatch ( fontname , "ultra" ) != NULL && strstrmatch ( fontname , "condensed" ) != NULL ) {
 pfminfo -> width = 1 ;
 pfminfo -> panose [ 3 ] = 8 ;
 }
 else if ( strstrmatch ( fontname , "extra" ) != NULL && strstrmatch ( fontname , "condensed" ) != NULL ) {
 pfminfo -> width = 2 ;
 pfminfo -> panose [ 3 ] = 8 ;
 }
 else if ( strstrmatch ( fontname , "semi" ) != NULL && strstrmatch ( fontname , "condensed" ) != NULL ) {
 pfminfo -> width = 4 ;
 pfminfo -> panose [ 3 ] = 6 ;
 }
 else if ( strstrmatch ( fontname , "condensed" ) != NULL || strstrmatch ( fontname , "narrow" ) != NULL ) {
 pfminfo -> width = 3 ;
 pfminfo -> panose [ 3 ] = 6 ;
 }
 else if ( strstrmatch ( fontname , "ultra" ) != NULL && strstrmatch ( fontname , "expanded" ) != NULL ) {
 pfminfo -> width = 9 ;
 pfminfo -> panose [ 3 ] = 7 ;
 }
 else if ( strstrmatch ( fontname , "extra" ) != NULL && strstrmatch ( fontname , "expanded" ) != NULL ) {
 pfminfo -> width = 8 ;
 pfminfo -> panose [ 3 ] = 7 ;
 }
 else if ( strstrmatch ( fontname , "semi" ) != NULL && strstrmatch ( fontname , "expanded" ) != NULL ) {
 pfminfo -> width = 6 ;
 pfminfo -> panose [ 3 ] = 5 ;
 }
 else if ( strstrmatch ( fontname , "expanded" ) != NULL ) {
 pfminfo -> width = 7 ;
 pfminfo -> panose [ 3 ] = 5 ;
 }
 if ( samewid > 0 ) pfminfo -> panose [ 3 ] = 9 ;
 if ( hold . hheadset ) {
 pfminfo -> hheadset = true ;
 pfminfo -> hheadascent_add = hold . hheadascent_add ;
 pfminfo -> hheaddescent_add = hold . hheaddescent_add ;
 pfminfo -> hhead_ascent = hold . hhead_ascent ;
 pfminfo -> hhead_descent = hold . hhead_descent ;
 pfminfo -> linegap = hold . linegap ;
 }
 if ( hold . vheadset ) {
 pfminfo -> vheadset = true ;
 pfminfo -> vlinegap = hold . vlinegap ;
 }
 }
 if ( ! pfminfo -> subsuper_set ) SFDefaultOS2SubSuper ( pfminfo , sf -> ascent + sf -> descent , sf -> italicangle ) ;
 }


gnutls_handshake_set_max_packet_length (gnutls_session_t session, size_t max)
{
  session->internals.max_handshake_data_buffer_size = max;
}


static bool check_address_object ( ts_type_t ts_type , chunk_t object ) {
 switch ( ts_type ) {
 case TS_IPV4_ADDR_RANGE : if ( object . len > 5 ) {
 DBG1 ( DBG_ASN , "IPv4 address object is larger than 5 octets" ) ;
 return FALSE ;
 }
 break ;
 case TS_IPV6_ADDR_RANGE : if ( object . len > 17 ) {
 DBG1 ( DBG_ASN , "IPv6 address object is larger than 17 octets" ) ;
 return FALSE ;
 }
 break ;
 default : DBG1 ( DBG_ASN , "unknown address family" ) ;
 return FALSE ;
 }
 if ( object . len == 0 ) {
 DBG1 ( DBG_ASN , "An ASN.1 bit string must contain at least the " "initial octet" ) ;
 return FALSE ;
 }
 if ( object . len == 1 && object . ptr [ 0 ] != 0 ) {
 DBG1 ( DBG_ASN , "An empty ASN.1 bit string must contain a zero " "initial octet" ) ;
 return FALSE ;
 }
 if ( object . ptr [ 0 ] > 7 ) {
 DBG1 ( DBG_ASN , "number of unused bits is too large" ) ;
 return FALSE ;
 }
 return TRUE ;
 }


_gnutls_recv_handshake_header (gnutls_session_t session,
			       gnutls_handshake_description_t type,
			       gnutls_handshake_description_t * recv_type)
{
  int ret;
  uint32_t length32 = 0;
  uint8_t *dataptr = NULL;	/* for realloc */
  size_t handshake_header_size = HANDSHAKE_HEADER_SIZE;

  /* if we have data into the buffer then return them, do not read the next packet.
   * In order to return we need a full TLS handshake header, or in case of a version 2
   * packet, then we return the first byte.
   */
  if (session->internals.handshake_header_buffer.header_size ==
      handshake_header_size || (session->internals.v2_hello != 0
				&& type == GNUTLS_HANDSHAKE_CLIENT_HELLO
				&& session->internals.
				handshake_header_buffer.packet_length > 0))
    {

      *recv_type = session->internals.handshake_header_buffer.recv_type;

      if (*recv_type != type)
	{
	  gnutls_assert ();
	  _gnutls_handshake_log
	    ("HSK[%x]: Handshake type mismatch (under attack?)\n", session);
	  return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
	}

      return session->internals.handshake_header_buffer.packet_length;
    }

  /* Note: SSL2_HEADERS == 1 */

  dataptr = session->internals.handshake_header_buffer.header;

  /* If we haven't already read the handshake headers.
   */
  if (session->internals.handshake_header_buffer.header_size < SSL2_HEADERS)
    {
      ret =
	_gnutls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE,
				       type, dataptr, SSL2_HEADERS);

      if (ret < 0)
	{
	  gnutls_assert ();
	  return ret;
	}

      /* The case ret==0 is caught here.
       */
      if (ret != SSL2_HEADERS)
	{
	  gnutls_assert ();
	  return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
	}
      session->internals.handshake_header_buffer.header_size = SSL2_HEADERS;
    }

  if (session->internals.v2_hello == 0
      || type != GNUTLS_HANDSHAKE_CLIENT_HELLO)
    {
      ret =
	_gnutls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE,
				       type,
				       &dataptr[session->
						internals.
						handshake_header_buffer.
						header_size],
				       HANDSHAKE_HEADER_SIZE -
				       session->internals.
				       handshake_header_buffer.header_size);
      if (ret <= 0)
	{
	  gnutls_assert ();
	  return (ret < 0) ? ret : GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
	}
      if ((size_t) ret !=
	  HANDSHAKE_HEADER_SIZE -
	  session->internals.handshake_header_buffer.header_size)
	{
	  gnutls_assert ();
	  return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
	}
      *recv_type = dataptr[0];

      /* we do not use DECR_LEN because we know
       * that the packet has enough data.
       */
      length32 = _gnutls_read_uint24 (&dataptr[1]);
      handshake_header_size = HANDSHAKE_HEADER_SIZE;

      _gnutls_handshake_log ("HSK[%x]: %s was received [%ld bytes]\n",
			     session, _gnutls_handshake2str (dataptr[0]),
			     length32 + HANDSHAKE_HEADER_SIZE);

    }
  else
    {				/* v2 hello */
      length32 = session->internals.v2_hello - SSL2_HEADERS;	/* we've read the first byte */

      handshake_header_size = SSL2_HEADERS;	/* we've already read one byte */

      *recv_type = dataptr[0];

      _gnutls_handshake_log ("HSK[%x]: %s(v2) was received [%ld bytes]\n",
			     session, _gnutls_handshake2str (*recv_type),
			     length32 + handshake_header_size);

      if (*recv_type != GNUTLS_HANDSHAKE_CLIENT_HELLO)
	{			/* it should be one or nothing */
	  gnutls_assert ();
	  return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
	}
    }

  /* put the packet into the buffer */
  session->internals.handshake_header_buffer.header_size =
    handshake_header_size;
  session->internals.handshake_header_buffer.packet_length = length32;
  session->internals.handshake_header_buffer.recv_type = *recv_type;

  if (*recv_type != type)
    {
      gnutls_assert ();
      return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
    }

  return length32;
}


static vpx_codec_err_t parse_layer_options_from_string ( SvcContext * svc_ctx , LAYER_OPTION_TYPE type , const char * input , int * option0 , int * option1 ) {
 int i ;
 vpx_codec_err_t res = VPX_CODEC_OK ;
 char * input_string ;
 char * token ;
 const char * delim = "," ;
 char * save_ptr ;
 if ( input == NULL || option0 == NULL || ( option1 == NULL && type == SCALE_FACTOR ) ) return VPX_CODEC_INVALID_PARAM ;
 input_string = strdup ( input ) ;
 token = strtok_r ( input_string , delim , & save_ptr ) ;
 for ( i = 0 ;
 i < svc_ctx -> spatial_layers ;
 ++ i ) {
 if ( token != NULL ) {
 res = extract_option ( type , token , option0 + i , option1 + i ) ;
 if ( res != VPX_CODEC_OK ) break ;
 token = strtok_r ( NULL , delim , & save_ptr ) ;
 }
 else {
 break ;
 }
 }
 if ( res == VPX_CODEC_OK && i != svc_ctx -> spatial_layers ) {
 svc_log ( svc_ctx , SVC_LOG_ERROR , "svc: layer params type: %d %d values required, " "but only %d specified\n" , type , svc_ctx -> spatial_layers , i ) ;
 res = VPX_CODEC_INVALID_PARAM ;
 }
 free ( input_string ) ;
 return res ;
 }


static int RENAME(swScale)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { /* load a few things into local vars to make the code more readable? and faster */ const int srcW= c->srcW; const int dstW= c->dstW; const int dstH= c->dstH; const int chrDstW= c->chrDstW; const int chrSrcW= c->chrSrcW; const int lumXInc= c->lumXInc; const int chrXInc= c->chrXInc; const enum PixelFormat dstFormat= c->dstFormat; const int flags= c->flags; int16_t *vLumFilterPos= c->vLumFilterPos; int16_t *vChrFilterPos= c->vChrFilterPos; int16_t *hLumFilterPos= c->hLumFilterPos; int16_t *hChrFilterPos= c->hChrFilterPos; int16_t *vLumFilter= c->vLumFilter; int16_t *vChrFilter= c->vChrFilter; int16_t *hLumFilter= c->hLumFilter; int16_t *hChrFilter= c->hChrFilter; int32_t *lumMmxFilter= c->lumMmxFilter; int32_t *chrMmxFilter= c->chrMmxFilter; int32_t av_unused *alpMmxFilter= c->alpMmxFilter; const int vLumFilterSize= c->vLumFilterSize; const int vChrFilterSize= c->vChrFilterSize; const int hLumFilterSize= c->hLumFilterSize; const int hChrFilterSize= c->hChrFilterSize; int16_t **lumPixBuf= c->lumPixBuf; int16_t **chrPixBuf= c->chrPixBuf; int16_t **alpPixBuf= c->alpPixBuf; const int vLumBufSize= c->vLumBufSize; const int vChrBufSize= c->vChrBufSize; uint8_t *formatConvBuffer= c->formatConvBuffer; const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); int lastDstY; uint32_t *pal=c->pal_yuv; /* vars which will change and which we need to store back in the context */ int dstY= c->dstY; int lumBufIndex= c->lumBufIndex; int chrBufIndex= c->chrBufIndex; int lastInLumBuf= c->lastInLumBuf; int lastInChrBuf= c->lastInChrBuf; if (isPacked(c->srcFormat)) { src[0]= src[1]= src[2]= src[3]= src[0]; srcStride[0]= srcStride[1]= srcStride[2]= srcStride[3]= srcStride[0]; } srcStride[1]<<= c->vChrDrop; srcStride[2]<<= c->vChrDrop; DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n", src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3], dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]); DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n", srcSliceY, srcSliceH, dstY, dstH); DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n", vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize); if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) { static int warnedAlready=0; //FIXME move this into the context perhaps if (flags & SWS_PRINT_INFO && !warnedAlready) { av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n" " ->cannot do aligned memory accesses anymore\n"); warnedAlready=1; } } /* Note the user might start scaling the picture in the middle so this will not get executed. This is not really intended but works currently, so people might do it. */ if (srcSliceY ==0) { lumBufIndex=-1; chrBufIndex=-1; dstY=0; lastInLumBuf= -1; lastInChrBuf= -1; } lastDstY= dstY; for (;dstY < dstH; dstY++) { unsigned char *dest =dst[0]+dstStride[0]*dstY; const int chrDstY= dstY>>c->chrDstVSubSample; unsigned char *uDest=dst[1]+dstStride[1]*chrDstY; unsigned char *vDest=dst[2]+dstStride[2]*chrDstY; unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL; const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)]; const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input int enough_lines; //handle holes (FAST_BILINEAR & weird filters) if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1); assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1); DEBUG_BUFFERS("dstY: %d\n", dstY); DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n", firstLumSrcY, lastLumSrcY, lastInLumBuf); DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n", firstChrSrcY, lastChrSrcY, lastInChrBuf); // Do we have enough lines in this slice to output the dstY line enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample); if (!enough_lines) { lastLumSrcY = srcSliceY + srcSliceH - 1; lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1; DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n", lastLumSrcY, lastChrSrcY); } //Do horizontal scaling while(lastInLumBuf < lastLumSrcY) { const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3]; lumBufIndex++; assert(lumBufIndex < 2*vLumBufSize); assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); assert(lastInLumBuf + 1 - srcSliceY >= 0); RENAME(hyscale)(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize, formatConvBuffer, pal, 0); if (CONFIG_SWSCALE_ALPHA && alpPixBuf) RENAME(hyscale)(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW, lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize, formatConvBuffer, pal, 1); lastInLumBuf++; DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n", lumBufIndex, lastInLumBuf); } while(lastInChrBuf < lastChrSrcY) { const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; chrBufIndex++; assert(chrBufIndex < 2*vChrBufSize); assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)); assert(lastInChrBuf + 1 - chrSrcSliceY >= 0); //FIXME replace parameters through context struct (some at least) if (c->needs_hcscale) RENAME(hcscale)(c, chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, hChrFilter, hChrFilterPos, hChrFilterSize, formatConvBuffer, pal); lastInChrBuf++; DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n", chrBufIndex, lastInChrBuf); } //wrap buf index around to stay inside the ring buffer if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; if (!enough_lines) break; //we can't output a dstY line so let's try with the next slice #if COMPILE_TEMPLATE_MMX c->blueDither= ff_dither8[dstY&1]; if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) c->greenDither= ff_dither8[dstY&1]; else c->greenDither= ff_dither4[dstY&1]; c->redDither= ff_dither8[(dstY+1)&1]; #endif if (dstY < dstH-2) { const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; const int16_t **chrSrcPtr= (const int16_t **) chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; #if COMPILE_TEMPLATE_MMX int i; if (flags & SWS_ACCURATE_RND) { int s= APCK_SIZE / 8; for (i=0; i<vLumFilterSize; i+=2) { *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ]; *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)]; lumMmxFilter[s*i+APCK_COEF/4 ]= lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; alpMmxFilter[s*i+APCK_COEF/4 ]= alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; } } for (i=0; i<vChrFilterSize; i+=2) { *(const void**)&chrMmxFilter[s*i ]= chrSrcPtr[i ]; *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrSrcPtr[i+(vChrFilterSize>1)]; chrMmxFilter[s*i+APCK_COEF/4 ]= chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); } } else { for (i=0; i<vLumFilterSize; i++) { lumMmxFilter[4*i+0]= (int32_t)lumSrcPtr[i]; lumMmxFilter[4*i+1]= (uint64_t)lumSrcPtr[i] >> 32; lumMmxFilter[4*i+2]= lumMmxFilter[4*i+3]= ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001; if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { alpMmxFilter[4*i+0]= (int32_t)alpSrcPtr[i]; alpMmxFilter[4*i+1]= (uint64_t)alpSrcPtr[i] >> 32; alpMmxFilter[4*i+2]= alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2]; } } for (i=0; i<vChrFilterSize; i++) { chrMmxFilter[4*i+0]= (int32_t)chrSrcPtr[i]; chrMmxFilter[4*i+1]= (uint64_t)chrSrcPtr[i] >> 32; chrMmxFilter[4*i+2]= chrMmxFilter[4*i+3]= ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001; } } #endif if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) { const int chrSkipMask= (1<<c->chrDstVSubSample)-1; if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi c->yuv2nv12X(c, vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, dest, uDest, dstW, chrDstW, dstFormat); } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like const int chrSkipMask= (1<<c->chrDstVSubSample)-1; if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi if (is16BPS(dstFormat) || isNBPS(dstFormat)) { yuv2yuvX16inC( vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW, dstFormat); } else if (vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12 const int16_t *lumBuf = lumSrcPtr[0]; const int16_t *chrBuf= chrSrcPtr[0]; const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL; c->yuv2yuv1(c, lumBuf, chrBuf, alpBuf, dest, uDest, vDest, aDest, dstW, chrDstW); } else { //General YV12 c->yuv2yuvX(c, vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW); } } else { assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); assert(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); if (vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB int chrAlpha= vChrFilter[2*dstY+1]; if(flags & SWS_FULL_CHR_H_INT) { yuv2rgbXinC_full(c, //FIXME write a packed1_full function vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } else { c->yuv2packed1(c, *lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1), alpPixBuf ? *alpSrcPtr : NULL, dest, dstW, chrAlpha, dstFormat, flags, dstY); } } else if (vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB int lumAlpha= vLumFilter[2*dstY+1]; int chrAlpha= vChrFilter[2*dstY+1]; lumMmxFilter[2]= lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001; chrMmxFilter[2]= chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001; if(flags & SWS_FULL_CHR_H_INT) { yuv2rgbXinC_full(c, //FIXME write a packed2_full function vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } else { c->yuv2packed2(c, *lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1), alpPixBuf ? *alpSrcPtr : NULL, alpPixBuf ? *(alpSrcPtr+1) : NULL, dest, dstW, lumAlpha, chrAlpha, dstY); } } else { //general RGB if(flags & SWS_FULL_CHR_H_INT) { yuv2rgbXinC_full(c, vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } else { c->yuv2packedX(c, vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } } } } else { // hmm looks like we can't use MMX here without overwriting this array's tail const int16_t **lumSrcPtr= (const int16_t **)lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; const int16_t **chrSrcPtr= (const int16_t **)chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) { const int chrSkipMask= (1<<c->chrDstVSubSample)-1; if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi yuv2nv12XinC( vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, dest, uDest, dstW, chrDstW, dstFormat); } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 const int chrSkipMask= (1<<c->chrDstVSubSample)-1; if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi if (is16BPS(dstFormat) || isNBPS(dstFormat)) { yuv2yuvX16inC( vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW, dstFormat); } else { yuv2yuvXinC( vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW); } } else { assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); assert(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); if(flags & SWS_FULL_CHR_H_INT) { yuv2rgbXinC_full(c, vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } else { yuv2packedXinC(c, vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } } } } if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf) fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255); #if COMPILE_TEMPLATE_MMX if (flags & SWS_CPU_CAPS_MMX2 ) __asm__ volatile("sfence":::"memory"); /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ if (flags & SWS_CPU_CAPS_3DNOW) __asm__ volatile("femms" :::"memory"); else __asm__ volatile("emms" :::"memory"); #endif /* store changed local vars back in the context */ c->dstY= dstY; c->lumBufIndex= lumBufIndex; c->chrBufIndex= chrBufIndex; c->lastInLumBuf= lastInLumBuf; c->lastInChrBuf= lastInChrBuf; return dstY - lastDstY; }