static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) { H264Context *h = &svq3->h; int i, j, k, m, dir, mode; int cbp = 0; uint32_t vlc; int8_t *top, *left; MpegEncContext *const s = (MpegEncContext *) h; const int mb_xy = h->mb_xy; const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF; h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF; h->topright_samples_available = 0xFFFF; if (mb_type == 0) { /* SKIP */ if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.f.mb_type[mb_xy] == -1) { svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0); if (s->pict_type == AV_PICTURE_TYPE_B) { svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1); } mb_type = MB_TYPE_SKIP; } else { mb_type = FFMIN(s->next_picture.f.mb_type[mb_xy], 6); if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0) return -1; if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0) return -1; mb_type = MB_TYPE_16x16; } } else if (mb_type < 8) { /* INTER */ if (svq3->thirdpel_flag && svq3->halfpel_flag == !get_bits1 (&s->gb)) { mode = THIRDPEL_MODE; } else if (svq3->halfpel_flag && svq3->thirdpel_flag == !get_bits1 (&s->gb)) { mode = HALFPEL_MODE; } else { mode = FULLPEL_MODE; } /* fill caches */ /* note ref_cache should contain here: ???????? ???11111 N??11111 N??11111 N??11111 */ for (m = 0; m < 2; m++) { if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) { for (i = 0; i < 4; i++) { *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride]; } } else { for (i = 0; i < 4; i++) { *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0; } } if (s->mb_y > 0) { memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t)); memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4); if (s->mb_x < (s->mb_width - 1)) { *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4]; h->ref_cache[m][scan8[0] + 4 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 || h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1; }else h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE; if (s->mb_x > 0) { *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1]; h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] == -1) ? PART_NOT_AVAILABLE : 1; }else h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE; }else memset(&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8); if (s->pict_type != AV_PICTURE_TYPE_B) break; } /* decode motion vector(s) and form prediction(s) */ if (s->pict_type == AV_PICTURE_TYPE_P) { if (svq3_mc_dir(h, (mb_type - 1), mode, 0, 0) < 0) return -1; } else { /* AV_PICTURE_TYPE_B */ if (mb_type != 2) { if (svq3_mc_dir(h, 0, mode, 0, 0) < 0) return -1; } else { for (i = 0; i < 4; i++) { memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); } } if (mb_type != 1) { if (svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0) return -1; } else { for (i = 0; i < 4; i++) { memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); } } } mb_type = MB_TYPE_16x16; } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */ memset(h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t)); if (mb_type == 8) { if (s->mb_x > 0) { for (i = 0; i < 4; i++) { h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6-i]; } if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) { h->left_samples_available = 0x5F5F; } } if (s->mb_y > 0) { h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+0]; h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+1]; h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+2]; h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+3]; if (h->intra4x4_pred_mode_cache[4+8*0] == -1) { h->top_samples_available = 0x33FF; } } /* decode prediction codes for luma blocks */ for (i = 0; i < 16; i+=2) { vlc = svq3_get_ue_golomb(&s->gb); if (vlc >= 25){ av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc); return -1; } left = &h->intra4x4_pred_mode_cache[scan8[i] - 1]; top = &h->intra4x4_pred_mode_cache[scan8[i] - 8]; left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]]; left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]]; if (left[1] == -1 || left[2] == -1){ av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n"); return -1; } } } else { /* mb_type == 33, DC_128_PRED block type */ for (i = 0; i < 4; i++) { memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4); } } write_back_intra_pred_mode(h); if (mb_type == 8) { ff_h264_check_intra4x4_pred_mode(h); h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF; h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF; } else { for (i = 0; i < 4; i++) { memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4); } h->top_samples_available = 0x33FF; h->left_samples_available = 0x5F5F; } mb_type = MB_TYPE_INTRA4x4; } else { /* INTRA16x16 */ dir = i_mb_type_info[mb_type - 8].pred_mode; dir = (dir >> 1) ^ 3*(dir & 1) ^ 1; if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir)) == -1){ av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n"); return -1; } cbp = i_mb_type_info[mb_type - 8].cbp; mb_type = MB_TYPE_INTRA16x16; } if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) { for (i = 0; i < 4; i++) { memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); } if (s->pict_type == AV_PICTURE_TYPE_B) { for (i = 0; i < 4; i++) { memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); } } } if (!IS_INTRA4x4(mb_type)) { memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy], DC_PRED, 8); } if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) { memset(h->non_zero_count_cache + 8, 0, 14*8*sizeof(uint8_t)); s->dsp.clear_blocks(h->mb+ 0); s->dsp.clear_blocks(h->mb+384); } if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) { if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48){ av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc); return -1; } cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc]; } if (IS_INTRA16x16(mb_type) || (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) { s->qscale += svq3_get_se_golomb(&s->gb); if (s->qscale > 31){ av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale); return -1; } } if (IS_INTRA16x16(mb_type)) { AV_ZERO128(h->mb_luma_dc[0]+0); AV_ZERO128(h->mb_luma_dc[0]+8); if (svq3_decode_block(&s->gb, h->mb_luma_dc, 0, 1)){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n"); return -1; } } if (cbp) { const int index = IS_INTRA16x16(mb_type) ? 1 : 0; const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1); for (i = 0; i < 4; i++) { if ((cbp & (1 << i))) { for (j = 0; j < 4; j++) { k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j); h->non_zero_count_cache[ scan8[k] ] = 1; if (svq3_decode_block(&s->gb, &h->mb[16*k], index, type)){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n"); return -1; } } } } if ((cbp & 0x30)) { for (i = 1; i < 3; ++i) { if (svq3_decode_block(&s->gb, &h->mb[16*16*i], 0, 3)){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n"); return -1; } } if ((cbp & 0x20)) { for (i = 1; i < 3; i++) { for (j = 0; j < 4; j++) { k = 16*i + j; h->non_zero_count_cache[ scan8[k] ] = 1; if (svq3_decode_block(&s->gb, &h->mb[16*k], 1, 1)){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n"); return -1; } } } } } } h->cbp= cbp; s->current_picture.f.mb_type[mb_xy] = mb_type; if (IS_INTRA(mb_type)) { h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8); } return 0; }


static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def) { #ifdef CONFIG_KVM KVMState *s = kvm_state; uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0; assert(kvm_enabled()); x86_cpu_def->name = "host"; host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); x86_cpu_vendor_words2str(x86_cpu_def->vendor, ebx, edx, ecx); host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); x86_cpu_def->family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); x86_cpu_def->model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); x86_cpu_def->stepping = eax & 0x0F; x86_cpu_def->level = kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX); x86_cpu_def->features[FEAT_1_EDX] = kvm_arch_get_supported_cpuid(s, 0x1, 0, R_EDX); x86_cpu_def->features[FEAT_1_ECX] = kvm_arch_get_supported_cpuid(s, 0x1, 0, R_ECX); if (x86_cpu_def->level >= 7) { x86_cpu_def->features[FEAT_7_0_EBX] = kvm_arch_get_supported_cpuid(s, 0x7, 0, R_EBX); } else { x86_cpu_def->features[FEAT_7_0_EBX] = 0; } x86_cpu_def->xlevel = kvm_arch_get_supported_cpuid(s, 0x80000000, 0, R_EAX); x86_cpu_def->features[FEAT_8000_0001_EDX] = kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_EDX); x86_cpu_def->features[FEAT_8000_0001_ECX] = kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_ECX); cpu_x86_fill_model_id(x86_cpu_def->model_id); /* Call Centaur's CPUID instruction. */ if (!strcmp(x86_cpu_def->vendor, CPUID_VENDOR_VIA)) { host_cpuid(0xC0000000, 0, &eax, &ebx, &ecx, &edx); eax = kvm_arch_get_supported_cpuid(s, 0xC0000000, 0, R_EAX); if (eax >= 0xC0000001) { /* Support VIA max extended level */ x86_cpu_def->xlevel2 = eax; host_cpuid(0xC0000001, 0, &eax, &ebx, &ecx, &edx); x86_cpu_def->features[FEAT_C000_0001_EDX] = kvm_arch_get_supported_cpuid(s, 0xC0000001, 0, R_EDX); } } /* Other KVM-specific feature fields: */ x86_cpu_def->features[FEAT_SVM] = kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX); x86_cpu_def->features[FEAT_KVM] = kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX); #endif /* CONFIG_KVM */ }


static void test_validate_fail_struct(TestInputVisitorData *data, const void *unused) { TestStruct *p = NULL; Error *err = NULL; Visitor *v; v = validate_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo', 'extra': 42 }"); visit_type_TestStruct(v, &p, NULL, &err); g_assert(err); error_free(err); if (p) { g_free(p->string); } g_free(p); }


static int dv_read_header(AVFormatContext *s, AVFormatParameters *ap) { unsigned state; RawDVContext *c = s->priv_data; c->dv_demux = dv_init_demux(s); if (!c->dv_demux) return -1; state = get_be32(s->pb); while ((state & 0xffffff7f) != 0x1f07003f) { if (url_feof(s->pb)) { av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); return -1; } state = (state << 8) | get_byte(s->pb); } AV_WB32(c->buf, state); if (get_buffer(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) <= 0 || url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) return AVERROR(EIO); c->dv_demux->sys = dv_frame_profile(c->buf); if (!c->dv_demux->sys) { av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n"); return -1; } s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, (AVRational){8,1}, c->dv_demux->sys->time_base); return 0; }


int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MJpegDecodeContext *s = avctx->priv_data; const uint8_t *buf_end, *buf_ptr; int start_code; AVFrame *picture = data; s->got_picture = 0; // picture from previous image can not be reused buf_ptr = buf; buf_end = buf + buf_size; while (buf_ptr < buf_end) { /* find start next marker */ start_code = find_marker(&buf_ptr, buf_end); { /* EOF */ if (start_code < 0) { goto the_end; } else { av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr); if ((buf_end - buf_ptr) > s->buffer_size) { av_free(s->buffer); s->buffer_size = buf_end-buf_ptr; s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE); av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n", s->buffer_size); /* unescape buffer of SOS, use special treatment for JPEG-LS */ if (start_code == SOS && !s->ls) { const uint8_t *src = buf_ptr; uint8_t *dst = s->buffer; while (src<buf_end) { uint8_t x = *(src++); *(dst++) = x; if (avctx->codec_id != CODEC_ID_THP) { if (x == 0xff) { while (src < buf_end && x == 0xff) x = *(src++); if (x >= 0xd0 && x <= 0xd7) *(dst++) = x; else if (x) init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8); av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n", (buf_end - buf_ptr) - (dst - s->buffer)); else if(start_code == SOS && s->ls){ const uint8_t *src = buf_ptr; uint8_t *dst = s->buffer; int bit_count = 0; int t = 0, b = 0; PutBitContext pb; s->cur_scan++; /* find marker */ while (src + t < buf_end){ uint8_t x = src[t++]; if (x == 0xff){ while((src + t < buf_end) && x == 0xff) x = src[t++]; if (x & 0x80) { t -= 2; bit_count = t * 8; init_put_bits(&pb, dst, t); /* unescape bitstream */ while(b < t){ uint8_t x = src[b++]; put_bits(&pb, 8, x); if(x == 0xFF){ x = src[b++]; put_bits(&pb, 7, x); bit_count--; flush_put_bits(&pb); init_get_bits(&s->gb, dst, bit_count); else init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8); s->start_code = start_code; if(s->avctx->debug & FF_DEBUG_STARTCODE){ av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); /* process markers */ if (start_code >= 0xd0 && start_code <= 0xd7) { av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f); /* APP fields */ } else if (start_code >= APP0 && start_code <= APP15) { mjpeg_decode_app(s); /* Comment */ } else if (start_code == COM){ mjpeg_decode_com(s); switch(start_code) { case SOI: s->restart_interval = 0; s->restart_count = 0; /* nothing to do on SOI */ case DQT: ff_mjpeg_decode_dqt(s); case DHT: if(ff_mjpeg_decode_dht(s) < 0){ av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n"); return -1; case SOF0: s->lossless=0; s->ls=0; s->progressive=0; if (ff_mjpeg_decode_sof(s) < 0) return -1; case SOF2: s->lossless=0; s->ls=0; s->progressive=1; if (ff_mjpeg_decode_sof(s) < 0) return -1; case SOF3: s->lossless=1; s->ls=0; s->progressive=0; if (ff_mjpeg_decode_sof(s) < 0) return -1; case SOF48: s->lossless=1; s->ls=1; s->progressive=0; if (ff_mjpeg_decode_sof(s) < 0) return -1; case LSE: if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0) return -1; case EOI: s->cur_scan = 0; if ((s->buggy_avid && !s->interlaced) || s->restart_interval) eoi_parser: av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n"); { if (s->interlaced) { s->bottom_field ^= 1; /* if not bottom field, do not output image yet */ if (s->bottom_field == !s->interlace_polarity) goto not_the_end; *picture = s->picture; *data_size = sizeof(AVFrame); if(!s->lossless){ picture->quality= FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2]); picture->qstride= 0; picture->qscale_table= s->qscale_table; memset(picture->qscale_table, picture->quality, (s->width+15)/16); if(avctx->debug & FF_DEBUG_QP) av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); picture->quality*= FF_QP2LAMBDA; goto the_end; case SOS: ff_mjpeg_decode_sos(s); /* buggy avid puts EOI every 10-20th frame */ /* if restart period is over process EOI */ if ((s->buggy_avid && !s->interlaced) || s->restart_interval) goto eoi_parser; case DRI: mjpeg_decode_dri(s); case SOF1: case SOF5: case SOF6: case SOF7: case SOF9: case SOF10: case SOF11: case SOF13: case SOF14: case SOF15: case JPG: av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code); // default: // printf("mjpeg: unsupported marker (%x)\n", start_code); // break; not_the_end: /* eof process start code */ buf_ptr += (get_bits_count(&s->gb)+7)/8; av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n", (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb)); the_end: av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", buf_end - buf_ptr); // return buf_end - buf_ptr; return buf_ptr - buf;


static int raw_write(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) { if (check_write_unsafe(bs, sector_num, buf, nb_sectors)) { int ret; ret = raw_write_scrubbed_bootsect(bs, buf); if (ret < 0) { return ret; } ret = bdrv_write(bs->file, 1, buf + 512, nb_sectors - 1); if (ret < 0) { return ret; } return ret + 512; } return bdrv_write(bs->file, sector_num, buf, nb_sectors); }


void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component) { AVComponentDescriptor comp= desc->comp[c]; int plane= comp.plane; int depth= comp.depth_minus1+1; int mask = (1<<depth)-1; int shift= comp.shift; int step = comp.step_minus1+1; int flags= desc->flags; if (flags & PIX_FMT_BITSTREAM){ int skip = x*step + comp.offset_plus1-1; const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); int shift = 8 - depth - (skip&7); while(w--){ int val = (*p >> shift) & mask; if(read_pal_component) val= data[1][4*val + c]; shift -= step; p -= shift>>3; shift &= 7; *dst++= val; } } else { const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; while(w--){ int val = flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p); val = (val>>shift) & mask; if(read_pal_component) val= data[1][4*val + c]; p+= step; *dst++= val; } } }


void set_system_io_map(MemoryRegion *mr) { memory_region_transaction_begin(); address_space_io.root = mr; memory_region_transaction_commit(); }


int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags) { BufferSinkContext *buf = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; AVFrame *cur_frame; /* no picref available, fetch it from the filterchain */ if (!av_fifo_size(buf->fifo)) { if (inlink->closed) return AVERROR_EOF; if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST) return AVERROR(EAGAIN); if ((ret = ff_request_frame(inlink)) < 0) return ret; } if (!av_fifo_size(buf->fifo)) return AVERROR(EINVAL); if (flags & AV_BUFFERSINK_FLAG_PEEK) { cur_frame = *((AVFrame **)av_fifo_peek2(buf->fifo, 0)); if ((ret = av_frame_ref(frame, cur_frame)) < 0) return ret; } else { av_fifo_generic_read(buf->fifo, &cur_frame, sizeof(cur_frame), NULL); av_frame_move_ref(frame, cur_frame); av_frame_free(&cur_frame); } return 0; }


static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S) { union { float f; uint32_t u; } value; int sign; int exp = s->float_max_exp; if (s->got_extra_bits) { const int max_bits = 1 + 23 + 8 + 1; const int left_bits = get_bits_left(&s->gb_extra_bits); if (left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits) return 0.0; } if (S) { S <<= s->float_shift; sign = S < 0; if (sign) S = -S; if (S >= 0x1000000) { if (s->got_extra_bits && get_bits1(&s->gb_extra_bits)) S = get_bits(&s->gb_extra_bits, 23); else S = 0; exp = 255; } else if (exp) { int shift = 23 - av_log2(S); exp = s->float_max_exp; if (exp <= shift) shift = --exp; exp -= shift; if (shift) { S <<= shift; if ((s->float_flag & WV_FLT_SHIFT_ONES) || (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) && get_bits1(&s->gb_extra_bits))) { S |= (1 << shift) - 1; } else if (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SENT)) { S |= get_bits(&s->gb_extra_bits, shift); } } } else { exp = s->float_max_exp; } S &= 0x7fffff; } else { sign = 0; exp = 0; if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) { if (get_bits1(&s->gb_extra_bits)) { S = get_bits(&s->gb_extra_bits, 23); if (s->float_max_exp >= 25) exp = get_bits(&s->gb_extra_bits, 8); sign = get_bits1(&s->gb_extra_bits); } else { if (s->float_flag & WV_FLT_ZERO_SIGN) sign = get_bits1(&s->gb_extra_bits); } } } *crc = *crc * 27 + S * 9 + exp * 3 + sign; value.u = (sign << 31) | (exp << 23) | S; return value.f; }


static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod method) { int ret; c->method = method; switch (c->method) { case GA_CHANNEL_VIRTIO_SERIAL: { int fd = qemu_open(path, O_RDWR | O_NONBLOCK #ifndef CONFIG_SOLARIS | O_ASYNC #endif ); if (fd == -1) { g_critical("error opening channel: %s", strerror(errno)); exit(EXIT_FAILURE); } #ifdef CONFIG_SOLARIS ret = ioctl(fd, I_SETSIG, S_OUTPUT | S_INPUT | S_HIPRI); if (ret == -1) { g_critical("error setting event mask for channel: %s", strerror(errno)); exit(EXIT_FAILURE); } #endif ret = ga_channel_client_add(c, fd); if (ret) { g_critical("error adding channel to main loop"); return false; } break; } case GA_CHANNEL_ISA_SERIAL: { struct termios tio; int fd = qemu_open(path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd == -1) { g_critical("error opening channel: %s", strerror(errno)); exit(EXIT_FAILURE); } tcgetattr(fd, &tio); /* set up serial port for non-canonical, dumb byte streaming */ tio.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY | IMAXBEL); tio.c_oflag = 0; tio.c_lflag = 0; tio.c_cflag |= GA_CHANNEL_BAUDRATE_DEFAULT; /* 1 available byte min or reads will block (we'll set non-blocking * elsewhere, else we have to deal with read()=0 instead) */ tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; /* flush everything waiting for read/xmit, it's garbage at this point */ tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tio); ret = ga_channel_client_add(c, fd); if (ret) { g_error("error adding channel to main loop"); } break; } case GA_CHANNEL_UNIX_LISTEN: { Error *local_err = NULL; int fd = unix_listen(path, NULL, strlen(path), &local_err); if (local_err != NULL) { g_critical("%s", error_get_pretty(local_err)); error_free(local_err); return false; } ga_channel_listen_add(c, fd, true); break; } default: g_critical("error binding/listening to specified socket"); return false; } return true; }


static void init_qxl_rom(PCIQXLDevice *d) { QXLRom *rom = memory_region_get_ram_ptr(&d->rom_bar); QXLModes *modes = (QXLModes *)(rom + 1); uint32_t ram_header_size; uint32_t surface0_area_size; uint32_t num_pages; uint32_t fb, maxfb = 0; int i; memset(rom, 0, d->rom_size); rom->magic = cpu_to_le32(QXL_ROM_MAGIC); rom->id = cpu_to_le32(d->id); rom->log_level = cpu_to_le32(d->guestdebug); rom->modes_offset = cpu_to_le32(sizeof(QXLRom)); rom->slot_gen_bits = MEMSLOT_GENERATION_BITS; rom->slot_id_bits = MEMSLOT_SLOT_BITS; rom->slots_start = 1; rom->slots_end = NUM_MEMSLOTS - 1; rom->n_surfaces = cpu_to_le32(NUM_SURFACES); modes->n_modes = cpu_to_le32(ARRAY_SIZE(qxl_modes)); for (i = 0; i < modes->n_modes; i++) { fb = qxl_modes[i].y_res * qxl_modes[i].stride; if (maxfb < fb) { maxfb = fb; } modes->modes[i].id = cpu_to_le32(i); modes->modes[i].x_res = cpu_to_le32(qxl_modes[i].x_res); modes->modes[i].y_res = cpu_to_le32(qxl_modes[i].y_res); modes->modes[i].bits = cpu_to_le32(qxl_modes[i].bits); modes->modes[i].stride = cpu_to_le32(qxl_modes[i].stride); modes->modes[i].x_mili = cpu_to_le32(qxl_modes[i].x_mili); modes->modes[i].y_mili = cpu_to_le32(qxl_modes[i].y_mili); modes->modes[i].orientation = cpu_to_le32(qxl_modes[i].orientation); } if (maxfb < VGA_RAM_SIZE && d->id == 0) maxfb = VGA_RAM_SIZE; ram_header_size = ALIGN(sizeof(QXLRam), 4096); surface0_area_size = ALIGN(maxfb, 4096); num_pages = d->vga.vram_size; num_pages -= ram_header_size; num_pages -= surface0_area_size; num_pages = num_pages / TARGET_PAGE_SIZE; rom->draw_area_offset = cpu_to_le32(0); rom->surface0_area_size = cpu_to_le32(surface0_area_size); rom->pages_offset = cpu_to_le32(surface0_area_size); rom->num_pages = cpu_to_le32(num_pages); rom->ram_header_offset = cpu_to_le32(d->vga.vram_size - ram_header_size); d->shadow_rom = *rom; d->rom = rom; d->modes = modes; }


roundAndPackFloat128( flag zSign, int32 zExp, uint64_t zSig0, uint64_t zSig1, uint64_t zSig2 STATUS_PARAM) { int8 roundingMode; flag roundNearestEven, increment, isTiny; roundingMode = STATUS(float_rounding_mode); roundNearestEven = ( roundingMode == float_round_nearest_even ); increment = ( (int64_t) zSig2 < 0 ); if ( ! roundNearestEven ) { if ( roundingMode == float_round_to_zero ) { increment = 0; } else { if ( zSign ) { increment = ( roundingMode == float_round_down ) && zSig2; } else { increment = ( roundingMode == float_round_up ) && zSig2; } } } if ( 0x7FFD <= (uint32_t) zExp ) { if ( ( 0x7FFD < zExp ) || ( ( zExp == 0x7FFD ) && eq128( LIT64( 0x0001FFFFFFFFFFFF ), LIT64( 0xFFFFFFFFFFFFFFFF ), zSig0, zSig1 ) && increment ) ) { float_raise( float_flag_overflow | float_flag_inexact STATUS_VAR); if ( ( roundingMode == float_round_to_zero ) || ( zSign && ( roundingMode == float_round_up ) ) || ( ! zSign && ( roundingMode == float_round_down ) ) ) { return packFloat128( zSign, 0x7FFE, LIT64( 0x0000FFFFFFFFFFFF ), LIT64( 0xFFFFFFFFFFFFFFFF ) ); } return packFloat128( zSign, 0x7FFF, 0, 0 ); } if ( zExp < 0 ) { if ( STATUS(flush_to_zero) ) return packFloat128( zSign, 0, 0, 0 ); isTiny = ( STATUS(float_detect_tininess) == float_tininess_before_rounding ) || ( zExp < -1 ) || ! increment || lt128( zSig0, zSig1, LIT64( 0x0001FFFFFFFFFFFF ), LIT64( 0xFFFFFFFFFFFFFFFF ) ); shift128ExtraRightJamming( zSig0, zSig1, zSig2, - zExp, &zSig0, &zSig1, &zSig2 ); zExp = 0; if ( isTiny && zSig2 ) float_raise( float_flag_underflow STATUS_VAR); if ( roundNearestEven ) { increment = ( (int64_t) zSig2 < 0 ); } else { if ( zSign ) { increment = ( roundingMode == float_round_down ) && zSig2; } else { increment = ( roundingMode == float_round_up ) && zSig2; } } } } if ( zSig2 ) STATUS(float_exception_flags) |= float_flag_inexact; if ( increment ) { add128( zSig0, zSig1, 0, 1, &zSig0, &zSig1 ); zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven ); } else { if ( ( zSig0 | zSig1 ) == 0 ) zExp = 0; } return packFloat128( zSign, zExp, zSig0, zSig1 ); }


static inline void RENAME(yvu9toyv12)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, unsigned int width, unsigned int height, int lumStride, int chromStride) { /* Y Plane */ memcpy(ydst, ysrc, width*height); /* XXX: implement upscaling for U,V */ }


int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, int n, int coded, const uint8_t *scan_table) { int level, i, last, run, run_diff; int dc_pred_dir; RLTable *rl; RL_VLC_ELEM *rl_vlc; int qmul, qadd; if (s->mb_intra) { qmul=1; qadd=0; /* DC coef */ level = msmpeg4_decode_dc(s, n, &dc_pred_dir); if (level < 0){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); if(s->inter_intra_pred) level=0; else return -1; } if (n < 4) { rl = &rl_table[s->rl_table_index]; if(level > 256*s->y_dc_scale){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale); if(!s->inter_intra_pred) return -1; } } else { rl = &rl_table[3 + s->rl_chroma_table_index]; if(level > 256*s->c_dc_scale){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale); if(!s->inter_intra_pred) return -1; } } block[0] = level; run_diff = s->msmpeg4_version >= 4; i = 0; if (!coded) { goto not_coded; } if (s->ac_pred) { if (dc_pred_dir == 0) scan_table = s->intra_v_scantable.permutated; /* left */ else scan_table = s->intra_h_scantable.permutated; /* top */ } else { scan_table = s->intra_scantable.permutated; } rl_vlc= rl->rl_vlc[0]; } else { qmul = s->qscale << 1; qadd = (s->qscale - 1) | 1; i = -1; rl = &rl_table[3 + s->rl_table_index]; if(s->msmpeg4_version==2) run_diff = 0; else run_diff = 1; if (!coded) { s->block_last_index[n] = i; return 0; } if(!scan_table) scan_table = s->inter_scantable.permutated; rl_vlc= rl->rl_vlc[s->qscale]; } { OPEN_READER(re, &s->gb); for(;;) { UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (level==0) { int cache; cache= GET_CACHE(re, &s->gb); /* escape */ if (s->msmpeg4_version==1 || (cache&0x80000000)==0) { if (s->msmpeg4_version==1 || (cache&0x40000000)==0) { /* third escape */ if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2); UPDATE_CACHE(re, &s->gb); if(s->msmpeg4_version<=3){ last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8); SKIP_COUNTER(re, &s->gb, 1+6+8); }else{ int sign; last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); if(!s->esc3_level_length){ int ll; //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y); if(s->qscale<8){ ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); if(ll==0){ if(SHOW_UBITS(re, &s->gb, 1)) av_log(s->avctx, AV_LOG_ERROR, "cool a new vlc code ,contact the ffmpeg developers and upload the file\n"); SKIP_BITS(re, &s->gb, 1); ll=8; } }else{ ll=2; while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){ ll++; SKIP_BITS(re, &s->gb, 1); } if(ll<8) SKIP_BITS(re, &s->gb, 1); } s->esc3_level_length= ll; s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); //printf("level length:%d, run length: %d\n", ll, s->esc3_run_length); UPDATE_CACHE(re, &s->gb); } run= SHOW_UBITS(re, &s->gb, s->esc3_run_length); SKIP_BITS(re, &s->gb, s->esc3_run_length); sign= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); level= SHOW_UBITS(re, &s->gb, s->esc3_level_length); SKIP_BITS(re, &s->gb, s->esc3_level_length); if(sign) level= -level; } //printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y); #if 0 // waste of time / this will detect very few errors { const int abs_level= FFABS(level); const int run1= run - rl->max_run[last][abs_level] - run_diff; if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ if(abs_level <= rl->max_level[last][run]){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); return DECODING_AC_LOST; } if(abs_level <= rl->max_level[last][run]*2){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); return DECODING_AC_LOST; } if(run1>=0 && abs_level <= rl->max_level[last][run1]){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); return DECODING_AC_LOST; } } } #endif //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ; if (level>0) level= level * qmul + qadd; else level= level * qmul - qadd; #if 0 // waste of time too :( if(level>2048 || level<-2048){ av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n"); return DECODING_AC_LOST; } #endif i+= run + 1; if(last) i+=192; #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level); #endif } else { /* second escape */ #if MIN_CACHE_BITS < 23 LAST_SKIP_BITS(re, &s->gb, 2); UPDATE_CACHE(re, &s->gb); #else SKIP_BITS(re, &s->gb, 2); #endif GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level); #endif } } else { /* first escape */ #if MIN_CACHE_BITS < 22 LAST_SKIP_BITS(re, &s->gb, 1); UPDATE_CACHE(re, &s->gb); #else SKIP_BITS(re, &s->gb, 1); #endif GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); i+= run; level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level); #endif } } else { i+= run; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level); #endif } if (i > 62){ i-= 192; if(i&(~63)){ const int left= s->gb.size_in_bits - get_bits_count(&s->gb); if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){ av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); break; }else{ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } } block[scan_table[i]] = level; break; } block[scan_table[i]] = level; } CLOSE_READER(re, &s->gb); } not_coded: if (s->mb_intra) { mpeg4_pred_ac(s, block, n, dc_pred_dir); if (s->ac_pred) { i = 63; /* XXX: not optimal */ } } if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize s->block_last_index[n] = i; return 0; }


static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, AVSubtitleRect *r) { uint32_t *pal, *dst2; uint8_t *src, *src2; int x, y; if (r->type != SUBTITLE_BITMAP) { av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n"); return; } if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) { av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle overflowing\n"); return; } dst += r->y * dst_linesize + r->x * 4; src = r->pict.data[0]; pal = (uint32_t *)r->pict.data[1]; for (y = 0; y < r->h; y++) { dst2 = (uint32_t *)dst; src2 = src; for (x = 0; x < r->w; x++) *(dst2++) = pal[*(src2++)]; dst += dst_linesize; src += r->pict.linesize[0]; } }


SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avctx) { unsigned int num_formats = sizeof(ff_schro_video_formats) / sizeof(ff_schro_video_formats[0]); unsigned int idx = get_video_format_idx(avctx); return (idx < num_formats) ? ff_schro_video_formats[idx] : SCHRO_VIDEO_FORMAT_CUSTOM; }


void qemu_console_copy(QemuConsole *con, int src_x, int src_y, int dst_x, int dst_y, int w, int h) { assert(con->console_type == GRAPHIC_CONSOLE); dpy_gfx_copy(con, src_x, src_y, dst_x, dst_y, w, h); }


static int aac_adtstoasc_init(AVBSFContext *ctx) { av_freep(&ctx->par_out->extradata); ctx->par_out->extradata_size = 0; return 0; }


static int dmg_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVDMGState *s = bs->opaque; uint64_t info_begin, info_end, last_in_offset, last_out_offset; uint32_t count, tmp; uint32_t max_compressed_size = 1, max_sectors_per_chunk = 1, i; int64_t offset; int ret; bs->read_only = 1; s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; /* read offset of info blocks */ offset = bdrv_getlength(bs->file); if (offset < 0) { ret = offset; goto fail; } offset -= 0x1d8; ret = read_uint64(bs, offset, &info_begin); if (ret < 0) { goto fail; } else if (info_begin == 0) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin, &tmp); if (ret < 0) { goto fail; } else if (tmp != 0x100) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin + 4, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } info_end = info_begin + count; offset = info_begin + 0x100; /* read offsets */ last_in_offset = last_out_offset = 0; while (offset < info_end) { uint32_t type; ret = read_uint32(bs, offset, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } offset += 4; ret = read_uint32(bs, offset, &type); if (ret < 0) { goto fail; } if (type == 0x6d697368 && count >= 244) { size_t new_size; uint32_t chunk_count; offset += 4; offset += 200; chunk_count = (count - 204) / 40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); s->types = g_realloc(s->types, new_size / 2); s->offsets = g_realloc(s->offsets, new_size); s->lengths = g_realloc(s->lengths, new_size); s->sectors = g_realloc(s->sectors, new_size); s->sectorcounts = g_realloc(s->sectorcounts, new_size); for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) { ret = read_uint32(bs, offset, &s->types[i]); if (ret < 0) { goto fail; } offset += 4; if (s->types[i] != 0x80000005 && s->types[i] != 1 && s->types[i] != 2) { if (s->types[i] == 0xffffffff && i > 0) { last_in_offset = s->offsets[i - 1] + s->lengths[i - 1]; last_out_offset = s->sectors[i - 1] + s->sectorcounts[i - 1]; } chunk_count--; i--; offset += 36; continue; } offset += 4; ret = read_uint64(bs, offset, &s->sectors[i]); if (ret < 0) { goto fail; } s->sectors[i] += last_out_offset; offset += 8; ret = read_uint64(bs, offset, &s->sectorcounts[i]); if (ret < 0) { goto fail; } offset += 8; if (s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) { error_report("sector count %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX); ret = -EINVAL; goto fail; } ret = read_uint64(bs, offset, &s->offsets[i]); if (ret < 0) { goto fail; } s->offsets[i] += last_in_offset; offset += 8; ret = read_uint64(bs, offset, &s->lengths[i]); if (ret < 0) { goto fail; } offset += 8; if (s->lengths[i] > DMG_LENGTHS_MAX) { error_report("length %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->lengths[i], i, DMG_LENGTHS_MAX); ret = -EINVAL; goto fail; } update_max_chunk_size(s, i, &max_compressed_size, &max_sectors_per_chunk); } s->n_chunks += chunk_count; } } /* initialize zlib engine */ s->compressed_chunk = qemu_try_blockalign(bs->file, max_compressed_size + 1); s->uncompressed_chunk = qemu_try_blockalign(bs->file, 512 * max_sectors_per_chunk); if (s->compressed_chunk == NULL || s->uncompressed_chunk == NULL) { ret = -ENOMEM; goto fail; } if (inflateInit(&s->zstream) != Z_OK) { ret = -EINVAL; goto fail; } s->current_chunk = s->n_chunks; qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->types); g_free(s->offsets); g_free(s->lengths); g_free(s->sectors); g_free(s->sectorcounts); qemu_vfree(s->compressed_chunk); qemu_vfree(s->uncompressed_chunk); return ret; }


static int ea_read_header(AVFormatContext *s) { EaDemuxContext *ea = s->priv_data; AVStream *st; if (process_ea_header(s)<=0) return AVERROR(EIO); if (init_video_stream(s, &ea->video) || init_video_stream(s, &ea->alpha)) return AVERROR(ENOMEM); if (ea->audio_codec) { if (ea->num_channels <= 0 || ea->num_channels > 2) { av_log(s, AV_LOG_WARNING, "Unsupported number of channels: %d\n", ea->num_channels); ea->audio_codec = 0; return 1; } if (ea->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate: %d\n", ea->sample_rate); ea->audio_codec = 0; return 1; } if (ea->bytes <= 0) { av_log(s, AV_LOG_ERROR, "Invalid number of bytes per sample: %d\n", ea->bytes); ea->audio_codec = AV_CODEC_ID_NONE; return 1; } /* initialize the audio decoder stream */ st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 33, 1, ea->sample_rate); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = ea->audio_codec; st->codecpar->codec_tag = 0; /* no tag */ st->codecpar->channels = ea->num_channels; st->codecpar->sample_rate = ea->sample_rate; st->codecpar->bits_per_coded_sample = ea->bytes * 8; st->codecpar->bit_rate = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample / 4; st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; ea->audio_stream_index = st->index; st->start_time = 0; } return 1; }


static void armv7m_bitband_init(void) { DeviceState *dev; dev = qdev_create(NULL, "ARM,bitband-memory"); qdev_prop_set_uint32(dev, "base", 0x20000000); qdev_init(dev); sysbus_mmio_map(sysbus_from_qdev(dev), 0, 0x22000000); dev = qdev_create(NULL, "ARM,bitband-memory"); qdev_prop_set_uint32(dev, "base", 0x40000000); qdev_init(dev); sysbus_mmio_map(sysbus_from_qdev(dev), 0, 0x42000000); }


static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len) { unsigned int crc; unsigned char packet[TS_PACKET_SIZE]; const unsigned char *buf_ptr; unsigned char *q; int first, b, len1, left; crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, buf, len - 4)); buf[len - 4] = (crc >> 24) & 0xff; buf[len - 3] = (crc >> 16) & 0xff; buf[len - 2] = (crc >> 8) & 0xff; buf[len - 1] = crc & 0xff; /* send each packet */ buf_ptr = buf; while (len > 0) { first = buf == buf_ptr; q = packet; *q++ = 0x47; b = s->pid >> 8; if (first) b |= 0x40; *q++ = b; *q++ = s->pid; s->cc = s->cc + 1 & 0xf; *q++ = 0x10 | s->cc; if (first) *q++ = 0; /* 0 offset */ len1 = TS_PACKET_SIZE - (q - packet); if (len1 > len) len1 = len; memcpy(q, buf_ptr, len1); q += len1; /* add known padding data */ left = TS_PACKET_SIZE - (q - packet); if (left > 0) memset(q, 0xff, left); s->write_packet(s, packet); buf_ptr += len1; len -= len1;


void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) { memory_region_transaction_begin(); as->root = root; as->current_map = g_new(FlatView, 1); flatview_init(as->current_map); as->ioeventfd_nb = 0; as->ioeventfds = NULL; QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link); as->name = g_strdup(name ? name : "anonymous"); address_space_init_dispatch(as); memory_region_update_pending |= root->enabled; memory_region_transaction_commit(); }


static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer opaque) { IOTrampoline *tramp = opaque; if (tramp->opaque == NULL) { return FALSE; } if ((cond & G_IO_IN) && tramp->fd_read) { tramp->fd_read(tramp->opaque); } if ((cond & G_IO_OUT) && tramp->fd_write) { tramp->fd_write(tramp->opaque); } return TRUE; }


static void test_flush_event_notifier(void) { EventNotifierTestData data = { .n = 0, .active = 10, .auto_set = true }; event_notifier_init(&data.e, false); aio_set_event_notifier(ctx, &data.e, event_ready_cb, event_active_cb); g_assert(aio_poll(ctx, false)); g_assert_cmpint(data.n, ==, 0); g_assert_cmpint(data.active, ==, 10); event_notifier_set(&data.e); g_assert(aio_poll(ctx, false)); g_assert_cmpint(data.n, ==, 1); g_assert_cmpint(data.active, ==, 9); g_assert(aio_poll(ctx, false)); wait_for_aio(); g_assert_cmpint(data.n, ==, 10); g_assert_cmpint(data.active, ==, 0); g_assert(!aio_poll(ctx, false)); aio_set_event_notifier(ctx, &data.e, NULL, NULL); g_assert(!aio_poll(ctx, false)); event_notifier_cleanup(&data.e); }


static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_t len) { char *mechname = malloc(len + 1); if (!mechname) { VNC_DEBUG("Out of memory reading mechname\n"); vnc_client_error(vs); } strncpy(mechname, (char*)data, len); mechname[len] = '\0'; VNC_DEBUG("Got client mechname '%s' check against '%s'\n", mechname, vs->sasl.mechlist); if (strncmp(vs->sasl.mechlist, mechname, len) == 0) { if (vs->sasl.mechlist[len] != '\0' && vs->sasl.mechlist[len] != ',') { VNC_DEBUG("One %d", vs->sasl.mechlist[len]); vnc_client_error(vs); return -1; } } else { char *offset = strstr(vs->sasl.mechlist, mechname); VNC_DEBUG("Two %p\n", offset); if (!offset) { vnc_client_error(vs); return -1; } VNC_DEBUG("Two '%s'\n", offset); if (offset[-1] != ',' || (offset[len] != '\0'&& offset[len] != ',')) { vnc_client_error(vs); return -1; } } free(vs->sasl.mechlist); vs->sasl.mechlist = mechname; VNC_DEBUG("Validated mechname '%s'\n", mechname); vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4); return 0; }


static void qxl_send_events(PCIQXLDevice *d, uint32_t events) { uint32_t old_pending; uint32_t le_events = cpu_to_le32(events); trace_qxl_send_events(d->id, events); assert(qemu_spice_display_is_running(&d->ssd)); old_pending = __sync_fetch_and_or(&d->ram->int_pending, le_events); if ((old_pending & le_events) == le_events) { return; } if (qemu_thread_is_self(&d->main)) { qxl_update_irq(d); } else { if (write(d->pipe[1], d, 1) != 1) { dprint(d, 1, "%s: write to pipe failed\n", __func__); } } }


static void decode_blocks(SnowContext *s){ int x, y; int w= s->b_width; int h= s->b_height; for(y=0; y<h; y++){ for(x=0; x<w; x++){ decode_q_branch(s, 0, x, y); } } }


static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) { VideoData *s = s1->priv_data; int ret, first_index, last_index; char buf[1024]; ByteIOContext pb1, *f = &pb1; AVStream *st; st = av_new_stream(s1, 0); if (!st) { av_free(s); return -ENOMEM; } if (ap->image_format) s->img_fmt = ap->image_format; pstrcpy(s->path, sizeof(s->path), s1->filename); s->img_number = 0; s->img_count = 0; /* find format */ if (s1->iformat->flags & AVFMT_NOFILE) s->is_pipe = 0; else s->is_pipe = 1; if (!ap->time_base.num) { st->codec->time_base= (AVRational){1,25}; } else { st->codec->time_base= ap->time_base; } if (!s->is_pipe) { if (find_image_range(&first_index, &last_index, s->path) < 0) goto fail; s->img_first = first_index; s->img_last = last_index; s->img_number = first_index; /* compute duration */ st->start_time = 0; st->duration = last_index - first_index + 1; if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0) goto fail; if (url_fopen(f, buf, URL_RDONLY) < 0) goto fail; } else { f = &s1->pb; } ret = av_read_image(f, s1->filename, s->img_fmt, read_header_alloc_cb, s); if (ret < 0) goto fail1; if (!s->is_pipe) { url_fclose(f); } else { url_fseek(f, 0, SEEK_SET); } st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->codec->width = s->width; st->codec->height = s->height; st->codec->pix_fmt = s->pix_fmt; s->img_size = avpicture_get_size(s->pix_fmt, (s->width+15)&(~15), (s->height+15)&(~15)); return 0; fail1: if (!s->is_pipe) url_fclose(f); fail: av_free(s); return AVERROR_IO; }


static void mpeg4_encode_gop_header(MpegEncContext *s) { int hours, minutes, seconds; int64_t time; put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, GOP_STARTCODE); time = s->current_picture_ptr->f.pts; if (s->reordered_input_picture[1]) time = FFMIN(time, s->reordered_input_picture[1]->f.pts); time = time * s->avctx->time_base.num; seconds = time / s->avctx->time_base.den; minutes = seconds / 60; seconds %= 60; hours = minutes / 60; minutes %= 60; hours %= 24; put_bits(&s->pb, 5, hours); put_bits(&s->pb, 6, minutes); put_bits(&s->pb, 1, 1); put_bits(&s->pb, 6, seconds); put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP)); put_bits(&s->pb, 1, 0); // broken link == NO s->last_time_base = time / s->avctx->time_base.den; ff_mpeg4_stuffing(&s->pb); }


static int av_encode(AVFormatContext **output_files, int nb_output_files, AVFormatContext **input_files, int nb_input_files, AVStreamMap *stream_maps, int nb_stream_maps) { int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; AVFormatContext *is, *os; AVCodecContext *codec, *icodec; AVOutputStream *ost, **ost_table = NULL; AVInputStream *ist, **ist_table = NULL; AVInputFile *file_table; AVFormatContext *stream_no_data; int key; file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile)); if (!file_table) goto fail; /* input stream init */ j = 0; for(i=0;i<nb_input_files;i++) { is = input_files[i]; file_table[i].ist_index = j; file_table[i].nb_streams = is->nb_streams; j += is->nb_streams; } nb_istreams = j; ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *)); if (!ist_table) goto fail; for(i=0;i<nb_istreams;i++) { ist = av_mallocz(sizeof(AVInputStream)); if (!ist) goto fail; ist_table[i] = ist; } j = 0; for(i=0;i<nb_input_files;i++) { is = input_files[i]; for(k=0;k<is->nb_streams;k++) { ist = ist_table[j++]; ist->st = is->streams[k]; ist->file_index = i; ist->index = k; ist->discard = 1; /* the stream is discarded by default (changed later) */ if (ist->st->codec.rate_emu) { ist->start = av_gettime(); ist->frame = 0; } } } /* output stream init */ nb_ostreams = 0; for(i=0;i<nb_output_files;i++) { os = output_files[i]; nb_ostreams += os->nb_streams; } if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { fprintf(stderr, "Number of stream maps must match number of output streams\n"); exit(1); } /* Sanity check the mapping args -- do the input files & streams exist? */ for(i=0;i<nb_stream_maps;i++) { int fi = stream_maps[i].file_index; int si = stream_maps[i].stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > file_table[fi].nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); exit(1); } } ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams); if (!ost_table) goto fail; for(i=0;i<nb_ostreams;i++) { ost = av_mallocz(sizeof(AVOutputStream)); if (!ost) goto fail; ost_table[i] = ost; } n = 0; for(k=0;k<nb_output_files;k++) { os = output_files[k]; for(i=0;i<os->nb_streams;i++) { int found; ost = ost_table[n++]; ost->file_index = k; ost->index = i; ost->st = os->streams[i]; if (nb_stream_maps > 0) { ost->source_index = file_table[stream_maps[n-1].file_index].ist_index + stream_maps[n-1].stream_index; /* Sanity check that the stream types match */ if (ist_table[ost->source_index]->st->codec.codec_type != ost->st->codec.codec_type) { fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", stream_maps[n-1].file_index, stream_maps[n-1].stream_index, ost->file_index, ost->index); exit(1); } } else { /* get corresponding input stream index : we select the first one with the right type */ found = 0; for(j=0;j<nb_istreams;j++) { ist = ist_table[j]; if (ist->discard && ist->st->codec.codec_type == ost->st->codec.codec_type) { ost->source_index = j; found = 1; } } if (!found) { /* try again and reuse existing stream */ for(j=0;j<nb_istreams;j++) { ist = ist_table[j]; if (ist->st->codec.codec_type == ost->st->codec.codec_type) { ost->source_index = j; found = 1; } } if (!found) { fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", ost->file_index, ost->index); exit(1); } } } ist = ist_table[ost->source_index]; ist->discard = 0; } } /* for each output stream, we compute the right encoding parameters */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; ist = ist_table[ost->source_index]; codec = &ost->st->codec; icodec = &ist->st->codec; if (ost->st->stream_copy) { /* if stream_copy is selected, no need to decode or encode */ codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; codec->codec_tag = icodec->codec_tag; codec->bit_rate = icodec->bit_rate; switch(codec->codec_type) { case CODEC_TYPE_AUDIO: codec->sample_rate = icodec->sample_rate; codec->channels = icodec->channels; break; case CODEC_TYPE_VIDEO: codec->frame_rate = icodec->frame_rate; codec->frame_rate_base = icodec->frame_rate_base; codec->width = icodec->width; codec->height = icodec->height; break; default: av_abort(); } } else { switch(codec->codec_type) { case CODEC_TYPE_AUDIO: if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE)) goto fail; if (codec->channels == icodec->channels && codec->sample_rate == icodec->sample_rate) { ost->audio_resample = 0; } else { if (codec->channels != icodec->channels && icodec->codec_id == CODEC_ID_AC3) { /* Special case for 5:1 AC3 input */ /* and mono or stereo output */ /* Request specific number of channels */ icodec->channels = codec->channels; if (codec->sample_rate == icodec->sample_rate) ost->audio_resample = 0; else { ost->audio_resample = 1; ost->resample = audio_resample_init(codec->channels, icodec->channels, codec->sample_rate, icodec->sample_rate); if(!ost->resample) { printf("Can't resample. Aborting.\n"); av_abort(); } } /* Request specific number of channels */ icodec->channels = codec->channels; } else { ost->audio_resample = 1; ost->resample = audio_resample_init(codec->channels, icodec->channels, codec->sample_rate, icodec->sample_rate); if(!ost->resample) { printf("Can't resample. Aborting.\n"); av_abort(); } } } ist->decoding_needed = 1; ost->encoding_needed = 1; break; case CODEC_TYPE_VIDEO: if (codec->width == icodec->width && codec->height == icodec->height && frame_topBand == 0 && frame_bottomBand == 0 && frame_leftBand == 0 && frame_rightBand == 0) { ost->video_resample = 0; ost->video_crop = 0; } else if ((codec->width == icodec->width - (frame_leftBand + frame_rightBand)) && (codec->height == icodec->height - (frame_topBand + frame_bottomBand))) { ost->video_resample = 0; ost->video_crop = 1; ost->topBand = frame_topBand; ost->leftBand = frame_leftBand; } else { ost->video_resample = 1; ost->video_crop = 0; // cropping is handled as part of resample if( avpicture_alloc( &ost->pict_tmp, PIX_FMT_YUV420P, codec->width, codec->height ) ) goto fail; ost->img_resample_ctx = img_resample_full_init( ost->st->codec.width, ost->st->codec.height, ist->st->codec.width, ist->st->codec.height, frame_topBand, frame_bottomBand, frame_leftBand, frame_rightBand); } ost->encoding_needed = 1; ist->decoding_needed = 1; break; default: av_abort(); } /* two pass mode */ if (ost->encoding_needed && (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { char logfilename[1024]; FILE *f; int size; char *logbuffer; snprintf(logfilename, sizeof(logfilename), "%s-%d.log", pass_logfilename ? pass_logfilename : DEFAULT_PASS_LOGFILENAME, i); if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(logfilename, "w"); if (!f) { perror(logfilename); exit(1); } ost->logfile = f; } else { /* read the log file */ f = fopen(logfilename, "r"); if (!f) { perror(logfilename); exit(1); } fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); logbuffer = av_malloc(size + 1); if (!logbuffer) { fprintf(stderr, "Could not allocate log buffer\n"); exit(1); } size = fread(logbuffer, 1, size, f); fclose(f); logbuffer[size] = '\0'; codec->stats_in = logbuffer; } } } } /* dump the file output parameters - cannot be done before in case of stream copy */ for(i=0;i<nb_output_files;i++) { dump_format(output_files[i], i, output_files[i]->filename, 1); } /* dump the stream mapping */ fprintf(stderr, "Stream mapping:\n"); for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; fprintf(stderr, " Stream #%d.%d -> #%d.%d\n", ist_table[ost->source_index]->file_index, ist_table[ost->source_index]->index, ost->file_index, ost->index); } /* open each encoder */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { AVCodec *codec; codec = avcodec_find_encoder(ost->st->codec.codec_id); if (!codec) { fprintf(stderr, "Unsupported codec for output stream #%d.%d\n", ost->file_index, ost->index); exit(1); } if (avcodec_open(&ost->st->codec, codec) < 0) { fprintf(stderr, "Error while opening codec for stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", ost->file_index, ost->index); exit(1); } } } /* open each decoder */ for(i=0;i<nb_istreams;i++) { ist = ist_table[i]; if (ist->decoding_needed) { AVCodec *codec; codec = avcodec_find_decoder(ist->st->codec.codec_id); if (!codec) { fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n", ist->st->codec.codec_id, ist->file_index, ist->index); exit(1); } if (avcodec_open(&ist->st->codec, codec) < 0) { fprintf(stderr, "Error while opening codec for input stream #%d.%d\n", ist->file_index, ist->index); exit(1); } //if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) // ist->st->codec.flags |= CODEC_FLAG_REPEAT_FIELD; } } /* init pts */ for(i=0;i<nb_istreams;i++) { ist = ist_table[i]; is = input_files[ist->file_index]; ist->pts = 0; ist->next_pts = 0; } /* compute buffer size max (should use a complete heuristic) */ for(i=0;i<nb_input_files;i++) { file_table[i].buffer_size_max = 2048; } /* open files and write file headers */ for(i=0;i<nb_output_files;i++) { os = output_files[i]; if (av_write_header(os) < 0) { fprintf(stderr, "Could not write header for output file #%d (incorrect codec paramters ?)\n", i); ret = -EINVAL; goto fail; } } #ifndef CONFIG_WIN32 if ( !using_stdin ) fprintf(stderr, "Press [q] to stop encoding\n"); #endif term_init(); stream_no_data = 0; key = -1; for(; received_sigterm == 0;) { int file_index, ist_index; AVPacket pkt; double pts_min; redo: /* if 'q' pressed, exits */ if (!using_stdin) { /* read_key() returns 0 on EOF */ key = read_key(); if (key == 'q') break; } /* select the stream that we must read now by looking at the smallest output pts */ file_index = -1; pts_min = 1e10; for(i=0;i<nb_ostreams;i++) { double pts; ost = ost_table[i]; os = output_files[ost->file_index]; ist = ist_table[ost->source_index]; pts = (double)ost->st->pts.val * os->pts_num / os->pts_den; if (!file_table[ist->file_index].eof_reached && pts < pts_min) { pts_min = pts; file_index = ist->file_index; } } /* if none, if is finished */ if (file_index < 0) { break; } /* finish if recording time exhausted */ if (recording_time > 0 && pts_min >= (recording_time / 1000000.0)) break; /* read a frame from it and output it in the fifo */ is = input_files[file_index]; if (av_read_frame(is, &pkt) < 0) { file_table[file_index].eof_reached = 1; continue; } if (!pkt.size) { stream_no_data = is; } else { stream_no_data = 0; } if (do_pkt_dump) { av_pkt_dump(stdout, &pkt, do_hex_dump); } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ if (pkt.stream_index >= file_table[file_index].nb_streams) goto discard_packet; ist_index = file_table[file_index].ist_index + pkt.stream_index; ist = ist_table[ist_index]; if (ist->discard) goto discard_packet; //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size); if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { fprintf(stderr, "Error while decoding stream #%d.%d\n", ist->file_index, ist->index); av_free_packet(&pkt); goto redo; } discard_packet: av_free_packet(&pkt); /* dump report by using the output first video and audio streams */ print_report(output_files, ost_table, nb_ostreams, 0); } /* at the end of stream, we must flush the decoder buffers */ for(i=0;i<nb_istreams;i++) { ist = ist_table[i]; if (ist->decoding_needed) { output_packet(ist, i, ost_table, nb_ostreams, NULL); } } term_exit(); /* dump report by using the first video and audio streams */ print_report(output_files, ost_table, nb_ostreams, 1); /* write the trailer if needed and close file */ for(i=0;i<nb_output_files;i++) { os = output_files[i]; av_write_trailer(os); } /* close each encoder */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost->encoding_needed) { av_freep(&ost->st->codec.stats_in); avcodec_close(&ost->st->codec); } } /* close each decoder */ for(i=0;i<nb_istreams;i++) { ist = ist_table[i]; if (ist->decoding_needed) { avcodec_close(&ist->st->codec); } } /* finished ! */ ret = 0; fail1: av_free(file_table); if (ist_table) { for(i=0;i<nb_istreams;i++) { ist = ist_table[i]; av_free(ist); } av_free(ist_table); } if (ost_table) { for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; if (ost) { if (ost->logfile) { fclose(ost->logfile); ost->logfile = NULL; } fifo_free(&ost->fifo); /* works even if fifo is not initialized but set to zero */ av_free(ost->pict_tmp.data[0]); if (ost->video_resample) img_resample_close(ost->img_resample_ctx); if (ost->audio_resample) audio_resample_close(ost->resample); av_free(ost); } } av_free(ost_table); } return ret; fail: ret = -ENOMEM; goto fail1; }


static void vm_change_state_handler(void *opaque, int running, RunState state) { GICv3ITSState *s = (GICv3ITSState *)opaque; Error *err = NULL; int ret; if (running) { return; } ret = kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL, KVM_DEV_ARM_ITS_SAVE_TABLES, NULL, true, &err); if (err) { error_report_err(err); } if (ret < 0 && ret != -EFAULT) { abort(); } }


static uint8_t usb_linux_get_alt_setting(USBHostDevice *s, uint8_t configuration, uint8_t interface) { char device_name[64], line[1024]; int alt_setting; sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port, (int)configuration, (int)interface); if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting", device_name)) { /* Assume alt 0 on error */ return 0; } if (sscanf(line, "%d", &alt_setting) != 1) { /* Assume alt 0 on error */ return 0; } return alt_setting; }


static int append_extradata(APNGDemuxContext *ctx, AVIOContext *pb, int len) { int previous_size = ctx->extra_data_size; int new_size, ret; uint8_t *new_extradata; if (previous_size > INT_MAX - len) return AVERROR_INVALIDDATA; new_size = previous_size + len; new_extradata = av_realloc(ctx->extra_data, new_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!new_extradata) return AVERROR(ENOMEM); ctx->extra_data = new_extradata; ctx->extra_data_size = new_size; if ((ret = avio_read(pb, ctx->extra_data + previous_size, len)) < 0) return ret; return previous_size; }


void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) { const int bs = ctx->block_width_l2; const int bw = 1 << bs; int dct_y_offset = ctx->dct_y_offset; int dct_uv_offset = ctx->dct_uv_offset; int linesize = ctx->m.linesize; int uvlinesize = ctx->m.uvlinesize; const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs + 1); const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs + ctx->is_444); const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs + ctx->is_444); PixblockDSPContext *pdsp = &ctx->m.pdsp; VideoDSPContext *vdsp = &ctx->m.vdsp; if (ctx->bit_depth != 10 && vdsp->emulated_edge_mc && ((mb_x << 4) + 16 > ctx->m.avctx->width || (mb_y << 4) + 16 > ctx->m.avctx->height)) { int y_w = ctx->m.avctx->width - (mb_x << 4); int y_h = ctx->m.avctx->height - (mb_y << 4); int uv_w = (y_w + 1) / 2; int uv_h = y_h; linesize = 16; uvlinesize = 8; vdsp->emulated_edge_mc(&ctx->edge_buf_y[0], ptr_y, linesize, ctx->m.linesize, linesize, 16, 0, 0, y_w, y_h); vdsp->emulated_edge_mc(&ctx->edge_buf_uv[0][0], ptr_u, uvlinesize, ctx->m.uvlinesize, uvlinesize, 16, 0, 0, uv_w, uv_h); vdsp->emulated_edge_mc(&ctx->edge_buf_uv[1][0], ptr_v, uvlinesize, ctx->m.uvlinesize, uvlinesize, 16, 0, 0, uv_w, uv_h); dct_y_offset = bw * linesize; dct_uv_offset = bw * uvlinesize; ptr_y = &ctx->edge_buf_y[0]; ptr_u = &ctx->edge_buf_uv[0][0]; ptr_v = &ctx->edge_buf_uv[1][0]; } else if (ctx->bit_depth == 10 && vdsp->emulated_edge_mc && ((mb_x << 3) + 8 > ctx->m.avctx->width || (mb_y << 3) + 8 > ctx->m.avctx->height)) { int y_w = ctx->m.avctx->width - (mb_x << 3); int y_h = ctx->m.avctx->height - (mb_y << 3); int uv_w = ctx->is_444 ? y_w : (y_w + 1) / 2; int uv_h = y_h; linesize = 16; uvlinesize = 8 + 8 * ctx->is_444; vdsp->emulated_edge_mc(&ctx->edge_buf_y[0], ptr_y, linesize, ctx->m.linesize, linesize / 2, 16, 0, 0, y_w, y_h); vdsp->emulated_edge_mc(&ctx->edge_buf_uv[0][0], ptr_u, uvlinesize, ctx->m.uvlinesize, uvlinesize / 2, 16, 0, 0, uv_w, uv_h); vdsp->emulated_edge_mc(&ctx->edge_buf_uv[1][0], ptr_v, uvlinesize, ctx->m.uvlinesize, uvlinesize / 2, 16, 0, 0, uv_w, uv_h); dct_y_offset = bw * linesize; dct_uv_offset = bw * uvlinesize; ptr_y = &ctx->edge_buf_y[0]; ptr_u = &ctx->edge_buf_uv[0][0]; ptr_v = &ctx->edge_buf_uv[1][0]; } if (!ctx->is_444) { pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize); pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize); pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize); pdsp->get_pixels(ctx->blocks[3], ptr_v, uvlinesize); if (mb_y + 1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) { if (ctx->interlaced) { ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + dct_y_offset, linesize); ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + dct_y_offset + bw, linesize); ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + dct_uv_offset, uvlinesize); ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + dct_uv_offset, uvlinesize); } else { ctx->bdsp.clear_block(ctx->blocks[4]); ctx->bdsp.clear_block(ctx->blocks[5]); ctx->bdsp.clear_block(ctx->blocks[6]); ctx->bdsp.clear_block(ctx->blocks[7]); } } else { pdsp->get_pixels(ctx->blocks[4], ptr_y + dct_y_offset, linesize); pdsp->get_pixels(ctx->blocks[5], ptr_y + dct_y_offset + bw, linesize); pdsp->get_pixels(ctx->blocks[6], ptr_u + dct_uv_offset, uvlinesize); pdsp->get_pixels(ctx->blocks[7], ptr_v + dct_uv_offset, uvlinesize); } } else { pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize); pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize); pdsp->get_pixels(ctx->blocks[6], ptr_y + dct_y_offset, linesize); pdsp->get_pixels(ctx->blocks[7], ptr_y + dct_y_offset + bw, linesize); pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize); pdsp->get_pixels(ctx->blocks[3], ptr_u + bw, uvlinesize); pdsp->get_pixels(ctx->blocks[8], ptr_u + dct_uv_offset, uvlinesize); pdsp->get_pixels(ctx->blocks[9], ptr_u + dct_uv_offset + bw, uvlinesize); pdsp->get_pixels(ctx->blocks[4], ptr_v, uvlinesize); pdsp->get_pixels(ctx->blocks[5], ptr_v + bw, uvlinesize); pdsp->get_pixels(ctx->blocks[10], ptr_v + dct_uv_offset, uvlinesize); pdsp->get_pixels(ctx->blocks[11], ptr_v + dct_uv_offset + bw, uvlinesize); } }


bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq) { virtio_scsi_acquire(s); if (s->events_dropped) { virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); virtio_scsi_release(s); return true; } virtio_scsi_release(s); return false; }


static attribute_align_arg void *frame_worker_thread(void *arg) { PerThreadContext *p = arg; FrameThreadContext *fctx = p->parent; AVCodecContext *avctx = p->avctx; AVCodec *codec = avctx->codec; while (1) { int i; if (p->state == STATE_INPUT_READY && !fctx->die) { pthread_mutex_lock(&p->mutex); while (p->state == STATE_INPUT_READY && !fctx->die) pthread_cond_wait(&p->input_cond, &p->mutex); pthread_mutex_unlock(&p->mutex); } if (fctx->die) break; if (!codec->update_thread_context && (avctx->thread_safe_callbacks || avctx->get_buffer == avcodec_default_get_buffer)) ff_thread_finish_setup(avctx); pthread_mutex_lock(&p->mutex); avcodec_get_frame_defaults(&p->frame); p->got_frame = 0; p->result = codec->decode(avctx, &p->frame, &p->got_frame, &p->avpkt); if (p->state == STATE_SETTING_UP) ff_thread_finish_setup(avctx); pthread_mutex_lock(&p->progress_mutex); for (i = 0; i < MAX_BUFFERS; i++) if (p->progress_used[i]) { p->progress[i][0] = INT_MAX; p->progress[i][1] = INT_MAX; } p->state = STATE_INPUT_READY; pthread_cond_broadcast(&p->progress_cond); pthread_cond_signal(&p->output_cond); pthread_mutex_unlock(&p->progress_mutex); pthread_mutex_unlock(&p->mutex); } return NULL; }


static void gen_spr_970_pmu_sup(CPUPPCState *env) { spr_register(env, SPR_970_PMC7, "PMC7", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); spr_register(env, SPR_970_PMC8, "PMC8", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); }


static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s, AVStream *stream, PayloadContext *hevc_data, char *attr, char *value) { /* profile-space: 0-3 */ /* profile-id: 0-31 */ if (!strcmp(attr, "profile-id")) { hevc_data->profile_id = atoi(value); av_dlog(s, "SDP: found profile-id: %d\n", hevc_data->profile_id); } /* tier-flag: 0-1 */ /* level-id: 0-255 */ /* interop-constraints: [base16] */ /* profile-compatibility-indicator: [base16] */ /* sprop-sub-layer-id: 0-6, defines highest possible value for TID, default: 6 */ /* recv-sub-layer-id: 0-6 */ /* max-recv-level-id: 0-255 */ /* tx-mode: MSM,SSM */ /* sprop-vps: [base64] */ /* sprop-sps: [base64] */ /* sprop-pps: [base64] */ /* sprop-sei: [base64] */ if (!strcmp(attr, "sprop-vps") || !strcmp(attr, "sprop-sps") || !strcmp(attr, "sprop-pps") || !strcmp(attr, "sprop-sei")) { uint8_t **data_ptr; int *size_ptr; if (!strcmp(attr, "sprop-vps")) { data_ptr = &hevc_data->vps; size_ptr = &hevc_data->vps_size; } else if (!strcmp(attr, "sprop-sps")) { data_ptr = &hevc_data->sps; size_ptr = &hevc_data->sps_size; } else if (!strcmp(attr, "sprop-pps")) { data_ptr = &hevc_data->pps; size_ptr = &hevc_data->pps_size; } else if (!strcmp(attr, "sprop-sei")) { data_ptr = &hevc_data->sei; size_ptr = &hevc_data->sei_size; } while (*value) { char base64packet[1024]; uint8_t decoded_packet[1024]; int decoded_packet_size; char *dst = base64packet; while (*value && *value != ',' && (dst - base64packet) < sizeof(base64packet) - 1) { *dst++ = *value++; } *dst++ = '\0'; if (*value == ',') value++; decoded_packet_size = av_base64_decode(decoded_packet, base64packet, sizeof(decoded_packet)); if (decoded_packet_size > 0) { uint8_t *tmp = av_realloc(*data_ptr, decoded_packet_size + sizeof(start_sequence) + *size_ptr); if (!tmp) { av_log(s, AV_LOG_ERROR, "Unable to allocate memory for extradata!\n"); return AVERROR(ENOMEM); } *data_ptr = tmp; memcpy(*data_ptr + *size_ptr, start_sequence, sizeof(start_sequence)); memcpy(*data_ptr + *size_ptr + sizeof(start_sequence), decoded_packet, decoded_packet_size); *size_ptr += sizeof(start_sequence) + decoded_packet_size; } } } /* max-lsr, max-lps, max-cpb, max-dpb, max-br, max-tr, max-tc */ /* max-fps */ /* sprop-max-don-diff: 0-32767 When the RTP stream depends on one or more other RTP streams (in this case tx-mode MUST be equal to "MSM" and MSM is in use), this parameter MUST be present and the value MUST be greater than 0. */ if (!strcmp(attr, "sprop-max-don-diff")) { if (atoi(value) > 0) hevc_data->using_donl_field = 1; av_dlog(s, "Found sprop-max-don-diff in SDP, DON field usage is: %d\n", hevc_data->using_donl_field); } /* sprop-depack-buf-nalus: 0-32767 */ if (!strcmp(attr, "sprop-depack-buf-nalus")) { if (atoi(value) > 0) hevc_data->using_donl_field = 1; av_dlog(s, "Found sprop-depack-buf-nalus in SDP, DON field usage is: %d\n", hevc_data->using_donl_field); } /* sprop-depack-buf-bytes: 0-4294967295 */ /* depack-buf-cap */ /* sprop-segmentation-id: 0-3 */ /* sprop-spatial-segmentation-idc: [base16] */ /* dec-parallel-ca: */ /* include-dph */ return 0; }


static int svq3_decode_frame (AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { MpegEncContext *const s = avctx->priv_data; H264Context *const h = avctx->priv_data; int m, mb_type; unsigned char *extradata; unsigned int size; s->flags = avctx->flags; s->flags2 = avctx->flags2; s->unrestricted_mv = 1; if (!s->context_initialized) { s->width = avctx->width; s->height = avctx->height; h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c; h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c; h->halfpel_flag = 1; h->thirdpel_flag = 1; h->unknown_svq3_flag = 0; h->chroma_qp = 4; if (MPV_common_init (s) < 0) return -1; h->b_stride = 4*s->mb_width; alloc_tables (h); /* prowl for the "SEQH" marker in the extradata */ extradata = (unsigned char *)avctx->extradata; for (m = 0; m < avctx->extradata_size; m++) { if (!memcmp (extradata, "SEQH", 4)) break; extradata++; } /* if a match was found, parse the extra data */ if (!memcmp (extradata, "SEQH", 4)) { GetBitContext gb; size = BE_32(&extradata[4]); init_get_bits (&gb, extradata + 8, size); /* 'frame size code' and optional 'width, height' */ if (get_bits (&gb, 3) == 7) { get_bits (&gb, 12); get_bits (&gb, 12); } h->halfpel_flag = get_bits1 (&gb); h->thirdpel_flag = get_bits1 (&gb); /* unknown fields */ get_bits1 (&gb); get_bits1 (&gb); get_bits1 (&gb); get_bits1 (&gb); s->low_delay = get_bits1 (&gb); /* unknown field */ get_bits1 (&gb); while (get_bits1 (&gb)) { get_bits (&gb, 8); } h->unknown_svq3_flag = get_bits1 (&gb); avctx->has_b_frames = !s->low_delay; } } /* special case for last picture */ if (buf_size == 0) { if (s->next_picture_ptr && !s->low_delay) { *(AVFrame *) data = *(AVFrame *) &s->next_picture; *data_size = sizeof(AVFrame); } return 0; } init_get_bits (&s->gb, buf, 8*buf_size); s->mb_x = s->mb_y = 0; if (svq3_decode_slice_header (h)) return -1; s->pict_type = h->slice_type; s->picture_number = h->slice_num; if(avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d\n", av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag, s->adaptive_quant, s->qscale ); } /* for hurry_up==5 */ s->current_picture.pict_type = s->pict_type; s->current_picture.key_frame = (s->pict_type == I_TYPE); /* skip b frames if we dont have reference frames */ if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0; /* skip b frames if we are in a hurry */ if (avctx->hurry_up && s->pict_type == B_TYPE) return 0; /* skip everything if we are in a hurry >= 5 */ if (avctx->hurry_up >= 5) return 0; if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) return 0; if (s->next_p_frame_damaged) { if (s->pict_type == B_TYPE) return 0; else s->next_p_frame_damaged = 0; } frame_start (h); if (s->pict_type == B_TYPE) { h->frame_num_offset = (h->slice_num - h->prev_frame_num); if (h->frame_num_offset < 0) { h->frame_num_offset += 256; } if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) { av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n"); return -1; } } else { h->prev_frame_num = h->frame_num; h->frame_num = h->slice_num; h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num); if (h->prev_frame_num_offset < 0) { h->prev_frame_num_offset += 256; } } for(m=0; m<2; m++){ int i; for(i=0; i<4; i++){ int j; for(j=-1; j<4; j++) h->ref_cache[m][scan8[0] + 8*i + j]= 1; h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE; } } for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits && ((get_bits_count(&s->gb) & 7) == 0 || show_bits (&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) { skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb)); s->gb.size_in_bits = 8*buf_size; if (svq3_decode_slice_header (h)) return -1; /* TODO: support s->mb_skip_run */ } mb_type = svq3_get_ue_golomb (&s->gb); if (s->pict_type == I_TYPE) { mb_type += 8; } else if (s->pict_type == B_TYPE && mb_type >= 4) { mb_type += 4; } if (mb_type > 33 || svq3_decode_mb (h, mb_type)) { av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); return -1; } if (mb_type != 0) { hl_decode_mb (h); } if (s->pict_type != B_TYPE && !s->low_delay) { s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] = (s->pict_type == P_TYPE && mb_type < 8) ? (mb_type - 1) : -1; } } ff_draw_horiz_band(s, 16*s->mb_y, 16); } MPV_frame_end(s); if (s->pict_type == B_TYPE || s->low_delay) { *(AVFrame *) data = *(AVFrame *) &s->current_picture; } else { *(AVFrame *) data = *(AVFrame *) &s->last_picture; } avctx->frame_number = s->picture_number - 1; /* dont output the last pic after seeking */ if (s->last_picture_ptr || s->low_delay) { *data_size = sizeof(AVFrame); } return buf_size; }


static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma) { int i; RDMALocalBlocks *local = &rdma->local_ram_blocks; for (i = 0; i < local->nb_blocks; i++) { local->block[i].mr = ibv_reg_mr(rdma->pd, local->block[i].local_host_addr, local->block[i].length, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE ); if (!local->block[i].mr) { perror("Failed to register local dest ram block!\n"); break; } rdma->total_registrations++; } if (i >= local->nb_blocks) { return 0; } for (i--; i >= 0; i--) { ibv_dereg_mr(local->block[i].mr); rdma->total_registrations--; } return -1; }


static int encode_plane(AVCodecContext *avctx, uint8_t *src, uint8_t *dst, int step, int stride, int width, int height, PutByteContext *pb) { UtvideoContext *c = avctx->priv_data; uint8_t lengths[256]; uint32_t counts[256] = { 0 }; HuffEntry he[256]; uint32_t offset = 0, slice_len = 0; int i, sstart, send = 0; int symbol; /* Do prediction / make planes */ switch (c->frame_pred) { case PRED_NONE: for (i = 0; i < c->slices; i++) { sstart = send; send = height * (i + 1) / c->slices; write_plane(src + sstart * stride, dst + sstart * width, step, stride, width, send - sstart); } break; case PRED_LEFT: for (i = 0; i < c->slices; i++) { sstart = send; send = height * (i + 1) / c->slices; left_predict(src + sstart * stride, dst + sstart * width, step, stride, width, send - sstart); } break; case PRED_MEDIAN: for (i = 0; i < c->slices; i++) { sstart = send; send = height * (i + 1) / c->slices; median_predict(src + sstart * stride, dst + sstart * width, step, stride, width, send - sstart); } break; default: av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n", c->frame_pred); return AVERROR_OPTION_NOT_FOUND; } /* Count the usage of values */ count_usage(dst, width, height, counts); /* Check for a special case where only one symbol was used */ for (symbol = 0; symbol < 256; symbol++) { /* If non-zero count is found, see if it matches width * height */ if (counts[symbol]) { /* Special case if only one symbol was used */ if (counts[symbol] == width * height) { /* * Write a zero for the single symbol * used in the plane, else 0xFF. */ for (i = 0; i < 256; i++) { if (i == symbol) bytestream2_put_byte(pb, 0); else bytestream2_put_byte(pb, 0xFF); } /* Write zeroes for lengths */ for (i = 0; i < c->slices; i++) bytestream2_put_le32(pb, 0); /* And that's all for that plane folks */ return 0; } break; } } /* Calculate huffman lengths */ calculate_code_lengths(lengths, counts); /* * Write the plane's header into the output packet: * - huffman code lengths (256 bytes) * - slice end offsets (gotten from the slice lengths) */ for (i = 0; i < 256; i++) { bytestream2_put_byte(pb, lengths[i]); he[i].len = lengths[i]; he[i].sym = i; } /* Calculate the huffman codes themselves */ calculate_codes(he); send = 0; for (i = 0; i < c->slices; i++) { sstart = send; send = height * (i + 1) / c->slices; /* * Write the huffman codes to a buffer, * get the offset in bits and convert to bytes. */ offset += write_huff_codes(dst + sstart * width, c->slice_bits, width * (send - sstart), width, send - sstart, he) >> 3; slice_len = offset - slice_len; /* Byteswap the written huffman codes */ c->dsp.bswap_buf((uint32_t *) c->slice_bits, (uint32_t *) c->slice_bits, slice_len >> 2); /* Write the offset to the stream */ bytestream2_put_le32(pb, offset); /* Seek to the data part of the packet */ bytestream2_seek_p(pb, 4 * (c->slices - i - 1) + offset - slice_len, SEEK_CUR); /* Write the slices' data into the output packet */ bytestream2_put_buffer(pb, c->slice_bits, slice_len); /* Seek back to the slice offsets */ bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset, SEEK_CUR); slice_len = offset; } /* And at the end seek to the end of written slice(s) */ bytestream2_seek_p(pb, offset, SEEK_CUR); return 0; }


static void init_excp_4xx_real (CPUPPCState *env) { #if !defined(CONFIG_USER_ONLY) env->excp_vectors[POWERPC_EXCP_CRITICAL] = 0x00000100; env->excp_vectors[POWERPC_EXCP_MCHECK] = 0x00000200; env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500; env->excp_vectors[POWERPC_EXCP_ALIGN] = 0x00000600; env->excp_vectors[POWERPC_EXCP_PROGRAM] = 0x00000700; env->excp_vectors[POWERPC_EXCP_SYSCALL] = 0x00000C00; env->excp_vectors[POWERPC_EXCP_PIT] = 0x00001000; env->excp_vectors[POWERPC_EXCP_FIT] = 0x00001010; env->excp_vectors[POWERPC_EXCP_WDT] = 0x00001020; env->excp_vectors[POWERPC_EXCP_DEBUG] = 0x00002000; env->excp_prefix = 0x00000000; env->ivor_mask = 0x0000FFF0; env->ivpr_mask = 0xFFFF0000; /* Hardware reset vector */ env->hreset_vector = 0xFFFFFFFCUL; #endif }


static void libschroedinger_decode_buffer_free(SchroBuffer *schro_buf, void *priv) { av_freep(&priv); }


void aio_set_dispatching(AioContext *ctx, bool dispatching) { ctx->dispatching = dispatching; if (!dispatching) { /* Write ctx->dispatching before reading e.g. bh->scheduled. * Optimization: this is only needed when we're entering the "unsafe" * phase where other threads must call event_notifier_set. */ smp_mb(); } }


static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) { #if 0 struct { uint32_t offset; /* 0x80000000 + sample start - 4 */ unsigned char unknown1[3]; /* 03 12 04 */ unsigned char channel; /* 1 or 2 */ uint32_t freq; uint32_t size; uint32_t unknown2; /* 01 f4 03 00 */ uint32_t unknown3; /* 00 00 00 00 */ uint32_t unknown4; /* 00 00 00 00 */ /* if loop unknown3 00 15 00 01 unknown4 00 00 00 01 long loop_start_sample; long loop_start_byte; long loop_end_sample; long loop_end_byte; long */ } adxhdr; /* big endian */ /* offset-6 "(c)CRI" */ #endif write_long(buf+0x00,0x80000000|0x20); write_long(buf+0x04,0x03120400|avctx->channels); write_long(buf+0x08,avctx->sample_rate); write_long(buf+0x0c,0); /* FIXME: set after */ write_long(buf+0x10,0x01040300); write_long(buf+0x14,0x00000000); write_long(buf+0x18,0x00000000); memcpy(buf+0x1c,"\0\0(c)CRI",8); return 0x20+4; }


static vscsi_req *vscsi_find_req(VSCSIState *s, uint32_t tag) { if (tag >= VSCSI_REQ_LIMIT || !s->reqs[tag].active) { return NULL; } return &s->reqs[tag]; }


static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size) { const uint8_t *s = src; const uint8_t *end; #ifdef HAVE_MMX const uint8_t *mm_end; #endif uint16_t *d = (uint16_t *)dst; end = s + src_size; #ifdef HAVE_MMX __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm __volatile( "movq %0, %%mm7\n\t" "movq %1, %%mm6\n\t" ::"m"(red_15mask),"m"(green_15mask)); mm_end = end - 15; while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movd %1, %%mm0\n\t" "movd 3%1, %%mm3\n\t" "punpckldq 6%1, %%mm0\n\t" "punpckldq 9%1, %%mm3\n\t" "movq %%mm0, %%mm1\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm3, %%mm4\n\t" "movq %%mm3, %%mm5\n\t" "psllq $7, %%mm0\n\t" "psllq $7, %%mm3\n\t" "pand %%mm7, %%mm0\n\t" "pand %%mm7, %%mm3\n\t" "psrlq $6, %%mm1\n\t" "psrlq $6, %%mm4\n\t" "pand %%mm6, %%mm1\n\t" "pand %%mm6, %%mm4\n\t" "psrlq $19, %%mm2\n\t" "psrlq $19, %%mm5\n\t" "pand %2, %%mm2\n\t" "pand %2, %%mm5\n\t" "por %%mm1, %%mm0\n\t" "por %%mm4, %%mm3\n\t" "por %%mm2, %%mm0\n\t" "por %%mm5, %%mm3\n\t" "psllq $16, %%mm3\n\t" "por %%mm3, %%mm0\n\t" MOVNTQ" %%mm0, %0\n\t" :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); d += 4; s += 12; } __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { const int r= *s++; const int g= *s++; const int b= *s++; *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); } }


static void read_tree(GetBitContext *gb, Tree *tree) { uint8_t tmp1[16], tmp2[16], *in = tmp1, *out = tmp2; int i, t, len; tree->vlc_num = get_bits(gb, 4); if (!tree->vlc_num) { for (i = 0; i < 16; i++) tree->syms[i] = i; return; } if (get_bits1(gb)) { len = get_bits(gb, 3); memset(tmp1, 0, sizeof(tmp1)); for (i = 0; i <= len; i++) { tree->syms[i] = get_bits(gb, 4); tmp1[tree->syms[i]] = 1; } for (i = 0; i < 16; i++) if (!tmp1[i]) tree->syms[++len] = i; } else { len = get_bits(gb, 2); for (i = 0; i < 16; i++) in[i] = i; for (i = 0; i <= len; i++) { int size = 1 << i; for (t = 0; t < 16; t += size << 1) merge(gb, out + t, in + t, size); FFSWAP(uint8_t*, in, out); } memcpy(tree->syms, in, 16); } }


uint32_t ide_data_readl(void *opaque, uint32_t addr) { IDEBus *bus = opaque; IDEState *s = idebus_active_if(bus); uint8_t *p; int ret; /* PIO data access allowed only when DRQ bit is set. The result of a read * during PIO in is indeterminate, return 0 and don't move forward. */ if (!(s->status & DRQ_STAT) || !ide_is_pio_out(s)) { p = s->data_ptr; ret = cpu_to_le32(*(uint32_t *)p); p += 4; s->data_ptr = p; if (p >= s->data_end) s->end_transfer_func(s); return ret;


void do_commit(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); BlockDriverState *bs; if (!strcmp(device, "all")) { bdrv_commit_all(); } else { int ret; bs = bdrv_find(device); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, device); return; } ret = bdrv_commit(bs); if (ret == -EBUSY) { qerror_report(QERR_DEVICE_IN_USE, device); return; } } }


void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref) { void (*start_frame)(AVFilterLink *, AVFilterPicRef *); AVFilterPad *dst = &link_dpad(link); if(!(start_frame = dst->start_frame)) start_frame = avfilter_default_start_frame; /* prepare to copy the picture if it has insufficient permissions */ if((dst->min_perms & picref->perms) != dst->min_perms || dst->rej_perms & picref->perms) { /* av_log(link->dst, AV_LOG_INFO, "frame copy needed (have perms %x, need %x, reject %x)\n", picref->perms, link_dpad(link).min_perms, link_dpad(link).rej_perms); */ link->cur_pic = avfilter_default_get_video_buffer(link, dst->min_perms); link->srcpic = picref; link->cur_pic->pts = link->srcpic->pts; } else link->cur_pic = picref; start_frame(link, link->cur_pic); }


static void ffserver_apply_stream_config(AVCodecContext *enc, const AVDictionary *conf, AVDictionary **opts) { AVDictionaryEntry *e; /* Return values from ffserver_set_*_param are ignored. Values are initially parsed and checked before inserting to AVDictionary. */ //video params if ((e = av_dict_get(conf, "VideoBitRateRangeMin", NULL, 0))) ffserver_set_int_param(&enc->rc_min_rate, e->value, 1000, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoBitRateRangeMax", NULL, 0))) ffserver_set_int_param(&enc->rc_max_rate, e->value, 1000, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "Debug", NULL, 0))) ffserver_set_int_param(&enc->debug, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "Strict", NULL, 0))) ffserver_set_int_param(&enc->strict_std_compliance, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoBufferSize", NULL, 0))) ffserver_set_int_param(&enc->rc_buffer_size, e->value, 8*1024, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoBitRateTolerance", NULL, 0))) ffserver_set_int_param(&enc->bit_rate_tolerance, e->value, 1000, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoBitRate", NULL, 0))) ffserver_set_int_param(&enc->bit_rate, e->value, 1000, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoSizeWidth", NULL, 0))) ffserver_set_int_param(&enc->width, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoSizeHeight", NULL, 0))) ffserver_set_int_param(&enc->height, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "PixelFormat", NULL, 0))) { int val; ffserver_set_int_param(&val, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); enc->pix_fmt = val; } if ((e = av_dict_get(conf, "VideoGopSize", NULL, 0))) ffserver_set_int_param(&enc->gop_size, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoFrameRateNum", NULL, 0))) ffserver_set_int_param(&enc->time_base.num, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoFrameRateDen", NULL, 0))) ffserver_set_int_param(&enc->time_base.den, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoQDiff", NULL, 0))) ffserver_set_int_param(&enc->max_qdiff, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoQMax", NULL, 0))) ffserver_set_int_param(&enc->qmax, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "VideoQMin", NULL, 0))) ffserver_set_int_param(&enc->qmin, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "LumiMask", NULL, 0))) ffserver_set_float_param(&enc->lumi_masking, e->value, 0, -FLT_MAX, FLT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "DarkMask", NULL, 0))) ffserver_set_float_param(&enc->dark_masking, e->value, 0, -FLT_MAX, FLT_MAX, NULL, 0, NULL); if (av_dict_get(conf, "BitExact", NULL, 0)) enc->flags |= CODEC_FLAG_BITEXACT; if (av_dict_get(conf, "DctFastint", NULL, 0)) enc->dct_algo = FF_DCT_FASTINT; if (av_dict_get(conf, "IdctSimple", NULL, 0)) enc->idct_algo = FF_IDCT_SIMPLE; if (av_dict_get(conf, "VideoHighQuality", NULL, 0)) enc->mb_decision = FF_MB_DECISION_BITS; if ((e = av_dict_get(conf, "VideoTag", NULL, 0))) enc->codec_tag = MKTAG(e->value[0], e->value[1], e->value[2], e->value[3]); if (av_dict_get(conf, "Qscale", NULL, 0)) { enc->flags |= CODEC_FLAG_QSCALE; ffserver_set_int_param(&enc->global_quality, e->value, FF_QP2LAMBDA, INT_MIN, INT_MAX, NULL, 0, NULL); } if (av_dict_get(conf, "Video4MotionVector", NULL, 0)) { enc->mb_decision = FF_MB_DECISION_BITS; //FIXME remove enc->flags |= CODEC_FLAG_4MV; } //audio params if ((e = av_dict_get(conf, "AudioChannels", NULL, 0))) ffserver_set_int_param(&enc->channels, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "AudioSampleRate", NULL, 0))) ffserver_set_int_param(&enc->sample_rate, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); if ((e = av_dict_get(conf, "AudioBitRate", NULL, 0))) ffserver_set_int_param(&enc->bit_rate, e->value, 0, INT_MIN, INT_MAX, NULL, 0, NULL); av_opt_set_dict2(enc->priv_data, opts, AV_OPT_SEARCH_CHILDREN); av_opt_set_dict2(enc, opts, AV_OPT_SEARCH_CHILDREN); if (av_dict_count(*opts)) av_log(NULL, AV_LOG_ERROR, "Something went wrong, %d options not set!!!\n", av_dict_count(*opts)); }


static uint32_t grlib_gptimer_readl(void *opaque, target_phys_addr_t addr) { GPTimerUnit *unit = opaque; target_phys_addr_t timer_addr; int id; uint32_t value = 0; addr &= 0xff; /* Unit registers */ switch (addr) { case SCALER_OFFSET: trace_grlib_gptimer_readl(-1, "scaler:", unit->scaler); return unit->scaler; case SCALER_RELOAD_OFFSET: trace_grlib_gptimer_readl(-1, "reload:", unit->reload); return unit->reload; case CONFIG_OFFSET: trace_grlib_gptimer_readl(-1, "config:", unit->config); return unit->config; default: break; } timer_addr = (addr % TIMER_BASE); id = (addr - TIMER_BASE) / TIMER_BASE; if (id >= 0 && id < unit->nr_timers) { /* GPTimer registers */ switch (timer_addr) { case COUNTER_OFFSET: value = ptimer_get_count(unit->timers[id].ptimer); trace_grlib_gptimer_readl(id, "counter value:", value); return value; case COUNTER_RELOAD_OFFSET: value = unit->timers[id].reload; trace_grlib_gptimer_readl(id, "reload value:", value); return value; case CONFIG_OFFSET: trace_grlib_gptimer_readl(id, "scaler value:", unit->timers[id].config); return unit->timers[id].config; default: break; } } trace_grlib_gptimer_unknown_register("read", addr); return 0; }


static void new_subtitle_stream(AVFormatContext *oc, int file_idx) { AVStream *st; AVOutputStream *ost; AVCodec *codec=NULL; AVCodecContext *subtitle_enc; enum CodecID codec_id; st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); if (!st) { fprintf(stderr, "Could not alloc stream\n"); ffmpeg_exit(1); } ost = new_output_stream(oc, file_idx); subtitle_enc = st->codec; output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1); if(!subtitle_stream_copy){ if (subtitle_codec_name) { codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1, avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance); codec= output_codecs[nb_output_codecs-1] = avcodec_find_encoder_by_name(subtitle_codec_name); } else { codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_SUBTITLE); codec = avcodec_find_encoder(codec_id); } } avcodec_get_context_defaults3(st->codec, codec); ost->bitstream_filters = subtitle_bitstream_filters; subtitle_bitstream_filters= NULL; subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; if(subtitle_codec_tag) subtitle_enc->codec_tag= subtitle_codec_tag; if (oc->oformat->flags & AVFMT_GLOBALHEADER) { subtitle_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->flags |= CODEC_FLAG_GLOBAL_HEADER; } if (subtitle_stream_copy) { st->stream_copy = 1; } else { subtitle_enc->codec_id = codec_id; set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec); } if (subtitle_language) { av_metadata_set2(&st->metadata, "language", subtitle_language, 0); av_freep(&subtitle_language); } subtitle_disable = 0; av_freep(&subtitle_codec_name); subtitle_stream_copy = 0; }


static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat) { __asm__ volatile( "movq 24+%4, %%mm6 \n\t" "mov %3, %%"REG_a" \n\t" "pxor %%mm7, %%mm7 \n\t" "1: \n\t" PREFETCH" 64(%0) \n\t" "movd (%0), %%mm0 \n\t" "movd 2(%0), %%mm1 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm3 \n\t" "pmaddwd %4, %%mm0 \n\t" "pmaddwd 8+%4, %%mm1 \n\t" "pmaddwd 16+%4, %%mm2 \n\t" "pmaddwd %%mm6, %%mm3 \n\t" "paddd %%mm1, %%mm0 \n\t" "paddd %%mm3, %%mm2 \n\t" "movd 6(%0), %%mm1 \n\t" "movd 8(%0), %%mm3 \n\t" "add $12, %0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "punpcklbw %%mm7, %%mm3 \n\t" "movq %%mm1, %%mm4 \n\t" "movq %%mm3, %%mm5 \n\t" "pmaddwd %4, %%mm1 \n\t" "pmaddwd 8+%4, %%mm3 \n\t" "pmaddwd 16+%4, %%mm4 \n\t" "pmaddwd %%mm6, %%mm5 \n\t" "paddd %%mm3, %%mm1 \n\t" "paddd %%mm5, %%mm4 \n\t" "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3 \n\t" "paddd %%mm3, %%mm0 \n\t" "paddd %%mm3, %%mm2 \n\t" "paddd %%mm3, %%mm1 \n\t" "paddd %%mm3, %%mm4 \n\t" "psrad $15, %%mm0 \n\t" "psrad $15, %%mm2 \n\t" "psrad $15, %%mm1 \n\t" "psrad $15, %%mm4 \n\t" "packssdw %%mm1, %%mm0 \n\t" "packssdw %%mm4, %%mm2 \n\t" "packuswb %%mm0, %%mm0 \n\t" "packuswb %%mm2, %%mm2 \n\t" "movd %%mm0, (%1, %%"REG_a") \n\t" "movd %%mm2, (%2, %%"REG_a") \n\t" "add $4, %%"REG_a" \n\t" " js 1b \n\t" : "+r" (src) : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-width), "m"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24][0]) : "%"REG_a ); }


static ram_addr_t find_ram_offset(ram_addr_t size) { RAMBlock *block, *next_block; ram_addr_t offset, mingap = ULONG_MAX; if (QLIST_EMPTY(&ram_list.blocks)) return 0; QLIST_FOREACH(block, &ram_list.blocks, next) { ram_addr_t end, next = ULONG_MAX; end = block->offset + block->length; QLIST_FOREACH(next_block, &ram_list.blocks, next) { if (next_block->offset >= end) { next = MIN(next, next_block->offset); } } if (next - end >= size && next - end < mingap) { offset = end; mingap = next - end; } } return offset; }


static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma) { int b_x, b_y; int16_t (*col )[4] = av_malloc(stride*h*sizeof( int16_t)*4); uint32_t (*dist)[4] = av_malloc(stride*h*sizeof(uint32_t)*4); for(b_y=0; b_y<h; b_y++){ int color= 1024; int distance= -1; for(b_x=0; b_x<w; b_x++){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_x; } col [b_x + b_y*stride][1]= color; dist[b_x + b_y*stride][1]= distance >= 0 ? b_x-distance : 9999; } color= 1024; distance= -1; for(b_x=w-1; b_x>=0; b_x--){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_x; } col [b_x + b_y*stride][0]= color; dist[b_x + b_y*stride][0]= distance >= 0 ? distance-b_x : 9999; } } for(b_x=0; b_x<w; b_x++){ int color= 1024; int distance= -1; for(b_y=0; b_y<h; b_y++){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_y; } col [b_x + b_y*stride][3]= color; dist[b_x + b_y*stride][3]= distance >= 0 ? b_y-distance : 9999; } color= 1024; distance= -1; for(b_y=h-1; b_y>=0; b_y--){ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color= dc[b_x + b_y*stride]; distance= b_y; } col [b_x + b_y*stride][2]= color; dist[b_x + b_y*stride][2]= distance >= 0 ? distance-b_y : 9999; } } for (b_y = 0; b_y < h; b_y++) { for (b_x = 0; b_x < w; b_x++) { int mb_index, error, j; int64_t guess, weight_sum; mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride; error = s->error_status_table[mb_index]; if (IS_INTER(s->current_picture.f.mb_type[mb_index])) continue; // inter if (!(error & ER_DC_ERROR)) continue; // dc-ok weight_sum = 0; guess = 0; for (j = 0; j < 4; j++) { int64_t weight = 256 * 256 * 256 * 16 / dist[b_x + b_y*stride][j]; guess += weight*(int64_t)col[b_x + b_y*stride][j]; weight_sum += weight; } guess = (guess + weight_sum / 2) / weight_sum; dc[b_x + b_y * stride] = guess; } } av_freep(&col); av_freep(&dist); }


Coroutine *qemu_coroutine_create(CoroutineEntry *entry) { Coroutine *co = NULL; if (CONFIG_COROUTINE_POOL) { co = QSLIST_FIRST(&alloc_pool); if (!co) { if (release_pool_size > POOL_BATCH_SIZE) { /* Slow path; a good place to register the destructor, too. */ if (!coroutine_pool_cleanup_notifier.notify) { coroutine_pool_cleanup_notifier.notify = coroutine_pool_cleanup; qemu_thread_atexit_add(&coroutine_pool_cleanup_notifier); } /* This is not exact; there could be a little skew between * release_pool_size and the actual size of release_pool. But * it is just a heuristic, it does not need to be perfect. */ alloc_pool_size = atomic_xchg(&release_pool_size, 0); QSLIST_MOVE_ATOMIC(&alloc_pool, &release_pool); co = QSLIST_FIRST(&alloc_pool); } } if (co) { QSLIST_REMOVE_HEAD(&alloc_pool, pool_next); alloc_pool_size--; } } if (!co) { co = qemu_coroutine_new(); } co->entry = entry; QSIMPLEQ_INIT(&co->co_queue_wakeup); return co; }


static void pxa2xx_gpio_write(void *opaque, target_phys_addr_t offset, uint32_t value) { struct pxa2xx_gpio_info_s *s = (struct pxa2xx_gpio_info_s *) opaque; int bank; offset -= s->base; if (offset >= 0x200) return; bank = pxa2xx_gpio_regs[offset].bank; switch (pxa2xx_gpio_regs[offset].reg) { case GPDR: /* GPIO Pin-Direction registers */ s->dir[bank] = value; pxa2xx_gpio_handler_update(s); break; case GPSR: /* GPIO Pin-Output Set registers */ s->olevel[bank] |= value; pxa2xx_gpio_handler_update(s); break; case GPCR: /* GPIO Pin-Output Clear registers */ s->olevel[bank] &= ~value; pxa2xx_gpio_handler_update(s); break; case GRER: /* GPIO Rising-Edge Detect Enable registers */ s->rising[bank] = value; break; case GFER: /* GPIO Falling-Edge Detect Enable registers */ s->falling[bank] = value; break; case GAFR_L: /* GPIO Alternate Function registers */ s->gafr[bank * 2] = value; break; case GAFR_U: /* GPIO Alternate Function registers */ s->gafr[bank * 2 + 1] = value; break; case GEDR: /* GPIO Edge Detect Status registers */ s->status[bank] &= ~value; pxa2xx_gpio_irq_update(s); break; default: cpu_abort(cpu_single_env, "%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset); } }


static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr) { AVFormatContext *s = nut->avf; AVIOContext *bc = s->pb; int64_t end; uint64_t tmp; nut->last_syncpoint_pos = avio_tell(bc) - 8; end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE); end += avio_tell(bc); tmp = ffio_read_varlen(bc); *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc); if (*back_ptr < 0) return -1; ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp / nut->time_base_count); if (skip_reserved(bc, end) || ffio_get_checksum(bc)) { av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n"); return -1; } *ts = tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE; ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts); return 0; }


static void coroutine_fn v9fs_flush(void *opaque) { ssize_t err; int16_t tag; size_t offset = 7; V9fsPDU *cancel_pdu; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; err = pdu_unmarshal(pdu, offset, "w", &tag); if (err < 0) { pdu_complete(pdu, err); return; } trace_v9fs_flush(pdu->tag, pdu->id, tag); QLIST_FOREACH(cancel_pdu, &s->active_list, next) { if (cancel_pdu->tag == tag) { break; } } if (cancel_pdu) { cancel_pdu->cancelled = 1; /* * Wait for pdu to complete. */ qemu_co_queue_wait(&cancel_pdu->complete, NULL); cancel_pdu->cancelled = 0; pdu_free(cancel_pdu); } pdu_complete(pdu, 7); }


static inline void expand_category(COOKContext *q, int *category, int *category_index) { int i; for (i = 0; i < q->num_vectors; i++) ++category[category_index[i]]; }