int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot, target_ulong address, int rw, int access_type) { uint8_t ASID = env->CP0_EntryHi & 0xFF; int i; for (i = 0; i < env->tlb->tlb_in_use; i++) { r4k_tlb_t *tlb = &env->tlb->mmu.r4k.tlb[i]; /* 1k pages are not supported. */ target_ulong mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1); target_ulong tag = address & ~mask; target_ulong VPN = tlb->VPN & ~mask; #if defined(TARGET_MIPS64) tag &= env->SEGMask; #endif /* Check ASID, virtual page number & size */ if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) { /* TLB match */ int n = !!(address & mask & ~(mask >> 1)); /* Check access rights */ if (!(n ? tlb->V1 : tlb->V0)) { return TLBRET_INVALID; } if (rw == MMU_INST_FETCH && (n ? tlb->XI1 : tlb->XI0)) { return TLBRET_XI; } if (rw == MMU_DATA_LOAD && (n ? tlb->RI1 : tlb->RI0)) { return TLBRET_RI; } if (rw != MMU_DATA_STORE || (n ? tlb->D1 : tlb->D0)) { *physical = tlb->PFN[n] | (address & (mask >> 1)); *prot = PAGE_READ; if (n ? tlb->D1 : tlb->D0) *prot |= PAGE_WRITE; return TLBRET_MATCH; } return TLBRET_DIRTY; } } return TLBRET_NOMATCH; }


GArray *bios_linker_loader_init(void) { return g_array_new(false, true /* clear */, 1); }


static void exynos4210_fimd_update(void *opaque) { Exynos4210fimdState *s = (Exynos4210fimdState *)opaque; Exynos4210fimdWindow *w; int i, line; target_phys_addr_t fb_line_addr, inc_size; int scrn_height; int first_line = -1, last_line = -1, scrn_width; bool blend = false; uint8_t *host_fb_addr; bool is_dirty = false; const int global_width = (s->vidtcon[2] & FIMD_VIDTCON2_SIZE_MASK) + 1; const int global_height = ((s->vidtcon[2] >> FIMD_VIDTCON2_VER_SHIFT) & FIMD_VIDTCON2_SIZE_MASK) + 1; if (!s || !s->console || !ds_get_bits_per_pixel(s->console) || !s->enabled) { return; } exynos4210_update_resolution(s); for (i = 0; i < NUM_OF_WINDOWS; i++) { w = &s->window[i]; if ((w->wincon & FIMD_WINCON_ENWIN) && w->host_fb_addr) { scrn_height = w->rightbot_y - w->lefttop_y + 1; scrn_width = w->virtpage_width; /* Total width of virtual screen page in bytes */ inc_size = scrn_width + w->virtpage_offsize; memory_region_sync_dirty_bitmap(w->mem_section.mr); host_fb_addr = w->host_fb_addr; fb_line_addr = w->mem_section.offset_within_region; for (line = 0; line < scrn_height; line++) { is_dirty = memory_region_get_dirty(w->mem_section.mr, fb_line_addr, scrn_width, DIRTY_MEMORY_VGA); if (s->invalidate || is_dirty) { if (first_line == -1) { first_line = line; } last_line = line; w->draw_line(w, host_fb_addr, s->ifb + w->lefttop_x * RGBA_SIZE + (w->lefttop_y + line) * global_width * RGBA_SIZE, blend); } host_fb_addr += inc_size; fb_line_addr += inc_size; is_dirty = false; } memory_region_reset_dirty(w->mem_section.mr, w->mem_section.offset_within_region, w->fb_len, DIRTY_MEMORY_VGA); blend = true; } } /* Copy resulting image to QEMU_CONSOLE. */ if (first_line >= 0) { uint8_t *d; int bpp; bpp = ds_get_bits_per_pixel(s->console); fimd_update_putpix_qemu(bpp); bpp = (bpp + 1) >> 3; d = ds_get_data(s->console); for (line = first_line; line <= last_line; line++) { fimd_copy_line_toqemu(global_width, s->ifb + global_width * line * RGBA_SIZE, d + global_width * line * bpp); } dpy_update(s->console, 0, 0, global_width, global_height); } s->invalidate = false; s->vidintcon[1] |= FIMD_VIDINT_INTFRMPEND; if ((s->vidcon[0] & FIMD_VIDCON0_ENVID_F) == 0) { exynos4210_fimd_enable(s, false); } exynos4210_fimd_update_irq(s); }


static int find_large_solid_color_rect(VncState *vs, int x, int y, int w, int h, int max_rows) { int dx, dy, dw, dh; int n = 0; /* Try to find large solid-color areas and send them separately. */ for (dy = y; dy < y + h; dy += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) { /* If a rectangle becomes too large, send its upper part now. */ if (dy - y >= max_rows) { n += send_rect_simple(vs, x, y, w, max_rows); y += max_rows; h -= max_rows; } dh = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (y + h - dy)); for (dx = x; dx < x + w; dx += VNC_TIGHT_MAX_SPLIT_TILE_SIZE) { uint32_t color_value; int x_best, y_best, w_best, h_best; dw = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (x + w - dx)); if (!check_solid_tile(vs, dx, dy, dw, dh, &color_value, false)) { continue ; } /* Get dimensions of solid-color area. */ find_best_solid_area(vs, dx, dy, w - (dx - x), h - (dy - y), color_value, &w_best, &h_best); /* Make sure a solid rectangle is large enough (or the whole rectangle is of the same color). */ if (w_best * h_best != w * h && w_best * h_best < VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE) { continue; } /* Try to extend solid rectangle to maximum size. */ x_best = dx; y_best = dy; extend_solid_area(vs, x, y, w, h, color_value, &x_best, &y_best, &w_best, &h_best); /* Send rectangles at top and left to solid-color area. */ if (y_best != y) { n += send_rect_simple(vs, x, y, w, y_best-y); } if (x_best != x) { n += vnc_tight_send_framebuffer_update(vs, x, y_best, x_best-x, h_best); } /* Send solid-color rectangle. */ n += send_sub_rect_solid(vs, x_best, y_best, w_best, h_best); /* Send remaining rectangles (at right and bottom). */ if (x_best + w_best != x + w) { n += vnc_tight_send_framebuffer_update(vs, x_best+w_best, y_best, w-(x_best-x)-w_best, h_best); } if (y_best + h_best != y + h) { n += vnc_tight_send_framebuffer_update(vs, x, y_best+h_best, w, h-(y_best-y)-h_best); } /* Return after all recursive calls are done. */ return n; } } return n + send_rect_simple(vs, x, y, w, h); }


static void iscsi_allocationmap_clear(IscsiLun *iscsilun, int64_t sector_num, int nb_sectors) { int64_t cluster_num, nb_clusters; if (iscsilun->allocationmap == NULL) { return; } cluster_num = DIV_ROUND_UP(sector_num, iscsilun->cluster_sectors); nb_clusters = (sector_num + nb_sectors) / iscsilun->cluster_sectors - cluster_num; if (nb_clusters > 0) { bitmap_clear(iscsilun->allocationmap, cluster_num, nb_clusters); } }


static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0); }


static int avi_read_header(AVFormatContext *s) { AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; unsigned int tag, tag1, handler; int codec_type, stream_index, frame_period; unsigned int size; int i; AVStream *st; AVIStream *ast = NULL; int avih_width = 0, avih_height = 0; int amv_file_format = 0; uint64_t list_end = 0; int ret; avi->stream_index = -1; ret = get_riff(s, pb); if (ret < 0) return ret; avi->fsize = avio_size(pb); if (avi->fsize <= 0) avi->fsize = avi->riff_end == 8 ? INT64_MAX : avi->riff_end; /* first list tag */ stream_index = -1; codec_type = -1; frame_period = 0; for (;;) { if (pb->eof_reached) goto fail; tag = avio_rl32(pb); size = avio_rl32(pb); print_tag("tag", tag, size); switch (tag) { case MKTAG('L', 'I', 'S', 'T'): list_end = avio_tell(pb) + size; /* Ignored, except at start of video packets. */ tag1 = avio_rl32(pb); print_tag("list", tag1, 0); if (tag1 == MKTAG('m', 'o', 'v', 'i')) { avi->movi_list = avio_tell(pb) - 4; if (size) avi->movi_end = avi->movi_list + size + (size & 1); else avi->movi_end = avio_size(pb); av_dlog(NULL, "movi end=%"PRIx64"\n", avi->movi_end); goto end_of_header; } else if (tag1 == MKTAG('I', 'N', 'F', 'O')) ff_read_riff_info(s, size - 4); else if (tag1 == MKTAG('n', 'c', 'd', 't')) avi_read_nikon(s, list_end); break; case MKTAG('I', 'D', 'I', 'T'): { unsigned char date[64] = { 0 }; size += (size & 1); size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1)); avio_skip(pb, size); avi_metadata_creation_time(&s->metadata, date); break; } case MKTAG('d', 'm', 'l', 'h'): avi->is_odml = 1; avio_skip(pb, size + (size & 1)); break; case MKTAG('a', 'm', 'v', 'h'): amv_file_format = 1; case MKTAG('a', 'v', 'i', 'h'): /* AVI header */ /* using frame_period is bad idea */ frame_period = avio_rl32(pb); avio_skip(pb, 4); avio_rl32(pb); avi->non_interleaved |= avio_rl32(pb) & AVIF_MUSTUSEINDEX; avio_skip(pb, 2 * 4); avio_rl32(pb); avio_rl32(pb); avih_width = avio_rl32(pb); avih_height = avio_rl32(pb); avio_skip(pb, size - 10 * 4); break; case MKTAG('s', 't', 'r', 'h'): /* stream header */ tag1 = avio_rl32(pb); handler = avio_rl32(pb); /* codec tag */ if (tag1 == MKTAG('p', 'a', 'd', 's')) { avio_skip(pb, size - 8); break; } else { stream_index++; st = avformat_new_stream(s, NULL); if (!st) goto fail; st->id = stream_index; ast = av_mallocz(sizeof(AVIStream)); if (!ast) goto fail; st->priv_data = ast; } if (amv_file_format) tag1 = stream_index ? MKTAG('a', 'u', 'd', 's') : MKTAG('v', 'i', 'd', 's'); print_tag("strh", tag1, -1); if (tag1 == MKTAG('i', 'a', 'v', 's') || tag1 == MKTAG('i', 'v', 'a', 's')) { int64_t dv_dur; /* After some consideration -- I don't think we * have to support anything but DV in type1 AVIs. */ if (s->nb_streams != 1) goto fail; if (handler != MKTAG('d', 'v', 's', 'd') && handler != MKTAG('d', 'v', 'h', 'd') && handler != MKTAG('d', 'v', 's', 'l')) goto fail; ast = s->streams[0]->priv_data; av_freep(&s->streams[0]->codec->extradata); av_freep(&s->streams[0]->codec); av_freep(&s->streams[0]->info); av_freep(&s->streams[0]); s->nb_streams = 0; if (CONFIG_DV_DEMUXER) { avi->dv_demux = avpriv_dv_init_demux(s); if (!avi->dv_demux) goto fail; } else goto fail; s->streams[0]->priv_data = ast; avio_skip(pb, 3 * 4); ast->scale = avio_rl32(pb); ast->rate = avio_rl32(pb); avio_skip(pb, 4); /* start time */ dv_dur = avio_rl32(pb); if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) { dv_dur *= AV_TIME_BASE; s->duration = av_rescale(dv_dur, ast->scale, ast->rate); } /* else, leave duration alone; timing estimation in utils.c * will make a guess based on bitrate. */ stream_index = s->nb_streams - 1; avio_skip(pb, size - 9 * 4); break; } assert(stream_index < s->nb_streams); st->codec->stream_codec_tag = handler; avio_rl32(pb); /* flags */ avio_rl16(pb); /* priority */ avio_rl16(pb); /* language */ avio_rl32(pb); /* initial frame */ ast->scale = avio_rl32(pb); ast->rate = avio_rl32(pb); if (!(ast->scale && ast->rate)) { av_log(s, AV_LOG_WARNING, "scale/rate is %"PRIu32"/%"PRIu32" which is invalid. " "(This file has been generated by broken software.)\n", ast->scale, ast->rate); if (frame_period) { ast->rate = 1000000; ast->scale = frame_period; } else { ast->rate = 25; ast->scale = 1; } } avpriv_set_pts_info(st, 64, ast->scale, ast->rate); ast->cum_len = avio_rl32(pb); /* start */ st->nb_frames = avio_rl32(pb); st->start_time = 0; avio_rl32(pb); /* buffer size */ avio_rl32(pb); /* quality */ ast->sample_size = avio_rl32(pb); /* sample ssize */ ast->cum_len *= FFMAX(1, ast->sample_size); av_dlog(s, "%"PRIu32" %"PRIu32" %d\n", ast->rate, ast->scale, ast->sample_size); switch (tag1) { case MKTAG('v', 'i', 'd', 's'): codec_type = AVMEDIA_TYPE_VIDEO; ast->sample_size = 0; break; case MKTAG('a', 'u', 'd', 's'): codec_type = AVMEDIA_TYPE_AUDIO; break; case MKTAG('t', 'x', 't', 's'): codec_type = AVMEDIA_TYPE_SUBTITLE; break; case MKTAG('d', 'a', 't', 's'): codec_type = AVMEDIA_TYPE_DATA; break; default: av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1); goto fail; } if (ast->sample_size == 0) st->duration = st->nb_frames; ast->frame_offset = ast->cum_len; avio_skip(pb, size - 12 * 4); break; case MKTAG('s', 't', 'r', 'f'): /* stream header */ if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) { avio_skip(pb, size); } else { uint64_t cur_pos = avio_tell(pb); if (cur_pos < list_end) size = FFMIN(size, list_end - cur_pos); st = s->streams[stream_index]; switch (codec_type) { case AVMEDIA_TYPE_VIDEO: if (amv_file_format) { st->codec->width = avih_width; st->codec->height = avih_height; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = AV_CODEC_ID_AMV; avio_skip(pb, size); break; } tag1 = ff_get_bmp_header(pb, st); if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D', 'X', 'S', 'A')) { st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_tag = tag1; st->codec->codec_id = AV_CODEC_ID_XSUB; break; } if (size > 10 * 4 && size < (1 << 30)) { st->codec->extradata_size = size - 10 * 4; st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!st->codec->extradata) { st->codec->extradata_size = 0; return AVERROR(ENOMEM); } avio_read(pb, st->codec->extradata, st->codec->extradata_size); } // FIXME: check if the encoder really did this correctly if (st->codec->extradata_size & 1) avio_r8(pb); /* Extract palette from extradata if bpp <= 8. * This code assumes that extradata contains only palette. * This is true for all paletted codecs implemented in * Libav. */ if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { int pal_size = (1 << st->codec->bits_per_coded_sample) << 2; const uint8_t *pal_src; pal_size = FFMIN(pal_size, st->codec->extradata_size); pal_src = st->codec->extradata + st->codec->extradata_size - pal_size; #if HAVE_BIGENDIAN for (i = 0; i < pal_size / 4; i++) ast->pal[i] = av_bswap32(((uint32_t *)pal_src)[i]); #else memcpy(ast->pal, pal_src, pal_size); #endif ast->has_pal = 1; } print_tag("video", tag1, 0); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_tag = tag1; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); /* This is needed to get the pict type which is necessary * for generating correct pts. */ st->need_parsing = AVSTREAM_PARSE_HEADERS; // Support "Resolution 1:1" for Avid AVI Codec if (tag1 == MKTAG('A', 'V', 'R', 'n') && st->codec->extradata_size >= 31 && !memcmp(&st->codec->extradata[28], "1:1", 3)) st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; if (st->codec->codec_tag == 0 && st->codec->height > 0 && st->codec->extradata_size < 1U << 30) { st->codec->extradata_size += 9; if ((ret = av_reallocp(&st->codec->extradata, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0) { st->codec->extradata_size = 0; return ret; } else memcpy(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9); } st->codec->height = FFABS(st->codec->height); // avio_skip(pb, size - 5 * 4); break; case AVMEDIA_TYPE_AUDIO: ret = ff_get_wav_header(pb, st->codec, size); if (ret < 0) return ret; ast->dshow_block_align = st->codec->block_align; if (ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align) { av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align); ast->sample_size = st->codec->block_align; } /* 2-aligned * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ if (size & 1) avio_skip(pb, 1); /* Force parsing as several audio frames can be in * one packet and timestamps refer to packet start. */ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; /* ADTS header is in extradata, AAC without header must be * stored as exact frames. Parser not needed and it will * fail. */ if (st->codec->codec_id == AV_CODEC_ID_AAC && st->codec->extradata_size) st->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (st->codec->stream_codec_tag == AV_RL32("Axan")) { st->codec->codec_id = AV_CODEC_ID_XAN_DPCM; st->codec->codec_tag = 0; } if (amv_file_format) { st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV; ast->dshow_block_align = 0; } break; case AVMEDIA_TYPE_SUBTITLE: st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id = AV_CODEC_ID_PROBE; break; default: st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = AV_CODEC_ID_NONE; st->codec->codec_tag = 0; avio_skip(pb, size); break; } } break; case MKTAG('i', 'n', 'd', 'x'): i = avio_tell(pb); if (pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && read_braindead_odml_indx(s, 0) < 0 && (s->error_recognition & AV_EF_EXPLODE)) goto fail; avio_seek(pb, i + size, SEEK_SET); break; case MKTAG('v', 'p', 'r', 'p'): if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) { AVRational active, active_aspect; st = s->streams[stream_index]; avio_rl32(pb); avio_rl32(pb); avio_rl32(pb); avio_rl32(pb); avio_rl32(pb); active_aspect.den = avio_rl16(pb); active_aspect.num = avio_rl16(pb); active.num = avio_rl32(pb); active.den = avio_rl32(pb); avio_rl32(pb); // nbFieldsPerFrame if (active_aspect.num && active_aspect.den && active.num && active.den) { st->sample_aspect_ratio = av_div_q(active_aspect, active); av_dlog(s, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect.den, active.num, active.den); } size -= 9 * 4; } avio_skip(pb, size); break; case MKTAG('s', 't', 'r', 'n'): if (s->nb_streams) { ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size); if (ret < 0) return ret; break; } default: if (size > 1000000) { av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, " "I will ignore it and try to continue anyway.\n"); if (s->error_recognition & AV_EF_EXPLODE) goto fail; avi->movi_list = avio_tell(pb) - 4; avi->movi_end = avio_size(pb); goto end_of_header; } /* skip tag */ size += (size & 1); avio_skip(pb, size); break; } } end_of_header: /* check stream number */ if (stream_index != s->nb_streams - 1) { fail: return AVERROR_INVALIDDATA; } if (!avi->index_loaded && pb->seekable) avi_load_index(s); avi->index_loaded = 1; avi->non_interleaved |= guess_ni_flag(s); for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->nb_index_entries) break; } if (i == s->nb_streams && avi->non_interleaved) { av_log(s, AV_LOG_WARNING, "Non-interleaved AVI without index, switching to interleaved\n"); avi->non_interleaved = 0; } if (avi->non_interleaved) { av_log(s, AV_LOG_INFO, "non-interleaved AVI\n"); clean_index(s); } ff_metadata_conv_ctx(s, NULL, avi_metadata_conv); ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); return 0; }


static void phys_page_set(AddressSpaceDispatch *d, hwaddr index, hwaddr nb, uint16_t leaf) { /* Wildly overreserve - it doesn't matter much. */ phys_map_node_reserve(3 * P_L2_LEVELS); phys_page_set_level(&d->phys_map, &index, &nb, leaf, P_L2_LEVELS - 1); }


static av_cold int g726_decode_init(AVCodecContext *avctx) { G726Context* c = avctx->priv_data; if (avctx->sample_rate <= 0) { av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); return -1; } if(avctx->channels != 1){ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); return -1; } c->code_size = avctx->bits_per_coded_sample; if (c->code_size < 2 || c->code_size > 5) { av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); return AVERROR(EINVAL); } g726_reset(c, c->code_size - 2); avctx->sample_fmt = AV_SAMPLE_FMT_S16; return 0; }


static uint32_t isa_mmio_readw(void *opaque, target_phys_addr_t addr) { return cpu_inw(addr & IOPORTS_MASK); }


static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) { MemoryRegion *mr = NULL; AssignStorage *assign_info = (AssignStorage *) sccb; sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev(); assert(mhd); ram_addr_t unassign_addr = (assign_info->rn - 1) * mhd->rzm; MemoryRegion *sysmem = get_system_memory(); /* if the addr is a multiple of 256 MB */ if ((unassign_addr % MEM_SECTION_SIZE == 0) && (unassign_addr >= mhd->padded_ram_size)) { mhd->standby_state_map[(unassign_addr - mhd->padded_ram_size) / MEM_SECTION_SIZE] = 0; /* find the specified memory region and destroy it */ mr = memory_region_find(sysmem, unassign_addr, 1).mr; memory_region_unref(mr); if (mr) { int i; int is_removable = 1; ram_addr_t map_offset = (unassign_addr - mhd->padded_ram_size - (unassign_addr - mhd->padded_ram_size) % mhd->standby_subregion_size); /* Mark all affected subregions as 'standby' once again */ for (i = 0; i < (mhd->standby_subregion_size / MEM_SECTION_SIZE); i++) { if (mhd->standby_state_map[i + map_offset / MEM_SECTION_SIZE]) { is_removable = 0; break; } } if (is_removable) { memory_region_del_subregion(sysmem, mr); object_unref(OBJECT(mr)); } } } sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION); }


static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return bdrv_get_info(bs->file->bs, bdi); }


static int nbd_co_writev_1(NbdClientSession *client, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int offset) { struct nbd_request request = { .type = NBD_CMD_WRITE }; struct nbd_reply reply; ssize_t ret; if (!bdrv_enable_write_cache(client->bs) && (client->nbdflags & NBD_FLAG_SEND_FUA)) { request.type |= NBD_CMD_FLAG_FUA; } request.from = sector_num * 512; request.len = nb_sectors * 512; nbd_coroutine_start(client, &request); ret = nbd_co_send_request(client, &request, qiov, offset); if (ret < 0) { reply.error = -ret; } else { nbd_co_receive_reply(client, &request, &reply, NULL, 0); } nbd_coroutine_end(client, &request); return -reply.error; }


START_TEST(simple_whitespace) { int i; struct { const char *encoded; LiteralQObject decoded; } test_cases[] = { { .encoded = " [ 43 , 42 ]", .decoded = QLIT_QLIST(((LiteralQObject[]){ QLIT_QINT(43), QLIT_QINT(42), { } })), }, { .encoded = " [ 43 , { 'h' : 'b' }, [ ], 42 ]", .decoded = QLIT_QLIST(((LiteralQObject[]){ QLIT_QINT(43), QLIT_QDICT(((LiteralQDictEntry[]){ { "h", QLIT_QSTR("b") }, { }})), QLIT_QLIST(((LiteralQObject[]){ { }})), QLIT_QINT(42), { } })), }, { .encoded = " [ 43 , { 'h' : 'b' , 'a' : 32 }, [ ], 42 ]", .decoded = QLIT_QLIST(((LiteralQObject[]){ QLIT_QINT(43), QLIT_QDICT(((LiteralQDictEntry[]){ { "h", QLIT_QSTR("b") }, { "a", QLIT_QINT(32) }, { }})), QLIT_QLIST(((LiteralQObject[]){ { }})), QLIT_QINT(42), { } })), }, { } }; for (i = 0; test_cases[i].encoded; i++) { QObject *obj; QString *str; obj = qobject_from_json(test_cases[i].encoded); fail_unless(obj != NULL); fail_unless(qobject_type(obj) == QTYPE_QLIST); fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); str = qobject_to_json(obj); qobject_decref(obj); obj = qobject_from_json(qstring_get_str(str)); fail_unless(obj != NULL); fail_unless(qobject_type(obj) == QTYPE_QLIST); fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); qobject_decref(obj); QDECREF(str); } }


gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) { if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map)) { return true; } return false; }


static int nvic_pending_prio(NVICState *s) { /* return the priority of the current pending interrupt, * or NVIC_NOEXC_PRIO if no interrupt is pending */ return s->vectpending ? s->vectors[s->vectpending].prio : NVIC_NOEXC_PRIO; }


static uint64_t pci_config_get_pref_base(PCIDevice *d, uint32_t base, uint32_t upper) { uint64_t val; val = ((uint64_t)pci_get_word(d->config + base) & PCI_PREF_RANGE_MASK) << 16; val |= (uint64_t)pci_get_long(d->config + upper) << 32; return val; }


static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[], const char *kind, const char *name, Error **errp) { int i = 0; int value = *obj; char *enum_str; assert(strings); while (strings[i++] != NULL); if (value >= i - 1) { error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); return; } enum_str = (char *)strings[value]; qmp_output_type_str(v, &enum_str, name, errp); }


static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; char color_parameter_type[5] = { 0 }; int color_primaries, color_trc, color_matrix; if (c->fc->nb_streams < 1) return 0; st = c->fc->streams[c->fc->nb_streams - 1]; avio_read(pb, color_parameter_type, 4); if (strncmp(color_parameter_type, "nclx", 4) && strncmp(color_parameter_type, "nclc", 4)) { av_log(c->fc, AV_LOG_WARNING, "unsupported color_parameter_type %s\n", color_parameter_type); return 0; } color_primaries = avio_rb16(pb); color_trc = avio_rb16(pb); color_matrix = avio_rb16(pb); av_dlog(c->fc, "%s: pri %d trc %d matrix %d", color_parameter_type, color_primaries, color_trc, color_matrix); if (c->isom) { uint8_t color_range = avio_r8(pb) >> 7; av_dlog(c->fc, " full %"PRIu8"", color_range); if (color_range) st->codec->color_range = AVCOL_RANGE_JPEG; else st->codec->color_range = AVCOL_RANGE_MPEG; /* 14496-12 references JPEG XR specs (rather than the more complete * 23001-8) so some adjusting is required */ if (color_primaries >= AVCOL_PRI_FILM) color_primaries = AVCOL_PRI_UNSPECIFIED; if ((color_trc >= AVCOL_TRC_LINEAR && color_trc <= AVCOL_TRC_LOG_SQRT) || color_trc >= AVCOL_TRC_BT2020_10) color_trc = AVCOL_TRC_UNSPECIFIED; if (color_matrix >= AVCOL_SPC_BT2020_NCL) color_matrix = AVCOL_SPC_UNSPECIFIED; st->codec->color_primaries = color_primaries; st->codec->color_trc = color_trc; st->codec->colorspace = color_matrix; } else { /* color primaries, Table 4-4 */ switch (color_primaries) { case 1: st->codec->color_primaries = AVCOL_PRI_BT709; break; case 5: st->codec->color_primaries = AVCOL_PRI_SMPTE170M; break; case 6: st->codec->color_primaries = AVCOL_PRI_SMPTE240M; break; } /* color transfer, Table 4-5 */ switch (color_trc) { case 1: st->codec->color_trc = AVCOL_TRC_BT709; break; case 7: st->codec->color_trc = AVCOL_TRC_SMPTE240M; break; } /* color matrix, Table 4-6 */ switch (color_matrix) { case 1: st->codec->colorspace = AVCOL_SPC_BT709; break; case 6: st->codec->colorspace = AVCOL_SPC_BT470BG; break; case 7: st->codec->colorspace = AVCOL_SPC_SMPTE240M; break; } } av_dlog(c->fc, "\n"); return 0; }


static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs) { int err = 0; char *old_name, *new_name; char *end; if (vs->newdirfid != -1) { V9fsFidState *dirfidp; dirfidp = lookup_fid(s, vs->newdirfid); if (dirfidp == NULL) { err = -ENOENT; goto out; } BUG_ON(dirfidp->fid_type != P9_FID_NONE); new_name = qemu_mallocz(dirfidp->path.size + vs->name.size + 2); strcpy(new_name, dirfidp->path.data); strcat(new_name, "/"); strcat(new_name + dirfidp->path.size, vs->name.data); } else { old_name = vs->fidp->path.data; end = strrchr(old_name, '/'); if (end) { end++; } else { end = old_name; } new_name = qemu_mallocz(end - old_name + vs->name.size + 1); strncat(new_name, old_name, end - old_name); strncat(new_name + (end - old_name), vs->name.data, vs->name.size); } v9fs_string_free(&vs->name); vs->name.data = qemu_strdup(new_name); vs->name.size = strlen(new_name); if (strcmp(new_name, vs->fidp->path.data) != 0) { if (v9fs_do_rename(s, &vs->fidp->path, &vs->name)) { err = -errno; } else { V9fsFidState *fidp; /* * Fixup fid's pointing to the old name to * start pointing to the new name */ for (fidp = s->fid_list; fidp; fidp = fidp->next) { if (vs->fidp == fidp) { /* * we replace name of this fid towards the end * so that our below strcmp will work */ continue; } if (!strncmp(vs->fidp->path.data, fidp->path.data, strlen(vs->fidp->path.data))) { /* replace the name */ v9fs_fix_path(&fidp->path, &vs->name, strlen(vs->fidp->path.data)); } } v9fs_string_copy(&vs->fidp->path, &vs->name); } } out: v9fs_string_free(&vs->name); return err; }


build_srat(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) { AcpiSystemResourceAffinityTable *srat; AcpiSratProcessorGiccAffinity *core; AcpiSratMemoryAffinity *numamem; int i, j, srat_start; uint64_t mem_base; uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t)); for (i = 0; i < guest_info->smp_cpus; i++) { for (j = 0; j < nb_numa_nodes; j++) { if (test_bit(i, numa_info[j].node_cpu)) { cpu_node[i] = j; break; } } } srat_start = table_data->len; srat = acpi_data_push(table_data, sizeof(*srat)); srat->reserved1 = cpu_to_le32(1); for (i = 0; i < guest_info->smp_cpus; ++i) { core = acpi_data_push(table_data, sizeof(*core)); core->type = ACPI_SRAT_PROCESSOR_GICC; core->length = sizeof(*core); core->proximity = cpu_to_le32(cpu_node[i]); core->acpi_processor_uid = cpu_to_le32(i); core->flags = cpu_to_le32(1); } g_free(cpu_node); mem_base = guest_info->memmap[VIRT_MEM].base; for (i = 0; i < nb_numa_nodes; ++i) { numamem = acpi_data_push(table_data, sizeof(*numamem)); build_srat_memory(numamem, mem_base, numa_info[i].node_mem, i, MEM_AFFINITY_ENABLED); mem_base += numa_info[i].node_mem; } build_header(linker, table_data, (void *)(table_data->data + srat_start), "SRAT", table_data->len - srat_start, 3, NULL, NULL); }


static void tcg_out_ri64(TCGContext *s, int const_arg, TCGArg arg) { if (const_arg) { assert(const_arg == 1); tcg_out8(s, TCG_CONST); tcg_out64(s, arg); } else { tcg_out_r(s, arg); } }


static void tgen_compare_branch(TCGContext *s, S390Opcode opc, int cc, TCGReg r1, TCGReg r2, int labelno) { TCGLabel* l = &s->labels[labelno]; intptr_t off; if (l->has_value) { off = l->u.value_ptr - s->code_ptr; } else { /* We need to keep the offset unchanged for retranslation. */ off = s->code_ptr[1]; tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, labelno, -2); } tcg_out16(s, (opc & 0xff00) | (r1 << 4) | r2); tcg_out16(s, off); tcg_out16(s, cc << 12 | (opc & 0xff)); }


void spapr_iommu_init(void) { QLIST_INIT(&spapr_tce_tables); /* hcall-tce */ spapr_register_hypercall(H_PUT_TCE, h_put_tce); }


static void migration_state_notifier(Notifier *notifier, void *data) { MigrationState *s = data; if (migration_is_active(s)) { #ifdef SPICE_INTERFACE_MIGRATION spice_server_migrate_start(spice_server); #endif } else if (migration_has_finished(s)) { #if SPICE_SERVER_VERSION >= 0x000701 /* 0.7.1 */ #ifndef SPICE_INTERFACE_MIGRATION spice_server_migrate_switch(spice_server); #else spice_server_migrate_end(spice_server, true); } else if (migration_has_failed(s)) { spice_server_migrate_end(spice_server, false); #endif #endif } }


static inline void downmix_3f_1r_to_stereo(float *samples) { int i; for (i = 0; i < 256; i++) { samples[i] += (samples[i + 256] + samples[i + 768]); samples[i + 256] += (samples[i + 512] + samples[i + 768]); samples[i + 512] = samples[i + 768] = 0; } }


static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; int ret; unsigned int frame_type, packet_size, padding, frame_size; avio_rb16(pb); /* channel number */ frame_type = avio_rb16(pb); packet_size = avio_rb32(pb); padding = -packet_size & 511; frame_size = packet_size - 8; if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) { av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n"); return AVERROR(EIO); } if (packet_size > LMLM4_MAX_PACKET_SIZE) { av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n"); return AVERROR(EIO); } if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0) return AVERROR(EIO); avio_skip(pb, padding); switch (frame_type) { case LMLM4_I_FRAME: pkt->flags = AV_PKT_FLAG_KEY; case LMLM4_P_FRAME: case LMLM4_B_FRAME: pkt->stream_index = 0; break; case LMLM4_MPEG1L2: pkt->stream_index = 1; break; } return ret; }


static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt) { BinkContext * const c = avctx->priv_data; GetBitContext gb; int plane, plane_idx, ret; int bits_count = pkt->size << 3; if (c->version > 'b') { if(c->pic->data[0]) avctx->release_buffer(avctx, c->pic); if ((ret = ff_get_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } } else { if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } } init_get_bits(&gb, pkt->data, bits_count); if (c->has_alpha) { if (c->version >= 'i') skip_bits_long(&gb, 32); if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0) return ret; } if (c->version >= 'i') skip_bits_long(&gb, 32); for (plane = 0; plane < 3; plane++) { plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); if (c->version > 'b') { if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0) return ret; } else { if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0) return ret; } if (get_bits_count(&gb) >= bits_count) break; } emms_c(); *got_frame = 1; *(AVFrame*)data = *c->pic; if (c->version > 'b') FFSWAP(AVFrame*, c->pic, c->last); /* always report that the buffer was completely consumed */ return pkt->size; }


static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]) { int i, j, p; for (p = 0; p < 4; p++) { int srcstr = srcStride[p] >> 1; int dststr = dstStride[p] >> 1; uint16_t *dstPtr = (uint16_t *) dst[p]; const uint16_t *srcPtr = (const uint16_t *) src[p]; int min_stride = FFMIN(srcstr, dststr); if(!dstPtr || !srcPtr) continue; for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) { for (j = 0; j < min_stride; j++) { dstPtr[j] = av_bswap16(srcPtr[j]); } srcPtr += srcstr; dstPtr += dststr; } } return srcSliceH; }


static void video_refresh(void *opaque) { VideoState *is = opaque; VideoPicture *vp; double time; SubPicture *sp, *sp2; if (!is->paused && get_master_sync_type(is) == AV_SYNC_EXTERNAL_CLOCK && is->realtime) check_external_clock_speed(is); if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) video_display(is); if (is->video_st) { if (is->force_refresh) pictq_prev_picture(is); retry: if (is->pictq_size == 0) { SDL_LockMutex(is->pictq_mutex); if (is->frame_last_dropped_pts != AV_NOPTS_VALUE && is->frame_last_dropped_pts > is->frame_last_pts) { update_video_pts(is, is->frame_last_dropped_pts, is->frame_last_dropped_pos, 0); is->frame_last_dropped_pts = AV_NOPTS_VALUE; } SDL_UnlockMutex(is->pictq_mutex); // nothing to do, no picture to display in the queue } else { double last_duration, duration, delay; /* dequeue the picture */ vp = &is->pictq[is->pictq_rindex]; if (vp->serial != is->videoq.serial) { pictq_next_picture(is); goto retry; } if (is->paused) goto display; /* compute nominal last_duration */ last_duration = vp->pts - is->frame_last_pts; if (last_duration > 0 && last_duration < is->max_frame_duration) { /* if duration of the last frame was sane, update last_duration in video state */ is->frame_last_duration = last_duration; } delay = compute_target_delay(is->frame_last_duration, is); time= av_gettime()/1000000.0; if (time < is->frame_timer + delay) return; if (delay > 0) is->frame_timer += delay * FFMAX(1, floor((time-is->frame_timer) / delay)); SDL_LockMutex(is->pictq_mutex); update_video_pts(is, vp->pts, vp->pos, vp->serial); SDL_UnlockMutex(is->pictq_mutex); if (is->pictq_size > 1) { VideoPicture *nextvp = &is->pictq[(is->pictq_rindex + 1) % VIDEO_PICTURE_QUEUE_SIZE]; duration = nextvp->pts - vp->pts; if(!is->step && (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){ is->frame_drops_late++; pictq_next_picture(is); goto retry; } } if (is->subtitle_st) { if (is->subtitle_stream_changed) { SDL_LockMutex(is->subpq_mutex); while (is->subpq_size) { free_subpicture(&is->subpq[is->subpq_rindex]); /* update queue size and signal for next picture */ if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE) is->subpq_rindex = 0; is->subpq_size--; } is->subtitle_stream_changed = 0; SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex); } else { if (is->subpq_size > 0) { sp = &is->subpq[is->subpq_rindex]; if (is->subpq_size > 1) sp2 = &is->subpq[(is->subpq_rindex + 1) % SUBPICTURE_QUEUE_SIZE]; else sp2 = NULL; if ((is->video_current_pts > (sp->pts + ((float) sp->sub.end_display_time / 1000))) || (sp2 && is->video_current_pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000)))) { free_subpicture(sp); /* update queue size and signal for next picture */ if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE) is->subpq_rindex = 0; SDL_LockMutex(is->subpq_mutex); is->subpq_size--; SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex); } } } } display: /* display picture */ if (!display_disable && is->show_mode == SHOW_MODE_VIDEO) video_display(is); pictq_next_picture(is); if (is->step && !is->paused) stream_toggle_pause(is); } } is->force_refresh = 0; if (show_status) { static int64_t last_time; int64_t cur_time; int aqsize, vqsize, sqsize; double av_diff; cur_time = av_gettime(); if (!last_time || (cur_time - last_time) >= 30000) { aqsize = 0; vqsize = 0; sqsize = 0; if (is->audio_st) aqsize = is->audioq.size; if (is->video_st) vqsize = is->videoq.size; if (is->subtitle_st) sqsize = is->subtitleq.size; av_diff = 0; if (is->audio_st && is->video_st) av_diff = get_audio_clock(is) - get_video_clock(is); printf("%7.2f A-V:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64" \r", get_master_clock(is), av_diff, is->frame_drops_early + is->frame_drops_late, aqsize / 1024, vqsize / 1024, sqsize, is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0, is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0); fflush(stdout); last_time = cur_time; } } }


static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt); FrameBuffer *buf; int i, ret; int pixel_size; int h_chroma_shift, v_chroma_shift; int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1 int w = s->width, h = s->height; if (!desc) return AVERROR(EINVAL); pixel_size = desc->comp[0].step_minus1 + 1; buf = av_mallocz(sizeof(*buf)); if (!buf) return AVERROR(ENOMEM); if (!(s->flags & CODEC_FLAG_EMU_EDGE)) { w += 2*edge; h += 2*edge; } avcodec_align_dimensions(s, &w, &h); if ((ret = av_image_alloc(buf->base, buf->linesize, w, h, s->pix_fmt, 32)) < 0) { av_freep(&buf); return ret; } /* XXX this shouldn't be needed, but some tests break without this line * those decoders are buggy and need to be fixed. * the following tests fail: */ memset(buf->base[0], 128, ret); av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { const int h_shift = i==0 ? 0 : h_chroma_shift; const int v_shift = i==0 ? 0 : v_chroma_shift; if (s->flags & CODEC_FLAG_EMU_EDGE) buf->data[i] = buf->base[i]; else if (buf->base[i]) buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*edge >> v_shift) + (pixel_size*edge >> h_shift), 32); } buf->w = s->width; buf->h = s->height; buf->pix_fmt = s->pix_fmt; buf->pool = pool; *pbuf = buf; return 0; }


URLProtocol *ffurl_protocol_next(const URLProtocol *prev) { return prev ? prev->next : first_protocol; }


static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag = track->enc->codec_tag; if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL && (tag == MKTAG('d','v','c','p') || track->enc->codec_id == CODEC_ID_RAWVIDEO || track->enc->codec_id == CODEC_ID_H263 || av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio if (track->enc->codec_id == CODEC_ID_DVVIDEO) tag = mov_get_dv_codec_tag(s, track); else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) tag = mov_get_rawvideo_codec_tag(s, track); else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { tag = ff_codec_get_tag(codec_movvideo_tags, track->enc->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id); if (tag) av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, " "the file may be unplayable!\n"); } } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { tag = ff_codec_get_tag(codec_movaudio_tags, track->enc->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id); if (ms_tag) { tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, " "the file may be unplayable!\n"); } } } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id); } return tag; }


static av_cold int nvenc_recalc_surfaces(AVCodecContext *avctx) { NvencContext *ctx = avctx->priv_data; int nb_surfaces = 0; if (ctx->rc_lookahead > 0) { nb_surfaces = ctx->rc_lookahead + ((ctx->encode_config.frameIntervalP > 0) ? ctx->encode_config.frameIntervalP : 0) + 1 + 4; if (ctx->nb_surfaces < nb_surfaces) { av_log(avctx, AV_LOG_WARNING, "Defined rc_lookahead requires more surfaces, " "increasing used surfaces %d -> %d\n", ctx->nb_surfaces, nb_surfaces); ctx->nb_surfaces = nb_surfaces; } } ctx->nb_surfaces = FFMAX(1, FFMIN(MAX_REGISTERED_FRAMES, ctx->nb_surfaces)); ctx->async_depth = FFMIN(ctx->async_depth, ctx->nb_surfaces - 1); return 0; }


yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2], const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes) { const int32_t *buf0 = buf[0], *buf1 = buf[1], *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], *vbuf0 = vbuf[0], *vbuf1 = vbuf[1], *abuf0 = hasAlpha ? abuf[0] : NULL, *abuf1 = hasAlpha ? abuf[1] : NULL; int yalpha1 = 4096 - yalpha; int uvalpha1 = 4096 - uvalpha; int i; int A = 0xffff<<14; for (i = 0; i < dstW; i++) { int Y = (buf0[i] * yalpha1 + buf1[i] * yalpha) >> 14; int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14; int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14; int R, G, B; Y -= c->yuv2rgb_y_offset; Y *= c->yuv2rgb_y_coeff; Y += 1 << 13; R = V * c->yuv2rgb_v2r_coeff; G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; if (hasAlpha) { A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha) >> 1; A += 1 << 13; } output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14); output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14); output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; } else { dest += 3; } } }


static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { if(st->codec->codec_id == CODEC_ID_PROBE){ AVProbeData *pd = &st->probe_data; av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); --st->probe_packets; pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size); pd->buf_size += pkt->size; memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ //FIXME we do not reduce score to 0 for the case of running out of buffer space in bytes set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0); if(st->codec->codec_id != CODEC_ID_PROBE){ pd->buf_size=0; av_freep(&pd->buf); av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } } } }


static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number) { int vo_ver_id; if(s->max_b_frames || s->quarter_sample){ vo_ver_id= 5; s->vo_type= ADV_SIMPLE_VO_TYPE; }else{ vo_ver_id= 1; s->vo_type= SIMPLE_VO_TYPE; } put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */ put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */ put_bits(&s->pb, 1, 0); /* random access vol */ put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */ put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ put_bits(&s->pb, 3, 1); /* is obj layer priority */ aspect_to_info(s, s->avctx->sample_aspect_ratio); put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); } if(s->low_delay){ put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 1, 0); /* vbv parameters= no */ }else{ put_bits(&s->pb, 1, 0); /* vol control parameters= no */ } put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ put_bits(&s->pb, 1, 1); /* marker bit */ put_bits(&s->pb, 16, s->time_increment_resolution); if (s->time_increment_bits < 1) s->time_increment_bits = 1; put_bits(&s->pb, 1, 1); /* marker bit */ put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ put_bits(&s->pb, 1, 1); /* marker bit */ put_bits(&s->pb, 13, s->width); /* vol width */ put_bits(&s->pb, 1, 1); /* marker bit */ put_bits(&s->pb, 13, s->height); /* vol height */ put_bits(&s->pb, 1, 1); /* marker bit */ put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1); put_bits(&s->pb, 1, 1); /* obmc disable */ if (vo_ver_id == 1) { put_bits(&s->pb, 1, s->vol_sprite_usage=0); /* sprite enable */ }else{ put_bits(&s->pb, 2, s->vol_sprite_usage=0); /* sprite enable */ } s->quant_precision=5; put_bits(&s->pb, 1, 0); /* not 8 bit == false */ put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/ if(s->mpeg_quant){ ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); } if (vo_ver_id != 1) put_bits(&s->pb, 1, s->quarter_sample); put_bits(&s->pb, 1, 1); /* complexity estimation disable */ s->resync_marker= s->rtp_mode; put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */ put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0); if(s->data_partitioning){ put_bits(&s->pb, 1, 0); /* no rvlc */ } if (vo_ver_id != 1){ put_bits(&s->pb, 1, 0); /* newpred */ put_bits(&s->pb, 1, 0); /* reduced res vop */ } put_bits(&s->pb, 1, 0); /* scalability */ ff_mpeg4_stuffing(&s->pb); /* user data */ if(!(s->flags & CODEC_FLAG_BITEXACT)){ put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, 0x1B2); /* user_data */ put_string(&s->pb, LIBAVCODEC_IDENT); ff_mpeg4_stuffing(&s->pb); } }


static void ide_atapi_cmd_read_pio(IDEState *s, int lba, int nb_sectors, int sector_size) { s->lba = lba; s->packet_transfer_size = nb_sectors * sector_size; s->elementary_transfer_size = 0; s->io_buffer_index = sector_size; s->cd_sector_size = sector_size; s->status = READY_STAT | SEEK_STAT; ide_atapi_cmd_reply_end(s); }


static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign) { dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE)); dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) << 1)); return dst + 2; }


static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 ) { int8_t tc[4]; tc[0] = tc0_table[index_a][bS[0]]+1; tc[1] = tc0_table[index_a][bS[1]]+1; tc[2] = tc0_table[index_a][bS[2]]+1; tc[3] = tc0_table[index_a][bS[3]]+1; h->h264dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta); } }


static void usbredir_configuration_status(void *priv, uint32_t id, struct usb_redir_configuration_status_header *config_status) { USBRedirDevice *dev = priv; AsyncURB *aurb; int len = 0; DPRINTF("set config status %d config %d id %u\n", config_status->status, config_status->configuration, id); aurb = async_find(dev, id); if (!aurb) { return; } if (aurb->packet) { if (aurb->get) { dev->dev.data_buf[0] = config_status->configuration; len = 1; } aurb->packet->len = usbredir_handle_status(dev, config_status->status, len); usb_generic_async_ctrl_complete(&dev->dev, aurb->packet); } async_free(dev, aurb); }


static void gen_smul_dual(TCGv a, TCGv b) { TCGv tmp1 = new_tmp(); TCGv tmp2 = new_tmp(); tcg_gen_ext16s_i32(tmp1, a); tcg_gen_ext16s_i32(tmp2, b); tcg_gen_mul_i32(tmp1, tmp1, tmp2); dead_tmp(tmp2); tcg_gen_sari_i32(a, a, 16); tcg_gen_sari_i32(b, b, 16); tcg_gen_mul_i32(b, b, a); tcg_gen_mov_i32(a, tmp1); dead_tmp(tmp1); }


static int ac3_parse_bsi(AC3DecodeContext *ctx) { ac3_bsi *bsi = &ctx->bsi; uint32_t *flags = &bsi->flags; GetBitContext *gb = &ctx->gb; *flags = 0; bsi->cmixlev = 0; bsi->surmixlev = 0; bsi->dsurmod = 0; bsi->bsid = get_bits(gb, 5); if (bsi->bsid > 0x08) return -1; bsi->bsmod = get_bits(gb, 3); bsi->acmod = get_bits(gb, 3); if (bsi->acmod & 0x01 && bsi->acmod != 0x01) bsi->cmixlev = get_bits(gb, 2); if (bsi->acmod & 0x04) bsi->surmixlev = get_bits(gb, 2); if (bsi->acmod == 0x02) bsi->dsurmod = get_bits(gb, 2); if (get_bits(gb, 1)) *flags |= AC3_BSI_LFEON; bsi->dialnorm = get_bits(gb, 5); if (get_bits(gb, 1)) { *flags |= AC3_BSI_COMPRE; bsi->compr = get_bits(gb, 5); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_LANGCODE; bsi->langcod = get_bits(gb, 8); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_AUDPRODIE; bsi->mixlevel = get_bits(gb, 5); bsi->roomtyp = get_bits(gb, 2); } if (bsi->acmod == 0x00) { bsi->dialnorm2 = get_bits(gb, 5); if (get_bits(gb, 1)) { *flags |= AC3_BSI_COMPR2E; bsi->compr2 = get_bits(gb, 5); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_LANGCOD2E; bsi->langcod2 = get_bits(gb, 8); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_AUDPRODIE; bsi->mixlevel2 = get_bits(gb, 5); bsi->roomtyp2 = get_bits(gb, 2); } } if (get_bits(gb, 1)) *flags |= AC3_BSI_COPYRIGHTB; if (get_bits(gb, 1)) *flags |= AC3_BSI_ORIGBS; if (get_bits(gb, 1)) { *flags |= AC3_BSI_TIMECOD1E; bsi->timecod1 = get_bits(gb, 14); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_TIMECOD2E; bsi->timecod2 = get_bits(gb, 14); } if (get_bits(gb, 1)) { *flags |= AC3_BSI_ADDBSIE; bsi->addbsil = get_bits(gb, 6); do { get_bits(gb, 8); } while (bsi->addbsil--); } bsi->nfchans = nfchans_tbl[bsi->acmod]; return 0; }


int av_grab(AVFormatContext *s) { UINT8 audio_buf[AUDIO_FIFO_SIZE]; UINT8 audio_buf1[AUDIO_FIFO_SIZE]; UINT8 audio_out[AUDIO_FIFO_SIZE]; UINT8 video_buffer[1024*1024]; char buf[256]; short *samples; URLContext *audio_handle = NULL, *video_handle = NULL; int ret; AVCodecContext *enc, *first_video_enc = NULL; int frame_size, frame_bytes; int use_audio, use_video; int frame_rate, sample_rate, channels; int width, height, frame_number, i, pix_fmt = 0; AVOutputStream *ost_table[s->nb_streams], *ost; UINT8 *picture_in_buf = NULL, *picture_420p = NULL; int audio_fifo_size = 0, picture_size = 0; INT64 time_start; /* init output stream info */ for(i=0;i<s->nb_streams;i++) ost_table[i] = NULL; /* output stream init */ for(i=0;i<s->nb_streams;i++) { ost = av_mallocz(sizeof(AVOutputStream)); if (!ost) goto fail; ost->index = i; ost->st = s->streams[i]; ost_table[i] = ost; } use_audio = 0; use_video = 0; frame_rate = 0; sample_rate = 0; frame_size = 0; channels = 1; width = 0; height = 0; frame_number = 0; for(i=0;i<s->nb_streams;i++) { AVCodec *codec; ost = ost_table[i]; enc = &ost->st->codec; codec = avcodec_find_encoder(enc->codec_id); if (!codec) { fprintf(stderr, "Unknown codec\n"); return -1; } if (avcodec_open(enc, codec) < 0) { fprintf(stderr, "Incorrect encode parameters\n"); return -1; } switch(enc->codec_type) { case CODEC_TYPE_AUDIO: use_audio = 1; if (enc->sample_rate > sample_rate) sample_rate = enc->sample_rate; if (enc->frame_size > frame_size) frame_size = enc->frame_size; if (enc->channels > channels) channels = enc->channels; break; case CODEC_TYPE_VIDEO: if (!first_video_enc) first_video_enc = enc; use_video = 1; if (enc->frame_rate > frame_rate) frame_rate = enc->frame_rate; if (enc->width > width) width = enc->width; if (enc->height > height) height = enc->height; break; } } /* audio */ samples = NULL; if (use_audio) { snprintf(buf, sizeof(buf), "audio:%d,%d", sample_rate, channels); ret = url_open(&audio_handle, buf, URL_RDONLY); if (ret < 0) { fprintf(stderr, "Could not open audio device: disabling audio capture\n"); use_audio = 0; } else { URLFormat f; /* read back exact grab parameters */ if (url_getformat(audio_handle, &f) < 0) { fprintf(stderr, "could not read back video grab parameters\n"); goto fail; } sample_rate = f.sample_rate; channels = f.channels; audio_fifo_size = ((AUDIO_FIFO_SIZE / 2) / audio_handle->packet_size) * audio_handle->packet_size; fprintf(stderr, "Audio sampling: %d Hz, %s\n", sample_rate, channels == 2 ? "stereo" : "mono"); } } /* video */ if (use_video) { snprintf(buf, sizeof(buf), "video:%d,%d,%f", width, height, (float)frame_rate / FRAME_RATE_BASE); ret = url_open(&video_handle, buf, URL_RDONLY); if (ret < 0) { fprintf(stderr,"Could not init video 4 linux capture: disabling video capture\n"); use_video = 0; } else { URLFormat f; const char *pix_fmt_str; /* read back exact grab parameters */ if (url_getformat(video_handle, &f) < 0) { fprintf(stderr, "could not read back video grab parameters\n"); goto fail; } width = f.width; height = f.height; pix_fmt = f.pix_fmt; switch(pix_fmt) { case PIX_FMT_YUV420P: pix_fmt_str = "420P"; break; case PIX_FMT_YUV422: pix_fmt_str = "422"; break; case PIX_FMT_RGB24: pix_fmt_str = "RGB24"; break; case PIX_FMT_BGR24: pix_fmt_str = "BGR24"; break; default: pix_fmt_str = "???"; break; } picture_size = video_handle->packet_size; picture_in_buf = malloc(picture_size); if (!picture_in_buf) goto fail; /* allocate a temporary picture if not grabbing in 420P format */ if (pix_fmt != PIX_FMT_YUV420P) { picture_420p = malloc((width * height * 3) / 2); } fprintf(stderr, "Video sampling: %dx%d, %s format, %0.2f fps\n", width, height, pix_fmt_str, (float)frame_rate / FRAME_RATE_BASE); } } if (!use_video && !use_audio) { fprintf(stderr,"Could not open grab devices : exiting\n"); exit(1); } /* init built in conversion functions */ for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; enc = &ost->st->codec; switch(enc->codec_type) { case CODEC_TYPE_AUDIO: ost->audio_resample = 0; if ((enc->channels != channels || enc->sample_rate != sample_rate)) { ost->audio_resample = 1; ost->resample = audio_resample_init(enc->channels, channels, enc->sample_rate, sample_rate); } if (fifo_init(&ost->fifo, (2 * audio_fifo_size * enc->sample_rate * enc->channels) / sample_rate)) goto fail; break; case CODEC_TYPE_VIDEO: ost->video_resample = 0; if (enc->width != width || enc->height != height) { UINT8 *buf; ost->video_resample = 1; buf = malloc((enc->width * enc->height * 3) / 2); if (!buf) goto fail; ost->pict_tmp.data[0] = buf; ost->pict_tmp.data[1] = buf + enc->width * height; ost->pict_tmp.data[2] = ost->pict_tmp.data[1] + (enc->width * height) / 4; ost->pict_tmp.linesize[0] = enc->width; ost->pict_tmp.linesize[1] = enc->width / 2; ost->pict_tmp.linesize[2] = enc->width / 2; ost->img_resample_ctx = img_resample_init( ost->st->codec.width, ost->st->codec.height, width, height); } } } fprintf(stderr, "Press [q] to stop encoding\n"); s->format->write_header(s); time_start = gettime(); term_init(); for(;;) { /* if 'q' pressed, exits */ if (read_key() == 'q') break; /* read & compress audio frames */ if (use_audio) { int ret, nb_samples, nb_samples_out; UINT8 *buftmp; for(;;) { ret = url_read(audio_handle, audio_buf, audio_fifo_size); if (ret <= 0) break; /* fill each codec fifo by doing the right sample rate conversion. This is not optimal because we do too much work, but it is easy to do */ nb_samples = ret / (channels * 2); for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; enc = &ost->st->codec; if (enc->codec_type == CODEC_TYPE_AUDIO) { /* rate & stereo convertion */ if (!ost->audio_resample) { buftmp = audio_buf; nb_samples_out = nb_samples; } else { buftmp = audio_buf1; nb_samples_out = audio_resample(ost->resample, (short *)buftmp, (short *)audio_buf, nb_samples); } fifo_write(&ost->fifo, buftmp, nb_samples_out * enc->channels * 2, &ost->fifo.wptr); } } /* compress as many frame as possible with each audio codec */ for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; enc = &ost->st->codec; if (enc->codec_type == CODEC_TYPE_AUDIO) { frame_bytes = enc->frame_size * 2 * enc->channels; while (fifo_read(&ost->fifo, audio_buf, frame_bytes, &ost->fifo.rptr) == 0) { ret = avcodec_encode_audio(enc, audio_out, sizeof(audio_out), (short *)audio_buf); s->format->write_packet(s, ost->index, audio_out, ret); } } } } } if (use_video) { AVPicture *picture1, *picture2, *picture; AVPicture picture_tmp0, picture_tmp1; ret = url_read(video_handle, picture_in_buf, picture_size); if (ret < 0) break; picture2 = &picture_tmp0; avpicture_fill(picture2, picture_in_buf, pix_fmt, width, height); if (pix_fmt != PIX_FMT_YUV420P) { picture = &picture_tmp1; avpicture_fill(picture, picture_420p, PIX_FMT_YUV420P, width, height); img_convert(picture, PIX_FMT_YUV420P, picture2, pix_fmt, width, height); } else { picture = picture2; } for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; enc = &ost->st->codec; if (enc->codec_type == CODEC_TYPE_VIDEO) { int n1, n2, nb; /* feed each codec with its requested frame rate */ n1 = ((INT64)frame_number * enc->frame_rate) / frame_rate; n2 = (((INT64)frame_number + 1) * enc->frame_rate) / frame_rate; nb = n2 - n1; if (nb > 0) { /* resize the picture if needed */ if (ost->video_resample) { picture1 = &ost->pict_tmp; img_resample(ost->img_resample_ctx, picture1, picture); } else { picture1 = picture; } ret = avcodec_encode_video(enc, video_buffer, sizeof(video_buffer), picture1); s->format->write_packet(s, ost->index, video_buffer, ret); } } } frame_number++; } /* write report */ { char buf[1024]; INT64 total_size; float ti, bitrate; static float last_ti; INT64 ti1; total_size = url_ftell(&s->pb); ti1 = gettime() - time_start; /* check elapsed time */ if (recording_time && ti1 >= recording_time) break; ti = ti1 / 1000000.0; if (ti < 0.1) ti = 0.1; /* dispaly twice per second */ if ((ti - last_ti) >= 0.5) { last_ti = ti; bitrate = (int)((total_size * 8) / ti / 1000.0); buf[0] = '\0'; if (use_video) { sprintf(buf + strlen(buf), "frame=%5d fps=%4.1f q=%2d ", frame_number, (float)frame_number / ti, first_video_enc->quality); } sprintf(buf + strlen(buf), "size=%8LdkB time=%0.1f bitrate=%6.1fkbits/s", total_size / 1024, ti, bitrate); fprintf(stderr, "%s \r", buf); fflush(stderr); } } } term_exit(); for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; enc = &ost->st->codec; avcodec_close(enc); } s->format->write_trailer(s); if (audio_handle) url_close(audio_handle); if (video_handle) url_close(video_handle); /* write report */ { float ti, bitrate; INT64 total_size; total_size = url_ftell(&s->pb); ti = (gettime() - time_start) / 1000000.0; if (ti < 0.1) ti = 0.1; bitrate = (int)((total_size * 8) / ti / 1000.0); fprintf(stderr, "\033[K\nTotal time = %0.1f s, %Ld KBytes, %0.1f kbits/s\n", ti, total_size / 1024, bitrate); if (use_video) { fprintf(stderr, "Total frames = %d\n", frame_number); } } ret = 0; fail1: if (picture_in_buf) free(picture_in_buf); if (picture_420p) free(picture_420p); for(i=0;i<s->nb_streams;i++) { ost = ost_table[i]; if (ost) { if (ost->fifo.buffer) fifo_free(&ost->fifo); if (ost->pict_tmp.data[0]) 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); free(ost); } } return ret; fail: ret = -ENOMEM; goto fail1; }


static int64_t nfs_client_open(NFSClient *client, QDict *options, int flags, Error **errp, int open_flags) { int ret = -EINVAL; QemuOpts *opts = NULL; Error *local_err = NULL; struct stat st; char *file = NULL, *strp = NULL; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } client->path = g_strdup(qemu_opt_get(opts, "path")); if (!client->path) { ret = -EINVAL; error_setg(errp, "No path was specified"); goto fail; } strp = strrchr(client->path, '/'); if (strp == NULL) { error_setg(errp, "Invalid URL specified"); goto fail; } file = g_strdup(strp); *strp = 0; /* Pop the config into our state object, Exit if invalid */ client->server = nfs_config(options, errp); if (!client->server) { ret = -EINVAL; goto fail; } client->context = nfs_init_context(); if (client->context == NULL) { error_setg(errp, "Failed to init NFS context"); goto fail; } if (qemu_opt_get(opts, "uid")) { client->uid = qemu_opt_get_number(opts, "uid", 0); nfs_set_uid(client->context, client->uid); } if (qemu_opt_get(opts, "gid")) { client->gid = qemu_opt_get_number(opts, "gid", 0); nfs_set_gid(client->context, client->gid); } if (qemu_opt_get(opts, "tcp-syncnt")) { client->tcp_syncnt = qemu_opt_get_number(opts, "tcp-syncnt", 0); nfs_set_tcp_syncnt(client->context, client->tcp_syncnt); } #ifdef LIBNFS_FEATURE_READAHEAD if (qemu_opt_get(opts, "readahead")) { if (open_flags & BDRV_O_NOCACHE) { error_setg(errp, "Cannot enable NFS readahead " "if cache.direct = on"); goto fail; } client->readahead = qemu_opt_get_number(opts, "readahead", 0); if (client->readahead > QEMU_NFS_MAX_READAHEAD_SIZE) { error_report("NFS Warning: Truncating NFS readahead " "size to %d", QEMU_NFS_MAX_READAHEAD_SIZE); client->readahead = QEMU_NFS_MAX_READAHEAD_SIZE; } nfs_set_readahead(client->context, client->readahead); #ifdef LIBNFS_FEATURE_PAGECACHE nfs_set_pagecache_ttl(client->context, 0); #endif client->cache_used = true; } #endif #ifdef LIBNFS_FEATURE_PAGECACHE if (qemu_opt_get(opts, "pagecache")) { if (open_flags & BDRV_O_NOCACHE) { error_setg(errp, "Cannot enable NFS pagecache " "if cache.direct = on"); goto fail; } client->pagecache = qemu_opt_get_number(opts, "pagecache", 0); if (client->pagecache > QEMU_NFS_MAX_PAGECACHE_SIZE) { error_report("NFS Warning: Truncating NFS pagecache " "size to %d pages", QEMU_NFS_MAX_PAGECACHE_SIZE); client->pagecache = QEMU_NFS_MAX_PAGECACHE_SIZE; } nfs_set_pagecache(client->context, client->pagecache); nfs_set_pagecache_ttl(client->context, 0); client->cache_used = true; } #endif #ifdef LIBNFS_FEATURE_DEBUG if (qemu_opt_get(opts, "debug")) { client->debug = qemu_opt_get_number(opts, "debug", 0); /* limit the maximum debug level to avoid potential flooding * of our log files. */ if (client->debug > QEMU_NFS_MAX_DEBUG_LEVEL) { error_report("NFS Warning: Limiting NFS debug level " "to %d", QEMU_NFS_MAX_DEBUG_LEVEL); client->debug = QEMU_NFS_MAX_DEBUG_LEVEL; } nfs_set_debug(client->context, client->debug); } #endif ret = nfs_mount(client->context, client->server->host, client->path); if (ret < 0) { error_setg(errp, "Failed to mount nfs share: %s", nfs_get_error(client->context)); goto fail; } if (flags & O_CREAT) { ret = nfs_creat(client->context, file, 0600, &client->fh); if (ret < 0) { error_setg(errp, "Failed to create file: %s", nfs_get_error(client->context)); goto fail; } } else { ret = nfs_open(client->context, file, flags, &client->fh); if (ret < 0) { error_setg(errp, "Failed to open file : %s", nfs_get_error(client->context)); goto fail; } } ret = nfs_fstat(client->context, client->fh, &st); if (ret < 0) { error_setg(errp, "Failed to fstat file: %s", nfs_get_error(client->context)); goto fail; } ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE); client->st_blocks = st.st_blocks; client->has_zero_init = S_ISREG(st.st_mode); *strp = '/'; goto out; fail: nfs_client_close(client); out: qemu_opts_del(opts); g_free(file); return ret; }


void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band, IVITile *tile, int32_t mv_scale) { int x, y, need_mc, mbn, blk, num_blocks, mv_x, mv_y, mc_type; int offs, mb_offset, row_offset; IVIMbInfo *mb, *ref_mb; const int16_t *src; int16_t *dst; void (*mc_no_delta_func)(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); offs = tile->ypos * band->pitch + tile->xpos; mb = tile->mbs; ref_mb = tile->ref_mbs; row_offset = band->mb_size * band->pitch; need_mc = 0; /* reset the mc tracking flag */ for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) { mb_offset = offs; for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) { mb->xpos = x; mb->ypos = y; mb->buf_offs = mb_offset; mb->type = 1; /* set the macroblocks type = INTER */ mb->cbp = 0; /* all blocks are empty */ if (!band->qdelta_present && !band->plane && !band->band_num) { mb->q_delta = band->glob_quant; mb->mv_x = 0; mb->mv_y = 0; } if (band->inherit_qdelta && ref_mb) mb->q_delta = ref_mb->q_delta; if (band->inherit_mv) { /* motion vector inheritance */ if (mv_scale) { mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); } else { mb->mv_x = ref_mb->mv_x; mb->mv_y = ref_mb->mv_y; } need_mc |= mb->mv_x || mb->mv_y; /* tracking non-zero motion vectors */ } mb++; if (ref_mb) ref_mb++; mb_offset += band->mb_size; } // for x offs += row_offset; } // for y if (band->inherit_mv && need_mc) { /* apply motion compensation if there is at least one non-zero motion vector */ num_blocks = (band->mb_size != band->blk_size) ? 4 : 1; /* number of blocks per mb */ mc_no_delta_func = (band->blk_size == 8) ? ff_ivi_mc_8x8_no_delta : ff_ivi_mc_4x4_no_delta; for (mbn = 0, mb = tile->mbs; mbn < tile->num_MBs; mb++, mbn++) { mv_x = mb->mv_x; mv_y = mb->mv_y; if (!band->is_halfpel) { mc_type = 0; /* we have only fullpel vectors */ } else { mc_type = ((mv_y & 1) << 1) | (mv_x & 1); mv_x >>= 1; mv_y >>= 1; /* convert halfpel vectors into fullpel ones */ } for (blk = 0; blk < num_blocks; blk++) { /* adjust block position in the buffer according with its number */ offs = mb->buf_offs + band->blk_size * ((blk & 1) + !!(blk & 2) * band->pitch); mc_no_delta_func(band->buf + offs, band->ref_buf + offs + mv_y * band->pitch + mv_x, band->pitch, mc_type); } } } else { /* copy data from the reference tile into the current one */ src = band->ref_buf + tile->ypos * band->pitch + tile->xpos; dst = band->buf + tile->ypos * band->pitch + tile->xpos; for (y = 0; y < tile->height; y++) { memcpy(dst, src, tile->width*sizeof(band->buf[0])); src += band->pitch; dst += band->pitch; } } }


static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ int y_size = s->b8_stride * (2 * s->mb_height + 1); int c_size = s->mb_stride * (s->mb_height + 1); int yc_size = y_size + 2 * c_size; int i; // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer() FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail) s->me.temp= s->me.scratchpad; s->rd_scratchpad= s->me.scratchpad; s->b_scratchpad= s->me.scratchpad; s->obmc_scratchpad= s->me.scratchpad + 16; if (s->encoding) { FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail) if(s->avctx->noise_reduction){ FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail) } } FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail) s->block= s->blocks[0]; for(i=0;i<12;i++){ s->pblocks[i] = &s->block[i]; } if (s->out_format == FMT_H263) { /* ac values */ FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail); s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; s->ac_val[2] = s->ac_val[1] + c_size; } return 0; fail: return -1; //free() through MPV_common_end() }


static int msrle_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MsrleContext *s = avctx->priv_data; int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8; int ret; s->buf = buf; s->size = buf_size; if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) return ret; if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) { const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } /* make the palette available */ memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); } /* FIXME how to correctly detect RLE ??? */ if (avctx->height * istride == avpkt->size) { /* assume uncompressed */ int linesize = av_image_get_linesize(avctx->pix_fmt, avctx->width, 0); uint8_t *ptr = s->frame->data[0]; uint8_t *buf = avpkt->data + (avctx->height-1)*istride; int i, j; for (i = 0; i < avctx->height; i++) { if (avctx->bits_per_coded_sample == 4) { for (j = 0; j < avctx->width - 1; j += 2) { ptr[j+0] = buf[j>>1] >> 4; ptr[j+1] = buf[j>>1] & 0xF; } if (avctx->width & 1) ptr[j+0] = buf[j>>1] >> 4; } else { memcpy(ptr, buf, linesize); } buf -= istride; ptr += s->frame->linesize[0]; } } else { bytestream2_init(&s->gb, buf, buf_size); ff_msrle_decode(avctx, (AVPicture*)s->frame, avctx->bits_per_coded_sample, &s->gb); } if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; /* report that the buffer was completely consumed */ return buf_size; }


static int doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcFormat, int dstFormat, int srcW, int srcH, int dstW, int dstH, int flags){ uint8_t *src[3]; uint8_t *dst[3]; uint8_t *out[3]; int srcStride[3], dstStride[3]; int i; uint64_t ssdY, ssdU, ssdV; struct SwsContext *srcContext, *dstContext, *outContext; int res; res = 0; for (i=0; i<3; i++){ // avoid stride % bpp != 0 if (srcFormat==PIX_FMT_RGB24 || srcFormat==PIX_FMT_BGR24) srcStride[i]= srcW*3; else srcStride[i]= srcW*4; if (dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24) dstStride[i]= dstW*3; else dstStride[i]= dstW*4; src[i]= (uint8_t*) malloc(srcStride[i]*srcH); dst[i]= (uint8_t*) malloc(dstStride[i]*dstH); out[i]= (uint8_t*) malloc(refStride[i]*h); if (!src[i] || !dst[i] || !out[i]) { perror("Malloc"); res = -1; goto end; } } dstContext = outContext = NULL; srcContext= sws_getContext(w, h, PIX_FMT_YUV420P, srcW, srcH, srcFormat, flags, NULL, NULL, NULL); if (!srcContext) { fprintf(stderr, "Failed to get %s ---> %s\n", sws_format_name(PIX_FMT_YUV420P), sws_format_name(srcFormat)); res = -1; goto end; } dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL); if (!dstContext) { fprintf(stderr, "Failed to get %s ---> %s\n", sws_format_name(srcFormat), sws_format_name(dstFormat)); res = -1; goto end; } outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUV420P, flags, NULL, NULL, NULL); if (!outContext) { fprintf(stderr, "Failed to get %s ---> %s\n", sws_format_name(dstFormat), sws_format_name(PIX_FMT_YUV420P)); res = -1; goto end; } // printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2], // (int)src[0], (int)src[1], (int)src[2]); sws_scale(srcContext, ref, refStride, 0, h , src, srcStride); sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1); ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1); if (srcFormat == PIX_FMT_GRAY8 || dstFormat==PIX_FMT_GRAY8) ssdU=ssdV=0; //FIXME check that output is really gray ssdY/= w*h; ssdU/= w*h/4; ssdV/= w*h/4; printf(" %s %dx%d -> %s %4dx%4d flags=%2d SSD=%5lld,%5lld,%5lld\n", sws_format_name(srcFormat), srcW, srcH, sws_format_name(dstFormat), dstW, dstH, flags, ssdY, ssdU, ssdV); fflush(stdout); end: sws_freeContext(srcContext); sws_freeContext(dstContext); sws_freeContext(outContext); for (i=0; i<3; i++){ free(src[i]); free(dst[i]); free(out[i]); } return res; }


static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) { int ret; struct addrinfo *res; char port_str[16]; struct rdma_cm_event *cm_event; char ip[40] = "unknown"; struct addrinfo *e; if (rdma->host == NULL || !strcmp(rdma->host, "")) { ERROR(errp, "RDMA hostname has not been set"); return -1; } /* create CM channel */ rdma->channel = rdma_create_event_channel(); if (!rdma->channel) { ERROR(errp, "could not create CM channel"); return -1; } /* create CM id */ ret = rdma_create_id(rdma->channel, &rdma->cm_id, NULL, RDMA_PS_TCP); if (ret) { ERROR(errp, "could not create channel id"); goto err_resolve_create_id; } snprintf(port_str, 16, "%d", rdma->port); port_str[15] = '\0'; ret = getaddrinfo(rdma->host, port_str, NULL, &res); if (ret < 0) { ERROR(errp, "could not getaddrinfo address %s", rdma->host); goto err_resolve_get_addr; } for (e = res; e != NULL; e = e->ai_next) { inet_ntop(e->ai_family, &((struct sockaddr_in *) e->ai_addr)->sin_addr, ip, sizeof ip); DPRINTF("Trying %s => %s\n", rdma->host, ip); /* resolve the first address */ ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_addr, RDMA_RESOLVE_TIMEOUT_MS); if (!ret) { goto route; } } ERROR(errp, "could not resolve address %s", rdma->host); goto err_resolve_get_addr; route: qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id); ret = rdma_get_cm_event(rdma->channel, &cm_event); if (ret) { ERROR(errp, "could not perform event_addr_resolved"); goto err_resolve_get_addr; } if (cm_event->event != RDMA_CM_EVENT_ADDR_RESOLVED) { ERROR(errp, "result not equal to event_addr_resolved %s", rdma_event_str(cm_event->event)); perror("rdma_resolve_addr"); goto err_resolve_get_addr; } rdma_ack_cm_event(cm_event); /* resolve route */ ret = rdma_resolve_route(rdma->cm_id, RDMA_RESOLVE_TIMEOUT_MS); if (ret) { ERROR(errp, "could not resolve rdma route"); goto err_resolve_get_addr; } ret = rdma_get_cm_event(rdma->channel, &cm_event); if (ret) { ERROR(errp, "could not perform event_route_resolved"); goto err_resolve_get_addr; } if (cm_event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) { ERROR(errp, "result not equal to event_route_resolved: %s", rdma_event_str(cm_event->event)); rdma_ack_cm_event(cm_event); goto err_resolve_get_addr; } rdma_ack_cm_event(cm_event); rdma->verbs = rdma->cm_id->verbs; qemu_rdma_dump_id("source_resolve_host", rdma->cm_id->verbs); qemu_rdma_dump_gid("source_resolve_host", rdma->cm_id); return 0; err_resolve_get_addr: rdma_destroy_id(rdma->cm_id); rdma->cm_id = NULL; err_resolve_create_id: rdma_destroy_event_channel(rdma->channel); rdma->channel = NULL; return -1; }


static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, const char *model, const char *name, int fd, int is_connected, const char *mcast, Error **errp) { struct sockaddr_in saddr; int newfd; NetClientState *nc; NetSocketState *s; /* fd passed: multicast: "learn" dgram_dst address from bound address and save it * Because this may be "shared" socket from a "master" process, datagrams would be recv() * by ONLY ONE process: we must "clone" this dgram socket --jjo */ if (is_connected && mcast != NULL) { if (parse_host_port(&saddr, mcast, errp) < 0) { goto err; } /* must be bound */ if (saddr.sin_addr.s_addr == 0) { error_setg(errp, "can't setup multicast destination address"); goto err; } /* clone dgram socket */ newfd = net_socket_mcast_create(&saddr, NULL, errp); if (newfd < 0) { goto err; } /* clone newfd to fd, close newfd */ dup2(newfd, fd); close(newfd); } nc = qemu_new_net_client(&net_dgram_socket_info, peer, model, name); s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; s->listen_fd = -1; s->send_fn = net_socket_send_dgram; net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); net_socket_read_poll(s, true); /* mcast: save bound address as dst */ if (is_connected) { s->dgram_dst = saddr; snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (cloned mcast=%s:%d)", fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); } else { snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); } return s; err: closesocket(fd); return NULL; }


static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, int _stride){ pixel *src = (pixel*)_src; int stride = _stride/sizeof(pixel); ((pixel4*)(src+0*stride))[0]= PIXEL_SPLAT_X4(src[-1+0*stride]); ((pixel4*)(src+1*stride))[0]= PIXEL_SPLAT_X4(src[-1+1*stride]); ((pixel4*)(src+2*stride))[0]= PIXEL_SPLAT_X4(src[-1+2*stride]); ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(src[-1+3*stride]); }


static void ehci_trace_itd(EHCIState *s, target_phys_addr_t addr, EHCIitd *itd) { trace_usb_ehci_itd(addr, itd->next); }


AVCodecParserContext *av_parser_init(int codec_id) { AVCodecParserContext *s; AVCodecParser *parser; int ret; if(codec_id == CODEC_ID_NONE) return NULL; for(parser = av_first_parser; parser != NULL; parser = parser->next) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || parser->codec_ids[2] == codec_id || parser->codec_ids[3] == codec_id || parser->codec_ids[4] == codec_id) goto found; } return NULL; found: s = av_mallocz(sizeof(AVCodecParserContext)); if (!s) return NULL; s->parser = parser; if (parser->priv_data_size) { s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) { av_free(s); return NULL; } } if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) { av_free(s->priv_data); av_free(s); return NULL; } } s->fetch_timestamp=1; s->pict_type = FF_I_TYPE; s->key_frame = -1; s->convergence_duration = 0; s->dts_sync_point = INT_MIN; s->dts_ref_dts_delta = INT_MIN; s->pts_dts_delta = INT_MIN; return s; }


int migrate_use_xbzrle(void) { MigrationState *s; s = migrate_get_current(); return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE]; }


static void xen_hvm_change_state_handler(void *opaque, int running, RunState rstate) { if (running) { xen_main_loop_prepare((XenIOState *)opaque); } }


static int parse_vlan(DeviceState *dev, Property *prop, const char *str) { VLANState **ptr = qdev_get_prop_ptr(dev, prop); int id; if (sscanf(str, "%d", &id) != 1) return -EINVAL; *ptr = qemu_find_vlan(id, 1); if (*ptr == NULL) return -ENOENT; return 0; }


static int qtrle_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; QtrleContext *s = avctx->priv_data; int header, start_line; int stream_ptr, height, row_ptr; int has_palette = 0; s->buf = buf; s->size = buf_size; s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; if (avctx->reget_buffer(avctx, &s->frame)) { av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } /* check if this frame is even supposed to change */ if (s->size < 8) goto done; /* start after the chunk size */ stream_ptr = 4; /* fetch the header */ header = AV_RB16(&s->buf[stream_ptr]); stream_ptr += 2; /* if a header is present, fetch additional decoding parameters */ if (header & 0x0008) { if(s->size < 14) goto done; start_line = AV_RB16(&s->buf[stream_ptr]); stream_ptr += 4; height = AV_RB16(&s->buf[stream_ptr]); stream_ptr += 4; } else { start_line = 0; height = s->avctx->height; } row_ptr = s->frame.linesize[0] * start_line; switch (avctx->bits_per_coded_sample) { case 1: case 33: qtrle_decode_1bpp(s, stream_ptr, row_ptr, height); break; case 2: case 34: qtrle_decode_2n4bpp(s, stream_ptr, row_ptr, height, 2); has_palette = 1; break; case 4: case 36: qtrle_decode_2n4bpp(s, stream_ptr, row_ptr, height, 4); has_palette = 1; break; case 8: case 40: qtrle_decode_8bpp(s, stream_ptr, row_ptr, height); has_palette = 1; break; case 16: qtrle_decode_16bpp(s, stream_ptr, row_ptr, height); break; case 24: qtrle_decode_24bpp(s, stream_ptr, row_ptr, height); break; case 32: qtrle_decode_32bpp(s, stream_ptr, row_ptr, height); break; default: av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", avctx->bits_per_coded_sample); break; } if(has_palette) { const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { s->frame.palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } /* make the palette available on the way out */ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); } done: *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; /* always report that the buffer was completely consumed */ return buf_size; }


static void cabac_init_decoder(HEVCContext *s) { GetBitContext *gb = &s->HEVClc->gb; skip_bits(gb, 1); align_get_bits(gb); ff_init_cabac_decoder(&s->HEVClc->cc, gb->buffer + get_bits_count(gb) / 8, (get_bits_left(gb) + 7) / 8); }


static void swap_sample_fmts_on_filter(AVFilterContext *filter) { AVFilterLink *link = NULL; int format, bps; int i, j; for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_formats->format_count == 1) break; } if (i == filter->nb_inputs) return; format = link->out_formats->formats[0]; bps = av_get_bytes_per_sample(format); for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_score = INT_MIN; if (outlink->type != AVMEDIA_TYPE_AUDIO || outlink->in_formats->format_count < 2) continue; for (j = 0; j < outlink->in_formats->format_count; j++) { int out_format = outlink->in_formats->formats[j]; int out_bps = av_get_bytes_per_sample(out_format); int score; if (av_get_packed_sample_fmt(out_format) == format || av_get_planar_sample_fmt(out_format) == format) { best_idx = j; break; } /* for s32 and float prefer double to prevent loss of information */ if (bps == 4 && out_bps == 8) { best_idx = j; break; } /* prefer closest higher or equal bps */ score = -abs(out_bps - bps); if (out_bps >= bps) score += INT_MAX/2; if (score > best_score) { best_score = score; best_idx = j; } } FFSWAP(int, outlink->in_formats->formats[0], outlink->in_formats->formats[best_idx]); } }


int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, BlockDriverState *base, const char *backing_file_str) { BlockDriverState *intermediate; BlockDriverState *base_bs = NULL; BlockDriverState *new_top_bs = NULL; BlkIntermediateStates *intermediate_state, *next; int ret = -EIO; QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete; QSIMPLEQ_INIT(&states_to_delete); if (!top->drv || !base->drv) { goto exit; } new_top_bs = bdrv_find_overlay(active, top); if (new_top_bs == NULL) { /* we could not find the image above 'top', this is an error */ goto exit; } /* special case of new_top_bs->backing_hd already pointing to base - nothing * to do, no intermediate images */ if (new_top_bs->backing_hd == base) { ret = 0; goto exit; } intermediate = top; /* now we will go down through the list, and add each BDS we find * into our deletion queue, until we hit the 'base' */ while (intermediate) { intermediate_state = g_malloc0(sizeof(BlkIntermediateStates)); intermediate_state->bs = intermediate; QSIMPLEQ_INSERT_TAIL(&states_to_delete, intermediate_state, entry); if (intermediate->backing_hd == base) { base_bs = intermediate->backing_hd; break; } intermediate = intermediate->backing_hd; } if (base_bs == NULL) { /* something went wrong, we did not end at the base. safely * unravel everything, and exit with error */ goto exit; } /* success - we can delete the intermediate states, and link top->base */ backing_file_str = backing_file_str ? backing_file_str : base_bs->filename; ret = bdrv_change_backing_file(new_top_bs, backing_file_str, base_bs->drv ? base_bs->drv->format_name : ""); if (ret) { goto exit; } bdrv_set_backing_hd(new_top_bs, base_bs); QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) { /* so that bdrv_close() does not recursively close the chain */ bdrv_set_backing_hd(intermediate_state->bs, NULL); bdrv_unref(intermediate_state->bs); } ret = 0; exit: QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) { g_free(intermediate_state); } return ret; }


static int smacker_decode_bigtree(BitstreamContext *bc, HuffContext *hc, DBCtx *ctx) { if (hc->current + 1 >= hc->length) { av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n"); return AVERROR_INVALIDDATA; } if (!bitstream_read_bit(bc)) { // Leaf int val, i1, i2; i1 = ctx->v1->table ? bitstream_read_vlc(bc, ctx->v1->table, SMKTREE_BITS, 3) : 0; i2 = ctx->v2->table ? bitstream_read_vlc(bc, ctx->v2->table, SMKTREE_BITS, 3) : 0; if (i1 < 0 || i2 < 0) return AVERROR_INVALIDDATA; val = ctx->recode1[i1] | (ctx->recode2[i2] << 8); if(val == ctx->escapes[0]) { ctx->last[0] = hc->current; val = 0; } else if(val == ctx->escapes[1]) { ctx->last[1] = hc->current; val = 0; } else if(val == ctx->escapes[2]) { ctx->last[2] = hc->current; val = 0; } hc->values[hc->current++] = val; return 1; } else { //Node int r = 0, r_new, t; t = hc->current++; r = smacker_decode_bigtree(bc, hc, ctx); if(r < 0) return r; hc->values[t] = SMK_NODE | r; r++; r_new = smacker_decode_bigtree(bc, hc, ctx); if (r_new < 0) return r_new; return r + r_new; } }


static av_cold int qtrle_encode_end(AVCodecContext *avctx) { QtrleEncContext *s = avctx->priv_data; av_frame_free(&avctx->coded_frame); avpicture_free(&s->previous_frame); av_free(s->rlecode_table); av_free(s->length_table); av_free(s->skip_table); return 0; }


static av_cold int pcx_encode_init(AVCodecContext *avctx) { avctx->coded_frame = av_frame_alloc(); if (!avctx->coded_frame) return AVERROR(ENOMEM); avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->key_frame = 1; return 0; }


static int decode_mb_info(IVI4DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx) { int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, blks_per_mb, mv_scale, mb_type_bits; IVIMbInfo *mb, *ref_mb; int row_offset = band->mb_size * band->pitch; mb = tile->mbs; ref_mb = tile->ref_mbs; offs = tile->ypos * band->pitch + tile->xpos; blks_per_mb = band->mb_size != band->blk_size ? 4 : 1; mb_type_bits = ctx->frame_type == FRAMETYPE_BIDIR ? 2 : 1; /* scale factor for motion vectors */ mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); mv_x = mv_y = 0; for (y = tile->ypos; y < tile->ypos + tile->height; y += band->mb_size) { mb_offset = offs; for (x = tile->xpos; x < tile->xpos + tile->width; x += band->mb_size) { mb->xpos = x; mb->ypos = y; mb->buf_offs = mb_offset; if (get_bits1(&ctx->gb)) { if (ctx->frame_type == FRAMETYPE_INTRA) { av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n"); return AVERROR_INVALIDDATA; } mb->type = 1; /* empty macroblocks are always INTER */ mb->cbp = 0; /* all blocks are empty */ mb->q_delta = 0; if (!band->plane && !band->band_num && ctx->in_q) { mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, IVI_VLC_BITS, 1); mb->q_delta = IVI_TOSIGNED(mb->q_delta); } mb->mv_x = mb->mv_y = 0; /* no motion vector coded */ if (band->inherit_mv) { /* motion vector inheritance */ if (mv_scale) { mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); } else { mb->mv_x = ref_mb->mv_x; mb->mv_y = ref_mb->mv_y; } } } else { if (band->inherit_mv) { mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */ } else if (ctx->frame_type == FRAMETYPE_INTRA) { mb->type = 0; /* mb_type is always INTRA for intra-frames */ } else { mb->type = get_bits(&ctx->gb, mb_type_bits); } mb->cbp = get_bits(&ctx->gb, blks_per_mb); mb->q_delta = 0; if (band->inherit_qdelta) { if (ref_mb) mb->q_delta = ref_mb->q_delta; } else if (mb->cbp || (!band->plane && !band->band_num && ctx->in_q)) { mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, IVI_VLC_BITS, 1); mb->q_delta = IVI_TOSIGNED(mb->q_delta); } if (!mb->type) { mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */ } else { if (band->inherit_mv) { /* motion vector inheritance */ if (mv_scale) { mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); } else { mb->mv_x = ref_mb->mv_x; mb->mv_y = ref_mb->mv_y; } } else { /* decode motion vector deltas */ mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, IVI_VLC_BITS, 1); mv_y += IVI_TOSIGNED(mv_delta); mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, IVI_VLC_BITS, 1); mv_x += IVI_TOSIGNED(mv_delta); mb->mv_x = mv_x; mb->mv_y = mv_y; } } } mb++; if (ref_mb) ref_mb++; mb_offset += band->mb_size; } offs += row_offset; } align_get_bits(&ctx->gb); return 0; }


static void hevc_parser_close(AVCodecParserContext *s) { HEVCParserContext *ctx = s->priv_data; int i; #if ADVANCED_PARSER HEVCContext *h = &ctx->h; for (i = 0; i < FF_ARRAY_ELEMS(h->ps.vps_list); i++) av_buffer_unref(&h->ps.vps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) av_buffer_unref(&h->ps.sps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) av_buffer_unref(&h->ps.pps_list[i]); h->ps.sps = NULL; av_freep(&h->HEVClc); #endif for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.vps_list); i++) av_buffer_unref(&ctx->ps.vps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.sps_list); i++) av_buffer_unref(&ctx->ps.sps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.pps_list); i++) av_buffer_unref(&ctx->ps.pps_list[i]); ctx->ps.sps = NULL; ff_h2645_packet_uninit(&ctx->pkt); av_freep(&ctx->pc.buffer); }


static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt) { MvContext *mv = avctx->priv_data; AVIOContext *pb = avctx->pb; AVStream *st = avctx->streams[mv->stream_index]; const AVIndexEntry *index; int frame = mv->frame[mv->stream_index]; int ret; uint64_t pos; if (frame < st->nb_index_entries) { index = &st->index_entries[frame]; pos = avio_tell(pb); if (index->pos > pos) avio_skip(pb, index->pos - pos); else if (index->pos < pos) { if (!pb->seekable) return AVERROR(EIO); ret = avio_seek(pb, index->pos, SEEK_SET); if (ret < 0) return ret; } ret = av_get_packet(pb, pkt, index->size); if (ret < 0) return ret; pkt->stream_index = mv->stream_index; pkt->pts = index->timestamp; pkt->flags |= AV_PKT_FLAG_KEY; mv->frame[mv->stream_index]++; mv->eof_count = 0; } else { mv->eof_count++; if (mv->eof_count >= avctx->nb_streams) return AVERROR_EOF; // avoid returning 0 without a packet return AVERROR(EAGAIN); } mv->stream_index++; if (mv->stream_index >= avctx->nb_streams) mv->stream_index = 0; return 0; }


static av_cold int prores_encode_close(AVCodecContext *avctx) { ProresContext* ctx = avctx->priv_data; av_freep(&avctx->coded_frame); av_free(ctx->fill_y); av_free(ctx->fill_u); av_free(ctx->fill_v); return 0; }


int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio) { int len, need_keyframe, missing_packets; AVIOContext *pb; uint8_t *buf; int64_t now; uint16_t first_missing, missing_mask; if (!fd && !avio) return -1; need_keyframe = s->handler && s->handler->need_keyframe && s->handler->need_keyframe(s->dynamic_protocol_context); missing_packets = find_missing_packets(s, &first_missing, &missing_mask); if (!need_keyframe && !missing_packets) return 0; /* Send new feedback if enough time has elapsed since the last * feedback packet. */ now = av_gettime(); if (s->last_feedback_time && (now - s->last_feedback_time) < MIN_FEEDBACK_INTERVAL) return 0; s->last_feedback_time = now; if (!fd) pb = avio; else if (avio_open_dyn_buf(&pb) < 0) return -1; if (need_keyframe) { avio_w8(pb, (RTP_VERSION << 6) | 1); /* PLI */ avio_w8(pb, RTCP_PSFB); avio_wb16(pb, 2); /* length in words - 1 */ // our own SSRC: we use the server's SSRC + 1 to avoid conflicts avio_wb32(pb, s->ssrc + 1); avio_wb32(pb, s->ssrc); // server SSRC } if (missing_packets) { avio_w8(pb, (RTP_VERSION << 6) | 1); /* NACK */ avio_w8(pb, RTCP_RTPFB); avio_wb16(pb, 3); /* length in words - 1 */ avio_wb32(pb, s->ssrc + 1); avio_wb32(pb, s->ssrc); // server SSRC avio_wb16(pb, first_missing); avio_wb16(pb, missing_mask); } avio_flush(pb); if (!fd) return 0; len = avio_close_dyn_buf(pb, &buf); if (len > 0 && buf) { ffurl_write(fd, buf, len); av_free(buf); } return 0; }


static struct pathelem *add_entry(struct pathelem *root, const char *name) { root->num_entries++; root = realloc(root, sizeof(*root) + sizeof(root->entries[0])*root->num_entries); root->entries[root->num_entries-1] = new_entry(root->pathname, root, name); root->entries[root->num_entries-1] = add_dir_maybe(root->entries[root->num_entries-1]); return root; }


yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, enum PixelFormat target, int hasAlpha) { const int16_t *buf0 = buf[0], *buf1 = buf[1], *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], *vbuf0 = vbuf[0], *vbuf1 = vbuf[1], *abuf0 = hasAlpha ? abuf[0] : NULL, *abuf1 = hasAlpha ? abuf[1] : NULL; int yalpha1 = 4095 - yalpha; int uvalpha1 = 4095 - uvalpha; int i; for (i = 0; i < (dstW >> 1); i++) { int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; int A1, A2; const void *r = c->table_rV[V], *g = (c->table_gU[U] + c->table_gV[V]), *b = c->table_bU[U]; if (hasAlpha) { A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19; A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19; } yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, r, g, b, y, target, hasAlpha); } }


static void nbd_recv_coroutines_enter_all(NbdClientSession *s) { int i; for (i = 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i]) { qemu_coroutine_enter(s->recv_coroutine[i], NULL); } } }


static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1, Jpeg2000Band *band) { int i, j, idx; int32_t *datap = (int32_t *) &comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x]; for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) for (i = 0; i < (cblk->coord[0][1] - cblk->coord[0][0]); ++i) { idx = (comp->coord[0][1] - comp->coord[0][0]) * j + i; datap[idx] = ((int32_t)(t1->data[j][i]) * band->i_stepsize + (1 << 15)) >> 16; } }


static void ehci_queues_rip_device(EHCIState *ehci, USBDevice *dev) { EHCIQueue *q, *tmp; QTAILQ_FOREACH_SAFE(q, &ehci->queues, next, tmp) { if (q->packet.owner == NULL || q->packet.owner->dev != dev) { continue; } ehci_free_queue(q); } }


static int vfio_add_std_cap(VFIODevice *vdev, uint8_t pos) { PCIDevice *pdev = &vdev->pdev; uint8_t cap_id, next, size; int ret; cap_id = pdev->config[pos]; next = pdev->config[pos + 1]; /* * If it becomes important to configure capabilities to their actual * size, use this as the default when it's something we don't recognize. * Since QEMU doesn't actually handle many of the config accesses, * exact size doesn't seem worthwhile. */ size = vfio_std_cap_max_size(pdev, pos); /* * pci_add_capability always inserts the new capability at the head * of the chain. Therefore to end up with a chain that matches the * physical device, we insert from the end by making this recursive. * This is also why we pre-caclulate size above as cached config space * will be changed as we unwind the stack. */ if (next) { ret = vfio_add_std_cap(vdev, next); if (ret) { return ret; } } else { pdev->config[PCI_CAPABILITY_LIST] = 0; /* Begin the rebuild */ } switch (cap_id) { case PCI_CAP_ID_MSI: ret = vfio_setup_msi(vdev, pos); break; case PCI_CAP_ID_MSIX: ret = vfio_setup_msix(vdev, pos); break; default: ret = pci_add_capability(pdev, cap_id, pos, size); break; } if (ret < 0) { error_report("vfio: %04x:%02x:%02x.%x Error adding PCI capability " "0x%x[0x%x]@0x%x: %d", vdev->host.domain, vdev->host.bus, vdev->host.slot, vdev->host.function, cap_id, size, pos, ret); return ret; } return 0; }


void ff_xvmc_decode_mb(MpegEncContext *s) { XvMCMacroBlock *mv_block; struct xvmc_pix_fmt *render; int i, cbp, blocks_per_mb; const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; if (s->encoding) { av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n"); return; } // from ff_mpv_decode_mb(), update DC predictors for P macroblocks if (!s->mb_intra) { s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision; } // MC doesn't skip blocks s->mb_skipped = 0; // Do I need to export quant when I could not perform postprocessing? // Anyway, it doesn't hurt. s->current_picture.qscale_table[mb_xy] = s->qscale; // start of XVMC-specific code render = (struct xvmc_pix_fmt*)s->current_picture.f->data[2]; assert(render); assert(render->xvmc_id == AV_XVMC_ID); assert(render->mv_blocks); // take the next free macroblock mv_block = &render->mv_blocks[render->start_mv_blocks_num + render->filled_mv_blocks_num]; mv_block->x = s->mb_x; mv_block->y = s->mb_y; mv_block->dct_type = s->interlaced_dct; // XVMC_DCT_TYPE_FRAME/FIELD; if (s->mb_intra) { mv_block->macroblock_type = XVMC_MB_TYPE_INTRA; // no MC, all done } else { mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN; if (s->mv_dir & MV_DIR_FORWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_FORWARD; // PMV[n][dir][xy] = mv[dir][n][xy] mv_block->PMV[0][0][0] = s->mv[0][0][0]; mv_block->PMV[0][0][1] = s->mv[0][0][1]; mv_block->PMV[1][0][0] = s->mv[0][1][0]; mv_block->PMV[1][0][1] = s->mv[0][1][1]; } if (s->mv_dir & MV_DIR_BACKWARD) { mv_block->macroblock_type |= XVMC_MB_TYPE_MOTION_BACKWARD; mv_block->PMV[0][1][0] = s->mv[1][0][0]; mv_block->PMV[0][1][1] = s->mv[1][0][1]; mv_block->PMV[1][1][0] = s->mv[1][1][0]; mv_block->PMV[1][1][1] = s->mv[1][1][1]; } switch(s->mv_type) { case MV_TYPE_16X16: mv_block->motion_type = XVMC_PREDICTION_FRAME; break; case MV_TYPE_16X8: mv_block->motion_type = XVMC_PREDICTION_16x8; break; case MV_TYPE_FIELD: mv_block->motion_type = XVMC_PREDICTION_FIELD; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][1] <<= 1; mv_block->PMV[1][0][1] <<= 1; mv_block->PMV[0][1][1] <<= 1; mv_block->PMV[1][1][1] <<= 1; } break; case MV_TYPE_DMV: mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME; if (s->picture_structure == PICT_FRAME) { mv_block->PMV[0][0][0] = s->mv[0][0][0]; // top from top mv_block->PMV[0][0][1] = s->mv[0][0][1] << 1; mv_block->PMV[0][1][0] = s->mv[0][0][0]; // bottom from bottom mv_block->PMV[0][1][1] = s->mv[0][0][1] << 1; mv_block->PMV[1][0][0] = s->mv[0][2][0]; // dmv00, top from bottom mv_block->PMV[1][0][1] = s->mv[0][2][1] << 1; // dmv01 mv_block->PMV[1][1][0] = s->mv[0][3][0]; // dmv10, bottom from top mv_block->PMV[1][1][1] = s->mv[0][3][1] << 1; // dmv11 } else { mv_block->PMV[0][1][0] = s->mv[0][2][0]; // dmv00 mv_block->PMV[0][1][1] = s->mv[0][2][1]; // dmv01 } break; default: assert(0); } mv_block->motion_vertical_field_select = 0; // set correct field references if (s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8) { mv_block->motion_vertical_field_select |= s->field_select[0][0]; mv_block->motion_vertical_field_select |= s->field_select[1][0] << 1; mv_block->motion_vertical_field_select |= s->field_select[0][1] << 2; mv_block->motion_vertical_field_select |= s->field_select[1][1] << 3; } } // !intra // time to handle data blocks mv_block->index = render->next_free_data_block_num; blocks_per_mb = 6; if (s->chroma_format >= 2) { blocks_per_mb = 4 + (1 << s->chroma_format); } // calculate cbp cbp = 0; for (i = 0; i < blocks_per_mb; i++) { cbp += cbp; if (s->block_last_index[i] >= 0) cbp++; } if (s->avctx->flags & AV_CODEC_FLAG_GRAY) { if (s->mb_intra) { // intra frames are always full chroma blocks for (i = 4; i < blocks_per_mb; i++) { memset(s->pblocks[i], 0, sizeof(*s->pblocks[i])); // so we need to clear them if (!render->unsigned_intra) *s->pblocks[i][0] = 1 << 10; } } else { cbp &= 0xf << (blocks_per_mb - 4); blocks_per_mb = 4; // luminance blocks only } } mv_block->coded_block_pattern = cbp; if (cbp == 0) mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN; for (i = 0; i < blocks_per_mb; i++) { if (s->block_last_index[i] >= 0) { // I do not have unsigned_intra MOCO to test, hope it is OK. if (s->mb_intra && (render->idct || !render->unsigned_intra)) *s->pblocks[i][0] -= 1 << 10; if (!render->idct) { s->idsp.idct(*s->pblocks[i]); /* It is unclear if MC hardware requires pixel diff values to be * in the range [-255;255]. TODO: Clipping if such hardware is * ever found. As of now it would only be an unnecessary * slowdown. */ } // copy blocks only if the codec doesn't support pblocks reordering if (s->avctx->xvmc_acceleration == 1) { memcpy(&render->data_blocks[render->next_free_data_block_num*64], s->pblocks[i], sizeof(*s->pblocks[i])); } render->next_free_data_block_num++; } } render->filled_mv_blocks_num++; assert(render->filled_mv_blocks_num <= render->allocated_mv_blocks); assert(render->next_free_data_block_num <= render->allocated_data_blocks); /* The above conditions should not be able to fail as long as this function * is used and the following 'if ()' automatically calls a callback to free * blocks. */ if (render->filled_mv_blocks_num == render->allocated_mv_blocks) ff_mpeg_draw_horiz_band(s, 0, 0); }